diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index cb329b6658..5009f0eace 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,137 @@ +==== 1.6.0.0-alpha1 ==== + +=== Improvements === +Add Dynamic sku option for configurable products +Moneybookers Multistore System Configuration +Moneybookers OBT Defaults +PrototypeJS upgraded to 1.7 + +=== Changes === +Relations between models and resource models were revised for better support of multiple databases +* Varien_Db_Adapter_Pdo_Mysql revised +* Introduced Varien_Db_Adapter_Interface, Varien_Db_Ddl_Table +* Introduced new classes named resource helpers +* Backwards comatibility and known issues +** Flat attribute definition is not backward compatible +** Old columns names are not fully mapped to new ones +** Error appears after Customer Group saving with name length more than 32 +** Caching config in Database results in endless recursion +** There's no sql upgrade for media storage tables +Deprecated GoogleBase module (http://googlemerchantblog.blogspot.com/2010/12/new-shopping-apis-and-deprecation-of.html) + +=== Fixes === +Fixed Unable to change customer password when email confirmation is enabled +Fixed Can't choose Group at the creation new Order by admin +Fixed Subtotal for Bundle product with quantity 2 calculates as for one +Fixed Breadcrumbs and the ?Use categories path for product URLs setting +Fixed RSS feed redirected to 404 error page (from admin panel) +Fixed Cache Management incorrect ACL check +Fixed Media Sub-Folder Creation and View in Admin +Fixed Quantity of bundle item is not stored correctly, in case when it is decimal +Fixed Shipping creation for bundle product shows wrong q-ty +Fixed Issue creating content staging site +Fixed Unable to create attribute with numbers +Fixed Moving Grouped product from Order and Shopping cart to the Wishlist does not work +Fixed Product Attribute can't be saved if Attribute Code contain numbers +Fixed Incorrect titles in "Sales Emails" tab +Fixed Any backend user can access the MCM (Downloader) +Fixed Saving attribute value in store view scope only causes data loss +Fixed Resources names are not translated on Role Resources page at backend +Fixed Quote Lifetime don't work +Fixed WYSIWYG Editor - Unable to Create a Folder when Inserting a File +Fixed Out of stock products getting "This product has not been configured." error msg +Fixed Impossible save empty values for store view scope +Fixed Include in Navigation Menu +Fixed Date Field error in product +Fixed product.js not working well images that are taller than wider. +Fixed Modern theme search results page bug +Fixed Bundled product special pricing does not reflect in cart +Fixed In Configurable Products only Admin attribute label is retrieved +Fixed Anchored categories w/ subcategories and products in both +Fixed Minimum quantity in Grouped product +Fixed Minimum Quantities Warning not working properly +Fixed Unable to change configurable product name for store view +Fixed Dropdown attributes with no value should be hidden +Fixed CLONE -"Compare Products" block does not appear on the category page and product page +Fixed Category and product design settings inheritance +Fixed Not shown button for browsing file in "downloadable product" tab "Downloadable Information"(Just for new prototype version). +Fixed Some small and thumbnail images are corrupted for products +Fixed Zooming doesn't work for an image larger or taller than the container +Fixed Frontend->Necessary to add pagination to the bottom of category +Fixed Category Tree -> Changing category color +Fixed Changing Attribute Scopes +Fixed Typo: wrong helper used in ProductController to call initProductLayout() +Fixed Unable to continue checkout when "Street Address" use non English characters +Fixed Time payment processing extremely long +Fixed Cannot create or save after editing customer's Address, "Please enter the street" error appears on frontend +Fixed product not salable marking/language issue +Fixed Free shipping doesn't work in table rates shipping method +Fixed Wrong order status after "Credit Memo" for product's with FPT +Fixed Missing Capture transaction in backend when capture money from PayPal (PayPal UK Express) +Fixed Unable to made online refund from Magento using PayPal UK Express checkout +Fixed It's possible to click twice on order place button and receive "Cart is empty" page +Fixed Unable to place order for customer with Cyrillic street name. +Fixed Backend - Add new customer - ALL TRANSLATIONS MISSING +Fixed Customer Segment "Up to Date" Condition Logical Inversion +Fixed Errorhandling in saveAction / editAction broken +Fixed Reward points expiration date is shown incorrect +Fixed Incorrect "Date of Birth" validation +Fixed Error when searching Customer Wishlist by Qty at admin backend +Fixed Default values for customer attributes settings are not used in some cases +Fixed Category Treeview Broken (Manage Products/Manage Categories) +Fixed Categories' does not show full categories tree (Just for new prototype version). +Fixed It should be possible to create Simple associated product during Configurable product creation process (Just for new prototype version) +Fixed It should be possible to delete row with Samples for Downloadable product during creation (Just for new prototype version) +Fixed No display of Remaining Balance, if only one credit card used with Authorize.net Payment Method +Fixed Partial Authorization is not working at all, when Authorize and Capture setting is enabled for Authorize.net +Fixed Subtotal displays incorrect subtotal if gift wrapping was applied +Fixed Orders with not supported statuses moved to orders archive. +Fixed No compiled CSS and JavaScripts are present in native database +Fixed View Details" link is not present for simple product with custom options or Gift Cards added to the Wishlist +Fixed Full Page Cache and design themes exceptions +Fixed Setting "Backorders" > "No Backorders" do not apply in backend and order creation. +Fixed Not received the warning message "This product is available for purchase in increments of 2 only." in backend order creation. +Fixed Order is in google sandbox doesn't contain gift card +Fixed Broken JS validation on "Configuration" step +Fixed Broken mysql4-data-upgrade-1.4.0.0.13-1.4.0.0.14.php file +Fixed "Turkish Lira" missing on the "Localization" step during installation +Fixed Magento Connect -> MCM -> "Log in" page - Message or some information about required fields doesn't appeared +Fixed Magento Connect -> MCM -> "Settings" tab -> Changes don't saved +Fixed Magento Connect -> MCM -> "Settings" tab -> data doesn't saved +Fixed Magento Connect -> MCM -> If extension packages contains files with the same names, it installation shoul be conflicted. +Fixed Payment Applicable From = "Specific Countries" option does not work for Express Checkout (Payflow Edition) +Fixed Credit Card information is required for $0.00 total. +Fixed Image-Upload does not work in Safari 5 +Fixed Paypal Direct send wrong billing address to API +Fixed Incorrect billing/shipping address transfer from Magento to PayPal ( WPP Payflow Edition, WPP Payflow Edition EC ) +Fixed Gateway error: A valid amount is required' appears during create Credit Memo for order, which uses Authorize.net +Fixed Magento creates order even if response from PaypalUk is empty +Fixed Enabled payment actions are available for order with "Zero subtotal" +Fixed Incorrect format of the transferring shipping/billing addresses from Magento to PayPal (WPP EC, WPS, WPP ) +Fixed When in backend ?new order? and using a custom price the subtotal is wrong +Fixed Buy One Get One Free not working +Fixed Table Rates & Free Shipping Cart Rules not working together +Fixed Catalog Prices include tax is not working. +Fixed buy 1 get 1 free doesn't work +Fixed Bundle Product using Fixed Price does not Display Tier Pricing Correctly +Fixed Cart Price Rule not working with Product Attributes +Fixed Tax from orders in status pending presents in Tax Report +Fixed Coupons Report Math Bug +Fixed Credit Memo refunding not working due to four decimal places for Shipping costs +Fixed Can not ad Product to order if it has custom options +Fixed Tier price does not applies correctly on the back-end if customer group is changed on the backoffice order +Fixed Wrong product with custom options price is displayed in the wishlist sidebar during order creation via back-end +Fixed Missing isset() in Mage_Sales_Model_Recurring_Profile::createOrder() +Fixed Shipping address is not saving during process order in backend with 'Save in Address book' option for existing customer. +Fixed Advanced search on boolean type attributes +Fixed UPS (UPSS,DHL,FedEx) options "Maximum Package Weight " works not correct. +Fixed Shipping method UPS_XML missing titles +Fixed Table rate shipping is not recalculate after applying a discount +Fixed PDF subtotal including tax is zero +Fixed Tax/VAT number not displayed +Fixed HTML typo in Transactional mail "account_new_confirmation.html" +Fixed Varien_Db_Adapter_Mysqli::raw_query() should throw an Exception after 10 tries + ==== 1.5.1.0 ==== === Improvements === @@ -602,7 +736,7 @@ Fixed No customer's information Fixed PayPal Business Email address update -==== 1.5.x-devel-97859 ==== +==== 1.5.x-devel-96719 ==== === Improvements === Implemented WS-I for API @@ -1627,6 +1761,7 @@ Fixed Order success page is not displayed after placing Order using Website Paym - now, return and cancel urls can be secure (https) Fixed Problems with newsletter template preview on newsletter queue edit page Fixed Link "configure" is inactive for downloadable products in product grid on Order creation page in backend +- also fixed "Manage Customer" grids + Manage Shopping Cart (Enterprise Checkout) grids Fixed A system error message is missing for cases when media storage synchronization is complete or an error occurred - output messages for notifications edited Fixed Incorrect price calculation for bundle product during backend order creation(Tax is doubles in Total) diff --git a/app/Mage.php b/app/Mage.php index 0c765b62cc..8380d4270b 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -151,11 +151,11 @@ public static function getVersionInfo() { return array( 'major' => '1', - 'minor' => '5', - 'revision' => '1', + 'minor' => '6', + 'revision' => '0', 'patch' => '0', - 'stability' => '', - 'number' => '', + 'stability' => 'alpha', + 'number' => '1', ); } @@ -510,10 +510,6 @@ public static function getBlockSingleton($type) */ public static function helper($name) { - if (strpos($name, '/') === false) { - $name .= '/data'; - } - $registryKey = '_helper/' . $name; if (!self::registry($registryKey)) { $helperClass = self::getConfig()->getHelperClassName($name); @@ -522,6 +518,23 @@ public static function helper($name) return self::registry($registryKey); } + /** + * Retreive resource helper object + * + * @param string $moduleName + * @return Mage_Core_Model_Resource_Helper_Abstract + */ + public static function getResourceHelper($moduleName) + { + $registryKey = '_resource_helper/' . $moduleName; + if (!self::registry($registryKey)) { + $helperClass = self::getConfig()->getResourceHelper($moduleName); + self::register($registryKey, $helperClass); + } + + return self::registry($registryKey); + } + /** * Return new exception by module to be thrown * @@ -532,7 +545,7 @@ public static function helper($name) */ public static function exception($module = 'Mage_Core', $message = '', $code = 0) { - $className = $module.'_Exception'; + $className = $module . '_Exception'; return new $className($message, $code); } @@ -564,7 +577,7 @@ public static function app($code = '', $type = 'store', $options = array()) self::$_app = new Mage_Core_Model_App(); self::setRoot(); self::$_events = new Varien_Event_Collection(); - self::$_config = new Mage_Core_Model_Config(); + self::$_config = new Mage_Core_Model_Config($options); Varien_Profiler::start('self::app::init'); self::$_app->init($code, $type, $options); @@ -612,14 +625,14 @@ public static function init($code = '', $type = 'store', $options = array(), $mo * @param string $type * @param string|array $options */ - public static function run($code = '', $type = 'store', $options=array()) + public static function run($code = '', $type = 'store', $options = array()) { try { Varien_Profiler::start('mage'); self::setRoot(); - self::$_app = new Mage_Core_Model_App(); - self::$_events = new Varien_Event_Collection(); - self::$_config = new Mage_Core_Model_Config(); + self::$_app = new Mage_Core_Model_App(); + self::$_events = new Varien_Event_Collection(); + self::$_config = new Mage_Core_Model_Config($options); self::$_app->run(array( 'scope_code' => $code, 'scope_type' => $type, @@ -664,11 +677,11 @@ public static function isInstalled($options = array()) if (is_string($options)) { $options = array('etc_dir' => $options); } - $etcDir = 'etc'; + $etcDir = self::getRoot() . DS . 'etc'; if (!empty($options['etc_dir'])) { $etcDir = $options['etc_dir']; } - $localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml'; + $localConfigFile = $etcDir . DS . 'local.xml'; self::$_isInstalled = false; diff --git a/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes.php b/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes.php index 2e5f82c6a0..0f693a2058 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes/Edit/Form.php b/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes/Edit/Form.php index 6de0d1e2a0..cafef3e585 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes/Edit/Form.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/Edit/Codes/Edit/Form.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Block/Adminhtml/List/Codes.php b/app/code/community/Find/Feed/Block/Adminhtml/List/Codes.php index 8745273213..1fa578a41c 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/List/Codes.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/List/Codes.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Block/Adminhtml/List/Codes/Grid.php b/app/code/community/Find/Feed/Block/Adminhtml/List/Codes/Grid.php index 36d15417fe..5c1200bdea 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/List/Codes/Grid.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/List/Codes/Grid.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Block/Adminhtml/List/Items.php b/app/code/community/Find/Feed/Block/Adminhtml/List/Items.php index bc4ffe395a..5c57a6cea4 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/List/Items.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/List/Items.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Block/Adminhtml/List/Items/Grid.php b/app/code/community/Find/Feed/Block/Adminhtml/List/Items/Grid.php index 7835014686..df664137cc 100644 --- a/app/code/community/Find/Feed/Block/Adminhtml/List/Items/Grid.php +++ b/app/code/community/Find/Feed/Block/Adminhtml/List/Items/Grid.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Helper/Data.php b/app/code/community/Find/Feed/Helper/Data.php index 9547bb5e4c..c123a1501e 100755 --- a/app/code/community/Find/Feed/Helper/Data.php +++ b/app/code/community/Find/Feed/Helper/Data.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Frequency.php b/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Frequency.php index b52827bd4d..f51aa33bd0 100644 --- a/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Frequency.php +++ b/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Frequency.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Hours.php b/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Hours.php index fc17461a80..e3320b3926 100644 --- a/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Hours.php +++ b/app/code/community/Find/Feed/Model/Adminhtml/System/Source/Cron/Hours.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Codes.php b/app/code/community/Find/Feed/Model/Codes.php index 2db7603ac7..2599d99f61 100644 --- a/app/code/community/Find/Feed/Model/Codes.php +++ b/app/code/community/Find/Feed/Model/Codes.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Import.php b/app/code/community/Find/Feed/Model/Import.php index 3a517f94e4..7098c82cda 100755 --- a/app/code/community/Find/Feed/Model/Import.php +++ b/app/code/community/Find/Feed/Model/Import.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Mysql4/Codes.php b/app/code/community/Find/Feed/Model/Mysql4/Codes.php index 27d5d4934a..9071957da0 100644 --- a/app/code/community/Find/Feed/Model/Mysql4/Codes.php +++ b/app/code/community/Find/Feed/Model/Mysql4/Codes.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,13 +30,6 @@ * @category Find * @package Find_Feed */ -class Find_Feed_Model_Mysql4_Codes extends Mage_Core_Model_Mysql4_Abstract +class Find_Feed_Model_Mysql4_Codes extends Find_Feed_Model_Resource_Codes { - /** - * Class local constructor - */ - protected function _construct() - { - $this->_init('find_feed/feed_import_codes', 'code_id'); - } } diff --git a/app/code/community/Find/Feed/Model/Mysql4/Codes/Collection.php b/app/code/community/Find/Feed/Model/Mysql4/Codes/Collection.php index 02ba7b82d8..34c99b8fdd 100644 --- a/app/code/community/Find/Feed/Model/Mysql4/Codes/Collection.php +++ b/app/code/community/Find/Feed/Model/Mysql4/Codes/Collection.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,26 +30,7 @@ * @category Find * @package Find_Feed */ -class Find_Feed_Model_Mysql4_Codes_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Find_Feed_Model_Mysql4_Codes_Collection extends Find_Feed_Model_Resource_Codes_Collection { - /** - * Local constructor - * - */ - protected function _construct() - { - $this->_init('find_feed/codes'); - } - - /** - * Fetch attributes to import - * - * @return array - */ - public function getImportAttributes() - { - $this->addFieldToFilter('is_imported', array('eq' => '1')); - return $this->_toOptionHash('import_code', 'eav_code'); - } } diff --git a/app/code/community/Find/Feed/Model/Mysql4/Setup.php b/app/code/community/Find/Feed/Model/Mysql4/Setup.php index eebc496a01..f66c05b3d6 100755 --- a/app/code/community/Find/Feed/Model/Mysql4/Setup.php +++ b/app/code/community/Find/Feed/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Observer.php b/app/code/community/Find/Feed/Model/Observer.php index d17342c035..2fbb95a6f8 100644 --- a/app/code/community/Find/Feed/Model/Observer.php +++ b/app/code/community/Find/Feed/Model/Observer.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/Model/Resource/Codes.php b/app/code/community/Find/Feed/Model/Resource/Codes.php new file mode 100644 index 0000000000..92d592c4f4 --- /dev/null +++ b/app/code/community/Find/Feed/Model/Resource/Codes.php @@ -0,0 +1,42 @@ +_init('find_feed/feed_import_codes', 'code_id'); + } +} diff --git a/app/code/community/Find/Feed/Model/Resource/Codes/Collection.php b/app/code/community/Find/Feed/Model/Resource/Codes/Collection.php new file mode 100644 index 0000000000..7536fc322d --- /dev/null +++ b/app/code/community/Find/Feed/Model/Resource/Codes/Collection.php @@ -0,0 +1,55 @@ +_init('find_feed/codes'); + } + + /** + * Fetch attributes to import + * + * @return array + */ + public function getImportAttributes() + { + $this->addFieldToFilter('is_imported', array('eq' => '1')); + return $this->_toOptionHash('import_code', 'eav_code'); + } + +} diff --git a/app/code/core/Mage/Shipping/Model/Rule/Action/Method.php b/app/code/community/Find/Feed/Model/Resource/Setup.php similarity index 76% rename from app/code/core/Mage/Shipping/Model/Rule/Action/Method.php rename to app/code/community/Find/Feed/Model/Resource/Setup.php index 692cb23403..7db78946c6 100644 --- a/app/code/core/Mage/Shipping/Model/Rule/Action/Method.php +++ b/app/code/community/Find/Feed/Model/Resource/Setup.php @@ -18,14 +18,19 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Mage - * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @category + * @package _home + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - -class Mage_Sales_Model_Shipping_Rule_Action_Method extends Mage_Sales_Model_Shipping_Rule_Action_Abstract +/** + * Thefind feed module setup + * + * @category Find + * @package Find_Feed + */ +class Find_Feed_Model_Resource_Setup extends Mage_Catalog_Model_Resource_Setup { - } + diff --git a/app/code/community/Find/Feed/controllers/Adminhtml/Codes/GridController.php b/app/code/community/Find/Feed/controllers/Adminhtml/Codes/GridController.php index 3ffa939add..22d41616ea 100644 --- a/app/code/community/Find/Feed/controllers/Adminhtml/Codes/GridController.php +++ b/app/code/community/Find/Feed/controllers/Adminhtml/Codes/GridController.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/controllers/Adminhtml/Items/GridController.php b/app/code/community/Find/Feed/controllers/Adminhtml/Items/GridController.php index ced97cdf5a..79f51427a1 100644 --- a/app/code/community/Find/Feed/controllers/Adminhtml/Items/GridController.php +++ b/app/code/community/Find/Feed/controllers/Adminhtml/Items/GridController.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/etc/adminhtml.xml b/app/code/community/Find/Feed/etc/adminhtml.xml index 2c1d0da2e4..454ccc689f 100644 --- a/app/code/community/Find/Feed/etc/adminhtml.xml +++ b/app/code/community/Find/Feed/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/community/Find/Feed/etc/config.xml b/app/code/community/Find/Feed/etc/config.xml index 3e46029213..9784dfb6e5 100755 --- a/app/code/community/Find/Feed/etc/config.xml +++ b/app/code/community/Find/Feed/etc/config.xml @@ -21,36 +21,37 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.0.2 + 1.6.0.0 Find_Feed_Model - find_feed_mysql4 + find_feed_resource - - Find_Feed_Model_Mysql4 + + Find_Feed_Model_Resource + find_feed_mysql4 find_feed_import_codes
-
+
Find_Feed - Find_Feed_Model_Mysql4_Setup + Find_Feed_Model_Resource_Setup diff --git a/app/code/community/Find/Feed/etc/system.xml b/app/code/community/Find/Feed/etc/system.xml index a5121c5fa5..6af369cf3f 100755 --- a/app/code/community/Find/Feed/etc/system.xml +++ b/app/code/community/Find/Feed/etc/system.xml @@ -21,7 +21,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/community/Find/Feed/sql/find_feed_setup/install-1.6.0.0.php b/app/code/community/Find/Feed/sql/find_feed_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..37b36e5343 --- /dev/null +++ b/app/code/community/Find/Feed/sql/find_feed_setup/install-1.6.0.0.php @@ -0,0 +1,74 @@ +startSetup(); +/** + * Create table 'find_feed/feed_import_codes' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('find_feed/feed_import_codes')) + ->addColumn('code_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Code id') + ->addColumn('import_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Import type') + ->addColumn('eav_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'EAV code') + ->addColumn('is_imported', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Is imported') + ->setComment('Find feed import codes'); +$installer->getConnection()->createTable($table); + +$this->addAttribute('catalog_product', 'is_imported', array( + 'group' => 'General', + 'type' => 'int', + 'input' => 'select', + 'label' => 'In feed', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => 1, + 'required' => 0, + 'visible_on_front' => 0, + 'is_html_allowed_on_front' => 0, + 'is_configurable' => 0, + 'source' => 'eav/entity_attribute_source_boolean', + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'unique' => false, + 'user_defined' => false, + 'is_user_defined' => false, + 'used_in_product_listing' => true +)); + +$installer->endSetup(); diff --git a/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-install-0.0.1.php b/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-install-0.0.1.php index 29b8858bfd..e48eb3b6e7 100755 --- a/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-install-0.0.1.php +++ b/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-install-0.0.1.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-upgrade-0.0.1-0.0.2.php b/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-upgrade-0.0.1-0.0.2.php index f502e21823..62cf0b81ad 100644 --- a/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-upgrade-0.0.1-0.0.2.php +++ b/app/code/community/Find/Feed/sql/find_feed_setup/mysql4-upgrade-0.0.1-0.0.2.php @@ -20,7 +20,7 @@ * * @category * @package _home - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Phoenix/Moneybookers/Block/Form.php b/app/code/community/Phoenix/Moneybookers/Block/Form.php index c23036d36f..1b8ff9d3c0 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Form.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Form.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Form extends Mage_Payment_Block_Form diff --git a/app/code/community/Phoenix/Moneybookers/Block/Info.php b/app/code/community/Phoenix/Moneybookers/Block/Info.php index 10b6e71c7b..dc921276c7 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Info.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Info.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Info extends Mage_Payment_Block_Info diff --git a/app/code/community/Phoenix/Moneybookers/Block/Jsinit.php b/app/code/community/Phoenix/Moneybookers/Block/Jsinit.php index 5c54b0732b..ecd38b2350 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Jsinit.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Jsinit.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Jsinit extends Mage_Adminhtml_Block_Template diff --git a/app/code/community/Phoenix/Moneybookers/Block/Payment.php b/app/code/community/Phoenix/Moneybookers/Block/Payment.php index 0b98a83dd7..bceb51c9b0 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Payment.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Payment.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Payment extends Mage_Core_Block_Template diff --git a/app/code/community/Phoenix/Moneybookers/Block/Placeform.php b/app/code/community/Phoenix/Moneybookers/Block/Placeform.php index b363eae370..139f6208b3 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Placeform.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Placeform.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Placeform extends Mage_Core_Block_Template diff --git a/app/code/community/Phoenix/Moneybookers/Block/Redirect.php b/app/code/community/Phoenix/Moneybookers/Block/Redirect.php index 96bbfba02b..8724d7acd7 100644 --- a/app/code/community/Phoenix/Moneybookers/Block/Redirect.php +++ b/app/code/community/Phoenix/Moneybookers/Block/Redirect.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Block_Redirect extends Mage_Core_Block_Template diff --git a/app/code/community/Phoenix/Moneybookers/Helper/Data.php b/app/code/community/Phoenix/Moneybookers/Helper/Data.php index e92b517440..7eae958136 100644 --- a/app/code/community/Phoenix/Moneybookers/Helper/Data.php +++ b/app/code/community/Phoenix/Moneybookers/Helper/Data.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Helper_Data extends Mage_Payment_Helper_Data diff --git a/app/code/community/Phoenix/Moneybookers/Model/Abstract.php b/app/code/community/Phoenix/Moneybookers/Model/Abstract.php index 7c743473a6..ad0e17df25 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Abstract.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Abstract.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ abstract class Phoenix_Moneybookers_Model_Abstract extends Mage_Payment_Model_Method_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Acc.php b/app/code/community/Phoenix/Moneybookers/Model/Acc.php index b64090508a..ab44942605 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Acc.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Acc.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Acc extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Csi.php b/app/code/community/Phoenix/Moneybookers/Model/Csi.php index cddcba0ac2..db54706ecd 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Csi.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Csi.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Csi extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Did.php b/app/code/community/Phoenix/Moneybookers/Model/Did.php index 206fc90b83..cb43754474 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Did.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Did.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Did extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Dnk.php b/app/code/community/Phoenix/Moneybookers/Model/Dnk.php index b33620f863..1a1c26dfcc 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Dnk.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Dnk.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Dnk extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Ebt.php b/app/code/community/Phoenix/Moneybookers/Model/Ebt.php index 45889004bb..d5e280d615 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Ebt.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Ebt.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Ebt extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Ent.php b/app/code/community/Phoenix/Moneybookers/Model/Ent.php index 78194fde60..106378cf1d 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Ent.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Ent.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Ent extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Event.php b/app/code/community/Phoenix/Moneybookers/Model/Event.php index 81409dc451..9743323fb2 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Event.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Event.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/community/Phoenix/Moneybookers/Model/Gcb.php b/app/code/community/Phoenix/Moneybookers/Model/Gcb.php index 4183784e2a..bc4738c776 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Gcb.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Gcb.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Gcb extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Gir.php b/app/code/community/Phoenix/Moneybookers/Model/Gir.php index 50f37338db..09ff3dd9a1 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Gir.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Gir.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Gir extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Idl.php b/app/code/community/Phoenix/Moneybookers/Model/Idl.php index 814bd2d813..24cea2d54f 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Idl.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Idl.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Idl extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Lsr.php b/app/code/community/Phoenix/Moneybookers/Model/Lsr.php index 4dfc398a95..89fc11abf5 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Lsr.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Lsr.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Lsr extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Mae.php b/app/code/community/Phoenix/Moneybookers/Model/Mae.php index 253f02d3fd..1cd0f88bc8 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Mae.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Mae.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Mae extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Npy.php b/app/code/community/Phoenix/Moneybookers/Model/Npy.php index bb88a37680..31ad5f2560 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Npy.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Npy.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Npy extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Obt.php b/app/code/community/Phoenix/Moneybookers/Model/Obt.php index f299d857f8..b943f1af22 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Obt.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Obt.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Obt extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Pli.php b/app/code/community/Phoenix/Moneybookers/Model/Pli.php index 4fcd40b7ef..4e886e2f56 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Pli.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Pli.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Pli extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Psp.php b/app/code/community/Phoenix/Moneybookers/Model/Psp.php index ebfac70309..97c11b6cdb 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Psp.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Psp.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Psp extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Pwy.php b/app/code/community/Phoenix/Moneybookers/Model/Pwy.php index 001d3832cc..e22178084a 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Pwy.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Pwy.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Pwy extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Sft.php b/app/code/community/Phoenix/Moneybookers/Model/Sft.php index 92776a4c08..aba1e73b66 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Sft.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Sft.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Sft extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/So2.php b/app/code/community/Phoenix/Moneybookers/Model/So2.php index 42a88d3afc..68dc7b7937 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/So2.php +++ b/app/code/community/Phoenix/Moneybookers/Model/So2.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_So2 extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/Model/Wlt.php b/app/code/community/Phoenix/Moneybookers/Model/Wlt.php index 1058f02c60..8ab8cd641f 100644 --- a/app/code/community/Phoenix/Moneybookers/Model/Wlt.php +++ b/app/code/community/Phoenix/Moneybookers/Model/Wlt.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_Model_Wlt extends Phoenix_Moneybookers_Model_Abstract diff --git a/app/code/community/Phoenix/Moneybookers/controllers/MoneybookersController.php b/app/code/community/Phoenix/Moneybookers/controllers/MoneybookersController.php index c54c2cebf9..b06db32c83 100644 --- a/app/code/community/Phoenix/Moneybookers/controllers/MoneybookersController.php +++ b/app/code/community/Phoenix/Moneybookers/controllers/MoneybookersController.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_MoneybookersController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/community/Phoenix/Moneybookers/controllers/ProcessingController.php b/app/code/community/Phoenix/Moneybookers/controllers/ProcessingController.php index 3342b023fa..2c060ebab4 100644 --- a/app/code/community/Phoenix/Moneybookers/controllers/ProcessingController.php +++ b/app/code/community/Phoenix/Moneybookers/controllers/ProcessingController.php @@ -14,7 +14,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Phoenix_Moneybookers_ProcessingController extends Mage_Core_Controller_Front_Action diff --git a/app/code/community/Phoenix/Moneybookers/etc/config.xml b/app/code/community/Phoenix/Moneybookers/etc/config.xml index b76a5e02e2..bbdd21d44e 100644 --- a/app/code/community/Phoenix/Moneybookers/etc/config.xml +++ b/app/code/community/Phoenix/Moneybookers/etc/config.xml @@ -15,14 +15,14 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> - 1.2.0.1 + 1.6.0.0 diff --git a/app/code/community/Phoenix/Moneybookers/etc/system.xml b/app/code/community/Phoenix/Moneybookers/etc/system.xml index 6247d9be10..97e8450b4a 100644 --- a/app/code/community/Phoenix/Moneybookers/etc/system.xml +++ b/app/code/community/Phoenix/Moneybookers/etc/system.xml @@ -15,7 +15,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> diff --git a/app/code/community/Phoenix/Moneybookers/sql/moneybookers_setup/install-1.6.0.0.php b/app/code/community/Phoenix/Moneybookers/sql/moneybookers_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..43b72a2c76 --- /dev/null +++ b/app/code/community/Phoenix/Moneybookers/sql/moneybookers_setup/install-1.6.0.0.php @@ -0,0 +1,22 @@ + */ -class Mage_Admin_Model_Acl_Role extends Varien_Object +class Mage_Admin_Model_Acl_Role extends Mage_Core_Model_Abstract { - + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('admin/acl_role'); + } } diff --git a/app/code/core/Mage/Admin/Model/Acl/Role/Generic.php b/app/code/core/Mage/Admin/Model/Acl/Role/Generic.php index cb91256d47..83b0d9f6b2 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Role/Generic.php +++ b/app/code/core/Mage/Admin/Model/Acl/Role/Generic.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/Model/Acl/Role/Group.php b/app/code/core/Mage/Admin/Model/Acl/Role/Group.php index 5250a9baf0..5bf94647c9 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Role/Group.php +++ b/app/code/core/Mage/Admin/Model/Acl/Role/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/Model/Acl/Role/Registry.php b/app/code/core/Mage/Admin/Model/Acl/Role/Registry.php index cd77a72499..e3e8f2086d 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Role/Registry.php +++ b/app/code/core/Mage/Admin/Model/Acl/Role/Registry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/Model/Acl/Role/User.php b/app/code/core/Mage/Admin/Model/Acl/Role/User.php index 319f420d5c..f68c266be4 100644 --- a/app/code/core/Mage/Admin/Model/Acl/Role/User.php +++ b/app/code/core/Mage/Admin/Model/Acl/Role/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/Model/Config.php b/app/code/core/Mage/Admin/Model/Config.php index 52d554688f..d5193a1a8c 100644 --- a/app/code/core/Mage/Admin/Model/Config.php +++ b/app/code/core/Mage/Admin/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -48,6 +48,7 @@ public function __construct() { parent::__construct(); $this->setCacheId('adminhtml_acl_menu_config'); + /* @var $adminhtmlConfig Varien_Simplexml_Config */ $adminhtmlConfig = Mage::app()->loadCache($this->getCacheId()); if ($adminhtmlConfig) { @@ -86,13 +87,13 @@ public function __construct() * @param string $parentName * @return Mage_Admin_Model_Config */ - public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource=null, $parentName=null) + public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource = null, $parentName = null) { if (is_null($resource)) { $resource = $this->getAdminhtmlConfig()->getNode("acl/resources"); $resourceName = null; } else { - $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName(); + $resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName(); $acl->add(Mage::getModel('admin/acl_resource', $resourceName), $parentName); } @@ -124,10 +125,10 @@ public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource=null, $par * @param string $name * @return Mage_Core_Model_Config_Element|boolean */ - public function getAclAssert($name='') + public function getAclAssert($name = '') { $asserts = $this->getNode("admin/acl/asserts"); - if (''===$name) { + if ('' === $name) { return $asserts; } @@ -144,10 +145,10 @@ public function getAclAssert($name='') * @param string $name * @return Mage_Core_Model_Config_Element|boolean */ - public function getAclPrivilegeSet($name='') + public function getAclPrivilegeSet($name = '') { $sets = $this->getNode("admin/acl/privilegeSets"); - if (''===$name) { + if ('' === $name) { return $sets; } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Acl.php b/app/code/core/Mage/Admin/Model/Mysql4/Acl.php index 82e71c10fd..5879e1a518 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Acl.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Acl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,145 +28,10 @@ /** * Resource model for admin ACL * - * @category Mage - * @package Mage_Admin + * @category Mage + * @package Mage_Admin * @author Magento Core Team */ -class Mage_Admin_Model_Mysql4_Acl +class Mage_Admin_Model_Mysql4_Acl extends Mage_Admin_Model_Resource_Acl { - const ACL_ALL_RULES = 'all'; - - /** - * Read resource connection - * - * @var mixed - */ - protected $_read; - - /** - * Write resource connection - * - * @var mixed - */ - protected $_write; - - /** - * Initialize resource connections - * - */ - function __construct() - { - $this->_read = Mage::getSingleton('core/resource')->getConnection('admin_read'); - $this->_write = Mage::getSingleton('core/resource')->getConnection('admin_write'); - } - - /** - * Load ACL for the user - * - * @param integer $userId - * @return Mage_Admin_Model_Acl - */ - function loadAcl() - { - $acl = Mage::getModel('admin/acl'); - - Mage::getSingleton('admin/config')->loadAclResources($acl); - - $roleTable = Mage::getSingleton('core/resource')->getTableName('admin/role'); - $rolesArr = $this->_read->fetchAll("select * from $roleTable order by tree_level"); - $this->loadRoles($acl, $rolesArr); - - $ruleTable = Mage::getSingleton('core/resource')->getTableName('admin/rule'); - $assertTable = Mage::getSingleton('core/resource')->getTableName('admin/assert'); - $rulesArr = $this->_read->fetchAll("select r.*, a.assert_type, a.assert_data - from $ruleTable r left join $assertTable a on a.assert_id=r.assert_id"); - $this->loadRules($acl, $rulesArr); - - return $acl; - } - - /** - * Load roles - * - * @param Mage_Admin_Model_Acl $acl - * @param array $rolesArr - * @return Mage_Admin_Model_Mysql4_Acl - */ - function loadRoles(Mage_Admin_Model_Acl $acl, array $rolesArr) - { - foreach ($rolesArr as $role) { - $parent = $role['parent_id']>0 ? Mage_Admin_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null; - switch ($role['role_type']) { - case Mage_Admin_Model_Acl::ROLE_TYPE_GROUP: - $roleId = $role['role_type'].$role['role_id']; - $acl->addRole(Mage::getModel('admin/acl_role_group', $roleId), $parent); - break; - - case Mage_Admin_Model_Acl::ROLE_TYPE_USER: - $roleId = $role['role_type'].$role['user_id']; - if (!$acl->hasRole($roleId)) { - $acl->addRole(Mage::getModel('admin/acl_role_user', $roleId), $parent); - } else { - $acl->addRoleParent($roleId, $parent); - } - break; - } - } - - return $this; - } - - /** - * Load rules - * - * @param Mage_Admin_Model_Acl $acl - * @param array $rulesArr - * @return Mage_Admin_Model_Mysql4_Acl - */ - function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr) - { - foreach ($rulesArr as $rule) { - $role = $rule['role_type'].$rule['role_id']; - $resource = $rule['resource_id']; - $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null; - - $assert = null; - if (0!=$rule['assert_id']) { - $assertClass = Mage::getSingleton('admin/config')->getAclAssert($rule['assert_type'])->getClassName(); - $assert = new $assertClass(unserialize($rule['assert_data'])); - } - try { - if ( $rule['permission'] == 'allow' ) { - if ($resource === self::ACL_ALL_RULES) { - $acl->allow($role, null, $privileges, $assert); - } - $acl->allow($role, $resource, $privileges, $assert); - } else if ( $rule['permission'] == 'deny' ) { - $acl->deny($role, $resource, $privileges, $assert); - } - } catch (Exception $e) { - //$m = $e->getMessage(); - //if ( eregi("^Resource '(.*)' not found", $m) ) { - // Deleting non existent resource rule from rules table - //$cond = $this->_write->quoteInto('resource_id = ?', $resource); - //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond); - //} else { - //TODO: We need to log such exceptions to somewhere like a system/errors.log - //} - } - /* - switch ($rule['permission']) { - case Mage_Admin_Model_Acl::RULE_PERM_ALLOW: - $acl->allow($role, $resource, $privileges, $assert); - break; - - case Mage_Admin_Model_Acl::RULE_PERM_DENY: - $acl->deny($role, $resource, $privileges, $assert); - break; - } - */ - } - return $this; - } - } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php b/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php index 68c7cbc667..f45698232e 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php @@ -20,66 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * ACL role resource * - * @category Mage - * @package Mage_Admin + * @category Mage + * @package Mage_Admin * @author Magento Core Team */ -class Mage_Admin_Model_Mysql4_Acl_Role +class Mage_Admin_Model_Mysql4_Acl_Role extends Mage_Admin_Model_Resource_Acl_Role { - protected $_roleTable; - protected $_read; - protected $_write; - - public function __construct() - { - $this->_roleTable = Mage::getSingleton('core/resource')->getTableName('admin/role'); - $this->_read = Mage::getSingleton('core/resource')->getConnection('admin_read'); - $this->_write = Mage::getSingleton('core/resource')->getConnection('admin_write'); - } - - public function load($roleId) - { - $select = $this->_read->select()->from($this->_roleTable) - ->where("role_id=?", $roleId); - return $this->_read->fetchRow($select); - } - - public function save(Mage_Admin_Model_Acl_Role $role) - { - $data = $role->getData(); - - $this->_write->beginTransaction(); - - try { - if ($role->getId()) { - $condition = $this->_write->quoteInto('role_id=?', $role->getRoleId()); - $this->_write->update($this->_roleTable, $data, $condition); - } else { - $data['created'] = now(); - $this->_write->insert($this->_roleTable, $data); - $role->setRoleId($this->_write->lastInsertId()); - } - - $this->_write->commit(); - } - catch (Mage_Core_Exception $e) - { - $this->_write->rollback(); - throw $e; - } - - return $role; - } - - public function delete() - { - - } } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php index 3c3ace0602..244ec77003 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Roles collection * - * @category Mage - * @package Mage_Admin + * @category Mage + * @package Mage_Admin * @author Magento Core Team */ -class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Varien_Data_Collection_Db +class Mage_Admin_Model_Mysql4_Acl_Role_Collection extends Mage_Admin_Model_Resource_Acl_Role_Collection { - protected $_roleTable; - - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('admin_read')); - $this->_roleTable = Mage::getSingleton('core/resource')->getTableName('admin/role'); - $this->_select->from($this->_roleTable); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('admin/acl_role')); - } } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php index 627824d818..cd8a2ad6d5 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Permissions_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * Permissions Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Permissions_Collection extends Mage_Admin_Model_Resource_Permissions_Collection { - protected function _construct() - { - $this->_init('admin/rules'); - } } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Role.php b/app/code/core/Mage/Admin/Model/Mysql4/Role.php index a0083331e5..b458598f41 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Role.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Role.php @@ -20,36 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Role extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('admin/role', 'role_id'); - } - - /** - * - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if ( !$object->getId() ) { - $object->setCreated(now()); - } - $object->setModified(now()); - return $this; - } - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (!intval($value) && is_string($value)) { - $field = 'role_id'; - } - return parent::load($object, $value, $field); - } +/** + * Mysql4 Role resource model + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Role extends Mage_Admin_Model_Resource_Role +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php index 386d4cb719..ee97b0ecaa 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php @@ -20,33 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Role_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('admin/role'); - } - - /** - * Enter description here... - * - * @param int $userId - * @return Mage_Admin_Model_Mysql4_Role_Collection - */ - public function setUserFilter($userId) - { - $this->addFieldToFilter('user_id', $userId); - $this->addFieldToFilter('role_type', 'G'); - return $this; - } - public function setRolesFilter() - { - $this->addFieldToFilter('role_type', 'G'); - return $this; - } +/** + * Role Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Role_Collection extends Mage_Admin_Model_Resource_Role_Collection +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Roles.php b/app/code/core/Mage/Admin/Model/Mysql4/Roles.php index 5c042fbb01..07e6770c66 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Roles.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Roles.php @@ -20,77 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Roles extends Mage_Core_Model_Mysql4_Abstract -{ - protected $_usersTable; - protected $_ruleTable; - - protected function _construct() { - $this->_init('admin/role', 'role_id'); - - $this->_usersTable = $this->getTable('admin/user'); - $this->_ruleTable = $this->getTable('admin/rule'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $role) - { - if ($role->getId() == '') { - if ($role->getIdFieldName()) { - $role->unsetData($role->getIdFieldName()); - } else { - $role->unsetData('id'); - } - } - - if ($role->getPid() > 0) { - $row = $this->load($role->getPid()); - } else { - $row = array('tree_level' => 0); - } - $role->setTreeLevel($row['tree_level'] + 1); - $role->setRoleName($role->getName()); - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $role) - { - $this->_updateRoleUsersAcl($role); - Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, - array(Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS)); - return $this; - } - - protected function _afterDelete(Mage_Core_Model_Abstract $role) - { - $this->_getWriteAdapter()->delete($this->getMainTable(), "parent_id={$role->getId()}"); - $this->_getWriteAdapter()->delete($this->_ruleTable, "role_id={$role->getId()}"); - return $this; - } - public function getRoleUsers(Mage_Admin_Model_Roles $role) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getMainTable(), array('user_id'))->where("(parent_id = '{$role->getId()}' AND role_type = 'U') AND user_id > 0"); - return $read->fetchCol($select); - } - - private function _updateRoleUsersAcl(Mage_Admin_Model_Roles $role) - { - $write = $this->_getWriteAdapter(); - $users = $this->getRoleUsers($role); - $rowsCount = 0; - if ( sizeof($users) > 0 ) { - $inStatement = implode(", ", $users); - $rowsCount = $write->update($this->_usersTable, array('reload_acl_flag' => 1), "user_id IN({$inStatement})"); - } - if ($rowsCount > 0) { - return true; - } else { - return false; - } - } +/** + * Mysql4 Roles resource model + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Roles extends Mage_Admin_Model_Resource_Roles +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php index 0a949ba5d2..db65520929 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php @@ -20,24 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Roles_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('admin/role'); - } - - protected function _initSelect(){ - parent::_initSelect(); - $this->getSelect()->where("main_table.role_type='G'"); - } - public function toOptionArray() - { - return $this->_toOptionArray('role_id', 'role_name'); - } +/** + * Roles Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Roles_Collection extends Mage_Admin_Model_Resource_Roles_Collection +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php index 63cb13dccd..10d325db45 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Roles_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('admin/user'); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->getSelect()->where("user_id > 0"); - } +/** + * Roles User Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Roles_User_Collection extends Mage_Admin_Model_Resource_Roles_User_Collection +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Rules.php b/app/code/core/Mage/Admin/Model/Mysql4/Rules.php index a0e94e0bcf..95752b0867 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Rules.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Rules.php @@ -20,57 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Rules extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() { - $this->_init('admin/rule', 'rule_id'); - } - - /** - * Save ACL resources - * - * @param Mage_Admin_Model_Rules $rule - */ - public function saveRel(Mage_Admin_Model_Rules $rule) - { - try { - $this->_getWriteAdapter()->beginTransaction(); - $roleId = $rule->getRoleId(); - $this->_getWriteAdapter()->delete($this->getMainTable(), "role_id = {$roleId}"); - $postedResources = $rule->getResources(); - if ($postedResources) { - $row = array( - 'role_type' => 'G', - 'resource_id' => 'all', - 'privileges' => '', // not used yet - 'assert_id' => 0, - 'role_id' => $roleId, - 'permission' => 'allow' - ); - - // If all was selected save it only and nothing else. - if ($postedResources === array('all')) { - $this->_getWriteAdapter()->insert($this->getMainTable(), $row); - } else { - foreach (Mage::getModel('admin/roles')->getResourcesList2D() as $index => $resName) { - $row['permission'] = (in_array($resName, $postedResources) ? 'allow' : 'deny'); - $row['resource_id'] = trim($resName, '/'); - $this->_getWriteAdapter()->insert($this->getMainTable(), $row); - } - } - } - $this->_getWriteAdapter()->commit(); - } catch (Mage_Core_Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } catch (Exception $e){ - $this->_getWriteAdapter()->rollBack(); - Mage::logException($e); - } - } +/** + * Mysql4 Rules Resource Model + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Rules extends Mage_Admin_Model_Resource_Rules +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php index 1b76a1f781..dedf318c8a 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_Rules_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('admin/rules'); - } - - public function getByRoles($id) - { - $this->getSelect()->where("role_id = ?", (int)$id); - return $this; - } - public function addSortByLength() - { - $this->getSelect()->columns(array('length' => 'LENGTH(resource_id)')) - ->order('length desc'); - return $this; - } +/** + * Mysql4 Rules Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_Rules_Collection extends Mage_Admin_Model_Resource_Rules_Collection +{ } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/User.php b/app/code/core/Mage/Admin/Model/Mysql4/User.php index ec83b8aab9..32ee3d99d4 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/User.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/User.php @@ -20,282 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * ACL user resource * - * @category Mage - * @package Mage_Admin + * @category Mage + * @package Mage_Admin * @author Magento Core Team */ -class Mage_Admin_Model_Mysql4_User extends Mage_Core_Model_Mysql4_Abstract +class Mage_Admin_Model_Mysql4_User extends Mage_Admin_Model_Resource_User { - - protected function _construct() - { - $this->_init('admin/user', 'user_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array( - array( - 'field' => 'email', - 'title' => Mage::helper('adminhtml')->__('Email') - ), - array( - 'field' => 'username', - 'title' => Mage::helper('adminhtml')->__('User Name') - ), - ); - return $this; - } - - /** - * Authenticate user by $username and $password - * - * @param string $username - * @param string $password - * @return boolean|Object - */ - public function recordLogin(Mage_Admin_Model_User $user) - { - $data = array( - 'logdate' => now(), - 'lognum' => $user->getLognum()+1 - ); - $condition = $this->_getWriteAdapter()->quoteInto('user_id=?', $user->getUserId()); - $this->_getWriteAdapter()->update($this->getTable('admin/user'), $data, $condition); - return $this; - } - - public function loadByUsername($username) - { - $select = $this->_getReadAdapter()->select()->from($this->getTable('admin/user')) - ->where('username=:username'); - return $this->_getReadAdapter()->fetchRow($select, array('username'=>$username)); - } - - public function hasAssigned2Role($user) - { - if (is_numeric($user)) { - $userId = $user; - } else if ($user instanceof Mage_Core_Model_Abstract) { - $userId = $user->getUserId(); - } else { - return null; - } - - if ( $userId > 0 ) { - $dbh = $this->_getReadAdapter(); - $select = $dbh->select(); - $select->from($this->getTable('admin/role')) - ->where("parent_id > 0 AND user_id = {$userId}"); - return $dbh->fetchAll($select); - } else { - return null; - } - } - - private function _encryptPassword($pwStr) - { - return Mage::helper('core')->getHash($pwStr, 2); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $user) - { - if (!$user->getId()) { - $user->setCreated(now()); - } - $user->setModified(now()); - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $user) - { - $user->setExtra(unserialize($user->getExtra())); - return $this; - } - - protected function _afterLoad(Mage_Core_Model_Abstract $user) - { - if (is_string($user->getExtra())) { - $user->setExtra(unserialize($user->getExtra())); - } - return parent::_afterLoad($user); - } - - public function load(Mage_Core_Model_Abstract $user, $value, $field=null) - { -// if (!intval($value) && is_string($value)) { -// $field = 'user_id'; -// } - return parent::load($user, $value, $field); - } - - public function delete(Mage_Core_Model_Abstract $user) - { - $dbh = $this->_getWriteAdapter(); - $uid = $user->getId(); - $dbh->beginTransaction(); - try { - $dbh->delete($this->getTable('admin/user'), "user_id=$uid"); - $dbh->delete($this->getTable('admin/role'), "user_id=$uid"); - } catch (Mage_Core_Exception $e) { - throw $e; - return false; - } catch (Exception $e){ - $dbh->rollBack(); - return false; - } - $dbh->commit(); - return true; - } - - /** - * TODO: unify _saveRelations() and add() methods, they make same things - */ - public function _saveRelations(Mage_Core_Model_Abstract $user) - { - $rolesIds = $user->getRoleIds(); - - if( !is_array($rolesIds) || count($rolesIds) == 0 ) { - return $user; - } - - $this->_getWriteAdapter()->beginTransaction(); - - try { - $this->_getWriteAdapter()->delete($this->getTable('admin/role'), "user_id = {$user->getId()}"); - foreach ($rolesIds as $rid) { - $rid = intval($rid); - if ($rid > 0) { - $row = Mage::getModel('admin/role')->load($rid)->getData(); - } else { - $row = array('tree_level' => 0); - } - - $data = array( - 'parent_id' => $rid, - 'tree_level' => $row['tree_level'] + 1, - 'sort_order' => 0, - 'role_type' => 'U', - 'user_id' => $user->getId(), - 'role_name' => $user->getFirstname() - ); - $this->_getWriteAdapter()->insert($this->getTable('admin/role'), $data); - } - $this->_getWriteAdapter()->commit(); - } catch (Mage_Core_Exception $e) { - throw $e; - } catch (Exception $e){ - $this->_getWriteAdapter()->rollBack(); - } - } - - public function getRoles(Mage_Core_Model_Abstract $user) - { - if ( !$user->getId() ) { - return array(); - } - $table = $this->getTable('admin/role'); - $read = $this->_getReadAdapter(); - $select = $read->select()->from($table, array()) - ->joinLeft(array('ar' => $table), - "(ar.role_id = `{$table}`.parent_id and ar.role_type = 'G')", - array('role_id')) - ->where("`{$table}`.user_id = {$user->getId()}"); - - return (($roles = $read->fetchCol($select)) ? $roles : array()); - } - - public function add(Mage_Core_Model_Abstract $user) - { - $dbh = $this->_getWriteAdapter(); - - $aRoles = $this->hasAssigned2Role($user); - if ( sizeof($aRoles) > 0 ) { - foreach($aRoles as $idx => $data){ - $dbh->delete($this->getTable('admin/role'), "role_id = {$data['role_id']}"); - } - } - - if ($user->getId() > 0) { - $role = Mage::getModel('admin/role')->load($user->getRoleId()); - } else { - $role = new Varien_Object(); - $role->setTreeLevel(0); - } - $dbh->insert($this->getTable('admin/role'), array( - 'parent_id' => $user->getRoleId(), - 'tree_level'=> ($role->getTreeLevel() + 1), - 'sort_order'=> 0, - 'role_type' => 'U', - 'user_id' => $user->getUserId(), - 'role_name' => $user->getFirstname() - )); - - return $this; - } - - public function deleteFromRole(Mage_Core_Model_Abstract $user) - { - if ( $user->getUserId() <= 0 ) { - return $this; - } - if ( $user->getRoleId() <= 0 ) { - return $this; - } - $dbh = $this->_getWriteAdapter(); - $condition = "`{$this->getTable('admin/role')}`.user_id = " . $dbh->quote($user->getUserId()) - . " AND `{$this->getTable('admin/role')}`.parent_id = " . $dbh->quote($user->getRoleId()); - $dbh->delete($this->getTable('admin/role'), $condition); - return $this; - } - - public function roleUserExists(Mage_Core_Model_Abstract $user) - { - if ( $user->getUserId() > 0 ) { - $roleTable = $this->getTable('admin/role'); - $dbh = $this->_getReadAdapter(); - $select = $dbh->select()->from($roleTable) - ->where("parent_id = {$user->getRoleId()} AND user_id = {$user->getUserId()}"); - return $dbh->fetchCol($select); - } else { - return array(); - } - } - - public function userExists(Mage_Core_Model_Abstract $user) - { - $usersTable = $this->getTable('admin/user'); - $db = $this->_getReadAdapter(); - - $select = $db->select() - ->from(array('u' => $usersTable)) - ->where('u.user_id != ?', (int) $user->getId()) - ->where('u.username = :username OR u.email = :email') - ; - $row = $db->fetchRow($select, array( - ':username' => $user->getUsername(), - ':email' => $user->getUsername(), - )); - return $row; - } - - public function saveExtra($object, $data) - { - if ($object->getId()) { - $this->_getWriteAdapter()->update($this->getMainTable(), array('extra'=>$data)); - } - return $this; - } } diff --git a/app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php b/app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php index b39f1a91f1..c791593fc9 100644 --- a/app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php +++ b/app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Admin_Model_Mysql4_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * Admin Mysql4 User Collection + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ +class Mage_Admin_Model_Mysql4_User_Collection extends Mage_Admin_Model_Resource_User_Collection { - protected function _construct() - { - $this->_init('admin/user'); - } } diff --git a/app/code/core/Mage/Admin/Model/Observer.php b/app/code/core/Mage/Admin/Model/Observer.php index 1644cb358e..ebc30aa242 100644 --- a/app/code/core/Mage/Admin/Model/Observer.php +++ b/app/code/core/Mage/Admin/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/Model/Resource/Acl.php b/app/code/core/Mage/Admin/Model/Resource/Acl.php new file mode 100755 index 0000000000..740ac5c9f5 --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Acl.php @@ -0,0 +1,171 @@ + + */ +class Mage_Admin_Model_Resource_Acl extends Mage_Core_Model_Resource_Db_Abstract +{ + const ACL_ALL_RULES = 'all'; + + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('admin/role', 'role_id'); + } + + /** + * Load ACL for the user + * + * @return Mage_Admin_Model_Acl + */ + public function loadAcl() + { + $acl = Mage::getModel('admin/acl'); + + Mage::getSingleton('admin/config')->loadAclResources($acl); + + $roleTable = $this->getTable('admin/role'); + $ruleTable = $this->getTable('admin/rule'); + $assertTable = $this->getTable('admin/assert'); + + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($roleTable) + ->order('tree_level'); + + $rolesArr = $adapter->fetchAll($select); + + $this->loadRoles($acl, $rolesArr); + + $select = $adapter->select() + ->from(array('r' => $ruleTable)) + ->joinLeft( + array('a' => $assertTable), + 'a.assert_id = r.assert_id', + array('assert_type', 'assert_data') + ); + + $rulesArr = $adapter->fetchAll($select); + + $this->loadRules($acl, $rulesArr); + + return $acl; + } + + /** + * Load roles + * + * @param Mage_Admin_Model_Acl $acl + * @param array $rolesArr + * @return Mage_Admin_Model_Resource_Acl + */ + public function loadRoles(Mage_Admin_Model_Acl $acl, array $rolesArr) + { + foreach ($rolesArr as $role) { + $parent = ($role['parent_id'] > 0) ? Mage_Admin_Model_Acl::ROLE_TYPE_GROUP . $role['parent_id'] : null; + switch ($role['role_type']) { + case Mage_Admin_Model_Acl::ROLE_TYPE_GROUP: + $roleId = $role['role_type'] . $role['role_id']; + $acl->addRole(Mage::getModel('admin/acl_role_group', $roleId), $parent); + break; + + case Mage_Admin_Model_Acl::ROLE_TYPE_USER: + $roleId = $role['role_type'] . $role['user_id']; + if (!$acl->hasRole($roleId)) { + $acl->addRole(Mage::getModel('admin/acl_role_user', $roleId), $parent); + } else { + $acl->addRoleParent($roleId, $parent); + } + break; + } + } + + return $this; + } + + /** + * Load rules + * + * @param Mage_Admin_Model_Acl $acl + * @param array $rulesArr + * @return Mage_Admin_Model_Resource_Acl + */ + public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr) + { + foreach ($rulesArr as $rule) { + $role = $rule['role_type'] . $rule['role_id']; + $resource = $rule['resource_id']; + $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null; + + $assert = null; + if (0 != $rule['assert_id']) { + $assertClass = Mage::getSingleton('admin/config')->getAclAssert($rule['assert_type'])->getClassName(); + $assert = new $assertClass(unserialize($rule['assert_data'])); + } + try { + if ( $rule['permission'] == 'allow' ) { + if ($resource === self::ACL_ALL_RULES) { + $acl->allow($role, null, $privileges, $assert); + } + $acl->allow($role, $resource, $privileges, $assert); + } else if ( $rule['permission'] == 'deny' ) { + $acl->deny($role, $resource, $privileges, $assert); + } + } catch (Exception $e) { + //$m = $e->getMessage(); + //if ( eregi("^Resource '(.*)' not found", $m) ) { + // Deleting non existent resource rule from rules table + //$cond = $this->_write->quoteInto('resource_id = ?', $resource); + //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond); + //} else { + //TODO: We need to log such exceptions to somewhere like a system/errors.log + //} + } + /* + switch ($rule['permission']) { + case Mage_Admin_Model_Acl::RULE_PERM_ALLOW: + $acl->allow($role, $resource, $privileges, $assert); + break; + + case Mage_Admin_Model_Acl::RULE_PERM_DENY: + $acl->deny($role, $resource, $privileges, $assert); + break; + } + */ + } + return $this; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Acl/Role.php b/app/code/core/Mage/Admin/Model/Resource/Acl/Role.php new file mode 100755 index 0000000000..4684803e38 --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Acl/Role.php @@ -0,0 +1,45 @@ + + */ +class Mage_Admin_Model_Resource_Acl_Role extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('admin/role', 'role_id'); + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Acl/Role/Collection.php b/app/code/core/Mage/Admin/Model/Resource/Acl/Role/Collection.php new file mode 100755 index 0000000000..5840d02fcd --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Acl/Role/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Admin_Model_Resource_Acl_Role_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('admin/acl_role'); + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Permissions/Collection.php b/app/code/core/Mage/Admin/Model/Resource/Permissions/Collection.php new file mode 100755 index 0000000000..c06a0c8f5c --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Permissions/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Admin_Model_Resource_Permissions_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('admin/rules'); + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Role.php b/app/code/core/Mage/Admin/Model/Resource/Role.php new file mode 100755 index 0000000000..4fe72a8fbf --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Role.php @@ -0,0 +1,60 @@ + + */ +class Mage_Admin_Model_Resource_Role extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('admin/role', 'role_id'); + } + + /** + * Process role before saving + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Admin_Model_Resource_Role + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if ( !$object->getId() ) { + $object->setCreated($this->formatDate(true)); + } + $object->setModified($this->formatDate(true)); + return $this; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Role/Collection.php b/app/code/core/Mage/Admin/Model/Resource/Role/Collection.php new file mode 100755 index 0000000000..457428c9e1 --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Role/Collection.php @@ -0,0 +1,69 @@ + + */ +class Mage_Admin_Model_Resource_Role_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('admin/role'); + } + + /** + * Add user filter + * + * @param int $userId + * @return Mage_Admin_Model_Resource_Role_Collection + */ + public function setUserFilter($userId) + { + $this->addFieldToFilter('user_id', $userId); + $this->addFieldToFilter('role_type', 'G'); + return $this; + } + + /** + * Set roles filter + * + * @return Mage_Admin_Model_Resource_Role_Collection + */ + public function setRolesFilter() + { + $this->addFieldToFilter('role_type', 'G'); + return $this; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Roles.php b/app/code/core/Mage/Admin/Model/Resource/Roles.php new file mode 100755 index 0000000000..d30599f4af --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Roles.php @@ -0,0 +1,178 @@ + + */ +class Mage_Admin_Model_Resource_Roles extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Users table + * + * @var string + */ + protected $_usersTable; + + /** + * Rule table + * + * @var string + */ + protected $_ruleTable; + + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('admin/role', 'role_id'); + + $this->_usersTable = $this->getTable('admin/user'); + $this->_ruleTable = $this->getTable('admin/rule'); + } + + /** + * Process role before saving + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Admin_Model_Resource_Roles + */ + protected function _beforeSave(Mage_Core_Model_Abstract $role) + { + if ($role->getId() == '') { + if ($role->getIdFieldName()) { + $role->unsetData($role->getIdFieldName()); + } else { + $role->unsetData('id'); + } + } + + if ($role->getPid() > 0) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('tree_level')) + ->where("{$this->getIdFieldName()} = :pid"); + + $binds = array( + 'pid' => (int) $role->getPid(), + ); + + $treeLevel = $this->_getReadAdapter()->fetchOne($select, $binds); + } else { + $treeLevel = 0; + } + $role->setTreeLevel($treeLevel + 1); + $role->setRoleName($role->getName()); + return $this; + } + + /** + * Process role after saving + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Admin_Model_Resource_Roles + */ + protected function _afterSave(Mage_Core_Model_Abstract $role) + { + $this->_updateRoleUsersAcl($role); + Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, + array(Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS)); + return $this; + } + + /** + * Process role after deleting + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Admin_Model_Resource_Roles + */ + protected function _afterDelete(Mage_Core_Model_Abstract $role) + { + $adapter = $this->_getWriteAdapter(); + + $adapter->delete( + $this->getMainTable(), + array('parent_id = ?' => (int) $role->getId()) + ); + + $adapter->delete( + $this->_ruleTable, + array('role_id = ?' => (int) $role->getId()) + ); + + return $this; + } + + /** + * Get role users + * + * @param Mage_Admin_Model_Roles $role + * @return array|false + */ + public function getRoleUsers(Mage_Admin_Model_Roles $role) + { + $read = $this->_getReadAdapter(); + + $binds = array( + 'role_id' => $role->getId(), + 'role_type' => 'U' + ); + + $select = $read->select() + ->from($this->getMainTable(), array('user_id')) + ->where('parent_id = :role_id') + ->where('role_type = :role_type') + ->where('user_id > 0'); + + return $read->fetchCol($select, $binds); + } + + /** + * Update role users ACL + * + * @param Mage_Admin_Model_Roles $role + * @return bool + */ + private function _updateRoleUsersAcl(Mage_Admin_Model_Roles $role) + { + $write = $this->_getWriteAdapter(); + $users = $this->getRoleUsers($role); + $rowsCount = 0; + + if (sizeof($users) > 0) { + $bind = array('reload_acl_flag' => 1); + $where = array('user_id IN(?)' => $users); + $rowsCount = $write->update($this->_usersTable, $bind, $where); + } + + return $rowsCount > 0; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Roles/Collection.php b/app/code/core/Mage/Admin/Model/Resource/Roles/Collection.php new file mode 100755 index 0000000000..9d0b9631e9 --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Roles/Collection.php @@ -0,0 +1,69 @@ + + */ +class Mage_Admin_Model_Resource_Roles_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('admin/role'); + } + + /** + * Init select + * + * @return Mage_Admin_Model_Resource_Roles_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + + $this->getSelect()->where("main_table.role_type = ?", 'G'); + + return $this; + } + + /** + * Convert to option array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('role_id', 'role_name'); + } +} diff --git a/app/code/core/Mage/Core/Model/Convert/History.php b/app/code/core/Mage/Admin/Model/Resource/Roles/User/Collection.php old mode 100644 new mode 100755 similarity index 61% rename from app/code/core/Mage/Core/Model/Convert/History.php rename to app/code/core/Mage/Admin/Model/Resource/Roles/User/Collection.php index f1c14589ea..a0b43938ee --- a/app/code/core/Mage/Core/Model/Convert/History.php +++ b/app/code/core/Mage/Admin/Model/Resource/Roles/User/Collection.php @@ -19,36 +19,41 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Admin + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Convert history + * Admin role users collection * + * @category Mage + * @package Mage_Admin * @author Magento Core Team */ -class Mage_Core_Model_Convert_History extends Mage_Core_Model_Abstract +class Mage_Admin_Model_Resource_Roles_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { + /** + * Initialize resource model + * + */ protected function _construct() { - $this->_init('core/convert_history'); + $this->_init('admin/user'); } - protected function _beforeSave() + /** + * Initialize select + * + * @return Mage_Admin_Model_Resource_Roles_User_Collection + */ + protected function _initSelect() { - if (!$this->getProfileId()) { - $profile = Mage::registry('current_convert_profile'); - if ($profile) { - $this->setProfileId($profile->getId()); - } - } - if (!$this->getUserId()) { - $this->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); - } + parent::_initSelect(); + + $this->getSelect()->where("user_id > 0"); - parent::_beforeSave(); return $this; } } diff --git a/app/code/core/Mage/Admin/Model/Resource/Rules.php b/app/code/core/Mage/Admin/Model/Resource/Rules.php new file mode 100755 index 0000000000..5947cb88ab --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Rules.php @@ -0,0 +1,100 @@ + + */ +class Mage_Admin_Model_Resource_Rules extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('admin/rule', 'rule_id'); + } + + /** + * Save ACL resources + * + * @param Mage_Admin_Model_Rules $rule + */ + public function saveRel(Mage_Admin_Model_Rules $rule) + { + try { + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + $roleId = $rule->getRoleId(); + + $condition = array( + 'role_id = ?' => (int) $roleId, + ); + + $adapter->delete($this->getMainTable(), $condition); + + $postedResources = $rule->getResources(); + if ($postedResources) { + $row = array( + 'role_type' => 'G', + 'resource_id' => 'all', + 'privileges' => '', // not used yet + 'assert_id' => 0, + 'role_id' => $roleId, + 'permission' => 'allow' + ); + + // If all was selected save it only and nothing else. + if ($postedResources === array('all')) { + $insertData = $this->_prepareDataForTable(new Varien_Object($row), $this->getMainTable()); + + $adapter->insert($this->getMainTable(), $insertData); + } else { + foreach (Mage::getModel('admin/roles')->getResourcesList2D() as $index => $resName) { + $row['permission'] = (in_array($resName, $postedResources) ? 'allow' : 'deny'); + $row['resource_id'] = trim($resName, '/'); + + $insertData = $this->_prepareDataForTable(new Varien_Object($row), $this->getMainTable()); + $adapter->insert($this->getMainTable(), $insertData); + } + } + } + + $adapter->commit(); + } catch (Mage_Core_Exception $e) { + $adapter->rollBack(); + throw $e; + } catch (Exception $e){ + $adapter->rollBack(); + Mage::logException($e); + } + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/Rules/Collection.php b/app/code/core/Mage/Admin/Model/Resource/Rules/Collection.php new file mode 100755 index 0000000000..cc97e15e0f --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/Rules/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Admin_Model_Resource_Rules_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('admin/rules'); + } + + /** + * Get rules by role id + * + * @param int $id + * @return Mage_Admin_Model_Resource_Rules_Collection + */ + public function getByRoles($id) + { + $this->addFieldToFilter('role_id', (int) $id); + return $this; + } + + /** + * Sort by length + * + * @return Mage_Admin_Model_Resource_Rules_Collection + */ + public function addSortByLength() + { + $length = $this->getConnection()->getLengthSql('{{resource_id}}'); + $this->addExpressionFieldToSelect('length', $length, 'resource_id'); + $this->getSelect()->order('length ' . Zend_Db_Select::SQL_DESC); + + return $this; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/User.php b/app/code/core/Mage/Admin/Model/Resource/User.php new file mode 100755 index 0000000000..36164a1902 --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/User.php @@ -0,0 +1,463 @@ + + */ +class Mage_Admin_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('admin/user', 'user_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Admin_Model_Resource_User + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array( + array( + 'field' => 'email', + 'title' => Mage::helper('adminhtml')->__('Email') + ), + array( + 'field' => 'username', + 'title' => Mage::helper('adminhtml')->__('User Name') + ), + ); + return $this; + } + + /** + * Authenticate user by $username and $password + * + * @param Mage_Admin_Model_User $user + * @return Mage_Admin_Model_Resource_User + */ + public function recordLogin(Mage_Admin_Model_User $user) + { + $adapter = $this->_getWriteAdapter(); + + $data = array( + 'logdate' => now(), + 'lognum' => $user->getLognum() + 1 + ); + + $condition = array( + 'user_id = ?' => (int) $user->getUserId(), + ); + + $adapter->update($this->getMainTable(), $data, $condition); + + return $this; + } + + /** + * Load data by specified username + * + * @param string $username + * @return false|array + */ + public function loadByUsername($username) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('username=:username'); + + $binds = array( + 'username' => $username + ); + + return $adapter->fetchRow($select, $binds); + } + + /** + * Check if user is assigned to any role + * + * @param int|Mage_Core_Admin_Model_User $user + * @return null|false|array + */ + public function hasAssigned2Role($user) + { + if (is_numeric($user)) { + $userId = $user; + } else if ($user instanceof Mage_Core_Model_Abstract) { + $userId = $user->getUserId(); + } else { + return null; + } + + if ( $userId > 0 ) { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select(); + $select->from($this->getTable('admin/role')) + ->where('parent_id > :parent_id') + ->where('user_id = :user_id'); + + $binds = array( + 'parent_id' => 0, + 'user_id' => $userId, + ); + + return $adapter->fetchAll($select, $binds); + } else { + return null; + } + } + + /** + * Encrypt password + * + * @param string $pwStr + * @return string + */ + private function _encryptPassword($pwStr) + { + return Mage::helper('core')->getHash($pwStr, 2); + } + + /** + * Set created/modified values before user save + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + protected function _beforeSave(Mage_Core_Model_Abstract $user) + { + if ($user->isObjectNew()) { + $user->setCreated($this->formatDate(true)); + } + $user->setModified($this->formatDate(true)); + + return parent::_beforeSave($user); + } + + /** + * Unserialize user extra data after user save + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + protected function _afterSave(Mage_Core_Model_Abstract $user) + { + $user->setExtra(unserialize($user->getExtra())); + return $this; + } + + /** + * Unserialize user extra data after user load + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + protected function _afterLoad(Mage_Core_Model_Abstract $user) + { + if (is_string($user->getExtra())) { + $user->setExtra(unserialize($user->getExtra())); + } + return parent::_afterLoad($user); + } + + /** + * Delete user role record with user + * + * @param Mage_Core_Model_Abstract $user + * @return bool + */ + public function delete(Mage_Core_Model_Abstract $user) + { + $this->_beforeDelete($user); + $adapter = $this->_getWriteAdapter(); + + $uid = $user->getId(); + $adapter->beginTransaction(); + try { + $conditions = array( + 'user_id = ?' => $uid + ); + + $adapter->delete($this->getMainTable(), $conditions); + $adapter->delete($this->getTable('admin/role'), $conditions); + } catch (Mage_Core_Exception $e) { + throw $e; + return false; + } catch (Exception $e){ + $adapter->rollBack(); + return false; + } + $adapter->commit(); + $this->_afterDelete($user); + return true; + } + + /** + * TODO: unify _saveRelations() and add() methods, they make same things + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + public function _saveRelations(Mage_Core_Model_Abstract $user) + { + $rolesIds = $user->getRoleIds(); + + if( !is_array($rolesIds) || count($rolesIds) == 0 ) { + return $user; + } + + $adapter = $this->_getWriteAdapter(); + + $adapter->beginTransaction(); + + try { + $conditions = array( + 'user_id = ?' => (int) $user->getId(), + ); + + $adapter->delete($this->getTable('admin/role'), $conditions); + foreach ($rolesIds as $rid) { + $rid = intval($rid); + if ($rid > 0) { + $row = Mage::getModel('admin/role')->load($rid)->getData(); + } else { + $row = array('tree_level' => 0); + } + + $data = new Varien_Object(array( + 'parent_id' => $rid, + 'tree_level' => $row['tree_level'] + 1, + 'sort_order' => 0, + 'role_type' => 'U', + 'user_id' => $user->getId(), + 'role_name' => $user->getFirstname() + )); + + $insertData = $this->_prepareDataForTable($data, $this->getTable('admin/role')); + $adapter->insert($this->getTable('admin/role'), $insertData); + } + $adapter->commit(); + } catch (Mage_Core_Exception $e) { + throw $e; + } catch (Exception $e){ + $adapter->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Get user roles + * + * @param Mage_Core_Model_Abstract $user + * @return array + */ + public function getRoles(Mage_Core_Model_Abstract $user) + { + if ( !$user->getId() ) { + return array(); + } + + $table = $this->getTable('admin/role'); + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($table, array()) + ->joinLeft( + array('ar' => $table), + "(ar.role_id = {$table}.parent_id and ar.role_type = 'G')", + array('role_id')) + ->where("{$table}.user_id = :user_id"); + + $binds = array( + 'user_id' => (int) $user->getId(), + ); + + $roles = $adapter->fetchCol($select, $binds); + + if ($roles) { + return $roles; + } + + return array(); + } + + /** + * Save user roles + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + public function add(Mage_Core_Model_Abstract $user) + { + $dbh = $this->_getWriteAdapter(); + + $aRoles = $this->hasAssigned2Role($user); + if ( sizeof($aRoles) > 0 ) { + foreach($aRoles as $idx => $data){ + $conditions = array( + 'role_id = ?' => $data['role_id'], + ); + + $dbh->delete($this->getTable('admin/role'), $conditions); + } + } + + if ($user->getId() > 0) { + $role = Mage::getModel('admin/role')->load($user->getRoleId()); + } else { + $role = new Varien_Object(); + $role->setTreeLevel(0); + } + + $data = new Varien_Object(array( + 'parent_id' => $user->getRoleId(), + 'tree_level' => ($role->getTreeLevel() + 1), + 'sort_order' => 0, + 'role_type' => 'U', + 'user_id' => $user->getUserId(), + 'role_name' => $user->getFirstname() + )); + + $insertData = $this->_prepareDataForTable($data, $this->getTable('admin/role')); + + $dbh->insert($this->getTable('admin/role'), $insertData); + + return $this; + } + + /** + * Delete user role + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Admin_Model_Resource_User + */ + public function deleteFromRole(Mage_Core_Model_Abstract $user) + { + if ( $user->getUserId() <= 0 ) { + return $this; + } + if ( $user->getRoleId() <= 0 ) { + return $this; + } + + $dbh = $this->_getWriteAdapter(); + + $condition = array( + 'user_id = ?' => (int) $user->getId(), + 'parent_id = ?' => (int) $user->getRoleId(), + ); + + $dbh->delete($this->getTable('admin/role'), $condition); + return $this; + } + + /** + * Check if role user exists + * + * @param Mage_Core_Model_Abstract $user + * @return array|false + */ + public function roleUserExists(Mage_Core_Model_Abstract $user) + { + if ( $user->getUserId() > 0 ) { + $roleTable = $this->getTable('admin/role'); + + $dbh = $this->_getReadAdapter(); + + $binds = array( + 'parent_id' => $user->getRoleId(), + 'user_id' => $user->getUserId(), + ); + + $select = $dbh->select()->from($roleTable) + ->where('parent_id = :parent_id') + ->where('user_id = :user_id'); + + return $dbh->fetchCol($select, $binds); + } else { + return array(); + } + } + + /** + * Check if user exists + * + * @param Mage_Core_Model_Abstract $user + * @return array|false + */ + public function userExists(Mage_Core_Model_Abstract $user) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select(); + + $binds = array( + 'username' => $user->getUsername(), + 'email' => $user->getEmail(), + 'user_id' => (int) $user->getId(), + ); + + $select->from($this->getMainTable()) + ->where('(username = :username OR email = :email)') + ->where('user_id <> :user_id'); + + return $adapter->fetchRow($select, $binds); + } + + /** + * Save user extra data + * + * @param Mage_Core_Model_Abstract $object + * @param string $data + * @return Mage_Admin_Model_Resource_User + */ + public function saveExtra($object, $data) + { + if ($object->getId()) { + $this->_getWriteAdapter()->update( + $this->getMainTable(), + array('extra' => $data), + array('user_id = ?' => (int) $object->getId()) + ); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Admin/Model/Resource/User/Collection.php b/app/code/core/Mage/Admin/Model/Resource/User/Collection.php new file mode 100755 index 0000000000..b8a9ae468d --- /dev/null +++ b/app/code/core/Mage/Admin/Model/Resource/User/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Admin_Model_Resource_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('admin/user'); + } +} diff --git a/app/code/core/Mage/Admin/Model/Role.php b/app/code/core/Mage/Admin/Model/Role.php index 81351b013e..982e74c6cd 100644 --- a/app/code/core/Mage/Admin/Model/Role.php +++ b/app/code/core/Mage/Admin/Model/Role.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Admin Role Model + * + * @method Mage_Admin_Model_Resource_Role _getResource() + * @method Mage_Admin_Model_Resource_Role getResource() + * @method int getParentId() + * @method Mage_Admin_Model_Role setParentId(int $value) + * @method int getTreeLevel() + * @method Mage_Admin_Model_Role setTreeLevel(int $value) + * @method int getSortOrder() + * @method Mage_Admin_Model_Role setSortOrder(int $value) + * @method string getRoleType() + * @method Mage_Admin_Model_Role setRoleType(string $value) + * @method int getUserId() + * @method Mage_Admin_Model_Role setUserId(int $value) + * @method string getRoleName() + * @method Mage_Admin_Model_Role setRoleName(string $value) + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ class Mage_Admin_Model_Role extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Admin/Model/Roles.php b/app/code/core/Mage/Admin/Model/Roles.php index b6d2c29d0b..0d5db92e88 100644 --- a/app/code/core/Mage/Admin/Model/Roles.php +++ b/app/code/core/Mage/Admin/Model/Roles.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Admin Roles Model + * + * @method Mage_Admin_Model_Resource_Roles _getResource() + * @method Mage_Admin_Model_Resource_Roles getResource() + * @method int getParentId() + * @method Mage_Admin_Model_Roles setParentId(int $value) + * @method int getTreeLevel() + * @method Mage_Admin_Model_Roles setTreeLevel(int $value) + * @method int getSortOrder() + * @method Mage_Admin_Model_Roles setSortOrder(int $value) + * @method string getRoleType() + * @method Mage_Admin_Model_Roles setRoleType(string $value) + * @method int getUserId() + * @method Mage_Admin_Model_Roles setUserId(int $value) + * @method string getRoleName() + * @method Mage_Admin_Model_Roles setRoleName(string $value) + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ class Mage_Admin_Model_Roles extends Mage_Core_Model_Abstract { /** @@ -67,7 +89,8 @@ public function getRoleUsers() return $this->getResource()->getRoleUsers($this); } - protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, $parentName=null, $level=0, $represent2Darray=null, $rawNodes = false, $module = 'adminhtml') + protected function _buildResourcesArray(Varien_Simplexml_Element $resource = null, + $parentName = null, $level = 0, $represent2Darray = null, $rawNodes = false, $module = 'adminhtml') { static $result; if (is_null($resource)) { @@ -76,8 +99,8 @@ protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, $level = -1; } else { $resourceName = $parentName; - if ($resource->getName()!='title' && $resource->getName()!='sort_order' && $resource->getName() != 'children') { - $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName(); + if ($resource->getName() != 'title' && $resource->getName() != 'sort_order' && $resource->getName() != 'children') { + $resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName(); //assigning module for its' children nodes if ($resource->getAttribute('module')) { @@ -107,7 +130,7 @@ protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, } } foreach ($children as $child) { - $this->_buildResourcesArray($child, $resourceName, $level+1, $represent2Darray, $rawNodes, $module); + $this->_buildResourcesArray($child, $resourceName, $level + 1, $represent2Darray, $rawNodes, $module); } if ($rawNodes) { return $resource; diff --git a/app/code/core/Mage/Admin/Model/Rules.php b/app/code/core/Mage/Admin/Model/Rules.php index 4d492921de..99cb54b1fd 100644 --- a/app/code/core/Mage/Admin/Model/Rules.php +++ b/app/code/core/Mage/Admin/Model/Rules.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Admin Rules Model + * + * @method Mage_Admin_Model_Resource_Rules _getResource() + * @method Mage_Admin_Model_Resource_Rules getResource() + * @method int getRoleId() + * @method Mage_Admin_Model_Rules setRoleId(int $value) + * @method string getResourceId() + * @method Mage_Admin_Model_Rules setResourceId(string $value) + * @method string getPrivileges() + * @method Mage_Admin_Model_Rules setPrivileges(string $value) + * @method int getAssertId() + * @method Mage_Admin_Model_Rules setAssertId(int $value) + * @method string getRoleType() + * @method Mage_Admin_Model_Rules setRoleType(string $value) + * @method string getPermission() + * @method Mage_Admin_Model_Rules setPermission(string $value) + * + * @category Mage + * @package Mage_Admin + * @author Magento Core Team + */ class Mage_Admin_Model_Rules extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Admin/Model/Session.php b/app/code/core/Mage/Admin/Model/Session.php index 6e1fe5d941..3f5cecba66 100644 --- a/app/code/core/Mage/Admin/Model/Session.php +++ b/app/code/core/Mage/Admin/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -99,7 +99,7 @@ public function login($username, $password, $request = null) $this->setUser($user); $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); if ($requestUri = $this->_getRequestUri($request)) { - Mage::dispatchEvent('admin_session_user_login_success', array('user'=>$user)); + Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user)); header('Location: ' . $requestUri); exit; } @@ -109,7 +109,8 @@ public function login($username, $password, $request = null) } } catch (Mage_Core_Exception $e) { - Mage::dispatchEvent('admin_session_user_login_failed', array('user_name'=>$username, 'exception' => $e)); + Mage::dispatchEvent('admin_session_user_login_failed', + array('user_name' => $username, 'exception' => $e)); if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $request->setParam('messageSent', true); @@ -125,7 +126,7 @@ public function login($username, $password, $request = null) * @param Mage_Admin_Model_User $user * @return Mage_Admin_Model_Session */ - public function refreshAcl($user=null) + public function refreshAcl($user = null) { if (is_null($user)) { $user = $this->getUser(); @@ -153,14 +154,14 @@ public function refreshAcl($user=null) * @param string $privilege * @return boolean */ - public function isAllowed($resource, $privilege=null) + public function isAllowed($resource, $privilege = null) { $user = $this->getUser(); $acl = $this->getAcl(); if ($user && $acl) { if (!preg_match('/^admin/', $resource)) { - $resource = 'admin/'.$resource; + $resource = 'admin/' . $resource; } try { diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index 6eecf223e6..d2721714c1 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -20,13 +20,40 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Admin user model * + * @method Mage_Admin_Model_Resource_User _getResource() + * @method Mage_Admin_Model_Resource_User getResource() + * @method string getFirstname() + * @method Mage_Admin_Model_User setFirstname(string $value) + * @method string getLastname() + * @method Mage_Admin_Model_User setLastname(string $value) + * @method string getEmail() + * @method Mage_Admin_Model_User setEmail(string $value) + * @method string getUsername() + * @method Mage_Admin_Model_User setUsername(string $value) + * @method string getPassword() + * @method Mage_Admin_Model_User setPassword(string $value) + * @method string getCreated() + * @method Mage_Admin_Model_User setCreated(string $value) + * @method string getModified() + * @method Mage_Admin_Model_User setModified(string $value) + * @method string getLogdate() + * @method Mage_Admin_Model_User setLogdate(string $value) + * @method int getLognum() + * @method Mage_Admin_Model_User setLognum(int $value) + * @method int getReloadAclFlag() + * @method Mage_Admin_Model_User setReloadAclFlag(int $value) + * @method int getIsActive() + * @method Mage_Admin_Model_User setIsActive(int $value) + * @method string getExtra() + * @method Mage_Admin_Model_User setExtra(string $value) + * * @category Mage * @package Mage_Admin * @author Magento Core Team @@ -194,7 +221,7 @@ public function sendNewPasswordEmail() return $this; } - public function getName($separator=' ') + public function getName($separator = ' ') { return $this->getFirstname() . $separator . $this->getLastname(); } @@ -229,7 +256,7 @@ public function authenticate($username, $password) try { $this->loadByUsername($username); - $sensitive = ($config) ? $username==$this->getUsername() : true; + $sensitive = ($config) ? $username == $this->getUsername() : true; if ($sensitive && $this->getId() && Mage::helper('core')->validateHash($password, $this->getPassword())) { if ($this->getIsActive() != '1') { @@ -306,18 +333,18 @@ protected function _getEncodedPassword($pwd) * @param integer $level * @return string */ - public function findFirstAvailableMenu($parent=null, $path='', $level=0) + public function findFirstAvailableMenu($parent = null, $path = '', $level = 0) { if ($parent == null) { $parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu'); } - foreach ($parent->children() as $childName=>$child) { + foreach ($parent->children() as $childName => $child) { $aclResource = 'admin/' . $path . $childName; if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) { if (!$child->children) { return (string)$child->action; } else if ($child->children) { - $action = $this->findFirstAvailableMenu($child->children, $path . $childName . '/', $level+1); + $action = $this->findFirstAvailableMenu($child->children, $path . $childName . '/', $level + 1); return $action ? $action : (string)$child->action; } } diff --git a/app/code/core/Mage/Admin/data/admin_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Admin/data/admin_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..aa6b4a77b9 --- /dev/null +++ b/app/code/core/Mage/Admin/data/admin_setup/data-install-1.6.0.0.php @@ -0,0 +1,48 @@ +setData(array( + 'parent_id' => 0, + 'tree_level' => 1, + 'sort_order' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'role_name' => 'Administrators' + )) + ->save(); + +Mage::getModel('admin/rules')->setData(array( + 'role_id' => $admGroupRole->getId(), + 'resource_id' => 'all', + 'privileges' => null, + 'assert_id' => 0, + 'role_type' => 'G', + 'permission' => 'allow' + )) + ->save(); diff --git a/app/code/core/Mage/Admin/etc/config.xml b/app/code/core/Mage/Admin/etc/config.xml index f32cec09ea..b4ce4f3093 100644 --- a/app/code/core/Mage/Admin/etc/config.xml +++ b/app/code/core/Mage/Admin/etc/config.xml @@ -21,46 +21,54 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - - - 0.7.2 - - - - - - - Mage_Admin_Model - admin_mysql4 - - - Mage_Admin_Model_Mysql4 - - admin_user
- admin_role
- admin_rule
- admin_assert
-
-
-
- - - - - Mage_Admin - - - + + + 1.6.0.0 + + + + + + Mage_Admin_Model + admin_resource + + + Mage_Admin_Model_Resource + admin_mysql4 + + + admin_user
+
+ + admin_role
+
+ + admin_rule
+
+ + admin_assert
+
+
+
+
+ + + + Mage_Admin + + + - Mage_Admin_Block + + Mage_Admin_Block + -
- +
@@ -69,7 +77,6 @@ - diff --git a/app/code/core/Mage/Admin/sql/admin_setup/install-1.6.0.0.php b/app/code/core/Mage/Admin/sql/admin_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..fd167fd6f3 --- /dev/null +++ b/app/code/core/Mage/Admin/sql/admin_setup/install-1.6.0.0.php @@ -0,0 +1,193 @@ +startSetup(); + +/** + * Create table 'admin/assert' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('admin/assert')) + ->addColumn('assert_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Assert ID') + ->addColumn('assert_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + 'default' => '', + ), 'Assert Type') + ->addColumn('assert_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Assert Data') + ->setComment('Admin Assert Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'admin/role' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('admin/role')) + ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Role ID') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Parent Role ID') + ->addColumn('tree_level', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Role Tree Level') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Role Sort Order') + ->addColumn('role_type', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + 'nullable' => false, + 'default' => '0', + ), 'Role Type') + ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'User ID') + ->addColumn('role_name', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Role Name') + ->addIndex($installer->getIdxName('admin/role', array('parent_id', 'sort_order')), + array('parent_id', 'sort_order')) + ->addIndex($installer->getIdxName('admin/role', array('tree_level')), + array('tree_level')) + ->setComment('Admin Role Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'admin/rule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('admin/rule')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule ID') + ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Role ID') + ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Resource ID') + ->addColumn('privileges', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => true, + ), 'Privileges') + ->addColumn('assert_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Assert ID') + ->addColumn('role_type', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + ), 'Role Type') + ->addColumn('permission', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array( + ), 'Permission') + ->addIndex($installer->getIdxName('admin/rule', array('resource_id', 'role_id')), + array('resource_id', 'role_id')) + ->addIndex($installer->getIdxName('admin/rule', array('role_id', 'resource_id')), + array('role_id', 'resource_id')) + ->addForeignKey($installer->getFkName('admin/rule', 'role_id', 'admin/role', 'role_id'), + 'role_id', $installer->getTable('admin/role'), 'role_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Admin Rule Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'admin/user' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('admin/user')) + ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'User ID') + ->addColumn('firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => true, + ), 'User First Name') + ->addColumn('lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => true, + ), 'User Last Name') + ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array( + 'nullable' => true, + ), 'User Email') + ->addColumn('username', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + 'nullable' => true, + ), 'User Login') + ->addColumn('password', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + 'nullable' => true, + ), 'User Password') + ->addColumn('created', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'User Created Time') + ->addColumn('modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'User Modified Time') + ->addColumn('logdate', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'User Last Login Time') + ->addColumn('lognum', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'User Login Number') + ->addColumn('reload_acl_flag', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Reload ACL') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'User Is Active') + ->addColumn('extra', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'User Extra Data') + ->addIndex($installer->getIdxName('admin/user', array('username'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('username'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Admin User Table'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php index ad1f7946e0..23fdd7265e 100644 --- a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php index cae86380cc..be057b767c 100644 --- a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php index 44c559c79b..8bea8dcc79 100644 --- a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Admin - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..5555a65def --- /dev/null +++ b/app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,329 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('admin/rule'), + 'FK_ADMIN_RULE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('admin/role'), + 'PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('admin/role'), + 'TREE_LEVEL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('admin/rule'), + 'RESOURCE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('admin/rule'), + 'ROLE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('admin/user'), + 'UNQ_ADMIN_USER_USERNAME' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('admin/user') => array( + 'columns' => array( + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'User ID' + ), + 'firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'User First Name' + ), + 'lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'User Last Name' + ), + 'email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'comment' => 'User Email' + ), + 'username' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'User Login' + ), + 'password' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'User Password' + ), + 'created' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'User Created Time' + ), + 'modified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'User Modified Time' + ), + 'logdate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'User Last Login Time' + ), + 'lognum' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User Login Number' + ), + 'reload_acl_flag' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Reload ACL' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'User Is Active' + ), + 'extra' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'User Extra Data' + ) + ), + 'comment' => 'Admin User Table' + ), + $installer->getTable('admin/role') => array( + 'columns' => array( + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Role ID' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent Role ID' + ), + 'tree_level' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role Tree Level' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role Sort Order' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role Type' + ), + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User ID' + ), + 'role_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Role Name' + ) + ), + 'comment' => 'Admin Role Table' + ), + $installer->getTable('admin/rule') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule ID' + ), + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role ID' + ), + 'resource_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Resource ID' + ), + 'privileges' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Privileges' + ), + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Assert ID' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'comment' => 'Role Type' + ), + 'permission' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 10, + 'comment' => 'Permission' + ) + ), + 'comment' => 'Admin Rule Table' + ), + $installer->getTable('admin/assert') => array( + 'columns' => array( + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Assert ID' + ), + 'assert_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'comment' => 'Assert Type' + ), + 'assert_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Assert Data' + ) + ), + 'comment' => 'Admin Assert Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('admin/role'), + $installer->getIdxName('admin/role', array('parent_id', 'sort_order')), + array('parent_id', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('admin/role'), + $installer->getIdxName('admin/role', array('tree_level')), + array('tree_level') +); + +$installer->getConnection()->addIndex( + $installer->getTable('admin/rule'), + $installer->getIdxName('admin/rule', array('resource_id', 'role_id')), + array('resource_id', 'role_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('admin/rule'), + $installer->getIdxName('admin/rule', array('role_id', 'resource_id')), + array('role_id', 'resource_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('admin/user'), + $installer->getIdxName( + 'admin/user', + array('username'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('username'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('admin/rule', 'role_id', 'admin/role', 'role_id'), + $installer->getTable('admin/rule'), + 'role_id', + $installer->getTable('admin/role'), + 'role_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/AdminNotification/Helper/Data.php b/app/code/core/Mage/AdminNotification/Helper/Data.php index 1da9d2eec6..d7214748bd 100644 --- a/app/code/core/Mage/AdminNotification/Helper/Data.php +++ b/app/code/core/Mage/AdminNotification/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/AdminNotification/Model/Feed.php b/app/code/core/Mage/AdminNotification/Model/Feed.php index f995cd862d..71c56e3b60 100644 --- a/app/code/core/Mage/AdminNotification/Model/Feed.php +++ b/app/code/core/Mage/AdminNotification/Model/Feed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/AdminNotification/Model/Inbox.php b/app/code/core/Mage/AdminNotification/Model/Inbox.php index 5ec0369055..705cc351c5 100644 --- a/app/code/core/Mage/AdminNotification/Model/Inbox.php +++ b/app/code/core/Mage/AdminNotification/Model/Inbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,25 @@ /** * AdminNotification Inbox model * - * @category Mage - * @package Mage_AdminNotification + * @method Mage_AdminNotification_Model_Resource_Inbox _getResource() + * @method Mage_AdminNotification_Model_Resource_Inbox getResource() + * @method int getSeverity() + * @method Mage_AdminNotification_Model_Inbox setSeverity(int $value) + * @method string getDateAdded() + * @method Mage_AdminNotification_Model_Inbox setDateAdded(string $value) + * @method string getTitle() + * @method Mage_AdminNotification_Model_Inbox setTitle(string $value) + * @method string getDescription() + * @method Mage_AdminNotification_Model_Inbox setDescription(string $value) + * @method string getUrl() + * @method Mage_AdminNotification_Model_Inbox setUrl(string $value) + * @method int getIsRead() + * @method Mage_AdminNotification_Model_Inbox setIsRead(int $value) + * @method int getIsRemove() + * @method Mage_AdminNotification_Model_Inbox setIsRemove(int $value) + * + * @category Mage + * @package Mage_AdminNotification * @author Magento Core Team */ class Mage_AdminNotification_Model_Inbox extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php b/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php index 60e9120862..24d5de681d 100644 --- a/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php +++ b/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,71 +28,10 @@ /** * AdminNotification Inbox model * - * @category Mage - * @package Mage_AdminNotification + * @category Mage + * @package Mage_AdminNotification * @author Magento Core Team */ -class Mage_AdminNotification_Model_Mysql4_Inbox extends Mage_Core_Model_Mysql4_Abstract +class Mage_AdminNotification_Model_Mysql4_Inbox extends Mage_AdminNotification_Model_Resource_Inbox { - protected function _construct() - { - $this->_init('adminnotification/inbox', 'notification_id'); - } - - public function loadLatestNotice(Mage_AdminNotification_Model_Inbox $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->order($this->getIdFieldName() . ' desc') - ->where('is_read <> 1') - ->where('is_remove <> 1') - ->limit(1); - $data = $this->_getReadAdapter()->fetchRow($select); - - if ($data) { - $object->setData($data); - } - - $this->_afterLoad($object); - - return $this; - } - - public function getNoticeStatus(Mage_AdminNotification_Model_Inbox $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array( - 'severity' => 'severity', - 'count_notice' => 'COUNT(' . $this->getIdFieldName() . ')')) - ->group('severity') - ->where('is_remove=?', 0) - ->where('is_read=?', 0); - $return = array(); - $rowSet = $this->_getReadAdapter()->fetchAll($select); - foreach ($rowSet as $row) { - $return[$row['severity']] = $row['count_notice']; - } - return $return; - } - - public function parse(Mage_AdminNotification_Model_Inbox $object, array $data) - { - $write = $this->_getWriteAdapter(); - foreach ($data as $item) { - $select = $write->select() - ->from($this->getMainTable()) - ->where('url=?', $item['url']); - - if (isset($item['internal'])) { - $row = false; - unset($item['internal']); - } else { - $row = $write->fetchRow($select); - } - - if (!$row) { - $write->insert($this->getMainTable(), $item); - } - } - } } diff --git a/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php b/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php index e16c6ee6c1..c23939520e 100644 --- a/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php +++ b/app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,21 +28,11 @@ /** * AdminNotification Inbox model * - * @category Mage - * @package Mage_AdminNotification + * @category Mage + * @package Mage_AdminNotification * @author Magento Core Team */ -class Mage_AdminNotification_Model_Mysql4_Inbox_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_AdminNotification_Model_Mysql4_Inbox_Collection + extends Mage_AdminNotification_Model_Resource_Inbox_Collection { - protected function _construct() - { - $this->_init('adminnotification/inbox'); - } - - public function addRemoveFilter() - { - $this->getSelect() - ->where('is_remove=?', 0); - return $this; - } } diff --git a/app/code/core/Mage/AdminNotification/Model/Observer.php b/app/code/core/Mage/AdminNotification/Model/Observer.php index 339d5d2fe5..787d17b686 100644 --- a/app/code/core/Mage/AdminNotification/Model/Observer.php +++ b/app/code/core/Mage/AdminNotification/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php b/app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php new file mode 100755 index 0000000000..14337f97e3 --- /dev/null +++ b/app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php @@ -0,0 +1,118 @@ + + */ +class Mage_AdminNotification_Model_Resource_Inbox extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * AdminNotification Resource initialization + * + */ + protected function _construct() + { + $this->_init('adminnotification/inbox', 'notification_id'); + } + + /** + * Load latest notice + * + * @param Mage_AdminNotification_Model_Inbox $object + * @return Mage_AdminNotification_Model_Resource_Inbox + */ + public function loadLatestNotice(Mage_AdminNotification_Model_Inbox $object) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->order($this->getIdFieldName() . ' DESC') + ->where('is_read != 1') + ->where('is_remove != 1') + ->limit(1); + $data = $adapter->fetchRow($select); + + if ($data) { + $object->setData($data); + } + + $this->_afterLoad($object); + + return $this; + } + + /** + * Get notifications grouped by severity + * + * @param Mage_AdminNotification_Model_Inbox $object + * @return array + */ + public function getNoticeStatus(Mage_AdminNotification_Model_Inbox $object) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array( + 'severity' => 'severity', + 'count_notice' => new Zend_Db_Expr('COUNT(' . $this->getIdFieldName() . ')'))) + ->group('severity') + ->where('is_remove=?', 0) + ->where('is_read=?', 0); + $return = $adapter->fetchPairs($select); + return $return; + } + + /** + * Save notifications (if not exists) + * + * @param Mage_AdminNotification_Model_Inbox $object + * @param array $data + */ + public function parse(Mage_AdminNotification_Model_Inbox $object, array $data) + { + $adapter = $this->_getWriteAdapter(); + foreach ($data as $item) { + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('url=?', $item['url']); + + if (isset($item['internal'])) { + $row = false; + unset($item['internal']); + } else { + $row = $adapter->fetchRow($select); + } + + if (!$row) { + $adapter->insert($this->getMainTable(), $item); + } + } + } +} diff --git a/app/code/core/Mage/AdminNotification/Model/Resource/Inbox/Collection.php b/app/code/core/Mage/AdminNotification/Model/Resource/Inbox/Collection.php new file mode 100755 index 0000000000..762dadf39e --- /dev/null +++ b/app/code/core/Mage/AdminNotification/Model/Resource/Inbox/Collection.php @@ -0,0 +1,57 @@ + + */ +class Mage_AdminNotification_Model_Resource_Inbox_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('adminnotification/inbox'); + } + + /** + * Add remove filter + * + * @return Mage_AdminNotification_Model_Resource_Inbox_Collection + */ + public function addRemoveFilter() + { + $this->getSelect() + ->where('is_remove=?', 0); + return $this; + } +} diff --git a/app/code/core/Mage/AdminNotification/Model/Survey.php b/app/code/core/Mage/AdminNotification/Model/Survey.php index 5d0466abd9..b9bb7431b1 100644 --- a/app/code/core/Mage/AdminNotification/Model/Survey.php +++ b/app/code/core/Mage/AdminNotification/Model/Survey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -63,7 +63,7 @@ public static function isSurveyUrlValid() */ public static function getSurveyUrl() { - $host = Mage::app()->getRequest()->isSecure()?'https://':'http://'; + $host = Mage::app()->getRequest()->isSecure() ? 'https://' : 'http://'; return $host . self::SURVEY_URL; } diff --git a/app/code/core/Mage/AdminNotification/etc/adminhtml.xml b/app/code/core/Mage/AdminNotification/etc/adminhtml.xml index 98f03d6ba2..3b1c426a94 100644 --- a/app/code/core/Mage/AdminNotification/etc/adminhtml.xml +++ b/app/code/core/Mage/AdminNotification/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/AdminNotification/etc/config.xml b/app/code/core/Mage/AdminNotification/etc/config.xml index d7f1dde028..8b87cb3fae 100644 --- a/app/code/core/Mage/AdminNotification/etc/config.xml +++ b/app/code/core/Mage/AdminNotification/etc/config.xml @@ -21,31 +21,31 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.0.0 + 1.6.0.0 - Mage_AdminNotification_Model - adminnotification_mysql4 + adminnotification_resource - - Mage_AdminNotification_Model_Mysql4 + + Mage_AdminNotification_Model_Resource + adminnotification_mysql4 adminnotification_inbox
-
+
@@ -59,13 +59,7 @@ - - - Mage_AdminNotification_Block - -
- @@ -94,7 +88,6 @@
- diff --git a/app/code/core/Mage/AdminNotification/etc/system.xml b/app/code/core/Mage/AdminNotification/etc/system.xml index 0d63ce4e50..70119fbef0 100644 --- a/app/code/core/Mage/AdminNotification/etc/system.xml +++ b/app/code/core/Mage/AdminNotification/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/install-1.6.0.0.php b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..cb89601f46 --- /dev/null +++ b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/install-1.6.0.0.php @@ -0,0 +1,83 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); +/** + * Create table 'adminnotification/inbox' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('adminnotification/inbox')) + ->addColumn('notification_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Notification id') + ->addColumn('severity', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Problem type') + ->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Create date') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Title') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Url') + ->addColumn('is_read', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Flag if notification read') + ->addColumn('is_remove', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Flag if notification might be removed') + ->addIndex($installer->getIdxName('adminnotification/inbox', array('severity')), + array('severity')) + ->addIndex($installer->getIdxName('adminnotification/inbox', array('is_read')), + array('is_read')) + ->addIndex($installer->getIdxName('adminnotification/inbox', array('is_remove')), + array('is_remove')) + ->setComment('Adminnotification Inbox'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php index 403a68fda9..6b0884ed33 100644 --- a/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php +++ b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_AdminNotification - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..fa7d5abc8f --- /dev/null +++ b/app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,135 @@ +startSetup(); + +/** + * Drop indexes + */ +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('adminnotification/inbox'), + 'IDX_SEVERITY' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('adminnotification/inbox'), + 'IDX_IS_READ' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('adminnotification/inbox'), + 'IDX_IS_REMOVE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('adminnotification/inbox') => array( + 'columns' => array( + 'notification_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Notification id' + ), + 'severity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Problem type' + ), + 'date_added' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Create date' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Title' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Url' + ), + 'is_read' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Flag if notification read' + ), + 'is_remove' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Flag if notification might be removed' + ) + ), + 'comment' => 'Adminnotification Inbox' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$connection = $installer->getConnection()->addIndex( + $installer->getTable('adminnotification/inbox'), + $installer->getIdxName('adminnotification/inbox', array('severity')), + array('severity') +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('adminnotification/inbox'), + $installer->getIdxName('adminnotification/inbox', array('is_read')), + array('is_read') +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('adminnotification/inbox'), + $installer->getIdxName('adminnotification/inbox', array('is_remove')), + array('is_remove') +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Adminhtml/Block/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Abstract.php index 82c188e39d..df26777ede 100644 --- a/app/code/core/Mage/Adminhtml/Block/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Buttons.php b/app/code/core/Mage/Adminhtml/Block/Api/Buttons.php index e0db50babe..a3a93fa1a7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Buttons.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Buttons.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Editroles.php b/app/code/core/Mage/Adminhtml/Block/Api/Editroles.php index 61c4362d24..29a28f807b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Editroles.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Editroles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Edituser.php b/app/code/core/Mage/Adminhtml/Block/Api/Edituser.php index 5ec0db4f12..5ce2840285 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Edituser.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Edituser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Grid/Role.php b/app/code/core/Mage/Adminhtml/Block/Api/Grid/Role.php index 6a2c444a1b..50dba8ce6c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Grid/Role.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Grid/Role.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Role.php b/app/code/core/Mage/Adminhtml/Block/Api/Role.php index 93cd907c26..b37dee5581 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Role.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Role.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Role/Grid/User.php b/app/code/core/Mage/Adminhtml/Block/Api/Role/Grid/User.php index 0cdc3aa686..70c9f01f3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Role/Grid/User.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Role/Grid/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Roles.php b/app/code/core/Mage/Adminhtml/Block/Api/Roles.php index 754989d28e..ebee0f5eeb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Roles.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Roles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Roleinfo.php b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Roleinfo.php index 190bed8b34..56127cf39c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Roleinfo.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Roleinfo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php index abd256b0c6..d38cc618be 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesedit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesusers.php b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesusers.php index 45f26e90df..72f7875ced 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesusers.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Rolesusers.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Userroles.php b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Userroles.php index 496fa7ded8..1b16b08fe7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Tab/Userroles.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Tab/Userroles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Api_Tab_Userroles extends Mage_Adminhtml_Block_Widget_Tabs diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User.php b/app/code/core/Mage/Adminhtml/Block/Api/User.php index af031eab92..da29860cfd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit.php index d4cb43eff7..b95eadc1b5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Form.php index 07c89c9585..273d8308db 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php index d72b01c94a..e8e33baa25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Roles.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Roles.php index 38ca041955..c4b1b277cd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Roles.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Roles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tabs.php index a380a7f49b..dffd2f594d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Grid.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Grid.php index 80569613cc..730ca341aa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Api/Users.php b/app/code/core/Mage/Adminhtml/Block/Api/Users.php index b53ed6072b..4d44fff479 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/Users.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/Users.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Backup.php b/app/code/core/Mage/Adminhtml/Block/Backup.php index c4aa363fc4..25b0a7ea9d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Backup.php +++ b/app/code/core/Mage/Adminhtml/Block/Backup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Backup/Grid.php b/app/code/core/Mage/Adminhtml/Block/Backup/Grid.php index 76413087b6..8b8308aa7a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Backup/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Backup/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cache.php b/app/code/core/Mage/Adminhtml/Block/Cache.php index c8d82dd12c..2ff91df5c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cache/Additional.php b/app/code/core/Mage/Adminhtml/Block/Cache/Additional.php index a8ae7792d9..e22931a1d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache/Additional.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache/Additional.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cache/Grid.php b/app/code/core/Mage/Adminhtml/Block/Cache/Grid.php index 89a2f1de35..1b35c2eb60 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php index 0bc9baebe9..4cd20f1ce0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog.php b/app/code/core/Mage/Adminhtml/Block/Catalog.php index b0b65a3022..f53f9efbf6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php index b1961d0b40..c5cb2cd774 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Checkboxes/Tree.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Checkboxes/Tree.php index 4cde9e642a..1164fdd255 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Checkboxes/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Checkboxes/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit.php index 323d54f919..69e4f777a1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php index effbdf7155..fc617790c5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Image.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Image.php index fb5b257203..19ddf2b64c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Image.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Pricestep.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Pricestep.php index af127eadd3..0fcd76a4af 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Pricestep.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Pricestep.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Available.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Available.php index bb45b2ff5e..f47a852a26 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Available.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Available.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Default.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Default.php index cb68ff80c4..ac85d545f8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Helper/Sortby/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php index 988e131aba..22dd4afbcd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Design.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Design.php index 5183cc9fa8..ce33bed0b9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Design.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Catalog_Category_Tab_Design extends Mage_Adminhtml_Block_Catalog_Form diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php index cffbc203cf..e53cd3d475 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php index 2b97d65741..fae4abbe62 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tabs.php index 83b85f16bc..8417c19290 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -104,8 +104,10 @@ protected function _prepareLayout() } $attributeSetId = $this->getCategory()->getDefaultAttributeSetId(); + /** @var $groupCollection Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection */ $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection') ->setAttributeSetFilter($attributeSetId) + ->setSortOrder() ->load(); $defaultGroupId = 0; foreach ($groupCollection as $group) { @@ -143,12 +145,6 @@ protected function _prepareLayout() )); } -// $this->addTab('general', array( -// 'label' => Mage::helper('catalog')->__('General Information'), -// 'content' => $this->getLayout()->createBlock('adminhtml/catalog_category_tab_general')->toHtml(), -// 'active' => true -// )); - $this->addTab('products', array( 'label' => Mage::helper('catalog')->__('Category Products'), 'content' => $this->getLayout()->createBlock('adminhtml/catalog_category_tab_product', 'category.product.grid')->toHtml(), diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php index 965342a8f0..577c81a314 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php index 0738275ffd..a628f7678a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form.php index f98e06cf3b..11af84cb6f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Attribute/Urlkey.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Attribute/Urlkey.php index 1e1172bceb..7d4a478025 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Attribute/Urlkey.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Attribute/Urlkey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/DateFieldsOrder.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/DateFieldsOrder.php index 402b8c85e2..7878327f72 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/DateFieldsOrder.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/DateFieldsOrder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/YearRange.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/YearRange.php index afedf29a5f..a8e09b990e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/YearRange.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Config/YearRange.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php index 8bcb3d6ace..2fe8576125 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Googleoptimizer/Import.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Googleoptimizer/Import.php index ad3acd1718..de9353aa16 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Googleoptimizer/Import.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Googleoptimizer/Import.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg.php index 4c67f51978..5f8af9aee4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -62,7 +62,11 @@ public function getAfterElementHtml() */ public function getIsWysiwygEnabled() { - return (bool)(Mage::getSingleton('cms/wysiwyg_config')->isEnabled() && $this->getEntityAttribute()->getIsWysiwygEnabled()); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Cms')) { + return (bool)(Mage::getSingleton('cms/wysiwyg_config')->isEnabled() && $this->getEntityAttribute()->getIsWysiwygEnabled()); + } + + return false; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php index 49a5ae005a..ee10d9c3d4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product.php index 7103af6e6b..62d0da5195 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php index 30a139abe8..d9df1cfad3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php index e94a2aa9de..7bed59eb4f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php index 42def14c88..2cce45dc08 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php index 0d657cf53c..df79a8895c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php index cc96dedbe2..4c391b9558 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php index ad0898a8dd..cd27d2dac6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php index e35b1bb69c..3b9c47baf0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php index d1e1dd72e2..e3e00f880c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php index 7362d423a0..71896a35ca 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Attributes.php index c20f627f9b..553a18d671 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Created.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Created.php index 8ae0021fa0..1a301ed7dd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Created.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/New/Product/Created.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php index 5194cbc250..8d6de62b11 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,7 +39,7 @@ public function __construct() parent::__construct(); $this->setId('setGrid'); $this->setDefaultSort('set_id'); - $this->setDefaultDir('asc'); + $this->setDefaultDir('ASC'); $this->setSaveParametersInSession(true); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php index ec8bcfb284..514568dac8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -173,6 +173,7 @@ public function getGroupTreeJson() $groups = Mage::getModel('eav/entity_attribute_group') ->getResourceCollection() ->setAttributeSetFilter($setId) + ->setSortOrder() ->load(); $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute') diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php index feff0d6fba..693f391287 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php index 6343748ee3..d14376a854 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php index abd094c94f..2e2fb38f5f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php index e22a3e0a00..5f3a8e7b4a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php index ead4f7d413..a1709c68a2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php index 1d7fec4f8f..2b5dc31959 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php index 14809d9e82..d9b1a1c9df 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php index 919363065a..fd000b3149 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Configure.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Configure.php index 4ba173b8a2..3b471325e8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Configure.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Configure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Error.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Error.php index b48d75ed60..1eb057514d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Error.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Error.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset.php index 0ccff0f5b2..c4944525ea 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Configurable.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Configurable.php index 2790626950..b343e8db73 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Configurable.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Grouped.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Grouped.php index 428646896b..4846c9c48b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Grouped.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Options.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Options.php index 387eba7afd..cc3dae096d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Qty.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Qty.php index acd63a5ddc..fd9bc26c04 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Qty.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Qty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Update/Result.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Update/Result.php index c76abb1dd2..02cfecacc9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Update/Result.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Update/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Created.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Created.php index dc488921f0..9c3e4adf14 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Created.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Created.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php index ff4e130415..532dc031f7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute.php index e35fdc9f66..4acdb13eed 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Attributes.php index 0670432aa8..90d3312bc6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Inventory.php index f9832504ec..5e2395b3ea 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Inventory.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Websites.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Websites.php index 706e6cd69f..03ba5d4942 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Websites.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tab/Websites.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tabs.php index 2f65b23c4a..0fd602c6c8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Action/Attribute/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Js.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Js.php index 90414aa088..ee9a816bca 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Js.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php index fafbc2fefe..a053a3455b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Ajax/Serializer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -50,7 +50,7 @@ public function getProductsJSON() $result[$id] = $product->toArray(array('qty', 'position')); } } - return $result ? Zend_Json_Encoder::encode($result) : '{}'; + return $result ? Zend_Json::encode($result) : '{}'; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts.php index c562e88de4..76bccf2c53 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Price.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Price.php index 802cc1690b..953367453b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ public function __construct() $this->setId('alertPrice'); $this->setDefaultSort('add_date'); - $this->setDefaultSort('desc'); + $this->setDefaultSort('DESC'); $this->setUseAjax(true); $this->setFilterVisibility(false); $this->setEmptyText(Mage::helper('catalog')->__('There are no customers for this alert')); @@ -53,10 +53,12 @@ protected function _prepareCollection() if ($store = $this->getRequest()->getParam('store')) { $websiteId = Mage::app()->getStore($store)->getWebsiteId(); } - $collection = Mage::getModel('productalert/price') - ->getCustomerCollection() - ->join($productId, $websiteId); - $this->setCollection($collection); + if (Mage::helper('catalog')->isModuleEnabled('Mage_ProductAlert')) { + $collection = Mage::getModel('productalert/price') + ->getCustomerCollection() + ->join($productId, $websiteId); + $this->setCollection($collection); + } return parent::_prepareCollection(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php index a346cabde7..80a0333dba 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ public function __construct() $this->setId('alertStock'); $this->setDefaultSort('add_date'); - $this->setDefaultSort('desc'); + $this->setDefaultSort('DESC'); $this->setUseAjax(true); $this->setFilterVisibility(false); $this->setEmptyText(Mage::helper('catalog')->__('There are no customers for this alert.')); @@ -53,10 +53,12 @@ protected function _prepareCollection() if ($store = $this->getRequest()->getParam('store')) { $websiteId = Mage::app()->getStore($store)->getWebsiteId(); } - $collection = Mage::getModel('productalert/stock') - ->getCustomerCollection() - ->join($productId, $websiteId); - $this->setCollection($collection); + if (Mage::helper('catalog')->isModuleEnabled('Mage_ProductAlert')) { + $collection = Mage::getModel('productalert/stock') + ->getCustomerCollection() + ->join($productId, $websiteId); + $this->setCollection($collection); + } return parent::_prepareCollection(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php index 9587e7c8a2..e7477bed16 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,8 +39,10 @@ class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes extends Mage_Admi protected function _prepareLayout() { parent::_prepareLayout(); - if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { - $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Cms')) { + if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) { + $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true); + } } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes/Create.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes/Create.php index 443d99465f..3eb5e02307 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php index cd00fb72ea..8047c61e42 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -212,12 +212,16 @@ public function getLoadTreeUrl($expanded=null) public function getSelectedCategoriesPathIds($rootId = false) { $ids = array(); - $collection = Mage::getModel('catalog/category')->getCollection(); + $categoryIds = $this->getCategoryIds(); + if (empty($categoryIds)) { + return array(); + } + $collection = Mage::getResourceModel('catalog/category_collection'); if ($rootId) { $collection->addFieldToFilter('parent_id', $rootId); } else { - $collection->addFieldToFilter('entity_id', array('in'=>$this->getCategoryIds())); + $collection->addFieldToFilter('entity_id', array('in'=>$categoryIds)); } foreach ($collection as $item) { diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php index 2dd161144d..615aed8412 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -95,17 +95,19 @@ protected function _addColumnFilterToCollection($column) */ protected function _prepareCollection() { + /* @var $collection Mage_Catalog_Model_Resource_Product_Link_Product_Collection */ $collection = Mage::getModel('catalog/product_link')->useCrossSellLinks() ->getProductCollection() ->setProduct($this->_getProduct()) ->setPositionOrder() ->addAttributeToSelect('*'); + if ($this->isReadonly()) { $productIds = $this->_getSelectedProducts(); if (empty($productIds)) { $productIds = array(0); } - $collection->addFieldToFilter('entity_id', array('in'=>$productIds)); + $collection->addFieldToFilter('entity_id', array('in' => $productIds)); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php index 7521c1e79e..950fe4cbbc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Inventory.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,7 +39,11 @@ public function __construct() public function getBackordersOption() { - return Mage::getSingleton('cataloginventory/source_backorders')->toOptionArray(); + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + return Mage::getSingleton('cataloginventory/source_backorders')->toOptionArray(); + } + + return array(); } /** @@ -49,7 +53,11 @@ public function getBackordersOption() */ public function getStockOption() { - return Mage::getSingleton('cataloginventory/source_stock')->toOptionArray(); + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + return Mage::getSingleton('cataloginventory/source_stock')->toOptionArray(); + } + + return array(); } /** @@ -69,12 +77,12 @@ public function getProduct() */ public function getStockItem() { - return Mage::registry('product')->getStockItem(); + return $this->getProduct()->getStockItem(); } public function isConfigurable() { - return Mage::registry('product')->isConfigurable(); + return $this->getProduct()->isConfigurable(); } public function getFieldValue($field) @@ -114,7 +122,7 @@ public function isReadonly() public function isNew() { - if (Mage::registry('product')->getId()) { + if ($this->getProduct()->getId()) { return false; } return true; diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options.php index 032fabd310..9b430da552 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php index caf77bc0a2..6f2f6c146d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php index b3338b3ad6..4c15c32f12 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Date.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Date.php index f97c0e443c..2f15647420 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/File.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/File.php index 216b5dad71..d9cc45812b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/File.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Select.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Select.php index 1fa25ba798..5c37920a93 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Select.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Text.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Text.php index 3ef622f21d..6f90cddf78 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Text.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Type/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price.php index 8cc56e7537..ff6f808b61 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Recurring.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Recurring.php index 8d53918bc8..4f05528eaf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Recurring.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Recurring.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php index 35d3f6b8a0..bc048fc300 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Price/Tier.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -161,7 +161,10 @@ protected function _sortTierPrices($a, $b) */ public function getCustomerGroups($groupId = null) { - if (is_null($this->_customerGroups)) { + if ($this->_customerGroups === null) { + if (!Mage::helper('catalog')->isModuleEnabled('Mage_Customer')) { + return array(); + } $collection = Mage::getModel('customer/group')->getCollection(); $this->_customerGroups = array( Mage_Customer_Model_Group::CUST_GROUP_ALL => Mage::helper('catalog')->__('ALL GROUPS') @@ -173,8 +176,8 @@ public function getCustomerGroups($groupId = null) } } - if (!is_null($groupId)) { - return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null; + if ($groupId !== null) { + return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : array(); } return $this->_customerGroups; diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php index f567bea99a..9461dae36d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Reviews.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Reviews.php index 2292dff4f8..5028c63a45 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Reviews.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Reviews.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Settings.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Settings.php index ba8ae8d2f3..996ef7e096 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Settings.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Settings.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config.php index cd2499a0f1..3971eb7f98 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php index 26e89193f8..83f77b964f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -105,7 +105,11 @@ protected function _getCreatedProducts() protected function _prepareCollection() { $allowProductTypes = array(); - foreach (Mage::getConfig()->getNode('global/catalog/product/type/configurable/allow_product_types')->children() as $type) { + foreach ( + Mage::getConfig() + ->getNode('global/catalog/product/type/configurable/allow_product_types') + ->children() as $type + ) { $allowProductTypes[] = $type->getName(); } @@ -118,13 +122,16 @@ protected function _prepareCollection() ->addAttributeToSelect('price') ->addFieldToFilter('attribute_set_id',$product->getAttributeSetId()) ->addFieldToFilter('type_id', $allowProductTypes) - ->addFilterByRequiredOptions(); + ->addFilterByRequiredOptions() + ->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner'); - Mage::getModel('cataloginventory/stock_item')->addCatalogInventoryToProductCollection($collection); + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + Mage::getModel('cataloginventory/stock_item')->addCatalogInventoryToProductCollection($collection); + } foreach ($product->getTypeInstance(true)->getUsedProductAttributes($product) as $attribute) { $collection->addAttributeToSelect($attribute->getAttributeCode()); - $collection->addAttributeToFilter($attribute->getAttributeCode(), array('nin'=>array(null))); + $collection->addAttributeToFilter($attribute->getAttributeCode(), array('notnull'=>1)); } $this->setCollection($collection); @@ -266,7 +273,11 @@ public function getEditParamsForAssociated() protected function _getRequiredAttributesIds() { $attributesIds = array(); - foreach ($this->_getProduct()->getTypeInstance(true)->getConfigurableAttributes($this->_getProduct()) as $attribute) { + foreach ( + $this->_getProduct() + ->getTypeInstance(true) + ->getConfigurableAttributes($this->_getProduct()) as $attribute + ) { $attributesIds[] = $attribute->getProductAttribute()->getId(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php index 344a7709e1..e73d349e25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Filter/Inventory.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Checkbox.php index d30642626c..5ce8fab683 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Inventory.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Inventory.php index 5d514ddfcd..eb19457c3a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Inventory.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid/Renderer/Inventory.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php index 44c3b4887b..f37f5ed297 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php index 8b885a56c8..397d6cc9f7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Settings.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Settings.php index dd8816e22f..576fc4919e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Settings.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Settings.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php index f6f2a0dc98..c735ca2342 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php index 7eb2cb30c3..06a1dab465 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Tag/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -45,14 +45,15 @@ public function __construct() protected function _prepareCollection() { - $tagId = Mage::registry('tagId'); - $collection = Mage::getModel('tag/tag') - ->getCustomerCollection() - ->addProductFilter($this->getProductId()) - ->addGroupByTag() - ->addDescOrder(); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) { + $collection = Mage::getModel('tag/tag') + ->getCustomerCollection() + ->addProductFilter($this->getProductId()) + ->addGroupByTag() + ->addDescOrder(); - $this->setCollection($collection); + $this->setCollection($collection); + } return parent::_prepareCollection(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php index b7b5361580..a6ed4ec6e3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Websites.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Websites.php index d71f5345e3..0dfcac74ee 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Websites.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Websites.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php index c0f6a35421..5ed0f5e478 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -54,6 +54,7 @@ protected function _prepareLayout() if ($setId) { $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection') ->setAttributeSetFilter($setId) + ->setSortOrder() ->load(); foreach ($groupCollection as $group) { @@ -79,11 +80,12 @@ protected function _prepareLayout() )); } - $this->addTab('inventory', array( - 'label' => Mage::helper('catalog')->__('Inventory'), - 'content' => $this->_translateHtml($this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()), - )); - + if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) { + $this->addTab('inventory', array( + 'label' => Mage::helper('catalog')->__('Inventory'), + 'content' => $this->_translateHtml($this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()), + )); + } /** * Don't display website tab for single mode @@ -127,7 +129,7 @@ protected function _prepareLayout() $alertPriceAllow = Mage::getStoreConfig('catalog/productalert/allow_price'); $alertStockAllow = Mage::getStoreConfig('catalog/productalert/allow_stock'); - if ($alertPriceAllow || $alertStockAllow) { + if (($alertPriceAllow || $alertStockAllow) && !$product->isGrouped()) { $this->addTab('productalert', array( 'label' => Mage::helper('catalog')->__('Product Alerts'), 'content' => $this->_translateHtml($this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts', 'admin.alerts.products')->toHtml()) @@ -135,25 +137,29 @@ protected function _prepareLayout() } if( $this->getRequest()->getParam('id', false) ) { - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')){ - $this->addTab('reviews', array( - 'label' => Mage::helper('catalog')->__('Product Reviews'), - 'url' => $this->getUrl('*/*/reviews', array('_current' => true)), - 'class' => 'ajax', - )); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) { + if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')){ + $this->addTab('reviews', array( + 'label' => Mage::helper('catalog')->__('Product Reviews'), + 'url' => $this->getUrl('*/*/reviews', array('_current' => true)), + 'class' => 'ajax', + )); + } } - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')){ - $this->addTab('tags', array( - 'label' => Mage::helper('catalog')->__('Product Tags'), - 'url' => $this->getUrl('*/*/tagGrid', array('_current' => true)), - 'class' => 'ajax', - )); - - $this->addTab('customers_tags', array( - 'label' => Mage::helper('catalog')->__('Customers Tagged Product'), - 'url' => $this->getUrl('*/*/tagCustomerGrid', array('_current' => true)), - 'class' => 'ajax', - )); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) { + if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')){ + $this->addTab('tags', array( + 'label' => Mage::helper('catalog')->__('Product Tags'), + 'url' => $this->getUrl('*/*/tagGrid', array('_current' => true)), + 'class' => 'ajax', + )); + + $this->addTab('customers_tags', array( + 'label' => Mage::helper('catalog')->__('Customers Tagged Product'), + 'url' => $this->getUrl('*/*/tagCustomerGrid', array('_current' => true)), + 'class' => 'ajax', + )); + } } } @@ -163,7 +169,7 @@ protected function _prepareLayout() * @see Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs_Configurable * @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tabs */ - if ($this->getProduct()->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { + if (!$product->isGrouped()) { $this->addTab('customer_options', array( 'label' => Mage::helper('catalog')->__('Custom Options'), 'url' => $this->getUrl('*/*/options', array('_current' => true)), diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Configurable.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Configurable.php index 6f4436244e..ff5eb8f6ea 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Configurable.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Grouped.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Grouped.php index 49643b9b8a..146f941b40 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Grouped.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Frontend/Product/Watermark.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Frontend/Product/Watermark.php index b32ce16f4a..0099b5dbf2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Frontend/Product/Watermark.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Frontend/Product/Watermark.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php index d4e3faf306..29699db2ab 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,7 +39,7 @@ public function __construct() parent::__construct(); $this->setId('productGrid'); $this->setDefaultSort('entity_id'); - $this->setDefaultDir('desc'); + $this->setDefaultDir('DESC'); $this->setSaveParametersInSession(true); $this->setUseAjax(true); $this->setVarNameFilter('product_filter'); @@ -59,14 +59,16 @@ protected function _prepareCollection() ->addAttributeToSelect('sku') ->addAttributeToSelect('name') ->addAttributeToSelect('attribute_set_id') - ->addAttributeToSelect('type_id') - ->joinField('qty', + ->addAttributeToSelect('type_id'); + + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); - + } if ($store->getId()) { //$collection->setStoreId($store->getId()); $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; @@ -168,13 +170,15 @@ protected function _prepareColumns() 'index' => 'price', )); - $this->addColumn('qty', - array( - 'header'=> Mage::helper('catalog')->__('Qty'), - 'width' => '100px', - 'type' => 'number', - 'index' => 'qty', - )); + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + $this->addColumn('qty', + array( + 'header'=> Mage::helper('catalog')->__('Qty'), + 'width' => '100px', + 'type' => 'number', + 'index' => 'qty', + )); + } $this->addColumn('visibility', array( @@ -227,7 +231,9 @@ protected function _prepareColumns() 'index' => 'stores', )); - $this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS')); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss')) { + $this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS')); + } return parent::_prepareColumns(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Apply.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Apply.php index c2634c90e3..b112559572 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Apply.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Apply.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Boolean.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Boolean.php index d9bd68e528..90aad07f3e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Boolean.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php index 0ad8caa290..08760cf40b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php index fd4dcf8d1c..117ff858aa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php index 601b669068..ba20f4dff1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Image.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Image.php index 700aeec402..2397aadeab 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Image.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php index 2ea5e89520..2aa50e5ca5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Price.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Price.php index 0edc93057a..6c5f8a7ee4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php index 31aac510f7..b986a9d212 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser/Container.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser/Container.php index 60edf587b7..66aac1d76d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser/Container.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Widget/Chooser/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search.php index a7b1ab5818..2d0f0d8de5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit.php index 417bf6012d..d3da33cd1f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php index c39beb8802..74d01c7022 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php index f508b42a59..89392713c2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Search/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement.php b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement.php index af400359cd..8e27585e2e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement.php +++ b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit.php b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit.php index 4c353b4be5..b433304825 100644 --- a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php index dd760e934b..cbef849c3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Grid.php b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Grid.php index 4ccc5cce1b..24cfb0d1e9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Checkout/Agreement/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Checkout_Agreement_Grid extends Mage_Adminhtml_Block_Widget_Grid diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block.php index 53a869eb68..dc92c43e03 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit.php index 2fe28f5f37..8d67cc31c9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php index 3a5d9c36e6..2bdc5cf881 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Grid.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Grid.php index 82bb2e6815..e829eaa305 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php index 524589c932..3b85d07f9a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Block/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php index 5f5af7be70..318b52281c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php index 2034a90bb0..89f40cc9e7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Form.php index 88a1f28998..e8a169b96d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php index fa06da8e07..cb0da7260a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php index 6c363e3d6a..2d6e7ac817 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Design diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php index b5a58577a3..9fc62c958f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php index 200740f390..995715f90a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php index a3a1e53f12..f30cb52088 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php index ce8600c074..b1288f6d1d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid/Renderer/Action.php index 48f040c329..68bdeeb329 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php index e4885e1a0b..670aba3e4b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php index 3c8c7abc85..e751e56fe2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php index 77fb2352a1..d6bb9c6a3a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Files.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php index 154e744f83..1d1f906a80 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Newfolder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php index 27f30a208f..e8b3334a2d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Content/Uploader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php index 6181d579b0..5a7e8611b5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Wysiwyg/Images/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer.php b/app/code/core/Mage/Adminhtml/Block/Customer.php index e11f6a1adc..d630f496de 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php index a02c5816ba..d48f5f1402 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Form.php index 58dbb2cdba..8501358f2a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Newpass.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Newpass.php index 61e5ce3061..37a472fa79 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Newpass.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Newpass.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php index 94c5d87094..6d3c5fc315 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php index c1e7d31a5e..0776993c84 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php index ce7c8d3458..87ec8ea558 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -115,10 +115,12 @@ public function initForm() ); $addressModel = Mage::getModel('customer/address'); - /* @var $addressForm Mage_Customer_Model_Form */ + $addressModel->setCountryId(Mage::helper('core')->getDefaultCountry($customer->getStore())); + /** @var $addressForm Mage_Customer_Model_Form */ $addressForm = Mage::getModel('customer/form'); $addressForm->setFormCode('adminhtml_customer_address') - ->setEntity($addressModel); + ->setEntity($addressModel) + ->initDefaultValues(); $attributes = $addressForm->getAttributes(); foreach ($attributes as $attribute) { @@ -186,6 +188,7 @@ public function initForm() $addressCollection = $customer->getAddresses(); $this->assign('customer', $customer); $this->assign('addressCollection', $addressCollection); + $form->setValues($addressModel->getData()); $this->setForm($form); return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Cart.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Cart.php index e5655b7572..a1aa43d28f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Cart.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Carts.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Carts.php index b5b8c6019c..4281febb7e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Carts.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Carts.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php index 5c231e7094..cc33cc14a6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php index 06a1b95766..9b336eea3c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Filter/Status.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Filter/Status.php index fc5612b173..a0245b43d4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Filter/Status.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Filter/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Action.php index 03d47cbbb5..9fd29017ee 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Status.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Status.php index a9e0be4945..4fd13bc623 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Status.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Newsletter/Grid/Renderer/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php index 9efe5592cf..f028041df0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -110,13 +110,15 @@ protected function _prepareColumns() )); } - $this->addColumn('action', array( - 'header' => ' ', - 'filter' => false, - 'sortable' => false, - 'width' => '100px', - 'renderer' => 'adminhtml/sales_reorder_renderer_action' - )); + if (Mage::helper('sales/reorder')->isAllow()) { + $this->addColumn('action', array( + 'header' => ' ', + 'filter' => false, + 'sortable' => false, + 'width' => '100px', + 'renderer' => 'adminhtml/sales_reorder_renderer_action' + )); + } return parent::_prepareColumns(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Reviews.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Reviews.php index 9679f2ece3..c07a0e60fd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Reviews.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Reviews.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tag.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tag.php index d07804c3de..716499ae0f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tags.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tags.php index 77e4828614..f7959b89bf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tags.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Tags.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php index bac0345ab3..2ceb1f3892 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -57,12 +57,16 @@ public function getGroupName() } } + /** + * Load Customer Log model + * + * @return Mage_Log_Model_Customer + */ public function getCustomerLog() { if (!$this->_customerLog) { $this->_customerLog = Mage::getModel('log/customer') - ->load($this->getCustomer()->getId()); - + ->loadByCustomer($this->getCustomer()->getId()); } return $this->_customerLog; } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Accordion.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Accordion.php index 28afcc6210..a8cd1356c5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Accordion.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Accordion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Cart.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Cart.php index 6f5a7c98d5..b9c2bc7f87 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Cart.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Grid/Renderer/Item.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Grid/Renderer/Item.php index 40d8c48009..0b76d63e2e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Grid/Renderer/Item.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Grid/Renderer/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Orders.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Orders.php index 862459467c..48187523cb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Orders.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Sales.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Sales.php index 73b013bdf4..fa44c1c009 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Sales.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Sales.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Wishlist.php index 2d21de8602..264101b7d3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php index b731ab8aaa..6fdbf6add5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -203,7 +203,7 @@ protected function _addColumnFilterToCollection($column) $collection->addDaysFilter($value); break; default: - $collection()->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()); + $collection->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition()); break; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist/Grid/Renderer/Description.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist/Grid/Renderer/Description.php index 7c3aa2f209..677449514d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist/Grid/Renderer/Description.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Wishlist/Grid/Renderer/Description.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php index 470fb9d292..926907943e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Boolean.php b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Boolean.php index a614011c61..b5e2e95629 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Boolean.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/File.php b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/File.php index 7fc025cbff..4c114eec5c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/File.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Image.php b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Image.php index 196020e77e..196c8f5f39 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Image.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Form/Element/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php index d9fc6b4044..bfe4474a5c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Filter/Country.php b/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Filter/Country.php index cb2111e5d2..ccd60f65a8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Filter/Country.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Filter/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Renderer/Multiaction.php b/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Renderer/Multiaction.php index 3e003bce4d..8663e9dae6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Renderer/Multiaction.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Grid/Renderer/Multiaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group.php index 148a3e0338..44cd213d24 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php index b550354f78..237c262b5f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php index 4514f83bf4..d442aa3b36 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Grid.php index f26db7f44b..e037431450 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online.php index 08525b6e2c..9bd2b8b722 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Filter.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Filter.php index 3acb2cb9c8..097ff27059 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Filter.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php index 759cf59589..a01fad94eb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Ip.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Ip.php index 2847e2f609..a86421137a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Ip.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Ip.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Type.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Type.php index 9e73127394..1d6930a59d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Type.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Url.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Url.php index 4a8246fa08..1cb7bab9ef 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Url.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid/Renderer/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard.php b/app/code/core/Mage/Adminhtml/Block/Dashboard.php index 3dd97a629f..d9fb3919ab 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Abstract.php index 111b20bbd3..93ccbd1bd4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Bar.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Bar.php index 749e8f430c..2de2302f52 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Bar.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Bar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Diagrams.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Diagrams.php index 8baefc8e47..f69318ed19 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Diagrams.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Diagrams.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php index e4da7cf8ea..873242dd40 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Grid.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Grid.php index 3bbb352117..f101d7440d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Grids.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Grids.php index 911cf7b52e..0f00305e00 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Grids.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Grids.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php index b32ddd19da..fcb6ced829 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -43,6 +43,9 @@ public function __construct() protected function _prepareCollection() { + if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) { + return $this; + } $collection = Mage::getResourceModel('reports/order_collection') ->addItemCountExpr() ->joinCustomerName('customer') diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Sales.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Sales.php index 18ada207db..2941ab8d0f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Sales.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Sales.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,6 +44,9 @@ protected function _construct() protected function _prepareLayout() { + if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) { + return $this; + } $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group'); $collection = Mage::getResourceModel('reports/order_collection') diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Last.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Last.php index 0192918b49..be3fcb3827 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Last.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Last.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,6 +44,9 @@ public function __construct() protected function _prepareCollection() { + if (!Mage::helper('core')->isModuleEnabled('Mage_CatalogSearch')) { + return parent::_prepareCollection(); + } $this->_collection = Mage::getModel('catalogsearch/query') ->getResourceCollection(); $this->_collection->setRecentQueryFilter(); diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Renderer/Searchquery.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Renderer/Searchquery.php index b09868bed7..3dce83ab43 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Renderer/Searchquery.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Renderer/Searchquery.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Top.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Top.php index 415cff9ef9..61ed0d554a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Top.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Searches/Top.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,6 +44,9 @@ public function __construct() protected function _prepareCollection() { + if (!Mage::helper('core')->isModuleEnabled('Mage_CatalogSearch')) { + return parent::_prepareCollection(); + } $this->_collection = Mage::getModel('catalogsearch/query') ->getResourceCollection(); @@ -70,7 +73,7 @@ protected function _prepareColumns() $this->addColumn('search_query', array( 'header' => $this->__('Search Term'), 'sortable' => false, - 'index' => 'query_text', + 'index' => 'name', 'renderer' => 'adminhtml/dashboard_searches_renderer_searchquery', )); diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php index 313a4d7844..a60b5f4523 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Most.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Most.php index 51c35a1fd8..61bd2cde3c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Most.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Most.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Newest.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Newest.php index 73193b78ad..d5e23d300f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Newest.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Customers/Newest.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php index 2c6fe207e5..0d3ae3914f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Ordered.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Ordered.php index 0d06fe5daf..753436aea9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Ordered.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Ordered.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -43,6 +43,9 @@ public function __construct() protected function _prepareCollection() { + if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) { + return $this; + } if ($this->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); $storeId = array_pop($storeIds); diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Viewed.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Viewed.php index 0012898e4b..3e304a04be 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Viewed.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php index 149a524ae1..0741865246 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,12 +37,14 @@ class Mage_Adminhtml_Block_Dashboard_Totals extends Mage_Adminhtml_Block_Dashboa protected function _construct() { parent::_construct(); - $this->setTemplate('dashboard/totalbar.phtml'); } protected function _prepareLayout() { + if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) { + return $this; + } $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group'); $period = $this->getRequest()->getParam('period', '24h'); diff --git a/app/code/core/Mage/Adminhtml/Block/Denied.php b/app/code/core/Mage/Adminhtml/Block/Denied.php index f29003593f..16693aed65 100644 --- a/app/code/core/Mage/Adminhtml/Block/Denied.php +++ b/app/code/core/Mage/Adminhtml/Block/Denied.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Html/Date.php b/app/code/core/Mage/Adminhtml/Block/Html/Date.php index 20b32d9540..923dd44788 100644 --- a/app/code/core/Mage/Adminhtml/Block/Html/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Html/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Html/Select.php b/app/code/core/Mage/Adminhtml/Block/Html/Select.php index 167e161a80..7c9e6f0008 100644 --- a/app/code/core/Mage/Adminhtml/Block/Html/Select.php +++ b/app/code/core/Mage/Adminhtml/Block/Html/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Media/Editor.php b/app/code/core/Mage/Adminhtml/Block/Media/Editor.php index 96983ebafb..232a139185 100644 --- a/app/code/core/Mage/Adminhtml/Block/Media/Editor.php +++ b/app/code/core/Mage/Adminhtml/Block/Media/Editor.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php b/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php index 42d2f630b6..1eff3369e0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php +++ b/app/code/core/Mage/Adminhtml/Block/Media/Uploader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Messages.php b/app/code/core/Mage/Adminhtml/Block/Messages.php index 8545383945..87546c9489 100644 --- a/app/code/core/Mage/Adminhtml/Block/Messages.php +++ b/app/code/core/Mage/Adminhtml/Block/Messages.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem.php index 7e50c298cb..8339ac5641 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid.php index a14eb219a4..1374d377c8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Filter/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Filter/Checkbox.php index 0f4e17f7e6..bb10bace3a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Filter/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Filter/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Renderer/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Renderer/Checkbox.php index fc61ef680c..8e4d0238e5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Renderer/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Problem/Grid/Renderer/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue.php index 9b7e8f1427..43dfeff276 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php index 3a89d46e07..ee61b385dc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php index 3627630d43..c22aa8d20f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid.php index 04647b211f..0b81e32d02 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid/Renderer/Action.php index b5bdbbc7ad..b0d3360147 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview.php index 94d74baec9..111dcbbea8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php index c059d74119..5939a0c203 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Queue/Preview/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber.php index 2f3a9d14da..12d40e1dd5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php index db191aef5b..2dd73df121 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Checkbox.php index 2feb8e039e..b154ea8433 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Website.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Website.php index 79b3e1be90..458ea12e84 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Website.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Filter/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Renderer/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Renderer/Checkbox.php index 3c401259d4..66e841e03c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Renderer/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid/Renderer/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template.php index e88d300ba8..7291521675 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php index a53b04b52c..50205e187f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit/Form.php index e5ea7905bd..368c0cea03 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php index 3d4bf52aa8..fbcb522c12 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php index c01081d910..8e6b4ec483 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Sender.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Sender.php index 80c6032a1c..8f5bb82d78 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Sender.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Sender.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview.php index f58ddf2cd9..b0ec65ceb5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview/Form.php b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview/Form.php index 07f7e90561..ef39ea765f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Preview/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Baseurl.php b/app/code/core/Mage/Adminhtml/Block/Notification/Baseurl.php index f7389f2578..299f55c4c3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Baseurl.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Baseurl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Grid.php b/app/code/core/Mage/Adminhtml/Block/Notification/Grid.php index 12b8e7a6b6..3c170c62fe 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php index d583045f3e..5bcbd6ac90 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Actions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Notice.php b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Notice.php index c3c4e972e2..6243ddf030 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Notice.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Notice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php index 21dcf061e3..74850b8ad7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Inbox.php b/app/code/core/Mage/Adminhtml/Block/Notification/Inbox.php index b64482c85e..45004eeb92 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Inbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Inbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Security.php b/app/code/core/Mage/Adminhtml/Block/Notification/Security.php index 3eff53ff43..9459a83045 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Security.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Security.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php b/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php index 8d80b3e7e8..d613cd9d5b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Survey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Toolbar.php b/app/code/core/Mage/Adminhtml/Block/Notification/Toolbar.php index 214ae8db96..c490c08bb7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Toolbar.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Toolbar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php index 15548538ba..d5c3fe2c90 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page.php b/app/code/core/Mage/Adminhtml/Block/Page.php index c9a27711be..e94d14d789 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page.php +++ b/app/code/core/Mage/Adminhtml/Block/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Footer.php b/app/code/core/Mage/Adminhtml/Block/Page/Footer.php index dfc76a9667..75b3dd56b6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Footer.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Footer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Head.php b/app/code/core/Mage/Adminhtml/Block/Page/Head.php index 506a34b7e1..73c7e73c11 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Head.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Head.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Header.php b/app/code/core/Mage/Adminhtml/Block/Page/Header.php index 6519097192..4976a165a2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Header.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php index 89ecd881c2..f92f9af252 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Notices.php b/app/code/core/Mage/Adminhtml/Block/Page/Notices.php index c78194d378..4b9c4a9956 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Notices.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Notices.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Buttons.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Buttons.php index c34507a857..776cda97f5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Buttons.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Buttons.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Editroles.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Editroles.php index 5b5e307953..659674dfbc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Editroles.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Editroles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Edituser.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Edituser.php index dc5caec5f2..8269e32938 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Edituser.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Edituser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/Role.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/Role.php index 1169cf2c4e..7d46139773 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/Role.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/Role.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/User.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/User.php index 8766847a27..cf6bd8e279 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/User.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Grid/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Role.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Role.php index a6cc290ef4..ac4619967c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Role.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Role.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Role/Grid/User.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Role/Grid/User.php index e763e883c7..a923281261 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Role/Grid/User.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Role/Grid/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Roles.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Roles.php index 1e00b90b5d..949593c76c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Roles.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Roles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Roleinfo.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Roleinfo.php index 9092cee197..81f589735b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Roleinfo.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Roleinfo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php index 83e258f814..d325516c52 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesusers.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesusers.php index a13f172b0d..dc21eb4146 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesusers.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesusers.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Useredit.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Useredit.php index 5ea476a802..32d858cb87 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Useredit.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Useredit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Permissions_Tab_Useredit extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Userroles.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Userroles.php index adfa1ae9e4..09f5b915d3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Userroles.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Userroles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Permissions_Tab_Userroles extends Mage_Adminhtml_Block_Widget_Tabs diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User.php index 1d283f5c44..b97b911e14 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit.php index 6e90344720..2fadbc09c4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Form.php index 33293e55fd..30a834336f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php index 2887bc0d1b..f652934a07 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php index a172485584..536bb7548d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tabs.php index 53317a8316..1fe8683554 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Grid.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Grid.php index 9f4629490c..5b5390dd8e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Usernroles.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Usernroles.php index f6de230cc9..d4781cacf9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Usernroles.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Usernroles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Permissions_UsernRoles extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/Users.php b/app/code/core/Mage/Adminhtml/Block/Permissions/Users.php index 86a7db7321..96468d2610 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/Users.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/Users.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit.php b/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit.php index e56e95ebf3..1d24d7b1ea 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit/Form.php index eb6dabf25c..9d81d4685c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Answer/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit.php index 6154ee61b8..e812468a68 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Form.php index e519685611..51bc2dc972 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers.php index 209d59e4dd..5935a96294 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Form.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Form.php index b3e04c45f7..b24d5c6159 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Grid.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Grid.php index ec8c54976e..c77ebde300 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/List.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/List.php index f7c9005450..2d48ba2bc9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/List.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Answers/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Form.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Form.php index 0a63aa1739..ed3efdd119 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tab/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tabs.php index 2f96955bab..d02f02edd9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Grid.php b/app/code/core/Mage/Adminhtml/Block/Poll/Grid.php index 3760998ba0..40fefe9533 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -82,17 +82,19 @@ protected function _prepareColumns() 'header' => Mage::helper('poll')->__('Date Posted'), 'align' => 'left', 'width' => '120px', - 'type' => 'date', + 'type' => 'datetime', 'index' => 'date_posted', + 'format' => Mage::app()->getLocale()->getDateFormat() )); $this->addColumn('date_closed', array( 'header' => Mage::helper('poll')->__('Date Closed'), 'align' => 'left', 'width' => '120px', - 'type' => 'date', + 'type' => 'datetime', 'default' => '--', 'index' => 'date_closed', + 'format' => Mage::app()->getLocale()->getDateFormat() )); if (!Mage::app()->isSingleStoreMode()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Poll/Poll.php b/app/code/core/Mage/Adminhtml/Block/Poll/Poll.php index c2ba57e4d5..2c4c21c6d0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Poll/Poll.php +++ b/app/code/core/Mage/Adminhtml/Block/Poll/Poll.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog.php index 0126c61d6b..2bc43d8d5c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit.php index 145f3cedd9..031613e463 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Form.php index 5fcb9f099c..d4fdd4c99d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php index f2b123e9ec..964eed53ba 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Conditions.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Conditions.php index 415d365cbb..25919f135f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Conditions.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Conditions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php index eb983bed8a..cc60d2e9c3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -80,7 +80,6 @@ protected function _prepareForm() { $model = Mage::registry('current_promo_catalog_rule'); - //$form = new Varien_Data_Form(array('id' => 'edit_form1', 'action' => $this->getData('action'), 'method' => 'post')); $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('rule_'); @@ -195,6 +194,8 @@ protected function _prepareForm() $this->setForm($form); + Mage::dispatchEvent('adminhtml_promo_catalog_edit_tab_main_prepare_form', array('form' => $form)); + return parent::_prepareForm(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tabs.php index 0b5685ca9d..f901abd925 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Grid.php b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Grid.php index 604bcdbba3..3aa5404338 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote.php index ba9f0a3461..4c5a0c8d79 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit.php index 36525a8725..51975499af 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Form.php index eea713d732..61bbd7d5da 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php index c3a4d3d019..194f8faa68 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Conditions.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Conditions.php index 83b3dbf0b9..50f8136938 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Conditions.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Conditions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php index 60b9e29464..1d689c5fb4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Labels.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php index b87eaa5826..d455aeec95 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tabs.php index da967428c8..d2a07abcc4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php index 0fe29133b0..1240a0e71c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser.php b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser.php index 8f35a68585..098611debf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php index 7991b6cc49..b8660d8fdf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Daterange.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Sku.php b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Sku.php index 11014c7252..f4f33c6501 100644 --- a/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Sku.php +++ b/app/code/core/Mage/Adminhtml/Block/Promo/Widget/Chooser/Sku.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit.php index f81c19343e..cbfdec826b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Form.php index 9ddf8ae9df..9a05c7a3b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php index 4836672bb6..ac72698a66 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Options.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Options.php index dda310937f..f7daf0c4d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Options.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tabs.php index 8c68243a52..4d5a54bc19 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php b/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php index 547d19be64..3e604d5807 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Rating.php b/app/code/core/Mage/Adminhtml/Block/Rating/Rating.php index 3c7b7e2f9f..06874e3998 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Rating.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Rating.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/MtdStart.php b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/MtdStart.php index 377ee7d867..224f1e951f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/MtdStart.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/MtdStart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php index 3e455825fd..612ce30826 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Config/Form/Field/YtdStart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts.php index 71afb08369..01595fa742 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts/Grid.php index 7a5bc533ce..f26f477a27 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Accounts/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders.php index 376fbe7fe1..28e0040e32 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders/Grid.php index c1d8eb4407..77983e86af 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Orders/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals.php index f7c4d16c85..206fee93d0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals/Grid.php index eaaf0b9ad3..a7eea5f854 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Customer/Totals/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Filter/Form.php b/app/code/core/Mage/Adminhtml/Block/Report/Filter/Form.php index ce08a84c73..f1eb36febd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Filter/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Filter/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php index 0251f219bb..5ff312f714 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -131,7 +131,7 @@ protected function _prepareCollection() } else if(0 !== sizeof($this->_defaultFilter)) { $this->_setFilterValues($this->_defaultFilter); } - + /** @var $collection Mage_Reports_Model_Resource_Report_Collection */ $collection = Mage::getResourceModel('reports/report_collection'); $collection->setPeriod($this->getFilter('report_period')); @@ -162,6 +162,19 @@ protected function _prepareCollection() } elseif ($this->getRequest()->getParam('group')){ $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); } + + // By default storeIds array contains only allowed stores + $allowedStoreIds = array_keys(Mage::app()->getStores()); + // And then array_intersect with post data for prevent unauthorized stores reports + $storeIds = array_intersect($allowedStoreIds, $storeIds); + // If selected all websites or unauthorized stores use only allowed + if (empty($storeIds)) { + $storeIds = $allowedStoreIds; + } + // reset array keys + $storeIds = array_values($storeIds); + + $collection->setStoreIds($storeIds); if ($this->getSubReportSize() !== null) { @@ -432,7 +445,11 @@ public function getCsv() $data = array('"'.$_index.'"'); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { - $data[] = '"'.str_replace(array('"', '\\'), array('""', '\\\\'), $column->getRowField($_subItem)).'"'; + $data[] = '"' . str_replace( + array('"', '\\'), + array('""', '\\\\'), + $column->getRowField($_subItem) + ) . '"'; } } $csv.= implode(',', $data)."\n"; @@ -582,11 +599,14 @@ public function getCurrentCurrencyCode() { if (is_null($this->_currentCurrencyCode)) { if ($this->getRequest()->getParam('store')) { - $this->_currentCurrencyCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getBaseCurrencyCode(); + $store = $this->getRequest()->getParam('store'); + $this->_currentCurrencyCode = Mage::app()->getStore($store)->getBaseCurrencyCode(); } else if ($this->getRequest()->getParam('website')){ - $this->_currentCurrencyCode = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getBaseCurrencyCode(); + $website = $this->getRequest()->getParam('website'); + $this->_currentCurrencyCode = Mage::app()->getWebsite($website)->getBaseCurrencyCode(); } else if ($this->getRequest()->getParam('group')){ - $this->_currentCurrencyCode = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getWebsite()->getBaseCurrencyCode(); + $group = $this->getRequest()->getParam('group'); + $this->_currentCurrencyCode = Mage::app()->getGroup($group)->getWebsite()->getBaseCurrencyCode(); } else { $this->_currentCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php index 4079a5736f..5abf5fe5f9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -98,7 +98,10 @@ public function addColumn($columnId, $column) $filterFieldId = $k; $filterFieldValue = $v; } - if (!$filterData->hasData($filterFieldId) || $filterData->getData($filterFieldId) != $filterFieldValue) { + if ( + !$filterData->hasData($filterFieldId) || + $filterData->getData($filterFieldId) != $filterFieldValue + ) { return $this; // don't add column } } @@ -106,6 +109,33 @@ public function addColumn($columnId, $column) return parent::addColumn($columnId, $column); } + /** + * Get allowed store ids array intersected with selected scope in store switcher + * + * @return array + */ + protected function _getStoreIds() + { + $filterData = $this->getFilterData(); + if ($filterData) { + $storeIds = explode(',', $filterData->getData('store_ids')); + } else { + $storeIds = array(); + } + // By default storeIds array contains only allowed stores + $allowedStoreIds = array_keys(Mage::app()->getStores()); + // And then array_intersect with post data for prevent unauthorized stores reports + $storeIds = array_intersect($allowedStoreIds, $storeIds); + // If selected all websites or unauthorized stores use only allowed + if (empty($storeIds)) { + $storeIds = $allowedStoreIds; + } + // reset array keys + $storeIds = array_values($storeIds); + + return $storeIds; + } + protected function _prepareCollection() { $filterData = $this->getFilterData(); @@ -116,10 +146,12 @@ protected function _prepareCollection() return parent::_prepareCollection(); } + $storeIds = $this->_getStoreIds();; + $resourceCollection = Mage::getResourceModel($this->getResourceCollectionName()) ->setPeriod($filterData->getData('period_type')) ->setDateRange($filterData->getData('from', null), $filterData->getData('to', null)) - ->addStoreFilter(explode(',', $filterData->getData('store_ids'))) + ->addStoreFilter($storeIds) ->addOrderStatusFilter($filterData->getData('order_statuses')) ->setAggregatedColumns($this->_getAggregatedColumns()); @@ -145,7 +177,7 @@ protected function _prepareCollection() $totalsCollection = Mage::getResourceModel($this->getResourceCollectionName()) ->setPeriod($filterData->getData('period_type')) ->setDateRange($filterData->getData('from', null), $filterData->getData('to', null)) - ->addStoreFilter(explode(',', $filterData->getData('store_ids'))) + ->addStoreFilter($storeIds) ->addOrderStatusFilter($filterData->getData('order_statuses')) ->setAggregatedColumns($this->_getAggregatedColumns()) ->isTotals(true); @@ -168,7 +200,7 @@ public function getCountTotals() $totalsCollection = Mage::getResourceModel($this->getResourceCollectionName()) ->setPeriod($filterData->getData('period_type')) ->setDateRange($filterData->getData('from', null), $filterData->getData('to', null)) - ->addStoreFilter(explode(',', $filterData->getData('store_ids'))) + ->addStoreFilter($this->_getStoreIds()) ->addOrderStatusFilter($filterData->getData('order_statuses')) ->setAggregatedColumns($this->_getAggregatedColumns()) ->isTotals(true); @@ -190,7 +222,7 @@ public function getSubTotals() $subTotalsCollection = Mage::getResourceModel($this->getResourceCollectionName()) ->setPeriod($filterData->getData('period_type')) ->setDateRange($filterData->getData('from', null), $filterData->getData('to', null)) - ->addStoreFilter(explode(',', $filterData->getData('store_ids'))) + ->addStoreFilter($this->_getStoreIds()) ->addOrderStatusFilter($filterData->getData('order_statuses')) ->setAggregatedColumns($this->_getAggregatedColumns()) ->isSubTotals(true); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Blanknumber.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Blanknumber.php index 4b0f6165ef..112f47439e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Blanknumber.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Blanknumber.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Currency.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Currency.php index 0305b3b294..c22a7d3ba0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Currency.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Currency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Customer.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Customer.php index 44e2b2ca11..e0aff6071f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -46,7 +46,7 @@ public function render(Varien_Object $row) $id = $row->getCustomerId(); if (!$id) { - return ' '; + return Mage::helper('adminhtml')->__('Show Reviews'); } return sprintf('%s', diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Product.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Product.php index 1843c88a23..7eb1feffde 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid/Column/Renderer/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product.php b/app/code/core/Mage/Adminhtml/Block/Report/Product.php index abdbe6b5c3..60dc8165a5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads.php index 79c90682db..f51c98abe6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Grid.php index 0f23419097..d6f18bc54a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Renderer/Purchases.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Renderer/Purchases.php index ad050307f7..cb0f6f5aa3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Renderer/Purchases.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Downloads/Renderer/Purchases.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Grid.php index acb1c62247..273aacc768 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock.php index 9623257d56..eb2bf0400e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock/Grid.php index 97ee072f9c..a2ec8ea05b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Lowstock/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -56,6 +56,7 @@ protected function _prepareCollection() $storeId = ''; } + /** @var $collection Mage_Reports_Model_Resource_Product_Lowstock_Collection */ $collection = Mage::getResourceModel('reports/product_lowstock_collection') ->addAttributeToSelect('*') ->setStoreId($storeId) @@ -63,7 +64,7 @@ protected function _prepareCollection() ->joinInventoryItem('qty') ->useManageStockFilter($storeId) ->useNotifyStockQtyFilter($storeId) - ->setOrder('qty', 'asc'); + ->setOrder('qty', Varien_Data_Collection::SORT_ORDER_ASC); if( $storeId ) { $collection->addStoreFilter($storeId); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered.php index 13251b7751..9a12b17184 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered/Grid.php index 191301b63f..0fef9ee102 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold.php index 066751de49..8fbc99b6f9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php index 7889b7bb1c..59088840bf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed.php index 8051dfd30d..849f69b9fa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed/Grid.php index bbbd76ee6f..11a85d8d2e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics.php b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics.php index 9bb9d9c39b..9b5dd97be9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php index 6bb739ac67..d93da70851 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Refresh/Statistics/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer.php index 12b3a55c02..b20a71df89 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php index d52c427bfb..c618dd53dd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail.php index 1b7e027fb4..f624385857 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail/Grid.php index b4aca5eeaa..e3569b8d57 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Detail/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product.php index 2083309e17..360cbb6e3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php index 68860d843c..7bf61a6dc1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Review/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers.php index 7ae30625bc..bd698abf33 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers/Grid.php index 2eeab79992..47d624efdc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons.php index d728a93fc7..e5db6c62ad 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php index b0d0489666..8395552ab3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,9 +44,11 @@ public function __construct() public function getResourceCollectionName() { - return ($this->getFilterData()->getData('report_type') == 'updated_at_order') - ? 'salesrule/report_updatedat_collection' - : 'salesrule/report_collection'; + if (($this->getFilterData()->getData('report_type') == 'updated_at_order')) { + return 'salesrule/report_updatedat_collection'; + } else { + return 'salesrule/report_collection'; + } } protected function _prepareColumns() diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php index f5900d5e72..ae4215a60b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Grid/Column/Renderer/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced.php index 88bd09e732..8b8f7c22bf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced/Grid.php index 62036d1c71..5576ddb4b7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Invoiced/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded.php index 40a60fad7b..ab1993e929 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded/Grid.php index 338a799da1..4396f61189 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Refunded/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales.php index a5fa32bf5b..7042f7a1e0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php index c0a3886f17..9e9a77fc64 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping.php index 8b9c819294..0fc5268266 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping/Grid.php index 70bbb7471f..340706fdea 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Shipping/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax.php index 34742176e7..b35c1d3541 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax/Grid.php index 6193922cfd..47a3274b3c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Sales/Tax/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Search.php b/app/code/core/Mage/Adminhtml/Block/Report/Search.php index 3fd1611a98..091e07e991 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Search.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Search.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php index be0114a915..a56108e55a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Search/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned.php index 5f2285583d..bbc3a541cd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php index 8b6a6a65f9..77ae5f118c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Abandoned/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -52,6 +52,7 @@ protected function _prepareCollection() $storeIds = ''; } + /** @var $collection Mage_Reports_Model_Resource_Quote_Collection */ $collection = Mage::getResourceModel('reports/quote_collection'); $filter = $this->getParam($this->getVarNameFilter(), array()); diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer.php index 8c983a4604..998eeb0b79 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer/Grid.php index 294dd64544..5ee05b2502 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product.php index 6402b251a2..36d53d01aa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product/Grid.php index 8c851045b2..b57898b6b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Shopcart/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -42,10 +42,10 @@ public function __construct() protected function _prepareCollection() { - /** @var $collection Mage_Reports_Model_Mysql4_Quote_Collection */ + /** @var $collection Mage_Reports_Model_Resource_Quote_Collection */ $collection = Mage::getResourceModel('reports/quote_collection'); $collection->prepareForProductsInCarts() - ->setSelectCountSqlType(Mage_Reports_Model_Mysql4_Quote_Collection::SELECT_COUNT_SQL_TYPE_CART); + ->setSelectCountSqlType(Mage_Reports_Model_Resource_Quote_Collection::SELECT_COUNT_SQL_TYPE_CART); $this->setCollection($collection); return parent::_prepareCollection(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer.php index 40c96831ec..86fb450b06 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail.php index 7fca61c1c6..e3456a27d0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail/Grid.php index 8b1ed8bc17..e5354c6ccd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Detail/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php index e35ac14d9f..005102ab28 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular.php index 19c65357f9..1fbe023344 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail.php index 0f3fd1fd36..4f27b64108 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail/Grid.php index df4375c7f1..66de6ca950 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Detail/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php index 026a41a659..28d53c80c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Popular/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product.php index 843a3075cd..a009c78247 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail.php index ea9ec44428..d6fbe731e7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail/Grid.php index 565689624b..76a6a6f7b1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Detail/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php index 408a310d79..ad882d6e31 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Tag/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Report/Wishlist.php index 26ef52d9ad..1a7b2a5a73 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Wishlist/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Wishlist/Grid.php index cf8775fe67..5b10850203 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Wishlist/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Wishlist/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Add.php b/app/code/core/Mage/Adminhtml/Block/Review/Add.php index 924dc0d9fa..f13f2b4861 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Add.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Add.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Add/Form.php b/app/code/core/Mage/Adminhtml/Block/Review/Add/Form.php index cb357e9f37..692889cd7b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Add/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Add/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Edit.php b/app/code/core/Mage/Adminhtml/Block/Review/Edit.php index 8e4c718440..95421c77a2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php index ecb969cfb7..40df93c846 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Grid.php b/app/code/core/Mage/Adminhtml/Block/Review/Grid.php index 3332e7eeab..d1296c7b45 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -73,6 +73,7 @@ protected function _prepareColumns() ->load() ->toOptionArray(); + $tmpArr = array(); foreach( $statuses as $key => $status ) { $tmpArr[$status['value']] = $status['label']; } @@ -93,7 +94,7 @@ protected function _prepareColumns() 'type' => 'datetime', 'width' => '100px', 'filter_index' => 'rt.created_at', - 'index' => 'created_at', + 'index' => 'review_created_at', )); if( !Mage::registry('usePendingFilter') ) { diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Grid/Filter/Type.php b/app/code/core/Mage/Adminhtml/Block/Review/Grid/Filter/Type.php index 8458ee3466..cf34ee79d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Grid/Filter/Type.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Grid/Filter/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Grid/Renderer/Type.php b/app/code/core/Mage/Adminhtml/Block/Review/Grid/Renderer/Type.php index fae2789a7c..7e7069d010 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Grid/Renderer/Type.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Grid/Renderer/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Main.php b/app/code/core/Mage/Adminhtml/Block/Review/Main.php index 7c34298e63..742d3d2362 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Review/Product/Grid.php index b6980dc002..e035732cb9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php index 9ae71d4d98..88b19ff4fc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Detailed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Summary.php b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Summary.php index 476f51921f..ff17881e2a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Review/Rating/Summary.php +++ b/app/code/core/Mage/Adminhtml/Block/Review/Rating/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales.php b/app/code/core/Mage/Adminhtml/Block/Sales.php index a4775882a5..d0dc61ab79 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo.php b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo.php index e64330acaf..121a29d7ef 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php index 1ff183fbf8..fa384cdc9e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice.php b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice.php index 4a07c1e57e..96f3c910e4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php index 3995f67283..710da8e281 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php index 62b203e2eb..090d885557 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Default.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Default.php index 84cc378fae..6c3a2d0d0f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name.php index 944938257c..28d240c68d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name/Grouped.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name/Grouped.php index 2497996d61..a216d92eeb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name/Grouped.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Qty.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Qty.php index fa230fa381..6a5294d9cc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Qty.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Qty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Configurable.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Configurable.php index c1c3cc94f8..e7d281dc70 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Configurable.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Default.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Default.php index e9d6eecb81..6f17e08eba 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Renderer/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php index 59f25fd065..0fd7c73a65 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Abstract.php index ee68b52878..2a8fc01847 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address.php index f6d43fc28a..7e2d6adb0b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address/Form.php index e3ed841888..146763e76a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Address/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php index 6ff93efd46..6797628963 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php index 3c202d9563..9c54b053a7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Abstract.php index 8c6d3ef840..9c32d7bba5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address.php index 1c8c3a1504..a49ff5fa45 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method.php index b869482bf8..736402dc9b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php index 247390b730..2982c55dfa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Method/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Comment.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Comment.php index 2a2bcbd016..a239828b67 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Comment.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Comment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons.php index 8ca4b7b094..a86a02662e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons/Form.php index ee83d19112..5d25132133 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Coupons/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php index 301c3bd2b3..f5378e7675 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer/Grid.php index d8a73ca90f..cfff77a86f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Data.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Data.php index a250b44fda..2ac6f854e3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Data.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form.php index 10be797e46..23b8185290 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php index 531d3116db..15b3ad601c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php index e4d8f5d66c..614ce10ecb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Account.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php index 6aafd20956..6b2761a828 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage.php index 4598ca5ac4..3d63baa322 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php index 8df02e3222..0f09b3f239 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Header.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Header.php index dd700ff6db..12eb496226 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Header.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items.php index 6aa72eced8..567ab9f3e9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php index 017f8f6774..d0c2a72339 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Items/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Load.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Load.php index 843c3819db..258812b440 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Load.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Load.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Messages.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Messages.php index ade1e4608f..2fd7e2c3fa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Messages.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Messages.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter.php index 94e65c3abe..d1783117b3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter/Form.php index 8e7edf72c3..623a7cb054 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Newsletter/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search.php index 5c36a2d216..65e54bdd97 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php index c55914c02f..181c4600bc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Giftmessage.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Giftmessage.php index 224ff9f697..0b97fe6518 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Giftmessage.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Giftmessage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Price.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Price.php index 6b9e634fa4..2ba1493ea6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Product.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Product.php index 3e68b13e98..c285f2df9f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Qty.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Qty.php index 4b76678498..206279dd54 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Qty.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid/Renderer/Qty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address.php index 46f9295312..66943f9a97 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method.php index 2b1eaff9e4..264515e056 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method/Form.php index 09bb7d0775..df9fc65a08 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Method/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar.php index 4edfa42576..e8fb64646a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Abstract.php index 0b3c76937a..7a6d76ddf6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Cart.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Cart.php index 11f7f0336f..10e88d1ca7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Cart.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Compared.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Compared.php index b3ba1dbfd4..0cab434d06 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Compared.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Compared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pcompared.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pcompared.php index 046e0c07d8..e9c5cd5e8b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pcompared.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pcompared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pviewed.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pviewed.php index 372f258f9a..f8a0c412ee 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pviewed.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Pviewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Reorder.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Reorder.php index 24b062af48..f26b4ff407 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Reorder.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Reorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Viewed.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Viewed.php index 2959ba282d..65efb3085c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Viewed.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php index 4349215e55..267542eb34 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Sidebar/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,8 @@ * @package Mage_Adminhtml * @author Magento Core Team */ -class Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Wishlist extends Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Abstract +class Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Wishlist + extends Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Abstract { /** * Storage action on selected item @@ -81,7 +82,7 @@ public function getItems() foreach ($items as $item) { $product = $item->getProduct(); $item->setName($product->getName()); - $item->setPrice($product->getPrice()); + $item->setPrice($product->getFinalPrice(1)); $item->setTypeId($product->getTypeId()); } return $items; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store.php index 62f1e0c858..b27de43174 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store/Select.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store/Select.php index 13f4a99080..f18ecbedd9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store/Select.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Store/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals.php index c68231931b..aecf5e35b0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Default.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Default.php index 331e358b7b..6338229c46 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Discount.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Discount.php index 2f68a2ae7a..5fd3546a93 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Discount.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Grandtotal.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Grandtotal.php index 1f1c27a94d..ff2178e61b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Grandtotal.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Grandtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Shipping.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Shipping.php index d596798076..f94d593f25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Shipping.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Subtotal.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Subtotal.php index a6183af62d..40560081c8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Subtotal.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Table.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Table.php index 88dc9bee25..934a90ba12 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Table.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Table.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Tax.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Tax.php index 1f02d5b629..9ca77ed307 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Tax.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Totals/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create.php index 5fe056d260..7a530e58b7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Adjustments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Adjustments.php index 41034023f5..4fe3e0dfbb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Adjustments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Adjustments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create_Adjustments extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Form.php index f25668379c..b103c01d87 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php index 6bbfe2f012..278a495002 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Create/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php index 78d04b047e..3394a2ae5a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php index 2492de9bd7..579ac45f0e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Comments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Comments.php index b3fa868129..fbade9489a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Comments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Comments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Form.php index f8c675a488..9cb807da15 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Items.php index fb483cd94f..4a6951578f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php index 412840121c..0f07e32a45 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create.php index 32b85a3774..7ab923ce02 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Form.php index 300af78603..534797adb9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php index c1b387900b..3eb60db62e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Tracking.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Tracking.php index 40aebffa14..e06451397e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Tracking.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Tracking.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Totals.php index bc269f8512..2461dfd0c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php index 9b37860351..46ffaec1bd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Comments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Comments.php index 215a378263..c3bb5d9eee 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Comments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Comments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Form.php index 743cbbed9e..870c390602 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Items.php index 2e5d87de0e..0a3ed08628 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Payment.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Payment.php index b3ebc1fedb..4b41da94f9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Payment.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create.php index b57e65d0dd..c52ec0e9d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Form.php index b20de86130..8e1c2ccce2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Items.php index 6411998371..b076e9e640 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Tracking.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Tracking.php index ac45fac0b6..cc71e735cf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Tracking.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Tracking.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Tracking/Info.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Tracking/Info.php index 7e1067d0d0..5d2122cb73 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Tracking/Info.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Tracking/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php index 8e5b80e4ae..feec1bdc25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Comments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Comments.php index c1bf261698..ebe389ee51 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Comments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Comments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php index 3f8c34f69d..ce8b0b7f46 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Items.php index 20fb4a3322..02ed083cd1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Tracking.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Tracking.php index b0462a54e0..c16a069449 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Tracking.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Tracking.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status.php index 3d844be38e..314b9bd9df 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign.php index 8b3e5a981e..8475fb8519 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php index 6fd9e15c24..1b303e9673 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Assign/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit.php index 2137179d57..9c120fdc1b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit/Form.php index 29702a0228..a168cc8333 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php index 03854e0ddf..1fa569bad8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New.php index 07a4f51e26..916ecd425c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php index 0d64722607..8ff7e3432c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Status/New/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totalbar.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totalbar.php index eaa9e530f9..7e895b19c6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totalbar.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totalbar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals.php index fab5c6345b..31f69255b8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php index ef39153ddf..4956af823a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Totals/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 fa9c0cfdd6..e36cbafcf2 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -53,19 +53,19 @@ public function getFullTaxInfo() * (In $info tax invalid when invoice is partial) */ /** @var $blockInvoice Mage_Adminhtml_Block_Sales_Order_Invoice_Totals */ - $blockInvoice = $this->getLayout()->getBlock('tax'); +// $blockInvoice = $this->getLayout()->getBlock('tax'); /** @var $invoice Mage_Sales_Model_Order_Invoice */ - $invoice = $blockInvoice->getSource(); - $items = $invoice->getItemsCollection(); +// $invoice = $blockInvoice->getSource(); +// $items = $invoice->getItemsCollection(); $i = 0; /** @var $item Mage_Sales_Model_Order_Invoice_Item */ - foreach ($items as $item) { - $info[$i]['hidden'] = $item->getHiddenTaxAmount(); - $info[$i]['amount'] = $item->getTaxAmount(); - $info[$i]['base_amount'] = $item->getBaseTaxAmount(); - $info[$i]['base_real_amount'] = $item->getBaseTaxAmount(); - $i++; - } +// foreach ($items as $item) { +// $info[$i]['hidden'] = $item->getHiddenTaxAmount(); +// $info[$i]['amount'] = $item->getTaxAmount(); +// $info[$i]['base_amount'] = $item->getBaseTaxAmount(); +// $info[$i]['base_real_amount'] = $item->getBaseTaxAmount(); +// $i++; +// } } return $info; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php index 51e10a53b0..3a923bca61 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Form.php index baae3617a1..3b4ab89523 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php index 56232b9bf1..3c9979b47e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php index e11d37f1fd..bcc7824e8d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php index 7711d20466..e890537526 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php index 528938381b..d87b1f53ef 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php index 17e4c4339b..09f170ccf5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Messages.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Messages.php index 9071846d52..146235cf83 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Messages.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Messages.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php index 2e6c85971e..003b8e2c36 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php index efa07d07f9..17475ec70d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Info.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Info.php index 7ad7631540..48f56b0e64 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Info.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php index 79c38c8a81..4d18b20b94 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php index f8ce60261c..458372ff47 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php index 23df4b038b..2166cb0807 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tabs.php index 8153a940b9..848cf83a3e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Reorder/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Sales/Reorder/Renderer/Action.php index 9814512bb3..59847a79b0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Reorder/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Reorder/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment.php b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment.php index 8e1c3e42e7..b42692a015 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php index 524eb724dc..e9d6ca0b1f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php b/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php index 8b8373d49b..9fd5743d88 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions.php index 99d33c84eb..3f97dff648 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php index 2d562c0940..42328d0d37 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php index 920bd94985..5a3d0b7386 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail/Grid.php index a18292a2ee..14c18a45a8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Grid.php index 0408b20087..e985cdad25 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Shipping/Carrier/Tablerate/Grid.php b/app/code/core/Mage/Adminhtml/Block/Shipping/Carrier/Tablerate/Grid.php index af7d420061..88566f251a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Shipping/Carrier/Tablerate/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Shipping/Carrier/Tablerate/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap.php b/app/code/core/Mage/Adminhtml/Block/Sitemap.php index 5488383e2b..7746a8afc4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit.php index 57de3b2892..490772ced9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php index 9d63b2cca4..443e082bf8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php index e138809f33..841fec3b61 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Action.php index 84a1657c93..3c0772f94a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Link.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Link.php index 68fb971892..da544aff73 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Link.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php index d37c8c70a8..7cbd8999e0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php +++ b/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid/Renderer/Time.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php index 50f1afc38a..ae05eb96e1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit.php index 8efa79fe5c..15ded0aa6f 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php index 1166aac899..c0feba5dbc 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Cache/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Cache/Edit.php index f66ccb4535..d5801a9f88 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Cache/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Cache/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Cache/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Cache/Form.php index 092c30014d..f67966c95e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Cache/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Cache/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Dwstree.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Dwstree.php index ce8cb6bfc3..fb5763cdd2 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Dwstree.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Dwstree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Edit.php index 5fbe3522ce..6b520894dc 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php index 3fc586096f..fe9e6d5795 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php index 55237ee50e..ee39b4190f 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Array/Abstract.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Array/Abstract.php index baac69ec1a..b3491b94dc 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Array/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Array/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php index 2bc7176312..fcd7e9e783 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Datetime.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Export.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Export.php index f8408420a3..07214232b3 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Export.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Export.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/File.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/File.php index e5cd7152fa..70a020954e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/File.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Heading.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Heading.php index 2088a89fd7..30676a9387 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Heading.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Heading.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Image.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Image.php index 70d2f055d5..801918ac60 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Image.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php index 2b929f52b9..3c39041620 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Import.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Notification.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Notification.php index d48bd710f0..395c5ed4d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Notification.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Notification.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Regexceptions.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Regexceptions.php index c382abda69..d2cbe73362 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Regexceptions.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Regexceptions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Allowspecific.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Allowspecific.php index 20e87e12d7..e2d053f4ac 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Allowspecific.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Allowspecific.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatcatalog.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatcatalog.php index 64535f9ba4..33203c33ed 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatcatalog.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatcatalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatproduct.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatproduct.php index 36b9995eaf..5009fe4742 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatproduct.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field/Select/Flatproduct.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php index 87edddb169..e09e6e0f36 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index b9bf78c1ad..c26c626f60 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Order/Statuses.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Order/Statuses.php index 8b0576be4a..2f280752b2 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Order/Statuses.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset/Order/Statuses.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php index 5caa800885..578c564062 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Switcher.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/System/Storage/Media/Synchronize.php b/app/code/core/Mage/Adminhtml/Block/System/Config/System/Storage/Media/Synchronize.php index c5c5d79e97..19ccd4afa6 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/System/Storage/Media/Synchronize.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/System/Storage/Media/Synchronize.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php index 8b639f03eb..7beee409df 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui.php index e9c6b54050..8a737b87ff 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit.php index 4f76afe6ed..8b7e915746 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Form.php index c85a592531..f55accf7d5 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Upload.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Upload.php index 5b395602c1..d44555aa54 100755 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Upload.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Upload.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php index 7e76aabf62..5c001b866e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php index 90bb272768..16d067de7b 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tab/Wizard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tabs.php index e69b134a82..af84495e20 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Grid.php index 3e58e71481..47d4c9dd2b 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Gui/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,7 +44,7 @@ public function __construct() protected function _prepareCollection() { $collection = Mage::getResourceModel('dataflow/profile_collection') - ->addFieldToFilter('entity_type', array('neq'=>'')); + ->addFieldToFilter('entity_type', array('notnull'=>'')); $this->setCollection($collection); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile.php index 71f8d92e38..55546894ab 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit.php index 7d74886e78..44cf0f5287 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Filter/Action.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Filter/Action.php index 7b02f062f6..793fd36832 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Filter/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Filter/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Form.php index 797564f9a5..b11dffbe13 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Renderer/Action.php index 7a7b79b3d8..d09cc1225c 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php index 4214db7450..72555665c7 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/History.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/History.php index dbd8d460a2..69f6c79bbb 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/History.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Run.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Run.php index 0c25ff3fe7..23631303b5 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Run.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tab/Run.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tabs.php index 3f17fa5fa8..4ce76c9443 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Grid.php index 9697672c85..a412ffb04f 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,7 +44,7 @@ public function __construct() protected function _prepareCollection() { $collection = Mage::getResourceModel('dataflow/profile_collection') - ->addFieldToFilter('entity_type', array('eq'=>'')); + ->addFieldToFilter('entity_type', array('null'=>'')); $this->setCollection($collection); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php index 5aecb5b2b6..13931bdf15 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -198,4 +198,3 @@ public function getExceptions() return $exceptions; } } - diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency.php b/app/code/core/Mage/Adminhtml/Block/System/Currency.php index 1db06c443f..da2e944f88 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Form.php index bc35895a2c..17defd51ea 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Main.php index e0d24614bd..d5412d8183 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Rates.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Rates.php index aeab43ffa2..882c00c37a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Rates.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tab/Rates.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tabs.php index 4ef182f759..0ec0581d29 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php index 7247d80ff3..58974f8da0 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php index d714c2057c..22dc55b554 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design.php b/app/code/core/Mage/Adminhtml/Block/System/Design.php index 84350cd8ef..36a8fe25b7 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit.php index f7d811487c..c8a5e6835c 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php index 8e35004dbe..d25aabc19c 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_System_Design_Edit_Tab_General extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tabs.php index 9ea3fda3c1..66c6f13d2a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Design/Grid.php index 86dbf1f22b..c14656cf3e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template.php index b1ae6d4899..439cb935e3 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit.php index 77c8a12cd5..04fecd032b 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php index edbda7fbe3..18537ab2d5 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -187,4 +187,3 @@ public function getVariables() return $variables; } } - diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php index ede1780c5a..635c090696 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Filter/Type.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Filter/Type.php index 97d6189e65..b7b1aeb9cb 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Filter/Type.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Filter/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Action.php index 404ebeb783..f7e800e8f0 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Sender.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Sender.php index 3331da336d..374a69cce8 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Sender.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Sender.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Type.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Type.php index 7050f2323e..ff77ac5efb 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Type.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Grid/Renderer/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Preview.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Preview.php index a124a4bfed..9497ad88e2 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Preview.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Preview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete.php index da023c357c..1e332c7fd6 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Form.php index aad699ae72..09c98ce8ed 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Group.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Group.php index a164dbe306..b09d95f53d 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Website.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Website.php index f2d670b4ea..42aee1a081 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Website.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Delete/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php index c4209e1f9c..f3e72aa850 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php index c613896fdb..6f0a23f5b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid.php index fb70effad1..fcd3670000 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Group.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Group.php index dc9bf69abc..f26806e573 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Store.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Store.php index 9827c94297..4519ee38ba 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Store.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Website.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Website.php index ad57b7cc4c..5fea8dd67e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Website.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Grid/Render/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Store.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Store.php index 083730a4ef..e6ce2d137a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Store.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Variable.php b/app/code/core/Mage/Adminhtml/Block/System/Variable.php index 773527561b..f0731c4620 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Variable.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Variable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit.php index beab426d17..5f7fec40e2 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit/Form.php index fa3626a6d3..780c46695e 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Variable/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Variable/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/System/Variable/Form/Renderer/Fieldset/Element.php deleted file mode 100644 index f8d81b7804..0000000000 --- a/app/code/core/Mage/Adminhtml/Block/System/Variable/Form/Renderer/Fieldset/Element.php +++ /dev/null @@ -1,114 +0,0 @@ - - */ -class Mage_Adminhtml_Block_System_Variable_Form_Renderer_Fieldset_Element extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element -{ - /** - * Initialize block template - */ - protected function _construct() - { - $this->setTemplate('system/variable/form/renderer/fieldset/element.phtml'); - } - - /** - * Check "Use default" checkbox display availability - * - * @return bool - */ - public function canDisplayUseDefault() - { - if ($this->getVariable()->getId() - && $this->getVariable()->getStoreId()) - { - return true; - } - return false; - } - - /** - * Check default value usage fact - * - * @return bool - */ - public function usedDefault() - { - if ($this->getVariable()->getStoreValue() === null) { - return true; - } - return false; - } - - /** - * Disable field in default value using case - * - * @return Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element - */ - public function checkFieldDisable() - { - if ($this->canDisplayUseDefault() && $this->usedDefault()) { - $this->getElement()->setDisabled(true); - } - return $this; - } - - /** - * Retrieve label scope - * - * @return string - */ - public function getScopeLabel() - { - return '[STORE VIEW]'; - } - - /** - * Retrieve element label html - * - * @return string - */ - public function getElementLabelHtml() - { - return $this->getElement()->getLabelHtml(); - } - - /** - * Retrieve element html - * - * @return string - */ - public function getElementHtml() - { - return $this->getElement()->getElementHtml(); - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/System/Variable/Grid.php b/app/code/core/Mage/Adminhtml/Block/System/Variable/Grid.php index da32640daf..6ba3b30c5f 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Variable/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Variable/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag.php b/app/code/core/Mage/Adminhtml/Block/Tag.php index d5ad72f0ed..aecaac9dab 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php index dd3e4ba32b..e4f6a8dd37 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Assigned/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php b/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php index 3177baa19c..2f2a08efd2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php index bccef050b2..2ee941387b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Customer/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php index 7369189627..6891c314aa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php index e1a287bca9..d44ecbf4eb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Accordion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php index 57a525688e..790a6780f3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Assigned.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php index f00e45abc1..420574694e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/All.php b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/All.php index 9d0766cfcb..836a2af2a8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/All.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/All.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Customers.php b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Customers.php index ab52e61582..21386c7a28 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Customers.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Customers.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Pending.php b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Pending.php index 574bf8469b..e3a20562d9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Pending.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Pending.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Products.php b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Products.php index d23df93082..f49d515515 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Products.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Grid/Products.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Pending.php b/app/code/core/Mage/Adminhtml/Block/Tag/Pending.php index 6744703a66..3e3e4ea1a9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Pending.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Pending.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Product.php b/app/code/core/Mage/Adminhtml/Block/Tag/Product.php index 8afe53726b..86a3b25cf4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Product.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php index 0451577f2f..8064060055 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php index a173d62147..0edafe3049 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Store/Switcher.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php index 72c2823a50..abf54ed10b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php index c146c50e88..2381e0f8b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php index 57e7dfc86e..d860f30607 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php index d7ea2c9b3e..0959a74302 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Tag/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Class.php b/app/code/core/Mage/Adminhtml/Block/Tax/Class.php index eb104aa123..f9a70abb30 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Class.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Class.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -42,11 +42,11 @@ public function __construct() public function setClassType($classType) { - if ($classType == 'PRODUCT') { + if ($classType == Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) { $this->_headerText = Mage::helper('tax')->__('Product Tax Classes'); $this->_addButtonLabel = Mage::helper('tax')->__('Add New Class'); } - elseif ($classType == 'CUSTOMER') { + elseif ($classType == Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) { $this->_headerText = Mage::helper('tax')->__('Customer Tax Classes'); $this->_addButtonLabel = Mage::helper('tax')->__('Add New Class'); } diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit.php index ba16a6fd34..38877bf482 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit/Form.php index 3352e93b8d..5219e4f0a4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -52,13 +52,13 @@ protected function _prepareForm() $classType = $this->getClassType(); - $this->setTitle($classType == 'CUSTOMER' + $this->setTitle($classType == Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER ? Mage::helper('cms')->__('Customer Tax Class Information') : Mage::helper('cms')->__('Product Tax Class Information') ); $fieldset = $form->addFieldset('base_fieldset', array( - 'legend' => $classType == 'CUSTOMER' + 'legend' => $classType == Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER ? Mage::helper('tax')->__('Customer Tax Class Information') : Mage::helper('tax')->__('Product Tax Class Information') )); diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Grid.php index a3093fda80..1b41635df2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Class/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Class/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php index 2d1b19b5a2..e38cab87a0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid.php index 0468bdf776..2fceff4122 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Tax_Rate_Grid extends Mage_Adminhtml_Block_Widget_Grid diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Country.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Country.php index e915a383a0..b114afc8d0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Country.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Data.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Data.php index 7092bf8bb4..53563b70ad 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Data.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Grid/Renderer/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/ImportExport.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/ImportExport.php index b76ce6842f..8a7ce77a22 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/ImportExport.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/ImportExport.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title.php index 9b344b0906..1e541c2b4d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title/Fieldset.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title/Fieldset.php index 029a355230..8a86262cfa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title/Fieldset.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Title/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Add.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Add.php index 941a5c8b5d..402b21bf7c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Add.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Add.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Save.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Save.php index 72725a7fe1..72dfd5e9cc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Save.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rate/Toolbar/Save.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rule.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rule.php index b6245bed16..94edbe5924 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rule.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php index 0f17e38d58..34b3f55b98 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit/Form.php index 9cf23bba7d..cfab638cc8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -65,12 +65,12 @@ protected function _prepareForm() $productClasses = Mage::getModel('tax/class') ->getCollection() - ->setClassTypeFilter('PRODUCT') + ->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) ->toOptionArray(); $customerClasses = Mage::getModel('tax/class') ->getCollection() - ->setClassTypeFilter('CUSTOMER') + ->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) ->toOptionArray(); $rates = Mage::getModel('tax/calculation_rate') diff --git a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Grid.php b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Grid.php index cbec4c7ceb..ad6fcb4100 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Tax/Rule/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Block_Tax_Rule_Grid extends Mage_Adminhtml_Block_Widget_Grid @@ -91,7 +91,7 @@ protected function _prepareColumns() 'filter_index' => 'ctc.customer_tax_class_id', 'type' => 'options', 'show_missing_option_values' => true, - 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter('CUSTOMER')->toOptionHash(), + 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER)->toOptionHash(), ) ); @@ -104,7 +104,7 @@ protected function _prepareColumns() 'filter_index' => 'ptc.product_tax_class_id', 'type' => 'options', 'show_missing_option_values' => true, - 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter('PRODUCT')->toOptionHash(), + 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)->toOptionHash(), ) ); diff --git a/app/code/core/Mage/Adminhtml/Block/Template.php b/app/code/core/Mage/Adminhtml/Block/Template.php index 27a9e09af8..da6ffabf23 100644 --- a/app/code/core/Mage/Adminhtml/Block/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Text/List.php b/app/code/core/Mage/Adminhtml/Block/Text/List.php index f9af0dbf79..0d4ca04dd3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Text/List.php +++ b/app/code/core/Mage/Adminhtml/Block/Text/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite.php index 80ea7effb8..f277bd6f18 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Category/Tree.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Category/Tree.php index 683708dd4e..0486837617 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Category/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Category/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php index df3bf4ef2a..9d91f164ce 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php index 24298ec40e..263592220d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -57,9 +57,9 @@ protected function _prepareForm() $form = new Varien_Data_Form( array( - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post' + 'id' => 'edit_form', + 'action' => $this->getData('action'), + 'method' => 'post' ) ); @@ -97,6 +97,7 @@ protected function _prepareForm() 'value' => $model->getIsSystem() )); + $isFilterAllowed = false; // get store switcher or a hidden field with its id if (!Mage::app()->isSingleStoreMode()) { $stores = Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(); @@ -115,7 +116,9 @@ protected function _prepareForm() if ($category && $category->getId()) { $categoryStores = $category->getStoreIds() ? $category->getStoreIds() : array(); $entityStores = array_intersect($entityStores, $categoryStores); + } + $isFilterAllowed = true; } elseif ($category && $category->getId()) { $entityStores = $category->getStoreIds() ? $category->getStoreIds() : array(); if (!$entityStores) { @@ -123,28 +126,27 @@ protected function _prepareForm() $noStoreError = $this->__('Chosen category does not associated with any website, ') . $this->__('so url rewrite is not possible.'); } + $isFilterAllowed = true; } /* * Stores should be filtered only if product and/or category is specified. * If we use custom rewrite, all stores are accepted. */ - if (($product && $product->getId()) || ($category && $category->getId())) { - if ($stores) { - foreach ($stores as $i => $store) { - if (isset($store['value']) && $store['value']) { - $found = false; - foreach ($store['value'] as $_k => $_v) { - if (isset($_v['value']) && in_array($_v['value'], $entityStores)) { - $found = true; - } else { - unset($stores[$i]['value'][$_k]); - } - } - if (!$found) { - unset($stores[$i]); + if ($stores && $isFilterAllowed) { + foreach ($stores as $i => $store) { + if (isset($store['value']) && $store['value']) { + $found = false; + foreach ($store['value'] as $_k => $_v) { + if (isset($_v['value']) && in_array($_v['value'], $entityStores)) { + $found = true; + } else { + unset($stores[$i]['value'][$_k]); } } + if (!$found) { + unset($stores[$i]); + } } } } diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Grid.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Grid.php index 304b8438ac..740deae50a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Link.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Link.php index d197132d00..2d71e09b46 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Link.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Product/Grid.php index dd7a87969d..7a184b8bf9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Product/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Selector.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Selector.php index 6447680f76..f4515f14f1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Selector.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Selector.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget.php b/app/code/core/Mage/Adminhtml/Block/Widget.php index e2c6e00688..af71632e9a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Accordion.php b/app/code/core/Mage/Adminhtml/Block/Widget/Accordion.php index 05ec179f27..e746c1bcd4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Accordion.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Accordion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Accordion/Item.php b/app/code/core/Mage/Adminhtml/Block/Widget/Accordion/Item.php index 85aab31439..bd74b6e2d8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Accordion/Item.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Accordion/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Breadcrumbs.php b/app/code/core/Mage/Adminhtml/Block/Widget/Breadcrumbs.php index 7c025bf8e8..720f419568 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Breadcrumbs.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Breadcrumbs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Button.php b/app/code/core/Mage/Adminhtml/Block/Widget/Button.php index b8f24c50ae..c20e0727df 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Button.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Button.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Container.php b/app/code/core/Mage/Adminhtml/Block/Widget/Container.php index 26f61bfea5..8b3c8557f9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Container.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form.php index 403d22cfa2..16a3a76dd2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php index bb0af66bbf..8756f3ffa6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element.php index 6c9fcfb285..63cc4fe4d5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Dependence.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Dependence.php index 17e27380e9..5f56648ff6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Dependence.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Dependence.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Gallery.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Gallery.php index 78d424092f..d476b06dfb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Gallery.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Element/Gallery.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Element.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Element.php index bd609d6a2f..1cceb8e257 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset.php index 4492507ef6..052538072b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset/Element.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset/Element.php index b0d5d39c09..18037260f2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset/Element.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form/Renderer/Fieldset/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index faea3ad36e..a693d2934d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -461,7 +461,7 @@ protected function _setCollectionOrder($column) if ($collection) { $columnIndex = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex(); - $collection->setOrder($columnIndex, $column->getDir()); + $collection->setOrder($columnIndex, strtoupper($column->getDir())); } return $this; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Block.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Block.php index 72eb80064f..89e504a8fd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Block.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php index 463837cd56..771f95a9f8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Abstract.php index 09624d3fda..a073af3e18 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -64,12 +64,19 @@ public function getEscapedValue($index=null) public function getCondition() { - return array('like'=>'%'.$this->_escapeValue($this->getValue()).'%'); + $helper = Mage::getResourceHelper('core'); + $likeExpression = $helper->addLikeEscape($this->getValue(), array('position' => 'any')); + return array('like' => $likeExpression); } + /** + * @deprecated after 1.5.0.0 + * @param $value + * @return mixed + */ protected function _escapeValue($value) { - return str_replace('_', '\_', $value); + return str_replace('_', '\_', str_replace('\\', '\\\\', $value)); } public function getHtml() diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Checkbox.php index 68b4606c34..3b720cf06d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Country.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Country.php index 330dfff894..36687851e3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Country.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php index 6a5c2627ae..6d11247607 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php index 8a63e383ab..7bd4db33b3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Datetime.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Interface.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Interface.php index 076a789b1f..b50aaed12b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Interface.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Massaction.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Massaction.php index 6229a25e42..ee80e33778 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Massaction.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Massaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Price.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Price.php index 9f58900309..717bea8b12 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Radio.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Radio.php index 4d138eb228..fcaeab469e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Radio.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Radio.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Range.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Range.php index d33c785122..2bfa0c40fb 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Range.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Range.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Select.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Select.php index 54282b0dc0..656080838e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Select.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Store.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Store.php index 81733b65b7..2e6bd8f5e2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Store.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Text.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Text.php index 9551c885e4..705fd08f22 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Text.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Theme.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Theme.php index 24969060a4..c1eed61923 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Theme.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Theme.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php index c5bfdc0c1f..dbef36e50b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php index 47c77ed7a3..5f080fee93 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Checkbox.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Checkbox.php index 1fb3282d2c..2a71abddfd 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Checkbox.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Concat.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Concat.php index 471c01dc1d..02403b06d2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Concat.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Concat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Country.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Country.php index 3e9edadfc5..304035ae45 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Country.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Currency.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Currency.php index 175334ccb0..26d281102c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Currency.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Currency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -49,7 +49,7 @@ class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Currency extends Mage_Adm */ public function render(Varien_Object $row) { - if ($data = $row->getData($this->getColumn()->getIndex())) { + if ($data = (string)$row->getData($this->getColumn()->getIndex())) { $currency_code = $this->_getCurrencyCode($row); if (!$currency_code) { diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php index 81607370ef..395401af1d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php index 0a4db0f9a4..5ed7daeea9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Input.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Input.php index 004e4d834c..b79ebc3fa2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Input.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Input.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Interface.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Interface.php index e6f063c1bc..9fdfa22ace 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Interface.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Ip.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Ip.php index 51774ae382..34336094c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Ip.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Ip.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Longtext.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Longtext.php index 34c65fd092..e8c54f58e8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Longtext.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Longtext.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Massaction.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Massaction.php index c96025dc81..507006e7f6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Massaction.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Massaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Number.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Number.php index 66dab14c73..93473509b9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Number.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Number.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 43fcdf91d6..24c9952b57 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Price.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Price.php index 9153923ad0..abff0f9c9c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Price.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Radio.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Radio.php index 71505c3bc6..6dfd4fe1ff 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Radio.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Radio.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Select.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Select.php index e572f7443c..cf62701875 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Select.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Store.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Store.php index df006f180b..8efbc35ca6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Store.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Text.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Text.php index 82aeb13c62..bbf38f1262 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Text.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Theme.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Theme.php index f61157384a..8cbc546f31 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Theme.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Theme.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Wrapline.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Wrapline.php index e49ce9820e..36cf3bbb6c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Wrapline.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Wrapline.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php index 0e85d04508..50cbe3d10d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction.php index f40d65b60a..ff8b246b07 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php index 762e3f827f..7b794e8fb2 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item.php index d7ad849caa..d472af91a5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Default.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Default.php index 11a2005557..e6042f8bf8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Interface.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Interface.php index 92cec34ed3..d07a8dd253 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Interface.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Item/Additional/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Serializer.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Serializer.php index e04aaeae6e..245f14c9d5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Serializer.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Serializer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tab/Interface.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tab/Interface.php index c109d267ad..a11b346b7b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tab/Interface.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tab/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php index c319dd4d28..ccbe26d7f5 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tree.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tree.php index f3e38c7747..52a15bcc0f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/View/Container.php b/app/code/core/Mage/Adminhtml/Block/Widget/View/Container.php index e02a5bc65f..2969baa413 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/View/Container.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/View/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Controller/Action.php b/app/code/core/Mage/Adminhtml/Controller/Action.php index 9093ed6176..cf716278a1 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Action.php +++ b/app/code/core/Mage/Adminhtml/Controller/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php index fcd9326a20..902fdc47c9 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php +++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php index 8eb8729118..b00902b965 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php +++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php b/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php index f82e3a08ba..22eecfa699 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php +++ b/app/code/core/Mage/Adminhtml/Controller/Sales/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Exception.php b/app/code/core/Mage/Adminhtml/Exception.php index edcada9ee5..aec29c1ea2 100644 --- a/app/code/core/Mage/Adminhtml/Exception.php +++ b/app/code/core/Mage/Adminhtml/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Catalog.php b/app/code/core/Mage/Adminhtml/Helper/Catalog.php index b290844ca7..b428d9816b 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Catalog.php +++ b/app/code/core/Mage/Adminhtml/Helper/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Composite.php b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Composite.php index a9f8c5b3e6..87ff988638 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Composite.php +++ b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Composite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php index 8907d5555d..0c447dbcd6 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -123,7 +123,7 @@ public function getAttributes() { if (is_null($this->_attributes)) { $this->_attributes = Mage::getSingleton('eav/config') - ->getEntityType('catalog_product') + ->getEntityType(Mage_Catalog_Model_Product::ENTITY) ->getAttributeCollection() ->addIsNotUniqueFilter() ->setInAllAttributeSetsFilter($this->getProductsSetIds()); diff --git a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Abstract.php b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Abstract.php index 0f7f9d8e76..7b851d3e7a 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php index 8245d38541..d395d20a49 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php +++ b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Order.php b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Order.php index c5ecea16a6..6789c69855 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Order.php +++ b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Data.php b/app/code/core/Mage/Adminhtml/Helper/Data.php index 43d64fac24..1d319be5eb 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Data.php +++ b/app/code/core/Mage/Adminhtml/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Js.php b/app/code/core/Mage/Adminhtml/Helper/Js.php index 40989f67b4..e3ddc85c74 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Js.php +++ b/app/code/core/Mage/Adminhtml/Helper/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Media/Js.php b/app/code/core/Mage/Adminhtml/Helper/Media/Js.php index 39e1dbf736..9e274513c1 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Media/Js.php +++ b/app/code/core/Mage/Adminhtml/Helper/Media/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Rss.php b/app/code/core/Mage/Adminhtml/Helper/Rss.php index e29a6f8959..1fb9b924ac 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Rss.php +++ b/app/code/core/Mage/Adminhtml/Helper/Rss.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Helper/Sales.php b/app/code/core/Mage/Adminhtml/Helper/Sales.php index b1d7dc63f1..ea23e9312b 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Sales.php +++ b/app/code/core/Mage/Adminhtml/Helper/Sales.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Config.php b/app/code/core/Mage/Adminhtml/Model/Config.php index 9a3ebc1a38..c26edb9c83 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config.php +++ b/app/code/core/Mage/Adminhtml/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php index da7aa83bab..d28d0f7546 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php +++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Renderer/Region.php b/app/code/core/Mage/Adminhtml/Model/Customer/Renderer/Region.php index 9938c7a8f3..7df04959a3 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Renderer/Region.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Renderer/Region.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Email/Template.php b/app/code/core/Mage/Adminhtml/Model/Email/Template.php index a423ed28c3..e0d5034a93 100644 --- a/app/code/core/Mage/Adminhtml/Model/Email/Template.php +++ b/app/code/core/Mage/Adminhtml/Model/Email/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Extension.php b/app/code/core/Mage/Adminhtml/Model/Extension.php index 3be8f4943f..ffbdd1204e 100644 --- a/app/code/core/Mage/Adminhtml/Model/Extension.php +++ b/app/code/core/Mage/Adminhtml/Model/Extension.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php index 625c276669..77116dea28 100644 --- a/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php +++ b/app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator.php b/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator.php index 986a952c37..d9486353c2 100644 --- a/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator.php +++ b/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator/NotProtected.php b/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator/NotProtected.php deleted file mode 100644 index aa42caae76..0000000000 --- a/app/code/core/Mage/Adminhtml/Model/LayoutUpdate/Validator/NotProtected.php +++ /dev/null @@ -1,118 +0,0 @@ - - */ -class Mage_Adminhtml_Model_LayoutUpdate_Validator_NotProtected extends Zend_Validate_Abstract -{ - const XML_INVALID = 'invalidXml'; - const PROTECTED_ATTR_HELPER_IN_TAG_ACTION_VAR = 'protectedAttrHelperInActionVar'; - - /** - * The Varien SimpleXml object - * - * @var Varien_Simplexml_Element - */ - protected $_value; - - /** - * Protected expressions - * - * @var array - */ - protected $_protectedExpressions = array( - self::PROTECTED_ATTR_HELPER_IN_TAG_ACTION_VAR => '//action/*[@helper]', - ); - - /** - * Construct - */ - public function __construct() - { - $this->_initMessageTemplates(); - } - - /** - * Initialize messages templates with translating - * - * @return Mage_Adminhtml_Model_LayoutUpdate_Validator_NotProtected - */ - protected function _initMessageTemplates() - { - if (!$this->_messageTemplates) { - $this->_messageTemplates = array( - self::PROTECTED_ATTR_HELPER_IN_TAG_ACTION_VAR => - Mage::helper('adminhtml')->__('Helper attributes should not be used in custom layout updates.'), - self::XML_INVALID => Mage::helper('adminhtml')->__('XML data is invalid.'), - ); - } - return $this; - } - - /** - * Check on the validity - * - * @throws Mage_Core_Exception Throw exception when xml object is not - * instance of Varien_Simplexml_Element - * @param Varien_Simplexml_Element|string $value - * @return bool - */ - public function isValid($value) - { - if (is_string($value)) { - $value = trim($value); - try { - //wrap XML value in the "config" tag because config cannot - //contain multiple root tags - $value = new Varien_Simplexml_Element('' . $value . ''); - } catch (Exception $e) { - $this->_error(self::XML_INVALID); - return false; - } - } elseif (!($value instanceof Varien_Simplexml_Element)) { - throw new Exception( - Mage::helper('adminhtml')->__('XML object is not instance of "Varien_Simplexml_Element".')); - } - - $this->_setValue($value); - - foreach ($this->_protectedExpressions as $key => $xpr) { - if ($this->_value->xpath($xpr)) { - $this->_error($key); - return false; - } - } - return true; - } -} diff --git a/app/code/core/Mage/Adminhtml/Model/Newsletter/Renderer/Text.php b/app/code/core/Mage/Adminhtml/Model/Newsletter/Renderer/Text.php index 770f1c34cd..06aef2f20b 100644 --- a/app/code/core/Mage/Adminhtml/Model/Newsletter/Renderer/Text.php +++ b/app/code/core/Mage/Adminhtml/Model/Newsletter/Renderer/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Observer.php b/app/code/core/Mage/Adminhtml/Model/Observer.php index a597842990..ac7c083f0e 100644 --- a/app/code/core/Mage/Adminhtml/Model/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Report/Item.php b/app/code/core/Mage/Adminhtml/Model/Report/Item.php index 098bac4fbc..8bd7756813 100644 --- a/app/code/core/Mage/Adminhtml/Model/Report/Item.php +++ b/app/code/core/Mage/Adminhtml/Model/Report/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_Report_Item extends Varien_Object diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order.php index 85ded57baf..d079bc1e61 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php index 067fdf39cf..a1cd767a03 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1338,7 +1338,8 @@ public function _prepareCustomer() $customerAddressId = $this->getShippingAddress()->getCustomerAddressId(); if ($customerAddressId && $customer->getId()) { $customer->getAddressItemById($customerAddressId)->addData($shippingAddress->getData()); - } elseif ($billingAddress !== null + } elseif (!empty($customerAddressId) + && $billingAddress !== null && $this->getBillingAddress()->getCustomerAddressId() == $customerAddressId ) { $billingAddress->setIsDefaultShipping(true); @@ -1474,6 +1475,7 @@ public function createOrder() if ($this->getSendConfirmation()) { $order->sendNewOrderEmail(); } + Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $quote)); return $order; diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php index 9af2cfa7c6..2ad4968e9b 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Search/Catalog.php b/app/code/core/Mage/Adminhtml/Model/Search/Catalog.php index 9932ef593f..c9bc80defa 100644 --- a/app/code/core/Mage/Adminhtml/Model/Search/Catalog.php +++ b/app/code/core/Mage/Adminhtml/Model/Search/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Search/Customer.php b/app/code/core/Mage/Adminhtml/Model/Search/Customer.php index 34c8021e96..a0664cc8a8 100644 --- a/app/code/core/Mage/Adminhtml/Model/Search/Customer.php +++ b/app/code/core/Mage/Adminhtml/Model/Search/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -50,9 +50,9 @@ public function load() ->addNameToSelect() ->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left') ->addAttributeToFilter(array( - array('attribute'=>'firstname', 'like'=>$this->getQuery().'%'), - array('attribute'=>'lastname', 'like'=>$this->getQuery().'%'), - array('attribute'=>'company', 'like'=>$this->getQuery().'%'), + array('attribute'=>'firstname', 'like' => $this->getQuery().'%'), + array('attribute'=>'lastname', 'like' => $this->getQuery().'%'), + array('attribute'=>'company', 'like' => $this->getQuery().'%'), )) ->setPage(1, 10) ->load(); diff --git a/app/code/core/Mage/Adminhtml/Model/Search/Order.php b/app/code/core/Mage/Adminhtml/Model/Search/Order.php index a07c63aaca..a4920502f1 100644 --- a/app/code/core/Mage/Adminhtml/Model/Search/Order.php +++ b/app/code/core/Mage/Adminhtml/Model/Search/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -52,16 +52,16 @@ public function load() $collection = Mage::getResourceModel('sales/order_collection') ->addAttributeToSelect('*') ->addAttributeToSearchFilter(array( - array('attribute'=>'increment_id', 'like'=>$query.'%'), - array('attribute'=>'billing_firstname', 'like'=>$query.'%'), - array('attribute'=>'billing_lastname', 'like'=>$query.'%'), - array('attribute'=>'billing_telephone', 'like'=>$query.'%'), - array('attribute'=>'billing_postcode', 'like'=>$query.'%'), + array('attribute' => 'increment_id', 'like'=>$query.'%'), + array('attribute' => 'billing_firstname', 'like'=>$query.'%'), + array('attribute' => 'billing_lastname', 'like'=>$query.'%'), + array('attribute' => 'billing_telephone', 'like'=>$query.'%'), + array('attribute' => 'billing_postcode', 'like'=>$query.'%'), - array('attribute'=>'shipping_firstname', 'like'=>$query.'%'), - array('attribute'=>'shipping_lastname', 'like'=>$query.'%'), - array('attribute'=>'shipping_telephone', 'like'=>$query.'%'), - array('attribute'=>'shipping_postcode', 'like'=>$query.'%'), + array('attribute' => 'shipping_firstname', 'like'=>$query.'%'), + array('attribute' => 'shipping_lastname', 'like'=>$query.'%'), + array('attribute' => 'shipping_telephone', 'like'=>$query.'%'), + array('attribute' => 'shipping_postcode', 'like'=>$query.'%'), )) ->setCurPage($this->getStart()) ->setPageSize($this->getLimit()) diff --git a/app/code/core/Mage/Adminhtml/Model/Session.php b/app/code/core/Mage/Adminhtml/Model/Session.php index 09129530dd..401136d239 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session.php +++ b/app/code/core/Mage/Adminhtml/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php index fadedbd686..0d5d0854c3 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session/Quote.php +++ b/app/code/core/Mage/Adminhtml/Model/Session/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Custom.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Custom.php index d2bc15e9c6..5e8702ab8f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Custom.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Custom.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usecustom.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usecustom.php index cf278b9a77..99ed97b835 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usecustom.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usecustom.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php index 2b15711959..dea21e90c6 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Usesecretkey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Baseurl.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Baseurl.php index 5f3bb8d1a9..6b4e96bedf 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Baseurl.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Baseurl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Cache.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Cache.php index ed5d6a300c..6a3204fc5f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Cache.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Cache.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Inventory/Managestock.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Inventory/Managestock.php index 09345c2452..b7a82f5e56 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Inventory/Managestock.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Inventory/Managestock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Type.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Type.php index 3e299b5a01..ac12f2452f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Type.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Category.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Category.php index 457b840809..445cb47262 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Category.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Abstract.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Abstract.php index 9750dde041..25c14e4b3b 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Allow.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Allow.php index 41d0987702..39b39edb08 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Allow.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Allow.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Base.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Base.php index d9111d64fe..1fe2460808 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Base.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Base.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Cron.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Cron.php index 4332e6c570..2b39e13b9d 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Cron.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Default.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Default.php index b8e5864039..1cfea0d350 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Default.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Currency/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php index b6947f0ebe..67d180afd0 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php index 5a04e135df..91f55f9d9a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php index 4b70a22801..dc330f4235 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datashare.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datashare.php index 4f05df64aa..42430935f1 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datashare.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Datashare.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Exception.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Exception.php index 736c814427..21c08ca4b0 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Exception.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Package.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Package.php index 0bae94290a..35f6adbf2d 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Package.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Design/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Address.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Address.php index 2f76a4f6ba..f98d75871c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Address.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Sender.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Sender.php index afa622fd7d..345fc0766c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Sender.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Email/Sender.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Encrypted.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Encrypted.php index 6e9248cabb..56f3c3d3e9 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Encrypted.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Encrypted.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php index 0b6ecb8c25..a27d8b2f98 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -135,9 +135,7 @@ protected function _getUploadDir() */ protected function _getUploadRoot($token) { - $uploadRoot = (string)Mage::getConfig()->getNode($token, $this->getScope(), $this->getScopeId()); - $uploadRoot = Mage::getConfig()->substDistroServerVars($uploadRoot); - return $uploadRoot; + return Mage::getBaseDir('media'); } /** diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php index d741344e55..ad148be31c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php index 9ce363b925..dfa5d057e5 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Favicon.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -36,21 +36,21 @@ class Mage_Adminhtml_Model_System_Config_Backend_Image_Favicon extends Mage_Admi { /** * The tail part of directory path for uploading - * + * */ const UPLOAD_DIR = 'favicon'; /** * Token for the root part of directory path for uploading - * + * */ - const UPLOAD_ROOT = 'system/filesystem/media'; + const UPLOAD_ROOT = 'media'; /** * Return path to directory for upload file * * @return string - * @throw Mage_Core_Exception + * @throw Mage_Core_Exception */ protected function _getUploadDir() { @@ -62,8 +62,8 @@ protected function _getUploadDir() /** * Makes a decision about whether to add info about the scope. - * - * @return boolean + * + * @return boolean */ protected function _addWhetherScopeInfo() { @@ -72,11 +72,21 @@ protected function _addWhetherScopeInfo() /** * Getter for allowed extensions of uploaded files. - * - * @return array + * + * @return array */ protected function _getAllowedExtensions() { return array('ico', 'png', 'gif', 'jpeg', 'apng', 'svg'); } + + /** + * Get real media dir path + * + * @param $token + * @return string + */ + protected function _getUploadRoot($token) { + return Mage::getBaseDir($token); + } } diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php index afeabdb090..f393bd4d2a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Layer/Children.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Layer/Children.php index 1f08b163c3..0209e30db2 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Layer/Children.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Layer/Children.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php index 6bb22e5bca..4fa95f2b34 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php index e566c48505..b13a692c64 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Log/Cron.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Log/Cron.php index 472b491fd4..887055c126 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Log/Cron.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Log/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Price/Scope.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Price/Scope.php index 1141932566..d627818b58 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Price/Scope.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Price/Scope.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Product/Alert/Cron.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Product/Alert/Cron.php index 9449b040e7..13b157f6cb 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Product/Alert/Cron.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Product/Alert/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Secure.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Secure.php index 67e492c2b1..ad1ffcfda8 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Secure.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Secure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php index 6c4efcc8f1..540c9e24c1 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php index 20251059a7..26c60859f0 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized/Array.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized/Array.php index 2fae4abf3e..83f8d18595 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized/Array.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized/Array.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Shipping/Tablerate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Shipping/Tablerate.php index a11e716e8f..7a36e3ebdc 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Shipping/Tablerate.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Shipping/Tablerate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap.php index 66c702da4e..4a6b9b18b0 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap/Cron.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap/Cron.php index 4386580964..cb5476c18e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap/Cron.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Sitemap/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Storage/Media/Database.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Storage/Media/Database.php index ea388b603e..e2cb158b8e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Storage/Media/Database.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Storage/Media/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Store.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Store.php index ab1447cb92..f4d51d7668 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Store.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php index 904f3dee63..c01da5d67c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Translate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Clone/Media/Image.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Clone/Media/Image.php index d436e22a02..90dd6fe41f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Clone/Media/Image.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Clone/Media/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -47,7 +47,7 @@ public function getPrefixes() //$entityTypeId = $entityType->loadByCode('catalog_product')->getEntityTypeId(); // use cached eav config - $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId(); + $entityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId(); /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */ $collection = Mage::getResourceModel('catalog/product_attribute_collection'); diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php index c5383ba06b..2ae0f09a85 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Allregion.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Allregion.php index 59a39d08de..7bafd08207 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Allregion.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Allregion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/GridPerPage.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/GridPerPage.php index 4919dc6e4d..26885ebf18 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/GridPerPage.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/GridPerPage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php index a75c79f75a..d861064f07 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListPerPage.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListPerPage.php index dd8d7e92cd..553dab939e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListPerPage.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListPerPage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListSort.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListSort.php index e873951350..d1544f2e91 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListSort.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListSort.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Type.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Type.php index a976508342..833277380e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Type.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/TimeFormat.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/TimeFormat.php index a158b53ae9..0da01ea29b 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/TimeFormat.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/TimeFormat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Category.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Category.php index 93f42d4ff5..bc7fb39428 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Category.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ public function toOptionArray($addEmpty = true) $collection = Mage::getResourceModel('catalog/category_collection'); $collection->addAttributeToSelect('name') - ->addPathFilter('^1/[0-9]+$') + ->addRootLevelFilter() ->load(); $options = array(); diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Checktype.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Checktype.php index cf4a208126..e8cc318b56 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Checktype.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Checktype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Page.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Page.php index 12463e53ec..a7c82beb71 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Page.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Cms_Page diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Wysiwyg/Enabled.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Wysiwyg/Enabled.php index d721ec3d02..d6cfc608b6 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Wysiwyg/Enabled.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cms/Wysiwyg/Enabled.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country.php index 4bed5f5f4b..5ccb5d9e85 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country/Full.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country/Full.php index 905d59f468..f2b8048d93 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country/Full.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Country/Full.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cron/Frequency.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cron/Frequency.php index bab3d48ce7..a7854163b4 100755 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cron/Frequency.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Cron/Frequency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency.php index aba31805ba..b24ed935a9 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency/Service.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency/Service.php index a55748a610..bb2b913d8b 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency/Service.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Currency/Service.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group.php index 78e04dc559..4ee238557d 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php index dac27c23b0..b4d62ce428 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Package.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Package.php index 0ea6a8beb3..04b993ddcd 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Package.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Package diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Robots.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Robots.php index 360ce1665d..11090da9b5 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Robots.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Design/Robots.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Dev/Dbautoup.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Dev/Dbautoup.php index 55054287ac..a1ef51b6ae 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Dev/Dbautoup.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Dev/Dbautoup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Dev_Dbautoup diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Identity.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Identity.php index f757dcdee4..bcc5861031 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Identity.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Identity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Method.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Method.php index 9654512b2d..2ae914a288 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Method.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Smtpauth.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Smtpauth.php index 21ba6d9e62..a806cad68e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Smtpauth.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Smtpauth.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Template.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Template.php index 59e4ccd5dd..78fc2add18 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Template.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Email/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Enabledisable.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Enabledisable.php index 831ae15819..98ccd0b6ca 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Enabledisable.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Enabledisable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Frequency.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Frequency.php index 0dac2c45aa..f69dc40515 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Frequency.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Frequency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Language.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Language.php index 29d9168b19..e5e422af69 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Language.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Language.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale.php index 9af0ec4230..e892ba8f61 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Country.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Country.php index adb436285d..ac26271a5d 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Country.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency.php index ff34ea3740..0635ed8339 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency/All.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency/All.php index 040cfe5d46..e346ec5911 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency/All.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Currency/All.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Timezone.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Timezone.php index a57dd61956..0e409f7f9f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Timezone.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Timezone.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Weekdays.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Weekdays.php index 421d811bc4..66d041f336 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Weekdays.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Locale/Weekdays.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Nooptreq.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Nooptreq.php index 0d57541760..a0c903e1a9 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Nooptreq.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Nooptreq.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Nooptreq diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Notification/Frequency.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Notification/Frequency.php index 97657b37c4..5a0569957b 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Notification/Frequency.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Notification/Frequency.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status.php index 37303baebe..c2da7e99ca 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/New.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/New.php index d00f01e4e5..d18071c8c1 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/New.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Newprocessing.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Newprocessing.php index 394c50fa7b..7a51d1c77c 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Newprocessing.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Newprocessing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Processing.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Processing.php index a3bbf5cfdb..76852c533f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Processing.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Order/Status/Processing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allmethods.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allmethods.php index 062b16bbd2..2e8c548ee8 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allmethods.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allmethods.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allowedmethods.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allowedmethods.php index ca7185ee92..7c6093d9d0 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allowedmethods.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allowedmethods.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allspecificcountries.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allspecificcountries.php index b749b3a672..2e47bc1540 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allspecificcountries.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Allspecificcountries.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Cctype.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Cctype.php index 9c295de96b..cc51c8d09f 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Cctype.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Payment/Cctype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Scope.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Scope.php index 5d1b16e7d5..6473353ee1 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Scope.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Scope.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php index 401f93c42b..f17ff55c9a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Price.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Price.php index f081327147..b0df449df3 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Price.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Type.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Type.php index c6f94a72bc..0920ebc6ae 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Type.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Thumbnail.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Thumbnail.php index 6459946e58..1228f6d688 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Thumbnail.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Thumbnail.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Reports/Scope.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Reports/Scope.php index f778f9347f..70c619ca2a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Reports/Scope.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Reports/Scope.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allmethods.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allmethods.php index d3eeab2599..69608cdac4 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allmethods.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allmethods.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allowedmethods.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allowedmethods.php index a074b49544..19d3f79945 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allowedmethods.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allowedmethods.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allspecificcountries.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allspecificcountries.php index a7a2c9c155..dd832af9ae 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allspecificcountries.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Allspecificcountries.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Flatrate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Flatrate.php index 18fbc54cdb..cbc36a325e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Flatrate.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Flatrate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Tablerate.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Tablerate.php index fa5ec62fd1..3a91cfcc26 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Tablerate.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Tablerate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Taxclass.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Taxclass.php index 8d10cd83f4..5b27b70398 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Taxclass.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Shipping/Taxclass.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Shipping_Taxclass diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Database.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Database.php index 4dab696927..81e39b8989 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Database.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -72,9 +72,7 @@ public function toOptionArray() $this->_connections = (array) Mage::app()->getConfig()->getNode('global/resources')->children(); foreach (array_keys($this->_connections) as $connectionName) { $connection = $this->_collectConnectionConfig($connectionName); - if (!isset($connection['active']) || $connection['active'] != 1 - || !isset($connection['host']) || empty($connection['host']) - ) { + if (!isset($connection['active']) || $connection['active'] != 1) { continue; } diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Storage.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Storage.php index 01576f0193..9766d91c92 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Storage.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Storage/Media/Storage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Store.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Store.php index bd98e0b8cf..1acd37a6e7 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Store.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Apply/On.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Apply/On.php index 28910d7527..3a214a6621 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Apply/On.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Apply/On.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Tax_Apply_On diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Basedon.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Basedon.php index d4f420efdf..df423f6cc7 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Basedon.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Basedon.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Tax_Basedon diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Catalog.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Catalog.php index 83fe1f51a7..8f982ef390 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Catalog.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Tax/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Tax_Catalog diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Watermark/Position.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Watermark/Position.php index 417128b2e2..6e75c6c488 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Watermark/Position.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Watermark/Position.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Protocol.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Protocol.php index 92d95a08eb..b300a2688e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Protocol.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Protocol.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Web_Protocol diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Redirect.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Redirect.php index 7812730b21..c710e64250 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Redirect.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Web/Redirect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_System_Config_Source_Web_Redirect diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Website.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Website.php index 9420133ebf..d3c30777f6 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Website.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesno.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesno.php index 2b9f357a97..fd3e83fc1a 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesno.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesno.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesnocustom.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesnocustom.php index 459422db2b..a8fb3d6900 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesnocustom.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Yesnocustom.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Store.php b/app/code/core/Mage/Adminhtml/Model/System/Store.php index c64782a842..e35d179e08 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Store.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/Model/Url.php b/app/code/core/Mage/Adminhtml/Model/Url.php index ee821f8eba..46fbac2d88 100644 --- a/app/code/core/Mage/Adminhtml/Model/Url.php +++ b/app/code/core/Mage/Adminhtml/Model/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Model_Url extends Mage_Core_Model_Url diff --git a/app/code/core/Mage/Adminhtml/controllers/AjaxController.php b/app/code/core/Mage/Adminhtml/controllers/AjaxController.php index 4e60e1c807..f6228de02b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/AjaxController.php +++ b/app/code/core/Mage/Adminhtml/controllers/AjaxController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php index 193f02c9f4..f348e096c1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php index 9230db65f4..5931e6f5ed 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Api_UserController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/core/Mage/Adminhtml/controllers/CacheController.php b/app/code/core/Mage/Adminhtml/controllers/CacheController.php index 907b36f5fa..af4b01d7d3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CacheController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CacheController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/WidgetController.php index 05f1b2caf8..d28ca4fd8d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/WidgetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php index 2d2ca08e12..76c95d2a11 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php index d93debeee1..5767b7ab67 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -77,7 +77,7 @@ public function saveAction() foreach ($attributesData as $attributeCode => $value) { $attribute = Mage::getSingleton('eav/config') - ->getAttribute('catalog_product', $attributeCode); + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); if (!$attribute->getAttributeId()) { unset($attributesData[$attributeCode]); continue; diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php index 36f595debc..639a86d515 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_ public function preDispatch() { parent::preDispatch(); - $this->_entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId(); + $this->_entityTypeId = Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId(); } protected function _initAction() @@ -200,7 +200,7 @@ public function saveAction() //validate attribute_code if (isset($data['attribute_code'])) { - $validatorAttrCode = new Zend_Validate_Regex(array('pattern' => '/^[a-z_]{1,255}$/')); + $validatorAttrCode = new Zend_Validate_Regex(array('pattern' => '/^[a-z_0-9]{1,255}$/')); if (!$validatorAttrCode->isValid($data['attribute_code'])) { $session->addError( $helper->__('Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/DatafeedsController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/DatafeedsController.php index 543934aacc..6168cc499c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/DatafeedsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/DatafeedsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php index 94dc953910..56808bd599 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php index 5c20c575c8..a746889206 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php index f7904dc58b..bd205549b1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php index 970620540b..7512df45ef 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/WidgetController.php index 468f929503..b4509531f7 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/WidgetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index 76bc3fed23..5370900190 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,6 +33,11 @@ */ class Mage_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller_Action { + /** + * The greatest value which could be stored in CatalogInventory Qty field + */ + const MAX_QTY_VALUE = 99999999.9999; + /** * Array of actions which can be processed without secret key validation * @@ -172,7 +177,6 @@ public function indexAction() ->_title($this->__('Manage Products')); $this->loadLayout(); - $this->_setActiveMenu('catalog/products'); $this->renderLayout(); } @@ -446,9 +450,8 @@ public function reviewsAction() public function superConfigAction() { $this->_initProduct(); - $this->getResponse()->setBody( - $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_grid')->toHtml() - ); + $this->loadLayout(false); + $this->renderLayout(); } /** @@ -481,6 +484,7 @@ public function validateAction() if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) { $productData['stock_data']['use_config_manage_stock'] = 0; } + /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); $product->setData('_edit_mode', true); if ($storeId = $this->getRequest()->getParam('store')) { @@ -527,12 +531,10 @@ public function validateAction() $response->setError(true); $response->setAttribute($e->getAttributeCode()); $response->setMessage($e->getMessage()); - } - catch (Mage_Core_Exception $e) { + } catch (Mage_Core_Exception $e) { $response->setError(true); $response->setMessage($e->getMessage()); - } - catch (Exception $e) { + } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); @@ -547,10 +549,15 @@ public function validateAction() */ protected function _initProductSave() { - $product = $this->_initProduct(); + $product = $this->_initProduct(); $productData = $this->getRequest()->getPost('product'); - if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) { - $productData['stock_data']['use_config_manage_stock'] = 0; + if ($productData) { + if (!isset($productData['stock_data']['use_config_manage_stock'])) { + $productData['stock_data']['use_config_manage_stock'] = 0; + } + if (isset($productData['stock_data']['qty']) && (float)$productData['stock_data']['qty'] > self::MAX_QTY_VALUE) { + $productData['stock_data']['qty'] = self::MAX_QTY_VALUE; + } } /** @@ -627,17 +634,19 @@ protected function _initProductSave() * Initialize data for configurable product */ if (($data = $this->getRequest()->getPost('configurable_products_data')) - && !$product->getConfigurableReadonly()) { + && !$product->getConfigurableReadonly() + ) { $product->setConfigurableProductsData(Mage::helper('core')->jsonDecode($data)); } if (($data = $this->getRequest()->getPost('configurable_attributes_data')) - && !$product->getConfigurableReadonly()) { + && !$product->getConfigurableReadonly() + ) { $product->setConfigurableAttributesData(Mage::helper('core')->jsonDecode($data)); } $product->setCanSaveConfigurableAttributes( - (bool)$this->getRequest()->getPost('affect_configurable_product_attributes') - && !$product->getConfigurableReadonly() + (bool) $this->getRequest()->getPost('affect_configurable_product_attributes') + && !$product->getConfigurableReadonly() ); /** @@ -707,13 +716,11 @@ public function saveAction() Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId); $this->_getSession()->addSuccess($this->__('The product has been saved.')); - } - catch (Mage_Core_Exception $e) { + } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()) ->setProductData($data); $redirectBack = true; - } - catch (Exception $e) { + } catch (Exception $e) { Mage::logException($e); $this->_getSession()->addError($e->getMessage()); $redirectBack = true; @@ -725,15 +732,13 @@ public function saveAction() 'id' => $productId, '_current'=>true )); - } - else if($this->getRequest()->getParam('popup')) { + } elseif($this->getRequest()->getParam('popup')) { $this->_redirect('*/*/created', array( '_current' => true, 'id' => $productId, 'edit' => $isEdit )); - } - else { + } else { $this->_redirect('*/*/', array('store'=>$storeId)); } } @@ -748,8 +753,7 @@ public function duplicateAction() $newProduct = $product->duplicate(); $this->_getSession()->addSuccess($this->__('The product has been duplicated.')); $this->_redirect('*/*/edit', array('_current'=>true, 'id'=>$newProduct->getId())); - } - catch (Exception $e) { + } catch (Exception $e) { Mage::logException($e); $this->_getSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', array('_current'=>true)); @@ -780,8 +784,7 @@ public function deleteAction() try { $product->delete(); $this->_getSession()->addSuccess($this->__('The product has been deleted.')); - } - catch (Exception $e) { + } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } } @@ -796,7 +799,7 @@ public function tagGridAction() { $this->loadLayout(); $this->getLayout()->getBlock('admin.product.tags') - ->setProductId($this->getRequest()->getParam('id')); + ->setProductId($this->getRequest()->getParam('id')); $this->renderLayout(); } @@ -805,9 +808,8 @@ public function tagGridAction() */ public function alertsPriceGridAction() { - $this->getResponse()->setBody( - $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_price')->toHtml() - ); + $this->loadLayout(false); + $this->renderLayout(); } /** @@ -815,39 +817,16 @@ public function alertsPriceGridAction() */ public function alertsStockGridAction() { - $this->getResponse()->setBody( - $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_alerts_stock')->toHtml() - ); + $this->loadLayout(false); + $this->renderLayout(); } + /** + * @deprecated since 1.5.0.0 + * @return Mage_Adminhtml_Catalog_ProductController + */ public function addCustomersToAlertQueueAction() { - $alerts = Mage::getSingleton('customeralert/config')->getAlerts();; - $block = $this->getLayout() - ->createBlock('adminhtml/messages', 'messages'); - $collection = $block - ->getMessageCollection(); - foreach ($alerts as $key=>$val) { - try { - if(Mage::getSingleton('customeralert/config')->getAlertByType($key) - ->setParamValues($this->getRequest()->getParams()) - ->addCustomersToAlertQueue()) - { - $getTitleByType = Mage::getSingleton('customeralert/config')->getTitleByType($key); - $collection->addMessage(Mage::getModel('core/message')->success( - $this->__('Customers for alert %s were successfuly added to queue', $getTitleByType) - )); - } - } catch (Exception $e) { - $title = Mage::getSingleton('customeralert/config')->getTitleByType($key); - $error = $e->getMessage(); - $collection->addMessage(Mage::getModel('core/message')->error( - $this->__('An error occurred while adding customers for the %s alert. Message: %s', $title, $error) - )); - continue; - } - } - print $block->getGroupedHtml(); return $this; } @@ -921,11 +900,9 @@ public function massStatusAction() } catch (Mage_Core_Model_Exception $e) { $this->_getSession()->addError($e->getMessage()); - } - catch (Mage_Core_Exception $e) { + } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); - } - catch (Exception $e) { + } catch (Exception $e) { $this->_getSession() ->addException($e, $this->__('An error occurred while updating the product(s) status.')); } @@ -970,7 +947,7 @@ public function quickCreateAction() /* @var $configurableProduct Mage_Catalog_Model_Product */ $configurableProduct = Mage::getModel('catalog/product') - ->setStoreId(0) + ->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID) ->load($this->getRequest()->getParam('product')); if (!$configurableProduct->isConfigurable()) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php index c8d97a3891..fe1cf4ffc2 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/CatalogController.php index c4aa92df8f..841b6636db 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CatalogController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CatalogController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php index 3b2a442ba7..f55eb7ffef 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/Block/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/Block/WidgetController.php index 5ffe7b350d..56ff0c556a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/Block/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/Block/WidgetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php index 8dcc11a0c5..4c99d0fb4d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/Page/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/Page/WidgetController.php index 30c83e319b..8d1ad3d0ec 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/Page/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/Page/WidgetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php index 14b4536019..fa8d591dc3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php index 2f720d828c..06f9e112e1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php @@ -20,17 +20,16 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Images manage controller for Cms WYSIWYG editor * - * @category Mage - * @package Mage_Adminhtml - * @author Magento Core Team + * @category Mage + * @package Mage_Adminhtml + * @author Magento Core Team */ class Mage_Adminhtml_Cms_Wysiwyg_ImagesController extends Mage_Adminhtml_Controller_Action { diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php index 8a6f5c2b3d..6aa9a44e2b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php @@ -20,17 +20,16 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Wysiwyg controller for different purposes * - * @category Mage - * @package Mage_Adminhtml - * @author Magento Core Team + * @category Mage + * @package Mage_Adminhtml + * @author Magento Core Team */ class Mage_Adminhtml_Cms_WysiwygController extends Mage_Adminhtml_Controller_Action { diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php index a02dafe252..0d10aea41a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php @@ -20,15 +20,15 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog composite product configuration controller * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Adminhtml * @author Magento Core Team */ class Mage_Adminhtml_Customer_Cart_Product_Composite_CartController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/ConfigController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/ConfigController.php index 81849d4cb2..7e2135e045 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/ConfigController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/ConfigController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index 9bfbc49b83..ac24e8edfc 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php index bf1a8378e9..4a2d40a728 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/OnlineController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Customer_OnlineController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php index 59cf540845..f9d2ebf7f8 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php @@ -20,18 +20,19 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog composite product configuration controller * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Adminhtml * @author Magento Core Team */ -class Mage_Adminhtml_Customer_Wishlist_Product_Composite_WishlistController extends Mage_Adminhtml_Controller_Action +class Mage_Adminhtml_Customer_Wishlist_Product_Composite_WishlistController + extends Mage_Adminhtml_Controller_Action { /** * Wishlist we're working with diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index 7fcbab9ccb..af38db312d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -306,7 +306,7 @@ public function saveAction() $customer->save(); // send welcome email - if ($customer->getWebsiteId() && (!empty($data['account']['sendemail']) || $sendPassToEmail)) { + if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) { $storeId = $customer->getSendemailStoreId(); if ($isNewCustomer) { $customer->sendNewAccountEmail('registered', '', $storeId); diff --git a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php index 722ffb03d0..5edfd5d892 100644 --- a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php +++ b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/IndexController.php b/app/code/core/Mage/Adminhtml/controllers/IndexController.php index b2860673ae..70cc2344a4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/IndexController.php +++ b/app/code/core/Mage/Adminhtml/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/JsonController.php b/app/code/core/Mage/Adminhtml/controllers/JsonController.php index 6d554ef19d..d1b498253c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/JsonController.php +++ b/app/code/core/Mage/Adminhtml/controllers/JsonController.php @@ -20,17 +20,24 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Json controller * + * @category Mage + * @package Mage_Adminhtml * @author Magento Core Team */ class Mage_Adminhtml_JsonController extends Mage_Adminhtml_Controller_Action { + /** + * Return JSON-encoded array of country regions + * + * @return string + */ public function countryRegionAction() { $arrRes = array(); diff --git a/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php b/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php index 1e3320626c..234981a244 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Media/EditorController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php b/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php index c0825ef8bc..bdc439415a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Media/UploaderController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php index 5ab3de07b9..cf346579a5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php index f755e652ed..de587c4946 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php index b93ffed5fd..cf95f21cd9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php index 6da6cd70be..9455b7fea3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** diff --git a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php index 9a3fa5124b..2431e0046c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php +++ b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php index ee3264541a..b4cdbe5533 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php index e7fb105254..fa201c2860 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Adminhtml_Permissions_UserController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php b/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php index e6e5e14c12..853a27cef5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Poll/AnswerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,8 +39,10 @@ public function editAction() $this->loadLayout(); $this->_setActiveMenu('cms/poll'); - $this->_addBreadcrumb(Mage::helper('poll')->__('Poll Manager'), Mage::helper('poll')->__('Poll Manager'), $this->getUrl('*/*/')); - $this->_addBreadcrumb(Mage::helper('poll')->__('Edit Poll Answer'), Mage::helper('poll')->__('Edit Poll Answer')); + $this->_addBreadcrumb(Mage::helper('poll')->__('Poll Manager'), + Mage::helper('poll')->__('Poll Manager'), $this->getUrl('*/*/')); + $this->_addBreadcrumb(Mage::helper('poll')->__('Edit Poll Answer'), + Mage::helper('poll')->__('Edit Poll Answer')); $this->_addContent($this->getLayout()->createBlock('adminhtml/poll_answer_edit')); @@ -57,8 +59,10 @@ public function saveAction() ->setId($this->getRequest()->getParam('id')) ->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('poll')->__('The answer has been saved.')); - $this->_redirect('*/poll/edit', array('id' => $this->getRequest()->getParam('poll_id'), 'tab' => 'answers_section')); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('poll')->__('The answer has been saved.')); + $this->_redirect('*/poll/edit', + array('id' => $this->getRequest()->getParam('poll_id'), 'tab' => 'answers_section')); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); @@ -71,7 +75,9 @@ public function saveAction() public function gridAction() { - $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/poll_edit_tab_answers_grid')->toHtml()); + $this->getResponse()->setBody( + $this->getLayout()->createBlock('adminhtml/poll_edit_tab_answers_grid')->toHtml() + ); } public function jsonSaveAction() @@ -80,7 +86,7 @@ public function jsonSaveAction() $response->setError(0); if ( $post = $this->getRequest()->getPost() ) { - $data = Zend_Json_Decoder::decode($post['data']); + $data = Zend_Json::decode($post['data']); try { if( trim($data['answer_title']) == '' ) { throw new Exception(Mage::helper('poll')->__('Invalid Answer.')); @@ -104,7 +110,7 @@ public function jsonDeleteAction() if ( $id = $this->getRequest()->getParam('id') ) { try { $model = Mage::getModel('poll/poll_answer'); - $model->setId(Zend_Json_Decoder::decode($id)) + $model->setId(Zend_Json::decode($id)) ->delete(); } catch (Exception $e) { $response->setError(1); diff --git a/app/code/core/Mage/Adminhtml/controllers/PollController.php b/app/code/core/Mage/Adminhtml/controllers/PollController.php index d327b18e79..38e1e4a868 100644 --- a/app/code/core/Mage/Adminhtml/controllers/PollController.php +++ b/app/code/core/Mage/Adminhtml/controllers/PollController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php index 15b90708b3..003b129067 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php @@ -20,18 +20,27 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - +/** + * Backend Catalog Price Rules controller + * + * @category Mage + * @package Mage_Adminhtml + * @author Magento Core Team + */ class Mage_Adminhtml_Promo_CatalogController extends Mage_Adminhtml_Controller_Action { protected function _initAction() { $this->loadLayout() ->_setActiveMenu('promo/catalog') - ->_addBreadcrumb(Mage::helper('catalogrule')->__('Promotions'), Mage::helper('catalogrule')->__('Promotions')); + ->_addBreadcrumb( + Mage::helper('catalogrule')->__('Promotions'), + Mage::helper('catalogrule')->__('Promotions') + ); return $this; } @@ -40,11 +49,16 @@ public function indexAction() $this->_title($this->__('Promotions'))->_title($this->__('Catalog Price Rules')); if (Mage::app()->loadCache('catalog_rules_dirty')) { - Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('catalogrule')->__('There are rules that have been changed but were not applied. Please, click Apply Rules in order to see immediate effect in the catalog.')); + Mage::getSingleton('adminhtml/session')->addNotice( + Mage::helper('catalogrule')->__('There are rules that have been changed but were not applied. Please, click Apply Rules in order to see immediate effect in the catalog.') + ); } $this->_initAction() - ->_addBreadcrumb(Mage::helper('catalogrule')->__('Catalog'), Mage::helper('catalogrule')->__('Catalog')) + ->_addBreadcrumb( + Mage::helper('catalogrule')->__('Catalog'), + Mage::helper('catalogrule')->__('Catalog') + ) ->renderLayout(); } @@ -63,7 +77,9 @@ public function editAction() if ($id) { $model->load($id); if (! $model->getRuleId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalogrule')->__('This rule no longer exists.')); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('catalogrule')->__('This rule no longer exists.') + ); $this->_redirect('*/*'); return; } @@ -83,9 +99,10 @@ public function editAction() $this->_initAction()->getLayout()->getBlock('promo_catalog_edit') ->setData('action', $this->getUrl('*/promo_catalog/save')); - $this - ->_addBreadcrumb($id ? Mage::helper('catalogrule')->__('Edit Rule') : Mage::helper('catalogrule')->__('New Rule'), $id ? Mage::helper('catalogrule')->__('Edit Rule') : Mage::helper('catalogrule')->__('New Rule')) - ->renderLayout(); + $breadcrumb = $id + ? Mage::helper('catalogrule')->__('Edit Rule') + : Mage::helper('catalogrule')->__('New Rule'); + $this->_addBreadcrumb($breadcrumb, $breadcrumb)->renderLayout(); } @@ -94,7 +111,10 @@ public function saveAction() if ($this->getRequest()->getPost()) { try { $model = Mage::getModel('catalogrule/rule'); - Mage::dispatchEvent('adminhtml_controller_catalogrule_prepare_save', array('request' => $this->getRequest())); + Mage::dispatchEvent( + 'adminhtml_controller_catalogrule_prepare_save', + array('request' => $this->getRequest()) + ); $data = $this->getRequest()->getPost(); $data = $this->_filterDates($data, array('from_date', 'to_date')); if ($id = $this->getRequest()->getParam('rule_id')) { @@ -130,9 +150,14 @@ public function saveAction() $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalogrule')->__('The rule has been saved.')); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('catalogrule')->__('The rule has been saved.') + ); Mage::getSingleton('adminhtml/session')->setPageData(false); if ($autoApply) { + // save rule website IDs for validation in Enterprise_AdminGws_Model_Controllers + // (see validatePromoCatalogApplyRules method) + Mage::register('ruleWebsites', explode(',', $model->getWebsiteIds())); $this->_forward('applyRules'); } else { Mage::app()->saveCache(1, 'catalog_rules_dirty'); @@ -146,7 +171,9 @@ public function saveAction() } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addError(Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.')); + $this->_getSession()->addError( + Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.') + ); Mage::logException($e); Mage::getSingleton('adminhtml/session')->setPageData($data); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('rule_id'))); @@ -164,19 +191,25 @@ public function deleteAction() $model->load($id); $model->delete(); Mage::app()->saveCache(1, 'catalog_rules_dirty'); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalogrule')->__('The rule has been deleted.')); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('catalogrule')->__('The rule has been deleted.') + ); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addError(Mage::helper('catalogrule')->__('An error occurred while deleting the rule. Please review the log and try again.')); + $this->_getSession()->addError( + Mage::helper('catalogrule')->__('An error occurred while deleting the rule. Please review the log and try again.') + ); Mage::logException($e); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalogrule')->__('Unable to find a rule to delete.')); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('catalogrule')->__('Unable to find a rule to delete.') + ); $this->_redirect('*/*/'); } @@ -267,19 +300,15 @@ public function applyRulesAction() $this->_redirect('*/*'); } + /** + * @deprecated since 1.5.0.0 + */ public function addToAlersAction() { - $alerts = Mage::getResourceModel('customeralert/type')->getAlertsForCronChecking(); - foreach ($alerts as $val) { - Mage::getSingleton('customeralert/config')->getAlertByType('price_is_changed') - ->setParamValues($val) - ->updateForPriceRule(); - } } protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('promo/catalog'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php index d4ca3644dd..d2d16501ca 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php index a2dd39859d..bb385cf28e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/WidgetController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/PromoController.php b/app/code/core/Mage/Adminhtml/controllers/PromoController.php index 79a8759bbf..c5405cf9cf 100644 --- a/app/code/core/Mage/Adminhtml/controllers/PromoController.php +++ b/app/code/core/Mage/Adminhtml/controllers/PromoController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/RatingController.php b/app/code/core/Mage/Adminhtml/controllers/RatingController.php index 80db85766d..3b2917f6ed 100644 --- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php +++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -128,7 +128,7 @@ public function deleteAction() try { $model = Mage::getModel('rating/rating'); /* @var $model Mage_Rating_Model_Rating */ - $model->setId($this->getRequest()->getParam('id')) + $model->load($this->getRequest()->getParam('id')) ->delete(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The rating has been deleted.')); $this->_redirect('*/*/'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php index 7ecf82f855..b1758d4315 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php index ab7d970880..4d0586eda8 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php index bbd312a91e..536e38006c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php index a0c2d1c4cb..c621024ea8 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php index be80c84b64..04100be59e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php index 8d78d43ad4..08764ff459 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php index c43fceccee..e2c3617d67 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/ReportController.php b/app/code/core/Mage/Adminhtml/controllers/ReportController.php index d5f66072af..d7b576fa1c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/ReportController.php +++ b/app/code/core/Mage/Adminhtml/controllers/ReportController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php index d451d92c70..60abbf28eb 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Rss/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Rss/OrderController.php index f72cf3bdab..33fd980824 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Rss/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Rss/OrderController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php index 87e6f348f0..b2510d245b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/CreditmemoController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/CreditmemoController.php index 62c240c5a6..d9e4704b94 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/CreditmemoController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/CreditmemoController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -60,4 +60,3 @@ public function indexAction() { parent::indexAction(); } } - diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/InvoiceController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/InvoiceController.php index fbcd480775..93af9ad173 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/InvoiceController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/InvoiceController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php index 1861282389..cc15a01a5d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -168,7 +168,9 @@ protected function _processActionData($action = null) /** * Collecting shipping rates */ - if (!$this->_getOrderCreateModel()->getQuote()->isVirtual() && $this->getRequest()->getPost('collect_shipping_rates')) { + if (!$this->_getOrderCreateModel()->getQuote()->isVirtual() && + $this->getRequest()->getPost('collect_shipping_rates') + ) { $this->_getOrderCreateModel()->collectShippingRates(); } @@ -257,7 +259,8 @@ protected function _processActionData($action = null) * Importing gift message allow items from specific product grid */ if ($data = $this->getRequest()->getPost('add_products')) { - $this->_getGiftmessageSaveModel()->importAllowQuoteItemsFromProducts(Mage::helper('core')->jsonDecode($data)); + $this->_getGiftmessageSaveModel() + ->importAllowQuoteItemsFromProducts(Mage::helper('core')->jsonDecode($data)); } /** @@ -321,6 +324,9 @@ public function reorderAction() $this->_getSession()->clear(); $orderId = $this->getRequest()->getParam('order_id'); $order = Mage::getModel('sales/order')->load($orderId); + if (!Mage::helper('sales/reorder')->canReorder($order)) { + return $this->_forward('noRoute'); + } if ($order->getId()) { $order->setReordered(true); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php index cb77d2124a..260d798075 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php index 586c596b17..357d250202 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php index 7e386867f8..ddf2807b64 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php index 9dd8792dca..7ba904387e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php index 89b73a15f6..26d5d47872 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/StatusController.php @@ -20,12 +20,16 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order status management controller + * + * @category Mage + * @package Mage_Adminhtml + * @author Magento Core Team */ class Mage_Adminhtml_Sales_Order_StatusController extends Mage_Adminhtml_Controller_Action { diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/View/GiftmessageController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/View/GiftmessageController.php index be29ef58b7..4359bfaae7 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/View/GiftmessageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/View/GiftmessageController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php index 2047ead154..53751951db 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Recurring/ProfileController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Recurring/ProfileController.php index 5482571fc4..d3b34ddc89 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Recurring/ProfileController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Recurring/ProfileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/ShipmentController.php index d363dcf57b..bec34d920b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/ShipmentController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/ShipmentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php index 62671b617b..769c153480 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/SalesController.php b/app/code/core/Mage/Adminhtml/controllers/SalesController.php index 481564d744..a93f8b5382 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SalesController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SalesController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php index 03691035e7..d5c435020d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/SurveyController.php b/app/code/core/Mage/Adminhtml/controllers/SurveyController.php index 6b72cca6f1..0ee718343c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SurveyController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SurveyController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php index 8b69868c7d..9e92d3409b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php b/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php index 551c45c3bf..77678814c0 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/BackupController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php b/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php index 5a9ade092a..084e44e38c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index ba2938af65..f525f522b9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -20,18 +20,17 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Adminhtml account controller * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Adminhtml * @author Magento Core Team */ - class Mage_Adminhtml_System_Config_System_StorageController extends Mage_Adminhtml_Controller_Action { /** diff --git a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php index 6f701ea7c9..b34beba4cc 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php index 2598ef8107..d7e444f772 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php index eb5e8f13f4..f87a783926 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -157,8 +157,7 @@ public function deleteAction() $profile->delete(); Mage::getSingleton('adminhtml/session')->addSuccess( Mage::helper('adminhtml')->__('The profile has been deleted.')); - } - catch (Exception $e){ + } catch (Exception $e){ Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } } @@ -172,7 +171,7 @@ public function saveAction() { if ($data = $this->getRequest()->getPost()) { if (!$this->_initProfile('profile_id')) { - return ; + return; } $profile = Mage::registry('current_convert_profile'); @@ -186,20 +185,18 @@ public function saveAction() Mage::getSingleton('adminhtml/session')->addSuccess( Mage::helper('adminhtml')->__('The profile has been saved.')); - } - catch (Exception $e){ + } catch (Exception $e){ Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setConvertProfileData($data); - $this->getResponse()->setRedirect($this->getUrl('*/*/edit', array('id'=>$profile->getId()))); + $this->getResponse()->setRedirect($this->getUrl('*/*/edit', array('id' => $profile->getId()))); return; } if ($this->getRequest()->getParam('continue')) { - $this->_redirect('*/*/edit', array('id'=>$profile->getId())); + $this->_redirect('*/*/edit', array('id' => $profile->getId())); } else { $this->_redirect('*/*'); } - } - else { + } else { Mage::getSingleton('adminhtml/session')->addError( $this->__('Invalid POST data (please check post_max_size and upload_max_filesize settings in your php.ini file).') ); @@ -217,23 +214,20 @@ public function runAction() public function batchRunAction() { if ($this->getRequest()->isPost()) { - $batchId = $this->getRequest()->getPost('batch_id',0); + $batchId = $this->getRequest()->getPost('batch_id', 0); $rowIds = $this->getRequest()->getPost('rows'); /* @var $batchModel Mage_Dataflow_Model_Batch */ $batchModel = Mage::getModel('dataflow/batch')->load($batchId); if (!$batchModel->getId()) { - //exit - return ; + return; } if (!is_array($rowIds) || count($rowIds) < 1) { - //exit - return ; + return; } if (!$batchModel->getAdapter()) { - //exit - return ; + return; } $batchImportModel = $batchModel->getBatchImportModel(); @@ -244,7 +238,6 @@ public function batchRunAction() $errors = array(); $saved = 0; - foreach ($rowIds as $importId) { $batchImportModel->load($importId); if (!$batchImportModel->getId()) { @@ -255,14 +248,27 @@ public function batchRunAction() try { $importData = $batchImportModel->getBatchData(); $adapter->saveRow($importData); - } - catch (Exception $e) { + } catch (Exception $e) { $errors[] = $e->getMessage(); continue; } $saved ++; } + if (method_exists($adapter, 'getEventPrefix')) { + /** + * Event for process rules relations after products import + */ + Mage::dispatchEvent($adapter->getEventPrefix() . '_finish_before', array( + 'adapter' => $adapter + )); + + /** + * Clear affected ids for adapter possible reuse + */ + $adapter->clearAffectedEntityIds(); + } + $result = array( 'savedRows' => $saved, 'errors' => $errors @@ -273,7 +279,8 @@ public function batchRunAction() public function batchFinishAction() { - if ($batchId = $this->getRequest()->getParam('id')) { + $batchId = $this->getRequest()->getParam('id'); + if ($batchId) { $batchModel = Mage::getModel('dataflow/batch')->load($batchId); /* @var $batchModel Mage_Dataflow_Model_Batch */ @@ -281,11 +288,9 @@ public function batchFinishAction() $result = array(); try { $batchModel->beforeFinish(); - } - catch (Mage_Core_Exception $e) { + } catch (Mage_Core_Exception $e) { $result['error'] = $e->getMessage(); - } - catch (Exception $e) { + } catch (Exception $e) { $result['error'] = Mage::helper('adminhtml')->__('An error occurred while finishing process. Please refresh the cache'); } $batchModel->delete(); @@ -307,22 +312,6 @@ public function historyAction() { protected function _isAllowed() { -// switch ($this->getRequest()->getActionName()) { -// case 'index': -// $aclResource = 'admin/system/convert/profiles'; -// break; -// case 'grid': -// $aclResource = 'admin/system/convert/profiles'; -// break; -// case 'run': -// $aclResource = 'admin/system/convert/profiles/run'; -// break; -// default: -// $aclResource = 'admin/system/convert/profiles/edit'; -// break; -// } - return Mage::getSingleton('admin/session')->isAllowed('admin/system/convert/profiles'); } } - diff --git a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php index 12ed01acb6..3d6c4f9d68 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php index 3dca58ecc8..d1a4ca900b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php index eaae2e75c7..ec57fcaee5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php index 5f896a9029..939bce68ef 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php index 499fbf2989..4e8d743b4c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/SystemController.php b/app/code/core/Mage/Adminhtml/controllers/SystemController.php index 50af1d3935..612b0c4d69 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SystemController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SystemController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/TagController.php b/app/code/core/Mage/Adminhtml/controllers/TagController.php index e6be3381f1..a6be40dcfb 100644 --- a/app/code/core/Mage/Adminhtml/controllers/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/TagController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php index 37fa8ccacb..13d2317560 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -45,7 +45,7 @@ public function indexAction() ->_title($this->__('Customer Tax Classes')); $this->_initAction() - ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class')->setClassType('CUSTOMER')) + ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class')->setClassType(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER)) ->renderLayout(); } @@ -72,7 +72,7 @@ public function editAction() $model = Mage::getModel('tax/class'); if ($classId) { $model->load($classId); - if (!$model->getId() || $model->getClassType() != 'CUSTOMER') { + if (!$model->getId() || $model->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; @@ -90,7 +90,7 @@ public function editAction() $this->_initAction() ->_addBreadcrumb($classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'), $classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')) - ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class_edit')->setData('action', $this->getUrl('*/tax_class/save'))->setClassType('CUSTOMER')) + ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class_edit')->setData('action', $this->getUrl('*/tax_class/save'))->setClassType(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER)) ->renderLayout(); } @@ -104,7 +104,7 @@ public function deleteAction() $classModel = Mage::getModel('tax/class') ->load($classId); - if (!$classModel->getId() || $classModel->getClassType() != 'CUSTOMER') { + if (!$classModel->getId() || $classModel->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; @@ -112,7 +112,7 @@ public function deleteAction() $ruleCollection = Mage::getModel('tax/calculation_rule') ->getCollection() - ->setClassTypeFilter('CUSTOMER', $classId); + ->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER, $classId); if ($ruleCollection->getSize() > 0) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('You cannot delete this tax class as it is used in Tax Rules. You have to delete the rules it is used in first.')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php index 93fbd86723..4929117cb4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,7 +44,7 @@ public function indexAction() ->_title($this->__('Customer Tax Classes')); $this->_initAction() - ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class')->setClassType('PRODUCT')) + ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class')->setClassType(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)) ->renderLayout(); } @@ -71,7 +71,7 @@ public function editAction() $model = Mage::getModel('tax/class'); if ($classId) { $model->load($classId); - if (!$model->getId() || $model->getClassType() != 'PRODUCT') { + if (!$model->getId() || $model->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; @@ -89,7 +89,7 @@ public function editAction() $this->_initAction() ->_addBreadcrumb($classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'), $classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class')) - ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class_edit')->setData('action', $this->getUrl('*/tax_class/save'))->setClassType('PRODUCT')) + ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class_edit')->setData('action', $this->getUrl('*/tax_class/save'))->setClassType(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)) ->renderLayout(); } @@ -103,7 +103,7 @@ public function deleteAction() $classModel = Mage::getModel('tax/class') ->load($classId); - if (!$classModel->getId() || $classModel->getClassType() != 'PRODUCT') { + if (!$classModel->getId() || $classModel->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; @@ -111,7 +111,7 @@ public function deleteAction() $ruleCollection = Mage::getModel('tax/calculation_rule') ->getCollection() - ->setClassTypeFilter('PRODUCT', $classId); + ->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT, $classId); if ($ruleCollection->getSize() > 0) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('You cannot delete this tax class as it is used in Tax Rules. You have to delete the rules it is used in first.')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php index cc8965b9b5..50ec6e9de1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php @@ -20,15 +20,15 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Adminhtml common tax class controller * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Adminhtml * @author Magento Core Team */ class Mage_Adminhtml_Tax_ClassController extends Mage_Adminhtml_Controller_Action @@ -42,12 +42,9 @@ public function saveAction() if ($postData = $this->getRequest()->getPost()) { //filtering - /** @var $helper Mage_Adminhtml_Helper_Data */ - $helper = Mage::helper('adminhtml'); - $postData['class_name'] = $helper->stripTags($postData['class_name']); + $postData['class_name'] = Mage::helper('adminhtml')->stripTags($postData['class_name']); - $model = Mage::getModel('tax/class') - ->setData($postData); + $model = Mage::getModel('tax/class')->setData($postData); try { $model->save(); @@ -55,7 +52,9 @@ public function saveAction() $classType = $model->getClassType(); $classUrl = '*/tax_class_' . strtolower($classType); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('The tax class has been saved.')); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('tax')->__('The tax class has been saved.') + ); $this->_redirect($classUrl); return ; @@ -64,7 +63,9 @@ public function saveAction() Mage::getSingleton('adminhtml/session')->setClassData($postData); $this->_redirectReferer(); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('An error occurred while saving this tax class.')); + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('tax')->__('An error occurred while saving this tax class.') + ); Mage::getSingleton('adminhtml/session')->setClassData($postData); $this->_redirectReferer(); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php index 45b5236f19..9decba622a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -97,8 +97,10 @@ public function saveAction() /** @var $helper Mage_Adminhtml_Helper_Data */ $helper = Mage::helper('adminhtml'); $ratePost['code'] = $helper->stripTags($ratePost['code']); - foreach ($ratePost['title'] as &$title) { - $title = $helper->stripTags($title); + if (!empty($ratePost['title'])) { + foreach ($ratePost['title'] as &$title) { + $title = $helper->stripTags($title); + } } $rateId = $this->getRequest()->getParam('tax_calculation_rate_id'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php index 17460b25ba..bdd9c2b8e5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php index 373d34cd46..7ce26034e6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php +++ b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Adminhtml/etc/adminhtml.xml b/app/code/core/Mage/Adminhtml/etc/adminhtml.xml index 80c7045607..e1b1c761e9 100644 --- a/app/code/core/Mage/Adminhtml/etc/adminhtml.xml +++ b/app/code/core/Mage/Adminhtml/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -61,7 +61,7 @@ 30 - Dataflow - Advance Profiles + Dataflow - Advanced Profiles adminhtml/system_convert_profile 40 diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index f7041b6409..9d627b74de 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -31,16 +31,16 @@ 0.7.1 - Mage_Adminhtml_Model - adminhtml_mysql4 + adminhtml_resource - - Mage_Adminhtml_Model_Mysql4 - + + Mage_Adminhtml_Model_Resource + adminhtml_mysql4 + @@ -56,7 +56,6 @@ - @@ -80,7 +79,6 @@ - @@ -92,7 +90,6 @@ - @@ -197,7 +194,6 @@ - default @@ -212,7 +208,9 @@ - true + + true + admin/index/noRoute diff --git a/app/code/core/Mage/Api/Controller/Action.php b/app/code/core/Mage/Api/Controller/Action.php index 7779c1c8e4..393ef72b11 100644 --- a/app/code/core/Mage/Api/Controller/Action.php +++ b/app/code/core/Mage/Api/Controller/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Exception.php b/app/code/core/Mage/Api/Exception.php index fccafd8eea..2e52caaa08 100644 --- a/app/code/core/Mage/Api/Exception.php +++ b/app/code/core/Mage/Api/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Helper/Data.php b/app/code/core/Mage/Api/Helper/Data.php index e14d6e17df..ddf394c8a6 100644 --- a/app/code/core/Mage/Api/Helper/Data.php +++ b/app/code/core/Mage/Api/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl.php b/app/code/core/Mage/Api/Model/Acl.php index 30973bc775..9f78a51ae4 100644 --- a/app/code/core/Mage/Api/Model/Acl.php +++ b/app/code/core/Mage/Api/Model/Acl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Assert/Ip.php b/app/code/core/Mage/Api/Model/Acl/Assert/Ip.php index 11dbba3d0c..658ba81f7b 100644 --- a/app/code/core/Mage/Api/Model/Acl/Assert/Ip.php +++ b/app/code/core/Mage/Api/Model/Acl/Assert/Ip.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php index 7da109423f..a3ed54283e 100644 --- a/app/code/core/Mage/Api/Model/Acl/Assert/Time.php +++ b/app/code/core/Mage/Api/Model/Acl/Assert/Time.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Resource.php b/app/code/core/Mage/Api/Model/Acl/Resource.php index 9b27684947..514819c0be 100644 --- a/app/code/core/Mage/Api/Model/Acl/Resource.php +++ b/app/code/core/Mage/Api/Model/Acl/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Role.php b/app/code/core/Mage/Api/Model/Acl/Role.php index e87eebd13a..c02e51eb41 100644 --- a/app/code/core/Mage/Api/Model/Acl/Role.php +++ b/app/code/core/Mage/Api/Model/Acl/Role.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,23 @@ /** * User acl role * - * @category Mage - * @package Mage_Api + * @method Mage_Api_Model_Resource_Role _getResource() + * @method Mage_Api_Model_Resource_Role getResource() + * @method int getParentId() + * @method Mage_Api_Model_Acl_Role setParentId(int $value) + * @method int getTreeLevel() + * @method Mage_Api_Model_Acl_Role setTreeLevel(int $value) + * @method int getSortOrder() + * @method Mage_Api_Model_Acl_Role setSortOrder(int $value) + * @method string getRoleType() + * @method Mage_Api_Model_Acl_Role setRoleType(string $value) + * @method int getUserId() + * @method Mage_Api_Model_Acl_Role setUserId(int $value) + * @method string getRoleName() + * @method Mage_Api_Model_Acl_Role setRoleName(string $value) + * + * @category Mage + * @package Mage_Api * @author Magento Core Team */ class Mage_Api_Model_Acl_Role extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Api/Model/Acl/Role/Generic.php b/app/code/core/Mage/Api/Model/Acl/Role/Generic.php index 1a94a402bc..3a145bd249 100644 --- a/app/code/core/Mage/Api/Model/Acl/Role/Generic.php +++ b/app/code/core/Mage/Api/Model/Acl/Role/Generic.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Role/Group.php b/app/code/core/Mage/Api/Model/Acl/Role/Group.php index 268f38465d..ebb710d7b0 100644 --- a/app/code/core/Mage/Api/Model/Acl/Role/Group.php +++ b/app/code/core/Mage/Api/Model/Acl/Role/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Role/Registry.php b/app/code/core/Mage/Api/Model/Acl/Role/Registry.php index e492fd600d..6744f5ef53 100644 --- a/app/code/core/Mage/Api/Model/Acl/Role/Registry.php +++ b/app/code/core/Mage/Api/Model/Acl/Role/Registry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Acl/Role/User.php b/app/code/core/Mage/Api/Model/Acl/Role/User.php index b8376f4729..dde5d2b311 100644 --- a/app/code/core/Mage/Api/Model/Acl/Role/User.php +++ b/app/code/core/Mage/Api/Model/Acl/Role/User.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Config.php b/app/code/core/Mage/Api/Model/Config.php index 06cd4fe8ec..17493ea4e3 100644 --- a/app/code/core/Mage/Api/Model/Config.php +++ b/app/code/core/Mage/Api/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Mysql4/Acl.php b/app/code/core/Mage/Api/Model/Mysql4/Acl.php index 54546c05c6..9ff943da8f 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Acl.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Acl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,133 +28,10 @@ /** * Resource model for admin ACL * - * @category Mage - * @package Mage_Api - * @author Magento Core Team + * @category Mage + * @package Mage_Api + * @author Magento Core Team */ -class Mage_Api_Model_Mysql4_Acl extends Mage_Core_Model_Mysql4_Abstract +class Mage_Api_Model_Mysql4_Acl extends Mage_Api_Model_Resource_Acl { - - /** - * Initialize resource connections - * - */ - protected function _construct() - { - $this->_init('api/role', 'role_id'); - } - - /** - * Load ACL for the user - * - * @param integer $userId - * @return Mage_Api_Model_Acl - */ - function loadAcl() - { - $acl = Mage::getModel('api/acl'); - - Mage::getSingleton('api/config')->loadAclResources($acl); - - $roleTable = Mage::getSingleton('core/resource')->getTableName('api/role'); - $rolesArr = $this->_getReadAdapter()->fetchAll( - $this->_getReadAdapter()->select() - ->from($this->getTable('role')) - ->order(array('tree_level', 'role_type')) - ); - $this->loadRoles($acl, $rolesArr); - - $rulesArr = $this->_getReadAdapter()->fetchAll( - $this->_getReadAdapter()->select() - ->from(array('r'=>$this->getTable('rule'))) - ->joinLeft( - array('a'=>$this->getTable('assert')), - 'a.assert_id=r.assert_id', - array('assert_type', 'assert_data') - )); - $this->loadRules($acl, $rulesArr); - return $acl; - } - - /** - * Load roles - * - * @param Mage_Api_Model_Acl $acl - * @param array $rolesArr - * @return Mage_Api_Model_Mysql4_Acl - */ - function loadRoles(Mage_Api_Model_Acl $acl, array $rolesArr) - { - foreach ($rolesArr as $role) { - $parent = $role['parent_id']>0 ? Mage_Api_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null; - switch ($role['role_type']) { - case Mage_Api_Model_Acl::ROLE_TYPE_GROUP: - $roleId = $role['role_type'].$role['role_id']; - $acl->addRole(Mage::getModel('api/acl_role_group', $roleId), $parent); - break; - - case Mage_Api_Model_Acl::ROLE_TYPE_USER: - $roleId = $role['role_type'].$role['user_id']; - if (!$acl->hasRole($roleId)) { - $acl->addRole(Mage::getModel('api/acl_role_user', $roleId), $parent); - } else { - $acl->addRoleParent($roleId, $parent); - } - break; - } - } - - return $this; - } - - /** - * Load rules - * - * @param Mage_Api_Model_Acl $acl - * @param array $rulesArr - * @return Mage_Api_Model_Mysql4_Acl - */ - function loadRules(Mage_Api_Model_Acl $acl, array $rulesArr) - { - foreach ($rulesArr as $rule) { - $role = $rule['role_type'].$rule['role_id']; - $resource = $rule['resource_id']; - $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null; - - $assert = null; - if (0!=$rule['assert_id']) { - $assertClass = Mage::getSingleton('api/config')->getAclAssert($rule['assert_type'])->getClassName(); - $assert = new $assertClass(unserialize($rule['assert_data'])); - } - try { - if ( $rule['permission'] == 'allow' ) { - $acl->allow($role, $resource, $privileges, $assert); - } else if ( $rule['permission'] == 'deny' ) { - $acl->deny($role, $resource, $privileges, $assert); - } - } catch (Exception $e) { - //$m = $e->getMessage(); - //if ( eregi("^Resource '(.*)' not found", $m) ) { - // Deleting non existent resource rule from rules table - //$cond = $this->_write->quoteInto('resource_id = ?', $resource); - //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond); - //} else { - //TODO: We need to log such exceptions to somewhere like a system/errors.log - //} - } - /* - switch ($rule['permission']) { - case Mage_Api_Model_Acl::RULE_PERM_ALLOW: - $acl->allow($role, $resource, $privileges, $assert); - break; - - case Mage_Api_Model_Acl::RULE_PERM_DENY: - $acl->deny($role, $resource, $privileges, $assert); - break; - } - */ - } - return $this; - } - } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php b/app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php index a0e410e605..a50733e659 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php @@ -20,29 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * ACL role resource * - * @category Mage - * @package Mage_Api + * @category Mage + * @package Mage_Api * @author Magento Core Team */ -class Mage_Api_Model_Mysql4_Acl_Role extends Mage_Core_Model_Mysql4_Abstract +class Mage_Api_Model_Mysql4_Acl_Role extends Mage_Api_Model_Resource_Acl_Role { - protected function _construct() - { - $this->_init('api/role', 'role_id'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$role->getId()) { - $this->setCreated(Mage::getSingleton('core/date')->gmtDate()); - } - return $this; - } } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php index bc21a2e637..7598e6b0d9 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Roles collection * - * @category Mage - * @package Mage_Api + * @category Mage + * @package Mage_Api * @author Magento Core Team */ -class Mage_Api_Model_Mysql4_Acl_Role_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Api_Model_Mysql4_Acl_Role_Collection extends Mage_Api_Model_Resource_Acl_Role_Collection { - protected function _construct() - { - $this->_init('api/role'); - } } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php index db7fbdbc3c..e6015d197e 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Permissions_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Permissions_Collection extends Mage_Api_Model_Resource_Permissions_Collection { - protected function _construct() - { - $this->_init('api/rules'); - } } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Role.php b/app/code/core/Mage/Api/Model/Mysql4/Role.php index f582cf1164..ca8f5cc5c4 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Role.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Role.php @@ -20,31 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Role extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('api/role', 'role_id'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if ( !$object->getId() ) { - $object->setCreated(now()); - } - $object->setModified(now()); - return $this; - } - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (!intval($value) && is_string($value)) { - $field = 'role_id'; - } - return parent::load($object, $value, $field); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Role extends Mage_Api_Model_Resource_Role +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php index 3a608bc9a6..2c94348a7d 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php @@ -20,33 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Role_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('api/role'); - } - - /** - * Enter description here... - * - * @param int $userId - * @return Mage_Api_Model_Mysql4_Role_Collection - */ - public function setUserFilter($userId) - { - $this->addFieldToFilter('user_id', $userId); - $this->addFieldToFilter('role_type', 'G'); - return $this; - } - public function setRolesFilter() - { - $this->addFieldToFilter('role_type', 'G'); - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Role_Collection extends Mage_Api_Model_Resource_Role_Collection +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Roles.php b/app/code/core/Mage/Api/Model/Mysql4/Roles.php index 9160d96b08..209c985815 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Roles.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Roles.php @@ -20,76 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Roles extends Mage_Core_Model_Mysql4_Abstract -{ - protected $_usersTable; - protected $_ruleTable; - - protected function _construct() { - $this->_init('api/role', 'role_id'); - - $this->_usersTable = $this->getTable('api/user'); - $this->_ruleTable = $this->getTable('api/rule'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $role) - { - if ($role->getId() == '') { - if ($role->getIdFieldName()) { - $role->unsetData($role->getIdFieldName()); - } else { - $role->unsetData('id'); - } - } - - if ($role->getPid() > 0) { - $row = $this->load($role->getPid()); - } else { - $row = array('tree_level' => 0); - } - $role->setTreeLevel($row['tree_level'] + 1); - $role->setRoleName($role->getName()); - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $role) - { - $this->_updateRoleUsersAcl($role); - Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG); - return $this; - } - - protected function _afterDelete(Mage_Core_Model_Abstract $role) - { - $this->_getWriteAdapter()->delete($this->getMainTable(), "parent_id={$role->getId()}"); - $this->_getWriteAdapter()->delete($this->_ruleTable, "role_id={$role->getId()}"); - return $this; - } - public function getRoleUsers(Mage_Api_Model_Roles $role) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getMainTable(), array('user_id'))->where("(parent_id = '{$role->getId()}' AND role_type = 'U') AND user_id > 0"); - return $read->fetchCol($select); - } - - private function _updateRoleUsersAcl(Mage_Api_Model_Roles $role) - { - $write = $this->_getWriteAdapter(); - $users = $this->getRoleUsers($role); - $rowsCount = 0; - if ( sizeof($users) > 0 ) { - $inStatement = implode(", ", $users); - $rowsCount = $write->update($this->_usersTable, array('reload_acl_flag' => 1), "user_id IN({$inStatement})"); - } - if ($rowsCount > 0) { - return true; - } else { - return false; - } - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Roles extends Mage_Api_Model_Resource_Roles +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php index be1c5eec1c..0f6c513b41 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php @@ -20,24 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Roles_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('api/role'); - } - - protected function _initSelect(){ - parent::_initSelect(); - $this->getSelect()->where("main_table.role_type='G'"); - } - public function toOptionArray() - { - return $this->_toOptionArray('role_id', 'role_name'); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Roles_Collection extends Mage_Api_Model_Resource_Roles_Collection +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php index 037577d735..be7bbf97d0 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Roles_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('api/user'); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->getSelect()->where("user_id > 0"); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Roles_User_Collection extends Mage_Api_Model_Resource_Roles_User_Collection +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Rules.php b/app/code/core/Mage/Api/Model/Mysql4/Rules.php index 23d18cb5af..3237831e64 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Rules.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Rules.php @@ -20,48 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Rules extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() { - $this->_init('api/rule', 'rule_id'); - } - - public function saveRel(Mage_Api_Model_Rules $rule) { - $this->_getWriteAdapter()->beginTransaction(); - - try { - $roleId = $rule->getRoleId(); - $this->_getWriteAdapter()->delete($this->getMainTable(), "role_id = {$roleId}"); - $masterResources = Mage::getModel('api/roles')->getResourcesList2D(); - $masterAdmin = false; - if ( $postedResources = $rule->getResources() ) { - foreach ($masterResources as $index => $resName) { - if ( !$masterAdmin ) { - $permission = ( in_array($resName, $postedResources) )? 'allow' : 'deny'; - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'role_type' => 'G', - 'resource_id' => trim($resName, '/'), - 'privileges' => '', # FIXME !!! - 'assert_id' => 0, - 'role_id' => $roleId, - 'permission' => $permission - )); - } - if ( $resName == 'all' && $permission == 'allow' ) { - $masterAdmin = true; - } - } - } - $this->_getWriteAdapter()->commit(); - } catch (Mage_Core_Exception $e) { - throw $e; - } catch (Exception $e){ - $this->_getWriteAdapter()->rollBack(); - } - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Rules extends Mage_Api_Model_Resource_Rules +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php index 022566219d..b6c66248f7 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_Rules_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected function _construct() - { - $this->_init('api/rules'); - } - - public function getByRoles($id) - { - $this->getSelect()->where("role_id = ?", (int)$id); - return $this; - } - public function addSortByLength() - { - $this->getSelect()->columns(array('length' => 'LENGTH(resource_id)')) - ->order('length desc'); - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_Rules_Collection extends Mage_Api_Model_Resource_Rules_Collection +{ } diff --git a/app/code/core/Mage/Api/Model/Mysql4/User.php b/app/code/core/Mage/Api/Model/Mysql4/User.php index 2fa75d2f31..86220cbb98 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/User.php +++ b/app/code/core/Mage/Api/Model/Mysql4/User.php @@ -20,311 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * ACL user resource * - * @category Mage - * @package Mage_Api + * @category Mage + * @package Mage_Api * @author Magento Core Team */ -class Mage_Api_Model_Mysql4_User extends Mage_Core_Model_Mysql4_Abstract +class Mage_Api_Model_Mysql4_User extends Mage_Api_Model_Resource_User { - - protected function _construct() - { - $this->_init('api/user', 'user_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array( - array( - 'field' => 'email', - 'title' => Mage::helper('api')->__('Email') - ), - array( - 'field' => 'username', - 'title' => Mage::helper('api')->__('User Name') - ), - ); - return $this; - } - - /** - * Authenticate user by $username and $password - * - * @param string $username - * @param string $password - * @return boolean|Object - */ - public function recordLogin(Mage_Api_Model_User $user) - { - $data = array( - 'lognum' => $user->getLognum()+1, - ); - $condition = $this->_getWriteAdapter()->quoteInto('user_id=?', $user->getUserId()); - $this->_getWriteAdapter()->update($this->getTable('api/user'), $data, $condition); - return $this; - } - - public function recordSession(Mage_Api_Model_User $user) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('api/session'), 'user_id') - ->where('user_id = ?', $user->getId()) - ->where('sessid = ?', $user->getSessid()); - $logdate = now(); - if ($this->_getReadAdapter()->fetchRow($select)) { - $this->_getWriteAdapter()->update( - $this->getTable('api/session'), - array ('logdate' => $logdate), - $this->_getReadAdapter()->quoteInto('user_id = ?', $user->getId()) . ' AND ' - . $this->_getReadAdapter()->quoteInto('sessid = ?', $user->getSessid()) - ); - } else { - $this->_getWriteAdapter()->insert( - $this->getTable('api/session'), - array( - 'user_id' => $user->getId(), - 'logdate' => $logdate, - 'sessid' => $user->getSessid() - ) - ); - } - $user->setLogdate($logdate); - return $this; - } - - public function cleanOldSessions(Mage_Api_Model_User $user) - { - $timeout = Mage::getStoreConfig('api/config/session_timeout'); - $this->_getWriteAdapter()->delete( - $this->getTable('api/session'), - $this->_getReadAdapter()->quoteInto('user_id = ?', $user->getId()) . ' AND ' - . new Zend_Db_Expr('(UNIX_TIMESTAMP(\'' . now() . '\') - UNIX_TIMESTAMP(logdate)) > ' . $timeout) - ); - return $this; - } - - public function loadByUsername($username) - { - $select = $this->_getReadAdapter()->select()->from($this->getTable('api/user')) - ->where('username=:username'); - return $this->_getReadAdapter()->fetchRow($select, array('username'=>$username)); - } - - public function loadBySessId ($sessId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('api/session')) - ->where('sessid = ?', $sessId); - if ($apiSession = $this->_getReadAdapter()->fetchRow($select)) { - $selectUser = $this->_getReadAdapter()->select() - ->from($this->getTable('api/user')) - ->where('user_id = ?', $apiSession['user_id']); - if ($user = $this->_getReadAdapter()->fetchRow($selectUser)) { - return array_merge($user, $apiSession); - } - } - return array(); - } - - public function clearBySessId($sessid) - { - $this->_getWriteAdapter()->delete( - $this->getTable('api/session'), - $this->_getReadAdapter()->quoteInto('sessid = ?', $sessid) - ); - return $this; - } - - public function hasAssigned2Role($user) - { - if (is_numeric($user)) { - $userId = $user; - } else if ($user instanceof Mage_Core_Model_Abstract) { - $userId = $user->getUserId(); - } else { - return null; - } - - if ( $userId > 0 ) { - $dbh = $this->_getReadAdapter(); - $select = $dbh->select(); - $select->from($this->getTable('api/role')) - ->where("parent_id > 0 AND user_id = {$userId}"); - return $dbh->fetchAll($select); - } else { - return null; - } - } - - protected function _beforeSave(Mage_Core_Model_Abstract $user) - { - if (!$user->getId()) { - $user->setCreated(now()); - } - $user->setModified(now()); - return $this; - } - - public function load(Mage_Core_Model_Abstract $user, $value, $field=null) - { - return parent::load($user, $value, $field); - } - - public function delete(Mage_Core_Model_Abstract $user) - { - $dbh = $this->_getWriteAdapter(); - $uid = (int) $user->getId(); - $dbh->beginTransaction(); - try { - $dbh->delete($this->getTable('api/user'), "user_id=$uid"); - $dbh->delete($this->getTable('api/role'), "user_id=$uid"); - } catch (Mage_Core_Exception $e) { - throw $e; - return false; - } catch (Exception $e){ - $dbh->rollBack(); - return false; - } - $dbh->commit(); - return true; - } - - public function _saveRelations(Mage_Core_Model_Abstract $user) - { - $rolesIds = $user->getRoleIds(); - - if( !is_array($rolesIds) || count($rolesIds) == 0 ) { - return $user; - } - - $this->_getWriteAdapter()->beginTransaction(); - - try { - $this->_getWriteAdapter()->delete($this->getTable('api/role'), "user_id = {$user->getId()}"); - foreach ($rolesIds as $rid) { - $rid = intval($rid); - if ($rid > 0) { - //$row = $this->load($user, $rid); - } else { - $row = array('tree_level' => 0); - } - $row = array('tree_level' => 0); - - $data = array( - 'parent_id' => $rid, - 'tree_level' => $row['tree_level'] + 1, - 'sort_order' => 0, - 'role_type' => 'U', - 'user_id' => $user->getId(), - 'role_name' => $user->getFirstname() - ); - $this->_getWriteAdapter()->insert($this->getTable('api/role'), $data); - } - $this->_getWriteAdapter()->commit(); - } catch (Mage_Core_Exception $e) { - throw $e; - } catch (Exception $e){ - $this->_getWriteAdapter()->rollBack(); - } - } - - public function _getRoles(Mage_Core_Model_Abstract $user) - { - if ( !$user->getId() ) { - return array(); - } - $table = $this->getTable('api/role'); - $read = $this->_getReadAdapter(); - $select = $read->select()->from($table, array()) - ->joinLeft(array('ar' => $table), - "(ar.role_id = `{$table}`.parent_id and ar.role_type = 'G')", - array('role_id')) - ->where("`{$table}`.user_id = {$user->getId()}"); - - return (($roles = $read->fetchCol($select)) ? $roles : array()); - } - - public function add(Mage_Core_Model_Abstract $user) { - - $dbh = $this->_getWriteAdapter(); - - $aRoles = $this->hasAssigned2Role($user); - if ( sizeof($aRoles) > 0 ) { - foreach($aRoles as $idx => $data){ - $dbh->delete($this->getTable('api/role'), "role_id = {$data['role_id']}"); - } - } - - if ($user->getId() > 0) { - $role = Mage::getModel('api/role')->load($user->getRoleId()); - } else { - $role = array('tree_level' => 0); - } - $dbh->insert($this->getTable('api/role'), array( - 'parent_id' => $user->getRoleId(), - 'tree_level'=> ($role->getTreeLevel() + 1), - 'sort_order'=> 0, - 'role_type' => 'U', - 'user_id' => $user->getUserId(), - 'role_name' => $user->getFirstname() - )); - - return $this; - } - - public function deleteFromRole(Mage_Core_Model_Abstract $user) { - if ( $user->getUserId() <= 0 ) { - return $this; - } - if ( $user->getRoleId() <= 0 ) { - return $this; - } - $dbh = $this->_getWriteAdapter(); - $condition = "`{$this->getTable('api/role')}`.user_id = " . $dbh->quote($user->getUserId()) . - " AND `{$this->getTable('api/role')}`.parent_id = " . $dbh->quote($user->getRoleId()); - $dbh->delete($this->getTable('api/role'), $condition); - return $this; - } - - public function roleUserExists(Mage_Core_Model_Abstract $user) - { - if ( $user->getUserId() > 0 ) { - $roleTable = $this->getTable('api/role'); - $dbh = $this->_getReadAdapter(); - $select = $dbh->select()->from($roleTable) - ->where("parent_id = {$user->getRoleId()} AND user_id = {$user->getUserId()}"); - return $dbh->fetchCol($select); - } else { - return array(); - } - } - - public function userExists(Mage_Core_Model_Abstract $user) - { - $usersTable = $this->getTable('api/user'); - $db = $this->_getReadAdapter(); - - $select = $db->select() - ->from(array('u' => $usersTable)) - ->where('u.user_id != ?', (int) $user->getId()) - ->where('u.username = :username OR u.email = :email') - ; - $row = $db->fetchRow($select, array( - ':username' => $user->getUsername(), - ':email' => $user->getUsername(), - )); - return $row; - } } diff --git a/app/code/core/Mage/Api/Model/Mysql4/User/Collection.php b/app/code/core/Mage/Api/Model/Mysql4/User/Collection.php index 04485f85f2..034cf40feb 100644 --- a/app/code/core/Mage/Api/Model/Mysql4/User/Collection.php +++ b/app/code/core/Mage/Api/Model/Mysql4/User/Collection.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Api_Model_Mysql4_User_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ +class Mage_Api_Model_Mysql4_User_Collection extends Mage_Api_Model_Resource_User_Collection { - protected function _construct() - { - $this->_init('api/user'); - } } diff --git a/app/code/core/Mage/Api/Model/Resource/Abstract.php b/app/code/core/Mage/Api/Model/Resource/Abstract.php index 208beda0ff..7bbbc3dac3 100644 --- a/app/code/core/Mage/Api/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Api/Model/Resource/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Resource/Acl.php b/app/code/core/Mage/Api/Model/Resource/Acl.php new file mode 100755 index 0000000000..1227dd81db --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Acl.php @@ -0,0 +1,157 @@ + + */ +class Mage_Api_Model_Resource_Acl extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource connections + * + */ + protected function _construct() + { + $this->_init('api/role', 'role_id'); + } + + /** + * Load ACL for the user + * + * @return Mage_Api_Model_Acl + */ + public function loadAcl() + { + $acl = Mage::getModel('api/acl'); + $adapter = $this->_getReadAdapter(); + + Mage::getSingleton('api/config')->loadAclResources($acl); + + $rolesArr = $adapter->fetchAll( + $adapter->select() + ->from($this->getTable('api/role')) + ->order(array('tree_level', 'role_type')) + ); + $this->loadRoles($acl, $rolesArr); + + $rulesArr = $adapter->fetchAll( + $adapter->select() + ->from(array('r'=>$this->getTable('api/rule'))) + ->joinLeft( + array('a'=>$this->getTable('api/assert')), + 'a.assert_id=r.assert_id', + array('assert_type', 'assert_data') + )); + $this->loadRules($acl, $rulesArr); + return $acl; + } + + /** + * Load roles + * + * @param Mage_Api_Model_Acl $acl + * @param array $rolesArr + * @return Mage_Api_Model_Resource_Acl + */ + public function loadRoles(Mage_Api_Model_Acl $acl, array $rolesArr) + { + foreach ($rolesArr as $role) { + $parent = $role['parent_id']>0 ? Mage_Api_Model_Acl::ROLE_TYPE_GROUP.$role['parent_id'] : null; + switch ($role['role_type']) { + case Mage_Api_Model_Acl::ROLE_TYPE_GROUP: + $roleId = $role['role_type'].$role['role_id']; + $acl->addRole(Mage::getModel('api/acl_role_group', $roleId), $parent); + break; + + case Mage_Api_Model_Acl::ROLE_TYPE_USER: + $roleId = $role['role_type'].$role['user_id']; + if (!$acl->hasRole($roleId)) { + $acl->addRole(Mage::getModel('api/acl_role_user', $roleId), $parent); + } else { + $acl->addRoleParent($roleId, $parent); + } + break; + } + } + + return $this; + } + + /** + * Load rules + * + * @param Mage_Api_Model_Acl $acl + * @param array $rulesArr + * @return Mage_Api_Model_Resource_Acl + */ + public function loadRules(Mage_Api_Model_Acl $acl, array $rulesArr) + { + foreach ($rulesArr as $rule) { + $role = $rule['role_type'].$rule['role_id']; + $resource = $rule['resource_id']; + $privileges = !empty($rule['api_privileges']) ? explode(',', $rule['api_privileges']) : null; + + $assert = null; + if (0!=$rule['assert_id']) { + $assertClass = Mage::getSingleton('api/config')->getAclAssert($rule['assert_type'])->getClassName(); + $assert = new $assertClass(unserialize($rule['assert_data'])); + } + try { + if ($rule['api_permission'] == 'allow') { + $acl->allow($role, $resource, $privileges, $assert); + } else if ($rule['api_permission'] == 'deny') { + $acl->deny($role, $resource, $privileges, $assert); + } + } catch (Exception $e) { + //$m = $e->getMessage(); + //if ( eregi("^Resource '(.*)' not found", $m) ) { + // Deleting non existent resource rule from rules table + //$cond = $this->_write->quoteInto('resource_id = ?', $resource); + //$this->_write->delete(Mage::getSingleton('core/resource')->getTableName('admin/rule'), $cond); + //} else { + //TODO: We need to log such exceptions to somewhere like a system/errors.log + //} + } + /* + switch ($rule['api_permission']) { + case Mage_Api_Model_Acl::RULE_PERM_ALLOW: + $acl->allow($role, $resource, $privileges, $assert); + break; + + case Mage_Api_Model_Acl::RULE_PERM_DENY: + $acl->deny($role, $resource, $privileges, $assert); + break; + } + */ + } + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Mysql4/Convert/Profile.php b/app/code/core/Mage/Api/Model/Resource/Acl/Role.php old mode 100644 new mode 100755 similarity index 63% rename from app/code/core/Mage/Core/Model/Mysql4/Convert/Profile.php rename to app/code/core/Mage/Api/Model/Resource/Acl/Role.php index fa40e9d6db..e08ee84138 --- a/app/code/core/Mage/Core/Model/Mysql4/Convert/Profile.php +++ b/app/code/core/Mage/Api/Model/Resource/Acl/Role.php @@ -19,31 +19,41 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Api + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Convert profile resource model + * ACL role resource * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Api * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Convert_Profile extends Mage_Core_Model_Mysql4_Abstract +class Mage_Api_Model_Resource_Acl_Role extends Mage_Core_Model_Resource_Db_Abstract { + /** + * Resource initialization + * + */ protected function _construct() { - $this->_init('core/convert_profile', 'profile_id'); + $this->_init('api/role', 'role_id'); } + /** + * Action before save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Api_Model_Resource_Acl_Role + */ protected function _beforeSave(Mage_Core_Model_Abstract $object) { - if (!$object->getCreatedAt()) { - $object->setCreatedAt($this->formatDate(time())); + if (!$object->getId()) { + $this->setCreated(Mage::getSingleton('core/date')->gmtDate()); } - $object->setUpdatedAt($this->formatDate(time())); - parent::_beforeSave($object); + return $this; } } diff --git a/app/code/core/Mage/Api/Model/Resource/Acl/Role/Collection.php b/app/code/core/Mage/Api/Model/Resource/Acl/Role/Collection.php new file mode 100755 index 0000000000..7e22a04e53 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Acl/Role/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Api_Model_Resource_Acl_Role_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/role'); + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Permissions/Collection.php b/app/code/core/Mage/Api/Model/Resource/Permissions/Collection.php new file mode 100755 index 0000000000..70b71f3495 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Permissions/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Api_Model_Resource_Permissions_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/rules'); + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Role.php b/app/code/core/Mage/Api/Model/Resource/Role.php new file mode 100755 index 0000000000..72524dc513 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Role.php @@ -0,0 +1,76 @@ + + */ +class Mage_Api_Model_Resource_Role extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('api/role', 'role_id'); + } + + /** + * Action before save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Api_Model_Resource_Role + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getId()) { + $object->setCreated(now()); + } + $object->setModified(now()); + return $this; + } + + /** + * Load an object + * + * @param Mage_Core_Model_Abstract $object + * @param mixed $value + * @param string $field field to load by (defaults to model id) + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (!intval($value) && is_string($value)) { + $field = 'role_id'; + } + return parent::load($object, $value, $field); + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Role/Collection.php b/app/code/core/Mage/Api/Model/Resource/Role/Collection.php new file mode 100755 index 0000000000..5c81104446 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Role/Collection.php @@ -0,0 +1,69 @@ + + */ +class Mage_Api_Model_Resource_Role_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/role'); + } + + /** + * Aet user filter + * + * @param int $userId + * @return Mage_Api_Model_Resource_Role_Collection + */ + public function setUserFilter($userId) + { + $this->addFieldToFilter('user_id', $userId); + $this->addFieldToFilter('role_type', Mage_Api_Model_Acl::ROLE_TYPE_GROUP); + return $this; + } + + /** + * Set roles filter + * + * @return Mage_Api_Model_Resource_Role_Collection + */ + public function setRolesFilter() + { + $this->addFieldToFilter('role_type', Mage_Api_Model_Acl::ROLE_TYPE_GROUP); + return $this; + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Roles.php b/app/code/core/Mage/Api/Model/Resource/Roles.php new file mode 100755 index 0000000000..32eadd0844 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Roles.php @@ -0,0 +1,151 @@ + + */ +class Mage_Api_Model_Resource_Roles extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * User table name + * + * @var unknown + */ + protected $_usersTable; + + /** + * Rule table name + * + * @var unknown + */ + protected $_ruleTable; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('api/role', 'role_id'); + + $this->_usersTable = $this->getTable('api/user'); + $this->_ruleTable = $this->getTable('api/rule'); + } + + /** + * Action before save + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Api_Model_Resource_Roles + */ + protected function _beforeSave(Mage_Core_Model_Abstract $role) + { + if ($role->getId() == '') { + if ($role->getIdFieldName()) { + $role->unsetData($role->getIdFieldName()); + } else { + $role->unsetData('id'); + } + } + + if ($role->getPid() > 0) { + $row = $this->load($role->getPid()); + } else { + $row = array('tree_level' => 0); + } + $role->setTreeLevel($row['tree_level'] + 1); + $role->setRoleName($role->getName()); + return $this; + } + + /** + * Action after save + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Api_Model_Resource_Roles + */ + protected function _afterSave(Mage_Core_Model_Abstract $role) + { + $this->_updateRoleUsersAcl($role); + Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG); + return $this; + } + + /** + * Action after delete + * + * @param Mage_Core_Model_Abstract $role + * @return Mage_Api_Model_Resource_Roles + */ + protected function _afterDelete(Mage_Core_Model_Abstract $role) + { + $adapter = $this->_getWriteAdapter(); + $adapter->delete($this->getMainTable(), array('parent_id=?'=>$role->getId())); + $adapter->delete($this->_ruleTable, array('role_id=?'=>$role->getId())); + return $this; + } + + /** + * Get role users + * + * @param Mage_Api_Model_Roles $role + * @return unknown + */ + public function getRoleUsers(Mage_Api_Model_Roles $role) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('user_id')) + ->where('parent_id = ?', $role->getId()) + ->where('role_type = ?', Mage_Api_Model_Acl::ROLE_TYPE_USER) + ->where('user_id > 0'); + return $adapter->fetchCol($select); + } + + /** + * Update role users + * + * @param Mage_Api_Model_Roles $role + * @return boolean + */ + private function _updateRoleUsersAcl(Mage_Api_Model_Roles $role) + { + $users = $this->getRoleUsers($role); + $rowsCount = 0; + if (sizeof($users) > 0) { + $rowsCount = $this->_getWriteAdapter()->update( + $this->_usersTable, + array('reload_acl_flag' => 1), + array('user_id IN(?)' => $users)); + } + return ($rowsCount > 0) ? true : false; + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Roles/Collection.php b/app/code/core/Mage/Api/Model/Resource/Roles/Collection.php new file mode 100755 index 0000000000..19b7079af3 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Roles/Collection.php @@ -0,0 +1,67 @@ + + */ +class Mage_Api_Model_Resource_Roles_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/role'); + } + + /** + * Init collection select + * + * @return Mage_Api_Model_Resource_Roles_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->getSelect()->where('main_table.role_type = ?', Mage_Api_Model_Acl::ROLE_TYPE_GROUP); + return $this; + } + + /** + * Convert items array to array for select options + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('role_id', 'role_name'); + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Roles/User/Collection.php b/app/code/core/Mage/Api/Model/Resource/Roles/User/Collection.php new file mode 100755 index 0000000000..5097f691f4 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Roles/User/Collection.php @@ -0,0 +1,59 @@ + + */ +class Mage_Api_Model_Resource_Roles_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/user'); + } + + /** + * Init collection select + * + * @return Mage_Api_Model_Resource_Roles_User_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + + $this->getSelect()->where("user_id > 0"); + + return $this; + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Rules.php b/app/code/core/Mage/Api/Model/Resource/Rules.php new file mode 100755 index 0000000000..8a5047ae5a --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Rules.php @@ -0,0 +1,87 @@ + + */ +class Mage_Api_Model_Resource_Rules extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('api/rule', 'rule_id'); + } + + /** + * Save rule + * + * @param Mage_Api_Model_Rules $rule + */ + public function saveRel(Mage_Api_Model_Rules $rule) + { + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + $roleId = $rule->getRoleId(); + $adapter->delete($this->getMainTable(), array('role_id = ?' => $roleId)); + $masterResources = Mage::getModel('api/roles')->getResourcesList2D(); + $masterAdmin = false; + if ($postedResources = $rule->getResources()) { + foreach ($masterResources as $index => $resName) { + if (!$masterAdmin) { + $permission = (in_array($resName, $postedResources))? 'allow' : 'deny'; + $adapter->insert($this->getMainTable(), array( + 'role_type' => 'G', + 'resource_id' => trim($resName, '/'), + 'api_privileges' => null, + 'assert_id' => 0, + 'role_id' => $roleId, + 'api_permission' => $permission + )); + } + if ($resName == 'all' && $permission == 'allow') { + $masterAdmin = true; + } + } + } + + $adapter->commit(); + } catch (Mage_Core_Exception $e) { + throw $e; + } catch (Exception $e) { + $adapter->rollBack(); + } + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/Rules/Collection.php b/app/code/core/Mage/Api/Model/Resource/Rules/Collection.php new file mode 100755 index 0000000000..311c947c35 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/Rules/Collection.php @@ -0,0 +1,69 @@ + + */ +class Mage_Api_Model_Resource_Rules_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/rules'); + } + + /** + * Retrieve rules by role + * + * @param int $id + * @return Mage_Api_Model_Resource_Rules_Collection + */ + public function getByRoles($id) + { + $this->getSelect()->where("role_id = ?", (int)$id); + return $this; + } + + /** + * Add sort by length + * + * @return Mage_Api_Model_Resource_Rules_Collection + */ + public function addSortByLength() + { + $this->getSelect()->columns(array('length' => $this->getConnection()->getLengthSql('resource_id'))) + ->order('length DESC'); + return $this; + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/User.php b/app/code/core/Mage/Api/Model/Resource/User.php new file mode 100755 index 0000000000..51c41346db --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/User.php @@ -0,0 +1,435 @@ + + */ +class Mage_Api_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('api/user', 'user_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Api_Model_Resource_User + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array( + array( + 'field' => 'email', + 'title' => Mage::helper('api')->__('Email') + ), + array( + 'field' => 'username', + 'title' => Mage::helper('api')->__('User Name') + ), + ); + return $this; + } + + /** + * Authenticate user by $username and $password + * + * @param Mage_Api_Model_User $user + * @return Mage_Api_Model_Resource_User + */ + public function recordLogin(Mage_Api_Model_User $user) + { + $data = array( + 'lognum' => $user->getLognum()+1, + ); + $condition = $this->_getReadAdapter()->quoteInto('user_id=?', $user->getUserId()); + $this->_getWriteAdapter()->update($this->getTable('api/user'), $data, $condition); + return $this; + } + + /** + * Record api user session + * + * @param Mage_Api_Model_User $user + * @return Mage_Api_Model_Resource_User + */ + public function recordSession(Mage_Api_Model_User $user) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + $select = $readAdapter->select() + ->from($this->getTable('api/session'), 'user_id') + ->where('user_id = ?', $user->getId()) + ->where('sessid = ?', $user->getSessid()); + $loginDate = now(); + if ($readAdapter->fetchRow($select)) { + $writeAdapter->update( + $this->getTable('api/session'), + array ('logdate' => $loginDate), + $readAdapter->quoteInto('user_id = ?', $user->getId()) . ' AND ' + . $readAdapter->quoteInto('sessid = ?', $user->getSessid()) + ); + } else { + $writeAdapter->insert( + $this->getTable('api/session'), + array( + 'user_id' => $user->getId(), + 'logdate' => $loginDate, + 'sessid' => $user->getSessid() + ) + ); + } + $user->setLogdate($loginDate); + return $this; + } + + /** + * Clean old session + * + * @param Mage_Api_Model_User $user + * @return Mage_Api_Model_Resource_User + */ + public function cleanOldSessions(Mage_Api_Model_User $user) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + $timeout = Mage::getStoreConfig('api/config/session_timeout'); + $timeSubtract = $readAdapter->getDateAddSql( + 'logdate', + $timeout, + Varien_Db_Adapter_Interface::INTERVAL_SECOND); + $writeAdapter->delete( + $this->getTable('api/session'), + array('user_id = ?' => $user->getId(), $readAdapter->quote(now()) . ' > '.$timeSubtract) + ); + return $this; + } + + /** + * Load data by username + * + * @param string $username + * @return array + */ + public function loadByUsername($username) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select()->from($this->getTable('api/user')) + ->where('username=:username'); + return $adapter->fetchRow($select, array('username'=>$username)); + } + + /** + * load by session id + * + * @param string $sessId + * @return array + */ + public function loadBySessId($sessId) + { + $result = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('api/session')) + ->where('sessid = ?', $sessId); + if ($apiSession = $adapter->fetchRow($select)) { + $selectUser = $adapter->select() + ->from($this->getTable('api/user')) + ->where('user_id = ?', $apiSession['user_id']); + if ($user = $adapter->fetchRow($selectUser)) { + $result = array_merge($user, $apiSession); + } + } + return $result; + } + + /** + * Clear by session + * + * @param string $sessid + * @return Mage_Api_Model_Resource_User + */ + public function clearBySessId($sessid) + { + $this->_getWriteAdapter()->delete( + $this->getTable('api/session'), + array('sessid = ?' => $sessid) + ); + return $this; + } + + /** + * Retrieve api user role data if it was assigned to role + * + * @param int | Mage_Api_Model_User $user + * @return null | array + */ + public function hasAssigned2Role($user) + { + $userId = null; + $result = null; + if (is_numeric($user)) { + $userId = $user; + } else if ($user instanceof Mage_Core_Model_Abstract) { + $userId = $user->getUserId(); + } + + if ($userId) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select(); + $select->from($this->getTable('api/role')) + ->where('parent_id > 0 AND user_id = ?', $userId); + $result = $adapter->fetchAll($select); + } + return $result; + } + + /** + * Action before save + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Api_Model_Resource_User + */ + protected function _beforeSave(Mage_Core_Model_Abstract $user) + { + if (!$user->getId()) { + $user->setCreated(now()); + } + $user->setModified(now()); + return $this; + } + + /** + * Delete the object + * + * @param Mage_Core_Model_Abstract $user + * @return boolean + */ + public function delete(Mage_Core_Model_Abstract $user) + { + $dbh = $this->_getWriteAdapter(); + $uid = (int) $user->getId(); + $dbh->beginTransaction(); + try { + $dbh->delete($this->getTable('api/user'), array('user_id = ?' => $uid)); + $dbh->delete($this->getTable('api/role'), array('user_id = ?' => $uid)); + } catch (Mage_Core_Exception $e) { + throw $e; + return false; + } catch (Exception $e) { + $dbh->rollBack(); + return false; + } + $dbh->commit(); + return true; + } + + /** + * Save user roles + * + * @param Mage_Core_Model_Abstract $user + * @return unknown + */ + public function _saveRelations(Mage_Core_Model_Abstract $user) + { + $rolesIds = $user->getRoleIds(); + if (!is_array($rolesIds) || count($rolesIds) == 0) { + return $user; + } + + $adapter = $this->_getWriteAdapter(); + + $adapter->beginTransaction(); + + try { + $adapter->delete( + $this->getTable('api/role'), + array('user_id = ?' => (int) $user->getId())); + foreach ($rolesIds as $rid) { + $rid = intval($rid); + if ($rid > 0) { + //$row = $this->load($user, $rid); + } else { + $row = array('tree_level' => 0); + } + $row = array('tree_level' => 0); + + $data = array( + 'parent_id' => $rid, + 'tree_level' => $row['tree_level'] + 1, + 'sort_order' => 0, + 'role_type' => Mage_Api_Model_Acl::ROLE_TYPE_USER, + 'user_id' => $user->getId(), + 'role_name' => $user->getFirstname() + ); + $adapter->insert($this->getTable('api/role'), $data); + } + $adapter->commit(); + } catch (Mage_Core_Exception $e) { + throw $e; + } catch (Exception $e) { + $adapter->rollBack(); + } + return $this; + } + + /** + * Retrieve roles data + * + * @param Mage_Core_Model_Abstract $user + * @return array + */ + public function _getRoles(Mage_Core_Model_Abstract $user) + { + if (!$user->getId()) { + return array(); + } + $table = $this->getTable('api/role'); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($table, array()) + ->joinLeft( + array('ar' => $table), + $adapter->quoteInto( + "ar.role_id = {$table}.parent_id AND ar.role_type = ?", + Mage_Api_Model_Acl::ROLE_TYPE_GROUP), + array('role_id')) + ->where("{$table}.user_id = ?", $user->getId()); + + return (($roles = $adapter->fetchCol($select)) ? $roles : array()); + } + + /** + * Add Role + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Api_Model_Resource_User + */ + public function add(Mage_Core_Model_Abstract $user) + { + $adapter = $this->_getWriteAdapter(); + $aRoles = $this->hasAssigned2Role($user); + if (sizeof($aRoles) > 0) { + foreach ($aRoles as $idx => $data) { + $adapter->delete( + $this->getTable('api/role'), + array('role_id = ?' => $data['role_id']) + ); + } + } + + if ($user->getId() > 0) { + $role = Mage::getModel('api/role')->load($user->getRoleId()); + } else { + $role = new Varien_Object(array('tree_level' => 0)); + } + $adapter->insert($this->getTable('api/role'), array( + 'parent_id' => $user->getRoleId(), + 'tree_level'=> ($role->getTreeLevel() + 1), + 'sort_order'=> 0, + 'role_type' => Mage_Api_Model_Acl::ROLE_TYPE_USER, + 'user_id' => $user->getUserId(), + 'role_name' => $user->getFirstname() + )); + + return $this; + } + + /** + * Delete from role + * + * @param Mage_Core_Model_Abstract $user + * @return Mage_Api_Model_Resource_User + */ + public function deleteFromRole(Mage_Core_Model_Abstract $user) + { + if ($user->getUserId() <= 0) { + return $this; + } + if ($user->getRoleId() <= 0) { + return $this; + }; + + $adapter = $this->_getWriteAdapter(); + $table = $this->getTable('api/role'); + + $condition = array( + "{$table}.user_id = ?" => $user->getUserId(), + "{$table}.parent_id = ?"=> $user->getRoleId() + ); + $adapter->delete($table, $condition); + return $this; + } + + /** + * Retrieve roles which exists for user + * + * @param Mage_Core_Model_Abstract $user + * @return array + */ + public function roleUserExists(Mage_Core_Model_Abstract $user) + { + $result = array(); + if ($user->getUserId() > 0) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select()->from($this->getTable('api/role')) + ->where('parent_id = ?', $user->getRoleId()) + ->where('user_id = ?', $user->getUserId()); + $result = $adapter->fetchCol($select); + } + return $result; + } + + /** + * Check if user not unique + * + * @param Mage_Core_Model_Abstract $user + * @return array + */ + public function userExists(Mage_Core_Model_Abstract $user) + { + $usersTable = $this->getTable('api/user'); + $adapter = $this->_getReadAdapter(); + $condition = array( + $adapter->quoteInto("{$usersTable}.username = ?", $user->getUsername()), + $adapter->quoteInto("{$usersTable}.email = ?", $user->getEmail()), + ); + $select = $adapter->select() + ->from($usersTable) + ->where(implode(' OR ', $condition)) + ->where($usersTable.'.user_id != ?', (int) $user->getId()); + return $adapter->fetchRow($select); + } +} diff --git a/app/code/core/Mage/Api/Model/Resource/User/Collection.php b/app/code/core/Mage/Api/Model/Resource/User/Collection.php new file mode 100755 index 0000000000..172cba76c2 --- /dev/null +++ b/app/code/core/Mage/Api/Model/Resource/User/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Api_Model_Resource_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('api/user'); + } +} diff --git a/app/code/core/Mage/Api/Model/Role.php b/app/code/core/Mage/Api/Model/Role.php index a1b8b4bd7d..86ad97c3e6 100644 --- a/app/code/core/Mage/Api/Model/Role.php +++ b/app/code/core/Mage/Api/Model/Role.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Api_Model_Resource_Role _getResource() + * @method Mage_Api_Model_Resource_Role getResource() + * @method int getParentId() + * @method Mage_Api_Model_Role setParentId(int $value) + * @method int getTreeLevel() + * @method Mage_Api_Model_Role setTreeLevel(int $value) + * @method int getSortOrder() + * @method Mage_Api_Model_Role setSortOrder(int $value) + * @method string getRoleType() + * @method Mage_Api_Model_Role setRoleType(string $value) + * @method int getUserId() + * @method Mage_Api_Model_Role setUserId(int $value) + * @method string getRoleName() + * @method Mage_Api_Model_Role setRoleName(string $value) + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ class Mage_Api_Model_Role extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Api/Model/Roles.php b/app/code/core/Mage/Api/Model/Roles.php index 4ce7adfa82..734eb9dca6 100644 --- a/app/code/core/Mage/Api/Model/Roles.php +++ b/app/code/core/Mage/Api/Model/Roles.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Api_Model_Resource_Roles _getResource() + * @method Mage_Api_Model_Resource_Roles getResource() + * @method int getParentId() + * @method Mage_Api_Model_Roles setParentId(int $value) + * @method int getTreeLevel() + * @method Mage_Api_Model_Roles setTreeLevel(int $value) + * @method int getSortOrder() + * @method Mage_Api_Model_Roles setSortOrder(int $value) + * @method string getRoleType() + * @method Mage_Api_Model_Roles setRoleType(string $value) + * @method int getUserId() + * @method Mage_Api_Model_Roles setUserId(int $value) + * @method string getRoleName() + * @method Mage_Api_Model_Roles setRoleName(string $value) + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Api/Model/Rules.php b/app/code/core/Mage/Api/Model/Rules.php index 79f8e1f1d8..8e24e21b67 100644 --- a/app/code/core/Mage/Api/Model/Rules.php +++ b/app/code/core/Mage/Api/Model/Rules.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Api_Model_Resource_Rules _getResource() + * @method Mage_Api_Model_Resource_Rules getResource() + * @method int getRoleId() + * @method Mage_Api_Model_Rules setRoleId(int $value) + * @method string getResourceId() + * @method Mage_Api_Model_Rules setResourceId(string $value) + * @method string getPrivileges() + * @method Mage_Api_Model_Rules setPrivileges(string $value) + * @method int getAssertId() + * @method Mage_Api_Model_Rules setAssertId(int $value) + * @method string getRoleType() + * @method Mage_Api_Model_Rules setRoleType(string $value) + * @method string getPermission() + * @method Mage_Api_Model_Rules setPermission(string $value) + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ class Mage_Api_Model_Rules extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Api/Model/Server.php b/app/code/core/Mage/Api/Model/Server.php index bbf8a9a7df..19e0c966d4 100644 --- a/app/code/core/Mage/Api/Model/Server.php +++ b/app/code/core/Mage/Api/Model/Server.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Interface.php b/app/code/core/Mage/Api/Model/Server/Adapter/Interface.php index 0bcf1d5177..f5ee1916e7 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Interface.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php index f16bdb756c..aca1f93179 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php b/app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php index 445e827198..e5dfdf8ebc 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Handler.php b/app/code/core/Mage/Api/Model/Server/Handler.php index 201018f230..29b42ef0cf 100644 --- a/app/code/core/Mage/Api/Model/Server/Handler.php +++ b/app/code/core/Mage/Api/Model/Server/Handler.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php index f6e76f8ccd..91a14ad616 100644 --- a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php +++ b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php index 59b5006cad..76525dea76 100644 --- a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/V2/Handler.php b/app/code/core/Mage/Api/Model/Server/V2/Handler.php index d392c1e698..37dd4da8e9 100644 --- a/app/code/core/Mage/Api/Model/Server/V2/Handler.php +++ b/app/code/core/Mage/Api/Model/Server/V2/Handler.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php index e4b2116f26..846342c6e5 100644 --- a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Server/Wsi/Handler.php b/app/code/core/Mage/Api/Model/Server/Wsi/Handler.php index 2ba34a93cf..4c4b560ed3 100644 --- a/app/code/core/Mage/Api/Model/Server/Wsi/Handler.php +++ b/app/code/core/Mage/Api/Model/Server/Wsi/Handler.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Session.php b/app/code/core/Mage/Api/Model/Session.php index f0673db29c..c65a00ec91 100644 --- a/app/code/core/Mage/Api/Model/Session.php +++ b/app/code/core/Mage/Api/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/User.php b/app/code/core/Mage/Api/Model/User.php index 885bdf05ef..bab0b0d3be 100644 --- a/app/code/core/Mage/Api/Model/User.php +++ b/app/code/core/Mage/Api/Model/User.php @@ -20,10 +20,40 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Api_Model_Resource_User _getResource() + * @method Mage_Api_Model_Resource_User getResource() + * @method string getFirstname() + * @method Mage_Api_Model_User setFirstname(string $value) + * @method string getLastname() + * @method Mage_Api_Model_User setLastname(string $value) + * @method string getEmail() + * @method Mage_Api_Model_User setEmail(string $value) + * @method string getUsername() + * @method Mage_Api_Model_User setUsername(string $value) + * @method string getApiKey() + * @method Mage_Api_Model_User setApiKey(string $value) + * @method string getCreated() + * @method Mage_Api_Model_User setCreated(string $value) + * @method string getModified() + * @method Mage_Api_Model_User setModified(string $value) + * @method int getLognum() + * @method Mage_Api_Model_User setLognum(int $value) + * @method int getReloadAclFlag() + * @method Mage_Api_Model_User setReloadAclFlag(int $value) + * @method int getIsActive() + * @method Mage_Api_Model_User setIsActive(int $value) + * + * @category Mage + * @package Mage_Api + * @author Magento Core Team + */ class Mage_Api_Model_User extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Api/Model/Wsdl/Config.php b/app/code/core/Mage/Api/Model/Wsdl/Config.php index 7d851573ea..b7921a624e 100644 --- a/app/code/core/Mage/Api/Model/Wsdl/Config.php +++ b/app/code/core/Mage/Api/Model/Wsdl/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Wsdl/Config/Base.php b/app/code/core/Mage/Api/Model/Wsdl/Config/Base.php index b4650ac993..a4dc792db2 100644 --- a/app/code/core/Mage/Api/Model/Wsdl/Config/Base.php +++ b/app/code/core/Mage/Api/Model/Wsdl/Config/Base.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/Model/Wsdl/Config/Element.php b/app/code/core/Mage/Api/Model/Wsdl/Config/Element.php index 0cb2aba095..77936b6dcb 100644 --- a/app/code/core/Mage/Api/Model/Wsdl/Config/Element.php +++ b/app/code/core/Mage/Api/Model/Wsdl/Config/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/controllers/IndexController.php b/app/code/core/Mage/Api/controllers/IndexController.php index 21f45a29e3..fb72455997 100644 --- a/app/code/core/Mage/Api/controllers/IndexController.php +++ b/app/code/core/Mage/Api/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/controllers/SoapController.php b/app/code/core/Mage/Api/controllers/SoapController.php index 74e43829cb..3674c65c25 100644 --- a/app/code/core/Mage/Api/controllers/SoapController.php +++ b/app/code/core/Mage/Api/controllers/SoapController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/controllers/V2/SoapController.php b/app/code/core/Mage/Api/controllers/V2/SoapController.php index 7d363270a2..f9516d7d13 100644 --- a/app/code/core/Mage/Api/controllers/V2/SoapController.php +++ b/app/code/core/Mage/Api/controllers/V2/SoapController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/controllers/XmlrpcController.php b/app/code/core/Mage/Api/controllers/XmlrpcController.php index fbc9668a5e..29a0edb8b4 100644 --- a/app/code/core/Mage/Api/controllers/XmlrpcController.php +++ b/app/code/core/Mage/Api/controllers/XmlrpcController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/etc/adminhtml.xml b/app/code/core/Mage/Api/etc/adminhtml.xml index 768f8ed0d3..937d456279 100644 --- a/app/code/core/Mage/Api/etc/adminhtml.xml +++ b/app/code/core/Mage/Api/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Api/etc/api.xml b/app/code/core/Mage/Api/etc/api.xml index 83a6b4d321..c1a87b83b2 100644 --- a/app/code/core/Mage/Api/etc/api.xml +++ b/app/code/core/Mage/Api/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Api/etc/config.xml b/app/code/core/Mage/Api/etc/config.xml index 63121dee3a..bd8f5dec55 100644 --- a/app/code/core/Mage/Api/etc/config.xml +++ b/app/code/core/Mage/Api/etc/config.xml @@ -21,20 +21,20 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.8.1 + 1.6.0.0 - + @@ -49,10 +49,11 @@ Mage_Api_Model - api_mysql4 + api_resource - - Mage_Api_Model_Mysql4 + + Mage_Api_Model_Resource + api_mysql4 api_assert
@@ -70,7 +71,7 @@ api_session
-
+
diff --git a/app/code/core/Mage/Api/etc/system.xml b/app/code/core/Mage/Api/etc/system.xml index 557fa44a53..74ce1d8a92 100644 --- a/app/code/core/Mage/Api/etc/system.xml +++ b/app/code/core/Mage/Api/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Api/sql/api_setup/install-1.6.0.0.php b/app/code/core/Mage/Api/sql/api_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..361b29a5ef --- /dev/null +++ b/app/code/core/Mage/Api/sql/api_setup/install-1.6.0.0.php @@ -0,0 +1,208 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); + +/** + * Create table 'api/assert' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('api/assert')) + ->addColumn('assert_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Assert id') + ->addColumn('assert_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Assert type') + ->addColumn('assert_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Assert additional data') + ->setComment('Api ACL Asserts'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'api/role' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('api/role')) + ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Role id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Parent role id') + ->addColumn('tree_level', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Role level in tree') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort order to display on admin area') + ->addColumn('role_type', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + 'nullable' => false, + 'default' => '0', + ), 'Role type') + ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'User id') + ->addColumn('role_name', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Role name') + ->addIndex($installer->getIdxName('api/role', array('parent_id', 'sort_order')), + array('parent_id', 'sort_order')) + ->addIndex($installer->getIdxName('api/role', array('tree_level')), + array('tree_level')) + ->setComment('Api ACL Roles'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'api/rule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('api/rule')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Api rule Id') + ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Api role Id') + ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Module code') + ->addColumn('api_privileges', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Privileges') + ->addColumn('assert_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Assert id') + ->addColumn('role_type', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + ), 'Role type') + ->addColumn('api_permission', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array( + ), 'Permission') + ->addIndex($installer->getIdxName('api/rule', array('resource_id', 'role_id')), + array('resource_id', 'role_id')) + ->addIndex($installer->getIdxName('api/rule', array('role_id', 'resource_id')), + array('role_id', 'resource_id')) + ->addForeignKey($installer->getFkName('api/rule', 'role_id', 'api/role', 'role_id'), + 'role_id', $installer->getTable('api/role'), 'role_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Api ACL Rules'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'api/user' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('api/user')) + ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'User id') + ->addColumn('firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'First name') + ->addColumn('lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Last name') + ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array( + ), 'Email') + ->addColumn('username', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Nickname') + ->addColumn('api_key', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Api key') + ->addColumn('created', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'User record create date') + ->addColumn('modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'User record modify date') + ->addColumn('lognum', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quantity of log ins') + ->addColumn('reload_acl_flag', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Refresh ACL flag') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Account status') + ->setComment('Api Users'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'api/session' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('api/session')) + ->addColumn('user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'User id') + ->addColumn('logdate', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Login date') + ->addColumn('sessid', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Sessioin id') + ->addIndex($installer->getIdxName('api/session', array('user_id')), + array('user_id')) + ->addIndex($installer->getIdxName('api/session', array('sessid')), + array('sessid')) + ->addForeignKey($installer->getFkName('api/session', 'user_id', 'api/user', 'user_id'), + 'user_id', $installer->getTable('api/user'), 'user_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Api Sessions'); +$installer->getConnection()->createTable($table); + + + +$installer->endSetup(); diff --git a/app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php index ced3b85fcd..ac5ce1694d 100644 --- a/app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/sql/api_setup/mysql4-modify-columns.php b/app/code/core/Mage/Api/sql/api_setup/mysql4-modify-columns.php new file mode 100644 index 0000000000..88a3b15b6e --- /dev/null +++ b/app/code/core/Mage/Api/sql/api_setup/mysql4-modify-columns.php @@ -0,0 +1,232 @@ + +$tables = array( + + 'api_assert' => array( + 'columns' => array( + + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Assert id' + ), + 'assert_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Assert type' + ), + 'assert_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Assert additional data' + ) + ), + 'comment' => 'Api ACL Asserts' + ), + + 'api_role' => array( + 'columns' => array( + + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Role id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent role id' + ), + 'tree_level' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role level in tree' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort order to display on admin area' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role type' + ), + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User id' + ), + 'role_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Role name' + ) + ), + 'comment' => 'Api ACL Roles' + ), + + 'api_rule' => array( + 'columns' => array( + + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Api rule Id' + ), + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Api role Id' + ), + 'resource_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Module code' + ), + 'api_privileges' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Privileges' + ), + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Assert id' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'comment' => 'Role type' + ), + 'api_permission' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 10, + 'comment' => 'Permission' + ) + ), + 'comment' => 'Api ACL Rules' + ), + + 'api_user' => array( + 'columns' => array( + + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'User id' + ), + 'firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'First name' + ), + 'lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Last name' + ), + 'email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'comment' => 'Email' + ), + 'username' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Nickname' + ), + 'api_key' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'comment' => 'Api key' + ), + 'created' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'default' => 'CURRENT_TIMESTAMP', + 'comment' => 'User record create date' + ), + 'modified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, +, + 'comment' => 'User record modify date' + ), + 'lognum' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Quantity of log ins' + ), + 'reload_acl_flag' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Refresh ACL flag' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Account status' + ) + ), + 'comment' => 'Api Users' + ), + + 'api_session' => array( + 'columns' => array( + + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User id' + ), + 'logdate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'default' => 'CURRENT_TIMESTAMP', + 'comment' => 'Login date' + ), + 'sessid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Sessioin id' + ) + ), + 'comment' => 'Api Sessions' + ) +); + +foreach ($tables as $table => $tableData) { + foreach ($tableData['columns'] as $column =>$columnDefinition) { + $installer->getConnection()->modifyColumn($installer->getTable($table), $column, $columnDefinition); + } + $installer->getConnection()->changeTableComment($installer->getTable($table), $tableData['comment']); +} diff --git a/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php index 978bf2bcfb..156f9ee277 100644 --- a/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php index 0d92d18acc..dc6fbf5183 100644 --- a/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php +++ b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..993eb145eb --- /dev/null +++ b/app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,375 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('api/rule'), + 'FK_API_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('api/session'), + 'FK_API_SESSION_USER' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('api/role'), + 'PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('api/role'), + 'TREE_LEVEL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('api/rule'), + 'RESOURCE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('api/rule'), + 'ROLE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('api/session'), + 'API_SESSION_USER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('api/session'), + 'API_SESSION_SESSID' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('api/assert') => array( + 'columns' => array( + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Assert id' + ), + 'assert_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Assert type' + ), + 'assert_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Assert additional data' + ) + ), + 'comment' => 'Api ACL Asserts' + ), + $installer->getTable('api/role') => array( + 'columns' => array( + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Role id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent role id' + ), + 'tree_level' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role level in tree' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort order to display on admin area' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Role type' + ), + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User id' + ), + 'role_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Role name' + ) + ), + 'comment' => 'Api ACL Roles' + ), + $installer->getTable('api/rule') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Api rule Id' + ), + 'role_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Api role Id' + ), + 'resource_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Module code' + ), + 'assert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Assert id' + ), + 'role_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'comment' => 'Role type' + ) + ), + 'comment' => 'Api ACL Rules' + ), + $installer->getTable('api/user') => array( + 'columns' => array( + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'User id' + ), + 'firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'First name' + ), + 'lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Last name' + ), + 'email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'comment' => 'Email' + ), + 'username' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Nickname' + ), + 'api_key' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Api key' + ), + 'created' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'User record create date' + ), + 'modified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'User record modify date' + ), + 'lognum' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Quantity of log ins' + ), + 'reload_acl_flag' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Refresh ACL flag' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Account status' + ) + ), + 'comment' => 'Api Users' + ), + $installer->getTable('api/session') => array( + 'columns' => array( + 'user_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'User id' + ), + 'logdate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Login date' + ), + 'sessid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Sessioin id' + ) + ), + 'comment' => 'Api Sessions' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('api/rule'), + 'privileges', + 'api_privileges', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Privileges' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('api/rule'), + 'permission', + 'api_permission', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 10, + 'comment' => 'Permission' + ) +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('api/rule'), + $installer->getIdxName('api/rule', array('resource_id', 'role_id')), + array('resource_id', 'role_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$installer->getConnection()->addIndex( + $installer->getTable('api/rule'), + $installer->getIdxName('api/rule', array('role_id', 'resource_id')), + array('role_id', 'resource_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$installer->getConnection()->addIndex( + $installer->getTable('api/session'), + $installer->getIdxName('api/session', array('user_id')), + array('user_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$installer->getConnection()->addIndex( + $installer->getTable('api/session'), + $installer->getIdxName('api/session', array('sessid')), + array('sessid'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$installer->getConnection()->addIndex( + $installer->getTable('api/role'), + $installer->getIdxName('api/role', array('parent_id', 'sort_order')), + array('parent_id', 'sort_order'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$installer->getConnection()->addIndex( + $installer->getTable('api/role'), + $installer->getIdxName('api/role', array('tree_level')), + array('tree_level'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('api/rule', 'role_id', 'api/role', 'role_id'), + $installer->getTable('api/rule'), + 'role_id', + $installer->getTable('api/role'), + 'role_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('api/session', 'user_id', 'api/user', 'user_id'), + $installer->getTable('api/session'), + 'user_id', + $installer->getTable('api/user'), + 'user_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Authorizenet/Block/Directpost/Form.php b/app/code/core/Mage/Authorizenet/Block/Directpost/Form.php index d792bd1815..0890f9dd96 100644 --- a/app/code/core/Mage/Authorizenet/Block/Directpost/Form.php +++ b/app/code/core/Mage/Authorizenet/Block/Directpost/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php b/app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php index bec9932e47..3457324bdb 100644 --- a/app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php +++ b/app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Block/Directpost/Info.php b/app/code/core/Mage/Authorizenet/Block/Directpost/Info.php deleted file mode 100644 index c2c518d1ba..0000000000 --- a/app/code/core/Mage/Authorizenet/Block/Directpost/Info.php +++ /dev/null @@ -1,87 +0,0 @@ - - */ -class Mage_Authorizenet_Block_Directpost_Info extends Mage_Payment_Block_Info -{ - const PAYMENT_METHOD_CODE = 'authorizenet_directpost'; - - /** - * Form block instance - * - * @var Mage_Authorizenet_Block_Directpost_Form - */ - protected $_formBlock; - - /** - * (non-PHPdoc) - * @see app/code/core/Mage/Core/Block/Mage_Core_Block_Template#_toHtml() - */ - protected function _toHtml() - { - if ($this->getForm()->getMethodCode() != self::PAYMENT_METHOD_CODE) { - return; - } - - return parent::_toHtml(); - } - - - /** - * Set payment info - * - * @return Mage_Authorizenet_Block_Directpost_Info - */ - public function setMethodInfo() - { - $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment(); - $this->setInfo($payment); - - return $this; - } - - /** - * Get form instance - * - * @return Mage_Authorizenet_Block_Directpost_Form - */ - public function getForm() - { - if (!$this->_formBlock) { - $this->_formBlock = Mage::getSingleton('core/layout') - ->createBlock($this->getMethod()->getFormBlockType()); - $this->_formBlock->setMethod($this->getMethod()); - } - - return $this->_formBlock; - } -} \ No newline at end of file diff --git a/app/code/core/Mage/Authorizenet/Helper/Data.php b/app/code/core/Mage/Authorizenet/Helper/Data.php index aacbb22165..ea24707acf 100755 --- a/app/code/core/Mage/Authorizenet/Helper/Data.php +++ b/app/code/core/Mage/Authorizenet/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost.php b/app/code/core/Mage/Authorizenet/Model/Directpost.php index b42c27896e..4594259026 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -168,10 +168,9 @@ public function void(Varien_Object $payment) if ($result->getTransactionId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getTransactionId()); } - $shouldCloseCaptureTransaction = !(bool)$payment->getOrder()->canCreditmemo(); $payment ->setIsTransactionClosed(1) - ->setShouldCloseParentTransaction($shouldCloseCaptureTransaction) + ->setShouldCloseParentTransaction(1) ->setTransactionAdditionalInfo($this->_realTransactionIdKey, $result->getTransactionId()); return $this; } diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php index 65f5eb7ef7..ed88cc1d49 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php index a836980496..2d66651dff 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Response.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Response.php index d9f707602b..4f47518cae 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Response.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Response.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Session.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Session.php index 266fcaa318..b7b9d53be1 100644 --- a/app/code/core/Mage/Authorizenet/Model/Directpost/Session.php +++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php index 41691e86b9..9397b2b356 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php index b4b9308922..99bdaf27ad 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Authorizenet/etc/config.xml b/app/code/core/Mage/Authorizenet/etc/config.xml index 7852eb2e4f..d2a7ff547d 100755 --- a/app/code/core/Mage/Authorizenet/etc/config.xml +++ b/app/code/core/Mage/Authorizenet/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.0.1 + 1.5.0.0 diff --git a/app/code/core/Mage/Authorizenet/etc/system.xml b/app/code/core/Mage/Authorizenet/etc/system.xml index d7439dfcbc..b160eead43 100755 --- a/app/code/core/Mage/Authorizenet/etc/system.xml +++ b/app/code/core/Mage/Authorizenet/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Backup/Exception.php b/app/code/core/Mage/Backup/Exception.php index eeb6c26257..8be06068a2 100644 --- a/app/code/core/Mage/Backup/Exception.php +++ b/app/code/core/Mage/Backup/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Backup/Helper/Data.php b/app/code/core/Mage/Backup/Helper/Data.php index 6d00629cb1..c9540e00e1 100644 --- a/app/code/core/Mage/Backup/Helper/Data.php +++ b/app/code/core/Mage/Backup/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Backup/Model/Backup.php b/app/code/core/Mage/Backup/Model/Backup.php index 0d2591e15a..a2c6664ab0 100644 --- a/app/code/core/Mage/Backup/Model/Backup.php +++ b/app/code/core/Mage/Backup/Model/Backup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Backup/Model/Db.php b/app/code/core/Mage/Backup/Model/Db.php index 606127153f..92818ae037 100644 --- a/app/code/core/Mage/Backup/Model/Db.php +++ b/app/code/core/Mage/Backup/Model/Db.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Backup/Model/Fs/Collection.php b/app/code/core/Mage/Backup/Model/Fs/Collection.php index a7bc76bd12..897a0ade97 100644 --- a/app/code/core/Mage/Backup/Model/Fs/Collection.php +++ b/app/code/core/Mage/Backup/Model/Fs/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Backup/Model/Mysql4/Db.php b/app/code/core/Mage/Backup/Model/Mysql4/Db.php index 14d762ad6f..f93c45100b 100644 --- a/app/code/core/Mage/Backup/Model/Mysql4/Db.php +++ b/app/code/core/Mage/Backup/Model/Mysql4/Db.php @@ -20,396 +20,18 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Database backup resource model * - * @category Mage - * @package Mage_Backup + * @category Mage + * @package Mage_Backup * @author Magento Core Team */ -class Mage_Backup_Model_Mysql4_Db +class Mage_Backup_Model_Mysql4_Db extends Mage_Backup_Model_Resource_Db { - /** - * Read connection - * - * @var Varien_Db_Adapter_Pdo_Mysql - */ - protected $_read; - - /** - * tables Foreign key data array - * [tbl_name] = array(create foreign key strings) - * - * @var array - */ - protected $_foreignKeys = array(); - - /** - * Initialize Backup DB resource model - * - */ - public function __construct() - { - $this->_read = Mage::getSingleton('core/resource')->getConnection('backup_read'); - } - - /** - * @deprecated after 1.4.0.0-alpha2 - */ - public function crear() - { - $this->clear(); - } - - /** - * Clear data - * - */ - public function clear() - { - $this->_foreignKeys = array(); - } - - /** - * Retrieve table list - * - * @return array - */ - public function getTables() - { - return $this->_read->listTables(); - } - - /** - * Retrieve SQL fragment for drop table - * - * @param string $tableName - * @return string - */ - public function getTableDropSql($tableName) - { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - return 'DROP TABLE IF EXISTS ' . $quotedTableName . ';'; - } - - /** - * Retrieve SQL fragment for create table - * - * @param string $tableName - * @param bool $withForeignKeys - * @return string - */ - public function getTableCreateSql($tableName, $withForeignKeys = false) - { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - $sql = 'SHOW CREATE TABLE ' . $quotedTableName; - $row = $this->_read->fetchRow($sql); - - if (!$row || !isset($row['Table']) || !isset($row['Create Table'])) { - return false; - } - - $regExp = '/,\s+CONSTRAINT `([^`]*)` FOREIGN KEY \(`([^`]*)`\) ' - . 'REFERENCES `([^`]*)` \(`([^`]*)`\)' - . '( ON DELETE (RESTRICT|CASCADE|SET NULL|NO ACTION))?' - . '( ON UPDATE (RESTRICT|CASCADE|SET NULL|NO ACTION))?/'; - $matches = array(); - preg_match_all($regExp, $row['Create Table'], $matches, PREG_SET_ORDER); - - foreach ($matches as $match) { - $this->_foreignKeys[$tableName][] = sprintf('ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s%s', - $this->_read->quoteIdentifier($match[1]), - $this->_read->quoteIdentifier($match[2]), - $this->_read->quoteIdentifier($match[3]), - $this->_read->quoteIdentifier($match[4]), - isset($match[5]) ? $match[5] : '', - isset($match[7]) ? $match[7] : '' - ); - } - - if ($withForeignKeys) { - return $row['Create Table'] . ';'; - } - else { - return preg_replace($regExp, '', $row['Create Table']) . ';'; - } - } - - /** - * Retrieve foreign keys for table(s) - * - * @param string|null $tableName - * @return string - */ - public function getTableForeignKeysSql($tableName = null) - { - if (is_null($tableName)) { - $sql = ''; - foreach ($this->_foreignKeys as $table => $foreignKeys) { - $sql .= sprintf("ALTER TABLE %s\n %s;\n", - $this->_read->quoteIdentifier($table), - join(",\n ", $foreignKeys) - ); - } - return $sql; - } - if (isset($this->_foreignKeys[$tableName]) && ($foreignKeys = $this->_foreignKeys[$tableName])) { - - } - return false; - } - - /** - * Retrieve table status - * - * @param string $tableName - * @return Varien_Object - */ - public function getTableStatus($tableName) - { - $sql = $this->_read->quoteInto('SHOW TABLE STATUS LIKE ?', $tableName); - $row = $this->_read->fetchRow($sql); - - if ($row) { - $statusObject = new Varien_Object(); - $statusObject->setIdFieldName('name'); - foreach ($row as $field => $value) { - $statusObject->setData(strtolower($field), $value); - } - - $cntRow = $this->_read->fetchRow( $this->_read->select()->from($tableName, 'COUNT(*) as rows')); - $statusObject->setRows($cntRow['rows']); - - return $statusObject; - } - - return false; - } - - /** - * Quote Table Row - * - * @param string $tableName - * @param array $row - * @return string - */ - protected function _quoteRow($tableName, array $row) - { - $describe = $this->_read->describeTable($tableName); - $rowData = array(); - foreach ($row as $k => $v) { - if (is_null($v)) { - $value = 'NULL'; - } - elseif (in_array(strtolower($describe[$k]['DATA_TYPE']), array('bigint','mediumint','smallint','tinyint'))) { - $value = $v; - } - else { - $value = $this->_read->quoteInto('?', $v); - } - $rowData[] = $value; - } - return '('.join(',', $rowData).')'; - } - - /** - * Retrive table partical data SQL insert - * - * @param string $tableName - * @param int $count - * @param int $offset - * @return string - */ - public function getTableDataSql($tableName, $count, $offset = 0) - { - $sql = null; - $quotedTableName = $this->_read->quoteIdentifier($tableName); - $select = $this->_read->select() - ->from($tableName) - ->limit($count, $offset); - $query = $this->_read->query($select); - - while ($row = $query->fetch()) { - if (is_null($sql)) { - $sql = 'INSERT INTO ' . $quotedTableName . ' VALUES '; - } - else { - $sql .= ','; - } - - $sql .= $this->_quoteRow($tableName, $row); - } - - if (!is_null($sql)) { - $sql .= ';' . "\n"; - } - - return $sql; - } - - /** - * Enter description here... - * - * @param unknown_type $tableName - * @param unknown_type $addDropIfExists - * @return unknown - */ - public function getTableCreateScript($tableName, $addDropIfExists=false) - { - $script = ''; - if ($this->_read) { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - - if ($addDropIfExists) { - $script .= 'DROP TABLE IF EXISTS ' . $quotedTableName .";\n"; - } - $sql = 'SHOW CREATE TABLE ' . $quotedTableName; - $data = $this->_read->fetchRow($sql); - $script.= isset($data['Create Table']) ? $data['Create Table'].";\n" : ''; - } - - return $script; - } - - /** - * Retrieve table header comment - * - * @return string - */ - public function getTableHeader($tableName) - { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - return "\n--\n" - . "-- Table structure for table {$quotedTableName}\n" - . "--\n\n"; - } - - public function getTableDataDump($tableName, $step=100) - { - $sql = ''; - if ($this->_read) { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - $colunms = $this->_read->fetchRow('SELECT * FROM '.$quotedTableName.' LIMIT 1'); - if ($colunms) { - $arrSql = array(); - - $colunms = array_keys($colunms); - $quote = $this->_read->getQuoteIdentifierSymbol(); - $sql = 'INSERT INTO ' . $quotedTableName . ' (' .$quote . implode($quote.', '.$quote,$colunms).$quote.')'; - $sql.= ' VALUES '; - - $startRow = 0; - $select = $this->_read->select(); - $select->from($tableName) - ->limit($step, $startRow); - while ($data = $this->_read->fetchAll($select)) { - $dataSql = array(); - foreach ($data as $row) { - $dataSql[] = $this->_read->quoteInto('(?)', $row); - } - $arrSql[] = $sql.implode(', ', $dataSql).';'; - $startRow += $step; - $select->limit($step, $startRow); - } - - $sql = implode("\n", $arrSql)."\n"; - } - - } - - return $sql; - } - - /** - * Returns SQL header data - */ - public function getHeader() - { - $dbConfig = $this->_read->getConfig(); - - $versionRow = $this->_read->fetchRow('SHOW VARIABLES LIKE \'version\''); - $hostName = !empty($dbConfig['unix_socket']) ? $dbConfig['unix_socket'] - : (!empty($dbConfig['host']) ? $dbConfig['host'] : 'localhost'); - - $header = "-- Magento DB backup\n" - . "--\n" - . "-- Host: {$hostName} Database: {$dbConfig['dbname']}\n" - . "-- ------------------------------------------------------\n" - . "-- Server version: {$versionRow['Value']}\n\n" - . "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n" - . "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n" - . "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n" - . "/*!40101 SET NAMES utf8 */;\n" - . "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n" - . "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n" - . "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n" - . "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n"; - - return $header; - } - - /** - * Returns SQL footer data - */ - public function getFooter() - { - $footer = "\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n" - . "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; \n" - . "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n" - . "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n" - . "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" - . "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n" - . "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n" - . "\n-- Dump completed on " . Mage::getSingleton('core/date')->gmtDate() . " GMT"; - - return $footer; - } - - /** - * Retrieve before insert data SQL fragment - * - * @param string $tableName - * @return string - */ - public function getTableDataBeforeSql($tableName) - { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - return "\n--\n" - . "-- Dumping data for table {$quotedTableName}\n" - . "--\n\n" - . "LOCK TABLES {$quotedTableName} WRITE;\n" - . "/*!40000 ALTER TABLE {$quotedTableName} DISABLE KEYS */;\n"; - } - - /** - * Retrieve after insert data SQL fragment - * - * @param string $tableName - * @return string - */ - public function getTableDataAfterSql($tableName) - { - $quotedTableName = $this->_read->quoteIdentifier($tableName); - return "/*!40000 ALTER TABLE {$quotedTableName} ENABLE KEYS */;\n" - . "UNLOCK TABLES;\n"; - } - - public function beginTransaction() - { - $this->_read->beginTransaction(); - } - - public function commitTransaction() - { - $this->_read->commit(); - } - - public function rollBackTransaction() - { - $this->_read->rollBack(); - } } diff --git a/app/code/core/Mage/Backup/Model/Resource/Db.php b/app/code/core/Mage/Backup/Model/Resource/Db.php new file mode 100755 index 0000000000..885107c7e0 --- /dev/null +++ b/app/code/core/Mage/Backup/Model/Resource/Db.php @@ -0,0 +1,303 @@ + + */ +class Mage_Backup_Model_Resource_Db +{ + /** + * Read connection + * + * @var Varien_Db_Adapter_Pdo_Mysql + */ + protected $_read; + + /** + * tables Foreign key data array + * [tbl_name] = array(create foreign key strings) + * + * @var array + */ + protected $_foreignKeys = array(); + + /** + * Initialize Backup DB resource model + * + */ + public function __construct() + { + $this->_read = Mage::getSingleton('core/resource')->getConnection('backup_read'); + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.0.0-alpha2 + * + */ + public function crear() + { + $this->clear(); + } + + /** + * Clear data + * + */ + public function clear() + { + $this->_foreignKeys = array(); + } + + /** + * Retrieve table list + * + * @return array + */ + public function getTables() + { + return $this->_read->listTables(); + } + + /** + * Retrieve SQL fragment for drop table + * + * @param string $tableName + * @return string + */ + public function getTableDropSql($tableName) + { + return Mage::getResourceHelper('backup')->getTableDropSql($tableName); + } + + /** + * Retrieve SQL fragment for create table + * + * @param string $tableName + * @param bool $withForeignKeys + * @return string + */ + public function getTableCreateSql($tableName, $withForeignKeys = false) + { + return Mage::getResourceHelper('backup')->getTableCreateSql($tableName, $withForeignKeys = false); + } + + /** + * Retrieve foreign keys for table(s) + * + * @param string|null $tableName + * @return string + */ + public function getTableForeignKeysSql($tableName = null) + { + $fkScript = ''; + if (!$tableName) { + $tables = $this->getTables(); + foreach($tables as $table) { + $fkScript = $fkScript . Mage::getResourceHelper('backup')->getTableForeignKeysSql($table); + } + } else { + $fkScript = $this->getTableForeignKeysSql($tableName); + } + return $fkScript; + } + + /** + * Retrieve table status + * + * @param string $tableName + * @return Varien_Object + */ + public function getTableStatus($tableName) + { + $row = $this->_read->showTableStatus($tableName); + + if ($row) { + $statusObject = new Varien_Object(); + $statusObject->setIdFieldName('name'); + foreach ($row as $field => $value) { + $statusObject->setData(strtolower($field), $value); + } + + $cntRow = $this->_read->fetchRow( + $this->_read->select()->from($tableName, 'COUNT(1) as rows')); + $statusObject->setRows($cntRow['rows']); + + return $statusObject; + } + + return false; + } + + /** + * Quote Table Row + * + * @deprecated + * + * @param string $tableName + * @param array $row + * @return string + */ + protected function _quoteRow($tableName, array $row) + { + return $row; + } + + /** + * Retrive table partical data SQL insert + * + * @param string $tableName + * @param int $count + * @param int $offset + * @return string + */ + public function getTableDataSql($tableName, $count = null, $offset = null) + { + return Mage::getResourceHelper('backup')->getInsertSql($tableName); + + } + + /** + * Enter description here... + * + * @param unknown_type $tableName + * @param unknown_type $addDropIfExists + * @return unknown + */ + public function getTableCreateScript($tableName, $addDropIfExists = false) + { + return Mage::getResourceHelper('backup')->getTableCreateScript($tableName, $addDropIfExists);; + } + + /** + * Retrieve table header comment + * + * @param unknown_type $tableName + * @return string + */ + public function getTableHeader($tableName) + { + $quotedTableName = $this->_read->quoteIdentifier($tableName); + return "\n--\n" + . "-- Table structure for table {$quotedTableName}\n" + . "--\n\n"; + } + + /** + * Return table data dump + * + * @param string $tableName + * @param bool $step + * @return string + */ + public function getTableDataDump($tableName, $step = false) + { + return $this->getTableDataSql($tableName); + } + + /** + * Returns SQL header data + * + * @return string + */ + public function getHeader() + { + return Mage::getResourceHelper('backup')->getHeader(); + } + + /** + * Returns SQL footer data + * + * @return string + */ + public function getFooter() + { + return Mage::getResourceHelper('backup')->getFooter(); + } + + /** + * Retrieve before insert data SQL fragment + * + * @param string $tableName + * @return string + */ + public function getTableDataBeforeSql($tableName) + { + return Mage::getResourceHelper('backup')->getTableDataBeforeSql($tableName); + } + + /** + * Retrieve after insert data SQL fragment + * + * @param string $tableName + * @return string + */ + public function getTableDataAfterSql($tableName) + { + return Mage::getResourceHelper('backup')->getTableDataAfterSql($tableName); + } + + /** + * Start transaction mode + * + * @return Mage_Backup_Model_Resource_Db + */ + public function beginTransaction() + { + Mage::getResourceHelper('backup')->turnOnSerializableMode(); + $this->_read->beginTransaction(); + return $this; + } + + /** + * Commit transaction + * + * @return Mage_Backup_Model_Resource_Db + */ + public function commitTransaction() + { + $this->_read->commit(); + Mage::getResourceHelper('backup')->turnOnReadCommittedMode(); + return $this; + } + + /** + * Rollback transaction + * + * @return Mage_Backup_Model_Resource_Db + */ + public function rollBackTransaction() + { + $this->_read->rollBack(); + return $this; + } +} diff --git a/app/code/core/Mage/Backup/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Backup/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..bcb54f9e87 --- /dev/null +++ b/app/code/core/Mage/Backup/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,289 @@ +_getReadAdapter()->quoteIdentifier($tableName); + return sprintf('DROP TABLE IF EXISTS %s;', $quotedTableName); + } + + /** + * Retrieve foreign keys for table(s) + * + * @param string|null $tableName + * @return string|false + */ + public function getTableForeignKeysSql($tableName = null) + { + if ($tableName === null) { + $sql = ''; + foreach ($this->_foreignKeys as $table => $foreignKeys) { + $sql .= sprintf("ALTER TABLE %s\n %s;\n", + $this->_getReadAdapter()->quoteIdentifier($table), + join(",\n ", $foreignKeys) + ); + } + return $sql; + } + + return false; + } + /** + * Get create script for table + * + * @param string $tableName + * @param boolean $addDropIfExists + * @return string + */ + public function getTableCreateScript($tableName, $addDropIfExists = false) + { + $script = ''; + $quotedTableName = $this->_getReadAdapter()->quoteIdentifier($tableName); + + if ($addDropIfExists) { + $script .= 'DROP TABLE IF EXISTS ' . $quotedTableName .";\n"; + } + //TODO fix me + $sql = 'SHOW CREATE TABLE ' . $quotedTableName; + $data = $this->_getReadAdapter()->fetchRow($sql); + $script .= isset($data['Create Table']) ? $data['Create Table'].";\n" : ''; + + return $script; + } + /** + * Retrieve SQL fragment for create table + * + * @param string $tableName + * @param bool $withForeignKeys + * @return string + */ + public function getTableCreateSql($tableName, $withForeignKeys = false) + { + $adapter = $this->_getReadAdapter(); + $quotedTableName = $adapter->quoteIdentifier($tableName); + $query = 'SHOW CREATE TABLE ' . $quotedTableName; + $row = $adapter->fetchRow($query); + + if (!$row || !isset($row['Table']) || !isset($row['Create Table'])) { + return false; + } + + $regExp = '/,\s+CONSTRAINT `([^`]*)` FOREIGN KEY \(`([^`]*)`\) ' + . 'REFERENCES `([^`]*)` \(`([^`]*)`\)' + . '( ON DELETE (RESTRICT|CASCADE|SET NULL|NO ACTION))?' + . '( ON UPDATE (RESTRICT|CASCADE|SET NULL|NO ACTION))?/'; + $matches = array(); + preg_match_all($regExp, $row['Create Table'], $matches, PREG_SET_ORDER); + + if (is_array($matches)) { + foreach ($matches as $match) { + $this->_foreignKeys[$tableName][] = sprintf('ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s%s', + $adapter->quoteIdentifier($match[1]), + $adapter->quoteIdentifier($match[2]), + $adapter->quoteIdentifier($match[3]), + $adapter->quoteIdentifier($match[4]), + isset($match[5]) ? $match[5] : '', + isset($match[7]) ? $match[7] : '' + ); + } + } + + if ($withForeignKeys) { + $sql = $row['Create Table']; + } else { + $sql = preg_replace($regExp, '', $row['Create Table']); + } + + return $sql . ';'; + } + /** + * Returns SQL header data, move from original resource model + * + * @return string + */ + public function getHeader() + { + $dbConfig = $this->_getReadAdapter()->getConfig(); + + $versionRow = $this->_getReadAdapter()->fetchRow('SHOW VARIABLES LIKE \'version\''); + $hostName = !empty($dbConfig['unix_socket']) ? $dbConfig['unix_socket'] + : (!empty($dbConfig['host']) ? $dbConfig['host'] : 'localhost'); + + $header = "-- Magento DB backup\n" + . "--\n" + . "-- Host: {$hostName} Database: {$dbConfig['dbname']}\n" + . "-- ------------------------------------------------------\n" + . "-- Server version: {$versionRow['Value']}\n\n" + . "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n" + . "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n" + . "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n" + . "/*!40101 SET NAMES utf8 */;\n" + . "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n" + . "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n" + . "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n" + . "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n"; + + return $header; + } + + /** + * Returns SQL footer data, move from original resource model + * + * @return string + */ + public function getFooter() + { + $footer = "\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n" + . "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; \n" + . "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n" + . "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n" + . "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" + . "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n" + . "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n" + . "\n-- Dump completed on " . Mage::getSingleton('core/date')->gmtDate() . " GMT"; + + return $footer; + } + + /** + * Retrieve before insert data SQL fragment + * + * @param string $tableName + * @return string + */ + public function getTableDataBeforeSql($tableName) + { + $quotedTableName = $this->_getReadAdapter()->quoteIdentifier($tableName); + return "\n--\n" + . "-- Dumping data for table {$quotedTableName}\n" + . "--\n\n" + . "LOCK TABLES {$quotedTableName} WRITE;\n" + . "/*!40000 ALTER TABLE {$quotedTableName} DISABLE KEYS */;\n"; + } + + /** + * Retrieve after insert data SQL fragment + * + * @param string $tableName + * @return string + */ + public function getTableDataAfterSql($tableName) + { + $quotedTableName = $this->_getReadAdapter()->quoteIdentifier($tableName); + return "/*!40000 ALTER TABLE {$quotedTableName} ENABLE KEYS */;\n" + . "UNLOCK TABLES;\n"; + } + + /** + * Return table part data SQL insert + * + * @param string $tableName + * @return string + */ + public function getInsertSql($tableName) + { + $sql = null; + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($tableName); + $query = $adapter->query($select); + + while ($row = $query->fetch()) { + if ($sql === null) { + $sql = sprintf('INSERT INTO %s VALUES ', $adapter->quoteIdentifier($tableName)); + } else { + $sql .= ','; + } + + $sql .= $this->_quoteRow($tableName, $row); + } + + if ($sql !== null) { + $sql .= ';' . "\n"; + } + + return $sql; + } + + /** + * Quote Table Row + * + * @param string $tableName + * @param array $row + * @return string + */ + protected function _quoteRow($tableName, array $row) + { + $adapter = $this->_getReadAdapter(); + $describe = $adapter->describeTable($tableName); + $dataTypes = array('bigint', 'mediumint', 'smallint', 'tinyint'); + $rowData = array(); + foreach ($row as $k => $v) { + if ($v === null) { + $value = 'NULL'; + } elseif (in_array(strtolower($describe[$k]['DATA_TYPE']), $dataTypes)) { + $value = $v; + } else { + $value = $adapter->quoteInto('?', $v); + } + $rowData[] = $value; + } + + return sprintf('(%s)', implode(',', $rowData)); + } + + /** + * Turn on serializable mode + */ + public function turnOnSerializableMode() + { + $this->_getReadAdapter()->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + } + + /** + * Turn on read committed mode + */ + public function turnOnReadCommittedMode() + { + $this->_getReadAdapter()->query("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"); + } +} diff --git a/app/code/core/Mage/Backup/etc/adminhtml.xml b/app/code/core/Mage/Backup/etc/adminhtml.xml index dfe811bea1..ac212733c4 100644 --- a/app/code/core/Mage/Backup/etc/adminhtml.xml +++ b/app/code/core/Mage/Backup/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Backup/etc/config.xml b/app/code/core/Mage/Backup/etc/config.xml index c580fb70bb..1fe7c44131 100644 --- a/app/code/core/Mage/Backup/etc/config.xml +++ b/app/code/core/Mage/Backup/etc/config.xml @@ -21,25 +21,26 @@ * * @category Mage * @package Mage_Backup - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 Mage_Backup_Model - backup_mysql4 + backup_resource - - Mage_Backup_Model_Mysql4 - + + Mage_Backup_Model_Resource + backup_mysql4 + diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php index c74aa5662b..6dd6271b6f 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php index 9869ae334f..987c0f3c96 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php index 8c686ce5a5..1ea2d12899 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php index ab4707f31e..810fc9e43b 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php index 9472d6f5b3..5f286d2db1 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php index 6d578500b0..99021773a7 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php index ca063b173e..58f1545ca4 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php index 0a03580f97..0a4963b01d 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php index 0bdbe33e1e..567ceafb50 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php index a08be2db34..e9fbd36d97 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php index a09ca92b36..cada5389c1 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php index debb0f4ed0..cddd1224d8 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php index 2a70755980..17b48d5012 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php index 701b8c9cfe..058571f376 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php index eea3fd55e3..6be1d07cf7 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index 1b10c9aa8f..b32844d9f8 100644 --- a/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php index 3791881503..af362e147f 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php index 10e806aca5..2e29a0a4cb 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View.php index bc66af2035..dc76000f14 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -51,7 +51,7 @@ public function getTierPrices($product = null) if (is_array($prices)) { foreach ($prices as $price) { $price['price_qty'] = $price['price_qty']*1; - $price['savePercent'] = ceil(100 - $price['price'] ); + $price['savePercent'] = ceil(100 - $price['price']); $price['formated_price'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price']))); $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $price['website_price'], true))); $res[] = $price; diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php index 8122bf1c27..fdef10d6f4 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php index 163b7025a9..ca892bfa0d 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php index 6362a6a3ae..874bf5d0d2 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php index b833e0bd01..2162a5de4e 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php index 7a1b5b34b0..290d1741a0 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php index bcbd891541..6e4ce82ccf 100644 --- a/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php +++ b/app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php b/app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php index bee28046b6..284e9c6832 100644 --- a/app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php b/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php index 514b229858..496026d16b 100644 --- a/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php +++ b/app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php b/app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php index 6f5abc3ae2..6e83845de9 100644 --- a/app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php +++ b/app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Helper/Data.php b/app/code/core/Mage/Bundle/Helper/Data.php index 939dacfe9a..12a0524a30 100644 --- a/app/code/core/Mage/Bundle/Helper/Data.php +++ b/app/code/core/Mage/Bundle/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php b/app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php index 1e4a4e3932..de618c82d3 100644 --- a/app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php +++ b/app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php b/app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php index 4a954c4c78..46066631e2 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,85 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Bundle extends Mage_CatalogIndex_Model_Mysql4_Data_Abstract +class Mage_Bundle_Model_Mysql4_Bundle extends Mage_Bundle_Model_Resource_Bundle { - /** - * Preparing select for getting selection's raw data by product id - * also can be specified extra parameter for limit which columns should be selected - * - * @param int $productId - * @param array $columns - * @return Zend_DB_Select - */ - protected function _getSelect($productId, $columns = array()) - { - return $this->_getReadAdapter()->select() - ->from(array("bundle_option" => $this->getTable('bundle/option')), array("type", "option_id")) - ->where("bundle_option.parent_id = ?", $productId) - ->where("bundle_option.required = 1") - ->joinLeft(array( - "bundle_selection" => $this->getTable('bundle/selection')), - "bundle_selection.option_id = bundle_option.option_id", $columns); - } - - /** - * Retrieve selection data for specified product id - * - * @param int $productId - * @return array - */ - public function getSelectionsData($productId) - { - return $this->_getReadAdapter()->fetchAll($this->_getSelect( - $productId, - array("*") - )); - } - - /** - * Removing all quote items for specified product - * - * @param int $productId - */ - public function dropAllQuoteChildItems($productId) - { - $result = $this->_getReadAdapter()->fetchRow( - $this->_getReadAdapter()->select() - ->from($this->getTable('sales/quote_item'), "GROUP_CONCAT(`item_id`) as items") - ->where("product_id = ?", $productId)); - - if ($result['items'] != '') { - $this->_getWriteAdapter() - ->query("DELETE FROM ".$this->getTable('sales/quote_item')." - WHERE `parent_item_id` in (". $result['items'] .")"); - } - } - - /** - * Removes specified selections by ids for specified product id - * - * @param int $productId - * @param array $ids - */ - public function dropAllUnneededSelections($productId, $ids) - { - $this->_getWriteAdapter() - ->query("DELETE FROM ".$this->getTable('bundle/selection')." - WHERE `parent_product_id` = ". $productId . ( count($ids) > 0 ? " and selection_id not in (" . implode(',', $ids) . ")": '')); - } - - /** - * Save product relations - * - * @param int $parentId - * @param array $childIds - * @return Mage_Bundle_Model_Mysql4_Bundle - */ - public function saveProductRelations($parentId, $childIds) - { - Mage::getResourceSingleton('catalog/product_relation') - ->processRelations($parentId, $childIds); - - return $this; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php b/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php index cd108089eb..a95c9fd418 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,429 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Indexer_Price - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default +class Mage_Bundle_Model_Mysql4_Indexer_Price extends Mage_Bundle_Model_Resource_Indexer_Price { - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareBundlePrice(); - - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds) - { - $this->_prepareBundlePrice($entityIds); - - return $this; - } - - /** - * Retrieve temporary price index table name for fixed bundle products - * - * @return string - */ - protected function _getBundlePriceTable() - { - if ($this->useIdxTable()) { - return $this->getTable('bundle/price_indexer_idx'); - } - return $this->getTable('bundle/price_indexer_tmp'); - } - - /** - * Retrieve table name for temporary bundle selection prices index - * - * @return string - */ - protected function _getBundleSelectionTable() - { - if ($this->useIdxTable()) { - return $this->getTable('bundle/selection_indexer_idx'); - } - return $this->getTable('bundle/selection_indexer_tmp'); - } - - /** - * Retrieve table name for temporary bundle option prices index - * - * @return string - */ - protected function _getBundleOptionTable() - { - if ($this->useIdxTable()) { - return $this->getTable('bundle/option_indexer_idx'); - } - return $this->getTable('bundle/option_indexer_tmp'); - } - - /** - * Prepare temporary price index table for fixed bundle products - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareBundlePriceTable() - { - $this->_getWriteAdapter()->delete($this->_getBundlePriceTable()); - return $this; - } - - /** - * Prepare table structure for temporary bundle selection prices index - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareBundleSelectionTable() - { - $this->_getWriteAdapter()->delete($this->_getBundleSelectionTable()); - return $this; - } - - /** - * Prepare table structure for temporary bundle option prices index - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareBundleOptionTable() - { - $this->_getWriteAdapter()->delete($this->_getBundleOptionTable()); - return $this; - } - - /** - * Prepare temporary price index data for bundle products by price type - * - * @param int $priceType - * @param int|array $entityIds the entity ids limitatation - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareBundlePriceByType($priceType, $entityIds = null) - { - $write = $this->_getWriteAdapter(); - $table = $this->_getBundlePriceTable(); - - $select = $write->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) - ->join( - array('cg' => $this->getTable('customer/customer_group')), - '', - array('customer_group_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('website_id', 'cw') - ->join( - array('cwd' => $this->_getWebsiteDateTable()), - 'cw.website_id = cwd.website_id', - array()) - ->joinLeft( - array('tp' => $this->_getTierPriceIndexTable()), - 'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id' - . ' AND tp.customer_group_id = cg.customer_group_id', - array()) - ->where('e.type_id=?', $this->getTypeId()); - - // add enable products limitation - $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true); - - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { - $select->columns(array('tax_class_id' => new Zend_Db_Expr('0'))); - } else { - $taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id'); - $select->columns(array('tax_class_id' => new Zend_Db_Expr("IF($taxClassId IS NOT NULL, $taxClassId, 0)"))); - } - - $priceTypeCond = $write->quoteInto('=?', $priceType); - $this->_addAttributeToSelect($select, 'price_type', 'e.entity_id', 'cs.store_id', $priceTypeCond); - - $price = $this->_addAttributeToSelect($select, 'price', 'e.entity_id', 'cs.store_id'); - $specialPrice = $this->_addAttributeToSelect($select, 'special_price', 'e.entity_id', 'cs.store_id'); - $specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', 'e.entity_id', 'cs.store_id'); - $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id'); - $curentDate = new Zend_Db_Expr('cwd.date'); - - $specialExpr = new Zend_Db_Expr("IF(IF({$specialFrom} IS NULL, 1, " - . "IF({$specialFrom} <= {$curentDate}, 1, 0)) > 0 AND IF({$specialTo} IS NULL, 1, " - . "IF({$specialTo} >= {$curentDate}, 1, 0)) > 0 AND {$specialPrice} > 0, $specialPrice, 0)"); - $tierExpr = new Zend_Db_Expr("tp.min_price"); - - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { - $finalPrice = new Zend_Db_Expr("IF({$specialExpr} > 0," - . " ROUND($price * ({$specialExpr} / 100), 4), {$price})"); - $tierPrice = new Zend_Db_Expr("IF({$tierExpr} IS NOT NULL," - . " ROUND({$price} - ({$price} * ({$tierExpr} / 100)), 4), NULL)"); - } else { - $finalPrice = new Zend_Db_Expr("0"); - $tierPrice = new Zend_Db_Expr("IF({$tierExpr} IS NOT NULL, 0, NULL)"); - } - - $select->columns(array( - 'price_type' => new Zend_Db_Expr($priceType), - 'special_price' => $specialExpr, - 'tier_percent' => $tierExpr, - 'orig_price' => new Zend_Db_Expr("IF({$price} IS NULL, 0, {$price})"), - 'price' => $finalPrice, - 'min_price' => $finalPrice, - 'max_price' => $finalPrice, - 'tier_price' => $tierPrice, - 'base_tier' => $tierPrice, - )); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('catalog_product_prepare_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('e.entity_id'), - 'website_field' => new Zend_Db_Expr('cw.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertFromSelect($table); - $write->query($query); - - return $this; - } - - /** - * Calculate fixed bundle product selections price - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _calculateBundleOptionPrice() - { - $write = $this->_getWriteAdapter(); - - $this->_prepareBundleSelectionTable(); - $this->_calculateBundleSelectionPrice(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED); - $this->_calculateBundleSelectionPrice(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC); - - $this->_prepareBundleOptionTable(); - - $select = $write->select() - ->from( - array('i' => $this->_getBundleSelectionTable()), - array('entity_id', 'customer_group_id', 'website_id', 'option_id')) - ->group(array('entity_id', 'customer_group_id', 'website_id', 'option_id')) - ->columns(array( - 'min_price' => new Zend_Db_Expr("IF(i.is_required = 1, MIN(i.price), 0)"), - 'alt_price' => new Zend_Db_Expr("IF(i.is_required = 0, MIN(i.price), 0)"), - 'max_price' => new Zend_Db_Expr("IF(i.group_type = 1, SUM(i.price), MAX(i.price))"), - 'tier_price' => new Zend_Db_Expr("IF(i.is_required = 1, MIN(i.tier_price), 0)"), - 'alt_tier_price' => new Zend_Db_Expr("IF(i.is_required = 0, MIN(i.tier_price), 0)"), - )); - - $query = $select->insertFromSelect($this->_getBundleOptionTable()); - $write->query($query); - - $this->_prepareDefaultFinalPriceTable(); - - $minPrice = new Zend_Db_Expr("IF(SUM(io.min_price) = 0, MIN(io.alt_price), SUM(io.min_price)) + i.price"); - $maxPrice = new Zend_Db_Expr("SUM(io.max_price) + i.price"); - $tierPrice = new Zend_Db_Expr("IF(i.tier_percent IS NOT NULL, IF(SUM(io.tier_price) = 0, " - . "SUM(io.alt_tier_price), SUM(io.tier_price)) + i.tier_price, NULL)"); - - $select = $write->select() - ->from( - array('io' => $this->_getBundleOptionTable()), - array('entity_id', 'customer_group_id', 'website_id')) - ->join( - array('i' => $this->_getBundlePriceTable()), - 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' - . ' AND i.website_id = io.website_id', - array()) - ->group(array('io.entity_id', 'io.customer_group_id', 'io.website_id')) - ->columns(array('i.tax_class_id', - 'orig_price' => 'i.orig_price', - 'price' => 'i.price', - 'min_price' => $minPrice, - 'max_price' => $maxPrice, - 'tier_price' => $tierPrice, - 'base_tier' => 'i.base_tier' - )); - - $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable()); - $write->query($query); - - return $this; - } - - /** - * Calculate bundle product selections price by product type - * - * @param int $priceType - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _calculateBundleSelectionPrice($priceType) - { - $write = $this->_getWriteAdapter(); - - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { - $priceExpr = new Zend_Db_Expr("IF(IF(bsp.selection_price_type IS NULL, bs.selection_price_type, " - . "bsp.selection_price_type) = 1, " - . "ROUND(i.price * (IF(bsp.selection_price_value IS NULL, bs.selection_price_value, " - . "bsp.selection_price_value) / 100), 4), IF(i.special_price > 0, " - . "ROUND(IF(bsp.selection_price_value IS NULL, bs.selection_price_value, bsp.selection_price_value) " - . "* (i.special_price / 100), 4), IF(bsp.selection_price_value IS NULL, bs.selection_price_value, " - . "bsp.selection_price_value))) * bs.selection_qty"); - $tierExpr = new Zend_Db_Expr("IF(i.base_tier IS NOT NULL, IF(IF(bsp.selection_price_type IS NULL, " - . "bs.selection_price_type, bsp.selection_price_type) = 1, " - . "ROUND(i.base_tier - (i.base_tier * (IF(bsp.selection_price_value IS NULL, bs.selection_price_value, " - . "bsp.selection_price_value) / 100)), 4), IF(i.tier_percent > 0, " - . "ROUND(IF(bsp.selection_price_value IS NULL, bs.selection_price_value, bsp.selection_price_value) " - . "- (IF(bsp.selection_price_value IS NULL, bs.selection_price_value, bsp.selection_price_value) " - . "* (i.tier_percent / 100)), 4), IF(bsp.selection_price_value IS NULL, bs.selection_price_value, " - . "bsp.selection_price_value))) * bs.selection_qty, NULL)"); - } else { - $priceExpr = new Zend_Db_Expr("IF(i.special_price > 0, ROUND(idx.min_price * (i.special_price / 100), 4), " - . "idx.min_price) * bs.selection_qty"); - $tierExpr = new Zend_Db_Expr("IF(i.base_tier IS NOT NULL, ROUND(idx.min_price * (i.base_tier / 100), 4) " - . "* bs.selection_qty, NULL)"); - } - - $select = $write->select() - ->from( - array('i' => $this->_getBundlePriceTable()), - array('entity_id', 'customer_group_id', 'website_id')) - ->join( - array('bo' => $this->getTable('bundle/option')), - 'bo.parent_id = i.entity_id', - array('option_id')) - ->join( - array('bs' => $this->getTable('bundle/selection')), - 'bs.option_id = bo.option_id', - array('selection_id')) - ->joinLeft( - array('bsp' => $this->getTable('bundle/selection_price')), - 'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id', - array('')) - ->join( - array('idx' => $this->getIdxTable()), - 'bs.product_id = idx.entity_id AND i.customer_group_id = idx.customer_group_id' - . ' AND i.website_id = idx.website_id', - array()) - ->join( - array('e' => $this->getTable('catalog/product')), - 'bs.product_id = e.entity_id AND e.required_options=0', - array()) - ->where('i.price_type=?', $priceType) - ->columns(array( - 'group_type' => new Zend_Db_Expr("IF(bo.type = 'select' OR bo.type = 'radio', 0, 1)"), - 'is_required' => 'bo.required', - 'price' => $priceExpr, - 'tier_price' => $tierExpr, - )); - - $query = $select->insertFromSelect($this->_getBundleSelectionTable()); - $write->query($query); - - return $this; - } - - /** - * Prepare temporary index price for bundle products - * - * @param int|array $entityIds the entity ids limitation - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareBundlePrice($entityIds = null) - { - $this->_prepareTierPriceIndex($entityIds); - $this->_prepareBundlePriceTable(); - $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED, $entityIds); - $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC, $entityIds); - - /** - * Add possibility modify prices from external events - */ - $select = $this->_getWriteAdapter()->select() - ->join(array('wd' => $this->_getWebsiteDateTable()), - 'i.website_id = wd.website_id', - array()); - Mage::dispatchEvent('prepare_catalog_product_price_index_table', array( - 'index_table' => array('i' => $this->_getBundlePriceTable()), - 'select' => $select, - 'entity_id' => 'i.entity_id', - 'customer_group_id' => 'i.customer_group_id', - 'website_id' => 'i.website_id', - 'website_date' => 'wd.date', - 'update_fields' => array('price', 'min_price', 'max_price') - )); - - $this->_calculateBundleOptionPrice(); - $this->_applyCustomOption(); - - $this->_movePriceDataToIndexTable(); - - return $this; - } - - /** - * Prepare percentage tier price for bundle products - * - * @see Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price::_prepareTierPriceIndex - * @param int|array $entityIds - * @return Mage_Bundle_Model_Mysql4_Indexer_Price - */ - protected function _prepareTierPriceIndex($entityIds = null) - { - $adapter = $this->_getWriteAdapter(); - - // remove index by bundle products - $select = $adapter->select() - ->from(array('i' => $this->_getTierPriceIndexTable()), null) - ->join( - array('e' => $this->getTable('catalog/product')), - 'i.entity_id=e.entity_id', - array()) - ->where('e.type_id=?', $this->getTypeId()); - $query = $select->deleteFromSelect('i'); - $adapter->query($query); - - $select = $adapter->select() - ->from( - array('tp' => $this->getValueTable('catalog/product', 'tier_price')), - array('entity_id')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'tp.entity_id=e.entity_id', - array()) - ->join( - array('cg' => $this->getTable('customer/customer_group')), - 'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)', - array('customer_group_id')) - ->join( - array('cw' => $this->getTable('core/website')), - 'tp.website_id = 0 OR tp.website_id = cw.website_id', - array('website_id')) - ->where('cw.website_id != 0') - ->where('e.type_id=?', $this->getTypeId()) - ->columns(new Zend_Db_Expr('MIN(tp.value)')) - ->group(array('tp.entity_id', 'cg.customer_group_id', 'cw.website_id')); - - if (!empty($entityIds)) { - $select->where('tp.entity_id IN(?)', $entityIds); - } - - $query = $select->insertFromSelect($this->_getTierPriceIndexTable()); - $adapter->query($query); - - return $this; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php b/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php index 396cbc3c76..1512914af7 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,193 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Indexer_Stock extends Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default +class Mage_Bundle_Model_Mysql4_Indexer_Stock extends Mage_Bundle_Model_Resource_Indexer_Stock { -/** - * Reindex temporary (price result data) for all products - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareIndexTable(); - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - public function reindexEntity($entityIds) - { - $this->_updateIndex($entityIds); - - return $this; - } - - /** - * Retrieve table name for temporary bundle option stock index - * - * @return string - */ - protected function _getBundleOptionTable() - { - return $this->getTable('bundle/stock_index'); - } - - /** - * Prepare stock status per Bundle options, website and stock - * - * @param int|array $entityIds - * @param bool $usePrimaryTable use primary or temporary index table - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false) - { - $this->_cleanBundleOptionStockData(); - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); - $adapter = $this->_getWriteAdapter(); - $select = $adapter->select() - ->from(array('bo' => $this->getTable('bundle/option')), array('parent_id')); - $this->_addWebsiteJoinToSelect($select, false); - $select->columns('website_id', 'cw') - ->join( - array('cis' => $this->getTable('cataloginventory/stock')), - '', - array('stock_id')) - ->joinLeft( - array('bs' => $this->getTable('bundle/selection')), - 'bs.option_id = bo.option_id', - array()) - ->joinLeft( - array('i' => $idxTable), - 'i.product_id = bs.product_id AND i.website_id = cw.website_id AND i.stock_id = cis.stock_id', - array()) - ->joinLeft( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id = bs.product_id', - array()) - ->where('cw.website_id != 0') - ->group(array('bo.parent_id', 'cw.website_id', 'cis.stock_id', 'bo.option_id')) - ->columns(array( - 'option_id' => 'bo.option_id', - 'status' => new Zend_Db_Expr("MAX(IF(e.required_options = 0, i.stock_status, 0))") - )); - - if (!is_null($entityIds)) { - $select->where('bo.parent_id IN(?)', $entityIds); - } - - // clone select for bundle product without required bundle options - $selectNonRequired = clone $select; - - $select->where('bo.required = ?', 1); - $selectNonRequired->where('bo.required = ?', 0) - ->having('`status` = 1'); - - $query = $select->insertFromSelect($this->_getBundleOptionTable()); - $adapter->query($query); - - $query = $selectNonRequired->insertFromSelect($this->_getBundleOptionTable()); - $adapter->query($query); - - return $this; - } - - /** - * Get the select object for get stock status by product ids - * - * @param int|array $entityIds - * @param bool $usePrimaryTable use primary or temporary index table - * @return Varien_Db_Select - */ - protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) - { - $this->_prepareBundleOptionStockData($entityIds, $usePrimaryTable); - - $adapter = $this->_getWriteAdapter(); - $select = $adapter->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('cw.website_id') - ->join( - array('cis' => $this->getTable('cataloginventory/stock')), - '', - array('stock_id')) - ->joinLeft( - array('cisi' => $this->getTable('cataloginventory/stock_item')), - 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', - array()) - ->joinLeft( - array('o' => $this->_getBundleOptionTable()), - 'o.entity_id = e.entity_id AND o.website_id = cw.website_id AND o.stock_id = cis.stock_id', - array()) - ->columns(array('qty' => new Zend_Db_Expr('0'))) - ->where('cw.website_id != 0') - ->where('e.type_id = ?', $this->getTypeId()) - ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); - - // add limitation of status - $condition = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition); - - if ($this->_isManageStock()) { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0,' - . ' 1, cisi.is_in_stock)'); - } else { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1,' - . 'cisi.is_in_stock, 1)'); - } - - $select->columns(array('status' => new Zend_Db_Expr("LEAST(MIN(o.stock_status), {$statusExpr})"))); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - return $select; - } - - /** - * Prepare stock status data in temporary index table - * - * @param int|array $entityIds the product limitation - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - protected function _prepareIndexTable($entityIds = null) - { - parent::_prepareIndexTable($entityIds); - $this->_cleanBundleOptionStockData(); - - return $this; - } - - /** - * Update Stock status index by product ids - * - * @param array|int $entityIds - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - protected function _updateIndex($entityIds) - { - parent::_updateIndex($entityIds); - $this->_cleanBundleOptionStockData(); - - return $this; - } - - /** - * Clean temporary bundle options stock data - * - * @return Mage_Bundle_Model_Mysql4_Indexer_Stock - */ - protected function _cleanBundleOptionStockData() - { - $this->_getWriteAdapter()->delete($this->_getBundleOptionTable()); - return $this; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Option.php b/app/code/core/Mage/Bundle/Model/Mysql4/Option.php index 389475e805..a238ecd0f4 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Option.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Option.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Bundle Option Resource Model * @@ -31,92 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Option extends Mage_Core_Model_Mysql4_Abstract +class Mage_Bundle_Model_Mysql4_Option extends Mage_Bundle_Model_Resource_Option { - /** - * Initialize connection and define resource - * - */ - protected function _construct() - { - $this->_init('bundle/option', 'option_id'); - } - - /** - * After save process - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Bundle_Model_Mysql4_Option - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - parent::_afterSave($object); - - $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId()); - $condition .= ' and (' . $this->_getWriteAdapter()->quoteInto('store_id = ?', $object->getStoreId()); - $condition .= ' or store_id = 0)'; - - $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition); - - $data = new Varien_Object(); - $data->setOptionId($object->getId()) - ->setStoreId($object->getStoreId()) - ->setTitle($object->getTitle()); - - $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData()); - - /** - * also saving default value if this store view scope - */ - - if ($object->getStoreId()) { - $data->setStoreId('0'); - $data->setTitle($object->getDefaultTitle()); - $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData()); - } - - return $this; - } - - /** - * After delete process - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Bundle_Model_Mysql4_Option - */ - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - parent::_afterDelete($object); - - $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition); - - return $this; - } - -/** - * Retrieve options searchable data - * - * @param int $productId - * @param int $storeId - * @return array - */ - public function getSearchableData($productId, $storeId) - { - $select = $this->_getReadAdapter()->select() - ->from(array('option' => $this->getMainTable()), null) - ->join( - array('option_title_default' => $this->getTable('bundle/option_value')), - 'option_title_default.option_id=option.option_id AND option_title_default.store_id=0', - array()) - ->joinLeft( - array('option_title_store' => $this->getTable('bundle/option_value')), - 'option_title_store.option_id=option.option_id AND option_title_store.store_id=' . intval($storeId), - array('title' => 'IFNULL(option_title_store.title, option_title_default.title)')) - ->where('option.parent_id=?', $productId); - if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) { - $searchData = array(); - } - return $searchData; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php b/app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php index eed2d0aec3..527ac9867c 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Bundle Options Resource Collection * @@ -31,130 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Bundle_Model_Mysql4_Option_Collection extends Mage_Bundle_Model_Resource_Option_Collection { - /** - * All item ids cache - * - * @var array - */ - protected $_itemIds; - - protected $_selectionsAppended = false; - protected function _construct() - { - $this->_init('bundle/option'); - } - - public function joinValues($storeId) - { - $this->getSelect()->joinLeft(array('option_value_default' => $this->getTable('bundle/option_value')), - '`main_table`.`option_id` = `option_value_default`.`option_id` and `option_value_default`.`store_id` = "0"', - array()) - ->columns(array('default_title' => 'option_value_default.title')); - - if ($storeId !== null) { - $this->getSelect() - ->columns(array('title' => 'IFNULL(`option_value`.`title`, `option_value_default`.`title`)')) - ->joinLeft(array('option_value' => $this->getTable('bundle/option_value')), - '`main_table`.`option_id` = `option_value`.`option_id` and `option_value`.`store_id` = "' . $storeId . '"', - array()); - } - return $this; - } - - public function setProductIdFilter($productId) - { - $this->addFieldToFilter('`main_table`.`parent_id`', $productId); - return $this; - } - - public function setPositionOrder() - { - $this->getSelect()->order('main_table.position asc') - ->order('main_table.option_id asc'); - return $this; - } - - /** - * Append selection to options - * stripBefore - indicates to reload - * appendAll - indicates do we need to filter by saleable and required custom options - * - * @param Mage_Bundle_Model_Mysql4_Selection_Collection $selectionsCollection - * @param bool $stripBefore - * @param bool $appendAll - * @return array - */ - public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true) - { - if ($stripBefore) { - $this->_stripSelections(); - } - - if (!$this->_selectionsAppended) { - foreach ($selectionsCollection->getItems() as $key => $_selection) { - if ($_option = $this->getItemById($_selection->getOptionId())) { - if ($appendAll || ($_selection->isSalable() && !$_selection->getRequiredOptions())) { - $_selection->setOption($_option); - $_option->addSelection($_selection); - } else { - $selectionsCollection->removeItemByKey($key); - } - } - } - $this->_selectionsAppended = true; - } - - return $this->getItems(); - } - - /** - * Removes appended selections before - * - * @return Mage_Bundle_Model_Mysql4_Option_Collection - */ - protected function _stripSelections() - { - foreach ($this->getItems() as $option) { - $option->setSelections(array()); - } - $this->_selectionsAppended = false; - return $this; - } - - - public function setIdFilter($ids) - { - if (is_array($ids)) { - $this->addFieldToFilter('`main_table`.`option_id`', array('in' => $ids)); - } else if ($ids != '') { - $this->addFieldToFilter('`main_table`.`option_id`', $ids); - } - return $this; - } - - /** - * Reset all item ids cache - * - * @return Mage_Bundle_Model_Mysql4_Option_Collection - */ - public function resetAllIds() - { - $this->_itemIds = null; - return $this; - } - - /** - * Retrive all ids for collection - * - * @return array - */ - public function getAllIds() - { - if (is_null($this->_itemIds)) { - $this->_itemIds = parent::getAllIds(); - } - return $this->_itemIds; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php b/app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php index 1065bae443..9e752aa4f8 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,773 +31,7 @@ * @category Mage * @package Mage_Bundle * @author Magento Core Team - * @deprecated since 1.4.0.0 - * @see Mage_Bundle_Model_Mysql4_Indexer_Price */ -class Mage_Bundle_Model_Mysql4_Price_Index extends Mage_Core_Model_Mysql4_Abstract +class Mage_Bundle_Model_Mysql4_Price_Index extends Mage_Bundle_Model_Resource_Price_Index { - /** - * EAV attributes cache - * - * @var array - */ - protected $_attributes = array(); - - /** - * Websites cache - * - * @var array - */ - protected $_websites; - - /** - * Customer Groups cache - * - * @var array - */ - protected $_customerGroups; - - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('bundle/price_index', 'entity_id'); - } - - /** - * Retrieve attribute object - * - * @param string $attributeCode - * @return Mage_Catalog_Model_Resource_Eav_Attribute - */ - protected function _getAttribute($attributeCode) - { - if (!isset($this->_attributes[$attributeCode])) { - $this->_attributes[$attributeCode] = Mage::getSingleton('catalog/config') - ->getAttribute('catalog_product', $attributeCode); - } - return $this->_attributes[$attributeCode]; - } - - /** - * Retrieve websites collection array - * - * @return array - */ - protected function _getWebsites() - { - if (is_null($this->_websites)) { - $this->_websites = Mage::app()->getWebsites(false); - } - return $this->_websites; - } - - /** - * Retrieve customer groups collection array - * - * @return array - */ - protected function _getCustomerGroups() - { - if (is_null($this->_customerGroups)) { - $this->_customerGroups = array(); - foreach (Mage::getModel('customer/group')->getCollection() as $group) { - $this->_customerGroups[$group->getId()] = $group; - } - } - return $this->_customerGroups; - } - - /** - * Retrieve product ids array by product condition - * - * @param Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $product - * @param int $lastEntityId - * @param int $limit - * @return array - */ - public function getProducts($product = null, $lastEntityId = 0, $limit = 100) - { - $select = $this->_getReadAdapter()->select() - ->from( - array('e' => $this->getTable('catalog/product')), - array('entity_id')) - ->where('e.type_id=?', 'bundle'); - if ($product instanceof Mage_Catalog_Model_Product) { - $select->where('e.entity_id=?', $product->getId()); - } - elseif ($product instanceof Mage_Catalog_Model_Product_Condition_Interface) { - $value = new Zend_Db_Expr($product->getIdsSelect($this->_getReadAdapter())); - $select->where('e.entity_id IN(?)', $value); - } - elseif (is_numeric($product) || is_array($product)) { - $select->where('e.entity_id IN(?)', $product); - } - - $priceType = $this->_getAttribute('price_type'); - $priceTypeAlias = 't_' . $priceType->getAttributeCode(); - $joinConds = array( - $this->_getReadAdapter()->quoteInto($priceTypeAlias . '.attribute_id=?', $priceType->getAttributeId()), - $priceTypeAlias.'.store_id=0', - $priceTypeAlias.'.entity_id=e.entity_id' - ); - $select->joinLeft( - array($priceTypeAlias => $priceType->getBackend()->getTable()), - join(' AND ', $joinConds), - array('price_type' => $priceTypeAlias . '.value') - ); - - $select->where('e.entity_id>?', $lastEntityId) - ->order('e.entity_id') - ->limit($limit); - - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Reindex Bundle product Price Index - * - * @param Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $products - * @return Mage_Bundle_Model_Price_Index - */ - public function reindex($products = null) - { - $lastEntityId = 0; - while (true) { - $productsData = $this->getProducts($products, $lastEntityId); - if (!$productsData) { - break; - } - - foreach ($productsData as $productId => $priceType) { - $this->_reindexProduct($productId, $priceType); - $lastEntityId = $productId; - } - } - - return $this; - } - - /** - * Reindex product price - * - * @param int $productId - * @param int $priceType - * @return Mage_Bundle_Model_Mysql4_Price_Index - */ - protected function _reindexProduct($productId, $priceType) - { - $options = $this->getSelections($productId); - $selectionProducts = array(); - foreach ($options as $option) { - foreach ($option['selections'] as $selection) { - $selectionProducts[$selection['product_id']] = $selection['product_id']; - } - } - - $priceIndex = array(); - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { - // load selection product prices from index for dynamic bundle - $priceIndex = $this->getProductsPriceFromIndex($selectionProducts); - } - - foreach ($this->_getWebsites() as $website) { - if (!$website->getDefaultStore()) { - continue; - } - $salableStatus = $this->getProductsSalableStatus($selectionProducts, $website); - $priceData = $this->getProductsPriceData($productId, $website); - $priceData = $priceData[$productId]; - - /* @var $website Mage_Core_Model_Website */ - foreach ($this->_getCustomerGroups() as $group) { - /* @var $group Mage_Customer_Model_Group */ - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { - $basePrice = $this->_getBasePrice($productId, $priceData, $website, $group); - $customOptions = $this->getCustomOptions($productId, $website); - } - elseif ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { - $basePrice = 0; - } - - list($minPrice, $maxPrice) = $this->_calculateBundleSelections($options, $salableStatus, - $productId, $priceType, $basePrice, $priceData, $priceIndex, $website, $group); - - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { - list($minPrice, $maxPrice) = $this->_calculateCustomOptions($customOptions, $basePrice, $minPrice, $maxPrice); - } - - $this->_savePriceIndex($productId, $website->getId(), $group->getId(), $minPrice, $maxPrice); - } - } - - return $this; - } - - /** - * Save price index - * - * @param int $productId - * @param int $websiteId - * @param int $groupId - * @param float $minPrice - * @param float $maxPrice - * @return Mage_Bundle_Model_Mysql4_Price_Index - */ - protected function _savePriceIndex($productId, $websiteId, $groupId, $minPrice, $maxPrice) - { - $adapter = $this->_getWriteAdapter(); - $adapter->beginTransaction(); - $sql = sprintf('INSERT INTO %s VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE' - . ' `min_price`=VALUES(`min_price`), `max_price`=VALUES(`max_price`)', - $adapter->quoteIdentifier($this->getMainTable())); - $bind = array($productId, $websiteId, $groupId, $minPrice, $maxPrice); - $adapter->query($sql, $bind); - $adapter->commit(); - - return $this; - } - - /** - * Retrieve bundle options with selections and prices by product - * - * @param int $productId - * @return array - */ - public function getSelections($productId) - { - $options = array(); - $select = $this->_getReadAdapter()->select() - ->from( - array('option_table' => $this->getTable('bundle/option')), - array('option_id', 'required', 'type')) - ->join( - array('selection_table' => $this->getTable('bundle/selection')), - 'selection_table.option_id=option_table.option_id', - array('selection_id', 'product_id', 'selection_price_type', - 'selection_price_value', 'selection_qty', 'selection_can_change_qty')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id=selection_table.product_id AND e.required_options=0', - array()) - ->where('option_table.parent_id=?', $productId); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - if (!isset($options[$row['option_id']])) { - $options[$row['option_id']] = array( - 'option_id' => $row['option_id'], - 'required' => $row['required'], - 'type' => $row['type'], - 'selections' => array() - ); - } - $options[$row['option_id']]['selections'][$row['selection_id']] = array( - 'selection_id' => $row['selection_id'], - 'product_id' => $row['product_id'], - 'price_type' => $row['selection_price_type'], - 'price_value' => $row['selection_price_value'], - 'qty' => $row['selection_qty'], - 'can_change_qty' => $row['selection_can_change_qty'] - ); - } - - return $options; - } - - /** - * Retrieve salable product statuses - * - * @param int|array $products - * @param Mage_Core_Model_Website $website - * @return array - */ - public function getProductsSalableStatus($products, Mage_Core_Model_Website $website) - { - $productsData = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') - ->where('e.entity_id IN(?)', $products); - // add belong to website - $select->joinLeft( - array('pw' => $this->getTable('catalog/product_website')), - 'e.entity_id=pw.product_id AND pw.website_id=' . $website->getId(), - array('pw.website_id') - ); - - $store = $website->getDefaultStore(); - - // add product status - $status = $this->_getAttribute('status'); - if ($status->isScopeGlobal()) { - $select->join( - array('t_status' => $status->getBackend()->getTable()), - 'e.entity_id=t_status.entity_id' - . ' AND t_status.attribute_id=' . $status->getAttributeId() - . ' AND t_status.store_id=0', - array('status' => 't_status.value')); - } - else { - $statusTable = $status->getBackend()->getTable(); - $select->join( - array('t1_status' => $statusTable), - 'e.entity_id=t1_status.entity_id' - . ' AND t1_status.attribute_id=' . $status->getAttributeId() - . ' AND t1_status.store_id=0', - array('status' => 'IF(t2_status.value_id > 0, t2_status.value, t1_status.value)')) - ->joinLeft( - array('t2_status' => $statusTable), - 't1_status.entity_id = t2_status.entity_id' - . ' AND t1_status.attribute_id = t2_status.attribute_id' - . ' AND t2_status.store_id=' . $store->getId(), - array()); - } - - Mage::dispatchEvent('catalog_product_prepare_index_select', array( - 'website' => $website, - 'select' => $select - )); - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $salable = isset($row['salable']) ? $row['salable'] : true; - $website = $row['website_id'] > 0 ? true : false; - $status = $row['status']; - - $productsData[$row['entity_id']] = $salable && $status && $website; - } - - return $productsData; - } - - /** - * Retrieve Selection Product price from Price Index - * Return index key {entity_id}-{website_id}-{customer_group_id} - * - * @param int|array $productIds - * @return array - */ - public function getProductsPriceFromIndex($productIds) - { - $index = array(); - $price = $this->_getAttribute('price'); - $select = $this->_getReadAdapter()->select() - ->from( - array('price_index' => $this->getTable('catalogindex/price')), - array('entity_id', 'customer_group_id', 'website_id', 'value')) - ->where('entity_id IN(?)', $productIds) - ->where('attribute_id=?', $price->getAttributeId()); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $indexKey = join('-', array( - $row['entity_id'], - $row['website_id'], - $row['customer_group_id'] - )); - $index[$indexKey] = $row['value']; - } - return $index; - } - - /** - * Retrieve product(s) price data - * - * @param int|array $products - * @param Mage_Core_Model_Website $website - * @return array - */ - public function getProductsPriceData($products, Mage_Core_Model_Website $website) - { - $productsData = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') - ->where('e.entity_id IN(?)', $products); - - $this->_addAttributeDataToSelect($select, 'price', $website); - $this->_addAttributeDataToSelect($select, 'special_price', $website); - $this->_addAttributeDataToSelect($select, 'special_from_date', $website); - $this->_addAttributeDataToSelect($select, 'special_to_date', $website); - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $productsData[$row['entity_id']] = array( - 'price' => $row['price'], - 'special_price' => $row['special_price'], - 'special_from_date' => $row['special_from_date'], - 'special_to_date' => $row['special_to_date'] - ); - } - - return $productsData; - } - - /** - * Add attribute data to select - * - * @param Varien_Db_Select $select - * @param string $attributeCode - * @param Mage_Core_Model_Website $website - * @return Mage_Bundle_Model_Mysql4_Price_Index - */ - protected function _addAttributeDataToSelect(Varien_Db_Select $select, $attributeCode, Mage_Core_Model_Website $website) - { - $attribute = $this->_getAttribute($attributeCode); - $store = $website->getDefaultStore(); - if ($attribute->isScopeGlobal()) { - $table = 't_' . $attribute->getAttributeCode(); - $select->joinLeft( - array($table => $attribute->getBackend()->getTable()), - 'e.entity_id='.$table.'.entity_id' - . ' AND '.$table.'.attribute_id=' . $attribute->getAttributeId() - . ' AND '.$table.'.store_id=0', - array($attribute->getAttributeCode() => $table . '.value')); - } - else { - $tableName = $attribute->getBackend()->getTable(); - $tableGlobal = 't1_' . $attribute->getAttributeCode(); - $tableStore = 't2_' . $attribute->getAttributeCode(); - - $select->joinLeft( - array($tableGlobal => $tableName), - 'e.entity_id='.$tableGlobal.'.entity_id' - . ' AND '.$tableGlobal.'.attribute_id=' . $attribute->getAttributeId() - . ' AND '.$tableGlobal.'.store_id=0', - array($attribute->getAttributeCode() => 'IF('.$tableStore.'.value_id > 0, '.$tableStore.'.value, '.$tableGlobal.'.value)')) - ->joinLeft( - array($tableStore => $tableName), - $tableGlobal.'.entity_id = '.$tableStore.'.entity_id' - . ' AND '.$tableGlobal.'.attribute_id = '.$tableStore.'.attribute_id' - . ' AND '.$tableStore.'.store_id=' . $store->getId(), - array()); - } - return $this; - } - - /** - * Retrieve fixed bundle base price (with special price and rules) - * - * @param int $productId - * @param array $priceData - * @param Mage_Core_Model_Website $website - * @param Mage_Customer_Model_Group $customerGroup - * @return float - */ - protected function _getBasePrice($productId, array $priceData, $website, $customerGroup) - { - $store = $website->getDefaultStore(); - $storeTimeStamp = Mage::app()->getLocale()->storeTimeStamp($store); - $finalPrice = $this->_calculateSpecialPrice($priceData['price'], $priceData, $website); - - $rulePrice = Mage::getResourceModel('catalogrule/rule') - ->getRulePrice($storeTimeStamp, $website->getId(), $customerGroup->getId(), $productId); - - if ($rulePrice !== null && $rulePrice !== false) { - $finalPrice = min($finalPrice, $rulePrice); - } - - return $finalPrice; - } - - /** - * Retrieve custom options for product - * - * @param int $productId - * @param Mage_Core_Model_Website $website - * @return array - */ - public function getCustomOptions($productId, Mage_Core_Model_Website $website) - { - $options = array(); - $store = $website->getDefaultStore(); - $price = $this->_getAttribute('price'); - - $select = $this->getReadConnection()->select() - ->from( - array('option_table' => $this->getTable('catalog/product_option')), - array('option_id', 'is_require', 'type')) - ->where('option_table.product_id=?', $productId); - - if ($price->isScopeGlobal()) { - $select->join( - array('price_table' => $this->getTable('catalog/product_option_price')), - 'option_table.option_id=price_table.option_id' - . ' AND price_table.store_id=0', - array('value_id' => 'option_price_id', 'price', 'price_type') - ); - } - else { - $select - ->join( - array('price_global_table' => $this->getTable('catalog/product_option_price')), - 'option_table.option_id=price_global_table.option_id' - . ' AND price_global_table.store_id=0', - array( - 'value_id' => 'IFNULL(price_store_table.option_price_id, price_global_table.option_price_id)', - 'price' => 'IFNULL(price_store_table.price, price_global_table.price)', - 'price_type' => 'IFNULL(price_store_table.price_type, price_global_table.price_type)' - )) - ->joinLeft( - array('price_store_table' => $this->getTable('catalog/product_option_price')), - 'option_table.option_id=price_store_table.option_id' - . ' AND price_store_table.store_id=' . $store->getId(), - array()); - } - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - if (!isset($options[$row['option_id']])) { - $options[$row['option_id']] = array( - 'option_id' => $row['option_id'], - 'is_require' => $row['is_require'], - 'type' => $row['type'], - 'values' => array() - ); - } - $options[$row['option_id']]['values'][$row['value_id']] = array( - 'price_type' => $row['price_type'], - 'price_value' => $row['price'] - ); - } - - $select = $this->getReadConnection()->select() - ->from( - array('option_table' => $this->getTable('catalog/product_option')), - array('option_id', 'is_require', 'type')) - ->join( - array('type_table' => $this->getTable('catalog/product_option_type_value')), - 'option_table.option_id=type_table.option_id', - array() - ) - ->where('option_table.product_id=?', $productId); - - if ($price->isScopeGlobal()) { - $select->join( - array('price_table' => $this->getTable('catalog/product_option_type_price')), - 'type_table.option_type_id=price_table.option_type_id' - . ' AND price_table.store_id=0', - array('value_id' => 'option_type_id', 'price', 'price_type') - ); - } - else { - $select - ->join( - array('price_global_table' => $this->getTable('catalog/product_option_type_price')), - 'type_table.option_type_id=price_global_table.option_type_id' - . ' AND price_global_table.store_id=0', - array( - 'value_id' => 'IFNULL(price_store_table.option_type_id, price_global_table.option_type_id)', - 'price' => 'IFNULL(price_store_table.price, price_global_table.price)', - 'price_type' => 'IFNULL(price_store_table.price_type, price_global_table.price_type)' - )) - ->joinLeft( - array('price_store_table' => $this->getTable('catalog/product_option_type_price')), - 'type_table.option_type_id=price_store_table.option_type_id' - . ' AND price_store_table.store_id=' . $store->getId(), - array()); - } - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - if (!isset($options[$row['option_id']])) { - $options[$row['option_id']] = array( - 'option_id' => $row['option_id'], - 'is_require' => $row['is_require'], - 'type' => $row['type'], - 'values' => array() - ); - } - $options[$row['option_id']]['values'][$row['value_id']] = array( - 'price_type' => $row['price_type'], - 'price_value' => $row['price'] - ); - } - - return $options; - } - - /** - * Calculate custom options price - * Return array with indexes(0 -> min_price, 1 -> max_price) - * - * @param array $options - * @param float $basePrice - * @param float $minPrice - * @param float $maxPrice - * @return array - */ - public function _calculateCustomOptions(array $options, $basePrice, $minPrice, $maxPrice) - { - foreach ($options as $option) { - $optionPrices = array(); - foreach ($option['values'] as $value) { - if ($value['price_type'] == 'percent') { - $valuePrice = $basePrice * $value['price_value'] / 100;; - } - else { - $valuePrice = $value['price_value']; - } - $optionPrices[] = $valuePrice; - } - if ($option['is_require']) { - $minPrice += min($optionPrices); - } - $multiTypes = array( - Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN, - Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX, - Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE - ); - if ($optionPrices) { - if (in_array($option['type'], $multiTypes)) { - $maxPrice += array_sum($optionPrices); - } - else { - $maxPrice += max($optionPrices); - } - } - } - - return array($minPrice, $maxPrice); - } - - /** - * Calculate minimal and maximal price for bundle selections - * Return array with prices (0 -> min_price, 1 -> max_price) - * - * @param array $options - * @param array $salableStatus - * @param int $productId - * @param int $priceType - * @param float $basePrice - * @param array $priceData - * @param array $priceIndex - * @param Mage_Core_Model_Website $website - * @param Mage_Customer_Model_Group $group - * @return array - */ - public function _calculateBundleSelections(array $options, array $salableStatus, - $productId, $priceType, $basePrice, $priceData, $priceIndex, $website, $group) - { - $minPrice = $maxPrice = $basePrice; - $optPrice = 0; - - foreach ($options as $option) { - $optionPrices = array(); - foreach ($option['selections'] as $selection) { - if (!$selection['product_id']) { - continue; - } - - if (!$salableStatus[$selection['product_id']]) { - continue; - } - - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { - $basePrice = $this->_getBasePrice($productId, $priceData, $website, $group); - } - - // calculate selection price - if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { - $priceIndexKey = join('-', array( - $selection['product_id'], - $website->getId(), - $group->getId() - )); - - $selectionPrice = isset($priceIndex[$priceIndexKey]) ? $priceIndex[$priceIndexKey] : 0; - $selectionPrice = $this->_calculateSpecialPrice($selectionPrice, $priceData, $website); - } - else { - if ($selection['price_type']) { // persent - $selectionPrice = $basePrice * $selection['price_value'] / 100; - } - else { - $selectionPrice = $this->_calculateSpecialPrice($selection['price_value'], $priceData, $website); - } - } - - // calculate selection qty - if ($selection['can_change_qty'] && $option['type'] != 'multi' && $option['type'] != 'checkbox') { - $qty = 1; - } else { - $qty = $selection['qty']; - } - - $selectionPrice = $selectionPrice * $qty; - $optionPrices[$selection['selection_id']] = $selectionPrice; - } - - if ($optionPrices) { - if ($option['required']) { - $minPrice += min($optionPrices); - } - else { - $optPrice = $optPrice && $optPrice < min($optionPrices) ? $optPrice : min($optionPrices); - } - if (in_array($option['type'], array('multi', 'checkbox'))) { - $maxPrice += array_sum($optionPrices); - } - else { - $maxPrice += max($optionPrices); - } - } - } - - if ($minPrice == 0) { - $minPrice = $optPrice; - } - return array($minPrice, $maxPrice); - } - - /** - * Apply special price - * - * @param float $finalPrice - * @param array $priceData - * @param Mage_Core_Model_Website $website - * @return float - */ - public function _calculateSpecialPrice($finalPrice, array $priceData, Mage_Core_Model_Website $website) - { - $store = $website->getDefaultStore(); - $specialPrice = $priceData['special_price']; - - if (!is_null($specialPrice) && $specialPrice != false) { - if (Mage::app()->getLocale()->isStoreDateInInterval($store, $priceData['special_from_date'], $priceData['special_to_date'])) { - $specialPrice = ($finalPrice * $specialPrice) / 100; - $finalPrice = min($finalPrice, $specialPrice); - } - } - - return $finalPrice; - } - - /** - * Retrieve price index for products - * - * @param int|array $productIds - * @param int $websiteId - * @param int $groupId - * @return array - */ - public function loadPriceIndex($productIds, $websiteId, $groupId) - { - $prices = array(); - $select = $this->_getReadAdapter()->select() - ->from( - array('pi' => $this->getMainTable()), - array('entity_id', 'min_price', 'max_price')) - ->where('entity_id IN(?)', $productIds) - ->where('website_id=?', $websiteId) - ->where('customer_group_id=?', $groupId); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $prices[$row['entity_id']] = array( - 'min_price' => $row['min_price'], - 'max_price' => $row['max_price'] - ); - } - - return $prices; - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Selection.php b/app/code/core/Mage/Bundle/Model/Mysql4/Selection.php index 523d60b8b6..76ff30cd6c 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Selection.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Selection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Bundle Selection Resource Model * @@ -31,176 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Selection extends Mage_Core_Model_Mysql4_Abstract +class Mage_Bundle_Model_Mysql4_Selection extends Mage_Bundle_Model_Resource_Selection { - protected function _construct() - { - $this->_init('bundle/selection', 'selection_id'); - } -/* - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - parent::_afterSave($object); - - $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId()); - $condition .= ' and ' . $this->_getWriteAdapter()->quoteInto('store_id = ?', $object->getStoreId()); - - $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition); - - $data = new Varien_Object(); - $data->setOptionId($object->getId()) - ->setStoreId($object->getStoreId()) - ->setTitle($object->getTitle()); - - $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData()); - - return $this; - } - - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - parent::_afterDelete($object); - - $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition); - - return $this; - } -*/ - - /** - * Retrieve Price From index - * - * @param int $productId - * @param float $qty - * @param int $storeId - * @param int $groupId - * @return mixed - */ - public function getPriceFromIndex($productId, $qty, $storeId, $groupId) { - $select = clone $this->_getReadAdapter()->select(); - $select->reset(); - - $attrPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price'); - $attrTierPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tier_price'); - - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - - $select->from(array("price_index" => $this->getTable('catalogindex/price')), array('price' => 'SUM(value)')) - ->where('entity_id in (?)', $productId) - ->where('website_id = ?', $websiteId) - ->where('customer_group_id = ?', $groupId) - ->where('attribute_id in (?)', array($attrPriceId, $attrTierPriceId)) - ->where('qty <= ?', $qty) - ->group('entity_id'); - - $price = $this->_getReadAdapter()->fetchCol($select); - if (!empty($price)) { - return array_shift($price); - } else { - return 0; - } - } - - /** - * Retrieve Required children ids - * Return grouped array, ex array( - * group => array(ids) - * ) - * - * @param int $parentId - * @param bool $required - * @return array - */ - public function getChildrenIds($parentId, $required = true) - { - $childrenIds = array(); - $notRequired = array(); - $select = $this->_getReadAdapter()->select() - ->from( - array('tbl_selection' => $this->getMainTable()), - array('product_id', 'parent_product_id', 'option_id')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id=tbl_selection.product_id AND e.required_options=0', - array() - ) - ->join( - array('tbl_option' => $this->getTable('bundle/option')), - '`tbl_option`.`option_id` = `tbl_selection`.`option_id`', - array('required') - ) - ->where('`tbl_selection`.`parent_product_id`=?', $parentId); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - if ($row['required']) { - $childrenIds[$row['option_id']][$row['product_id']] = $row['product_id']; - } - else { - $notRequired[$row['option_id']][$row['product_id']] = $row['product_id']; - } - } - - if (!$required) { - $childrenIds = array_merge($childrenIds, $notRequired); - } - else { - if (!$childrenIds) { - foreach ($notRequired as $groupedChildrenIds) { - foreach ($groupedChildrenIds as $childId) { - $childrenIds[0][$childId] = $childId; - } - } - } - if (!$childrenIds) { - $childrenIds = array(array()); - } - } - - return $childrenIds; - } - - /** - * Retrieve array of related bundle product ids by selection product id(s) - * - * @param int|array $childId - * @return array - */ - public function getParentIdsByChild($childId) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->distinct(true) - ->from($this->getMainTable(), 'parent_product_id') - ->where('product_id IN(?)', $childId); - - return $adapter->fetchCol($select); - } - - /** - * Save bundle item price per website - * - * @param Mage_Bundle_Model_Selection $item - */ - public function saveSelectionPrice($item) - { - if ($item->getDefaultPriceScope()) { - $this->_getWriteAdapter()->delete($this->getTable('bundle/selection_price'), - array( - 'selection_id = ?' => $item->getSelectionId(), - 'website_id = ?' => $item->getWebsiteId() - )); - } else { - $values = array( - 'selection_id' => $item->getSelectionId(), - 'website_id' => $item->getWebsiteId(), - 'selection_price_type' => $item->getSelectionPriceType(), - 'selection_price_value' => $item->getSelectionPriceValue() - ); - $this->_getWriteAdapter()->insertOnDuplicate( - $this->getTable('bundle/selection_price'), - $values, - array('selection_price_type', 'selection_price_value') - ); - } - } } diff --git a/app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php b/app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php index f6f7a30aa7..fdce3aeb2f 100644 --- a/app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php +++ b/app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,102 +32,6 @@ * @package Mage_Bundle * @author Magento Core Team */ -class Mage_Bundle_Model_Mysql4_Selection_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Bundle_Model_Mysql4_Selection_Collection extends Mage_Bundle_Model_Resource_Selection_Collection { - protected $_selectionTable; - - /** - * Initialize collection - */ - protected function _construct() - { - parent::_construct(); - $this->setRowIdFieldName('selection_id'); - $this->_selectionTable = $this->getTable('bundle/selection'); - } - - /** - * Initialize collection select - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->getSelect()->join(array('selection' => $this->_selectionTable), - '`selection`.`product_id`=`e`.`entity_id`', - array('*') - ); - } - - /** - * Join website scope prices to collection, override default prices - * - * @return Mage_Bundle_Model_Mysql4_Selection_Collection - */ - public function joinPrices($websiteId) - { - $this->getSelect()->joinLeft(array('price' => $this->getTable('bundle/selection_price')), - 'selection.selection_id = price.selection_id AND price.website_id = ' . $websiteId, - array( - 'selection_price_type' => 'IFNULL(price.selection_price_type, selection.selection_price_type)', - 'selection_price_value' => 'IFNULL(price.selection_price_value, selection.selection_price_value)', - 'price_scope' => 'price.website_id' - ) - ); - return $this; - } - - /** - * Apply option ids filter to collection - * - * @return Mage_Bundle_Model_Mysql4_Selection_Collection - */ - public function setOptionIdsFilter($optionIds) - { - if (!empty($optionIds)) { - $this->getSelect()->where('`selection`.`option_id` in (' . join(',', (array)$optionIds) . ')'); - } - return $this; - } - - /** - * Apply selection ids filter to collection - * - * @return Mage_Bundle_Model_Mysql4_Selection_Collection - */ - public function setSelectionIdsFilter($selectionIds) - { - if (!empty($selectionIds)) { - $this->getSelect()->where('`selection`.`selection_id` in (' . join(',', (array)$selectionIds) . ')'); - } - return $this; - } - - /** - * Set position order - * - * @return Mage_Bundle_Model_Mysql4_Selection_Collection - */ - public function setPositionOrder() - { - $this->getSelect()->order('selection.position asc') - ->order('selection.selection_id asc'); - return $this; - } - - /** - * Set store id for each collection item when collection was loaded - * - * @return void - */ - public function _afterLoad() - { - parent::_afterLoad(); - if ($this->getStoreId() && $this->_items) { - foreach ($this->_items as $item) { - $item->setStoreId($this->getStoreId()); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Bundle/Model/Observer.php b/app/code/core/Mage/Bundle/Model/Observer.php index d463171bc9..72c95bd163 100644 --- a/app/code/core/Mage/Bundle/Model/Observer.php +++ b/app/code/core/Mage/Bundle/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Option.php b/app/code/core/Mage/Bundle/Model/Option.php index 334ba190dd..94cecda1e4 100644 --- a/app/code/core/Mage/Bundle/Model/Option.php +++ b/app/code/core/Mage/Bundle/Model/Option.php @@ -20,13 +20,24 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Bundle Option Model * + * @method Mage_Bundle_Model_Resource_Option _getResource() + * @method Mage_Bundle_Model_Resource_Option getResource() + * @method int getParentId() + * @method Mage_Bundle_Model_Option setParentId(int $value) + * @method int getRequired() + * @method Mage_Bundle_Model_Option setRequired(int $value) + * @method int getPosition() + * @method Mage_Bundle_Model_Option setPosition(int $value) + * @method string getType() + * @method Mage_Bundle_Model_Option setType(string $value) + * * @category Mage * @package Mage_Bundle * @author Magento Core Team diff --git a/app/code/core/Mage/Bundle/Model/Price/Index.php b/app/code/core/Mage/Bundle/Model/Price/Index.php index 1cdeb7bc42..40315f48c2 100644 --- a/app/code/core/Mage/Bundle/Model/Price/Index.php +++ b/app/code/core/Mage/Bundle/Model/Price/Index.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,11 +28,21 @@ /** * Bundle Product Price Index * + * @method Mage_Bundle_Model_Resource_Price_Index _getResource() + * @method Mage_Bundle_Model_Resource_Price_Index getResource() + * @method Mage_Bundle_Model_Price_Index setEntityId(int $value) + * @method int getWebsiteId() + * @method Mage_Bundle_Model_Price_Index setWebsiteId(int $value) + * @method int getCustomerGroupId() + * @method Mage_Bundle_Model_Price_Index setCustomerGroupId(int $value) + * @method float getMinPrice() + * @method Mage_Bundle_Model_Price_Index setMinPrice(float $value) + * @method float getMaxPrice() + * @method Mage_Bundle_Model_Price_Index setMaxPrice(float $value) + * * @category Mage * @package Mage_Bundle * @author Magento Core Team - * @deprecated since 1.4.0.0 - * @see Mage_Bundle_Model_Mysql4_Indexer_Price */ class Mage_Bundle_Model_Price_Index extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php b/app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php index 9cb5385ae6..dab13fc1da 100644 --- a/app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php +++ b/app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -77,11 +77,12 @@ public function getFlatColums() { $columns = array(); $columns[$this->getAttribute()->getAttributeCode()] = array( - 'type' => 'int', + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => 'Bundle Price View ' . $this->getAttribute()->getAttributeCode(). ' column' ); return $columns; } diff --git a/app/code/core/Mage/Bundle/Model/Product/Price.php b/app/code/core/Mage/Bundle/Model/Product/Price.php index c960fc21f7..63dde5d5ce 100644 --- a/app/code/core/Mage/Bundle/Model/Product/Price.php +++ b/app/code/core/Mage/Bundle/Model/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -38,21 +38,21 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr /** * Flag wich indicates - is min/max prices have been calculated by index - * + * * @var bool */ protected $_isPricesCalculatedByIndex; /** * Is min/max prices have been calculated by index - * + * * @return bool */ public function getIsPricesCalculatedByIndex() { return $this->_isPricesCalculatedByIndex; - } - + } + /** * Return product base price * @@ -81,7 +81,6 @@ public function getFinalPrice($qty=null, $product) } $finalPrice = $product->getPrice(); - $basePrice = $finalPrice; /** * Just product with fixed price calculation has price @@ -98,7 +97,6 @@ public function getFinalPrice($qty=null, $product) $basePrice = $finalPrice; if ($product->hasCustomOptions()) { - $customOption = $product->getCustomOption('bundle_option_ids'); $customOption = $product->getCustomOption('bundle_selection_ids'); $selectionIds = unserialize($customOption->getValue()); $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product); @@ -111,25 +109,11 @@ public function getFinalPrice($qty=null, $product) if ($selection->isSalable()) { $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId()); if ($selectionQty) { - $finalPrice = $finalPrice + $this->getSelectionFinalPrice($product, $selection, $qty, $selectionQty->getValue()); + $finalPrice += $this->getSelectionFinalPrice($product, $selection, $qty, + $selectionQty->getValue()); } } } - } else { -// if ($options = $this->getOptions($product)) { -// /* some strange thing -// foreach ($options as $option) { -// $selectionCount = count($option->getSelections()); -// if ($selectionCount) { -// foreach ($option->getSelections() as $selection) { -// if ($selection->isSalable() && ($selection->getIsDefault() || ($option->getRequired() &&)) { -// $finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection); -// } -// } -// } -// } -// */ -// } } $finalPrice = $finalPrice + $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice; @@ -146,27 +130,48 @@ public function getChildFinalPrice($product, $productQty, $childProduct, $childP /** * Retrieve Price * - * @param unknown_type $product - * @param unknown_type $which - * @return unknown + * @deprecated after 1.10.1.1 + * @see Mage_Bundle_Model_Product_Price::getPricesTierPrice() + * + * @param Mage_Catalog_Model_Product $product + * @param string $which + * @return decimal|array */ public function getPrices($product, $which = null) { - return $this->getPricesDependingOnTax($product, $which); + return $this->getPricesTierPrice($product, $which); } /** * Retrieve Prices depending on tax * - * @param unknown_type $product - * @param unknown_type $which - * @return unknown + * @deprecated after 1.10.1.1 + * @see Mage_Bundle_Model_Product_Price::getPricesTierPrice() + * + * @param Mage_Catalog_Model_Product $product + * @param string $which + * @param bool|null $includeTax + * @return decimal|array */ public function getPricesDependingOnTax($product, $which = null, $includeTax = null) + { + return $this->getPricesTierPrice($product, $which, $includeTax); + } + + /** + * Retrieve Price + * with take into account tier price + * + * @param Mage_Catalog_Model_Product $product + * @param string $which + * @param bool|null $includeTax + * @param bool $takeTierPrice + * @return decimal|array + */ + public function getPricesTierPrice($product, $which = null, $includeTax = null, $takeTierPrice = true) { // check calculated price index - if ($product->getData('min_price') && - $product->getData('max_price')) { + if ($product->getData('min_price') && $product->getData('max_price')) { $minimalPrice = Mage::helper('tax')->getPrice($product, $product->getData('min_price'), $includeTax); $maximalPrice = Mage::helper('tax')->getPrice($product, $product->getData('max_price'), $includeTax); $this->_isPricesCalculatedByIndex = true; @@ -206,8 +211,18 @@ public function getPricesDependingOnTax($product, $which = null, $includeTax = n $qty = min(1, $qty); } - $selectionMinimalPrices[] = Mage::helper('tax')->getPrice($selection, $this->getSelectionFinalPrice($product, $selection, 1, $qty), $includeTax); - $selectionMaximalPrices[] = Mage::helper('tax')->getPrice($selection, $this->getSelectionFinalPrice($product, $selection, 1), $includeTax); + $selectionMinimalPrices[] = Mage::helper('tax')->getPrice( + $selection, + $this->getSelectionFinalPriceTierPrice($product, $selection, 1, $qty, $takeTierPrice), + $includeTax, + $takeTierPrice + ); + $selectionMaximalPrices[] = Mage::helper('tax')->getPrice( + $selection, + $this->getSelectionFinalPriceTierPrice($product, $selection, 1, null, $takeTierPrice), + $includeTax, + $takeTierPrice + ); } if (count($selectionMinimalPrices)) { @@ -217,7 +232,9 @@ public function getPricesDependingOnTax($product, $which = null, $includeTax = n $minPriceFounded = true; } elseif (true !== $minPriceFounded) { $selMinPrice += $minimalPrice; - $minPriceFounded = false === $minPriceFounded ? $selMinPrice : min($minPriceFounded, $selMinPrice); + $minPriceFounded = (false === $minPriceFounded) + ? $selMinPrice + : min($minPriceFounded, $selMinPrice); } if ($option->isMultiSelection()) { @@ -230,7 +247,7 @@ public function getPricesDependingOnTax($product, $which = null, $includeTax = n } } // condition is TRUE when all product options are NOT required - if (! is_bool($minPriceFounded)) { + if (!is_bool($minPriceFounded)) { $minimalPrice = $minPriceFounded; } @@ -257,10 +274,10 @@ public function getPricesDependingOnTax($product, $which = null, $includeTax = n Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX, Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE ); - + if (in_array($customOption->getType(), $multiTypes)) { $maximalValue = array_sum($prices); - } else { + } else { $maximalValue = max($prices); } $maximalPrice += Mage::helper('tax')->getPrice($product, $maximalValue, $includeTax); @@ -290,12 +307,12 @@ public function getPricesDependingOnTax($product, $which = null, $includeTax = n /** * Calculate Minimal price of bundle (counting all required options) * - * @param Mage_Catalog_Model_Product $product + * @param Mage_Catalog_Model_Product $product * @return decimal */ public function getMinimalPrice($product) { - return $this->getPrices($product, 'min'); + return $this->getPricesTierPrice($product, 'min'); } /** @@ -306,7 +323,7 @@ public function getMinimalPrice($product) */ public function getMaximalPrice($product) { - return $this->getPrices($product, 'max'); + return $this->getPricesTierPrice($product, 'max'); } /** @@ -372,29 +389,56 @@ public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQ */ public function getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qty = null) { - return $this->_applySpecialPrice($bundleProduct, $this->getSelectionPrice($bundleProduct, $selectionProduct, $qty)); + return $this->_applySpecialPrice( + $bundleProduct, + $this->getSelectionPrice($bundleProduct, $selectionProduct, $qty) + ); } + /** + * Calculate final price of selection + * + * @param Mage_Catalog_Model_Product $bundleProduct + * @param Mage_Catalog_Model_Product $selectionProduct + * @param decimal $bundleQty + * @param decimal $selectionQty + * @param bool $multiplyQty + * @return decimal + */ + public function getSelectionFinalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty = null, + $multiplyQty = true) + { + return $this->getSelectionFinalPriceTierPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty, + $multiplyQty); + } /** * Calculate final price of selection + * with take into account tier price * - * @param Mage_Catalog_Model_Product $bundleProduct - * @param Mage_Catalog_Model_Product $selectionProduct - * @param decimal $bundleQty - * @param decimal $selectionQty + * @param Mage_Catalog_Model_Product $bundleProduct + * @param Mage_Catalog_Model_Product $selectionProduct + * @param decimal $bundleQty + * @param decimal $selectionQty + * @param bool $multiplyQty + * @param bool $takeTierPrice * @return decimal */ - public function getSelectionFinalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty = null, $multiplyQty = true) + public function getSelectionFinalPriceTierPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty, + $multiplyQty = true, $takeTierPrice = true) { $selectionPrice = $this->getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty, $multiplyQty); - // apply bundle tier price - $tierPrice = $this->_applyTierPrice($bundleProduct, $bundleQty, $selectionPrice); // apply bundle special price $specialPrice = $this->_applySpecialPrice($bundleProduct, $selectionPrice); - return min(array($tierPrice, $specialPrice)); + if ($takeTierPrice) { + // apply bundle tier price + $tierPrice = $this->_applyTierPrice($bundleProduct, $bundleQty, $selectionPrice); + return min(array($tierPrice, $specialPrice)); + } else { + return $specialPrice; + } } /** @@ -417,6 +461,7 @@ protected function _applyTierPrice($product, $qty, $finalPrice) $tierPrice = $finalPrice - ($finalPrice * ($tierPrice / 100)); $finalPrice = min($finalPrice, $tierPrice); } + return $finalPrice; } @@ -447,7 +492,7 @@ public function getTierPrice($qty=null, $product) 'price' => $product->getPrice(), 'website_price' => $product->getPrice(), 'price_qty' => 1, - 'cust_group' => $allGroups, + 'cust_group' => $allGroups )); } @@ -518,11 +563,12 @@ public function getTierPrice($qty=null, $product) * @param null|int $productId * @return float */ - public static function calculatePrice($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $rulePrice = false, $wId = null, $gId = null, $productId = null) + public static function calculatePrice($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, + $rulePrice = false, $wId = null, $gId = null, $productId = null) { $resource = Mage::getResourceSingleton('bundle/bundle'); $selectionResource = Mage::getResourceSingleton('bundle/selection'); - $productPriceTypeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price_type'); + $productPriceTypeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price_type'); if ($wId instanceof Mage_Core_Model_Store) { $store = $wId->getId(); @@ -530,7 +576,6 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr } else { $store = Mage::app()->getStore($wId)->getId(); $wId = Mage::app()->getStore($wId)->getWebsiteId(); - //$store = Mage::app()->getWebsite($wId)->getDefaultGroup()->getDefaultStoreId(); } if (!$gId) { @@ -555,13 +600,16 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr continue; } - if ($result['selection_can_change_qty'] && $result['type'] != 'multi' && $result['type'] != 'checkbox') { + if ($result['selection_can_change_qty'] && $result['type'] != 'multi' + && $result['type'] != 'checkbox' + ) { $qty = 1; } else { $qty = $result['selection_qty']; } - $result['final_price'] = $selectionResource->getPriceFromIndex($result['product_id'], $qty, $store, $gId); + $result['final_price'] = $selectionResource->getPriceFromIndex($result['product_id'], $qty, $store, + $gId); $selectionPrice = $result['final_price']*$qty; @@ -572,8 +620,7 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr } } $basePrice = array_sum($options); - } - else { //fixed + } else { foreach ($results as $result) { if (!$result['product_id']) { continue; @@ -584,7 +631,9 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr $selectionPrice = $result['selection_price_value']; } - if ($result['selection_can_change_qty'] && $result['type'] != 'multi' && $result['type'] != 'checkbox') { + if ($result['selection_can_change_qty'] && $result['type'] != 'multi' + && $result['type'] != 'checkbox' + ) { $qty = 1; } else { $qty = $result['selection_qty']; @@ -602,7 +651,8 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr $basePrice = $basePrice + array_sum($options); } - $finalPrice = self::calculateSpecialPrice($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $store); + $finalPrice = self::calculateSpecialPrice($basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, + $store); /** * adding customer defined options price @@ -628,7 +678,8 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr } if ($rulePrice === false) { - $rulePrice = Mage::getResourceModel('catalogrule/rule')->getRulePrice(Mage::app()->getLocale()->storeTimeStamp($store), $wId, $gId, $productId); + $rulePrice = Mage::getResourceModel('catalogrule/rule') + ->getRulePrice(Mage::app()->getLocale()->storeTimeStamp($store), $wId, $gId, $productId); } if ($rulePrice !== null && $rulePrice !== false) { @@ -650,7 +701,8 @@ public static function calculatePrice($basePrice, $specialPrice, $specialPriceFr * @param mixed $store * @return float */ - public static function calculateSpecialPrice($finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $store = null) + public static function calculateSpecialPrice($finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, + $store = null) { if (!is_null($specialPrice) && $specialPrice != false) { if (Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) { @@ -658,6 +710,7 @@ public static function calculateSpecialPrice($finalPrice, $specialPrice, $specia $finalPrice = min($finalPrice, $specialPrice); } } + return $finalPrice; } @@ -670,22 +723,4 @@ public function isTierPriceFixed() { return false; } - - /* - public function getCustomOptionPrices($productId, $storeId, $which = null) { - - $optionsCollection = Mage::getResourceModel('catalog/product_option_collection') - ->addProductToFilter($productId) - ->; - - if (is_null($which)) { - return array($minimalPrice, $maximalPrice); - } else if ($which = 'max') { - return $maximalPrice; - } else if ($which = 'min') { - return $minimalPrice; - } - return 0; - } - */ } diff --git a/app/code/core/Mage/Bundle/Model/Product/Type.php b/app/code/core/Mage/Bundle/Model/Product/Type.php index 928693fd20..8470d7e5fe 100644 --- a/app/code/core/Mage/Bundle/Model/Product/Type.php +++ b/app/code/core/Mage/Bundle/Model/Product/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Resource/Bundle.php b/app/code/core/Mage/Bundle/Model/Resource/Bundle.php new file mode 100755 index 0000000000..92d9c0053d --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Bundle.php @@ -0,0 +1,125 @@ + + */ +class Mage_Bundle_Model_Resource_Bundle extends Mage_CatalogIndex_Model_Resource_Data_Abstract +{ + /** + * Preparing select for getting selection's raw data by product id + * also can be specified extra parameter for limit which columns should be selected + * + * @param int $productId + * @param array $columns + * @return Zend_DB_Select + */ + protected function _getSelect($productId, $columns = array()) + { + return $this->_getReadAdapter()->select() + ->from(array("bundle_option" => $this->getTable('bundle/option')), array('type', 'option_id')) + ->where("bundle_option.parent_id = ?", $productId) + ->where("bundle_option.required = 1") + ->joinLeft(array( + "bundle_selection" => $this->getTable('bundle/selection')), + "bundle_selection.option_id = bundle_option.option_id", + $columns + ); + } + + /** + * Retrieve selection data for specified product id + * + * @param int $productId + * @return array + */ + public function getSelectionsData($productId) + { + return $this->_getReadAdapter()->fetchAll($this->_getSelect( + $productId, + array("*") + )); + } + + /** + * Removing all quote items for specified product + * + * @param int $productId + */ + public function dropAllQuoteChildItems($productId) + { + $quoteItemIds = $this->_getReadAdapter()->fetchCol( + $this->_getReadAdapter()->select() + ->from($this->getTable('sales/quote_item'), array('item_id')) + ->where('product_id = :product_id'), + array('product_id' => $productId) + ); + if ($quoteItemIds) { + $this->_getWriteAdapter()->delete( + $this->getTable('sales/quote_item'), + array('parent_item_id IN(?)' => $quoteItemIds) + ); + } + } + + /** + * Removes specified selections by ids for specified product id + * + * @param int $productId + * @param array $ids + */ + public function dropAllUnneededSelections($productId, $ids) + { + $where = array( + 'parent_product_id = ?' => $productId + ); + if (!empty($ids)) { + $where['selection_id NOT IN (?) '] = $ids; + } + $this->_getWriteAdapter() + ->delete($this->getTable('bundle/selection'), $where); + } + + /** + * Save product relations + * + * @param int $parentId + * @param array $childIds + * @return Mage_Bundle_Model_Resource_Bundle + */ + public function saveProductRelations($parentId, $childIds) + { + Mage::getResourceSingleton('catalog/product_relation') + ->processRelations($parentId, $childIds); + + return $this; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php b/app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php new file mode 100755 index 0000000000..95532731e0 --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php @@ -0,0 +1,557 @@ + + */ +class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default +{ + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareBundlePrice(); + + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + public function reindexEntity($entityIds) + { + $this->_prepareBundlePrice($entityIds); + + return $this; + } + + /** + * Retrieve temporary price index table name for fixed bundle products + * + * @return string + */ + protected function _getBundlePriceTable() + { + if ($this->useIdxTable()) { + return $this->getTable('bundle/price_indexer_idx'); + } + return $this->getTable('bundle/price_indexer_tmp'); + } + + /** + * Retrieve table name for temporary bundle selection prices index + * + * @return string + */ + protected function _getBundleSelectionTable() + { + if ($this->useIdxTable()) { + return $this->getTable('bundle/selection_indexer_idx'); + } + return $this->getTable('bundle/selection_indexer_tmp'); + } + + /** + * Retrieve table name for temporary bundle option prices index + * + * @return string + */ + protected function _getBundleOptionTable() + { + if ($this->useIdxTable()) { + return $this->getTable('bundle/option_indexer_idx'); + } + return $this->getTable('bundle/option_indexer_tmp'); + } + + /** + * Prepare temporary price index table for fixed bundle products + * + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareBundlePriceTable() + { + $this->_getWriteAdapter()->delete($this->_getBundlePriceTable()); + return $this; + } + + /** + * Prepare table structure for temporary bundle selection prices index + * + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareBundleSelectionTable() + { + $this->_getWriteAdapter()->delete($this->_getBundleSelectionTable()); + return $this; + } + + /** + * Prepare table structure for temporary bundle option prices index + * + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareBundleOptionTable() + { + $this->_getWriteAdapter()->delete($this->_getBundleOptionTable()); + return $this; + } + + /** + * Prepare temporary price index data for bundle products by price type + * + * @param int $priceType + * @param int|array $entityIds the entity ids limitatation + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareBundlePriceByType($priceType, $entityIds = null) + { + $write = $this->_getWriteAdapter(); + $table = $this->_getBundlePriceTable(); + + $select = $write->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) + ->join( + array('cg' => $this->getTable('customer/customer_group')), + '', + array('customer_group_id') + ); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $select->columns('website_id', 'cw') + ->join( + array('cwd' => $this->_getWebsiteDateTable()), + 'cw.website_id = cwd.website_id', + array() + ) + ->joinLeft( + array('tp' => $this->_getTierPriceIndexTable()), + 'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id' + . ' AND tp.customer_group_id = cg.customer_group_id', + array() + ) + ->where('e.type_id=?', $this->getTypeId()); + + // add enable products limitation + $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true); + if (Mage::helper('core')->isModuleEnabled('Mage_Tax')) { + $taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id'); + } else { + $taxClassId = new Zend_Db_Expr('0'); + } + + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { + $select->columns(array('tax_class_id' => new Zend_Db_Expr('0'))); + } else { + $select->columns(array('tax_class_id' => $write->getCheckSql($taxClassId . ' IS NOT NULL', $taxClassId, 0))); + } + + $priceTypeCond = $write->quoteInto('=?', $priceType); + $this->_addAttributeToSelect($select, 'price_type', 'e.entity_id', 'cs.store_id', $priceTypeCond); + + $price = $this->_addAttributeToSelect($select, 'price', 'e.entity_id', 'cs.store_id'); + $specialPrice = $this->_addAttributeToSelect($select, 'special_price', 'e.entity_id', 'cs.store_id'); + $specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', 'e.entity_id', 'cs.store_id'); + $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id'); + $curentDate = new Zend_Db_Expr('cwd.website_date'); + + + $specialExpr = $write->getCheckSql( + $write->getCheckSql( + $specialFrom . ' IS NULL', + '1', + $write->getCheckSql( + $specialFrom . ' <= ' . $curentDate, + '1', + '0' + ) + ) . " > 0 AND ". + $write->getCheckSql( + $specialTo . ' IS NULL', + '1', + $write->getCheckSql( + $specialTo . ' >= ' . $curentDate, + '1', + '0' + ) + ) + . " > 0 AND {$specialPrice} > 0 ", + $specialPrice, + '0' + ); + $tierExpr = new Zend_Db_Expr("tp.min_price"); + + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { + $finalPrice = $write->getCheckSql( + $specialExpr . ' > 0', + 'ROUND(' . $price . ' * (' . $specialExpr . ' / 100), 4)', + $price + ); + $tierPrice = $write->getCheckSql( + $tierExpr . ' IS NOT NULL', + 'ROUND(' . $price .' - ' . '(' . $price . ' * (' . $tierExpr . ' / 100)), 4)', + 'NULL' + ); + } else { + $finalPrice = new Zend_Db_Expr("0"); + $tierPrice = $write->getCheckSql($tierExpr . ' IS NOT NULL', '0', 'NULL'); + } + + $select->columns(array( + 'price_type' => new Zend_Db_Expr($priceType), + 'special_price' => $specialExpr, + 'tier_percent' => $tierExpr, + 'orig_price' => $write->getCheckSql($price . ' IS NULL', '0', $price), + 'price' => $finalPrice, + 'min_price' => $finalPrice, + 'max_price' => $finalPrice, + 'tier_price' => $tierPrice, + 'base_tier' => $tierPrice, + )); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('catalog_product_prepare_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('e.entity_id'), + 'website_field' => new Zend_Db_Expr('cw.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $query = $select->insertFromSelect($table); + $write->query($query); + + return $this; + } + + /** + * Calculate fixed bundle product selections price + * + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _calculateBundleOptionPrice() + { + $write = $this->_getWriteAdapter(); + + $this->_prepareBundleSelectionTable(); + $this->_calculateBundleSelectionPrice(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED); + $this->_calculateBundleSelectionPrice(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC); + + $this->_prepareBundleOptionTable(); + + $select = $write->select() + ->from( + array('i' => $this->_getBundleSelectionTable()), + array('entity_id', 'customer_group_id', 'website_id', 'option_id') + ) + ->group(array('entity_id', 'customer_group_id', 'website_id', 'option_id', 'is_required', 'group_type')) + ->columns(array( + 'min_price' => $write->getCheckSql('i.is_required = 1', 'MIN(i.price)', '0'), + 'alt_price' => $write->getCheckSql('i.is_required = 0', 'MIN(i.price)', '0'), + 'max_price' => $write->getCheckSql('i.group_type = 1', 'SUM(i.price)', 'MAX(i.price)'), + 'tier_price' => $write->getCheckSql('i.is_required = 1', 'MIN(i.tier_price)', '0'), + 'alt_tier_price' => $write->getCheckSql('i.is_required = 0', 'MIN(i.tier_price)', '0'), + )); + + $query = $select->insertFromSelect($this->_getBundleOptionTable()); + $write->query($query); + + $this->_prepareDefaultFinalPriceTable(); + + $minPrice = new Zend_Db_Expr($write->getCheckSql( + 'SUM(io.min_price) = 0', + 'MIN(io.alt_price)', + 'SUM(io.min_price)' + ) . ' + i.price'); + $maxPrice = new Zend_Db_Expr("SUM(io.max_price) + i.price"); + $tierPrice = $write->getCheckSql( + 'MIN(i.tier_percent) IS NOT NULL', + $write->getCheckSql( + 'SUM(io.tier_price) = 0', + 'SUM(io.alt_tier_price)', + 'SUM(io.tier_price)' + ) . ' + MIN(i.tier_price)', + 'NULL' + ); + + $select = $write->select() + ->from( + array('io' => $this->_getBundleOptionTable()), + array('entity_id', 'customer_group_id', 'website_id') + ) + ->join( + array('i' => $this->_getBundlePriceTable()), + 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' + . ' AND i.website_id = io.website_id', + array() + ) + ->group(array('io.entity_id', 'io.customer_group_id', 'io.website_id', + 'i.tax_class_id', 'i.orig_price', 'i.price')) + ->columns(array('i.tax_class_id', + 'orig_price' => 'i.orig_price', + 'price' => 'i.price', + 'min_price' => $minPrice, + 'max_price' => $maxPrice, + 'tier_price' => $tierPrice, + 'base_tier' => 'MIN(i.base_tier)' + )); + + $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable()); + $write->query($query); + + return $this; + } + + /** + * Calculate bundle product selections price by product type + * + * @param int $priceType + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _calculateBundleSelectionPrice($priceType) + { + $write = $this->_getWriteAdapter(); + + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { + + $selectionPriceValue = $write->getCheckSql( + 'bsp.selection_price_value IS NULL', + 'bs.selection_price_value', + 'bsp.selection_price_value' + ); + $selectionPriceType = $write->getCheckSql( + 'bsp.selection_price_type IS NULL', + 'bs.selection_price_type', + 'bsp.selection_price_type' + ); + $priceExpr = new Zend_Db_Expr( + $write->getCheckSql( + $selectionPriceType . ' = 1', + 'ROUND(i.price * (' . $selectionPriceValue . ' / 100),4)', + $write->getCheckSql( + 'i.special_price > 0', + 'ROUND(' . $selectionPriceValue . ' * (i.special_price / 100),4)', + $selectionPriceValue + ) + ) . '* bs.selection_qty' + ); + + + $tierExpr = $write->getCheckSql( + 'i.base_tier IS NOT NULL', + $write->getCheckSql( + $selectionPriceType .' = 1', + 'ROUND(i.base_tier - (i.base_tier * (' . $selectionPriceValue . ' / 100)),4)', + $write->getCheckSql( + 'i.tier_percent > 0', + 'ROUND(' . $selectionPriceValue + . ' - (' . $selectionPriceValue . ' * (i.tier_percent / 100)),4)', + $selectionPriceValue + ) + ) . ' * bs.selection_qty', + 'NULL' + ); + } else { + $priceExpr = new Zend_Db_Expr( + $write->getCheckSql( + 'i.special_price > 0', + 'ROUND(idx.min_price * (i.special_price / 100), 4)', + 'idx.min_price' + ) . ' * bs.selection_qty' + ); + $tierExpr = $write->getCheckSql( + 'i.base_tier IS NOT NULL', + 'ROUND(idx.min_price * (i.base_tier / 100), 4)* bs.selection_qty', + 'NULL' + ); + + } + + $select = $write->select() + ->from( + array('i' => $this->_getBundlePriceTable()), + array('entity_id', 'customer_group_id', 'website_id') + ) + ->join( + array('bo' => $this->getTable('bundle/option')), + 'bo.parent_id = i.entity_id', + array('option_id') + ) + ->join( + array('bs' => $this->getTable('bundle/selection')), + 'bs.option_id = bo.option_id', + array('selection_id') + ) + ->joinLeft( + array('bsp' => $this->getTable('bundle/selection_price')), + 'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id', + array('') + ) + ->join( + array('idx' => $this->getIdxTable()), + 'bs.product_id = idx.entity_id AND i.customer_group_id = idx.customer_group_id' + . ' AND i.website_id = idx.website_id', + array() + ) + ->join( + array('e' => $this->getTable('catalog/product')), + 'bs.product_id = e.entity_id AND e.required_options=0', + array() + ) + ->where('i.price_type=?', $priceType) + ->columns(array( + 'group_type' => $write->getCheckSql( + "bo.type = 'select' OR bo.type = 'radio'", + '0', + '1' + ), + 'is_required' => 'bo.required', + 'price' => $priceExpr, + 'tier_price' => $tierExpr, + )); + + $query = $select->insertFromSelect($this->_getBundleSelectionTable()); + $write->query($query); + + return $this; + } + + /** + * Prepare temporary index price for bundle products + * + * @param int|array $entityIds the entity ids limitation + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareBundlePrice($entityIds = null) + { + $this->_prepareTierPriceIndex($entityIds); + $this->_prepareBundlePriceTable(); + $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED, $entityIds); + $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC, $entityIds); + + /** + * Add possibility modify prices from external events + */ + $select = $this->_getWriteAdapter()->select() + ->join(array('wd' => $this->_getWebsiteDateTable()), + 'i.website_id = wd.website_id', + array() + ); + Mage::dispatchEvent('prepare_catalog_product_price_index_table', array( + 'index_table' => array('i' => $this->_getBundlePriceTable()), + 'select' => $select, + 'entity_id' => 'i.entity_id', + 'customer_group_id' => 'i.customer_group_id', + 'website_id' => 'i.website_id', + 'website_date' => 'wd.website_date', + 'update_fields' => array('price', 'min_price', 'max_price') + )); + + $this->_calculateBundleOptionPrice(); + $this->_applyCustomOption(); + + $this->_movePriceDataToIndexTable(); + + return $this; + } + + /** + * Prepare percentage tier price for bundle products + * + * @see Mage_Catalog_Model_Resource_Product_Indexer_Price::_prepareTierPriceIndex + * + * @param int|array $entityIds + * @return Mage_Bundle_Model_Resource_Indexer_Price + */ + protected function _prepareTierPriceIndex($entityIds = null) + { + $adapter = $this->_getWriteAdapter(); + + // remove index by bundle products + $select = $adapter->select() + ->from(array('i' => $this->_getTierPriceIndexTable()), null) + ->join( + array('e' => $this->getTable('catalog/product')), + 'i.entity_id=e.entity_id', + array() + ) + ->where('e.type_id=?', $this->getTypeId()); + $query = $select->deleteFromSelect('i'); + $adapter->query($query); + + $select = $adapter->select() + ->from( + array('tp' => $this->getValueTable('catalog/product', 'tier_price')), + array('entity_id') + ) + ->join( + array('e' => $this->getTable('catalog/product')), + 'tp.entity_id=e.entity_id', + array() + ) + ->join( + array('cg' => $this->getTable('customer/customer_group')), + 'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)', + array('customer_group_id') + ) + ->join( + array('cw' => $this->getTable('core/website')), + 'tp.website_id = 0 OR tp.website_id = cw.website_id', + array('website_id') + ) + ->where('cw.website_id != 0') + ->where('e.type_id=?', $this->getTypeId()) + ->columns(new Zend_Db_Expr('MIN(tp.value)')) + ->group(array('tp.entity_id', 'cg.customer_group_id', 'cw.website_id')); + + if (!empty($entityIds)) { + $select->where('tp.entity_id IN(?)', $entityIds); + } + + $query = $select->insertFromSelect($this->_getTierPriceIndexTable()); + $adapter->query($query); + + return $this; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Indexer/Stock.php b/app/code/core/Mage/Bundle/Model/Resource/Indexer/Stock.php new file mode 100755 index 0000000000..094d1d0a4e --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Indexer/Stock.php @@ -0,0 +1,241 @@ + + */ +class Mage_Bundle_Model_Resource_Indexer_Stock extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default +{ + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareIndexTable(); + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + public function reindexEntity($entityIds) + { + $this->_updateIndex($entityIds); + + return $this; + } + + /** + * Retrieve table name for temporary bundle option stock index + * + * @return string + */ + protected function _getBundleOptionTable() + { + return $this->getTable('bundle/stock_index'); + } + + /** + * Prepare stock status per Bundle options, website and stock + * + * @param int|array $entityIds + * @param bool $usePrimaryTable use primary or temporary index table + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false) + { + $this->_cleanBundleOptionStockData(); + $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from(array('bo' => $this->getTable('bundle/option')), array('parent_id')); + $this->_addWebsiteJoinToSelect($select, false); + $status = new Zend_Db_Expr('MAX(' . + $adapter->getCheckSql('e.required_options = 0', 'i.stock_status', '0') . ')'); + $select->columns('website_id', 'cw') + ->join( + array('cis' => $this->getTable('cataloginventory/stock')), + '', + array('stock_id') + ) + ->joinLeft( + array('bs' => $this->getTable('bundle/selection')), + 'bs.option_id = bo.option_id', + array() + ) + ->joinLeft( + array('i' => $idxTable), + 'i.product_id = bs.product_id AND i.website_id = cw.website_id AND i.stock_id = cis.stock_id', + array() + ) + ->joinLeft( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = bs.product_id', + array() + ) + ->where('cw.website_id != 0') + ->group(array('bo.parent_id', 'cw.website_id', 'cis.stock_id', 'bo.option_id')) + ->columns(array( + 'option_id' => 'bo.option_id', + 'status' => $status + )); + + if (!is_null($entityIds)) { + $select->where('bo.parent_id IN(?)', $entityIds); + } + + // clone select for bundle product without required bundle options + $selectNonRequired = clone $select; + + $select->where('bo.required = ?', 1); + $selectNonRequired->where('bo.required = ?', 0) + ->having($status . ' = 1'); + $query = $select->insertFromSelect($this->_getBundleOptionTable()); + $adapter->query($query); + + $query = $selectNonRequired->insertFromSelect($this->_getBundleOptionTable()); + $adapter->query($query); + + return $this; + } + + /** + * Get the select object for get stock status by product ids + * + * @param int|array $entityIds + * @param bool $usePrimaryTable use primary or temporary index table + * @return Varien_Db_Select + */ + protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) + { + $this->_prepareBundleOptionStockData($entityIds, $usePrimaryTable); + + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $select->columns('cw.website_id') + ->join( + array('cis' => $this->getTable('cataloginventory/stock')), + '', + array('stock_id') + ) + ->joinLeft( + array('cisi' => $this->getTable('cataloginventory/stock_item')), + 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', + array() + ) + ->joinLeft( + array('o' => $this->_getBundleOptionTable()), + 'o.entity_id = e.entity_id AND o.website_id = cw.website_id AND o.stock_id = cis.stock_id', + array() + ) + ->columns(array('qty' => new Zend_Db_Expr('0'))) + ->where('cw.website_id != 0') + ->where('e.type_id = ?', $this->getTypeId()) + ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); + + // add limitation of status + $condition = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition); + + if ($this->_isManageStock()) { + $statusExpr = $adapter->getCheckSql( + 'cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0', + '1', + 'cisi.is_in_stock' + ); + } else { + $statusExpr = $adapter->getCheckSql( + 'cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1', + 'cisi.is_in_stock', + '1' + ); + } + + $select->columns(array('status' => $adapter->getLeastSql(array( + new Zend_Db_Expr('MIN(' . $adapter->getCheckSql('o.stock_status IS NOT NULL','o.stock_status', '0') .')'), + new Zend_Db_Expr('MIN(' . $statusExpr . ')'), + )))); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + return $select; + } + + /** + * Prepare stock status data in temporary index table + * + * @param int|array $entityIds the product limitation + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + protected function _prepareIndexTable($entityIds = null) + { + parent::_prepareIndexTable($entityIds); + $this->_cleanBundleOptionStockData(); + + return $this; + } + + /** + * Update Stock status index by product ids + * + * @param array|int $entityIds + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + protected function _updateIndex($entityIds) + { + parent::_updateIndex($entityIds); + $this->_cleanBundleOptionStockData(); + + return $this; + } + + /** + * Clean temporary bundle options stock data + * + * @return Mage_Bundle_Model_Resource_Indexer_Stock + */ + protected function _cleanBundleOptionStockData() + { + $this->_getWriteAdapter()->delete($this->_getBundleOptionTable()); + return $this; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Option.php b/app/code/core/Mage/Bundle/Model/Resource/Option.php new file mode 100755 index 0000000000..c8e4dbac58 --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Option.php @@ -0,0 +1,139 @@ + + */ +class Mage_Bundle_Model_Resource_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define resource + * + */ + protected function _construct() + { + $this->_init('bundle/option', 'option_id'); + } + + /** + * After save process + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Bundle_Model_Resource_Option + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + parent::_afterSave($object); + + $condition = array( + 'option_id = ?' => $object->getId(), + 'store_id = ? OR store_id = 0' => $object->getStoreId() + ); + + $write = $this->_getWriteAdapter(); + $write->delete($this->getTable('bundle/option_value'), $condition); + + $data = new Varien_Object(); + $data->setOptionId($object->getId()) + ->setStoreId($object->getStoreId()) + ->setTitle($object->getTitle()); + + $write->insert($this->getTable('bundle/option_value'), $data->getData()); + + /** + * also saving default value if this store view scope + */ + + if ($object->getStoreId()) { + $data->setStoreId(0); + $data->setTitle($object->getDefaultTitle()); + $write->insert($this->getTable('bundle/option_value'), $data->getData()); + } + + return $this; + } + + /** + * After delete process + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Bundle_Model_Resource_Option + */ + protected function _afterDelete(Mage_Core_Model_Abstract $object) + { + parent::_afterDelete($object); + + $this->_getWriteAdapter()->delete( + $this->getTable('bundle/option_value'), + array('option_id = ?' => $object->getId()) + ); + + return $this; + } + + /** + * Retrieve options searchable data + * + * @param int $productId + * @param int $storeId + * @return array + */ + public function getSearchableData($productId, $storeId) + { + $adapter = $this->_getReadAdapter(); + + $title = $adapter->getCheckSql('option_title_store.title IS NOT NULL', + 'option_title_store.title', + 'option_title_default.title' + ); + $bind = array( + 'store_id' => $storeId, + 'product_id' => $productId + ); + $select = $adapter->select() + ->from(array('opt' => $this->getMainTable()), array()) + ->join( + array('option_title_default' => $this->getTable('bundle/option_value')), + 'option_title_default.option_id = opt.option_id AND option_title_default.store_id = 0', + array() + ) + ->joinLeft( + array('option_title_store' => $this->getTable('bundle/option_value')), + 'option_title_store.option_id = opt.option_id AND option_title_store.store_id = :store_id', + array('title' => $title) + ) + ->where('opt.parent_id=:product_id'); + if (!$searchData = $adapter->fetchCol($select, $bind)) { + $searchData = array(); + } + return $searchData; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Option/Collection.php b/app/code/core/Mage/Bundle/Model/Resource/Option/Collection.php new file mode 100755 index 0000000000..9dacb3436e --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Option/Collection.php @@ -0,0 +1,206 @@ + + */ +class Mage_Bundle_Model_Resource_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * All item ids cache + * + * @var array + */ + protected $_itemIds; + + /** + * True when selections a + * + * @var bool + */ + protected $_selectionsAppended = false; + + /** + * Init model and resource model + * + */ + protected function _construct() + { + $this->_init('bundle/option'); + } + + /** + * Joins values to options + * + * @param int $storeId + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + public function joinValues($storeId) + { + $this->getSelect() + ->joinLeft( + array('option_value_default' => $this->getTable('bundle/option_value')), + 'main_table.option_id = option_value_default.option_id and option_value_default.store_id = 0', + array() + ) + ->columns(array('default_title' => 'option_value_default.title')); + + $title = $this->getConnection()->getCheckSql( + 'option_value.title IS NOT NULL', + 'option_value.title', + 'option_value_default.title' + ); + if ($storeId !== null) { + $this->getSelect() + ->columns(array('title' => $title)) + ->joinLeft(array('option_value' => $this->getTable('bundle/option_value')), + $this->getConnection()->quoteInto( + 'main_table.option_id = option_value.option_id and option_value.store_id = ?', + $storeId + ), + array() + ); + } + return $this; + } + + /** + * Sets product id filter + * + * @param int $productId + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + public function setProductIdFilter($productId) + { + $this->addFieldToFilter('main_table.parent_id', $productId); + return $this; + } + + /** + * Sets order by position + * + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + public function setPositionOrder() + { + $this->getSelect()->order('main_table.position asc') + ->order('main_table.option_id asc'); + return $this; + } + + /** + * Append selection to options + * stripBefore - indicates to reload + * appendAll - indicates do we need to filter by saleable and required custom options + * + * @param Mage_Bundle_Model_Resource_Selection_Collection $selectionsCollection + * @param bool $stripBefore + * @param bool $appendAll + * @return array + */ + public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true) + { + if ($stripBefore) { + $this->_stripSelections(); + } + + if (!$this->_selectionsAppended) { + foreach ($selectionsCollection->getItems() as $key => $_selection) { + if ($_option = $this->getItemById($_selection->getOptionId())) { + if ($appendAll || ($_selection->isSalable() && !$_selection->getRequiredOptions())) { + $_selection->setOption($_option); + $_option->addSelection($_selection); + } else { + $selectionsCollection->removeItemByKey($key); + } + } + } + $this->_selectionsAppended = true; + } + + return $this->getItems(); + } + + /** + * Removes appended selections before + * + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + protected function _stripSelections() + { + foreach ($this->getItems() as $option) { + $option->setSelections(array()); + } + $this->_selectionsAppended = false; + return $this; + } + + /** + * Sets filter by option id + * + * @param array|int $ids + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + public function setIdFilter($ids) + { + if (is_array($ids)) { + $this->addFieldToFilter('main_table.option_id', array('in' => $ids)); + } else if ($ids != '') { + $this->addFieldToFilter('main_table.option_id', $ids); + } + return $this; + } + + /** + * Reset all item ids cache + * + * @return Mage_Bundle_Model_Resource_Option_Collection + */ + public function resetAllIds() + { + $this->_itemIds = null; + return $this; + } + + /** + * Retrive all ids for collection + * + * @return array + */ + public function getAllIds() + { + if (is_null($this->_itemIds)) { + $this->_itemIds = parent::getAllIds(); + } + return $this->_itemIds; + } +} + diff --git a/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php b/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php new file mode 100755 index 0000000000..b520f9a78a --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Price/Index.php @@ -0,0 +1,856 @@ + + */ +class Mage_Bundle_Model_Resource_Price_Index extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * EAV attributes cache + * + * @var array + */ + protected $_attributes = array(); + + /** + * Websites cache + * + * @var array + */ + protected $_websites; + + /** + * Customer Groups cache + * + * @var array + */ + protected $_customerGroups; + + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('bundle/price_index', 'entity_id'); + } + + /** + * Retrieve attribute object + * + * @param string $attributeCode + * @return Mage_Catalog_Model_Resource_Eav_Attribute + */ + protected function _getAttribute($attributeCode) + { + if (!isset($this->_attributes[$attributeCode])) { + $this->_attributes[$attributeCode] = Mage::getSingleton('catalog/config') + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); + } + return $this->_attributes[$attributeCode]; + } + + /** + * Retrieve websites collection array + * + * @return array + */ + protected function _getWebsites() + { + if (is_null($this->_websites)) { + $this->_websites = Mage::app()->getWebsites(false); + } + return $this->_websites; + } + + /** + * Retrieve customer groups collection array + * + * @return array + */ + protected function _getCustomerGroups() + { + if (is_null($this->_customerGroups)) { + $this->_customerGroups = array(); + foreach (Mage::getModel('customer/group')->getCollection() as $group) { + $this->_customerGroups[$group->getId()] = $group; + } + } + return $this->_customerGroups; + } + + /** + * Retrieve product ids array by product condition + * + * @param Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $product + * @param int $lastEntityId + * @param int $limit + * @return array + */ + public function getProducts($product = null, $lastEntityId = 0, $limit = 100) + { + + $select = $this->_getReadAdapter()->select() + ->from( + array('e' => $this->getTable('catalog/product')), + array('entity_id') + ) + ->where('e.type_id=?', Mage_Catalog_Model_Product_Type::TYPE_BUNDLE); + if ($product instanceof Mage_Catalog_Model_Product) { + $select->where('e.entity_id=?', $product->getId()); + } elseif ($product instanceof Mage_Catalog_Model_Product_Condition_Interface) { + $value = new Zend_Db_Expr($product->getIdsSelect($this->_getReadAdapter())); + $select->where('e.entity_id IN(?)', $value); + } elseif (is_numeric($product) || is_array($product)) { + $select->where('e.entity_id IN(?)', $product); + } + + $priceType = $this->_getAttribute('price_type'); + $priceTypeAlias = 't_' . $priceType->getAttributeCode(); + $joinConds = array( + $priceTypeAlias . '.attribute_id=:attribute_id', + $priceTypeAlias . '.store_id=0', + $priceTypeAlias . '.entity_id=e.entity_id' + ); + + $select->joinLeft( + array($priceTypeAlias => $priceType->getBackend()->getTable()), + join(' AND ', $joinConds), + array('price_type' => $priceTypeAlias . '.value') + ); + + $select->where('e.entity_id>:last_entity_id', $lastEntityId) + ->order('e.entity_id') + ->limit($limit); + $bind = array( + 'attribute_id' => $priceType->getAttributeId(), + 'last_entity_id' => $lastEntityId + ); + return $this->_getReadAdapter()->fetchPairs($select, $bind); + } + + /** + * Reindex Bundle product Price Index + * + * @param Mage_Core_Model_Product|Mage_Catalog_Model_Product_Condition_Interface|array|int $products + * @return Mage_Bundle_Model_Resource_Price_Index + */ + public function reindex($products = null) + { + $lastEntityId = 0; + while (true) { + $productsData = $this->getProducts($products, $lastEntityId); + if (!$productsData) { + break; + } + + foreach ($productsData as $productId => $priceType) { + $this->_reindexProduct($productId, $priceType); + $lastEntityId = $productId; + } + } + + return $this; + } + + /** + * Reindex product price + * + * @param int $productId + * @param int $priceType + * @return Mage_Bundle_Model_Resource_Price_Index + */ + protected function _reindexProduct($productId, $priceType) + { + $options = $this->getSelections($productId); + $selectionProducts = array(); + foreach ($options as $option) { + foreach ($option['selections'] as $selection) { + $selectionProducts[$selection['product_id']] = $selection['product_id']; + } + } + + $priceIndex = array(); + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { + // load selection product prices from index for dynamic bundle + $priceIndex = $this->getProductsPriceFromIndex($selectionProducts); + } + + foreach ($this->_getWebsites() as $website) { + if (!$website->getDefaultStore()) { + continue; + } + $salableStatus = $this->getProductsSalableStatus($selectionProducts, $website); + $priceData = $this->getProductsPriceData($productId, $website); + $priceData = $priceData[$productId]; + + /* @var $website Mage_Core_Model_Website */ + foreach ($this->_getCustomerGroups() as $group) { + /* @var $group Mage_Customer_Model_Group */ + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { + $basePrice = $this->_getBasePrice($productId, $priceData, $website, $group); + $customOptions = $this->getCustomOptions($productId, $website); + } elseif ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { + $basePrice = 0; + } + + list($minPrice, $maxPrice) = $this->_calculateBundleSelections($options, $salableStatus, + $productId, $priceType, $basePrice, $priceData, $priceIndex, $website, $group + ); + + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { + list($minPrice, $maxPrice) = + $this->_calculateCustomOptions($customOptions, $basePrice, $minPrice, $maxPrice); + } + + $this->_savePriceIndex($productId, $website->getId(), $group->getId(), $minPrice, $maxPrice); + } + } + + return $this; + } + + /** + * Save price index + * + * @param int $productId + * @param int $websiteId + * @param int $groupId + * @param float $minPrice + * @param float $maxPrice + * @return Mage_Bundle_Model_Resource_Price_Index + */ + protected function _savePriceIndex($productId, $websiteId, $groupId, $minPrice, $maxPrice) + { + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + $bind = array($productId, $websiteId, $groupId, $minPrice, $maxPrice); + $adapter->insertOnDuplicate($this->getMainTable(), $bind, array('min_price', 'max_price')); + $adapter->commit(); + + return $this; + } + + /** + * Retrieve bundle options with selections and prices by product + * + * @param int $productId + * @return array + */ + public function getSelections($productId) + { + $options = array(); + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from( + array('option_table' => $this->getTable('bundle/option')), + array('option_id', 'required', 'type') + ) + ->join( + array('selection_table' => $this->getTable('bundle/selection')), + 'selection_table.option_id=option_table.option_id', + array('selection_id', 'product_id', 'selection_price_type', + 'selection_price_value', 'selection_qty', 'selection_can_change_qty') + ) + ->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id=selection_table.product_id AND e.required_options=0', + array() + ) + ->where('option_table.parent_id=:product_id'); + + $query = $read->query($select, array('product_id' => $productId)); + while ($row = $query->fetch()) { + if (!isset($options[$row['option_id']])) { + $options[$row['option_id']] = array( + 'option_id' => $row['option_id'], + 'required' => $row['required'], + 'type' => $row['type'], + 'selections' => array() + ); + } + $options[$row['option_id']]['selections'][$row['selection_id']] = array( + 'selection_id' => $row['selection_id'], + 'product_id' => $row['product_id'], + 'price_type' => $row['selection_price_type'], + 'price_value' => $row['selection_price_value'], + 'qty' => $row['selection_qty'], + 'can_change_qty' => $row['selection_can_change_qty'] + ); + } + + return $options; + } + + /** + * Retrieve salable product statuses + * + * @param int|array $products + * @param Mage_Core_Model_Website $website + * @return array + */ + public function getProductsSalableStatus($products, Mage_Core_Model_Website $website) + { + $read = $this->_getReadAdapter(); + $productsData = array(); + $select = $read->select() + ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') + ->where('e.entity_id IN(?)', $products); + // add belong to website + $select->joinLeft( + array('pw' => $this->getTable('catalog/product_website')), + 'e.entity_id=pw.product_id AND pw.website_id=:website_id', + array('pw.website_id') + ); + + $store = $website->getDefaultStore(); + + // add product status + $status = $this->_getAttribute('status'); + if ($status->isScopeGlobal()) { + $select->join( + array('t_status' => $status->getBackend()->getTable()), + 'e.entity_id=t_status.entity_id' + . ' AND t_status.attribute_id=:status_attribute_id' + . ' AND t_status.store_id=0', + array('status' => 't_status.value') + ); + } else { + + $statusField = $read->getCheckSql( + 't2_status.value_id > 0', + 't2_status.value', + 't1_status.value' + ); + + $statusTable = $status->getBackend()->getTable(); + $select->join( + array('t1_status' => $statusTable), + 'e.entity_id=t1_status.entity_id' + . ' AND t1_status.attribute_id=:status_attribute_id' + . ' AND t1_status.store_id=0', + array('status' => $statusField) + ) + ->joinLeft( + array('t2_status' => $statusTable), + 't1_status.entity_id = t2_status.entity_id' + . ' AND t1_status.attribute_id = t2_status.attribute_id' + . ' AND t2_status.store_id=:store_id', + array() + ); + } + + $bind = array( + 'status_attribute_id' => $status->getAttributeId(), + 'website_id' => $website->getId(), + 'store_id' => $store->getId() + ); + + Mage::dispatchEvent('catalog_product_prepare_index_select', array( + 'website' => $website, + 'select' => $select, + 'bind' => $bind + )); + + $query = $read->query($select, $bind); + while ($row = $query->fetch()) { + $salable = isset($row['salable']) ? $row['salable'] : true; + $website = $row['website_id'] > 0 ? true : false; + $status = $row['status']; + + $productsData[$row['entity_id']] = $salable && $status && $website; + } + + return $productsData; + } + + /** + * Retrieve Selection Product price from Price Index + * Return index key {entity_id}-{website_id}-{customer_group_id} + * + * @param int|array $productIds + * @return array + */ + public function getProductsPriceFromIndex($productIds) + { + $price = $this->_getAttribute('price'); + $read = $this->_getReadAdapter(); + $key = $read->getConcatSql(array('entity_id', 'customer_group_id', 'website_id'), '-'); + + $select = $read->select() + ->from( + array('price_index' => $this->getTable('catalogindex/price')), + array('index_key' => $key, 'value') + ) + ->where('entity_id IN(?)', $productIds) + ->where('attribute_id= :attribute_id'); + $index = $read->fetchPairs($select, array('attribute_id' => $price->getAttributeId())); + return $index; + } + + /** + * Retrieve product(s) price data + * + * @param int|array $products + * @param Mage_Core_Model_Website $website + * @return array + */ + public function getProductsPriceData($products, Mage_Core_Model_Website $website) + { + $productsData = array(); + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') + ->where('e.entity_id IN(?)', $products); + + $this->_addAttributeDataToSelect($select, 'price', $website); + $this->_addAttributeDataToSelect($select, 'special_price', $website); + $this->_addAttributeDataToSelect($select, 'special_from_date', $website); + $this->_addAttributeDataToSelect($select, 'special_to_date', $website); + + $query = $read->query($select); + while ($row = $query->fetch()) { + $productsData[$row['entity_id']] = array( + 'price' => $row['price'], + 'special_price' => $row['special_price'], + 'special_from_date' => $row['special_from_date'], + 'special_to_date' => $row['special_to_date'] + ); + } + + return $productsData; + } + + /** + * Add attribute data to select + * + * @param Varien_Db_Select $select + * @param string $attributeCode + * @param Mage_Core_Model_Website $website + * @return Mage_Bundle_Model_Resource_Price_Index + */ + protected function _addAttributeDataToSelect(Varien_Db_Select $select, $attributeCode, + Mage_Core_Model_Website $website) + { + $attribute = $this->_getAttribute($attributeCode); + $store = $website->getDefaultStore(); + if ($attribute->isScopeGlobal()) { + $table = 't_' . $attribute->getAttributeCode(); + $select->joinLeft( + array($table => $attribute->getBackend()->getTable()), + "e.entity_id={$table}.entity_id" + . " AND {$table}.attribute_id={$attribute->getAttributeId()}" + . " AND {$table}.store_id=0", + array($attribute->getAttributeCode() => $table . '.value') + ); + } else { + $tableName = $attribute->getBackend()->getTable(); + $tableGlobal = 't1_' . $attribute->getAttributeCode(); + $tableStore = 't2_' . $attribute->getAttributeCode(); + + $attributeCond = $this->getReadConnection()->getCheckSql( + $tableStore . '.value_id > 0', + $tableStore . '.value', + $tableGlobal . '.value' + ); + $select->joinLeft( + array($tableGlobal => $tableName), + "e.entity_id = {$tableGlobal}.entity_id" + . " AND {$tableGlobal}.attribute_id = {$attribute->getAttributeId()}" + . " AND {$tableGlobal}.store_id = 0", + array($attribute->getAttributeCode() => $attributeCond) + ) + ->joinLeft( + array($tableStore => $tableName), + "{$tableGlobal}.entity_id = {$tableStore}.entity_id" + . " AND {$tableGlobal}.attribute_id = {$tableStore}.attribute_id" + . " AND {$tableStore}.store_id = " . $store->getId(), + array() + ); + } + return $this; + } + + /** + * Retrieve fixed bundle base price (with special price and rules) + * + * @param int $productId + * @param array $priceData + * @param Mage_Core_Model_Website $website + * @param Mage_Customer_Model_Group $customerGroup + * @return float + */ + protected function _getBasePrice($productId, array $priceData, $website, $customerGroup) + { + $store = $website->getDefaultStore(); + $storeTimeStamp = Mage::app()->getLocale()->storeTimeStamp($store); + $finalPrice = $this->_calculateSpecialPrice($priceData['price'], $priceData, $website); + + $rulePrice = Mage::getResourceModel('catalogrule/rule') + ->getRulePrice($storeTimeStamp, $website->getId(), $customerGroup->getId(), $productId); + + if ($rulePrice !== null && $rulePrice !== false) { + $finalPrice = min($finalPrice, $rulePrice); + } + + return $finalPrice; + } + + /** + * Retrieve custom options for product + * + * @param int $productId + * @param Mage_Core_Model_Website $website + * @return array + */ + public function getCustomOptions($productId, Mage_Core_Model_Website $website) + { + $options = array(); + $store = $website->getDefaultStore(); + $price = $this->_getAttribute('price'); + $adapter = $this->_getReadAdapter(); + + $bind = array( + ':product_id' => $productId, + ':store_id' => $store->getId(), + + ); + $select = $adapter->select() + ->from( + array('option_table' => $this->getTable('catalog/product_option')), + array('option_id', 'is_require', 'type') + ) + ->where('option_table.product_id=:product_id'); + + if ($price->isScopeGlobal()) { + $select->join( + array('price_table' => $this->getTable('catalog/product_option_price')), + 'option_table.option_id = price_table.option_id' . + ' AND price_table.store_id = 0', + array('value_id' => 'option_price_id', 'price', 'price_type') + ); + } else { + $valueIdCond = $adapter->getCheckSql( + 'price_store_table.option_price_id IS NOT NULL', + 'price_store_table.option_price_id', + 'price_global_table.option_price_id' + ); + $priceCond = $adapter->getCheckSql( + 'price_store_table.price IS NOT NULL', + 'price_store_table.price', + 'price_global_table.price' + ); + $priceTypeCond = $adapter->getCheckSql( + 'price_store_table.price_type IS NOT NULL', + 'price_store_table.price_type', + 'price_global_table.price_type' + ); + + $select + ->join( + array('price_global_table' => $this->getTable('catalog/product_option_price')), + 'option_table.option_id=price_global_table.option_id' . + ' AND price_global_table.store_id=0', + array( + 'value_id' => $valueIdCond, + 'price' => $priceCond, + 'price_type' => $priceTypeCond + )) + ->joinLeft( + array('price_store_table' => $this->getTable('catalog/product_option_price')), + 'option_table.option_id = price_store_table.option_id' . + ' AND price_store_table.store_id=:store_id', + array() + ); + } + + $query = $adapter->query($select, $bind); + while ($row = $query->fetch()) { + if (!isset($options[$row['option_id']])) { + $options[$row['option_id']] = array( + 'option_id' => $row['option_id'], + 'is_require' => $row['is_require'], + 'type' => $row['type'], + 'values' => array() + ); + } + $options[$row['option_id']]['values'][$row['value_id']] = array( + 'price_type' => $row['price_type'], + 'price_value' => $row['price'] + ); + } + + $select = $adapter->select() + ->from( + array('option_table' => $this->getTable('catalog/product_option')), + array('option_id', 'is_require', 'type') + ) + ->join( + array('type_table' => $this->getTable('catalog/product_option_type_value')), + 'option_table.option_id=type_table.option_id', + array() + ) + ->where('option_table.product_id=:product_id'); + + if ($price->isScopeGlobal()) { + $select->join( + array('price_table' => $this->getTable('catalog/product_option_type_price')), + 'type_table.option_type_id=price_table.option_type_id' . + ' AND price_table.store_id=0', + array('value_id' => 'option_type_id', 'price', 'price_type') + ); + } else { + $select + ->join( + array('price_global_table' => $this->getTable('catalog/product_option_type_price')), + 'type_table.option_type_id=price_global_table.option_type_id' . + ' AND price_global_table.store_id=0', + array( + 'value_id' => $valueIdCond, + 'price' => $priceCond, + 'price_type' => $priceTypeCond + ) + ) + ->joinLeft( + array('price_store_table' => $this->getTable('catalog/product_option_type_price')), + 'type_table.option_type_id=price_store_table.option_type_id' . + ' AND price_store_table.store_id=:store_id', + array() + ); + } + + $query = $adapter->query($select, $bind); + while ($row = $query->fetch()) { + if (!isset($options[$row['option_id']])) { + $options[$row['option_id']] = array( + 'option_id' => $row['option_id'], + 'is_require' => $row['is_require'], + 'type' => $row['type'], + 'values' => array() + ); + } + $options[$row['option_id']]['values'][$row['value_id']] = array( + 'price_type' => $row['price_type'], + 'price_value' => $row['price'] + ); + } + + return $options; + } + + /** + * Calculate custom options price + * Return array with indexes(0 -> min_price, 1 -> max_price) + * + * @param array $options + * @param float $basePrice + * @param float $minPrice + * @param float $maxPrice + * @return array + */ + public function _calculateCustomOptions(array $options, $basePrice, $minPrice, $maxPrice) + { + foreach ($options as $option) { + $optionPrices = array(); + foreach ($option['values'] as $value) { + if ($value['price_type'] == 'percent') { + $valuePrice = $basePrice * $value['price_value'] / 100; + } else { + $valuePrice = $value['price_value']; + } + $optionPrices[] = $valuePrice; + } + if ($option['is_require']) { + $minPrice += min($optionPrices); + } + $multiTypes = array( + Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN, + Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX, + Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE + ); + if ($optionPrices) { + if (in_array($option['type'], $multiTypes)) { + $maxPrice += array_sum($optionPrices); + } else { + $maxPrice += max($optionPrices); + } + } + } + + return array($minPrice, $maxPrice); + } + + /** + * Calculate minimal and maximal price for bundle selections + * Return array with prices (0 -> min_price, 1 -> max_price) + * + * @param array $options + * @param array $salableStatus + * @param int $productId + * @param int $priceType + * @param float $basePrice + * @param array $priceData + * @param array $priceIndex + * @param Mage_Core_Model_Website $website + * @param Mage_Customer_Model_Group $group + * @return array + */ + public function _calculateBundleSelections(array $options, array $salableStatus, $productId, $priceType, $basePrice, + $priceData, $priceIndex, $website, $group) + { + $minPrice = $maxPrice = $basePrice; + $optPrice = 0; + + foreach ($options as $option) { + $optionPrices = array(); + foreach ($option['selections'] as $selection) { + if (!$selection['product_id']) { + continue; + } + + if (!$salableStatus[$selection['product_id']]) { + continue; + } + + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) { + $basePrice = $this->_getBasePrice($productId, $priceData, $website, $group); + } + + // calculate selection price + if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { + $priceIndexKey = join('-', array( + $selection['product_id'], + $website->getId(), + $group->getId() + )); + + $selectionPrice = isset($priceIndex[$priceIndexKey]) ? $priceIndex[$priceIndexKey] : 0; + $selectionPrice = $this->_calculateSpecialPrice($selectionPrice, $priceData, $website); + } else { + if ($selection['price_type']) { // percent + $selectionPrice = $basePrice * $selection['price_value'] / 100; + } else { + $selectionPrice = $this->_calculateSpecialPrice($selection['price_value'], + $priceData, $website); + } + } + + // calculate selection qty + if ($selection['can_change_qty'] && $option['type'] != 'multi' && $option['type'] != 'checkbox') { + $qty = 1; + } else { + $qty = $selection['qty']; + } + + $selectionPrice = $selectionPrice * $qty; + $optionPrices[$selection['selection_id']] = $selectionPrice; + } + + if ($optionPrices) { + if ($option['required']) { + $minPrice += min($optionPrices); + } else { + $optPrice = $optPrice && $optPrice < min($optionPrices) ? $optPrice : min($optionPrices); + } + if (in_array($option['type'], array('multi', 'checkbox'))) { + $maxPrice += array_sum($optionPrices); + } else { + $maxPrice += max($optionPrices); + } + } + } + + if ($minPrice == 0) { + $minPrice = $optPrice; + } + return array($minPrice, $maxPrice); + } + + /** + * Apply special price + * + * @param float $finalPrice + * @param array $priceData + * @param Mage_Core_Model_Website $website + * @return float + */ + public function _calculateSpecialPrice($finalPrice, array $priceData, Mage_Core_Model_Website $website) + { + $store = $website->getDefaultStore(); + $specialPrice = $priceData['special_price']; + + if (!is_null($specialPrice) && $specialPrice != false) { + if (Mage::app()->getLocale()->isStoreDateInInterval($store, $priceData['special_from_date'], + $priceData['special_to_date'])) { + $specialPrice = ($finalPrice * $specialPrice) / 100; + $finalPrice = min($finalPrice, $specialPrice); + } + } + + return $finalPrice; + } + + /** + * Retrieve price index for products + * + * @param int|array $productIds + * @param int $websiteId + * @param int $groupId + * @return array + */ + public function loadPriceIndex($productIds, $websiteId, $groupId) + { + $prices = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from( + array('pi' => $this->getMainTable()), + array('entity_id', 'min_price', 'max_price') + ) + ->where('entity_id IN(?)', $productIds) + ->where('website_id=:website_id') + ->where('customer_group_id=:group_id'); + $bind = array( + 'website_id' => $websiteId, + 'group_id' => $groupId + ); + $query = $adapter->query($select, $bind); + while ($row = $query->fetch()) { + $prices[$row['entity_id']] = array( + 'min_price' => $row['min_price'], + 'max_price' => $row['max_price'] + ); + } + + return $prices; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Selection.php b/app/code/core/Mage/Bundle/Model/Resource/Selection.php new file mode 100755 index 0000000000..ae06a5bbd6 --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Selection.php @@ -0,0 +1,196 @@ + + */ +class Mage_Bundle_Model_Resource_Selection extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and id field + * + */ + protected function _construct() + { + $this->_init('bundle/selection', 'selection_id'); + } + + /** + * Retrieve Price From index + * + * @param int $productId + * @param float $qty + * @param int $storeId + * @param int $groupId + * @return mixed + */ + public function getPriceFromIndex($productId, $qty, $storeId, $groupId) + { + $adapter = $this->_getReadAdapter(); + $select = clone $adapter->select(); + $select->reset(); + + $attrPriceId = Mage::getSingleton('eav/entity_attribute') + ->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price'); + $attrTierPriceId = Mage::getSingleton('eav/entity_attribute') + ->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price'); + + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); + + $select->from(array("price_index" => $this->getTable('catalogindex/price')), array('price' => 'SUM(value)')) + ->where('entity_id = :product_id') + ->where('website_id = :website_id') + ->where('customer_group_id = :customer_group') + ->where('attribute_id = :price_attribute OR attribute_id = :tier_price_attribute') + ->where('qty <= :qty') + ->group('entity_id'); + + $bind = array( + 'product_id' => $productId, + 'website_id' => $websiteId, + 'customer_group' => $groupId, + 'price_attribute' => $attrPriceId, + 'tier_price_attribute' => $attrTierPriceId, + 'qty' => $qty + ); + + $price = $adapter->fetchCol($select, $bind); + if (!empty($price)) { + return array_shift($price); + } else { + return 0; + } + } + + /** + * Retrieve Required children ids + * Return grouped array, ex array( + * group => array(ids) + * ) + * + * @param int $parentId + * @param bool $required + * @return array + */ + public function getChildrenIds($parentId, $required = true) + { + $childrenIds = array(); + $notRequired = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from( + array('tbl_selection' => $this->getMainTable()), + array('product_id', 'parent_product_id', 'option_id') + ) + ->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = tbl_selection.product_id AND e.required_options=0', + array() + ) + ->join( + array('tbl_option' => $this->getTable('bundle/option')), + 'tbl_option.option_id = tbl_selection.option_id', + array('required') + ) + ->where('tbl_selection.parent_product_id = :parent_id'); + foreach ($adapter->fetchAll($select, array('parent_id' => $parentId)) as $row) { + if ($row['required']) { + $childrenIds[$row['option_id']][$row['product_id']] = $row['product_id']; + } else { + $notRequired[$row['option_id']][$row['product_id']] = $row['product_id']; + } + } + + if (!$required) { + $childrenIds = array_merge($childrenIds, $notRequired); + } else { + if (!$childrenIds) { + foreach ($notRequired as $groupedChildrenIds) { + foreach ($groupedChildrenIds as $childId) { + $childrenIds[0][$childId] = $childId; + } + } + } + if (!$childrenIds) { + $childrenIds = array(array()); + } + } + + return $childrenIds; + } + + /** + * Retrieve array of related bundle product ids by selection product id(s) + * + * @param int|array $childId + * @return array + */ + public function getParentIdsByChild($childId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->distinct(true) + ->from($this->getMainTable(), 'parent_product_id') + ->where('product_id IN(?)', $childId); + + return $adapter->fetchCol($select); + } + + /** + * Save bundle item price per website + * + * @param Mage_Bundle_Model_Selection $item + */ + public function saveSelectionPrice($item) + { + $write = $this->_getWriteAdapter(); + if ($item->getDefaultPriceScope()) { + $write->delete($this->getTable('bundle/selection_price'), + array( + 'selection_id = ?' => $item->getSelectionId(), + 'website_id = ?' => $item->getWebsiteId() + ) + ); + } else { + $values = array( + 'selection_id' => $item->getSelectionId(), + 'website_id' => $item->getWebsiteId(), + 'selection_price_type' => $item->getSelectionPriceType(), + 'selection_price_value' => $item->getSelectionPriceValue() + ); + $write->insertOnDuplicate( + $this->getTable('bundle/selection_price'), + $values, + array('selection_price_type', 'selection_price_value') + ); + } + } +} diff --git a/app/code/core/Mage/Bundle/Model/Resource/Selection/Collection.php b/app/code/core/Mage/Bundle/Model/Resource/Selection/Collection.php new file mode 100755 index 0000000000..fe44eb5052 --- /dev/null +++ b/app/code/core/Mage/Bundle/Model/Resource/Selection/Collection.php @@ -0,0 +1,153 @@ + + */ +class Mage_Bundle_Model_Resource_Selection_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Selection table name + * + * @var string + */ + protected $_selectionTable; + + /** + * Initialize collection + * + */ + protected function _construct() + { + parent::_construct(); + $this->setRowIdFieldName('selection_id'); + $this->_selectionTable = $this->getTable('bundle/selection'); + } + + /** + * Set store id for each collection item when collection was loaded + * + * @return void + */ + public function _afterLoad() + { + parent::_afterLoad(); + if ($this->getStoreId() && $this->_items) { + foreach ($this->_items as $item) { + $item->setStoreId($this->getStoreId()); + } + } + return $this; + } + + /** + * Initialize collection select + * + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->getSelect()->join(array('selection' => $this->_selectionTable), + 'selection.product_id = e.entity_id', + array('*') + ); + } + + /** + * Join website scope prices to collection, override default prices + * + * @param int $websiteId + * @return Mage_Bundle_Model_Resource_Selection_Collection + */ + public function joinPrices($websiteId) + { + $adapter = $this->getConnection(); + $priceType = $adapter->getCheckSql( + 'price.selection_price_type IS NOT NULL', + 'price.selection_price_type', + 'selection.selection_price_type' + ); + $priceValue = $adapter->getCheckSql( + 'price.selection_price_value IS NOT NULL', + 'price.selection_price_value', + 'selection.selection_price_value' + ); + $this->getSelect()->joinLeft(array('price' => $this->getTable('bundle/selection_price')), + 'selection.selection_id = price.selection_id AND price.website_id = ' . (int)$websiteId, + array( + 'selection_price_type' => $priceType, + 'selection_price_value' => $priceValue, + 'price_scope' => 'price.website_id' + ) + ); + return $this; + } + + /** + * Apply option ids filter to collection + * + * @param array $optionIds + * @return Mage_Bundle_Model_Resource_Selection_Collection + */ + public function setOptionIdsFilter($optionIds) + { + if (!empty($optionIds)) { + $this->getSelect()->where('selection.option_id IN (?)', $optionIds); + } + return $this; + } + + /** + * Apply selection ids filter to collection + * + * @param array $selectionIds + * @return Mage_Bundle_Model_Resource_Selection_Collection + */ + public function setSelectionIdsFilter($selectionIds) + { + if (!empty($selectionIds)) { + $this->getSelect()->where('selection.selection_id IN (?)', $selectionIds); + } + return $this; + } + + /** + * Set position order + * + * @return Mage_Bundle_Model_Resource_Selection_Collection + */ + public function setPositionOrder() + { + $this->getSelect()->order('selection.position asc') + ->order('selection.selection_id asc'); + return $this; + } +} diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php index e212789574..e4fc0834dd 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index 2665dbb7a0..2540f20065 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 3d3c73defc..2efa373859 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 811806f908..72d4558c67 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Selection.php b/app/code/core/Mage/Bundle/Model/Selection.php index 32f6660e78..6a7150bbce 100644 --- a/app/code/core/Mage/Bundle/Model/Selection.php +++ b/app/code/core/Mage/Bundle/Model/Selection.php @@ -20,13 +20,34 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Bundle Selection Model * + * @method Mage_Bundle_Model_Resource_Selection _getResource() + * @method Mage_Bundle_Model_Resource_Selection getResource() + * @method int getOptionId() + * @method Mage_Bundle_Model_Selection setOptionId(int $value) + * @method int getParentProductId() + * @method Mage_Bundle_Model_Selection setParentProductId(int $value) + * @method int getProductId() + * @method Mage_Bundle_Model_Selection setProductId(int $value) + * @method int getPosition() + * @method Mage_Bundle_Model_Selection setPosition(int $value) + * @method int getIsDefault() + * @method Mage_Bundle_Model_Selection setIsDefault(int $value) + * @method int getSelectionPriceType() + * @method Mage_Bundle_Model_Selection setSelectionPriceType(int $value) + * @method float getSelectionPriceValue() + * @method Mage_Bundle_Model_Selection setSelectionPriceValue(float $value) + * @method float getSelectionQty() + * @method Mage_Bundle_Model_Selection setSelectionQty(float $value) + * @method int getSelectionCanChangeQty() + * @method Mage_Bundle_Model_Selection setSelectionCanChangeQty(int $value) + * * @category Mage * @package Mage_Bundle * @author Magento Core Team diff --git a/app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php b/app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php index ea1e88bd2d..eded2e9612 100644 --- a/app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php +++ b/app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/Model/Source/Option/Type.php b/app/code/core/Mage/Bundle/Model/Source/Option/Type.php index 6e798a343a..b283eda0a2 100644 --- a/app/code/core/Mage/Bundle/Model/Source/Option/Type.php +++ b/app/code/core/Mage/Bundle/Model/Source/Option/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php b/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php index 86b3b159d1..620757dffd 100644 --- a/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php +++ b/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php b/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php index cf7fe9e85f..1e13ef2963 100644 --- a/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php +++ b/app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/controllers/Product/EditController.php b/app/code/core/Mage/Bundle/controllers/Product/EditController.php index b172bdfd5f..de53faf5a5 100644 --- a/app/code/core/Mage/Bundle/controllers/Product/EditController.php +++ b/app/code/core/Mage/Bundle/controllers/Product/EditController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/controllers/SelectionController.php b/app/code/core/Mage/Bundle/controllers/SelectionController.php index 60184a3813..e3e1b24481 100644 --- a/app/code/core/Mage/Bundle/controllers/SelectionController.php +++ b/app/code/core/Mage/Bundle/controllers/SelectionController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/data/bundle_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Bundle/data/bundle_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..f11710d34b --- /dev/null +++ b/app/code/core/Mage/Bundle/data/bundle_setup/data-install-1.6.0.0.php @@ -0,0 +1,44 @@ +getAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to')); + if (!in_array('bundle', $applyTo)) { + $applyTo[] = 'bundle'; + $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to', implode(',', $applyTo)); + } +} + +$applyTo = explode(',', $installer->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'cost', 'apply_to')); +unset($applyTo[array_search('bundle', $applyTo)]); +$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'cost', 'apply_to', implode(',', $applyTo)); diff --git a/app/code/core/Mage/Bundle/etc/config.xml b/app/code/core/Mage/Bundle/etc/config.xml index 34311d11ff..e2c943b0c9 100644 --- a/app/code/core/Mage/Bundle/etc/config.xml +++ b/app/code/core/Mage/Bundle/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.1.14 + 1.6.0.0 Mage_Bundle_Model - bundle_mysql4 + bundle_resource - - Mage_Bundle_Model_Mysql4 + + Mage_Bundle_Model_Resource + bundle_mysql4 - + Mage_Bundle - Mage_Catalog_Model_Resource_Eav_Mysql4_Setup + Mage_Catalog_Model_Resource_Setup - Mage_Bundle_Block + + Mage_Bundle_Block + @@ -98,8 +101,8 @@ bundle/product_type 1 - - + + bundle/product_price bundle/catalogIndex_data_bundle @@ -132,11 +135,11 @@ - - - - - + + + + + @@ -183,8 +186,8 @@ - - + + @@ -220,12 +223,12 @@ - + - + diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/install-1.6.0.0.php b/app/code/core/Mage/Bundle/sql/bundle_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..f2a74643df --- /dev/null +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/install-1.6.0.0.php @@ -0,0 +1,650 @@ +startSetup(); + +/** + * Create table 'catalog_product_bundle_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('required', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Required') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Type') + ->addIndex($installer->getIdxName('bundle/option', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('bundle/option', 'parent_id', 'catalog/product', 'entity_id'), + 'parent_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Bundle Option'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_bundle_option_value' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/option_value')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Option Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Title') + ->addIndex($installer->getIdxName('bundle/option_value', array('option_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('option_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey($installer->getFkName('bundle/option_value', 'option_id', 'bundle/option', 'option_id'), + 'option_id', $installer->getTable('bundle/option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Bundle Option Value'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_bundle_selection' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/selection')) + ->addColumn('selection_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Selection Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Option Id') + ->addColumn('parent_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Product Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Default') + ->addColumn('selection_price_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Selection Price Type') + ->addColumn('selection_price_value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Selection Price Value') + ->addColumn('selection_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Selection Qty') + ->addColumn('selection_can_change_qty', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Selection Can Change Qty') + ->addIndex($installer->getIdxName('bundle/selection', array('option_id')), + array('option_id')) + ->addIndex($installer->getIdxName('bundle/selection', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('bundle/selection', 'option_id', 'bundle/option', 'option_id'), + 'option_id', $installer->getTable('bundle/option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('bundle/selection', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Bundle Selection'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_bundle_selection_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/selection_price')) + ->addColumn('selection_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Selection Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('selection_price_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Selection Price Type') + ->addColumn('selection_price_value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Selection Price Value') + ->addIndex($installer->getIdxName('bundle/selection_price', array('website_id')), + array('website_id')) + ->addForeignKey($installer->getFkName('bundle/selection_price', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('bundle/selection_price', 'selection_id', 'bundle/selection', 'selection_id'), + 'selection_id', $installer->getTable('bundle/selection'), 'selection_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Bundle Selection Price'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_bundle_price_index' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/price_index')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + ), 'Max Price') + ->addIndex($installer->getIdxName('bundle/price_index', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('bundle/price_index', array('customer_group_id')), + array('customer_group_id')) + ->addForeignKey($installer->getFkName('bundle/price_index', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('bundle/price_index', 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('bundle/price_index', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Bundle Price Index'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_bundle_stock_index' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/stock_index')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Stock Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option Id') + ->addColumn('stock_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'default' => '0', + ), 'Stock Status') + ->setComment('Catalog Product Bundle Stock Index'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/price_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class Id') + ->addColumn('price_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Price Type') + ->addColumn('special_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Special Price') + ->addColumn('tier_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Percent') + ->addColumn('orig_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Orig Price') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('base_tier', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tier') + ->setComment('Catalog Product Index Price Bundle Idx'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/price_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class Id') + ->addColumn('price_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Price Type') + ->addColumn('special_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Special Price') + ->addColumn('tier_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Percent') + ->addColumn('orig_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Orig Price') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('base_tier', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tier') + ->setComment('Catalog Product Index Price Bundle Tmp'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_sel_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/selection_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option Id') + ->addColumn('selection_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Selection Id') + ->addColumn('group_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Group Type') + ->addColumn('is_required', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Is Required') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Index Price Bundle Sel Idx'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_sel_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/selection_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option Id') + ->addColumn('selection_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Selection Id') + ->addColumn('group_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Group Type') + ->addColumn('is_required', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Is Required') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Index Price Bundle Sel Tmp'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_opt_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/option_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option Id') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('alt_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Alt Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('alt_tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Alt Tier Price') + ->setComment('Catalog Product Index Price Bundle Opt Idx'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog_product_index_price_bundle_opt_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('bundle/option_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option Id') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('alt_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Alt Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('alt_tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Alt Tier Price') + ->setComment('Catalog Product Index Price Bundle Opt Tmp'); +$installer->getConnection()->createTable($table); + +/** + * Add attributes to the eav/attribute + */ +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'price_type', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => '', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'used_in_product_listing' => true, + 'unique' => false, + 'apply_to' => 'bundle', + 'is_configurable' => false + )); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'sku_type', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => '', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'bundle', + 'is_configurable' => false + )); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'weight_type', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => '', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'used_in_product_listing' => true, + 'unique' => false, + 'apply_to' => 'bundle', + 'is_configurable' => false + )); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'price_view', array( + 'group' => 'Prices', + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Price View', + 'input' => 'select', + 'class' => '', + 'source' => 'bundle/product_attribute_source_price_view', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => true, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'used_in_product_listing' => true, + 'unique' => false, + 'apply_to' => 'bundle', + 'is_configurable' => false + )); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'shipment_type', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Shipment', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'used_in_product_listing' => true, + 'unique' => false, + 'apply_to' => 'bundle', + 'is_configurable' => false + )); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php index 3bed1be09f..616e7504c8 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -80,4 +80,3 @@ $db->rollback(); throw $e; } - diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php index a5568c7406..3270a15b60 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php index 9e6cc923fb..037721fed7 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php index 83070fb835..8f081bcfcc 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php index 215d9b0dcd..d430bbabfc 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php index d6335fa97d..f967ca958d 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php index 1380bf2d51..7fabe4683a 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php index 99810f01e3..cc49c1e062 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php index e0347b667a..aaf97d9afc 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php index 2a616ae913..c7e17e3848 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php index 705737df58..3b1300b133 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php index f7123bc10f..b5ac6834c7 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php index 134ec9260c..b76221c4ff 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php index af5e9b8053..a58b234f85 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php index 2ede6aaed8..942f5ec95b 100644 --- a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..6638007ca5 --- /dev/null +++ b/app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,960 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/option'), + 'FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/option_value'), + 'FK_CATALOG_PRODUCT_BUNDLE_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'FK_CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'FK_CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'FK_CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/price_index'), + 'CATALOG_PRODUCT_BUNDLE_PRICE_INDEX_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/selection'), + 'FK_CATALOG_PRODUCT_BUNDLE_SELECTION_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/selection'), + 'FK_CATALOG_PRODUCT_BUNDLE_SELECTION_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/selection_price'), + 'FK_BUNDLE_PRICE_SELECTION_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('bundle/selection_price'), + 'FK_BUNDLE_PRICE_SELECTION_WEBSITE' +); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/option'), + 'FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/option_value'), + 'UNQ_OPTION_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/option_value'), + 'FK_CATALOG_PRODUCT_BUNDLE_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/price_index'), + 'IDX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/price_index'), + 'IDX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/selection'), + 'FK_CATALOG_PRODUCT_BUNDLE_SELECTION_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/selection'), + 'FK_CATALOG_PRODUCT_BUNDLE_SELECTION_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('bundle/selection_price'), + 'FK_BUNDLE_PRICE_SELECTION_WEBSITE' +); + +/** + * Change columns + */ +$tables = array( + $installer->getTable('bundle/option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'required' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Required' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Type' + ) + ), + 'comment' => 'Catalog Product Bundle Option' + ), + $installer->getTable('bundle/option_value') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Option Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Title' + ) + ), + 'comment' => 'Catalog Product Bundle Option Value' + ), + $installer->getTable('bundle/selection') => array( + 'columns' => array( + 'selection_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Selection Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Option Id' + ), + 'parent_product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Product Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product Id' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'is_default' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Default' + ), + 'selection_price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Selection Price Type' + ), + 'selection_price_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Selection Price Value' + ), + 'selection_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Selection Qty' + ), + 'selection_can_change_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Selection Can Change Qty' + ) + ), + 'comment' => 'Catalog Product Bundle Selection' + ), + $installer->getTable('bundle/selection_price') => array( + 'columns' => array( + 'selection_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Selection Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'selection_price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Selection Price Type' + ), + 'selection_price_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Selection Price Value' + ) + ), + 'comment' => 'Catalog Product Bundle Selection Price' + ), + $installer->getTable('bundle/price_index') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'comment' => 'Max Price' + ) + ), + 'comment' => 'Catalog Product Bundle Price Index' + ), + $installer->getTable('bundle/stock_index') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Stock Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'stock_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'default' => '0', + 'comment' => 'Stock Status' + ) + ), + 'comment' => 'Catalog Product Bundle Stock Index' + ), + $installer->getTable('bundle/price_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class Id' + ), + 'price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Price Type' + ), + 'special_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Special Price' + ), + 'tier_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Percent' + ), + 'orig_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Orig Price' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'base_tier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tier' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Idx' + ), + $installer->getTable('bundle/price_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class Id' + ), + 'price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Price Type' + ), + 'special_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Special Price' + ), + 'tier_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Percent' + ), + 'orig_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Orig Price' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'base_tier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tier' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Tmp', + 'engine' => 'InnoDB' + ), + $installer->getTable('bundle/selection_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'selection_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Selection Id' + ), + 'group_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Group Type' + ), + 'is_required' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Is Required' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Sel Idx' + ), + $installer->getTable('bundle/selection_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'selection_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Selection Id' + ), + 'group_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Group Type' + ), + 'is_required' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Is Required' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Sel Tmp', + 'engine' => 'InnoDB' + ), + $installer->getTable('bundle/option_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'alt_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Alt Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'alt_tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Alt Tier Price' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Opt Idx' + ), + $installer->getTable('bundle/option_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'alt_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Alt Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'alt_tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Alt Tier Price' + ) + ), + 'comment' => 'Catalog Product Index Price Bundle Opt Tmp', + 'engine' => 'InnoDB' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('bundle/option'), + $installer->getIdxName('bundle/option', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/option_value'), + $installer->getIdxName( + 'bundle/option_value', + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/price_index'), + $installer->getIdxName('bundle/price_index', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/price_index'), + $installer->getIdxName('bundle/price_index', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/selection'), + $installer->getIdxName('bundle/selection', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/selection'), + $installer->getIdxName('bundle/selection', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('bundle/selection_price'), + $installer->getIdxName('bundle/selection_price', array('website_id')), + array('website_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/selection', 'option_id', 'bundle/option', 'option_id'), + $installer->getTable('bundle/selection'), + 'option_id', + $installer->getTable('bundle/option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/option', 'parent_id', 'catalog/product', 'entity_id'), + $installer->getTable('bundle/option'), + 'parent_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/option_value', 'option_id', 'bundle/option', 'option_id'), + $installer->getTable('bundle/option_value'), + 'option_id', + $installer->getTable('bundle/option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/price_index', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('bundle/price_index'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/price_index', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('bundle/price_index'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/price_index', 'website_id', 'core/website', 'website_id'), + $installer->getTable('bundle/price_index'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/selection', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('bundle/selection'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/selection_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('bundle/selection_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('bundle/selection_price', 'selection_id', 'bundle/selection', 'selection_id'), + $installer->getTable('bundle/selection_price'), + 'selection_id', + $installer->getTable('bundle/selection'), + 'selection_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Catalog/Block/Breadcrumbs.php b/app/code/core/Mage/Catalog/Block/Breadcrumbs.php index 7928f8e739..4bb84b266b 100644 --- a/app/code/core/Mage/Catalog/Block/Breadcrumbs.php +++ b/app/code/core/Mage/Catalog/Block/Breadcrumbs.php @@ -20,9 +20,10 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog breadcrumbs * diff --git a/app/code/core/Mage/Catalog/Block/Category/View.php b/app/code/core/Mage/Catalog/Block/Category/View.php index b2328962ed..0db6634295 100644 --- a/app/code/core/Mage/Catalog/Block/Category/View.php +++ b/app/code/core/Mage/Catalog/Block/Category/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Category/Widget/Link.php b/app/code/core/Mage/Catalog/Block/Category/Widget/Link.php index 82bd2808f4..16f8e41537 100644 --- a/app/code/core/Mage/Catalog/Block/Category/Widget/Link.php +++ b/app/code/core/Mage/Catalog/Block/Category/Widget/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php b/app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php index f81e082281..60078cfae5 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php b/app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php index 56515f7c00..8033b3885d 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php +++ b/app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php b/app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php index 96b9026a81..1e84bf7f2f 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php +++ b/app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php b/app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php index 5771e57a6a..092533ddec 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php +++ b/app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php index a8cd8ed7c3..876069131d 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php +++ b/app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/State.php b/app/code/core/Mage/Catalog/Block/Layer/State.php index 6bcd04dcbe..67ed9f97b1 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/State.php +++ b/app/code/core/Mage/Catalog/Block/Layer/State.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Layer/View.php b/app/code/core/Mage/Catalog/Block/Layer/View.php index 31ec010c3c..444e75ef83 100644 --- a/app/code/core/Mage/Catalog/Block/Layer/View.php +++ b/app/code/core/Mage/Catalog/Block/Layer/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Navigation.php b/app/code/core/Mage/Catalog/Block/Navigation.php index 1dd4d8536a..69789dd619 100644 --- a/app/code/core/Mage/Catalog/Block/Navigation.php +++ b/app/code/core/Mage/Catalog/Block/Navigation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product.php b/app/code/core/Mage/Catalog/Block/Product.php index 9181180df2..aa83fda8f7 100644 --- a/app/code/core/Mage/Catalog/Block/Product.php +++ b/app/code/core/Mage/Catalog/Block/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index 434034d349..0199cf6d6c 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -230,8 +230,11 @@ public function addPriceBlockType($type, $block = '', $template = '') */ public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $templateType = false, $displayIfNoReviews = false) { - $this->_initReviewsHelperBlock(); - return $this->_reviewsHelperBlock->getSummaryHtml($product, $templateType, $displayIfNoReviews); + if ($this->_initReviewsHelperBlock()) { + return $this->_reviewsHelperBlock->getSummaryHtml($product, $templateType, $displayIfNoReviews); + } + + return ''; } /** @@ -242,19 +245,28 @@ public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $temp */ public function addReviewSummaryTemplate($type, $template) { - $this->_initReviewsHelperBlock(); - $this->_reviewsHelperBlock->addTemplate($type, $template); + if ($this->_initReviewsHelperBlock()) { + $this->_reviewsHelperBlock->addTemplate($type, $template); + } + + return ''; } /** * Create reviews summary helper block once * + * @return boolean */ protected function _initReviewsHelperBlock() { if (!$this->_reviewsHelperBlock) { - $this->_reviewsHelperBlock = $this->getLayout()->createBlock('review/helper'); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) { + $this->_reviewsHelperBlock = $this->getLayout()->createBlock('review/helper'); + return true; + } } + + return false; } /** @@ -342,7 +354,7 @@ public function getTierPrices($product = null) * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ - protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection) + protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Product_Collection $collection) { return $collection ->addMinimalPrice() diff --git a/app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php index 992e1694f4..5d75a8b480 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php index 43dc1e9940..93928ce9be 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php +++ b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php b/app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php index 789e8a025d..cfaec9b2ce 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php +++ b/app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Gallery.php b/app/code/core/Mage/Catalog/Block/Product/Gallery.php index af76499a92..c8bd70b7c3 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Gallery.php +++ b/app/code/core/Mage/Catalog/Block/Product/Gallery.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/List.php b/app/code/core/Mage/Catalog/Block/Product/List.php index 1b0e937c68..b1764e8f21 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List.php +++ b/app/code/core/Mage/Catalog/Block/Product/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -135,10 +135,6 @@ public function getMode() */ protected function _beforeToHtml() { - /*$toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime()); - if ($toolbarTemplate = $this->getToolbarTemplate()) { - $toolbar->setTemplate($toolbarTemplate); - }*/ $toolbar = $this->getToolbarBlock(); // called prepare sortable parameters @@ -167,7 +163,7 @@ protected function _beforeToHtml() )); $this->_getProductCollection()->load(); - Mage::getModel('review/review')->appendSummary($this->_getProductCollection()); + return parent::_beforeToHtml(); } diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php b/app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php index 6b5afd450b..c3ffa93605 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Promotion.php b/app/code/core/Mage/Catalog/Block/Product/List/Promotion.php index 621f01d751..08cf1c6dee 100755 --- a/app/code/core/Mage/Catalog/Block/Product/List/Promotion.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Promotion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Catalog_Block_Product_List_Promotion extends Mage_Catalog_Block_Product_List diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Random.php b/app/code/core/Mage/Catalog/Block/Product/List/Random.php index ac137a8af3..3b78a08aab 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Random.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Random.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Related.php b/app/code/core/Mage/Catalog/Block/Product/List/Related.php index bd6cf8283a..230ecd6d9c 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Related.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Related.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -43,14 +43,16 @@ protected function _prepareData() $this->_itemCollection = $product->getRelatedProductCollection() ->addAttributeToSelect('required_options') - ->addAttributeToSort('position', 'asc') + ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC) ->addStoreFilter() ; - Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, - Mage::getSingleton('checkout/session')->getQuoteId() - ); - $this->_addProductAttributesAndPrices($this->_itemCollection); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) { + Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, + Mage::getSingleton('checkout/session')->getQuoteId() + ); + $this->_addProductAttributesAndPrices($this->_itemCollection); + } // Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php b/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php index 6627d37bbc..a5b106c045 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar/Pager.php b/app/code/core/Mage/Catalog/Block/Product/List/Toolbar/Pager.php deleted file mode 100644 index 937b30197d..0000000000 --- a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar/Pager.php +++ /dev/null @@ -1,379 +0,0 @@ - - */ -class Mage_Catalog_Block_Product_List_Toolbar_Pager extends Mage_Page_Block_Html_Pager -{ - /** - * Pages quantity per frame - * @var int - */ - protected $_frameLength = 5; - - /** - * Next/previous page position relatively to the current frame - * @var int - */ - protected $_jump = 5; - - /** - * Frame initialization flag - * @var bool - */ - protected $_frameInitialized = false; - - /** - * Start page position in frame - * @var int - */ - protected $_frameStart; - - /** - * Finish page position in frame - * @var int - */ - protected $_frameEnd; - - /** - * Custom limit - * @var int - */ - protected $_limit; - - /** - * Define default template and settings - */ - protected function _construct() - { - parent::_construct(); - $this->setTemplate('catalog/product/list/toolbar/pager.phtml'); - } - - /** - * Getter for $_frameStart - * - * @return int - */ - public function getFrameStart() - { - $this->_initFrame(); - return $this->_frameStart; - } - - /** - * Getter for $_frameEnd - * - * @return int - */ - public function getFrameEnd() - { - $this->_initFrame(); - return $this->_frameEnd; - } - - /** - * Return array of pages in frame - * - * @return array - */ - public function getFramePages() - { - $start = $this->getFrameStart(); - $end = $this->getFrameEnd(); - return range($start, $end); - } - - /** - * Return page number of Previous jump - * - * @return int - */ - public function getPreviousJumpPage() - { - if (!$this->getJump()) { - return null; - } - $frameStart = $this->getFrameStart(); - if ($frameStart - 1 > 1) { - return max(2, $frameStart - $this->getJump()); - } - - return null; - } - - /** - * Prepare URL for Previous Jump - * - * @return string - */ - public function getPreviousJumpUrl() - { - return $this->getPageUrl($this->getPreviousJumpPage()); - } - - /** - * Return page number of Next jump - * - * @return int - */ - public function getNextJumpPage() - { - if (!$this->getJump()) { - return null; - } - $frameEnd = $this->getFrameEnd(); - if ($this->getLastPageNum() - $frameEnd > 1) { - return min($this->getLastPageNum() - 1, $frameEnd + $this->getJump()); - } - - return null; - } - - /** - * Prepare URL for Next Jump - * - * @return string - */ - public function getNextJumpUrl() - { - return $this->getPageUrl($this->getNextJumpPage()); - } - - /** - * Getter for $_frameLength - * - * @return int - */ - public function getFrameLength() - { - return $this->_frameLength; - } - - /** - * Getter for $_jump - * - * @return int - */ - public function getJump() - { - return $this->_jump; - } - - /** - * Setter for $_frameLength - * - * @param int $frame - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - public function setFrameLength($frame) - { - $frame = abs(intval($frame)); - if ($this->getFrameLength() != $frame) { - $this->_setFrameInitialized(false); - $this->_frameLength = $frame; - } - - return $this; - } - - /** - * Setter for $_jump - * - * @param int $jump - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - public function setJump($jump) - { - $jump = abs(intval($jump)); - if ($this->getJump() != $jump) { - $this->_setFrameInitialized(false); - $this->_jump = $jump; - } - - return $this; - } - - /** - * Setter for $_limit - * - * @param int $limit - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - public function setLimit($limit) - { - $this->_limit = abs(intval($limit)); - return $this; - } - - /** - * Return pager limitation from request or as assigned value - * - * @return int - */ - public function getLimit() - { - if ($this->_limit !== null) { - return $this->_limit; - } - return parent::getLimit(); - } - - /** - * Custom setter for pager collection - * - * @param Varien_Data_Collection - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - public function setCollection($collection) - { - parent::setCollection($collection); - $this->_setFrameInitialized(false); - return $this; - } - - /** - * Whether to show first page in pagination or not - * - * @return bool - */ - public function canShowFirst() - { - return $this->getJump() > 1 && $this->getFrameStart() > 1; - } - - /** - * Whether to show last page in pagination or not - * - * @return bool - */ - public function canShowLast() - { - return $this->getJump() > 1 && $this->getFrameEnd() < $this->getLastPageNum(); - } - - /** - * Whether to show link to Previous Jump - * - * @return bool - */ - public function canShowPreviousJump() - { - return $this->getPreviousJumpPage() !== null; - } - - /** - * Whether to show link to Next Jump - * - * @return bool - */ - public function canShowNextJump() - { - return $this->getNextJumpPage() !== null; - } - - /** - * Initialize frame data, such as frame start, frame start etc. - * - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - protected function _initFrame() - { - if (!$this->isFrameInitialized()) { - $start = 0; - $end = 0; - - $collection = $this->getCollection(); - if ($collection->getLastPageNumber() <= $this->getFrameLength()) { - $start = 1; - $end = $collection->getLastPageNumber(); - } - else { - $half = ceil($this->getFrameLength() / 2); - if ($collection->getCurPage() >= $half && $collection->getCurPage() <= $collection->getLastPageNumber() - $half) { - $start = ($collection->getCurPage() - $half) + 1; - $end = ($start + $this->getFrameLength()) - 1; - } - elseif ($collection->getCurPage() < $half) { - $start = 1; - $end = $this->getFrameLength(); - } - elseif ($collection->getCurPage() > ($collection->getLastPageNumber() - $half)) { - $end = $collection->getLastPageNumber(); - $start = $end - $this->getFrameLength() + 1; - } - } - - $this->_frameStart = $start; - $this->_frameEnd = $end; - - $this->_setFrameInitialized(true); - } - - return $this; - } - - /** - * Setter for flag _frameInitialized - * - * @param bool $flag - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - protected function _setFrameInitialized($flag) - { - $this->_frameInitialized = (bool)$flag; - return $this; - } - - /** - * Check if frame data was initialized - * - * @return Mage_Catalog_Block_Product_List_Toolbar_Pager - */ - public function isFrameInitialized() - { - return $this->_frameInitialized; - } - - /** - * Render block HTML - * - * @return string - */ - protected function _toHtml() - { - if ($this->getLastPageNum() > 1) { - return parent::_toHtml(); - } else { - return ''; - } - } -} diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php b/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php index 725cdcf647..eea0a2b8a1 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -47,14 +47,16 @@ protected function _prepareData() $product = Mage::registry('product'); /* @var $product Mage_Catalog_Model_Product */ $this->_itemCollection = $product->getUpSellProductCollection() - ->addAttributeToSort('position', 'asc') + ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC) ->addStoreFilter() ; - Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, - Mage::getSingleton('checkout/session')->getQuoteId() - ); - $this->_addProductAttributesAndPrices($this->_itemCollection); + if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) { + Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, + Mage::getSingleton('checkout/session')->getQuoteId() + ); + $this->_addProductAttributesAndPrices($this->_itemCollection); + } // Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); diff --git a/app/code/core/Mage/Catalog/Block/Product/New.php b/app/code/core/Mage/Catalog/Block/Product/New.php index cd2b3461d7..007386fef3 100644 --- a/app/code/core/Mage/Catalog/Block/Product/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Price.php b/app/code/core/Mage/Catalog/Block/Product/Price.php index b1a2d57866..ec47b1f769 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Price.php +++ b/app/code/core/Mage/Catalog/Block/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Price/Template.php b/app/code/core/Mage/Catalog/Block/Product/Price/Template.php index 2769a8db4f..8ae93ac6c2 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Price/Template.php +++ b/app/code/core/Mage/Catalog/Block/Product/Price/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Send.php b/app/code/core/Mage/Catalog/Block/Product/Send.php index 7ab6a6818d..5c0ca4bb5f 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Send.php +++ b/app/code/core/Mage/Catalog/Block/Product/Send.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View.php b/app/code/core/Mage/Catalog/Block/Product/View.php index a0262a851a..0cffc8e971 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View.php +++ b/app/code/core/Mage/Catalog/Block/Product/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/View/Abstract.php index 4d3e8dce95..e345f89e2d 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Additional.php b/app/code/core/Mage/Catalog/Block/Product/View/Additional.php index 199822b00c..29a731c653 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Additional.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Additional.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Attributes.php b/app/code/core/Mage/Catalog/Block/Product/View/Attributes.php index ae18dafd24..6f1704e179 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Attributes.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Description.php b/app/code/core/Mage/Catalog/Block/Product/View/Description.php index cb0b9acac4..27bd2f2f8a 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Description.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Description.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Media.php b/app/code/core/Mage/Catalog/Block/Product/View/Media.php index 55d98c6850..71e3ca0963 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Media.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Media.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options.php b/app/code/core/Mage/Catalog/Block/Product/View/Options.php index 34ee619277..e593ef85f2 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php index ec589a3b21..1e55184076 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php index 2bd8e39e09..18db26162c 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php index 283f22c1c3..8d683d7ef6 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php index 0422a5ae30..3a2c96f944 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php index a10549c6c5..abdb1ca2ef 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php index 6c41a66e63..697a12f317 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Price.php b/app/code/core/Mage/Catalog/Block/Product/View/Price.php index ae58b71f20..a3359f11c1 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Price.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php b/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php index a86062d02d..e2212d40c6 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php b/app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php index 928a7f73c9..e349f9b8c4 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php b/app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php index e21bc1d5fc..dd972c7e5f 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php b/app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php index 5e1286df74..e2bf595398 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php b/app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php index abd6243047..f8f503579c 100644 --- a/app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php +++ b/app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Widget/Link.php b/app/code/core/Mage/Catalog/Block/Product/Widget/Link.php index 5b0aac6e84..88bc92630c 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Widget/Link.php +++ b/app/code/core/Mage/Catalog/Block/Product/Widget/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Product/Widget/New.php b/app/code/core/Mage/Catalog/Block/Product/Widget/New.php index d2f4125257..5d1a09e551 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Widget/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/Widget/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php index 7c19f09951..fd1c7e7db5 100644 --- a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php index 07a8d5d52b..cecaf1c6a8 100644 --- a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php +++ b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php index 4fafabdceb..9b50d101de 100644 --- a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php +++ b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php index de116a0c85..d61709a1d8 100644 --- a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php +++ b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php index a8729ff35e..a628139e7f 100644 --- a/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php +++ b/app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Block/Widget/Link.php b/app/code/core/Mage/Catalog/Block/Widget/Link.php index 989aa2b62e..40483c2b92 100644 --- a/app/code/core/Mage/Catalog/Block/Widget/Link.php +++ b/app/code/core/Mage/Catalog/Block/Widget/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Exception.php b/app/code/core/Mage/Catalog/Exception.php index 1f0c660ccb..7a572a962a 100644 --- a/app/code/core/Mage/Catalog/Exception.php +++ b/app/code/core/Mage/Catalog/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Category.php b/app/code/core/Mage/Catalog/Helper/Category.php index dd4d3b7f6f..465e7ed2a2 100644 --- a/app/code/core/Mage/Catalog/Helper/Category.php +++ b/app/code/core/Mage/Catalog/Helper/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -35,7 +35,7 @@ class Mage_Catalog_Helper_Category extends Mage_Core_Helper_Abstract { const XML_PATH_CATEGORY_URL_SUFFIX = 'catalog/seo/category_url_suffix'; const XML_PATH_USE_CATEGORY_CANONICAL_TAG = 'catalog/seo/category_canonical_tag'; - + const XML_PATH_CATEGORY_ROOT_ID = 'catalog/category/root_id'; /** * Store categories cache diff --git a/app/code/core/Mage/Catalog/Helper/Category/Flat.php b/app/code/core/Mage/Catalog/Helper/Category/Flat.php index 1f5fa72b77..3e8ac5405a 100644 --- a/app/code/core/Mage/Catalog/Helper/Category/Flat.php +++ b/app/code/core/Mage/Catalog/Helper/Category/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Data.php b/app/code/core/Mage/Catalog/Helper/Data.php index f90b592397..8e6f17c47c 100644 --- a/app/code/core/Mage/Catalog/Helper/Data.php +++ b/app/code/core/Mage/Catalog/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -41,7 +41,7 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog'; const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives'; const XML_PATH_CONTENT_TEMPLATE_FILTER = 'global/catalog/content/tempate_filter'; - + /** * Breadcrumb Path cache * @@ -268,4 +268,13 @@ public function getPageTemplateProcessor() $model = (string)Mage::getConfig()->getNode(self::XML_PATH_CONTENT_TEMPLATE_FILTER); return Mage::getModel($model); } + + /** + * Initialize mapping for old and new field names + */ + public function getOldFieldMap() + { + return (array)Mage::getConfig()->getNode('global/catalog_product/old_fields_map/'); + } + } diff --git a/app/code/core/Mage/Catalog/Helper/Image.php b/app/code/core/Mage/Catalog/Helper/Image.php index 7ccc5201a9..f7ec3693b7 100644 --- a/app/code/core/Mage/Catalog/Helper/Image.php +++ b/app/code/core/Mage/Catalog/Helper/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Map.php b/app/code/core/Mage/Catalog/Helper/Map.php index 4de183d80b..3ecff8dab9 100644 --- a/app/code/core/Mage/Catalog/Helper/Map.php +++ b/app/code/core/Mage/Catalog/Helper/Map.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Output.php b/app/code/core/Mage/Catalog/Helper/Output.php index 3dcb223d8a..15d277d732 100644 --- a/app/code/core/Mage/Catalog/Helper/Output.php +++ b/app/code/core/Mage/Catalog/Helper/Output.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -119,7 +119,7 @@ public function process($method, $result, $params) */ public function productAttribute($product, $attributeHtml, $attributeName) { - $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeName); + $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeName); if ($attribute && $attribute->getId() && ($attribute->getFrontendInput() != 'media_image') && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) { if ($attribute->getFrontendInput() != 'price') { @@ -153,7 +153,7 @@ public function productAttribute($product, $attributeHtml, $attributeName) */ public function categoryAttribute($category, $attributeHtml, $attributeName) { - $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_category', $attributeName); + $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, $attributeName); if ($attribute && ($attribute->getFrontendInput() != 'image') && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) { diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index ae4775fd9d..2d62c75c28 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Compare.php b/app/code/core/Mage/Catalog/Helper/Product/Compare.php index f17c55cdc2..30dfac05d1 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Compare.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Compare.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Configuration.php b/app/code/core/Mage/Catalog/Helper/Product/Configuration.php index 2f659e500b..d6d0a502aa 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Configuration.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Configuration.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php b/app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php index ede511dcc3..4352261c41 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Flat.php b/app/code/core/Mage/Catalog/Helper/Product/Flat.php index 92dbc22b54..0142e66516 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Flat.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Options.php b/app/code/core/Mage/Catalog/Helper/Product/Options.php index 8c5815fe78..f57ea7a23b 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Options.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/Url.php b/app/code/core/Mage/Catalog/Helper/Product/Url.php index eb11faf7df..8a3a77ea78 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Url.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Helper/Product/View.php b/app/code/core/Mage/Catalog/Helper/Product/View.php index 1c4715c465..acdb9ea1c1 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/View.php +++ b/app/code/core/Mage/Catalog/Helper/Product/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Abstract.php b/app/code/core/Mage/Catalog/Model/Abstract.php index c86ca4b138..099cad5956 100644 --- a/app/code/core/Mage/Catalog/Model/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -127,7 +127,7 @@ public function getLockedAttributes() } /** - * Checks that model have locked attribtues + * Checks that model have locked attributes * * @return boolean */ @@ -139,7 +139,7 @@ public function hasLockedAttributes() /** * Retrieve locked attributes * - * @return array + * @return boolean */ public function isLockedAttribute($attributeCode) { @@ -161,7 +161,7 @@ public function isLockedAttribute($attributeCode) * @param boolean $isChanged * @return Varien_Object */ - public function setData($key, $value=null) + public function setData($key, $value = null) { if ($this->hasLockedAttributes()) { if (is_array($key)) { @@ -189,9 +189,9 @@ public function setData($key, $value=null) * * @param string $key * @param boolean $isChanged - * @return Varien_Object + * @return Mage_Catalog_Model_Abstract */ - public function unsetData($key=null) + public function unsetData($key = null) { if ((!is_null($key) && $this->isLockedAttribute($key)) || $this->isReadonly()) { @@ -204,7 +204,7 @@ public function unsetData($key=null) /** * Get collection instance * - * @return object + * @return Mage_Catalog_Model_Resource_Collection_Abstract */ public function getResourceCollection() { @@ -213,7 +213,15 @@ public function getResourceCollection() return $collection; } - public function loadByAttribute($attribute, $value, $additionalAttributes='*') + /** + * Load entity by attribute + * + * @param Mage_Eav_Model_Entity_Attribute_Interface|integer|string|array $attribute + * @param null|string|array $value + * @param string $additionalAttributes + * @return bool|Mage_Catalog_Model_Abstract + */ + public function loadByAttribute($attribute, $value, $additionalAttributes = '*') { $collection = $this->getResourceCollection() ->addAttributeToSelect($additionalAttributes) @@ -239,7 +247,7 @@ public function getStore() /** * Retrieve all store ids of object current website * - * @return unknown + * @return array */ public function getWebsiteStoreIds() { @@ -252,6 +260,7 @@ public function getWebsiteStoreIds() * Default value existing is flag for using store value in data * * @param string $attributeCode + * @value mixed $value * @return Mage_Catalog_Model_Abstract */ public function setAttributeDefaultValue($attributeCode, $value) @@ -264,7 +273,7 @@ public function setAttributeDefaultValue($attributeCode, $value) * Retrieve default value for attribute code * * @param string $attributeCode - * @return mixed + * @return array|boolean */ public function getAttributeDefaultValue($attributeCode) { @@ -307,7 +316,7 @@ protected function _beforeSave() } /** - * Checks model is deleteable + * Checks model is deletable * * @return boolean */ @@ -317,19 +326,19 @@ public function isDeleteable() } /** - * Set is deleteable flag + * Set is deletable flag * * @param boolean $value * @return Mage_Catalog_Model_Abstract */ public function setIsDeleteable($value) { - $this->_isDeleteable = (boolean) $value; + $this->_isDeleteable = (bool) $value; return $this; } /** - * Checks model is deleteable + * Checks model is deletable * * @return boolean */ @@ -339,14 +348,14 @@ public function isReadonly() } /** - * Set is deleteable flag + * Set is deletable flag * * @param boolean $value * @return Mage_Catalog_Model_Abstract */ public function setIsReadonly($value) { - $this->_isReadonly = (boolean) $value; + $this->_isReadonly = (bool)$value; return $this; } diff --git a/app/code/core/Mage/Catalog/Model/Api/Resource.php b/app/code/core/Mage/Catalog/Model/Api/Resource.php index d4e86e5d5a..9cd461db80 100644 --- a/app/code/core/Mage/Catalog/Model/Api/Resource.php +++ b/app/code/core/Mage/Catalog/Model/Api/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Attribute/Backend/Customlayoutupdate.php b/app/code/core/Mage/Catalog/Model/Attribute/Backend/Customlayoutupdate.php index 092dadbd5e..6a23b8638d 100644 --- a/app/code/core/Mage/Catalog/Model/Attribute/Backend/Customlayoutupdate.php +++ b/app/code/core/Mage/Catalog/Model/Attribute/Backend/Customlayoutupdate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category.php b/app/code/core/Mage/Catalog/Model/Category.php index e5e4d915c6..6cc117925d 100644 --- a/app/code/core/Mage/Catalog/Model/Category.php +++ b/app/code/core/Mage/Catalog/Model/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -182,11 +182,6 @@ public function getTreeModelInstance() */ public function move($parentId, $afterCategoryId) { - /** - * Setting affected category ids for third party engine index refresh - */ - $this->setMovedCategoryId($this->getId()); - /** * Validate new parent category id. (category model is used for backward * compatibility in event params) @@ -201,6 +196,17 @@ public function move($parentId, $afterCategoryId) ); } + if (!$this->getId()) { + Mage::throwException( + Mage::helper('catalog')->__('Category move operation is not possible: the current category was not found.') + ); + } + + /** + * Setting affected category ids for third party engine index refresh + */ + $this->setMovedCategoryId($this->getId()); + $eventParams = array( $this->_eventObject => $this, 'parent' => $parent, @@ -586,7 +592,7 @@ private function _getAttribute($attributeCode) } else { $attribute = Mage::getSingleton('catalog/config') - ->getAttribute('catalog_category', $attributeCode); + ->getAttribute(self::ENTITY, $attributeCode); } return $attribute; } diff --git a/app/code/core/Mage/Catalog/Model/Category/Api.php b/app/code/core/Mage/Catalog/Model/Category/Api.php index 71dfdd2350..091e6e3a59 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Api.php +++ b/app/code/core/Mage/Catalog/Model/Category/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Api/V2.php b/app/code/core/Mage/Catalog/Model/Category/Api/V2.php index 8b844e74b1..d512106567 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Category/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Api.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Api.php index 5b701bb84a..1977a6e045 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Api.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Api/V2.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Api/V2.php index 22287f9088..ddd8489b9b 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php index 8b769ff1e4..1d67a5098c 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php index 7012aab682..93e8845e75 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Sortby.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Urlkey.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Urlkey.php index 4091161707..9496856da1 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Urlkey.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Urlkey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Layout.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Layout.php index 3f8f483dc1..d3511b020a 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Layout.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Mode.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Mode.php index 994a2f4817..6c0c1a355b 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Mode.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Mode.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Page.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Page.php index 3522926908..d420450244 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Page.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Sortby.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Sortby.php index 90306a82c0..c69122644a 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Sortby.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Source/Sortby.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Indexer/Flat.php b/app/code/core/Mage/Catalog/Model/Category/Indexer/Flat.php index b94744c0cd..23e11b754c 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Indexer/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Category/Indexer/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Category/Indexer/Product.php b/app/code/core/Mage/Catalog/Model/Category/Indexer/Product.php index a1d669d287..36b560d7b3 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Indexer/Product.php +++ b/app/code/core/Mage/Catalog/Model/Category/Indexer/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,6 +31,25 @@ * - Category save (changed assigned products list or category move) * - Store save (new store creation, changed store group) - require reindex all data * - Store group save (changed root category or group website) - require reindex all data + * + * @method Mage_Catalog_Model_Resource_Category_Indexer_Product _getResource() + * @method Mage_Catalog_Model_Resource_Category_Indexer_Product getResource() + * @method int getCategoryId() + * @method Mage_Catalog_Model_Category_Indexer_Product setCategoryId(int $value) + * @method int getProductId() + * @method Mage_Catalog_Model_Category_Indexer_Product setProductId(int $value) + * @method int getPosition() + * @method Mage_Catalog_Model_Category_Indexer_Product setPosition(int $value) + * @method int getIsParent() + * @method Mage_Catalog_Model_Category_Indexer_Product setIsParent(int $value) + * @method int getStoreId() + * @method Mage_Catalog_Model_Category_Indexer_Product setStoreId(int $value) + * @method int getVisibility() + * @method Mage_Catalog_Model_Category_Indexer_Product setVisibility(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Category_Indexer_Product extends Mage_Index_Model_Indexer_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Config.php b/app/code/core/Mage/Catalog/Model/Config.php index e900b6e9b9..51e50c6b7d 100644 --- a/app/code/core/Mage/Catalog/Model/Config.php +++ b/app/code/core/Mage/Catalog/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -293,7 +293,7 @@ protected function _getResource() public function getAttributesUsedInProductListing() { if (is_null($this->_usedInProductListing)) { $this->_usedInProductListing = array(); - $entityType = 'catalog_product'; + $entityType = Mage_Catalog_Model_Product::ENTITY; $attributesData = $this->_getResource() ->setStoreId($this->getStoreId()) ->getAttributesUsedInListing(); @@ -316,7 +316,7 @@ public function getAttributesUsedInProductListing() { public function getAttributesUsedForSortBy() { if (is_null($this->_usedForSortBy)) { $this->_usedForSortBy = array(); - $entityType = 'catalog_product'; + $entityType = Mage_Catalog_Model_Product::ENTITY; $attributesData = $this->_getResource() ->getAttributesUsedForSortBy(); Mage::getSingleton('eav/config') diff --git a/app/code/core/Mage/Catalog/Model/Convert.php b/app/code/core/Mage/Catalog/Model/Convert.php index cfce5196c5..c1f120ee1a 100644 --- a/app/code/core/Mage/Catalog/Model/Convert.php +++ b/app/code/core/Mage/Catalog/Model/Convert.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Catalog.php b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Catalog.php index 9d0d186a88..aab00fa0da 100644 --- a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Catalog.php +++ b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php index 852ea9c565..de628da596 100644 --- a/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php +++ b/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,6 +31,13 @@ class Mage_Catalog_Model_Convert_Adapter_Product const MULTI_DELIMITER = ' , '; const ENTITY = 'catalog_product_import'; + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'catalog_product_import'; + /** * Product model * @@ -93,8 +100,64 @@ class Mage_Catalog_Model_Convert_Adapter_Product protected $_toNumber = array(); /** - * Load product collection Id(s) + * Retrieve event prefix for adapter + * + * @return string + */ + public function getEventPrefix() + { + return $this->_eventPrefix; + } + + /** + * Affected entity ids + * + * @var array + */ + protected $_affectedEntityIds = array(); + + /** + * Store affected entity ids + * + * @param int|array $ids + * @return Mage_Catalog_Model_Convert_Adapter_Product + */ + protected function _addAffectedEntityIds($ids) + { + if (is_array($ids)) { + foreach ($ids as $id) { + $this->_addAffectedEntityIds($id); + } + } else { + $this->_affectedEntityIds[] = $ids; + } + + return $this; + } + + /** + * Retrieve affected entity ids * + * @return array + */ + public function getAffectedEntityIds() + { + return $this->_affectedEntityIds; + } + + /** + * Clear affected entity ids results + * + * @return Mage_Catalog_Model_Convert_Adapter_Product + */ + public function clearAffectedEntityIds() + { + $this->_affectedEntityIds = array(); + return $this; + } + + /** + * Load product collection Id(s) */ public function load() { @@ -273,6 +336,7 @@ public function getStoreByCode($store) if (isset($this->_stores[$store])) { return $this->_stores[$store]; } + return false; } @@ -295,6 +359,7 @@ public function getStoreById($id) if (isset($this->_storesIdCode[$id])) { return $this->getStoreByCode($this->_storesIdCode[$id]); } + return false; } @@ -390,16 +455,12 @@ public function getProduct() public function setStockItem(Mage_CatalogInventory_Model_Stock_Item $object) { $id = Mage::objects()->save($object); - //$this->_product = $object; Mage::register('Object_Cache_StockItem', $id); - - //$this->_stockItem = $object; } public function getStockItem() { return Mage::objects()->load(Mage::registry('Object_Cache_StockItem')); - //return $this->_stockItem; } public function save() @@ -419,7 +480,6 @@ public function save() ); } - //$stockItems = $this->getInventoryItems(); $stockItems = Mage::registry('current_imported_inventory'); if ($collections) foreach ($collections as $storeId=>$collection) { $this->addException(Mage::helper('catalog')->__('Records for "'.$stores[$storeId].'" store found.')); @@ -512,15 +572,15 @@ public function save() } } } - //unset(Zend::unregister('imported_stock_item')); unset($collections); + return $this; } /** * Save product (import) * - * @param array $importData + * @param array $importData * @throws Mage_Core_Exception * @return bool */ @@ -539,8 +599,7 @@ public function saveRow(array $importData) ); Mage::throwException($message); } - } - else { + } else { $store = $this->getStoreByCode($importData['store']); } @@ -561,8 +620,7 @@ public function saveRow(array $importData) if ($productId) { $product->load($productId); - } - else { + } else { $productTypes = $this->getProductTypes(); $productAttributeSets = $this->getProductAttributeSets(); @@ -640,8 +698,7 @@ public function saveRow(array $importData) if (!in_array($website->getId(), $websiteIds)) { $websiteIds[] = $website->getId(); } - } - catch (Exception $e) {} + } catch (Exception $e) {} } $product->setWebsiteIds($websiteIds); unset($websiteIds); @@ -707,8 +764,7 @@ public function saveRow(array $importData) if (isset($importData[$field])) { if (in_array($field, $this->_toNumber)) { $stockData[$field] = $this->getNumber($importData[$field]); - } - else { + } else { $stockData[$field] = $importData[$field]; } } @@ -761,13 +817,16 @@ public function saveRow(array $importData) $product->save(); + // Store affected products ids + $this->_addAffectedEntityIds($product->getId()); + return true; } /** * Silently save product (import) * - * @param array $ + * @param array $importData * @return bool */ public function saveRowSilently(array $importData) @@ -775,8 +834,7 @@ public function saveRowSilently(array $importData) try { $result = $this->saveRow($importData); return $result; - } - catch (Exception $e) { + } catch (Exception $e) { return false; } } @@ -784,14 +842,13 @@ public function saveRowSilently(array $importData) /** * Process after import data * Init indexing process after catalog product import - * */ public function finish() { /** * Back compatibility event */ - Mage::dispatchEvent('catalog_product_import_after', array()); + Mage::dispatchEvent($this->_eventPrefix . '_after', array()); $entity = new Varien_Object(); Mage::getSingleton('index/indexer')->processEntityAction( diff --git a/app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php b/app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php index 0b3e7177f4..8a74d1e507 100644 --- a/app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php +++ b/app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -211,7 +211,7 @@ public function getStoreId() return $this->_storeId; } -/** + /** * ReDefine Product Type Instance to Product * * @param Mage_Catalog_Model_Product $product @@ -260,9 +260,9 @@ public function getAttribute($code) */ public function parse() { - $data = $this->getData(); - $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId(); - $inventoryFields = array(); + $data = $this->getData(); + $entityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId(); + $inventoryFields = array(); foreach ($data as $i=>$row) { $this->setPosition('Line: '.($i+1)); diff --git a/app/code/core/Mage/Catalog/Model/Design.php b/app/code/core/Mage/Catalog/Model/Design.php index ec032a302c..a531614b2a 100644 --- a/app/code/core/Mage/Catalog/Model/Design.php +++ b/app/code/core/Mage/Catalog/Model/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Entity/Attribute.php b/app/code/core/Mage/Catalog/Model/Entity/Attribute.php index 73f5d74c97..74037c874f 100644 --- a/app/code/core/Mage/Catalog/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Entity/Attribute.php @@ -20,13 +20,54 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Product attribute extension with event dispatching * + * @method Mage_Catalog_Model_Resource_Attribute _getResource() + * @method Mage_Catalog_Model_Resource_Attribute getResource() + * @method string getFrontendInputRenderer() + * @method Mage_Catalog_Model_Entity_Attribute setFrontendInputRenderer(string $value) + * @method int setIsGlobal(int $value) + * @method int getIsVisible() + * @method int setIsVisible(int $value) + * @method int getIsSearchable() + * @method Mage_Catalog_Model_Entity_Attribute setIsSearchable(int $value) + * @method int getSearchWeight() + * @method Mage_Catalog_Model_Entity_Attribute setSearchWeight(int $value) + * @method int getIsFilterable() + * @method Mage_Catalog_Model_Entity_Attribute setIsFilterable(int $value) + * @method int getIsComparable() + * @method Mage_Catalog_Model_Entity_Attribute setIsComparable(int $value) + * @method Mage_Catalog_Model_Entity_Attribute setIsVisibleOnFront(int $value) + * @method int getIsHtmlAllowedOnFront() + * @method Mage_Catalog_Model_Entity_Attribute setIsHtmlAllowedOnFront(int $value) + * @method int getIsUsedForPriceRules() + * @method Mage_Catalog_Model_Entity_Attribute setIsUsedForPriceRules(int $value) + * @method int getIsFilterableInSearch() + * @method Mage_Catalog_Model_Entity_Attribute setIsFilterableInSearch(int $value) + * @method int getUsedInProductListing() + * @method Mage_Catalog_Model_Entity_Attribute setUsedInProductListing(int $value) + * @method int getUsedForSortBy() + * @method Mage_Catalog_Model_Entity_Attribute setUsedForSortBy(int $value) + * @method int getIsConfigurable() + * @method Mage_Catalog_Model_Entity_Attribute setIsConfigurable(int $value) + * @method string getApplyTo() + * @method Mage_Catalog_Model_Entity_Attribute setApplyTo(string $value) + * @method int getIsVisibleInAdvancedSearch() + * @method Mage_Catalog_Model_Entity_Attribute setIsVisibleInAdvancedSearch(int $value) + * @method int getPosition() + * @method Mage_Catalog_Model_Entity_Attribute setPosition(int $value) + * @method int getIsWysiwygEnabled() + * @method Mage_Catalog_Model_Entity_Attribute setIsWysiwygEnabled(int $value) + * @method int getIsUsedForPromoRules() + * @method Mage_Catalog_Model_Entity_Attribute setIsUsedForPromoRules(int $value) + * + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute @@ -42,6 +83,9 @@ class Mage_Catalog_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribut */ protected function _beforeSave() { + if ($this->_getResource()->isUsedBySuperProducts($this)) { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('This attribute is used in configurable products')); + } $this->setData('modulePrefix', self::MODULE_NAME); return parent::_beforeSave(); } diff --git a/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php b/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php index 722fd98c1a..58028a8383 100644 --- a/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php +++ b/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php index 14e368bf80..0917b98203 100644 --- a/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Entity/Product/Attribute/Frontend/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Index.php b/app/code/core/Mage/Catalog/Model/Index.php index 4bd9621930..7c347ec6be 100644 --- a/app/code/core/Mage/Catalog/Model/Index.php +++ b/app/code/core/Mage/Catalog/Model/Index.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Indexer/Url.php b/app/code/core/Mage/Catalog/Model/Indexer/Url.php index b17f5c6f0c..aa7ab758df 100644 --- a/app/code/core/Mage/Catalog/Model/Indexer/Url.php +++ b/app/code/core/Mage/Catalog/Model/Indexer/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer.php b/app/code/core/Mage/Catalog/Model/Layer.php index e7bb52119a..ee17087000 100644 --- a/app/code/core/Mage/Catalog/Model/Layer.php +++ b/app/code/core/Mage/Catalog/Model/Layer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -222,12 +222,10 @@ public function getFilterableAttributes() if (!$setIds) { return array(); } - /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */ - $collection = Mage::getResourceModel('catalog/product_attribute_collection') - ->setItemObjectClass('catalog/resource_eav_attribute'); - - $collection->getSelect()->distinct(true); + /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */ + $collection = Mage::getResourceModel('catalog/product_attribute_collection'); $collection + ->setItemObjectClass('catalog/resource_eav_attribute') ->setAttributeSetFilter($setIds) ->addStoreLabel(Mage::app()->getStore()->getId()) ->setOrder('position', 'ASC'); diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php index 1854152acc..29fb8fcfda 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php index 23dd222e9c..534eafb6de 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php index 747f0a6dfb..ba03020f87 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php index 875017c189..d656cd3977 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php index 489f2fa749..50cc94afd7 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php index cd0143a578..b697ef264f 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Layer/State.php b/app/code/core/Mage/Catalog/Model/Layer/State.php index 7cea65d0eb..7b592fb3f5 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/State.php +++ b/app/code/core/Mage/Catalog/Model/Layer/State.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Observer.php b/app/code/core/Mage/Catalog/Model/Observer.php index 12941014eb..4a3adc3237 100644 --- a/app/code/core/Mage/Catalog/Model/Observer.php +++ b/app/code/core/Mage/Catalog/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product.php b/app/code/core/Mage/Catalog/Model/Product.php index 301ac667a6..107c47dd2f 100644 --- a/app/code/core/Mage/Catalog/Model/Product.php +++ b/app/code/core/Mage/Catalog/Model/Product.php @@ -20,13 +20,16 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog product model * + * @method Mage_Catalog_Model_Resource_Product getResource() + * @method Mage_Catalog_Model_Resource_Product _getResource() + * * @category Mage * @package Mage_Catalog * @author Magento Core Team @@ -107,6 +110,18 @@ protected function _construct() $this->_init('catalog/product'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('catalog')->getOldFieldMap(); + return $this; + } + /** * Retrieve Store Id * @@ -128,7 +143,7 @@ public function getStoreId() public function getResourceCollection() { if (empty($this->_resourceCollectionName)) { - Mage::throwException(Mage::helper('core')->__('The model collection resource name is not defined.')); + Mage::throwException(Mage::helper('catalog')->__('The model collection resource name is not defined.')); } $collection = Mage::getResourceModel($this->_resourceCollectionName); $collection->setStoreId($this->getStoreId()); @@ -1224,6 +1239,24 @@ public function isAvailable() return $this->getTypeInstance(true)->isSalable($this); } + /** + * Is product salable detecting by product type + * + * @return bool + */ + public function getIsSalable() + { + $productType = $this->getTypeInstance(true); + if (is_callable(array($productType, 'getIsSalable'))) { + return $this->getTypeInstance(true)->getIsSalable($this); + } + if ($this->hasData('is_salable')) { + return $this->getData('is_salable'); + } + + return $this->isSalable(); + } + /** * Check is a virtual product * Data helper wraper @@ -1336,10 +1369,12 @@ public function toArray(array $arrAttributes=array()) public function fromArray($data) { if (isset($data['stock_item'])) { - $stockItem = Mage::getModel('cataloginventory/stock_item') - ->setData($data['stock_item']) - ->setProduct($this); - $this->setStockItem($stockItem); + if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { + $stockItem = Mage::getModel('cataloginventory/stock_item') + ->setData($data['stock_item']) + ->setProduct($this); + $this->setStockItem($stockItem); + } unset($data['stock_item']); } $this->setData($data); @@ -1591,29 +1626,51 @@ public function getDefaultAttributeSetId() return $this->getResource()->getEntityType()->getDefaultAttributeSetId(); } + /** + * Return Catalog Product Image helper instance + * + * @return Mage_Catalog_Helper_Image + */ + protected function _getImageHelper() + { + return Mage::helper('catalog/image'); + } /** - * Deprecated since 1.1.5 + * Return re-sized image URL + * + * @deprecated since 1.1.5 + * @return string */ public function getImageUrl() { - return (string)Mage::helper('catalog/image')->init($this, 'image')->resize(265); + return (string)$this->_getImageHelper()->init($this, 'image')->resize(265); } /** - * Deprecated since 1.1.5 + * Return re-sized small image URL + * + * @deprecated since 1.1.5 + * @param int $width + * @param int $height + * @return string */ public function getSmallImageUrl($width = 88, $height = 77) { - return (string)Mage::helper('catalog/image')->init($this, 'small_image')->resize($width, $height); + return (string)$this->_getImageHelper()->init($this, 'small_image')->resize($width, $height); } /** - * Deprecated since 1.1.5 + * Return re-sized thumbnail image URL + * + * @deprecated since 1.1.5 + * @param int $width + * @param int $height + * @return string */ public function getThumbnailUrl($width = 75, $height = 75) { - return (string)Mage::helper('catalog/image')->init($this, 'thumbnail')->resize($width, $height); + return (string)$this->_getImageHelper()->init($this, 'thumbnail')->resize($width, $height); } /** @@ -1644,7 +1701,7 @@ public function getReservedAttributes() /** * Check whether attribute reserved or not * - * @param Mage_Eav_Model_Entity_Attribute $attribute Attribute model object + * @param Mage_Catalog_Model_Entity_Attribute $attribute Attribute model object * @return boolean */ public function isReservedAttribute ($attribute) @@ -1669,15 +1726,6 @@ public function setOrigData($key=null, $data=null) return $this; } - /** - * @deprecated - * @see Mage_Sales_Model_Observer::substractQtyFromQuotes() - */ - protected function _substractQtyFromQuotes() - { - // kept for legacy purposes - } - /** * Reset all model data * @@ -1840,4 +1888,14 @@ protected function _clearOptionReferences() return $this; } + + /** + * Retrieve product entities info as array + * + * @return array + */ + public function getProductEntitiesInfo() + { + return $this->_getResource()->getProductEntitiesInfo(); + } } diff --git a/app/code/core/Mage/Catalog/Model/Product/Action.php b/app/code/core/Mage/Catalog/Model/Product/Action.php index 1f970b5bc7..fc60f52d39 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Action.php +++ b/app/code/core/Mage/Catalog/Model/Product/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Api.php b/app/code/core/Mage/Catalog/Model/Product/Api.php index e259e5e4b3..dd7a853e09 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php index 85817f0ad5..e1afaa7dd8 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php index b9ff2a171a..c01c66a31a 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api/V2.php index 901ff1da28..d577f73458 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Boolean.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Boolean.php index bed6f49299..97657baac2 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Boolean.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php index 16e8e48369..077bfdc04d 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Price.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Price.php index 511fb18af1..04dd6f788d 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Recurring.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Recurring.php index 2fa5f3865b..d93615a549 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Recurring.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Recurring.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php index 7e69c4bef2..528115947f 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Sku.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Startdate.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Startdate.php index 0f97fe8c53..95994762aa 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Startdate.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Startdate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Tierprice.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Tierprice.php index 9d054e046d..6d1ac5d71e 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Tierprice.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Tierprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Urlkey.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Urlkey.php index e6815b767b..49cb401183 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Urlkey.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Urlkey.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Frontend/Image.php index 64159301cd..0f8c27669b 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Frontend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Frontend/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php index 068a69d0dd..01311b3922 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api/V2.php index a280df54c1..e0f2ba5e8c 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api.php index 02eb81c567..c466fb2a71 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api/V2.php index 08b13290e7..517251b6e5 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Set/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Boolean.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Boolean.php index 7851b9c77b..5a9219df6a 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Boolean.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Layout.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Layout.php index d343f32312..1601ffa457 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Layout.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api.php index d7d9d3bb9c..ac35e7d4ca 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api/V2.php index 08bd9675c0..f44d53ca33 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php b/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php index 8fa658624d..9d81cf3007 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php +++ b/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Catalog Compare Item Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Compare_Item _getResource() + * @method Mage_Catalog_Model_Resource_Product_Compare_Item getResource() + * @method Mage_Catalog_Model_Product_Compare_Item setVisitorId(int $value) + * @method Mage_Catalog_Model_Product_Compare_Item setCustomerId(int $value) + * @method int getProductId() + * @method Mage_Catalog_Model_Product_Compare_Item setProductId(int $value) + * @method int getStoreId() + * @method Mage_Catalog_Model_Product_Compare_Item setStoreId(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Compare_Item extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Product/Compare/List.php b/app/code/core/Mage/Catalog/Model/Product/Compare/List.php index 5be469479d..ca44cc9ee6 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Compare/List.php +++ b/app/code/core/Mage/Catalog/Model/Product/Compare/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Condition.php b/app/code/core/Mage/Catalog/Model/Product/Condition.php index 3d1c49bff8..e814f71221 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Condition.php +++ b/app/code/core/Mage/Catalog/Model/Product/Condition.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Condition/Interface.php b/app/code/core/Mage/Catalog/Model/Product/Condition/Interface.php index f5a149d9eb..df5a4ef6d0 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Condition/Interface.php +++ b/app/code/core/Mage/Catalog/Model/Product/Condition/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Interface.php b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Interface.php index ccca6e736e..0b4aebfaa4 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Interface.php +++ b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option.php b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option.php index 163914c055..acb9492bde 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option.php +++ b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option/Interface.php b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option/Interface.php index abd4c4603c..146cf4e9b3 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option/Interface.php +++ b/app/code/core/Mage/Catalog/Model/Product/Configuration/Item/Option/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Flat/Flag.php b/app/code/core/Mage/Catalog/Model/Product/Flat/Flag.php index 2461988ca7..9eaf1058f4 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Flat/Flag.php +++ b/app/code/core/Mage/Catalog/Model/Product/Flat/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php b/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php index 7c3937c6eb..b2f9ffdd7a 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php +++ b/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,28 @@ /** * Catalog Product Flat Indexer Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Flat_Indexer _getResource() + * @method Mage_Catalog_Model_Resource_Product_Flat_Indexer getResource() + * @method int getEntityTypeId() + * @method Mage_Catalog_Model_Product_Flat_Indexer setEntityTypeId(int $value) + * @method int getAttributeSetId() + * @method Mage_Catalog_Model_Product_Flat_Indexer setAttributeSetId(int $value) + * @method string getTypeId() + * @method Mage_Catalog_Model_Product_Flat_Indexer setTypeId(string $value) + * @method string getSku() + * @method Mage_Catalog_Model_Product_Flat_Indexer setSku(string $value) + * @method int getHasOptions() + * @method Mage_Catalog_Model_Product_Flat_Indexer setHasOptions(int $value) + * @method int getRequiredOptions() + * @method Mage_Catalog_Model_Product_Flat_Indexer setRequiredOptions(int $value) + * @method string getCreatedAt() + * @method Mage_Catalog_Model_Product_Flat_Indexer setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Catalog_Model_Product_Flat_Indexer setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Flat_Indexer extends Mage_Core_Model_Abstract { @@ -43,16 +62,6 @@ protected function _construct() $this->_init('catalog/product_flat_indexer'); } - /** - * Get resource instance - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - protected function _getResource() - { - return parent::_getResource(); - } - /** * Rebuild Catalog Product Flat Data * diff --git a/app/code/core/Mage/Catalog/Model/Product/Flat/Observer.php b/app/code/core/Mage/Catalog/Model/Product/Flat/Observer.php index 00e96d4ad2..090924e6c6 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Flat/Observer.php +++ b/app/code/core/Mage/Catalog/Model/Product/Flat/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Image.php b/app/code/core/Mage/Catalog/Model/Product/Image.php index 615514aceb..e2cdd81069 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Image.php +++ b/app/code/core/Mage/Catalog/Model/Product/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Indexer/Eav.php b/app/code/core/Mage/Catalog/Model/Product/Indexer/Eav.php index c470047962..db04c126ed 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Indexer/Eav.php +++ b/app/code/core/Mage/Catalog/Model/Product/Indexer/Eav.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,19 @@ /** * Catalog Product Eav Indexer Model * - * @category Mage - * @package Mage_Catalog + * @method Mage_Catalog_Model_Resource_Product_Indexer_Eav _getResource() + * @method Mage_Catalog_Model_Resource_Product_Indexer_Eav getResource() + * @method Mage_Catalog_Model_Product_Indexer_Eav setEntityId(int $value) + * @method int getAttributeId() + * @method Mage_Catalog_Model_Product_Indexer_Eav setAttributeId(int $value) + * @method int getStoreId() + * @method Mage_Catalog_Model_Product_Indexer_Eav setStoreId(int $value) + * @method int getValue() + * @method Mage_Catalog_Model_Product_Indexer_Eav setValue(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Indexer_Eav extends Mage_Index_Model_Indexer_Abstract { @@ -123,7 +134,7 @@ protected function _attributeIsIndexable($attribute) { if (!$attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute) { $attribute = Mage::getSingleton('eav/config') - ->getAttribute('catalog_product', $attribute); + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attribute); } return $attribute->isIndexable(); diff --git a/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php b/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php index 3d20f15128..7fa42cac61 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Catalog_Model_Product_Indexer_Flat extends Mage_Index_Model_Indexer_Abstract diff --git a/app/code/core/Mage/Catalog/Model/Product/Indexer/Price.php b/app/code/core/Mage/Catalog/Model/Product/Indexer/Price.php index f3addaf8ee..15a11bf922 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Indexer/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Indexer/Price.php @@ -20,9 +20,36 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Catalog_Model_Resource_Product_Indexer_Price _getResource() + * @method Mage_Catalog_Model_Resource_Product_Indexer_Price getResource() + * @method Mage_Catalog_Model_Product_Indexer_Price setEntityId(int $value) + * @method int getCustomerGroupId() + * @method Mage_Catalog_Model_Product_Indexer_Price setCustomerGroupId(int $value) + * @method int getWebsiteId() + * @method Mage_Catalog_Model_Product_Indexer_Price setWebsiteId(int $value) + * @method int getTaxClassId() + * @method Mage_Catalog_Model_Product_Indexer_Price setTaxClassId(int $value) + * @method float getPrice() + * @method Mage_Catalog_Model_Product_Indexer_Price setPrice(float $value) + * @method float getFinalPrice() + * @method Mage_Catalog_Model_Product_Indexer_Price setFinalPrice(float $value) + * @method float getMinPrice() + * @method Mage_Catalog_Model_Product_Indexer_Price setMinPrice(float $value) + * @method float getMaxPrice() + * @method Mage_Catalog_Model_Product_Indexer_Price setMaxPrice(float $value) + * @method float getTierPrice() + * @method Mage_Catalog_Model_Product_Indexer_Price setTierPrice(float $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team + */ class Mage_Catalog_Model_Product_Indexer_Price extends Mage_Index_Model_Indexer_Abstract { /** diff --git a/app/code/core/Mage/Catalog/Model/Product/Link.php b/app/code/core/Mage/Catalog/Model/Product/Link.php index 1a325f2cc3..3c7bfea250 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Link.php +++ b/app/code/core/Mage/Catalog/Model/Product/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,17 @@ /** * Catalog product link model * - * @category Mage - * @package Mage_Catalog + * @method Mage_Catalog_Model_Resource_Product_Link _getResource() + * @method Mage_Catalog_Model_Resource_Product_Link getResource() + * @method int getProductId() + * @method Mage_Catalog_Model_Product_Link setProductId(int $value) + * @method int getLinkedProductId() + * @method Mage_Catalog_Model_Product_Link setLinkedProductId(int $value) + * @method int getLinkTypeId() + * @method Mage_Catalog_Model_Product_Link setLinkTypeId(int $value) + * + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Product_Link extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Catalog/Model/Product/Link/Api.php b/app/code/core/Mage/Catalog/Model/Product/Link/Api.php index 2b80c15b13..d8006bc6ff 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Link/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Link/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php index 205edde51c..53d35d27c7 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Link/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Media/Config.php b/app/code/core/Mage/Catalog/Model/Product/Media/Config.php index 671fafde88..0f1f7e43dd 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Media/Config.php +++ b/app/code/core/Mage/Catalog/Model/Product/Media/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option.php b/app/code/core/Mage/Catalog/Model/Product/Option.php index 9c9e35c3ff..c7b011cec3 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option.php @@ -20,16 +20,37 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog product option model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Option _getResource() + * @method Mage_Catalog_Model_Resource_Product_Option getResource() + * @method int getProductId() + * @method Mage_Catalog_Model_Product_Option setProductId(int $value) + * @method string getType() + * @method Mage_Catalog_Model_Product_Option setType(string $value) + * @method int getIsRequire() + * @method Mage_Catalog_Model_Product_Option setIsRequire(int $value) + * @method string getSku() + * @method Mage_Catalog_Model_Product_Option setSku(string $value) + * @method int getMaxCharacters() + * @method Mage_Catalog_Model_Product_Option setMaxCharacters(int $value) + * @method string getFileExtension() + * @method Mage_Catalog_Model_Product_Option setFileExtension(string $value) + * @method int getImageSizeX() + * @method Mage_Catalog_Model_Product_Option setImageSizeX(int $value) + * @method int getImageSizeY() + * @method Mage_Catalog_Model_Product_Option setImageSizeY(int $value) + * @method int getSortOrder() + * @method Mage_Catalog_Model_Product_Option setSortOrder(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Option extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php b/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php index 6b0856606c..64885d4e37 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php index f08b2ccc0b..bdd2b8523a 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php index 7587c35e06..9d3f83e22c 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php index 569423514d..e61201af65 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php index 14a56c9ffa..f620bb624f 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php index f7be288758..60a98d530f 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Value.php b/app/code/core/Mage/Catalog/Model/Product/Option/Value.php index e649f22afd..71afa4afef 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Value.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Value.php @@ -20,16 +20,25 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog product option select type model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Option_Value _getResource() + * @method Mage_Catalog_Model_Resource_Product_Option_Value getResource() + * @method int getOptionId() + * @method Mage_Catalog_Model_Product_Option_Value setOptionId(int $value) + * @method string getSku() + * @method Mage_Catalog_Model_Product_Option_Value setSku(string $value) + * @method int getSortOrder() + * @method Mage_Catalog_Model_Product_Option_Value setSortOrder(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Option_Value extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Product/Status.php b/app/code/core/Mage/Catalog/Model/Product/Status.php index 1081ef9dba..02e069eb63 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Status.php +++ b/app/code/core/Mage/Catalog/Model/Product/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Product status functionality model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Status _getResource() + * @method Mage_Catalog_Model_Resource_Product_Status getResource() + * @method int getProductId() + * @method Mage_Catalog_Model_Product_Status setProductId(int $value) + * @method int getStoreId() + * @method Mage_Catalog_Model_Product_Status setStoreId(int $value) + * @method int getVisibility() + * @method Mage_Catalog_Model_Product_Status setVisibility(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Status extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Product/Type.php b/app/code/core/Mage/Catalog/Model/Product/Type.php index 94be6e04a4..ea32bae4c0 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 3a87290a1b..ac23f965a0 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -744,7 +744,7 @@ public function getOptionSku($product = null, $sku='') $group = $option->groupFactory($option->getType()) ->setOption($option)->setListener(new Varien_Object()); - + if ($optionSku = $group->getOptionSku($confItemOption->getValue(), $skuDelimiter)) { $sku .= $skuDelimiter . $optionSku; } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Api.php b/app/code/core/Mage/Catalog/Model/Product/Type/Api.php index a5ee89dc21..7b15e4be37 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Api/V2.php b/app/code/core/Mage/Catalog/Model/Product/Type/Api/V2.php index 251a82e363..95f2e73360 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Api/V2.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php index fe1a65d28f..308c4daa90 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -447,20 +447,31 @@ public function save($product = null) public function isSalable($product = null) { $salable = parent::isSalable($product); - if (!is_null($salable)) { - return $salable; - } - $salable = false; - foreach ($this->getUsedProducts(null, $product) as $child) { - if ($child->isSalable()) { - $salable = true; - break; + if ($salable !== false) { + $salable = false; + foreach ($this->getUsedProducts(null, $product) as $child) { + if ($child->isSalable()) { + $salable = true; + break; + } } } + return $salable; } + /** + * Chack is product available for sale + * is alias to isSalable for compatibility + * + * @return bool + */ + public function getIsSalable($product = null) + { + return $this->isSalable($product); + } + /** * Retrieve used product by attribute values * $attrbutesInfo = array( @@ -563,7 +574,11 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process $product->addCustomOption('product_qty_'.$subProduct->getId(), 1, $subProduct); $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct); - $_result = $subProduct->getTypeInstance(true)->_prepareProduct($buyRequest, $subProduct, $processMode); + $_result = $subProduct->getTypeInstance(true)->_prepareProduct( + $buyRequest, + $subProduct, + $processMode + ); if (is_string($_result) && !is_array($_result)) { return $_result; } @@ -586,7 +601,8 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process } $_result[0]->setParentProductId($product->getId()) - // add custom option to simple product for protection of process when we add simple product separately + // add custom option to simple product for protection of process + //when we add simple product separately ->addCustomOption('parent_product_id', $product->getId()); if ($this->_isStrictProcessMode($processMode)) { $_result[0]->setCartQty(1); @@ -713,7 +729,9 @@ public function hasOptions($product = null) */ public function getWeight($product = null) { - if ($this->getProduct($product)->hasCustomOptions() && ($simpleProductOption = $this->getProduct($product)->getCustomOption('simple_product'))) { + if ($this->getProduct($product)->hasCustomOptions() && + ($simpleProductOption = $this->getProduct($product)->getCustomOption('simple_product')) + ) { $simpleProduct = $simpleProductOption->getProduct($product); if ($simpleProduct) { return $simpleProduct->getWeight(); diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Attribute.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Attribute.php index 8a53ba6926..ce67f1a1af 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Catalog Configurable Product Attribute Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute _getResource() + * @method Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute getResource() + * @method int getProductId() + * @method Mage_Catalog_Model_Product_Type_Configurable_Attribute setProductId(int $value) + * @method int getAttributeId() + * @method Mage_Catalog_Model_Product_Type_Configurable_Attribute setAttributeId(int $value) + * @method int getPosition() + * @method Mage_Catalog_Model_Product_Type_Configurable_Attribute setPosition(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Type_Configurable_Attribute extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php index 1b2c57e303..7303bcb8e9 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Grouped.php b/app/code/core/Mage/Catalog/Model/Product/Type/Grouped.php index 9f671401e4..2de6fc5756 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Grouped.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -323,7 +323,7 @@ protected function _prepareProduct(Varien_Object $buyRequest, $product, $process if (!$isStrictProcessMode || count($associatedProductsInfo)) { $product->addCustomOption('product_type', self::TYPE_CODE, $product); - $product->addCustomOption('info_buyRequest',serialize($buyRequest)); + $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); $products[] = $product; } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Grouped/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Grouped/Price.php index 143280ab9a..d670f12962 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Grouped/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Grouped/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php index c7b1aab990..830e76ee84 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Simple.php b/app/code/core/Mage/Catalog/Model/Product/Type/Simple.php index 89b8f91b0f..f527948789 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Simple.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Virtual.php b/app/code/core/Mage/Catalog/Model/Product/Type/Virtual.php index 967efc1190..17cd87564b 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Virtual.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Virtual.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Url.php b/app/code/core/Mage/Catalog/Model/Product/Url.php index 9673a5dfea..2076ff9dcc 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Url.php +++ b/app/code/core/Mage/Catalog/Model/Product/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Product/Visibility.php b/app/code/core/Mage/Catalog/Model/Product/Visibility.php index 14cff3a450..8760296382 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Visibility.php +++ b/app/code/core/Mage/Catalog/Model/Product/Visibility.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -193,11 +193,12 @@ static public function getOptionText($optionId) public function getFlatColums() { return array($this->getAttribute()->getAttributeCode() => array( - 'type' => 'tinyint', + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => 'Catalog Product Visibility ' . $this->getAttribute()->getAttributeCode() . ' column' )); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Website.php b/app/code/core/Mage/Catalog/Model/Product/Website.php index 1d6f9600b2..6329605461 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Website.php +++ b/app/code/core/Mage/Catalog/Model/Product/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,14 @@ /** * Catalog Product Website Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Product_Website _getResource() + * @method Mage_Catalog_Model_Resource_Product_Website getResource() + * @method int getWebsiteId() + * @method Mage_Catalog_Model_Product_Website setWebsiteId(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Product_Website extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Catalog/Model/Resource/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php new file mode 100755 index 0000000000..d2609eef33 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php @@ -0,0 +1,689 @@ + + */ +abstract class Mage_Catalog_Model_Resource_Abstract extends Mage_Eav_Model_Entity_Abstract +{ + /** + * Store firstly set attributes to filter selected attributes when used specific store_id + * + * @var array + */ + protected $_attributes = array(); + + /** + * Redeclare attribute model + * + * @return string + */ + protected function _getDefaultAttributeModel() + { + return 'catalog/resource_eav_attribute'; + } + + /** + * Returns default Store ID + * + * @return int + */ + public function getDefaultStoreId() + { + return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; + } + + /** + * Check whether the attribute is Applicable to the object + * + * @param Varien_Object $object + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @return boolean + */ + protected function _isApplicableAttribute($object, $attribute) + { + $applyTo = $attribute->getApplyTo(); + return count($applyTo) == 0 || in_array($object->getTypeId(), $applyTo); + } + + /** + * Check whether attribute instance (attribute, backend, frontend or source) has method and applicable + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|Mage_Eav_Model_Entity_Attribute_Backend_Abstract|Mage_Eav_Model_Entity_Attribute_Frontend_Abstract|Mage_Eav_Model_Entity_Attribute_Source_Abstract $instance + * @param string $method + * @param array $args array of arguments + * @return boolean + */ + protected function _isCallableAttributeInstance($instance, $method, $args) + { + if ($instance instanceof Mage_Eav_Model_Entity_Attribute_Backend_Abstract + && ($method == 'beforeSave' || $method = 'afterSave') + ) { + $attributeCode = $instance->getAttribute()->getAttributeCode(); + if (isset($args[0]) && $args[0] instanceof Varien_Object && $args[0]->getData($attributeCode) === false) { + return false; + } + } + + return parent::_isCallableAttributeInstance($instance, $method, $args); + } + + + + /** + * Retrieve select object for loading entity attributes values + * Join attribute store value + * + * @param Varien_Object $object + * @param string $table + * @return Varien_Db_Select + */ + protected function _getLoadAttributesSelect($object, $table) + { + /** + * This condition is applicable for all cases when we was work in not single + * store mode, customize some value per specific store view and than back + * to single store mode. We should load correct values + */ + if (Mage::app()->isSingleStoreMode()) { + $storeId = (int)Mage::app()->getStore(true)->getId(); + } else { + $storeId = (int)$object->getStoreId(); + } + + $setId = $object->getAttributeSetId(); + $storeIds = array($this->getDefaultStoreId()); + if ($storeId != $this->getDefaultStoreId()) { + $storeIds[] = $storeId; + } + + $select = $this->_getReadAdapter()->select() + ->from(array('attr_table' => $table), array()) + ->where("attr_table.{$this->getEntityIdField()} = ?", $object->getId()) + ->where('attr_table.store_id IN (?)', $storeIds); + if ($setId) { + $select->join( + array('set_table' => $this->getTable('eav/entity_attribute')), + $this->_getReadAdapter()->quoteInto('attr_table.attribute_id = set_table.attribute_id' . + ' AND set_table.attribute_set_id = ?', $setId), + array() + ); + } + return $select; + } + + /** + * Adds Columns prepared for union + * + * @param Varien_Db_Select $select + * @param string $table + * @param string $type + * @return Varien_Db_Select + */ + protected function _addLoadAttributesSelectFields($select, $table, $type) + { + $select->columns( + Mage::getResourceHelper('catalog')->attributeSelectFields('attr_table', $type) + ); + return $select; + } + + /** + * Prepare select object for loading entity attributes values + * + * @param array $selects + * @return Varien_Db_Select + */ + protected function _prepareLoadSelect(array $selects) + { + $select = parent::_prepareLoadSelect($selects); + $select->order('store_id'); + return $select; + } + + /** + * Initialize attribute value for object + * + * @param Mage_Catalog_Model_Abstract $object + * @param array $valueRow + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _setAttributeValue($object, $valueRow) + { + $attribute = $this->getAttribute($valueRow['attribute_id']); + if ($attribute) { + $attributeCode = $attribute->getAttributeCode(); + $isDefaultStore = $valueRow['store_id'] == $this->getDefaultStoreId(); + if (isset($this->_attributes[$valueRow['attribute_id']])) { + if ($isDefaultStore) { + $object->setAttributeDefaultValue($attributeCode, $valueRow['value']); + } else { + $object->setAttributeDefaultValue( + $attributeCode, + $this->_attributes[$valueRow['attribute_id']]['value'] + ); + } + } else { + $this->_attributes[$valueRow['attribute_id']] = $valueRow; + } + + $value = $valueRow['value']; + $valueId = $valueRow['value_id']; + + $object->setData($attributeCode, $value); + if (!$isDefaultStore) { + $object->setExistsStoreValueFlag($attributeCode); + } + $attribute->getBackend()->setValueId($valueId); + } + + return $this; + } + + /** + * Insert or Update attribute data + * + * @param Mage_Catalog_Model_Abstract $object + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param mixed $value + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _saveAttributeValue($object, $attribute, $value) + { + $write = $this->_getWriteAdapter(); + $storeId = (int)Mage::app()->getStore($object->getStoreId())->getId(); + $table = $attribute->getBackend()->getTable(); + + /** + * If we work in single store mode all values should be saved just + * for default store id + * In this case we clear all not default values + */ + if (Mage::app()->isSingleStoreMode()) { + $storeId = $this->getDefaultStoreId(); + $write->delete($table, array( + 'attribute_id = ?' => $attribute->getAttributeId(), + 'entity_id = ?' => $object->getEntityId(), + 'store_id <> ?' => $storeId + )); + } + + $data = new Varien_Object(array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getAttributeId(), + 'store_id' => $storeId, + 'entity_id' => $object->getEntityId(), + 'value' => $this->_prepareValueForSave($value, $attribute) + )); + $bind = $this->_prepareDataForTable($data, $table); + + if ($attribute->isScopeStore()) { + /** + * Update attribute value for store + */ + $this->_attributeValuesToSave[$table][] = $bind; + } else if ($attribute->isScopeWebsite() && $storeId != $this->getDefaultStoreId()) { + /** + * Update attribute value for website + */ + $storeIds = Mage::app()->getStore($storeId)->getWebsite()->getStoreIds(true); + foreach ($storeIds as $storeId) { + $bind['store_id'] = (int)$storeId; + $this->_attributeValuesToSave[$table][] = $bind; + } + } else { + /** + * Update global attribute value + */ + $bind['store_id'] = $this->getDefaultStoreId(); + $this->_attributeValuesToSave[$table][] = $bind; + } + + return $this; + } + + /** + * Insert entity attribute value + * + * @param Varien_Object $object + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param mixed $value + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _insertAttribute($object, $attribute, $value) + { + /** + * save required attributes in global scope every time if store id different from default + */ + $storeId = (int)Mage::app()->getStore($object->getStoreId())->getId(); + if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { + $table = $attribute->getBackend()->getTable(); + $data = new Varien_Object(array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getAttributeId(), + 'store_id' => $this->getDefaultStoreId(), + 'entity_id' => $object->getEntityId(), + 'value' => $this->_prepareValueForSave($value, $attribute) + )); + $bind = $this->_prepareDataForTable($data, $table); + $this->_getWriteAdapter()->select()->insertIgnoreFromSelect($table, $bind); + } + + return $this->_saveAttributeValue($object, $attribute, $value); + } + + /** + * Update entity attribute value + * + * @deprecated after 1.5.1.0 + * @see Mage_Catalog_Model_Resource_Abstract::_saveAttributeValue() + * + * @param Varien_Object $object + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param mixed $valueId + * @param mixed $value + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _updateAttribute($object, $attribute, $valueId, $value) + { + return $this->_saveAttributeValue($object, $attribute, $value); + } + + /** + * Update attribute value for specific store + * + * @param Mage_Catalog_Model_Abstract $object + * @param object $attribute + * @param mixed $value + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _updateAttributeForStore($object, $attribute, $value, $storeId) + { + $adapter = $this->_getWriteAdapter(); + $table = $attribute->getBackend()->getTable(); + $entityIdField = $attribute->getBackend()->getEntityIdField(); + $select = $adapter->select() + ->from($table, 'value_id') + ->where('entity_type_id = :entity_type_id') + ->where("$entityIdField = :entity_field_id") + ->where('store_id = :store_id') + ->where('attribute_id = :attribute_id'); + $bind = array( + 'entity_type_id' => $object->getEntityTypeId(), + 'entity_field_id' => $object->getId(), + 'store_id' => $storeId, + 'attribute_id' => $attribute->getId() + ); + $valueId = $adapter->fetchOne($select, $bind); + /** + * When value for store exist + */ + if ($valueId) { + $bind = array('value' => $this->_prepareValueForSave($value, $attribute)); + $where = array('value_id = ?' => (int)$valueId); + + $adapter->update($table, $bind, $where); + } else { + $bind = array( + $idField => (int)$object->getId(), + 'entity_type_id' => (int)$object->getEntityTypeId(), + 'attribute_id' => (int)$attribute->getId(), + 'value' => $this->_prepareValueForSave($value, $attribute), + 'store_id' => (int)$storeId + ); + + $adapter->insert($table, $bind); + } + + return $this; + } + + /** + * Delete entity attribute values + * + * @param Varien_Object $object + * @param string $table + * @param array $info + * @return Mage_Catalog_Model_Resource_Abstract + */ + protected function _deleteAttributes($object, $table, $info) + { + $adapter = $this->_getWriteAdapter(); + $entityIdField = $this->getEntityIdField(); + $globalValues = array(); + $websiteAttributes = array(); + $storeAttributes = array(); + + /** + * Separate attributes by scope + */ + foreach ($info as $itemData) { + $attribute = $this->getAttribute($itemData['attribute_id']); + if ($attribute->isScopeStore()) { + $storeAttributes[] = (int)$itemData['attribute_id']; + } elseif ($attribute->isScopeWebsite()) { + $websiteAttributes[] = (int)$itemData['attribute_id']; + } else { + $globalValues[] = (int)$itemData['value_id']; + } + } + + /** + * Delete global scope attributes + */ + if (!empty($globalValues)) { + $adapter->delete($table, array('value_id IN (?)' => $globalValues)); + } + + $condition = array( + $entityIdField . ' = ?' => $object->getId(), + 'entity_type_id = ?' => $object->getEntityTypeId() + ); + + /** + * Delete website scope attributes + */ + if (!empty($websiteAttributes)) { + $storeIds = $object->getWebsiteStoreIds(); + if (!empty($storeIds)) { + $delCondition = $condition; + $delCondition['attribute_id IN(?)'] = $websiteAttributes; + $delCondition['store_id IN(?)'] = $storeIds; + + $adapter->delete($table, $delCondition); + } + } + + /** + * Delete store scope attributes + */ + if (!empty($storeAttributes)) { + $delCondition = $condition; + $delCondition['attribute_id IN(?)'] = $storeAttributes; + $delCondition['store_id = ?'] = (int)$object->getStoreId(); + + $adapter->delete($table, $delCondition); + } + + return $this; + } + + /** + * Retrieve Object instance with original data + * + * @param Varien_Object $object + * @return Varien_Object + */ + protected function _getOrigObject($object) + { + $className = get_class($object); + $origObject = new $className(); + $origObject->setData(array()); + $origObject->setStoreId($object->getStoreId()); + $this->load($origObject, $object->getData($this->getEntityIdField())); + + return $origObject; + } + + /** + * Collect original data + * + * @deprecated after 1.5.1.0 + * + * @param Varien_Object $object + * @return array + */ + protected function _collectOrigData($object) + { + $this->loadAllAttributes($object); + + if ($this->getUseDataSharing()) { + $storeId = $object->getStoreId(); + } else { + $storeId = $this->getStoreId(); + } + + $data = array(); + foreach ($this->getAttributesByTable() as $table=>$attributes) { + $select = $this->_getReadAdapter()->select() + ->from($table) + ->where($this->getEntityIdField() . '=?', $object->getId()); + + $where = $this->_getReadAdapter()->quoteInto('store_id=?', $storeId); + + $globalAttributeIds = array(); + foreach ($attributes as $attr) { + if ($attr->getIsGlobal()) { + $globalAttributeIds[] = $attr->getId(); + } + } + if (!empty($globalAttributeIds)) { + $where .= ' or '.$this->_getReadAdapter()->quoteInto('attribute_id in (?)', $globalAttributeIds); + } + $select->where($where); + + $values = $this->_getReadAdapter()->fetchAll($select); + + if (empty($values)) { + continue; + } + + foreach ($values as $row) { + $data[$this->getAttribute($row['attribute_id'])->getName()][$row['store_id']] = $row; + } + } + return $data; + } + + /** + * Check is attribute value empty + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param mixed $value + * @return bool + */ + protected function _isAttributeValueEmpty(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $value) + { + return $value === false; + } + + /** + * Return if attribute exists in original data array. + * Checks also attribute's store scope: + * We should insert on duplicate key update values if we unchecked 'STORE VIEW' checkbox in store view. + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param mixed $value New value of the attribute. + * @param array $origData + * @return bool + */ + protected function _canUpdateAttribute( + Mage_Eav_Model_Entity_Attribute_Abstract $attribute, + $value, + array &$origData) + { + $result = parent::_canUpdateAttribute($attribute, $value, $origData); + if ($result && + ($attribute->isScopeStore() || $attribute->isScopeWebsite()) && + !$this->_isAttributeValueEmpty($attribute, $value) && + $value == $origData[$attribute->getAttributeCode()] && + isset($origData['store_id']) && $origData['store_id'] != $this->getDefaultStoreId() + ) { + return false; + } + + return $result; + } + + /** + * Prepare value for save + * + * @param mixed $value + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return mixed + */ + protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) + { + $type = $attribute->getBackendType(); + if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') { + $value = null; + } + + return parent::_prepareValueForSave($value, $attribute); + } + + /** + * Retrieve attribute's raw value from DB. + * + * @param int $entityId + * @param int|string|array $attribute atrribute's ids or codes + * @param int|Mage_Core_Model_Store $store + * @return bool|string|array + */ + public function getAttributeRawValue($entityId, $attribute, $store) + { + if (!$entityId || empty($attribute)) { + return false; + } + if (!is_array($attribute)) { + $attribute = array($attribute); + } + + $attributesData = array(); + $staticAttributes = array(); + $typedAttributes = array(); + $staticTable = null; + $adapter = $this->_getReadAdapter(); + + foreach ($attribute as $_attribute) { + /* @var $attribute Mage_Catalog_Model_Entity_Attribute */ + $_attribute = $this->getAttribute($_attribute); + if (!$_attribute) { + continue; + } + $attributeCode = $_attribute->getAttributeCode(); + $attrTable = $_attribute->getBackend()->getTable(); + $isStatic = $_attribute->getBackend()->isStatic(); + + if ($isStatic) { + $staticAttributes[] = $attributeCode; + $staticTable = $attrTable; + } else { + /** + * That structure needed to avoid farther sql joins for getting attribute's code by id + */ + $typedAttributes[$attrTable][$_attribute->getId()] = $attributeCode; + } + } + + /** + * Collecting static attributes + */ + if ($staticAttributes) { + $select = $adapter->select()->from($staticTable, $staticAttributes) + ->where($this->getEntityIdField() . ' = :entity_id'); + $attributesData = $adapter->fetchRow($select, array('entity_id' => $entityId)); + } + + /** + * Collecting typed attributes, performing separate SQL query for each attribute type table + */ + if ($store instanceof Mage_Core_Model_Store) { + $store = $store->getId(); + } + + $store = (int)$store; + if ($typedAttributes) { + foreach ($typedAttributes as $table => $_attributes) { + $select = $adapter->select() + ->from(array('default_value' => $table), array('attribute_id')) + ->where('default_value.attribute_id IN (?)', array_keys($_attributes)) + ->where('default_value.entity_type_id = :entity_type_id') + ->where('default_value.entity_id = :entity_id') + ->where('default_value.store_id = ?', 0); + $bind = array( + 'entity_type_id' => $this->getTypeId(), + 'entity_id' => $entityId, + ); + + if ($store != $this->getDefaultStoreId()) { + $valueExpr = $adapter->getCheckSql('store_value.value IS NULL', + 'default_value.value', 'store_value.value'); + $joinCondition = array( + $adapter->quoteInto('store_value.attribute_id IN (?)', array_keys($_attributes)), + 'store_value.entity_type_id = :entity_type_id', + 'store_value.entity_id = :entity_id', + 'store_value.store_id = :store_id', + ); + + $select->joinLeft( + array('store_value' => $table), + implode(' AND ', $joinCondition), + array('attr_value' => $valueExpr) + ); + + $bind['store_id'] = $store; + + } else { + $select->columns(array('attr_value' => 'value'), 'default_value'); + } + + $result = $adapter->fetchPairs($select, $bind); + foreach ($result as $attrId => $value) { + $attrCode = $typedAttributes[$table][$attrId]; + $attributesData[$attrCode] = $value; + } + } + } + + if (sizeof($attributesData) == 1) { + $_data = each($attributesData); + $attributesData = $_data[1]; + } + + return $attributesData ? $attributesData : false; + } + + /** + * Reset firstly loaded attributes + * + * @param Varien_Object $object + * @param integer $entityId + * @param array|null $attributes + * @return Mage_Catalog_Model_Resource_Abstract + */ + public function load($object, $entityId, $attributes = array()) + { + $this->_attributes = array(); + return parent::load($object, $entityId, $attributes); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Attribute.php new file mode 100755 index 0000000000..5f9a681a41 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Attribute.php @@ -0,0 +1,168 @@ + + */ +class Mage_Catalog_Model_Resource_Attribute extends Mage_Eav_Model_Resource_Entity_Attribute +{ + /** + * Perform actions before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Attribute + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $applyTo = $object->getApplyTo(); + if (is_array($applyTo)) { + $object->setApplyTo(implode(',', $applyTo)); + } + return parent::_beforeSave($object); + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Attribute + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $this->_clearUselessAttributeValues($object); + return parent::_afterSave($object); + } + + /** + * Clear useless attribute values + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Attribute + */ + protected function _clearUselessAttributeValues(Mage_Core_Model_Abstract $object) + { + $origData = $object->getOrigData(); + + if ($object->isScopeGlobal() + && isset($origData['is_global']) + && Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL != $origData['is_global'] + ) { + $attributeStoreIds = array_keys(Mage::app()->getStores()); + if (!empty($attributeStoreIds)) { + $delCondition = array( + 'entity_type_id=?' => $object->getEntityTypeId(), + 'attribute_id = ?' => $object->getId(), + 'store_id IN(?)' => $attributeStoreIds + ); + $this->_getWriteAdapter()->delete($object->getBackendTable(), $delCondition); + } + } + + return $this; + } + + /** + * Delete entity + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Attribute + */ + public function deleteEntity(Mage_Core_Model_Abstract $object) + { + if (!$object->getEntityAttributeId()) { + return $this; + } + + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('eav/entity_attribute')) + ->where('entity_attribute_id = ?', (int)$object->getEntityAttributeId()); + $result = $this->_getReadAdapter()->fetchRow($select); + + if ($result) { + $attribute = Mage::getSingleton('eav/config') + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $result['attribute_id']); + + if ($this->isUsedBySuperProducts($attribute, $result['attribute_set_id'])) { + Mage::throwException(Mage::helper('eav')->__("Attribute '%s' used in configurable products", $attribute->getAttributeCode())); + } + $backendTable = $attribute->getBackend()->getTable(); + if ($backendTable) { + $select = $this->_getWriteAdapter()->select() + ->from($attribute->getEntity()->getEntityTable(), 'entity_id') + ->where('attribute_set_id = ?', $result['attribute_set_id']); + + $clearCondition = array( + 'entity_type_id =?' => $attribute->getEntityTypeId(), + 'attribute_id =?' => $attribute->getId(), + 'entity_id IN (?)' => $select + ); + $this->_getWriteAdapter()->delete($backendTable, $clearCondition); + } + } + + $condition = array('entity_attribute_id = ?' => $object->getEntityAttributeId()); + $this->_getWriteAdapter()->delete($this->getTable('entity_attribute'), $condition); + + return $this; + } + + /** + * Defines is Attribute used by super products + * + * @param Mage_Core_Model_Abstract $object + * @param int $attributeSet + * @return int + */ + public function isUsedBySuperProducts(Mage_Core_Model_Abstract $object, $attributeSet = null) + { + $adapter = $this->_getReadAdapter(); + $attrTable = $this->getTable('catalog/product_super_attribute'); + $productTable = $this->getTable('catalog/product'); + + $bind = array('attribute_id' => $object->getAttributeId()); + $select = clone $adapter->select(); + $select->reset() + ->from(array('main_table' => $attrTable), array('psa_count' => 'COUNT(product_super_attribute_id)')) + ->join(array('entity' => $productTable), 'main_table.product_id = entity.entity_id') + ->where('main_table.attribute_id = :attribute_id') + ->group('main_table.attribute_id') + ->limit(1); + + if ($attributeSet !== null) { + $bind['attribute_set_id'] = $attributeSet; + $select->where('entity.attribute_set_id = :attribute_set_id'); + } + + $helper = Mage::getResourceHelper('core'); + $query = $helper->getQueryUsingAnalyticFunction($select); + return $adapter->fetchOne($query, $bind); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category.php b/app/code/core/Mage/Catalog/Model/Resource/Category.php new file mode 100755 index 0000000000..c2061b329f --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category.php @@ -0,0 +1,895 @@ + + */ +class Mage_Catalog_Model_Resource_Category extends Mage_Catalog_Model_Resource_Abstract +{ + /** + * Category tree object + * + * @var Varien_Data_Tree_Db + */ + protected $_tree; + + /** + * Catalog products table name + * + * @var string + */ + protected $_categoryProductTable; + + /** + * Id of 'is_active' category attribute + * + * @var int + */ + protected $_isActiveAttributeId = null; + + /** + * Store id + * + * @var int + */ + protected $_storeId = null; + + /** + * Class constructor + * + */ + public function __construct() + { + $resource = Mage::getSingleton('core/resource'); + $this->setType(Mage_Catalog_Model_Category::ENTITY) + ->setConnection( + $resource->getConnection('catalog_read'), + $resource->getConnection('catalog_write') + ); + $this->_categoryProductTable = $this->getTable('catalog/category_product'); + } + + /** + * Set store Id + * + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Category + */ + public function setStoreId($storeId) + { + $this->_storeId = $storeId; + return $this; + } + + /** + * Return store id + * + * @return integer + */ + public function getStoreId() + { + if ($this->_storeId === null) { + return Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Retrieve category tree object + * + * @return Varien_Data_Tree_Db + */ + protected function _getTree() + { + if (!$this->_tree) { + $this->_tree = Mage::getResourceModel('catalog/category_tree') + ->load(); + } + return $this->_tree; + } + + /** + * Process category data before delete + * update children count for parent category + * delete child categories + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Category + */ + protected function _beforeDelete(Varien_Object $object) + { + parent::_beforeDelete($object); + + /** + * Update children count for all parent categories + */ + $parentIds = $object->getParentIds(); + if ($parentIds) { + $childDecrease = $object->getChildrenCount() + 1; // +1 is itself + $data = array('children_count' => new Zend_Db_Expr('children_count - ' . $childDecrease)); + $where = array('entity_id IN(?)' => $parentIds); + $this->_getWriteAdapter()->update( $this->getEntityTable(), $data, $where); + } + $this->deleteChildren($object); + return $this; + } + + /** + * Delete children categories of specific category + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Category + */ + public function deleteChildren(Varien_Object $object) + { + $adapter = $this->_getWriteAdapter(); + $pathField = $adapter->quoteIdentifier('path'); + + $select = $adapter->select() + ->from($this->getEntityTable(), array('entity_id')) + ->where($pathField . ' LIKE :c_path'); + + $childrenIds = $adapter->fetchCol($select, array('c_path' => $object->getPath() . '/%')); + + if (!empty($childrenIds)) { + $adapter->delete( + $this->getEntityTable(), + array('entity_id IN (?)' => $childrenIds) + ); + } + + /** + * Add deleted children ids to object + * This data can be used in after delete event + */ + $object->setDeletedChildrenIds($childrenIds); + return $this; + } + + /** + * Process category data before saving + * prepare path and increment children count for parent categories + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Category + */ + protected function _beforeSave(Varien_Object $object) + { + parent::_beforeSave($object); + + if (!$object->getChildrenCount()) { + $object->setChildrenCount(0); + } + if ($object->getLevel() === null) { + $object->setLevel(1); + } + + if (!$object->getId()) { + $object->setPosition($this->_getMaxPosition($object->getPath()) + 1); + $path = explode('/', $object->getPath()); + $level = count($path); + $object->setLevel($level); + if ($level) { + $object->setParentId($path[$level - 1]); + } + $object->setPath($object->getPath() . '/'); + + $toUpdateChild = explode('/',$object->getPath()); + + $this->_getWriteAdapter()->update( + $this->getEntityTable(), + array('children_count' => new Zend_Db_Expr('children_count+1')), + array('entity_id IN(?)' => $toUpdateChild) + ); + + } + return $this; + } + + /** + * Process category data after save category object + * save related products ids and update path value + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Category + */ + protected function _afterSave(Varien_Object $object) + { + /** + * Add identifier for new category + */ + if (substr($object->getPath(), -1) == '/') { + $object->setPath($object->getPath() . $object->getId()); + $this->_savePath($object); + } + + $this->_saveCategoryProducts($object); + return parent::_afterSave($object); + } + + /** + * Update path field + * + * @param Mage_Catalog_Model_Category $object + * @return Mage_Catalog_Model_Resource_Category + */ + protected function _savePath($object) + { + if ($object->getId()) { + $this->_getWriteAdapter()->update( + $this->getEntityTable(), + array('path' => $object->getPath()), + array('entity_id = ?' => $object->getId()) + ); + } + return $this; + } + + /** + * Get maximum position of child categories by specific tree path + * + * @param string $path + * @return int + */ + protected function _getMaxPosition($path) + { + $adapter = $this->getReadConnection(); + $positionField = $adapter->quoteIdentifier('position'); + $level = count(explode('/', $path)); + $bind = array( + 'c_level' => $level, + 'c_path' => $path . '/%' + ); + $select = $adapter->select() + ->from($this->getTable('catalog/category'), 'MAX(' . $positionField . ')') + ->where($adapter->quoteIdentifier('path') . ' LIKE :c_path') + ->where($adapter->quoteIdentifier('level') . ' = :c_level'); + + $position = $adapter->fetchOne($select, $bind); + if (!$position) { + $position = 0; + } + return $position; + } + + /** + * Save category products relation + * + * @param Mage_Catalog_Model_Category $category + * @return Mage_Catalog_Model_Resource_Category + */ + protected function _saveCategoryProducts($category) + { + $category->setIsChangedProductList(false); + $id = $category->getId(); + /** + * new category-product relationships + */ + $products = $category->getPostedProducts(); + + /** + * Example re-save category + */ + if ($products === null) { + return $this; + } + + /** + * old category-product relationships + */ + $oldProducts = $category->getProductsPosition(); + + $insert = array_diff_key($products, $oldProducts); + $delete = array_diff_key($oldProducts, $products); + + /** + * Find product ids which are presented in both arrays + * and saved before (check $oldProducts array) + */ + $update = array_intersect_key($products, $oldProducts); + $update = array_diff_assoc($update, $oldProducts); + + $adapter = $this->_getWriteAdapter(); + + /** + * Delete products from category + */ + if (!empty($delete)) { + $cond = array( + 'product_id IN(?)' => array_keys($delete), + 'category_id=?' => $id + ); + $adapter->delete($this->_categoryProductTable, $cond); + } + + /** + * Add products to category + */ + if (!empty($insert)) { + $data = array(); + foreach ($insert as $productId => $position) { + $data[] = array( + 'category_id' => (int)$id, + 'product_id' => (int)$productId, + 'position' => (int)$position + ); + } + $adapter->insertMultiple($this->_categoryProductTable, $data); + } + + /** + * Update product positions in category + */ + if (!empty($update)) { + foreach ($update as $productId => $position) { + $where = array( + 'category_id = ?'=> (int)$id, + 'product_id = ?' => (int)$productId + ); + $bind = array('position' => (int)$position); + $adapter->update($this->_categoryProductTable, $bind, $where); + } + } + + if (!empty($insert) || !empty($delete)) { + $productIds = array_unique(array_merge(array_keys($insert), array_keys($delete))); + Mage::dispatchEvent('catalog_category_change_products', array( + 'category' => $category, + 'product_ids' => $productIds + )); + } + + if (!empty($insert) || !empty($update) || !empty($delete)) { + $category->setIsChangedProductList(true); + /** + * Moved to index + */ + //$categoryIds = explode('/', $category->getPath()); + //$this->refreshProductIndex($categoryIds); + + /** + * Setting affected products to category for third party engine index refresh + */ + $productIds = array_keys($insert + $delete + $update); + $category->setAffectedProductIds($productIds); + } + return $this; + } + + /** + * Get positions of associated to category products + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getProductsPosition($category) + { + $select = $this->_getWriteAdapter()->select() + ->from($this->_categoryProductTable, array('product_id', 'position')) + ->where('category_id = :category_id'); + $bind = array('category_id' => (int)$category->getId()); + + return $this->_getWriteAdapter()->fetchPairs($select, $bind); + } + + /** + * Get chlden categories count + * + * @param int $categoryId + * @return int + */ + public function getChildrenCount($categoryId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getEntityTable(), 'children_count') + ->where('entity_id = :entity_id'); + $bind = array('entity_id' => $categoryId); + + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Check if category id exist + * + * @param int $entityId + * @return bool + */ + public function checkId($entityId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getEntityTable(), 'entity_id') + ->where('entity_id = :entity_id'); + $bind = array('entity_id' => $entityId); + + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Check array of category identifiers + * + * @param array $ids + * @return array + */ + public function verifyIds(array $ids) + { + if (empty($ids)) { + return array(); + } + + $select = $this->_getReadAdapter()->select() + ->from($this->getEntityTable(), 'entity_id') + ->where('entity_id IN(?)', $ids); + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Get count of active/not active children categories + * + * @param Mage_Catalog_Model_Category $category + * @param bool $isActiveFlag + * @return int + */ + public function getChildrenAmount($category, $isActiveFlag = true) + { + $storeId = Mage::app()->getStore()->getId(); + $attributeId = $this->_getIsActiveAttributeId(); + $table = $this->getTable(array($this->getEntityTablePrefix(), 'int')); + $adapter = $this->_getReadAdapter(); + $checkSql = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'd.value'); + + $bind = array( + 'attribute_id' => $attributeId, + 'store_id' => $storeId, + 'active_flag' => $isActiveFlag, + 'c_path' => $category->getPath() . '/%' + ); + $select = $adapter->select() + ->from(array('m' => $this->getEntityTable()), array('COUNT(m.entity_id)')) + ->joinLeft( + array('d' => $table), + 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = m.entity_id', + array() + ) + ->joinLeft( + array('c' => $table), + "c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id", + array() + ) + ->where('m.path LIKE :c_path') + ->where($checkSql . ' = :active_flag'); + + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Get "is_active" attribute identifier + * + * @return int + */ + protected function _getIsActiveAttributeId() + { + if ($this->_isActiveAttributeId === null) { + $bind = array( + 'catalog_category' => Mage_Catalog_Model_Category::ENTITY, + 'is_active' => 'is_active', + ); + $select = $this->_getReadAdapter()->select() + ->from(array('a'=>$this->getTable('eav/attribute')), array('attribute_id')) + ->join(array('t'=>$this->getTable('eav/entity_type')), 'a.entity_type_id = t.entity_type_id') + ->where('entity_type_code = :catalog_category') + ->where('attribute_code = :is_active'); + + $this->_isActiveAttributeId = $this->_getReadAdapter()->fetchOne($select, $bind); + } + + return $this->_isActiveAttributeId; + } + + /** + * Return entities where attribute value is + * + * @param array|int $entityIdsFilter + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $expectedValue + * @return array + */ + public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue) + { + $bind = array( + 'attribute_id' => $attribute->getId(), + 'value' => $expectedValue + ); + $select = $this->_getReadAdapter()->select() + ->from($attribute->getBackend()->getTable(), array('entity_id')) + ->where('attribute_id = :attribute_id') + ->where('value = :value') + ->where('entity_id IN(?)', $entityIdsFilter); + + return $this->_getReadAdapter()->fetchCol($select, $bind); + } + + /** + * Get products count in category + * + * @param Mage_Catalog_Model_Category $category + * @return int + */ + public function getProductCount($category) + { + $productTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); + + $select = $this->getReadConnection()->select() + ->from( + array('main_table' => $productTable), + array(new Zend_Db_Expr('COUNT(main_table.product_id)')) + ) + ->where('main_table.category_id = :category_id'); + + $bind = array('category_id' => (int)$category->getId()); + $counts = $this->getReadConnection()->fetchOne($select, $bind); + + return intval($counts); + } + + /** + * Retrieve categories + * + * @param integer $parent + * @param integer $recursionLevel + * @param boolean|string $sorted + * @param boolean $asCollection + * @param boolean $toLoad + * @return Varien_Data_Tree_Node_Collection|Mage_Catalog_Model_Resource_Category_Collection + */ + public function getCategories($parent, $recursionLevel = 0, $sorted = false, $asCollection = false, $toLoad = true) + { + $tree = Mage::getResourceModel('catalog/category_tree'); + /* @var $tree Mage_Catalog_Model_Resource_Category_Tree */ + $nodes = $tree->loadNode($parent) + ->loadChildren($recursionLevel) + ->getChildren(); + + $tree->addCollectionData(null, $sorted, $parent, $toLoad, true); + + if ($asCollection) { + return $tree->getCollection(); + } + return $nodes; + } + + /** + * Return parent categories of category + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getParentCategories($category) + { + $pathIds = array_reverse(explode(',', $category->getPathInStore())); + $categories = Mage::getResourceModel('catalog/category_collection') + ->setStore(Mage::app()->getStore()) + ->addAttributeToSelect('name') + ->addAttributeToSelect('url_key') + ->addFieldToFilter('entity_id', array('in' => $pathIds)) + ->addFieldToFilter('is_active', 1) + ->load() + ->getItems(); + return $categories; + } + + /** + * Return parent category of current category with own custom design settings + * + * @param Mage_Catalog_Model_Category $category + * @return Mage_Catalog_Model_Category + */ + public function getParentDesignCategory($category) + { + $pathIds = array_reverse($category->getPathIds()); + $collection = $category->getCollection() + ->setStore(Mage::app()->getStore()) + ->addAttributeToSelect('custom_design') + ->addAttributeToSelect('custom_design_from') + ->addAttributeToSelect('custom_design_to') + ->addAttributeToSelect('page_layout') + ->addAttributeToSelect('custom_layout_update') + ->addAttributeToSelect('custom_apply_to_products') + ->addFieldToFilter('entity_id', array('in' => $pathIds)) + ->addFieldToFilter('custom_use_parent_settings', 0) + ->addFieldToFilter('level', array('neq' => 0)) + ->setOrder('level', 'DESC') + ->load(); + return $collection->getFirstItem(); + } + + + /** + * Return child categories + * + * @param Mage_Catalog_Model_Category $category + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function getChildrenCategories($category) + { + $collection = $category->getCollection(); + /* @var $collection Mage_Catalog_Model_Resource_Category_Collection */ + $collection->addAttributeToSelect('url_key') + ->addAttributeToSelect('name') + ->addAttributeToSelect('all_children') + ->addAttributeToSelect('is_anchor') + ->addAttributeToFilter('is_active', 1) + ->addIdFilter($category->getChildren()) + ->setOrder('position', Varien_Db_Select::SQL_ASC) + ->joinUrlRewrite() + ->load(); + + return $collection; + } + + /** + * Return children ids of category + * + * @param Mage_Catalog_Model_Category $category + * @param boolean $recursive + * @return array + */ + public function getChildren($category, $recursive = true) + { + $attributeId = (int)$this->_getIsActiveAttributeId(); + $backendTable = $this->getTable(array($this->getEntityTablePrefix(), 'int')); + $adapter = $this->_getReadAdapter(); + $checkSql = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'd.value'); + $bind = array( + 'attribute_id' => $attributeId, + 'store_id' => $category->getStoreId(), + 'scope' => 1, + 'c_path' => $category->getPath() . '/%' + ); + $select = $this->_getReadAdapter()->select() + ->from(array('m' => $this->getEntityTable()), 'entity_id') + ->joinLeft( + array('d' => $backendTable), + 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = m.entity_id', + array() + ) + ->joinLeft( + array('c' => $backendTable), + 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id', + array() + ) + ->where($checkSql . ' = :scope') + ->where($adapter->quoteIdentifier('path') . ' LIKE :c_path'); + if (!$recursive) { + $select->where($adapter->quoteIdentifier('level') . ' <= :c_level'); + $bind['c_level'] = $category->getLevel() + 1; + } + + return $adapter->fetchCol($select, $bind); + } + + /** + * Return all children ids of category (with category id) + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getAllChildren($category) + { + $children = $this->getChildren($category); + $myId = array($category->getId()); + $children = array_merge($myId, $children); + + return $children; + } + + /** + * Check is category in list of store categories + * + * @param Mage_Catalog_Model_Category $category + * @return boolean + */ + public function isInRootCategoryList($category) + { + $rootCategoryId = Mage::app()->getStore()->getRootCategoryId(); + + return in_array($rootCategoryId, $category->getParentIds()); + } + + /** + * Check category is forbidden to delete. + * If category is root and assigned to store group return false + * + * @param integer $categoryId + * @return boolean + */ + public function isForbiddenToDelete($categoryId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('core/store_group'), array('group_id')) + ->where('root_category_id = :root_category_id'); + $result = $this->_getReadAdapter()->fetchOne($select, array('root_category_id' => $categoryId)); + + if ($result) { + return true; + } + return false; + } + + /** + * Get category path value by its id + * + * @param int $categoryId + * @return string + */ + public function getCategoryPathById($categoryId) + { + $select = $this->getReadConnection()->select() + ->from($this->getEntityTable(), array('path')) + ->where('entity_id = :entity_id'); + $bind = array('entity_id' => (int)$categoryId); + + return $this->getReadConnection()->fetchOne($select, $bind); + } + + /** + * Move category to another parent node + * + * @param Mage_Catalog_Model_Category $category + * @param Mage_Catalog_Model_Category $newParent + * @param null|int $afterCategoryId + * @return Mage_Catalog_Model_Resource_Category + */ + public function changeParent(Mage_Catalog_Model_Category $category, Mage_Catalog_Model_Category $newParent, + $afterCategoryId = null) + { + $childrenCount = $this->getChildrenCount($category->getId()) + 1; + $table = $this->getEntityTable(); + $adapter = $this->_getWriteAdapter(); + $levelFiled = $adapter->quoteIdentifier('level'); + $pathField = $adapter->quoteIdentifier('path'); + + /** + * Decrease children count for all old category parent categories + */ + $adapter->update( + $table, + array('children_count' => new Zend_Db_Expr('children_count - ' . $childrenCount)), + array('entity_id IN(?)' => $category->getParentIds()) + ); + + /** + * Increase children count for new category parents + */ + $adapter->update( + $table, + array('children_count' => new Zend_Db_Expr('children_count + ' . $childrenCount)), + array('entity_id IN(?)' => $newParent->getPathIds()) + ); + + $position = $this->_processPositions($category, $newParent, $afterCategoryId); + + $newPath = sprintf('%s/%s', $newParent->getPath(), $category->getId()); + $newLevel = $newParent->getLevel() + 1; + $levelDisposition = $newLevel - $category->getLevel(); + + /** + * Update children nodes path + */ + $adapter->update( + $table, + array( + 'path' => new Zend_Db_Expr('REPLACE(' . $pathField . ','. + $adapter->quote($category->getPath() . '/'). ', '.$adapter->quote($newPath . '/').')' + ), + 'level' => new Zend_Db_Expr( $levelFiled . ' + ' . $levelDisposition) + ), + array($pathField . ' LIKE ?' => $category->getPath() . '/%') + ); + /** + * Update moved category data + */ + $data = array( + 'path' => $newPath, + 'level' => $newLevel, + 'position' =>$position, + 'parent_id' =>$newParent->getId() + ); + $adapter->update($table, $data, array('entity_id = ?' => $category->getId())); + + // Update category object to new data + $category->addData($data); + + return $this; + } + + /** + * Process positions of old parent category children and new parent category children. + * Get position for moved category + * + * @param Mage_Catalog_Model_Category $category + * @param Mage_Catalog_Model_Category $newParent + * @param null|int $afterCategoryId + * @return int + */ + protected function _processPositions($category, $newParent, $afterCategoryId) + { + $table = $this->getEntityTable(); + $adapter = $this->_getWriteAdapter(); + $positionField = $adapter->quoteIdentifier('position'); + + $bind = array( + 'position' => new Zend_Db_Expr($positionField . ' - 1') + ); + $where = array( + 'parent_id = ?' => $category->getParentId(), + $positionField . ' > ?' => $category->getPosition() + ); + $adapter->update($table, $bind, $where); + + /** + * Prepare position value + */ + if ($afterCategoryId) { + $select = $adapter->select() + ->from($table,'position') + ->where('entity_id = :entity_id'); + $position = $adapter->fetchOne($select, array('entity_id' => $afterCategoryId)); + + $bind = array( + 'position' => new Zend_Db_Expr($positionField . ' + 1') + ); + $where = array( + 'parent_id = ?' => $newParent->getId(), + $positionField . ' > ?' => $position + ); + $adapter->update($table,$bind,$where); + } elseif ($afterCategoryId !== null) { + $position = 0; + $bind = array( + 'position' => new Zend_Db_Expr($positionField . ' + 1') + ); + $where = array( + 'parent_id = ?' => $newParent->getId(), + $positionField . ' > ?' => $position + ); + $adapter->update($table,$bind,$where); + } else { + $select = $adapter->select() + ->from($table,array('position' => new Zend_Db_Expr('MIN(' . $positionField. ')'))) + ->where('parent_id = :parent_id'); + $position = $adapter->fetchOne($select, array('patent_id' => $newParent->getId())); + } + $position += 1; + + return $position; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php new file mode 100755 index 0000000000..e815b67513 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php @@ -0,0 +1,65 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Attribute_Collection + extends Mage_Eav_Model_Resource_Entity_Attribute_Collection +{ + /** + * Main select object initialization. + * Joins catalog/eav_attribute table + * + * @return Mage_Catalog_Model_Resource_Category_Attribute_Collection + */ + protected function _initSelect() + { + $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable())) + ->where('main_table.entity_type_id=?', Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Category::ENTITY)->getTypeId()) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'additional_table.attribute_id = main_table.attribute_id' + ); + return $this; + } + + /** + * Specify attribute entity type filter + * + * @param int $typeId + * @return Mage_Catalog_Model_Resource_Category_Attribute_Collection + */ + public function setEntityTypeFilter($typeId) + { + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Frontend/Image.php new file mode 100755 index 0000000000..890af7ec37 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Frontend/Image.php @@ -0,0 +1,54 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Attribute_Frontend_Image + extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +{ + const IMAGE_PATH_SEGMENT = 'catalog/category/'; + + /** + * Return image url + * + * @param Varien_Object $object + * @return string|null + */ + public function getUrl($object) + { + $url = false; + if ($image = $object->getData($this->getAttribute()->getAttributeCode())) { + $url = Mage::getBaseUrl('media') . self::IMAGE_PATH_SEGMENT . $image; + } + return $url; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Layout.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Layout.php new file mode 100755 index 0000000000..fd6ef05c2e --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Layout.php @@ -0,0 +1,57 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Attribute_Source_Layout + extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +{ + /** + * Return cms layout update options + * + * @return array + */ + public function getAllOptions() + { + if (!$this->_options) { + $layouts = array(); + foreach (Mage::getConfig()->getNode('global/cms/layouts')->children() as $layoutName=>$layoutConfig) { + $this->_options[] = array( + 'value'=>$layoutName, + 'label'=>(string)$layoutConfig->label + ); + } + array_unshift($this->_options, array('value'=>'', 'label' => Mage::helper('catalog')->__('No layout updates'))); + } + return $this->_options; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Mode.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Mode.php new file mode 100755 index 0000000000..c505181b0b --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Mode.php @@ -0,0 +1,62 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Attribute_Source_Mode extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +{ + /** + * Returns all mode options + * + * @return array + */ + public function getAllOptions() + { + if (!$this->_options) { + $this->_options = array( + array( + 'value' => Mage_Catalog_Model_Category::DM_PRODUCT, + 'label' => Mage::helper('catalog')->__('Products only'), + ), + array( + 'value' => Mage_Catalog_Model_Category::DM_PAGE, + 'label' => Mage::helper('catalog')->__('Static block only'), + ), + array( + 'value' => Mage_Catalog_Model_Category::DM_MIXED, + 'label' => Mage::helper('catalog')->__('Static block and products'), + ) + ); + } + return $this->_options; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Page.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Page.php new file mode 100755 index 0000000000..aa92cec95d --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Source/Page.php @@ -0,0 +1,52 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Attribute_Source_Page extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +{ + /** + * Return all block options + * + * @return array + */ + public function getAllOptions() + { + if (!$this->_options) { + $this->_options = Mage::getResourceModel('cms/block_collection') + ->load() + ->toOptionArray(); + array_unshift($this->_options, array('value' => '', 'label' => Mage::helper('catalog')->__('Please select a static block ...'))); + } + return $this->_options; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Collection.php new file mode 100755 index 0000000000..9bf1451843 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Collection.php @@ -0,0 +1,416 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'catalog_category_collection'; + + /** + * Event object name + * + * @var string + */ + protected $_eventObject = 'category_collection'; + + /** + * Name of product table + * + * @var string + */ + protected $_productTable; + + /** + * Store id, that we should count products on + * + * @var int + */ + protected $_productStoreId; + + /** + * Name of product website table + * + * @var string + */ + protected $_productWebsiteTable; + + /** + * Load with product count flag + * + * @var boolean + */ + protected $_loadWithProductCount = false; + + /** + * Init collection and determine table names + * + */ + protected function _construct() + { + $this->_init('catalog/category'); + + $this->_productWebsiteTable = $this->getTable('catalog/product_website'); + $this->_productTable = $this->getTable('catalog/category_product'); + } + + /** + * Add Id filter + * + * @param array $categoryIds + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addIdFilter($categoryIds) + { + if (is_array($categoryIds)) { + if (empty($categoryIds)) { + $condition = ''; + } else { + $condition = array('in' => $categoryIds); + } + } elseif (is_numeric($categoryIds)) { + $condition = $categoryIds; + } elseif (is_string($categoryIds)) { + $ids = explode(',', $categoryIds); + if (empty($ids)) { + $condition = $categoryIds; + } else { + $condition = array('in' => $ids); + } + } + $this->addFieldToFilter('entity_id', $condition); + return $this; + } + + /** + * Set flag for loading product count + * + * @param boolean $flag + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function setLoadProductCount($flag) + { + $this->_loadWithProductCount = $flag; + return $this; + } + + /** + * Before collection load + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + protected function _beforeLoad() + { + Mage::dispatchEvent($this->_eventPrefix . '_load_before', + array($this->_eventObject => $this)); + return parent::_beforeLoad(); + } + + /** + * After collection load + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + protected function _afterLoad() + { + Mage::dispatchEvent($this->_eventPrefix . '_load_after', + array($this->_eventObject => $this)); + + return parent::_afterLoad(); + } + + /** + * Set id of the store that we should count products on + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function setProductStoreId($storeId) + { + $this->_productStoreId = $storeId; + return $this; + } + + /** + * Get id of the store that we should count products on + * + * @return int + */ + public function getProductStoreId() + { + if (is_null($this->_productStoreId)) { + $this->_productStoreId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; + } + return $this->_productStoreId; + } + + /** + * Load collection + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + + if ($this->_loadWithProductCount) { + $this->addAttributeToSelect('all_children'); + $this->addAttributeToSelect('is_anchor'); + } + + parent::load($printQuery, $logQuery); + + if ($this->_loadWithProductCount) { + $this->_loadProductCount(); + } + + return $this; + } + + /** + * Load categories product count + * + */ + protected function _loadProductCount() + { + $this->loadProductCount($this->_items, true, true); + } + + /** + * Load product count for specified items + * + * @param array $items + * @param boolean $countRegular get product count for regular (non-anchor) categories + * @param boolean $countAnchor get product count for anchor categories + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function loadProductCount($items, $countRegular = true, $countAnchor = true) + { + $anchor = array(); + $regular = array(); + + foreach ($items as $item) { + if ($item->getIsAnchor()) { + $anchor[$item->getId()] = $item; + } else { + $regular[$item->getId()] = $item; + } + } + + if ($countRegular) { + // Retrieve regular categories product counts + $regularIds = array_keys($regular); + if (!empty($regularIds)) { + $select = $this->_conn->select(); + $select->from( + array('main_table' => $this->_productTable), + array('category_id', new Zend_Db_Expr('COUNT(main_table.product_id)')) + ) + ->where($this->_conn->quoteInto('main_table.category_id IN(?)', $regularIds)) + ->group('main_table.category_id'); + $counts = $this->_conn->fetchPairs($select); + foreach ($regular as $item) { + if (isset($counts[$item->getId()])) { + $item->setProductCount($counts[$item->getId()]); + } else { + $item->setProductCount(0); + } + } + } + } + + if ($countAnchor) { + // Retrieve Anchor categories product counts + foreach ($anchor as $item) { + if ($allChildren = $item->getAllChildren()) { + $bind = array( + 'entity_id' => $item->getId(), + 'c_path' => $item->getPath() . '/%' + ); + $select = $this->_conn->select(); + $select->from( + array('main_table' => $this->_productTable), + new Zend_Db_Expr('COUNT(DISTINCT main_table.product_id)') + ) + ->joinInner( + array('e' => $this->getTable('catalog/category')), + 'main_table.category_id=e.entity_id', + array() + ) + ->where('e.entity_id = :entity_id') + ->orWhere('e.path LIKE :c_path'); + $item->setProductCount((int) $this->_conn->fetchOne($select, $bind)); + } else { + $item->setProductCount(0); + } + } + } + return $this; + } + + /** + * Add category path filter + * + * @param string $regexp + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addPathFilter($regexp) + { + $this->addFieldToFilter('path', array('regexp' => $regexp)); + return $this; + } + + /** + * Joins url rewrite rules to collection + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function joinUrlRewrite() + { + $storeId = Mage::app()->getStore()->getId(); + $this->joinTable( + 'core/url_rewrite', + 'category_id=entity_id', + array('request_path'), + "{{table}}.is_system=1" + . " AND {{table}}.product_id IS NULL" + . " AND {{table}}.store_id='{$storeId}'" + . " AND id_path LIKE 'category/%'", + 'left' + ); + return $this; + } + + /** + * Add active category filter + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addIsActiveFilter() + { + $this->addAttributeToFilter('is_active', 1); + Mage::dispatchEvent($this->_eventPrefix . '_add_is_active_filter', + array($this->_eventObject => $this)); + return $this; + } + + /** + * Add name attribute to result + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addNameToResult() + { + $this->addAttributeToSelect('name'); + return $this; + } + + /** + * Add url rewrite rules to collection + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addUrlRewriteToResult() + { + $this->joinUrlRewrite(); + return $this; + } + + /** + * Add category path filter + * + * @param array|string $paths + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addPathsFilter($paths) + { + if (!is_array($paths)) { + $paths = array($paths); + } + $select = $this->getSelect(); + $orWhere = false; + foreach ($paths as $path) { + if ($orWhere) { + $select->orWhere('e.path LIKE ?', "$path%"); + } else { + $select->where('e.path LIKE ?', "$path%"); + $orWhere = true; + } + } + return $this; + } + + /** + * Add category level filter + * + * @param int|string $level + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addLevelFilter($level) + { + $this->addFieldToFilter('level', array('lteq' => $level)); + return $this; + } + + /** + * Add root category filter + * + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addRootLevelFilter() + { + $this->addFieldToFilter('path', array('neq' => '1')); + $this->addLevelFilter(1); + return $this; + } + + /** + * Add order field + * + * @param string $field + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function addOrderField($field) + { + $this->setOrder($field, self::SORT_ORDER_ASC); + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php new file mode 100755 index 0000000000..6b4c4cc6e7 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php @@ -0,0 +1,1361 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Flat extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Store id + * + * @var int + */ + protected $_storeId = null; + + /** + * Loaded + * + * @var boolean + */ + protected $_loaded = false; + + /** + * Nodes + * + * @var array + */ + protected $_nodes = array(); + + /** + * Columns + * + * @var array + */ + protected $_columns = null; + + /** + * Columns sql + * + * @var array + */ + protected $_columnsSql = null; + + /** + * Attribute codes + * + * @var array + */ + protected $_attributeCodes = null; + + /** + * Inactive categories ids + * + * @var array + */ + protected $_inactiveCategoryIds = null; + + /** + * Is rebuild + * + * @var boolean + */ + protected $_isRebuilt = null; + + /** + * array with root category id per store + * + * @var array + */ + protected $_storesRootCategories; + + /** + * Resource initializations + * + */ + protected function _construct() + { + $this->_init('catalog/category_flat', 'entity_id'); + } + + /** + * Set store id + * + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function setStoreId($storeId) + { + $this->_storeId = (int)$storeId; + return $this; + } + + /** + * Return store id + * + * @return integer + */ + public function getStoreId() + { + if (is_null($this->_storeId)) { + return (int)Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Get main table name + * + * @return string + */ + public function getMainTable() + { + return $this->getMainStoreTable($this->getStoreId()); + } + + /** + * Return name of table for given $storeId. + * + * @param integer $storeId + * @return string + */ + public function getMainStoreTable($storeId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) + { + if (is_string($storeId)) { + $storeId = intval($storeId); + } + if ($this->getUseStoreTables() && $storeId) { + $suffix = sprintf('store_%d', $storeId); + $table = $this->getTable(array('catalog/category_flat', $suffix)); + } else { + $table = parent::getMainTable(); + } + + return $table; + } + + /** + * Return true if need use for each store different table of flat categories data. + * + * @return boolean + */ + public function getUseStoreTables() + { + return true; + } + + /** + * Add inactive categories ids + * + * @param unknown_type $ids + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function addInactiveCategoryIds($ids) + { + if (!is_array($this->_inactiveCategoryIds)) { + $this->_initInactiveCategoryIds(); + } + $this->_inactiveCategoryIds = array_merge($ids, $this->_inactiveCategoryIds); + return $this; + } + + /** + * Retreive inactive categories ids + * + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + protected function _initInactiveCategoryIds() + { + $this->_inactiveCategoryIds = array(); + Mage::dispatchEvent('catalog_category_tree_init_inactive_category_ids', array('tree' => $this)); + return $this; + } + + /** + * Retreive inactive categories ids + * + * @return array + */ + public function getInactiveCategoryIds() + { + if (!is_array($this->_inactiveCategoryIds)) { + $this->_initInactiveCategoryIds(); + } + + return $this->_inactiveCategoryIds; + } + + /** + * Load nodes by parent id + * + * @param unknown_type $parentNode + * @param integer $recursionLevel + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + protected function _loadNodes($parentNode = null, $recursionLevel = 0, $storeId = 0) + { + $_conn = $this->_getReadAdapter(); + $startLevel = 1; + $parentPath = ''; + if ($parentNode instanceof Mage_Catalog_Model_Category) { + $parentPath = $parentNode->getPath(); + $startLevel = $parentNode->getLevel(); + } elseif (is_numeric($parentNode)) { + $selectParent = $_conn->select() + ->from($this->getMainStoreTable($storeId)) + ->where('entity_id = ?', $parentNode) + ->where('store_id = ?', $storeId); + if ($parentNode = $_conn->fetchRow($selectParent)) { + $parentPath = $parentNode['path']; + $startLevel = $parentNode['level']; + } + } + $select = $_conn->select() + ->from( + array('main_table' => $this->getMainStoreTable($storeId)), + array('entity_id', + new Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('name')), + new Zend_Db_Expr('main_table.' . $_conn->quoteIdentifier('path')), + 'is_active', + 'is_anchor')) + ->joinLeft( + array('url_rewrite'=>$this->getTable('core/url_rewrite')), + 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND ' . + $_conn->quoteInto( + 'url_rewrite.product_id IS NULL AND url_rewrite.store_id=? AND ',//url_rewrite.id_path LIKE "category/%"', + $storeId) . + $_conn->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), + array('request_path' => 'url_rewrite.request_path')) + ->where('main_table.is_active = ?', '1') + ->where('main_table.include_in_menu = ?', '1') + ->order('main_table.position'); + + if ($parentPath) { + $select->where($_conn->quoteInto("main_table.path like ?", "$parentPath/%")); + } + if ($recursionLevel != 0) { + $levelField = $_conn->quoteIdentifier('level'); + $select->where($levelField . ' <= ?', $startLevel + $recursionLevel); + } + + $inactiveCategories = $this->getInactiveCategoryIds(); + + if (!empty($inactiveCategories)) { + $select->where('main_table.entity_id NOT IN (?)', $inactiveCategories); + } + + $arrNodes = $_conn->fetchAll($select); + $nodes = array(); + foreach ($arrNodes as $node) { + $node['id'] = $node['entity_id']; + $nodes[$node['id']] = Mage::getModel('catalog/category')->setData($node); + } + + return $nodes; + } + + /** + * Creating sorted array of nodes + * + * @param array $children + * @param string $path + * @param Varien_Object $parent + */ + public function addChildNodes($children, $path, $parent) + { + if (isset($children[$path])) { + foreach ($children[$path] as $child) { + $childrenNodes = $parent->getChildrenNodes(); + if ($childrenNodes && isset($childrenNodes[$child->getId()])) { + $childrenNodes[$child['entity_id']]->setChildrenNodes(array($child->getId()=>$child)); + } else { + if ($childrenNodes) { + $childrenNodes[$child->getId()] = $child; + } else { + $childrenNodes = array($child->getId()=>$child); + } + $parent->setChildrenNodes($childrenNodes); + } + + if ($path) { + $childrenPath = explode('/', $path); + } else { + $childrenPath = array(); + } + $childrenPath[] = $child->getId(); + $childrenPath = implode('/', $childrenPath); + $this->addChildNodes($children, $childrenPath, $child); + } + } + } + + /** + * Return sorted array of nodes + * + * @param integer|null $parentId + * @param integer $recursionLevel + * @param integer $storeId + * @return array + */ + public function getNodes($parentId, $recursionLevel = 0, $storeId = 0) + { + if (!$this->_loaded) { + $selectParent = $this->_getReadAdapter()->select() + ->from($this->getMainStoreTable($storeId)) + ->where('entity_id = ?', $parentId); + if ($parentNode = $this->_getReadAdapter()->fetchRow($selectParent)) { + $parentNode['id'] = $parentNode['entity_id']; + $parentNode = Mage::getModel('catalog/category')->setData($parentNode); + $this->_nodes[$parentNode->getId()] = $parentNode; + $nodes = $this->_loadNodes($parentNode, $recursionLevel, $storeId); + $childrenItems = array(); + foreach ($nodes as $node) { + $pathToParent = explode('/', $node->getPath()); + array_pop($pathToParent); + $pathToParent = implode('/', $pathToParent); + $childrenItems[$pathToParent][] = $node; + } + $this->addChildNodes($childrenItems, $parentNode->getPath(), $parentNode); + $childrenNodes = $this->_nodes[$parentNode->getId()]; + if ($childrenNodes->getChildrenNodes()) { + $this->_nodes = $childrenNodes->getChildrenNodes(); + } + else { + $this->_nodes = array(); + } + $this->_loaded = true; + } + } + return $this->_nodes; + } + + /** + * Return array or collection of categories + * + * @param integer $parent + * @param integer $recursionLevel + * @param boolean|string $sorted + * @param boolean $asCollection + * @param boolean $toLoad + * @return array|Varien_Data_Collection + */ + public function getCategories($parent, $recursionLevel = 0, $sorted = false, $asCollection = false, $toLoad = true) + { + if ($asCollection) { + $select = $this->_getReadAdapter()->select() + ->from(array('mt' => $this->getMainStoreTable($this->getStoreId())), array('path')) + ->where('mt.entity_id = ?', $parent); + $parentPath = $this->_getReadAdapter()->fetchOne($select); + + $collection = Mage::getModel('catalog/category')->getCollection() + ->addNameToResult() + ->addUrlRewriteToResult() + ->addParentPathFilter($parentPath) + ->addStoreFilter() + ->addIsActiveFilter() + ->addAttributeToFilter('include_in_menu', 1) + ->addSortedField($sorted); + if ($toLoad) { + return $collection->load(); + } + return $collection; + } + return $this->getNodes($parent, $recursionLevel, Mage::app()->getStore()->getId()); + } + + /** + * Return node with id $nodeId + * + * @param integer $nodeId + * @param array $nodes + * @return Varien_Object + */ + public function getNodeById($nodeId, $nodes = null) + { + if (is_null($nodes)) { + $nodes = $this->getNodes($nodeId); + } + if (isset($nodes[$nodeId])) { + return $nodes[$nodeId]; + } + foreach ($nodes as $node) { + if ($node->getChildrenNodes()) { + return $this->getNodeById($nodeId, $node->getChildrenNodes()); + } + } + return array(); + } + + /** + * Check if category flat data is rebuilt + * + * @return bool + */ + public function isRebuilt() + { + if ($this->_isRebuilt === null) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainStoreTable(Mage::app()->getDefaultStoreView()->getId()), 'entity_id') + ->limit(1); + try { + $this->_isRebuilt = (bool) $this->_getReadAdapter()->fetchOne($select); + } catch (Exception $e) { + $this->_isRebuilt = false; + } + } + return $this->_isRebuilt; + } + + /** + * Rebuild flat data from eav + * + * @param unknown_type $stores + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function rebuild($stores = null) + { + if ($stores === null) { + $stores = Mage::app()->getStores(); + } + + if (!is_array($stores)) { + $stores = array($stores); + } + + $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID; + $categories = array(); + $categoriesIds = array(); + /* @var $store Mage_Core_Model_Store */ + foreach ($stores as $store) { + $this->_createTable($store->getId()); + + if (!isset($categories[$store->getRootCategoryId()])) { + $select = $this->_getWriteAdapter()->select() + ->from($this->getTable('catalog/category')) + ->where('path = ?', (string)$rootId) + ->orWhere('path = ?', "{$rootId}/{$store->getRootCategoryId()}") + ->orWhere('path LIKE ?', "{$rootId}/{$store->getRootCategoryId()}/%"); + $categories[$store->getRootCategoryId()] = $this->_getWriteAdapter()->fetchAll($select); + $categoriesIds[$store->getRootCategoryId()] = array(); + foreach ($categories[$store->getRootCategoryId()] as $category) { + $categoriesIds[$store->getRootCategoryId()][] = $category['entity_id']; + } + } + $categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500); + foreach ($categoriesIdsChunks as $categoriesIdsChunk) { + $attributesData = $this->_getAttributeValues($categoriesIdsChunk, $store->getId()); + $data = array(); + foreach ($categories[$store->getRootCategoryId()] as $category) { + if (!isset($attributesData[$category['entity_id']])) { + continue; + } + $category['store_id'] = $store->getId(); + $data[] = $this->_prepareValuesToInsert( + array_merge($category, $attributesData[$category['entity_id']]) + ); + } + $this->_getWriteAdapter()->insertMultiple($this->getMainStoreTable($store->getId()), $data); + } + } + return $this; + } + + /** + * Prepare array of column and columnValue pairs + * + * @param array $data + * @return array + */ + protected function _prepareValuesToInsert($data) + { + $values = array(); + foreach (array_keys($this->_columns) as $key => $column) { + if (isset($data[$column])) { + $values[$column] = $data[$column]; + } else { + $values[$column] = null; + } + } + return $values; + } + + /** + * Create Flate Table(s) + * + * @param array|int $stores + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function createTable($stores) + { + return $this->_createTable($stores); + } + + /** + * Creating table and adding attributes as fields to table + * + * @param array|integer $store + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + protected function _createTable($store) + { + $tableName = $this->getMainStoreTable($store); + $_writeAdapter = $this->_getWriteAdapter(); + $_writeAdapter->dropTable($tableName); + $table = $this->_getWriteAdapter() + ->newTable($tableName) + ->setComment(sprintf('Catalog Category Flat (Store %d)', $store)); + + //Adding columns + if ($this->_columnsSql === null) { + $this->_columns = array_merge($this->_getStaticColumns(), $this->_getEavColumns()); + foreach ($this->_columns as $fieldName => $fieldProp) { + $default = $fieldProp['default']; + if ($fieldProp['type'][0] == Varien_Db_Ddl_Table::TYPE_TIMESTAMP + && $default == 'CURRENT_TIMESTAMP') { + $default = Varien_Db_Ddl_Table::TIMESTAMP_INIT; + } + $table->addColumn($fieldName, $fieldProp['type'][0], $fieldProp['type'][1], array( + 'nullable' => $fieldProp['nullable'], + 'unsigned' => $fieldProp['unsigned'], + 'default' => $default, + 'primary' => isset($fieldProp['primary']) ? $fieldProp['primary'] : false, + ), ($fieldProp['comment'] != '') ? + $fieldProp['comment'] : + ucwords(str_replace('_', ' ', $fieldName)) + ); + } + } + + // Adding indexes + $table->addIndex($_writeAdapter->getIndexName($tableName, array('entity_id')), array('entity_id'), array('type' => 'primary')); + $table->addIndex($_writeAdapter->getIndexName($tableName, array('store_id')), array('store_id'), array('type' => 'index')); + $table->addIndex($_writeAdapter->getIndexName($tableName, array('path')), array('path'), array('type' => 'index')); + $table->addIndex($_writeAdapter->getIndexName($tableName, array('level')), array('level'), array('type' => 'index')); + + // Adding foreign keys + $table->addForeignKey( + $_writeAdapter->getForeignKeyName($tableName, 'entity_id', $this->getTable('catalog/category'), 'entity_id'), + 'entity_id', $this->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); + $table->addForeignKey( + $_writeAdapter->getForeignKeyName($tableName, 'store_id', $this->getTable('core/store'), 'store_id'), + 'store_id', $this->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); + $_writeAdapter->createTable($table); + return $this; + } + + /** + * Return array of static columns + * + * @return array + */ + protected function _getStaticColumns() + { + $helper = Mage::getResourceHelper('catalog'); + $columns = array(); + $columnsToSkip = array('entity_type_id', 'attribute_set_id'); + $describe = $this->_getWriteAdapter()->describeTable($this->getTable('catalog/category')); + + foreach ($describe as $column) { + if (in_array($column['COLUMN_NAME'], $columnsToSkip)) { + continue; + } + $_is_unsigned = ''; + $ddlType = $helper->getDdlTypeByColumnType($column['DATA_TYPE']); + $column['DEFAULT'] = trim($column['DEFAULT'],"' "); + switch ($ddlType) { + case Varien_Db_Ddl_Table::TYPE_SMALLINT: + case Varien_Db_Ddl_Table::TYPE_INTEGER: + case Varien_Db_Ddl_Table::TYPE_BIGINT: + $_is_unsigned = (bool)$column['UNSIGNED']; + if ($column['DEFAULT'] === '') { + $column['DEFAULT'] = null; + } + + $options = null; + if ($column['SCALE'] > 0) { + $ddlType = Varien_Db_Ddl_Table::TYPE_DECIMAL; + } else { + break; + } + case Varien_Db_Ddl_Table::TYPE_DECIMAL: + $options = $column['PRECISION'] . ',' . $column['SCALE']; + $_is_unsigned = null; + if ($column['DEFAULT'] === '') { + $column['DEFAULT'] = null; + } + break; + case Varien_Db_Ddl_Table::TYPE_TEXT: + $options = $column['LENGTH']; + $_is_unsigned = null; + break; + case Varien_Db_Ddl_Table::TYPE_TIMESTAMP: + $options = null; + $_is_unsigned = null; + break; + + } + $columns[$column['COLUMN_NAME']] = array( + 'type' => array($ddlType, $options), + 'unsigned' => $_is_unsigned, + 'nullable' => $column['NULLABLE'], + 'default' => ($column['DEFAULT'] === null ? false : $column['DEFAULT']), + 'comment' => $column['COLUMN_NAME'] + ); + } + $columns['store_id'] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_SMALLINT, 5), + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ); + return $columns; + } + + /** + * Return array of eav columns, skip attribute with static type + * + * @return array + */ + protected function _getEavColumns() + { + $columns = array(); + $attributes = $this->_getAttributes(); + foreach ($attributes as $attribute) { + if ($attribute['backend_type'] == 'static') { + continue; + } + $columns[$attribute['attribute_code']] = array(); + switch ($attribute['backend_type']) { + case 'varchar': + $columns[$attribute['attribute_code']] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_TEXT, 255), + 'unsigned' => null, + 'nullable' => true, + 'default' => null, + 'comment' => (string)$attribute['frontend_label'] + ); + break; + case 'int': + $columns[$attribute['attribute_code']] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_INTEGER, null), + 'unsigned' => null, + 'nullable' => true, + 'default' => null, + 'comment' => (string)$attribute['frontend_label'] + ); + break; + case 'text': + $columns[$attribute['attribute_code']] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '64k'), + 'unsigned' => null, + 'nullable' => true, + 'default' => null, + 'comment' => (string)$attribute['frontend_label'] + ); + break; + case 'datetime': + $columns[$attribute['attribute_code']] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null), + 'unsigned' => null, + 'nullable' => true, + 'default' => null, + 'comment' => (string)$attribute['frontend_label'] + ); + break; + case 'decimal': + $columns[$attribute['attribute_code']] = array( + 'type' => array(Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4'), + 'unsigned' => null, + 'nullable' => true, + 'default' => null, + 'comment' => (string)$attribute['frontend_label'] + ); + break; + } + } + return $columns; + } + + /** + * Return array of attribute codes for entity type 'catalog_category' + * + * @return array + */ + protected function _getAttributes() + { + if ($this->_attributeCodes === null) { + $select = $this->_getWriteAdapter()->select() + ->from($this->getTable('eav/entity_type'), array()) + ->join( + $this->getTable('eav/attribute'), + $this->getTable('eav/attribute').'.entity_type_id = ' . $this->getTable('eav/entity_type') . '.entity_type_id', + $this->getTable('eav/attribute').'.*' + ) + ->where($this->getTable('eav/entity_type').'.entity_type_code = ?', Mage_Catalog_Model_Category::ENTITY); + $this->_attributeCodes = array(); + foreach ($this->_getWriteAdapter()->fetchAll($select) as $attribute) { + $this->_attributeCodes[$attribute['attribute_id']] = $attribute; + } + } + return $this->_attributeCodes; + } + + /** + * Return attribute values for given entities and store + * + * @param array $entityIds + * @param integer $store_id + * @return array + */ + protected function _getAttributeValues($entityIds, $store_id) + { + if (!is_array($entityIds)) { + $entityIds = array($entityIds); + } + $values = array(); + + foreach ($entityIds as $entityId) { + $values[$entityId] = array(); + } + $attributes = $this->_getAttributes(); + $attributesType = array( + 'varchar', + 'int', + 'decimal', + 'text', + 'datetime' + ); + foreach ($attributesType as $type) { + foreach ($this->_getAttributeTypeValues($type, $entityIds, $store_id) as $row) { + $values[$row['entity_id']][$attributes[$row['attribute_id']]['attribute_code']] = $row['value']; + } + } + return $values; + } + + /** + * Return attribute values for given entities and store of specific attribute type + * + * @param string $type + * @param array $entityIds + * @param integer $store_id + * @return array + */ + protected function _getAttributeTypeValues($type, $entityIds, $store_id) + { + $select = $this->_getWriteAdapter()->select() + ->from(array('def' => $this->getTable(array('catalog/category', $type))), array('entity_id', 'attribute_id')) + ->joinLeft( + array('store' => $this->getTable(array('catalog/category', $type))), + 'store.entity_id = def.entity_id AND store.attribute_id = def.attribute_id AND store.store_id = ' . $store_id, + array('value' => $this->_getWriteAdapter()->getCheckSql('store.value_id > 0', + $this->_getWriteAdapter()->quoteIdentifier('store.value'), + $this->_getWriteAdapter()->quoteIdentifier('def.value')) + ) + ) + ->where('def.entity_id IN (?)', $entityIds) + ->where('def.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + return $this->_getWriteAdapter()->fetchAll($select); + } + + /** + * Delete store table(s) of given stores; + * + * @param array|integer $stores + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function deleteStores($stores) + { + $this->_deleteTable($stores); + return $this; + } + + /** + * Delete table(s) of given stores. + * + * @param array|integer $stores + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + protected function _deleteTable($stores) + { + if (!is_array($stores)) { + $stores = array($stores); + } + foreach ($stores as $store) { + $this->_getWriteAdapter()->dropTable($this->getMainStoreTable($store)); + } + return $this; + } + + /** + * Synchronize flat data with eav model for category + * + * @param Varien_Object $category + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + protected function _synchronize($category) + { + $table = $this->getMainStoreTable($category->getStoreId()); + $data = $this->_prepareDataForAllFields($category); + $this->_getWriteAdapter()->insertOnDuplicate($table, $data); + return $this; + } + + /** + * Synchronize flat data with eav model. + * + * @param Mage_Catalog_Model_Category|int $category + * @param array $storeIds + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function synchronize($category = null, $storeIds = array()) + { + if (is_null($category)) { + if (empty($storeIds)) { + $storeIds = null; + } + $stores = $this->getStoresRootCategories($storeIds); + + $storesObjects = array(); + foreach ($stores as $storeId => $rootCategoryId) { + $_store = new Varien_Object(array( + 'store_id' => $storeId, + 'root_category_id' => $rootCategoryId + )); + $_store->setIdFieldName('store_id'); + $storesObjects[] = $_store; + } + + $this->rebuild($storesObjects); + } else if ($category instanceof Mage_Catalog_Model_Category) { + $categoryId = $category->getId(); + foreach ($category->getStoreIds() as $storeId) { + if ($storeId == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { + continue; + } + + $attributeValues = $this->_getAttributeValues($categoryId, $storeId); + $data = new Varien_Object($category->getData()); + $data->addData($attributeValues[$categoryId]) + ->setStoreId($storeId); + $this->_synchronize($data); + } + } else if (is_numeric($category)) { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/category')) + ->where('entity_id=?', $category); + $row = $write->fetchRow($select); + if (!$row) { + return $this; + } + + $stores = $this->getStoresRootCategories(); + $path = explode('/', $row['path']); + foreach ($stores as $storeId => $rootCategoryId) { + if (in_array($rootCategoryId, $path)) { + $attributeValues = $this->_getAttributeValues($category, $storeId); + $data = new Varien_Object($row); + $data->addData($attributeValues[$category]) + ->setStoreId($storeId); + $this->_synchronize($data); + } else { + $where = $write->quoteInto('entity_id = ?', $category); + $write->delete($this->getMainStoreTable($storeId), $where); + } + } + } + + return $this; + } + + /** + * Remove table of given stores + * + * @param int|array $stores + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function removeStores($stores) + { + $this->_deleteTable($stores); + return $this; + } + + /** + * Synchronize flat category data after move by affected category ids + * + * @param array $affectedCategoryIds + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function move(array $affectedCategoryIds) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/category'), array('entity_id', 'path')) + ->where('entity_id IN(?)', $affectedCategoryIds); + $pairs = $write->fetchPairs($select); + + $pathCond = array($write->quoteInto('entity_id IN(?)', $affectedCategoryIds)); + $parentIds = array(); + + foreach ($pairs as $path) { + $pathCond[] = $write->quoteInto('path LIKE ?', $path . '/%'); + $parentIds = array_merge($parentIds, explode('/', $path)); + } + + $stores = $this->getStoresRootCategories(); + $where = join(' OR ', $pathCond); + $lastId = 0; + while (true) { + $select = $write->select() + ->from($this->getTable('catalog/category')) + ->where('entity_id>?', $lastId) + ->where($where) + ->order('entity_id') + ->limit(500); + $rowSet = $write->fetchAll($select); + + if (!$rowSet) { + break; + } + + $addStores = array(); + $remStores = array(); + + foreach ($rowSet as &$row) { + $lastId = $row['entity_id']; + $path = explode('/', $row['path']); + foreach ($stores as $storeId => $rootCategoryId) { + if (in_array($rootCategoryId, $path)) { + $addStores[$storeId][$row['entity_id']] = $row; + } else { + $remStores[$storeId][] = $row['entity_id']; + } + } + } + + // remove + foreach ($remStores as $storeId => $categoryIds) { + $where = $write->quoteInto('entity_id IN(?)', $categoryIds); + $write->delete($this->getMainStoreTable($storeId), $where); + } + + // add/update + foreach ($addStores as $storeId => $storeCategoryIds) { + $attributeValues = $this->_getAttributeValues(array_keys($storeCategoryIds), $storeId); + foreach ($storeCategoryIds as $row) { + $data = new Varien_Object($row); + $data->addData($attributeValues[$row['entity_id']]) + ->setStoreId($storeId); + $this->_synchronize($data); + } + } + } + + return $this; + } + + /** + * Synchronize flat data with eav after moving category + * + * @param integer $categoryId + * @param integer $prevParentId + * @param integer $parentId + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function moveold($categoryId, $prevParentId, $parentId) + { + $catalogCategoryTable = $this->getTable('catalog/category'); + $_staticFields = array( + 'parent_id', + 'path', + 'level', + 'position', + 'children_count', + 'updated_at' + ); + $prevParent = Mage::getModel('catalog/category')->load($prevParentId); + $parent = Mage::getModel('catalog/category')->load($parentId); + if ($prevParent->getStore()->getWebsiteId() != $parent->getStore()->getWebsiteId()) { + foreach ($prevParent->getStoreIds() as $storeId) { + $this->_getWriteAdapter()->delete( + $this->getMainStoreTable($storeId), + $this->_getWriteAdapter()->quoteInto('entity_id = ?', $categoryId) + ); + } + $select = $this->_getReadAdapter()->select() + ->from($catalogCategoryTable, 'path') + ->where('entity_id = ?', $categoryId); + + $categoryPath = $this->_getWriteAdapter()->fetchOne($select); + + $select = $this->_getWriteAdapter()->select() + ->from($catalogCategoryTable, 'entity_id') + ->where('path LIKE ?', "$categoryPath/%") + ->orWhere('path = ?', $categoryPath); + $_categories = $this->_getWriteAdapter()->fetchAll($select); + foreach ($_categories as $_category) { + foreach ($parent->getStoreIds() as $storeId) { + $_tmpCategory = Mage::getModel('catalog/category') + ->setStoreId($storeId) + ->load($_category['entity_id']); + $this->_synchronize($_tmpCategory); + } + } + } else { + foreach ($parent->getStoreIds() as $store) { + $mainStoreTable = $this->getMainStoreTable($store); + + $update = "UPDATE {$mainStoreTable}, {$catalogCategoryTable} SET"; + foreach ($_staticFields as $field) { + $update .= " {$mainStoreTable}.".$field."={$catalogCategoryTable}.".$field.","; + } + $update = substr($update, 0, -1); + $update .= " WHERE {$mainStoreTable}.entity_id = {$catalogCategoryTable}.entity_id AND " . + "($catalogCategoryTable}.path like '{$parent->getPath()}/%' OR " . + "{$catalogCategoryTable}.path like '{$prevParent->getPath()}/%')"; + $this->_getWriteAdapter()->query($update); + } + } + $prevParent = null; + $parent = null; + $_tmpCategory = null; +// $this->_move($categoryId, $prevParentPath, $parentPath); + return $this; + } + + /** + * Prepare array of category data to insert or update. + * array( + * 'field_name' => 'value' + * ) + * + * @param Mage_Catalog_Model_Category $category + * @param array $replaceFields + * @return array + */ + protected function _prepareDataForAllFields($category, $replaceFields = array()) + { + $table = $this->getMainStoreTable($category->getStoreId()); + $this->_getWriteAdapter()->resetDdlCache($table); + $table = $this->_getWriteAdapter()->describeTable($table); + $data = array(); + foreach ($table as $column=>$columnData) { + if (null !== $category->getData($column)) { + if (key_exists($column, $replaceFields)) { + $value = $category->getData($replaceFields[$column]); + } else { + $value = $category->getData($column); + } + if (is_array($value)) { + $value = implode(',', $value); + } + $data[$column] = $value; + } + } + return $data; + } + + /** + * Retrieve attribute instance + * Special for non static flat table + * + * @param mixed $attribute + * @return Mage_Eav_Model_Entity_Attribute_Abstract + */ + public function getAttribute($attribute) + { + return Mage::getSingleton('catalog/config') + ->getAttribute(Mage_Catalog_Model_Category::ENTITY, $attribute); + } + + /** + * Get count of active/not active children categories + * + * @param Mage_Catalog_Model_Category $category + * @param bool $isActiveFlag + * @return integer + */ + public function getChildrenAmount($category, $isActiveFlag = true) + { + $_table = $this->getMainStoreTable($category->getStoreId()); + $select = $this->_getReadAdapter()->select() + ->from($_table, "COUNT({$_table}.entity_id)") + ->where("{$_table}.path LIKE ?", $category->getPath() . '/%') + ->where("{$_table}.is_active = ?", (int) $isActiveFlag); + return (int) $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Get products count in category + * + * @param Mage_Catalog_Model_Category $category + * @return integer + */ + public function getProductCount($category) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('catalog/category_product'), "COUNT({$this->getTable('catalog/category_product')}.product_id)") + ->where("{$this->getTable('catalog/category_product')}.category_id = ?", $category->getId()) + ->group("{$this->getTable('catalog/category_product')}.category_id"); + return (int) $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Return parent categories of category + * + * @param Mage_Catalog_Model_Category $category + * @param unknown_type $isActive + * @return array + */ + public function getParentCategories($category, $isActive = true) + { + $categories = array(); + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), array('main_table.entity_id', 'main_table.name')) + ->joinLeft( + array('url_rewrite'=>$this->getTable('core/url_rewrite')), + 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND '. + $read->quoteInto('url_rewrite.product_id IS NULL AND url_rewrite.store_id=? AND ', + $category->getStoreId() ). + $read->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), + array('request_path' => 'url_rewrite.request_path')) + ->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore()))); + if ($isActive) { + $select->where('main_table.is_active = ?', '1'); + } + $select->order('main_table.path ASC'); + $result = $this->_getReadAdapter()->fetchAll($select); + foreach ($result as $row) { + $row['id'] = $row['entity_id']; + $categories[$row['entity_id']] = Mage::getModel('catalog/category')->setData($row); + } + return $categories; + } + + /** + * Return parent category of current category with own custom design settings + * + * @param Mage_Catalog_Model_Category $category + * @return Mage_Catalog_Model_Category + */ + public function getParentDesignCategory($category) + { + $adapter = $this->_getReadAdapter(); + $levelField = $adapter->quoteIdentifier('level'); + $pathIds = array_reverse($category->getPathIds()); + $select = $adapter->select() + ->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), '*') + ->where('entity_id IN (?)', $pathIds) + ->where('custom_use_parent_settings = ?', 0) + ->where($levelField . ' != ?', 0) + ->order('level ' . Varien_Db_Select::SQL_DESC); + $result = $adapter->fetchRow($select); + return Mage::getModel('catalog/category')->setData($result); + } + + /** + * Return children categories of category + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getChildrenCategories($category) + { + $categories = $this->_loadNodes($category, 1, $category->getStoreId()); + return $categories; + } + + /** + * Check is category in list of store categories + * + * @param Mage_Catalog_Model_Category $category + * @return boolean + */ + public function isInRootCategoryList($category) + { + $pathIds = $category->getParentIds(); + return in_array(Mage::app()->getStore()->getRootCategoryId(), $pathIds); + } + + /** + * Return children ids of category + * + * @param Mage_Catalog_Model_Category $category + * @param unknown_type $recursive + * @param unknown_type $isActive + * @return array + */ + public function getChildren($category, $recursive = true, $isActive = true) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainStoreTable($category->getStoreId()), 'entity_id') + ->where('path LIKE ?', "{$category->getPath()}/%"); + if (!$recursive) { + $select->where('level <= ?', $category->getLevel() + 1); + } + if ($isActive) { + $select->where('is_active = ?', '1'); + } + $_categories = $this->_getReadAdapter()->fetchAll($select); + $categoriesIds = array(); + foreach ($_categories as $_category) { + $categoriesIds[] = $_category['entity_id']; + } + return $categoriesIds; + } + + /** + * Return all children ids of category (with category id) + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getAllChildren($category) + { + $categoriesIds = $this->getChildren($category); + $myId = array($category->getId()); + $categoriesIds = array_merge($myId, $categoriesIds); + + return $categoriesIds; + } + + /** + * Check if category id exist + * + * @param int $id + * @return bool + */ + public function checkId($id) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainStoreTable($this->getStoreId()), 'entity_id') + ->where('entity_id=?', $id); + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Get design update data of parent categories + * + * @param Mage_Catalog_Model_Category $category + * @return array + */ + public function getDesignUpdateData($category) + { + $categories = array(); + $pathIds = array(); + foreach (array_reverse($category->getParentIds()) as $pathId) { + if ($pathId == Mage::app()->getStore()->getRootCategoryId()) { + $pathIds[] = $pathId; + break; + } + $pathIds[] = $pathId; + } + $select = $this->_getReadAdapter()->select() + ->from( + array('main_table' => $this->getMainStoreTable($category->getStoreId())), + array( + 'main_table.entity_id', + 'main_table.custom_design', + 'main_table.custom_design_apply', + 'main_table.custom_design_from', + 'main_table.custom_design_to', + ) + ) + ->where('main_table.entity_id IN (?)', $pathIds) + ->where('main_table.is_active = ?', '1') + ->order('main_table.path ' . Varien_Db_Select::SQL_DESC); + $result = $this->_getReadAdapter()->fetchAll($select); + foreach ($result as $row) { + $row['id'] = $row['entity_id']; + $categories[$row['entity_id']] = Mage::getModel('catalog/category')->setData($row); + } + return $categories; + } + + /** + * Retrieve anchors above + * + * @param array $filterIds + * @param int $storeId + * @return array + */ + public function getAnchorsAbove(array $filterIds, $storeId = 0) + { + $select = $this->_getReadAdapter()->select() + ->from(array('e' => $this->getMainStoreTable($storeId)), 'entity_id') + ->where('is_anchor = ?', 1) + ->where('entity_id IN (?)', $filterIds); + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Retrieve array with root category id per store + * + * @param int|array $storeIds result limitation + * @return array + */ + public function getStoresRootCategories($storeIds = null) + { + if (is_null($this->_storesRootCategories)) { + $select = $this->_getWriteAdapter()->select() + ->from(array('cs' => $this->getTable('core/store')), array('store_id')) + ->join( + array('csg' => $this->getTable('core/store_group')), + 'csg.group_id = cs.group_id', + array('root_category_id')) + ->where('cs.store_id <> ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + $this->_storesRootCategories = $this->_getWriteAdapter()->fetchPairs($select); + } + + if (!is_null($storeIds)) { + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + + $stores = array(); + foreach ($this->_storesRootCategories as $storeId => $rootId) { + if (in_array($storeId, $storeIds)) { + $stores[$storeId] = $rootId; + } + } + return $stores; + } + + return $this->_storesRootCategories; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat/Collection.php new file mode 100755 index 0000000000..f81132c48a --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat/Collection.php @@ -0,0 +1,386 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Flat_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'catalog_category_collection'; + + /** + * Event object name + * + * @var string + */ + protected $_eventObject = 'category_collection'; + + /** + * Store id of application + * + * @var integer + */ + protected $_storeId = null; + + /** + * Collection initialization + * + */ + protected function _construct() + { + $this->_init('catalog/category_flat'); + $this->setModel('catalog/category'); + } + + /** + * Enter description here ... + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + protected function _initSelect() + { + $this->getSelect()->from( + array('main_table' => $this->getResource()->getMainStoreTable($this->getStoreId())), + array('entity_id', 'level', 'path', 'position', 'is_active', 'is_anchor') + ); + return $this; + } + + /** + * Add filter by entity id(s). + * + * @param mixed $categoryIds + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addIdFilter($categoryIds) + { + if (is_array($categoryIds)) { + if (empty($categoryIds)) { + $condition = ''; + } else { + $condition = array('in' => $categoryIds); + } + } elseif (is_numeric($categoryIds)) { + $condition = $categoryIds; + } elseif (is_string($categoryIds)) { + $ids = explode(',', $categoryIds); + if (empty($ids)) { + $condition = $categoryIds; + } else { + $condition = array('in' => $ids); + } + } + $this->addFieldToFilter('entity_id', $condition); + return $this; + } + + /** + * Before collection load + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + protected function _beforeLoad() + { + Mage::dispatchEvent($this->_eventPrefix . '_load_before', + array($this->_eventObject => $this)); + return parent::_beforeLoad(); + } + + /** + * After collection load + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + protected function _afterLoad() + { + Mage::dispatchEvent($this->_eventPrefix . '_load_after', + array($this->_eventObject => $this)); + + return parent::_afterLoad(); + } + + /** + * Set store id + * + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function setStoreId($storeId) + { + $this->_storeId = $storeId; + return $this; + } + + /** + * Return store id. + * If store id is not set yet, return store of application + * + * @return integer + */ + public function getStoreId() + { + if (is_null($this->_storeId)) { + return Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Add filter by path to collection + * + * @param string $parent + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addParentPathFilter($parent) + { + $this->addFieldToFilter('path', array('like' => "{$parent}/%")); + return $this; + } + + /** + * Add store filter + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addStoreFilter() + { + $this->addFieldToFilter('main_table.store_id', $this->getStoreId()); + return $this; + } + + /** + * Set field to sort by + * + * @param string $sorted + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addSortedField($sorted) + { + if (is_string($sorted)) { + $this->addOrder($sorted, self::SORT_ORDER_ASC); + } else { + $this->addOrder('name', self::SORT_ORDER_ASC); + } + return $this; + } + + /** + * Enter description here ... + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addIsActiveFilter() + { + $this->addFieldToFilter('is_active', 1); + Mage::dispatchEvent($this->_eventPrefix . '_add_is_active_filter', + array($this->_eventObject => $this)); + return $this; + } + + /** + * Add name field to result + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addNameToResult() + { + $this->addAttributeToSelect('name'); + return $this; + } + + /** + * Add attribute to select + * + * @param array|string $attribute + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addAttributeToSelect($attribute = '*') + { + if ($attribute == '*') { + // Save previous selected columns + $columns = $this->getSelect()->getPart(Zend_Db_Select::COLUMNS); + $this->getSelect()->reset(Zend_Db_Select::COLUMNS); + foreach ($columns as $column) { + if ($column[0] == 'main_table') { + // If column selected from main table, + // no need to select it again + continue; + } + + // Joined columns + if ($column[2] !== null) { + $expression = array($column[2] => $column[1]); + } else { + $expression = $column[2]; + } + $this->getSelect()->columns($expression, $column[0]); + } + + $this->getSelect()->columns('*', 'main_table'); + return $this; + } + + if (!is_array($attribute)) { + $attribute = array($attribute); + } + + $this->getSelect()->columns($attribute, 'main_table'); + return $this; + } + + /** + * Retrieve resource instance + * + * @return Mage_Catalog_Model_Resource_Category_Flat + */ + public function getResource() + { + return parent::getResource(); + } + + /** + * Add attribute to sort order + * + * @param string $attribute + * @param string $dir + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) + { + if (!is_string($attribute)) { + return $this; + } + $this->setOrder($attribute, $dir); + return $this; + } + + /** + * Emulate simple add attribute filter to collection + * + * @param string $attribute + * @param mixed $condition + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addAttributeToFilter($attribute, $condition = null) + { + if (!is_string($attribute) || $condition === null) { + return $this; + } + + return $this->addFieldToFilter($attribute, $condition); + } + + /** + * Enter description here ... + * + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addUrlRewriteToResult() + { + $storeId = Mage::app()->getStore()->getId(); + $this->getSelect()->joinLeft( + array('url_rewrite' => $this->getTable('core/url_rewrite')), + 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 '. + 'AND url_rewrite.product_id IS NULL'. + ' AND ' . $this->getConnection()->quoteInto('url_rewrite.store_id=?', $storeId). + ' AND ' . $this->getConnection()->quoteInto('url_rewrite.id_path LIKE ?','category/%'), + array('request_path') + ); + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $paths + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addPathsFilter($paths) + { + if (!is_array($paths)) { + $paths = array($paths); + } + $select = $this->getSelect(); + $orWhere = false; + foreach ($paths as $path) { + if ($orWhere) { + $select->orWhere('main_table.path LIKE ?', "$path%"); + } else { + $select->where('main_table.path LIKE ?', "$path%"); + $orWhere = true; + } + } + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $level + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addLevelFilter($level) + { + $this->getSelect()->where('main_table.level <= ?', $level); + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $field + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function addOrderField($field) + { + $this->setOrder('main_table.' . $field, self::SORT_ORDER_ASC); + return $this; + } + + /** + * Set collection page start and records to show + * + * @param integer $pageNum + * @param integer $pageSize + * @return Mage_Catalog_Model_Resource_Category_Flat_Collection + */ + public function setPage($pageNum, $pageSize) + { + $this->setCurPage($pageNum) + ->setPageSize($pageSize); + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php new file mode 100755 index 0000000000..26c110408c --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php @@ -0,0 +1,1099 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Indexer_Product extends Mage_Index_Model_Resource_Abstract +{ + /** + * Category table + * + * @var string + */ + protected $_categoryTable; + + /** + * Category product table + * + * @var string + */ + protected $_categoryProductTable; + + /** + * Product website table + * + * @var string + */ + protected $_productWebsiteTable; + + /** + * Store table + * + * @var string + */ + protected $_storeTable; + + /** + * Group table + * + * @var string + */ + protected $_groupTable; + + /** + * Array of info about stores + * + * @var array + */ + protected $_storesInfo; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('catalog/category_product_index', 'category_id'); + $this->_categoryTable = $this->getTable('catalog/category'); + $this->_categoryProductTable = $this->getTable('catalog/category_product'); + $this->_productWebsiteTable = $this->getTable('catalog/product_website'); + $this->_storeTable = $this->getTable('core/store'); + $this->_groupTable = $this->getTable('core/store_group'); + } + + /** + * Process product save. + * Method is responsible for index support + * when product was saved and assigned categories was changed. + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + public function catalogProductSave(Mage_Index_Model_Event $event) + { + $productId = $event->getEntityPk(); + $data = $event->getNewData(); + + /** + * Check if category ids were updated + */ + if (!isset($data['category_ids'])) { + return $this; + } + + /** + * Select relations to categories + */ + $select = $this->_getWriteAdapter()->select() + ->from(array('cp' => $this->_categoryProductTable), 'category_id') + ->joinInner(array('ce' => $this->_categoryTable), 'ce.entity_id=cp.category_id', 'path') + ->where('cp.product_id=:product_id'); + + /** + * Get information about product categories + */ + $categories = $this->_getWriteAdapter()->fetchPairs($select, array('product_id' => $productId)); + $categoryIds = array(); + $allCategoryIds = array(); + + foreach ($categories as $id=>$path) { + $categoryIds[] = $id; + $allCategoryIds = array_merge($allCategoryIds, explode('/', $path)); + } + $allCategoryIds = array_unique($allCategoryIds); + $allCategoryIds = array_diff($allCategoryIds, $categoryIds); + + /** + * Delete previous index data + */ + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + array('product_id = ?' => $productId) + ); + + $this->_refreshAnchorRelations($allCategoryIds, $productId); + $this->_refreshDirectRelations($categoryIds, $productId); + $this->_refreshRootRelations($productId); + return $this; + } + + /** + * Process Catalog Product mass action + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + public function catalogProductMassAction(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + + /** + * check is product ids were updated + */ + if (!isset($data['product_ids'])) { + return $this; + } + $productIds = $data['product_ids']; + $categoryIds = array(); + $allCategoryIds = array(); + + /** + * Select relations to categories + */ + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->distinct(true) + ->from(array('cp' => $this->_categoryProductTable), array('category_id')) + ->join( + array('ce' => $this->_categoryTable), + 'ce.entity_id=cp.category_id', + array('path')) + ->where('cp.product_id IN(?)', $productIds); + $pairs = $adapter->fetchPairs($select); + foreach ($pairs as $categoryId => $categoryPath) { + $categoryIds[] = $categoryId; + $allCategoryIds = array_merge($allCategoryIds, explode('/', $categoryPath)); + } + + $allCategoryIds = array_unique($allCategoryIds); + $allCategoryIds = array_diff($allCategoryIds, $categoryIds); + + /** + * Delete previous index data + */ + $this->_getWriteAdapter()->delete( + $this->getMainTable(), array('product_id IN(?)' => $productIds) + ); + + $this->_refreshAnchorRelations($allCategoryIds, $productIds); + $this->_refreshDirectRelations($categoryIds, $productIds); + $this->_refreshRootRelations($productIds); + return $this; + } + + /** + * Return array of used root category id - path pairs + * + * @return array + */ + protected function _getRootCategories() + { + $rootCategories = array(); + $stores = $this->_getStoresInfo(); + foreach ($stores as $storeInfo) { + if ($storeInfo['root_id']) { + $rootCategories[$storeInfo['root_id']] = $storeInfo['root_path']; + } + } + + return $rootCategories; + } + + /** + * Process category index after category save + * + * @param Mage_Index_Model_Event $event + */ + public function catalogCategorySave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + + $checkRootCategories = false; + $processRootCategories = false; + $affectedRootCategoryIds = array(); + $rootCategories = $this->_getRootCategories(); + + /** + * Check if we have reindex category move results + */ + if (isset($data['affected_category_ids'])) { + $categoryIds = $data['affected_category_ids']; + $checkRootCategories = true; + } else if (isset($data['products_was_changed'])) { + $categoryIds = array($event->getEntityPk()); + + if (isset($rootCategories[$event->getEntityPk()])) { + $processRootCategories = true; + $affectedRootCategoryIds[] = $event->getEntityPk(); + } + } else { + return; + } + + $select = $this->_getWriteAdapter()->select() + ->from($this->_categoryTable, 'path') + ->where('entity_id IN (?)', $categoryIds); + $paths = $this->_getWriteAdapter()->fetchCol($select); + $allCategoryIds = array(); + foreach ($paths as $path) { + if ($checkRootCategories) { + foreach ($rootCategories as $rootCategoryId => $rootCategoryPath) { + if (strpos($path, sprintf('%d/', $rootCategoryPath)) === 0 || $path == $rootCategoryPath) { + $affectedRootCategoryIds[$rootCategoryId] = $rootCategoryId; + } + } + } + $allCategoryIds = array_merge($allCategoryIds, explode('/', $path)); + } + $allCategoryIds = array_unique($allCategoryIds); + + if ($checkRootCategories && count($affectedRootCategoryIds) > 1) { + $processRootCategories = true; + } + + /** + * retrieve anchor category id + */ + $anchorInfo = $this->_getAnchorAttributeInfo(); + $bind = array( + 'attribute_id' => $anchorInfo['id'], + 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + 'e_value' => 1 + ); + $select = $this->_getReadAdapter()->select() + ->distinct(true) + ->from(array('ce' => $this->_categoryTable), array('entity_id')) + ->joinInner( + array('dca'=>$anchorInfo['table']), + "dca.entity_id=ce.entity_id AND dca.attribute_id=:attribute_id AND dca.store_id=:store_id", + array()) + ->where('dca.value=:e_value') + ->where('ce.entity_id IN (?)', $allCategoryIds); + $anchorIds = $this->_getWriteAdapter()->fetchCol($select, $bind); + /** + * delete only anchor id and category ids + */ + $deleteCategoryIds = array_merge($anchorIds,$categoryIds); + + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds) + ); + + $directIds = array_diff($categoryIds, $anchorIds); + if ($anchorIds) { + $this->_refreshAnchorRelations($anchorIds); + } + if ($directIds) { + $this->_refreshDirectRelations($directIds); + } + + /** + * Need to re-index affected root category ids when its are not anchor + */ + if ($processRootCategories) { + $reindexRootCategoryIds = array_diff($affectedRootCategoryIds, $anchorIds); + if ($reindexRootCategoryIds) { + $this->_refreshNotAnchorRootCategories($reindexRootCategoryIds); + } + } + + } + + /** + * Reindex not anchor root categories + * + * @param array $categoryIds + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product + */ + protected function _refreshNotAnchorRootCategories(array $categoryIds = null) + { + if (empty($categoryIds)) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + + // remove anchor relations + $where = array( + 'category_id IN(?)' => $categoryIds, + 'is_parent=?' => 0 + ); + $adapter->delete($this->getMainTable(), $where); + + $stores = $this->_getStoresInfo(); + /** + * Build index for each store + */ + foreach ($stores as $storeData) { + $storeId = $storeData['store_id']; + $websiteId = $storeData['website_id']; + $rootPath = $storeData['root_path']; + $rootId = $storeData['root_id']; + if (!in_array($rootId, $categoryIds)) { + continue; + } + + $select = $adapter->select() + ->distinct(true) + ->from(array('cc' => $this->getTable('catalog/category')), null) + ->join( + array('i' => $this->getMainTable()), + 'i.category_id = cc.entity_id and i.store_id = 1', + array()) + ->joinLeft( + array('ie' => $this->getMainTable()), + 'ie.category_id = ' . (int)$rootId . ' AND ie.product_id=i.product_id AND ie.store_id = ' . (int)$storeId, + array()) + ->where('cc.path LIKE ?', $rootPath . '/%') + ->where('ie.category_id IS NULL') + ->columns(array( + 'category_id' => new Zend_Db_Expr($rootId), + 'product_id' => 'i.product_id', + 'position' => new Zend_Db_Expr('0'), + 'is_parent' => new Zend_Db_Expr('0'), + 'store_id' => new Zend_Db_Expr($storeId), + 'visibility' => 'i.visibility' + )); + $query = $select->insertFromSelect($this->getMainTable()); + $adapter->query($query); + + $visibilityInfo = $this->_getVisibilityAttributeInfo(); + $statusInfo = $this->_getStatusAttributeInfo(); + + $select = $this->_getReadAdapter()->select() + ->from(array('pw' => $this->_productWebsiteTable), array()) + ->joinLeft( + array('i' => $this->getMainTable()), + 'i.product_id = pw.product_id AND i.category_id = ' . (int)$rootId . ' AND i.store_id = ' . (int) $storeId, + array()) + ->join( + array('dv' => $visibilityInfo['table']), + "dv.entity_id = pw.product_id AND dv.attribute_id = {$visibilityInfo['id']} AND dv.store_id = 0", + array()) + ->joinLeft( + array('sv' => $visibilityInfo['table']), + "sv.entity_id = pw.product_id AND sv.attribute_id = {$visibilityInfo['id']} AND sv.store_id = " . (int)$storeId, + array()) + ->join( + array('ds' => $statusInfo['table']), + "ds.entity_id = pw.product_id AND ds.attribute_id = {$statusInfo['id']} AND ds.store_id = 0", + array()) + ->joinLeft( + array('ss' => $statusInfo['table']), + "ss.entity_id = pw.product_id AND ss.attribute_id = {$statusInfo['id']} AND ss.store_id = " . (int)$storeId, + array()) + ->where('i.product_id IS NULL') + ->where('pw.website_id=?', $websiteId) + ->where( + $this->_getWriteAdapter()->getCheckSql('ss.value_id IS NOT NULL', 'ss.value', 'ds.value') . ' = ?', + Mage_Catalog_Model_Product_Status::STATUS_ENABLED) + ->columns(array( + 'category_id' => new Zend_Db_Expr($rootId), + 'product_id' => 'pw.product_id', + 'position' => new Zend_Db_Expr('0'), + 'is_parent' => new Zend_Db_Expr('1'), + 'store_id' => new Zend_Db_Expr($storeId), + 'visibility' => $adapter->getCheckSql('sv.value_id IS NOT NULL', 'sv.value', 'dv.value') + )); + + $query = $select->insertFromSelect($this->getMainTable()); + $this->_getWriteAdapter()->query($query); + } + + return $this; + } + + + /** + * Rebuild index for direct associations categories and products + * + * @param null|array $categoryIds + * @param null|array $productIds + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + protected function _refreshDirectRelations($categoryIds = null, $productIds = null) + { + if (!$categoryIds && !$productIds) { + return $this; + } + + $visibilityInfo = $this->_getVisibilityAttributeInfo(); + $statusInfo = $this->_getStatusAttributeInfo(); + $adapter = $this->_getWriteAdapter(); + /** + * Insert direct relations + * product_ids (enabled filter) X category_ids X store_ids + * Validate store root category + */ + $isParent = new Zend_Db_Expr('1'); + $select = $adapter->select() + ->from(array('cp' => $this->_categoryProductTable), + array('category_id', 'product_id', 'position', $isParent)) + ->joinInner(array('pw' => $this->_productWebsiteTable), 'pw.product_id=cp.product_id', array()) + ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) + ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array('store_id')) + ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', array()) + ->joinInner( + array('ce'=>$this->_categoryTable), + 'ce.entity_id=cp.category_id AND ('. + $adapter->quoteIdentifier('ce.path') . ' LIKE ' . + $adapter->getConcatSql(array($adapter->quoteIdentifier('rc.path') , $adapter->quote('/%'))) . + ' OR ce.entity_id=rc.entity_id)', + array()) + ->joinLeft( + array('dv'=>$visibilityInfo['table']), + $adapter->quoteInto( + "dv.entity_id=cp.product_id AND dv.attribute_id=? AND dv.store_id=0", + $visibilityInfo['id']), + array() + ) + ->joinLeft( + array('sv'=>$visibilityInfo['table']), + $adapter->quoteInto( + "sv.entity_id=cp.product_id AND sv.attribute_id=? AND sv.store_id=s.store_id", + $visibilityInfo['id']), + array('visibility' => $adapter->getCheckSql('sv.value_id IS NOT NULL', + $adapter->quoteIdentifier('sv.value'), + $adapter->quoteIdentifier('dv.value') + )) + ) + ->joinLeft( + array('ds'=>$statusInfo['table']), + "ds.entity_id=cp.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", + array()) + ->joinLeft( + array('ss'=>$statusInfo['table']), + "ss.entity_id=cp.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", + array()) + ->where( + $adapter->getCheckSql('ss.value_id IS NOT NULL', + $adapter->quoteIdentifier('ss.value'), + $adapter->quoteIdentifier('ds.value') + ) . ' = ?', + Mage_Catalog_Model_Product_Status::STATUS_ENABLED + ); + if ($categoryIds) { + $select->where('cp.category_id IN (?)', $categoryIds); + } + if ($productIds) { + $select->where('cp.product_id IN(?)', $productIds); + } + $sql = $select->insertFromSelect( + $this->getMainTable(), + array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), + true + ); + $adapter->query($sql); + return $this; + } + + /** + * Rebuild index for anchor categories and associated t child categories products + * + * @param null | array $categoryIds + * @param null | array $productIds + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + protected function _refreshAnchorRelations($categoryIds = null, $productIds = null) + { + if (!$categoryIds && !$productIds) { + return $this; + } + + $anchorInfo = $this->_getAnchorAttributeInfo(); + $visibilityInfo = $this->_getVisibilityAttributeInfo(); + $statusInfo = $this->_getStatusAttributeInfo(); + + /** + * Insert anchor categories relations + */ + $adapter = $this->_getReadAdapter(); + $isParent = $adapter->getCheckSql('MIN(cp.category_id)=ce.entity_id', 1, 0); // new Zend_Db_Expr('IF (, 1, 0) AS is_parent'); + $position = $adapter->getCheckSql( + 'MIN(cp.category_id)=ce.entity_id', + 'MIN(cp.position)', + 'ROUND((MIN(cc.position) + 1) * (MIN(' . $adapter->quoteIdentifier('cc.level') . ') + 1) * 10000, 0)'. + ' + MIN(cp.position)' + ); + $select = $adapter->select() + ->distinct(true) + ->from(array('ce' => $this->_categoryTable), array('entity_id')) + ->joinLeft( + array('cc' => $this->_categoryTable), + $adapter->quoteIdentifier('cc.path') . + ' LIKE ('.$adapter->getConcatSql(array($adapter->quoteIdentifier('ce.path'),$adapter->quote('/%'))).')' + , array() + ) + ->joinInner( + array('cp' => $this->_categoryProductTable), + 'cp.category_id=cc.entity_id OR cp.category_id=ce.entity_id', + array('cp.product_id', 'position' => $position, 'is_parent' => $isParent) + ) + ->joinInner(array('pw' => $this->_productWebsiteTable), 'pw.product_id=cp.product_id', array()) + ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) + ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array('store_id')) + ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', array()) + ->joinLeft( + array('dca'=>$anchorInfo['table']), + "dca.entity_id=ce.entity_id AND dca.attribute_id={$anchorInfo['id']} AND dca.store_id=0", + array()) + ->joinLeft( + array('sca'=>$anchorInfo['table']), + "sca.entity_id=ce.entity_id AND sca.attribute_id={$anchorInfo['id']} AND sca.store_id=s.store_id", + array()) + ->joinLeft( + array('dv'=>$visibilityInfo['table']), + "dv.entity_id=pw.product_id AND dv.attribute_id={$visibilityInfo['id']} AND dv.store_id=0", + array()) + ->joinLeft( + array('sv'=>$visibilityInfo['table']), + "sv.entity_id=pw.product_id AND sv.attribute_id={$visibilityInfo['id']} AND sv.store_id=s.store_id", + array('visibility' => $adapter->getCheckSql('MIN(sv.value_id) IS NOT NULL', 'MIN(sv.value)', 'MIN(dv.value)')) + ) + ->joinLeft( + array('ds'=>$statusInfo['table']), + "ds.entity_id=pw.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", + array()) + ->joinLeft( + array('ss'=>$statusInfo['table']), + "ss.entity_id=pw.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", + array()) + /** + * Condition for anchor or root category (all products should be assigned to root) + */ + ->where('('. + $adapter->quoteIdentifier('ce.path') . ' LIKE ' . + $adapter->getConcatSql(array($adapter->quoteIdentifier('rc.path'), $adapter->quote('/%'))) . ' AND ' . + $adapter->getCheckSql('sca.value_id IS NOT NULL', + $adapter->quoteIdentifier('sca.value'), + $adapter->quoteIdentifier('dca.value')) . '=1) OR ce.entity_id=rc.entity_id' + ) + ->where( + $adapter->getCheckSql('ss.value_id IS NOT NULL', 'ss.value', 'ds.value') . '=?', + Mage_Catalog_Model_Product_Status::STATUS_ENABLED + ) + ->group(array('ce.entity_id', 'cp.product_id', 's.store_id')); + if ($categoryIds) { + $select->where('ce.entity_id IN (?)', $categoryIds); + } + if ($productIds) { + $select->where('pw.product_id IN(?)', $productIds); + } + + $sql = $select->insertFromSelect($this->getMainTable()); + $this->_getWriteAdapter()->query($sql); + return $this; + } + + /** + * Add product association with root store category for products which are not assigned to any another category + * + * @param int | array $productIds + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + protected function _refreshRootRelations($productIds) + { + $visibilityInfo = $this->_getVisibilityAttributeInfo(); + $statusInfo = $this->_getStatusAttributeInfo(); + $adapter = $this->_getWriteAdapter(); + /** + * Insert anchor categories relations + */ + $isParent = new Zend_Db_Expr('0'); + $position = new Zend_Db_Expr('0'); + $select = $this->_getReadAdapter()->select() + ->distinct(true) + ->from(array('pw' => $this->_productWebsiteTable), array()) + ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) + ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array()) + ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', + array('entity_id')) + ->joinLeft(array('cp' => $this->_categoryProductTable), 'cp.product_id=pw.product_id', + array('pw.product_id', $position, $isParent, 's.store_id')) + ->joinLeft( + array('dv'=>$visibilityInfo['table']), + "dv.entity_id=pw.product_id AND dv.attribute_id={$visibilityInfo['id']} AND dv.store_id=0", + array()) + ->joinLeft( + array('sv'=>$visibilityInfo['table']), + "sv.entity_id=pw.product_id AND sv.attribute_id={$visibilityInfo['id']} AND sv.store_id=s.store_id", + array('visibility' => $adapter->getCheckSql('sv.value_id IS NOT NULL', + $adapter->quoteIdentifier('sv.value'), + $adapter->quoteIdentifier('dv.value') + )) + ) + ->joinLeft( + array('ds'=>$statusInfo['table']), + "ds.entity_id=pw.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", + array()) + ->joinLeft( + array('ss'=>$statusInfo['table']), + "ss.entity_id=pw.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", + array()) + /** + * Condition for anchor or root category (all products should be assigned to root) + */ + ->where('cp.product_id IS NULL') + ->where( + $adapter->getCheckSql('ss.value_id IS NOT NULL', + $adapter->quoteIdentifier('ss.value'), + $adapter->quoteIdentifier('ds.value') + ) . ' = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) + ->where('pw.product_id IN(?)', $productIds); + + $sql = $select->insertFromSelect($this->getMainTable()); + $this->_getWriteAdapter()->query($sql); + + $select = $this->_getReadAdapter()->select() + ->from(array('pw' => $this->_productWebsiteTable), array()) + ->joinInner(array('g' => $this->_groupTable), 'g.website_id = pw.website_id', array()) + ->joinInner(array('s' => $this->_storeTable), 's.group_id = g.group_id', array()) + ->joinLeft(array('i' => $this->getMainTable()), 'i.product_id = pw.product_id AND i.category_id = g.root_category_id', array()) + ->joinLeft( + array('dv' => $visibilityInfo['table']), + "dv.entity_id = pw.product_id AND dv.attribute_id = {$visibilityInfo['id']} AND dv.store_id = 0", + array()) + ->joinLeft( + array('sv' => $visibilityInfo['table']), + "sv.entity_id = pw.product_id AND sv.attribute_id = {$visibilityInfo['id']} AND sv.store_id = s.store_id", + array()) + ->join( + array('ds' => $statusInfo['table']), + "ds.entity_id = pw.product_id AND ds.attribute_id = {$statusInfo['id']} AND ds.store_id = 0", + array()) + ->joinLeft( + array('ss' => $statusInfo['table']), + "ss.entity_id = pw.product_id AND ss.attribute_id = {$statusInfo['id']} AND ss.store_id = s.store_id", + array()) + ->where('i.product_id IS NULL') + ->where($adapter->getCheckSql('ss.value_id IS NOT NULL', 'ss.value', 'ds.value') . '=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) + ->where('pw.product_id IN(?)', $productIds) + ->columns(array( + 'category_id' => 'g.root_category_id', + 'product_id' => 'pw.product_id', + 'position' => $position, + 'is_parent' => new Zend_Db_Expr('1'), + 'store_id' => 's.store_id', + 'visibility' => $adapter->getCheckSql('sv.value_id IS NOT NULL', 'sv.value', 'dv.value'), + )); + + $sql = $select->insertFromSelect($this->getMainTable()); + $this->_getWriteAdapter()->query($sql); + + return $this; + } + + /** + * Get is_anchor category attribute information + * + * @return array array('id' => $id, 'table'=>$table) + */ + protected function _getAnchorAttributeInfo() + { + $isAnchorAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_anchor'); + $info = array( + 'id' => $isAnchorAttribute->getId() , + 'table' => $isAnchorAttribute->getBackend()->getTable() + ); + return $info; + } + + /** + * Get visibility product attribute information + * + * @return array array('id' => $id, 'table'=>$table) + */ + protected function _getVisibilityAttributeInfo() + { + $visibilityAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'visibility'); + $info = array( + 'id' => $visibilityAttribute->getId() , + 'table' => $visibilityAttribute->getBackend()->getTable() + ); + return $info; + } + + /** + * Get status product attribute information + * + * @return array array('id' => $id, 'table'=>$table) + */ + protected function _getStatusAttributeInfo() + { + $statusAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'status'); + $info = array( + 'id' => $statusAttribute->getId() , + 'table' => $statusAttribute->getBackend()->getTable() + ); + return $info; + } + + /** + * Rebuild all index data + * + * @return Mage_Catalog_Model_Resource_Category_Indexer_Product + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->clearTemporaryIndexTable(); + $idxTable = $this->getIdxTable(); + $idxAdapter = $this->_getIndexAdapter(); + $stores = $this->_getStoresInfo(); + /** + * Build index for each store + */ + foreach ($stores as $storeData) { + $storeId = $storeData['store_id']; + $websiteId = $storeData['website_id']; + $rootPath = $storeData['root_path']; + $rootId = $storeData['root_id']; + /** + * Prepare visibility for all enabled store products + */ + $enabledTable = $this->_prepareEnabledProductsVisibility($websiteId, $storeId); + /** + * Select information about anchor categories + */ + $anchorTable = $this->_prepareAnchorCategories($storeId, $rootPath); + /** + * Add relations between not anchor categories and products + */ + $select = $idxAdapter->select(); + /** @var $select Varien_Db_Select */ + $select->from( + array('cp' => $this->_categoryProductTable), + array('category_id', 'product_id', 'position', 'is_parent' => new Zend_Db_Expr('1'), + 'store_id' => new Zend_Db_Expr($storeId)) + ) + ->joinInner(array('pv' => $enabledTable), 'pv.product_id=cp.product_id', array('visibility')) + ->joinLeft(array('ac' => $anchorTable), 'ac.category_id=cp.category_id', array()) + ->where('ac.category_id IS NULL'); + + $query = $select->insertFromSelect( + $idxTable, + array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), + false + ); + $idxAdapter->query($query); + + /** + * Assign products not associated to any category to root category in index + */ + + $select = $idxAdapter->select(); + $select->from( + array('pv' => $enabledTable), + array(new Zend_Db_Expr($rootId), 'product_id', new Zend_Db_Expr('0'), new Zend_Db_Expr('1'), + new Zend_Db_Expr($storeId), 'visibility') + ) + ->joinLeft(array('cp' => $this->_categoryProductTable), 'pv.product_id=cp.product_id', array()) + ->where('cp.product_id IS NULL'); + + $query = $select->insertFromSelect( + $idxTable, + array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), + false + ); + $idxAdapter->query($query); + + /** + * Prepare anchor categories products + */ + $anchorProductsTable = $this->_getAnchorCategoriesProductsTemporaryTable(); + $idxAdapter->delete($anchorProductsTable); + + $position = $idxAdapter->getCheckSql('ca.category_id=MIN(ce.entity_id)', + 'MIN(' . $idxAdapter->quoteIdentifier('cp.position') . ')', + 'ROUND((MIN(' . $idxAdapter->quoteIdentifier('ce.position') . ') + 1) * ' . + '(MIN(' . $idxAdapter->quoteIdentifier('ce.level') . ') + 1) * 10000, 0) + ' . + 'MIN(' . $idxAdapter->quoteIdentifier('cp.position') . ')' + ); + + $select = $idxAdapter->select() + ->useStraightJoin(true) + ->distinct(true) + ->from(array('ca' => $anchorTable), array('category_id')) + ->joinInner( + array('ce' => $this->_categoryTable), + $idxAdapter->quoteIdentifier('ce.path') . ' LIKE ' . + $idxAdapter->quoteIdentifier('ca.path') . ' OR ce.entity_id = ca.category_id', + array() + ) + ->joinInner( + array('cp' => $this->_categoryProductTable), + 'cp.category_id = ce.entity_id', + array('product_id') + ) + ->joinInner(array('pv' => $enabledTable), 'pv.product_id = cp.product_id', array('position' => $position)) + ->group(array('ca.category_id', 'cp.product_id')); + $query = $select->insertFromSelect($anchorProductsTable, + array('category_id', 'product_id', 'position'), false); + $idxAdapter->query($query); + + /** + * Add anchor categories products to index + */ + $select = $idxAdapter->select() + ->from( + array('ap' => $anchorProductsTable), + array('category_id', 'product_id', + 'position', // => new Zend_Db_Expr('MIN('. $idxAdapter->quoteIdentifier('ap.position').')'), + 'is_parent' => $idxAdapter->getCheckSql('cp.product_id > 0', 1, 0), + 'store_id' => new Zend_Db_Expr($storeId)) + ) + ->joinLeft( + array('cp' => $this->_categoryProductTable), + 'cp.category_id=ap.category_id AND cp.product_id=ap.product_id', + array() + ) + ->joinInner(array('pv' => $enabledTable), 'pv.product_id = ap.product_id', array('visibility')); + + $query = $select->insertFromSelect( + $idxTable, + array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), + false + ); + $idxAdapter->query($query); + + $select = $idxAdapter->select() + ->from(array('e' => $this->getTable('catalog/product')), null) + ->join( + array('ei' => $enabledTable), + 'ei.product_id = e.entity_id', + array()) + ->joinLeft( + array('i' => $idxTable), + 'i.product_id = e.entity_id AND i.category_id = :category_id AND i.store_id = :store_id', + array()) + ->where('i.product_id IS NULL') + ->columns(array( + 'category_id' => new Zend_Db_Expr($rootId), + 'product_id' => 'e.entity_id', + 'position' => new Zend_Db_Expr('0'), + 'is_parent' => new Zend_Db_Expr('1'), + 'store_id' => new Zend_Db_Expr($storeId), + 'visibility' => 'ei.visibility' + )); + + $query = $select->insertFromSelect( + $idxTable, + array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), + false + ); + + $idxAdapter->query($query, array('store_id' => $storeId, 'category_id' => $rootId)); + } + + $this->syncData(); + + /** + * Clean up temporary tables + */ + $this->clearTemporaryIndexTable(); + $idxAdapter->delete($enabledTable); + $idxAdapter->delete($anchorTable); + $idxAdapter->delete($anchorProductsTable); + return $this; + } + + + /** + * Create temporary table with enabled products visibility info + * + * @param int $websiteId + * @param int $storeId + * @return string temporary table name + */ + protected function _prepareEnabledProductsVisibility($websiteId, $storeId) + { + $statusAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'status'); + $visibilityAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'visibility'); + $statusAttributeId = $statusAttribute->getId(); + $visibilityAttributeId = $visibilityAttribute->getId(); + $statusTable = $statusAttribute->getBackend()->getTable(); + $visibilityTable = $visibilityAttribute->getBackend()->getTable(); + + /** + * Prepare temporary table + */ + $tmpTable = $this->_getEnabledProductsTemporaryTable(); + $this->_getIndexAdapter()->delete($tmpTable); + + $adapter = $this->_getIndexAdapter(); + $visibilityExpr = $adapter->getCheckSql('pvs.value_id>0', $adapter->quoteIdentifier('pvs.value'), + $adapter->quoteIdentifier('pvd.value')); + $select = $adapter->select() + ->from(array('pw' => $this->_productWebsiteTable), array('product_id', 'visibility' => $visibilityExpr)) + ->joinLeft( + array('pvd' => $visibilityTable), + $adapter->quoteInto('pvd.entity_id=pw.product_id AND pvd.attribute_id=? AND pvd.store_id=0', + $visibilityAttributeId), + array()) + ->joinLeft( + array('pvs' => $visibilityTable), + $adapter->quoteInto('pvs.entity_id=pw.product_id AND pvs.attribute_id=? AND ', $visibilityAttributeId) + . $adapter->quoteInto('pvs.store_id=?', $storeId), + array()) + ->joinLeft( + array('psd' => $statusTable), + $adapter->quoteInto('psd.entity_id=pw.product_id AND psd.attribute_id=? AND psd.store_id=0', + $statusAttributeId), + array()) + ->joinLeft( + array('pss' => $statusTable), + $adapter->quoteInto('pss.entity_id=pw.product_id AND pss.attribute_id=? AND ', $statusAttributeId) + . $adapter->quoteInto('pss.store_id=?', $storeId), + array()) + ->where('pw.website_id=?',$websiteId) + ->where($adapter->getCheckSql('pss.value_id > 0', + $adapter->quoteIdentifier('pss.value'), + $adapter->quoteIdentifier('psd.value')) . ' = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + + $query = $select->insertFromSelect($tmpTable, array('product_id' , 'visibility'), false); + $adapter->query($query); + return $tmpTable; + } + + /** + * Retrieve temporary table of category enabled products + * + * @return string + */ + protected function _getEnabledProductsTemporaryTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/category_product_enabled_indexer_idx'); + } + return $this->getTable('catalog/category_product_enabled_indexer_tmp'); + } + + /** + * Get array with store|website|root_categry path information + * + * @return array + */ + protected function _getStoresInfo() + { + if (is_null($this->_storesInfo)) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from(array('s' => $this->getTable('core/store')), array('store_id', 'website_id')) + ->join( + array('sg' => $this->getTable('core/store_group')), + 'sg.group_id = s.group_id', + array()) + ->join( + array('c' => $this->getTable('catalog/category')), + 'c.entity_id = sg.root_category_id', + array( + 'root_path' => 'path', + 'root_id' => 'entity_id' + ) + ); + $this->_storesInfo = $adapter->fetchAll($select); + } + + return $this->_storesInfo; + } + + + /** + * @param int $storeId + * @param string $rootPath + * @return string temporary table name + */ + protected function _prepareAnchorCategories($storeId, $rootPath) + { + $isAnchorAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_anchor'); + $anchorAttributeId = $isAnchorAttribute->getId(); + $anchorTable = $isAnchorAttribute->getBackend()->getTable(); + $adapter = $this->_getIndexAdapter(); + $tmpTable = $this->_getAnchorCategoriesTemporaryTable(); + $adapter->delete($tmpTable); + + $anchorExpr = $adapter->getCheckSql('cas.value_id>0', $adapter->quoteIdentifier('cas.value'), + $adapter->quoteIdentifier('cad.value')); + $pathConcat = $adapter->getConcatSql(array($adapter->quoteIdentifier('ce.path'), $adapter->quote('/%'))); + $select = $adapter->select() + ->from( + array('ce' => $this->_categoryTable), + array('category_id' => 'ce.entity_id', 'path' => $pathConcat)) + ->joinLeft( + array('cad' => $anchorTable), + $adapter->quoteInto("cad.entity_id=ce.entity_id AND cad.attribute_id=? AND cad.store_id=0", + $anchorAttributeId), + array()) + ->joinLeft( + array('cas' => $anchorTable), + $adapter->quoteInto("cas.entity_id=ce.entity_id AND cas.attribute_id=? AND ", $anchorAttributeId) + . $adapter->quoteInto('cas.store_id=?', $storeId), + array()) + ->where("{$anchorExpr} = 1 AND {$adapter->quoteIdentifier('ce.path')} LIKE ?", $rootPath . '%1') + ->orWhere('ce.path = ?', $rootPath); + + $query = $select->insertFromSelect($tmpTable, array('category_id' , 'path'), false); + $adapter->query($query); + return $tmpTable; + } + + /** + * Retrieve temporary table of anchor categories + * + * @return string + */ + protected function _getAnchorCategoriesTemporaryTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/category_anchor_indexer_idx'); + } + return $this->getTable('catalog/category_anchor_indexer_tmp'); + } + + /** + * Retrieve temporary table of anchor categories products + * + * @return string + */ + protected function _getAnchorCategoriesProductsTemporaryTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/category_anchor_products_indexer_idx'); + } + return $this->getTable('catalog/category_anchor_products_indexer_tmp'); + } + + /** + * Retrieve temporary decimal index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/category_product_indexer_idx'); + } + return $this->getTable('catalog/category_product_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php new file mode 100755 index 0000000000..0e73fad4ad --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php @@ -0,0 +1,658 @@ + + */ +class Mage_Catalog_Model_Resource_Category_Tree extends Varien_Data_Tree_Dbp +{ + const ID_FIELD = 'id'; + const PATH_FIELD = 'path'; + const ORDER_FIELD = 'order'; + const LEVEL_FIELD = 'level'; + + /** + * Categories resource collection + * + * @var Mage_Catalog_Model_Resource_Category_Collection + */ + protected $_collection; + + /** + * Id of 'is_active' category attribute + * + * @var int + */ + protected $_isActiveAttributeId = null; + + /** + * Join URL rewrites data to collection flag + * + * @var boolean + */ + protected $_joinUrlRewriteIntoCollection = false; + + /** + * Inactive categories ids + * + * @var array + */ + protected $_inactiveCategoryIds = null; + + /** + * store id + * + * @var integer + */ + protected $_storeId = null; + + /** + * Initialize tree + * + */ + public function __construct() + { + $resource = Mage::getSingleton('core/resource'); + + parent::__construct( + $resource->getConnection('catalog_write'), + $resource->getTableName('catalog/category'), + array( + Varien_Data_Tree_Dbp::ID_FIELD => 'entity_id', + Varien_Data_Tree_Dbp::PATH_FIELD => 'path', + Varien_Data_Tree_Dbp::ORDER_FIELD => 'position', + Varien_Data_Tree_Dbp::LEVEL_FIELD => 'level', + ) + ); + } + + /** + * Set store id + * + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + public function setStoreId($storeId) + { + $this->_storeId = (int) $storeId; + return $this; + } + + /** + * Return store id + * + * @return integer + */ + public function getStoreId() + { + if ($this->_storeId === null) { + $this->_storeId = Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Enter description here... + * + * @param Mage_Catalog_Model_Resource_Category_Collection $collection + * @param boolean $sorted + * @param array $exclude + * @param boolean $toLoad + * @param boolean $onlyActive + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + public function addCollectionData($collection = null, $sorted = false, $exclude = array(), $toLoad = true, + $onlyActive = false) + { + if (is_null($collection)) { + $collection = $this->getCollection($sorted); + } else { + $this->setCollection($collection); + } + + if (!is_array($exclude)) { + $exclude = array($exclude); + } + + $nodeIds = array(); + foreach ($this->getNodes() as $node) { + if (!in_array($node->getId(), $exclude)) { + $nodeIds[] = $node->getId(); + } + } + $collection->addIdFilter($nodeIds); + if ($onlyActive) { + + $disabledIds = $this->_getDisabledIds($collection); + if ($disabledIds) { + $collection->addFieldToFilter('entity_id', array('nin' => $disabledIds)); + } + $collection->addAttributeToFilter('is_active', 1); + $collection->addAttributeToFilter('include_in_menu', 1); + } + + if ($this->_joinUrlRewriteIntoCollection) { + $collection->joinUrlRewrite(); + $this->_joinUrlRewriteIntoCollection = false; + } + + if ($toLoad) { + $collection->load(); + + foreach ($collection as $category) { + if ($this->getNodeById($category->getId())) { + $this->getNodeById($category->getId()) + ->addData($category->getData()); + } + } + + foreach ($this->getNodes() as $node) { + if (!$collection->getItemById($node->getId()) && $node->getParent()) { + $this->removeNode($node); + } + } + } + + return $this; + } + + /** + * Add inactive categories ids + * + * @param unknown_type $ids + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + public function addInactiveCategoryIds($ids) + { + if (!is_array($this->_inactiveCategoryIds)) { + $this->_initInactiveCategoryIds(); + } + $this->_inactiveCategoryIds = array_merge($ids, $this->_inactiveCategoryIds); + return $this; + } + + /** + * Retrieve inactive categories ids + * + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + protected function _initInactiveCategoryIds() + { + $this->_inactiveCategoryIds = array(); + Mage::dispatchEvent('catalog_category_tree_init_inactive_category_ids', array('tree' => $this)); + return $this; + } + + /** + * Retrieve inactive categories ids + * + * @return array + */ + public function getInactiveCategoryIds() + { + if (!is_array($this->_inactiveCategoryIds)) { + $this->_initInactiveCategoryIds(); + } + + return $this->_inactiveCategoryIds; + } + + /** + * Return disable category ids + * + * @param Mage_Catalog_Model_Resource_Category_Collection $collection + * @return array + */ + protected function _getDisabledIds($collection) + { + $storeId = Mage::app()->getStore()->getId(); + + $this->_inactiveItems = $this->getInactiveCategoryIds(); + + + $this->_inactiveItems = array_merge( + $this->_getInactiveItemIds($collection, $storeId), + $this->_inactiveItems + ); + + + $allIds = $collection->getAllIds(); + $disabledIds = array(); + + foreach ($allIds as $id) { + $parents = $this->getNodeById($id)->getPath(); + foreach ($parents as $parent) { + if (!$this->_getItemIsActive($parent->getId(), $storeId)){ + $disabledIds[] = $id; + continue; + } + } + } + return $disabledIds; + } + + /** + * Returns attribute id for attribute "is_active" + * + * @return int + */ + protected function _getIsActiveAttributeId() + { + $resource = Mage::getSingleton('core/resource'); + if (is_null($this->_isActiveAttributeId)) { + $bind = array( + 'entity_type_code' => Mage_Catalog_Model_Category::ENTITY, + 'attribute_code' => 'is_active' + ); + $select = $this->_conn->select() + ->from(array('a'=>$resource->getTableName('eav/attribute')), array('attribute_id')) + ->join(array('t'=>$resource->getTableName('eav/entity_type')), 'a.entity_type_id = t.entity_type_id') + ->where('entity_type_code = :entity_type_code') + ->where('attribute_code = :attribute_code'); + + $this->_isActiveAttributeId = $this->_conn->fetchOne($select, $bind); + } + return $this->_isActiveAttributeId; + } + + /** + * Retrieve inactive category item ids + * + * @param Mage_Catalog_Model_Resource_Category_Collection $collection + * @param int $storeId + * @return array + */ + protected function _getInactiveItemIds($collection, $storeId) + { + $filter = $collection->getAllIdsSql(); + $attributeId = $this->_getIsActiveAttributeId(); + + $conditionSql = $this->_conn->getCheckSql('c.value_id > 0', 'c.value', 'd.value'); + $table = Mage::getSingleton('core/resource')->getTableName(array('catalog/category', 'int')); + $bind = array( + 'attribute_id' => $attributeId, + 'store_id' => $storeId, + 'zero_store_id'=> 0, + 'cond' => 0, + + ); + $select = $this->_conn->select() + ->from(array('d'=>$table), array('d.entity_id')) + ->where('d.attribute_id = :attribute_id') + ->where('d.store_id = :zero_store_id') + ->where('d.entity_id IN (?)', new Zend_Db_Expr($filter)) + ->joinLeft( + array('c'=>$table), + 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = d.entity_id', + array() + ) + ->where($conditionSql . ' = :cond'); + + return $this->_conn->fetchCol($select, $bind); + } + + /** + * Check is category items active + * + * @param int $id + * @return boolean + */ + protected function _getItemIsActive($id) + { + if (!in_array($id, $this->_inactiveItems)) { + return true; + } + return false; + } + + /** + * Get categories collection + * + * @param boolean $sorted + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function getCollection($sorted = false) + { + if (is_null($this->_collection)) { + $this->_collection = $this->_getDefaultCollection($sorted); + } + return $this->_collection; + } + + /** + * Enter description here... + * + * @param Mage_Catalog_Model_Resource_Category_Collection $collection + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + public function setCollection($collection) + { + if (!is_null($this->_collection)) { + destruct($this->_collection); + } + $this->_collection = $collection; + return $this; + } + + /** + * Enter description here... + * + * @param boolean $sorted + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + protected function _getDefaultCollection($sorted = false) + { + $this->_joinUrlRewriteIntoCollection = true; + $collection = Mage::getModel('catalog/category')->getCollection(); + /** @var $collection Mage_Catalog_Model_Resource_Category_Collection */ + + $attributes = Mage::getConfig()->getNode('frontend/category/collection/attributes'); + if ($attributes) { + $attributes = $attributes->asArray(); + $attributes = array_keys($attributes); + } + $collection->addAttributeToSelect($attributes); + + if ($sorted) { + if (is_string($sorted)) { + // $sorted is supposed to be attribute name + $collection->addAttributeToSort($sorted); + } else { + $collection->addAttributeToSort('name'); + } + } + + return $collection; + } + + /** + * Move tree before + * + * @param unknown_type $category + * @param Varien_Data_Tree_Node $newParent + * @param Varien_Data_Tree_Node $prevNode + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + protected function _beforeMove($category, $newParent, $prevNode) + { + Mage::dispatchEvent('catalog_category_tree_move_before', array( + 'category' => $category, + 'prev_parent' => $prevNode, + 'parent' => $newParent + )); + + return $this; + } + + /** + * Executing parents move method and cleaning cache after it + * + * @param unknown_type $category + * @param unknown_type $newParent + * @param unknown_type $prevNode + */ + public function move($category, $newParent, $prevNode = null) + { + $this->_beforeMove($category, $newParent, $prevNode); + Mage::getResourceSingleton('catalog/category')->move($category->getId(), $newParent->getId()); + parent::move($category, $newParent, $prevNode); + + $this->_afterMove($category, $newParent, $prevNode); + } + + /** + * Move tree after + * + * @param unknown_type $category + * @param Varien_Data_Tree_Node $newParent + * @param Varien_Data_Tree_Node $prevNode + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + protected function _afterMove($category, $newParent, $prevNode) + { + Mage::app()->cleanCache(array(Mage_Catalog_Model_Category::CACHE_TAG)); + + Mage::dispatchEvent('catalog_category_tree_move_after', array( + 'category' => $category, + 'prev_node' => $prevNode, + 'parent' => $newParent + )); + + return $this; + } + + /** + * Load whole category tree, that will include specified categories ids. + * + * @param array $ids + * @param bool $addCollectionData + * @param bool $updateAnchorProductCount + * @return Mage_Catalog_Model_Resource_Category_Tree + */ + public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductCount = true) + { + $levelField = $this->_conn->quoteIdentifier('level'); + $pathField = $this->_conn->quoteIdentifier('path'); + // load first two levels, if no ids specified + if (empty($ids)) { + $select = $this->_conn->select() + ->from($this->_table, 'entity_id') + ->where($levelField . ' <= 2'); + $ids = $this->_conn->fetchCol($select); + } + if (!is_array($ids)) { + $ids = array($ids); + } + foreach ($ids as $key => $id) { + $ids[$key] = (int)$id; + } + + // collect paths of specified IDs and prepare to collect all their parents and neighbours + $select = $this->_conn->select() + ->from($this->_table, array('path', 'level')) + ->where('entity_id IN (?)', $ids); + $where = array($levelField . '=0' => true); + + foreach ($this->_conn->fetchAll($select) as $item) { + $pathIds = explode('/', $item['path']); + $level = (int)$item['level']; + while ($level > 0) { + $pathIds[count($pathIds) - 1] = '%'; + $path = implode('/', $pathIds); + $where["$levelField=$level AND $pathField LIKE '$path'"] = true; + array_pop($pathIds); + $level--; + } + } + $where = array_keys($where); + + // get all required records + if ($addCollectionData) { + $select = $this->_createCollectionDataSelect(); + } else { + $select = clone $this->_select; + $select->order($this->_orderField . ' ' . Varien_Db_Select::SQL_ASC); + } + $select->where(implode(' OR ', $where)); + + // get array of records and add them as nodes to the tree + $arrNodes = $this->_conn->fetchAll($select); + if (!$arrNodes) { + return false; + } + if ($updateAnchorProductCount) { + $this->_updateAnchorProductCount($arrNodes); + } + $childrenItems = array(); + foreach ($arrNodes as $key => $nodeInfo) { + $pathToParent = explode('/', $nodeInfo[$this->_pathField]); + array_pop($pathToParent); + $pathToParent = implode('/', $pathToParent); + $childrenItems[$pathToParent][] = $nodeInfo; + } + $this->addChildNodes($childrenItems, '', null); + return $this; + } + + /** + * Load array of category parents + * + * @param string $path + * @param bool $addCollectionData + * @param bool $withRootNode + * @return array + */ + public function loadBreadcrumbsArray($path, $addCollectionData = true, $withRootNode = false) + { + $pathIds = explode('/', $path); + if (!$withRootNode) { + array_shift($pathIds); + } + $result = array(); + if (!empty($pathIds)) { + if ($addCollectionData) { + $select = $this->_createCollectionDataSelect(false); + } else { + $select = clone $this->_select; + } + $select + ->where('e.entity_id IN(?)', $pathIds) + ->order($this->_conn->getLengthSql('e.path') . ' ' . Varien_Db_Select::SQL_ASC); + $result = $this->_conn->fetchAll($select); + $this->_updateAnchorProductCount($result); + } + return $result; + } + + /** + * Replace products count with self products count, if category is non-anchor + * + * @param array $data + */ + protected function _updateAnchorProductCount(&$data) + { + foreach ($data as $key => $row) { + if (0 === (int)$row['is_anchor']) { + $data[$key]['product_count'] = $row['self_product_count']; + } + } + } + + /** + * Obtain select for categories with attributes. + * By default everything from entity table is selected + * + name, is_active and is_anchor + * Also the correct product_count is selected, depending on is the category anchor or not. + * + * @param bool $sorted + * @param array $optionalAttributes + * @return Zend_Db_Select + */ + protected function _createCollectionDataSelect($sorted = true, $optionalAttributes = array()) + { + $select = $this->_getDefaultCollection($sorted ? $this->_orderField : false) + ->getSelect(); + // add attributes to select + $attributes = array('name', 'is_active', 'is_anchor'); + if ($optionalAttributes) { + $attributes = array_unique(array_merge($attributes, $optionalAttributes)); + } + foreach ($attributes as $attributeCode) { + /* @var $attribute Mage_Eav_Model_Entity_Attribute */ + $attribute = Mage::getResourceSingleton('catalog/category')->getAttribute($attributeCode); + // join non-static attribute table + if (!$attribute->getBackend()->isStatic()) { + $tableDefault = sprintf('d_%s', $attributeCode); + $tableStore = sprintf('s_%s', $attributeCode); + $valueExpr = $this->_conn + ->getCheckSql("{$tableStore}.value_id > 0", "{$tableStore}.value", "{$tableDefault}.value"); + + $select + ->joinLeft( + array($tableDefault => $attribute->getBackend()->getTable()), + sprintf('%1$s.entity_id=e.entity_id AND %1$s.attribute_id=%2$d' + . ' AND %1$s.entity_type_id=e.entity_type_id AND %1$s.store_id=%3$d', + $tableDefault, $attribute->getId(), Mage_Core_Model_App::ADMIN_STORE_ID), + array($attributeCode => 'value')) + ->joinLeft( + array($tableStore => $attribute->getBackend()->getTable()), + sprintf('%1$s.entity_id=e.entity_id AND %1$s.attribute_id=%2$d' + . ' AND %1$s.entity_type_id=e.entity_type_id AND %1$s.store_id=%3$d', + $tableStore, $attribute->getId(), $this->getStoreId()), + array($attributeCode => $valueExpr) + ); + } + } + + // count children products qty plus self products qty + $categoriesTable = Mage::getSingleton('core/resource')->getTableName('catalog/category'); + $categoriesProductsTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); + + $subConcat = $this->_conn->getConcatSql(array('e.path', $this->_conn->quote('/%'))); + $subSelect = $this->_conn->select() + ->from(array('see' => $categoriesTable), null) + ->joinLeft( + array('scp' => $categoriesProductsTable), + 'see.entity_id=scp.category_id', + array('COUNT(DISTINCT scp.product_id)')) + ->where('see.entity_id = e.entity_id') + ->orWhere('see.path LIKE ?', $subConcat); + $select->columns(array('product_count' => $subSelect)); + + $subSelect = $this->_conn->select() + ->from(array('cp' => $categoriesProductsTable), 'COUNT(cp.product_id)') + ->where('cp.category_id = e.entity_id'); + + $select->columns(array('self_product_count' => $subSelect)); + + return $select; + } + + /** + * Get real existing category ids by specified ids + * + * @param array $ids + * @return array + */ + public function getExistingCategoryIdsBySpecifiedIds($ids) + { + if (empty($ids)) { + return array(); + } + if (!is_array($ids)) { + $ids = array($ids); + } + $select = $this->_conn->select() + ->from($this->_table, array('entity_id')) + ->where('entity_id IN (?)', $ids); + return $this->_conn->fetchCol($select); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Collection/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Collection/Abstract.php new file mode 100755 index 0000000000..db6a168611 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Collection/Abstract.php @@ -0,0 +1,220 @@ + + */ +class Mage_Catalog_Model_Resource_Collection_Abstract extends Mage_Eav_Model_Entity_Collection_Abstract +{ + /** + * Current scope (store Id) + * + * @var int + */ + protected $_storeId; + + /** + * Set store scope + * + * @param int|string|Mage_Core_Model_Store $store + * @return Mage_Catalog_Model_Resource_Collection_Abstract + */ + public function setStore($store) + { + $this->setStoreId(Mage::app()->getStore($store)->getId()); + return $this; + } + + /** + * Set store scope + * + * @param int|string|Mage_Core_Model_Store $storeId + * @return Mage_Catalog_Model_Resource_Collection_Abstract + */ + public function setStoreId($storeId) + { + if ($storeId instanceof Mage_Core_Model_Store) { + $storeId = $storeId->getId(); + } + $this->_storeId = (int)$storeId; + return $this; + } + + /** + * Return current store id + * + * @return int + */ + public function getStoreId() + { + if (is_null($this->_storeId)) { + $this->setStoreId(Mage::app()->getStore()->getId()); + } + return $this->_storeId; + } + + /** + * Retrieve default store id + * + * @return int + */ + public function getDefaultStoreId() + { + return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; + } + + /** + * Retrieve attributes load select + * + * @param string $table + * @param array|int $attributeIds + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + protected function _getLoadAttributesSelect($table, $attributeIds = array()) + { + if (empty($attributeIds)) { + $attributeIds = $this->_selectAttributes; + } + $storeId = $this->getStoreId(); + + if ($storeId) { + + $adapter = $this->getConnection(); + $entityIdField = $this->getEntity()->getEntityIdField(); + $joinCondition = array( + 't_s.attribute_id = t_d.attribute_id', + 't_s.entity_id = t_d.entity_id', + $adapter->quoteInto('t_s.store_id = ?', $storeId) + ); + $select = $adapter->select() + ->from(array('t_d' => $table), array($entityIdField, 'attribute_id')) + ->joinLeft( + array('t_s' => $table), + implode(' AND ', $joinCondition), + array()) + ->where('t_d.entity_type_id = ?', $this->getEntity()->getTypeId()) + ->where("t_d.{$entityIdField} IN (?)", array_keys($this->_itemsById)) + ->where('t_d.attribute_id IN (?)', $attributeIds) + ->where('t_d.store_id = ?', 0); + } else { + $select = parent::_getLoadAttributesSelect($table) + ->where('store_id = ?', $this->getDefaultStoreId()); + } + + return $select; + } + + /** + * @param Varien_Db_Select $select + * @param string $table + * @param string $type + * @return Varien_Db_Select + */ + protected function _addLoadAttributesSelectValues($select, $table, $type) + { + $storeId = $this->getStoreId(); + if ($storeId) { + $helper = Mage::getResourceHelper('eav'); + $adapter = $this->getConnection(); + $valueExpr = $adapter->getCheckSql( + 't_s.value_id IS NULL', + $helper->prepareEavAttributeValue('t_d.value', $type), + $helper->prepareEavAttributeValue('t_s.value', $type) + ); + + $select->columns(array( + 'default_value' => $helper->prepareEavAttributeValue('t_d.value', $type), + 'store_value' => $helper->prepareEavAttributeValue('t_s.value', $type), + 'value' => $valueExpr + )); + } else { + $select = parent::_addLoadAttributesSelectValues($select, $table, $type); + } + return $select; + } + + /** + * Adding join statement to collection select instance + * + * @param string $method + * @param object $attribute + * @param string $tableAlias + * @param array $condition + * @param string $fieldCode + * @param string $fieldAlias + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + protected function _joinAttributeToSelect($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias) + { + if (isset($this->_joinAttributes[$fieldCode]['store_id'])) { + $store_id = $this->_joinAttributes[$fieldCode]['store_id']; + } else { + $store_id = $this->getStoreId(); + } + + $adapter = $this->getConnection(); + + if ($store_id != $this->getDefaultStoreId() && !$attribute->isScopeGlobal()) { + /** + * Add joining default value for not default store + * if value for store is null - we use default value + */ + $defCondition = '('.implode(') AND (', $condition).')'; + $defAlias = $tableAlias . '_default'; + $defAlias = $this->getConnection()->getTableName($defAlias); + $defFieldAlias= str_replace($tableAlias, $defAlias, $fieldAlias); + $tableAlias = $this->getConnection()->getTableName($tableAlias); + + $defCondition = str_replace($tableAlias, $defAlias, $defCondition); + $defCondition.= $adapter->quoteInto( + " AND " . $adapter->quoteColumnAs("$defAlias.store_id", null) . " = ?", + $this->getDefaultStoreId()); + + $this->getSelect()->$method( + array($defAlias => $attribute->getBackend()->getTable()), + $defCondition, + array() + ); + + $method = 'joinLeft'; + $fieldAlias = $this->getConnection()->getCheckSql("{$tableAlias}.value_id > 0", + $fieldAlias, $defFieldAlias); + $this->_joinAttributes[$fieldCode]['condition_alias'] = $fieldAlias; + $this->_joinAttributes[$fieldCode]['attribute'] = $attribute; + } else { + $store_id = $this->getDefaultStoreId(); + } + $condition[] = $adapter->quoteInto( + $adapter->quoteColumnAs("$tableAlias.store_id", null) . ' = ?', $store_id); + return parent::_joinAttributeToSelect($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Config.php b/app/code/core/Mage/Catalog/Model/Resource/Config.php new file mode 100755 index 0000000000..541040d54f --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Config.php @@ -0,0 +1,152 @@ + + */ +class Mage_Catalog_Model_Resource_Config extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * catalog_product entity type id + * + * @var int + */ + protected $_entityTypeId; + + /** + * Store id + * + * @var int + */ + protected $_storeId = null; + + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('eav/attribute', 'attribute_id'); + } + + /** + * Set store id + * + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Config + */ + public function setStoreId($storeId) + { + $this->_storeId = (int)$storeId; + return $this; + } + + /** + * Return store id. + * If is not set return current app store + * + * @return integer + */ + public function getStoreId() + { + if ($this->_storeId === null) { + return Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Retrieve catalog_product entity type id + * + * @return int + */ + public function getEntityTypeId() + { + if ($this->_entityTypeId === null) { + $this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId(); + } + return $this->_entityTypeId; + } + + /** + * Retrieve Product Attributes Used in Catalog Product listing + * + * @return array + */ + public function getAttributesUsedInListing() + { + $adapter = $this->_getReadAdapter(); + $storeLabelExpr = $adapter->getCheckSql('al.value IS NOT NULL', 'al.value', 'main_table.frontend_label'); + + $select = $adapter->select() + ->from(array('main_table' => $this->getTable('eav/attribute'))) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'main_table.attribute_id = additional_table.attribute_id' + ) + ->joinLeft( + array('al' => $this->getTable('eav/attribute_label')), + 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(), + array('store_label' => $storeLabelExpr) + ) + ->where('main_table.entity_type_id = ?', (int)$this->getEntityTypeId()) + ->where('additional_table.used_in_product_listing = ?', 1); + + return $adapter->fetchAll($select); + } + + /** + * Retrieve Used Product Attributes for Catalog Product Listing Sort By + * + * @return array + */ + public function getAttributesUsedForSortBy() + { + $adapter = $this->_getReadAdapter(); + $storeLabelExpr = $adapter->getCheckSql('al.value IS NULL', 'main_table.frontend_label','al.value'); + $select = $adapter->select() + ->from(array('main_table' => $this->getTable('eav/attribute'))) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'main_table.attribute_id = additional_table.attribute_id', + array() + ) + ->joinLeft( + array('al' => $this->getTable('eav/attribute_label')), + 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(), + array('store_label' => $storeLabelExpr) + ) + ->where('main_table.entity_type_id = ?', (int)$this->getEntityTypeId()) + ->where('additional_table.used_for_sort_by = ?', 1); + + return $adapter->fetchAll($select); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php index 6aff8f0aff..5a159dd360 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php @@ -20,35 +20,87 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog attribute model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @method Mage_Catalog_Model_Resource_Attribute _getResource() + * @method Mage_Catalog_Model_Resource_Attribute getResource() + * @method Mage_Catalog_Model_Resource_Eav_Attribute getFrontendInputRenderer() + * @method string setFrontendInputRenderer(string $value) + * @method int setIsGlobal(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsVisible() + * @method int setIsVisible(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsSearchable() + * @method int setIsSearchable(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getSearchWeight() + * @method int setSearchWeight(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsFilterable() + * @method int setIsFilterable(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsComparable() + * @method int setIsComparable(int $value) + * @method int setIsVisibleOnFront(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsHtmlAllowedOnFront() + * @method int setIsHtmlAllowedOnFront(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsUsedForPriceRules() + * @method int setIsUsedForPriceRules(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsFilterableInSearch() + * @method int setIsFilterableInSearch(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getUsedInProductListing() + * @method int setUsedInProductListing(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getUsedForSortBy() + * @method int setUsedForSortBy(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsConfigurable() + * @method int setIsConfigurable(int $value) + * @method string setApplyTo(string $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsVisibleInAdvancedSearch() + * @method int setIsVisibleInAdvancedSearch(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getPosition() + * @method int setPosition(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsWysiwygEnabled() + * @method int setIsWysiwygEnabled(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsUsedForPromoRules() + * @method int setIsUsedForPromoRules(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsUsedForCustomerSegment() + * @method int setIsUsedForCustomerSegment(int $value) + * @method Mage_Catalog_Model_Resource_Eav_Attribute getIsUsedForTargetRules() + * @method int setIsUsedForTargetRules(int $value) + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Attribute extends Mage_Eav_Model_Entity_Attribute { - const SCOPE_STORE = 0; - const SCOPE_GLOBAL = 1; - const SCOPE_WEBSITE = 2; + const SCOPE_STORE = 0; + const SCOPE_GLOBAL = 1; + const SCOPE_WEBSITE = 2; - const MODULE_NAME = 'Mage_Catalog'; - const ENTITY = 'catalog_eav_attribute'; + const MODULE_NAME = 'Mage_Catalog'; + const ENTITY = 'catalog_eav_attribute'; - protected $_eventPrefix = 'catalog_entity_attribute'; - protected $_eventObject = 'attribute'; + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'catalog_entity_attribute'; + /** + * Event object name + * + * @var string + */ + protected $_eventObject = 'attribute'; /** * Array with labels * * @var array */ - static protected $_labels = null; + static protected $_labels = null; protected function _construct() { @@ -58,6 +110,7 @@ protected function _construct() /** * Processing object before save data * + * @throws Mage_Core_Exception * @return Mage_Core_Model_Abstract */ protected function _beforeSave() @@ -65,11 +118,11 @@ protected function _beforeSave() $this->setData('modulePrefix', self::MODULE_NAME); if (isset($this->_origData['is_global'])) { if (!isset($this->_data['is_global'])) { - Mage::throwException('0_o'); + $this->_data['is_global'] = self::SCOPE_GLOBAL; } if (($this->_data['is_global'] != $this->_origData['is_global']) && $this->_getResource()->isUsedBySuperProducts($this)) { - Mage::throwException(Mage::helper('eav')->__('Scope must not be changed, because the attribute is used in configurable products.')); + Mage::throwException(Mage::helper('catalog')->__('Scope must not be changed, because the attribute is used in configurable products.')); } } if ($this->getFrontendInput() == 'price') { @@ -102,7 +155,7 @@ protected function _afterSave() /** * Init indexing process after attribute data commit * - * @return Mage_CatalogInventory_Model_Stock_Item + * @return Mage_Catalog_Model_Resource_Eav_Attribute */ public function afterCommitCallback() { @@ -138,6 +191,7 @@ protected function _afterDeleteCommit() Mage::getSingleton('index/indexer')->indexEvents( self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE ); + return $this; } /** @@ -187,7 +241,8 @@ public function isScopeStore() */ public function getStoreId() { - if ($dataObject = $this->getDataObject()) { + $dataObject = $this->getDataObject(); + if ($dataObject) { return $dataObject->getStoreId(); } return $this->getData('store_id'); @@ -221,7 +276,7 @@ public function getSourceModel() $model = $this->getData('source_model'); if (empty($model)) { if ($this->getBackendType() == 'int' && $this->getFrontendInput() == 'select') { - return 'eav/entity_attribute_source_table'; + return $this->_getDefaultSourceModel(); } } return $model; @@ -257,8 +312,6 @@ public function getFrontendLabel() protected function _getLabelForStore() { return $this->getFrontendLabel(); -// self::initLabels(); -// return isset(self::$_labels[$this->getData('frontend_label')]) ? self::$_labels[$this->getData('frontend_label')] : false; } /** diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php index 4eaf0e6086..b5fe4fc8a0 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php @@ -20,696 +20,18 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog entity abstract model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -abstract class Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract extends Mage_Eav_Model_Entity_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract extends Mage_Catalog_Model_Resource_Abstract { - /** - * Store firstly set attributes to filter selected attributes when used specific store_id - * - * @var array - */ - protected $_attributes = array(); - /** - * Redeclare attribute model - * - * @return string - */ - protected function _getDefaultAttributeModel() - { - return 'catalog/resource_eav_attribute'; - } - - public function getDefaultStoreId() - { - return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; - } - - /** - * Check whether the attribute is Applicable to the object - * - * @param Varien_Object $object - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @return boolean - */ - protected function _isApplicableAttribute ($object, $attribute) - { - $applyTo = $attribute->getApplyTo(); - return count($applyTo) == 0 || in_array($object->getTypeId(), $applyTo); - } - - /** - * Check whether attribute instance (attribute, backend, frontend or source) has method and applicable - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract|Mage_Eav_Model_Entity_Attribute_Backend_Abstract|Mage_Eav_Model_Entity_Attribute_Frontend_Abstract|Mage_Eav_Model_Entity_Attribute_Source_Abstract $instance - * @param string $method - * @param array $args array of arguments - * @return boolean - */ - protected function _isCallableAttributeInstance($instance, $method, $args) - { - if ($instance instanceof Mage_Eav_Model_Entity_Attribute_Backend_Abstract - && ($method == 'beforeSave' || $method = 'afterSave') - ) { - $attributeCode = $instance->getAttribute()->getAttributeCode(); - if (isset($args[0]) && $args[0] instanceof Varien_Object && $args[0]->getData($attributeCode) === false) { - return false; - } - } - - return parent::_isCallableAttributeInstance($instance, $method, $args); - } - - - - /** - * Retrieve select object for loading entity attributes values - * - * Join attribute store value - * - * @param Varien_Object $object - * @param mixed $rowId - * @return Zend_Db_Select - */ - protected function _getLoadAttributesSelect($object, $table) - { - /** - * This condition is applicable for all cases when we was work in not single - * store mode, customize some value per specific store view and than back - * to single store mode. We should load correct values - */ - if (Mage::app()->isSingleStoreMode()) { - $storeId = Mage::app()->getStore(true)->getId(); - } - else { - $storeId = $object->getStoreId(); - } - - $setId = $object->getAttributeSetId(); - $storeIds = array($this->getDefaultStoreId()); - if ($storeId != $this->getDefaultStoreId()) { - $storeIds[] = $storeId; - } - $select = $this->_getReadAdapter()->select() - ->from(array('attr_table' => $table)) - ->where('attr_table.'.$this->getEntityIdField().'=?', $object->getId()) - ->where('attr_table.store_id IN (?)', $storeIds); - if ($setId) { - $select->join( - array('set_table' => $this->getTable('eav/entity_attribute')), - 'attr_table.attribute_id=set_table.attribute_id AND set_table.attribute_set_id=' . intval($setId), - array() - ); - } - return $select; - } - - /** - * Prepare select object for loading entity attributes values - * - * @param array $selects - * @return Zend_Db_Select - */ - protected function _prepareLoadSelect(array $selects) - { - $select = parent::_prepareLoadSelect($selects); - $select->order('store_id'); - return $select; - } - - /** - * Initialize attribute value for object - * - * @param Mage_Catalog_Model_Abstract $object - * @param array $valueRow - * @return Mage_Eav_Model_Entity_Abstract - */ - protected function _setAttribteValue($object, $valueRow) - { - $attribute = $this->getAttribute($valueRow['attribute_id']); - if ($attribute) { - $attributeCode = $attribute->getAttributeCode(); - $isDefaultStore = $valueRow['store_id'] == $this->getDefaultStoreId(); - if (isset($this->_attributes[$valueRow['attribute_id']])) { - if ($isDefaultStore) { - $object->setAttributeDefaultValue($attributeCode, $valueRow['value']); - } - else { - $object->setAttributeDefaultValue( - $attributeCode, - $this->_attributes[$valueRow['attribute_id']]['value'] - ); - } - } - else { - $this->_attributes[$valueRow['attribute_id']] = $valueRow; - } - - $value = $valueRow['value']; - $valueId = $valueRow['value_id']; - - $object->setData($attributeCode, $value); - if (!$isDefaultStore) { - $object->setExistsStoreValueFlag($attributeCode); - } - $attribute->getBackend()->setValueId($valueId); - } - return $this; - } - - /** - * Insert or Update attribute data - * - * @param Mage_Catalog_Model_Abstract $object - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param mixed $value - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract - */ - protected function _saveAttributeValue($object, $attribute, $value) - { - $write = $this->_getWriteAdapter(); - $storeId = Mage::app()->getStore($object->getStoreId())->getId(); - $table = $attribute->getBackend()->getTable(); - - /** - * If we work in single store mode all values should be saved just - * for default store id - * In this case we clear all not default values - */ - if (Mage::app()->isSingleStoreMode()) { - $storeId = $this->getDefaultStoreId(); - $write->delete($table, join(' AND ', array( - $write->quoteInto('attribute_id=?', $attribute->getAttributeId()), - $write->quoteInto('entity_id=?', $object->getEntityId()), - $write->quoteInto('store_id<>?', $storeId) - ))); - } - - $bind = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getAttributeId(), - 'store_id' => $storeId, - 'entity_id' => $object->getEntityId(), - 'value' => $this->_prepareValueForSave($value, $attribute) - ); - - if ($attribute->isScopeStore()) { - /** - * Update attribute value for store - */ - $this->_attributeValuesToSave[$table][] = $bind; - } else if ($attribute->isScopeWebsite() && $storeId != $this->getDefaultStoreId()) { - /** - * Update attribute value for website - */ - $storeIds = Mage::app()->getStore($storeId)->getWebsite()->getStoreIds(true); - foreach ($storeIds as $storeId) { - $bind['store_id'] = $storeId; - $this->_attributeValuesToSave[$table][] = $bind; - } - } else { - /** - * Update global attribute value - */ - $bind['store_id'] = $this->getDefaultStoreId(); - $this->_attributeValuesToSave[$table][] = $bind; - } - - return $this; - } - - /** - * Insert entity attribute value - * - * @param Varien_Object $object - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param mixed $value - * @return Mage_Eav_Model_Entity_Abstract - */ - protected function _insertAttribute($object, $attribute, $value) - { - /** - * save required attributes in global scope every time if store id different from default - */ - $storeId = Mage::app()->getStore($object->getStoreId())->getId(); - if ($attribute->getIsRequired() && $this->getDefaultStoreId() != $storeId) { - $bind = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getAttributeId(), - 'store_id' => $this->getDefaultStoreId(), - 'entity_id' => $object->getEntityId(), - 'value' => $this->_prepareValueForSave($value, $attribute) - ); - $this->_getWriteAdapter()->select()->insertIgnoreFromSelect($attribute->getBackend()->getTable(), $bind); - } - return $this->_saveAttributeValue($object, $attribute, $value); - -// $entityIdField = $attribute->getBackend()->getEntityIdField(); -// $row = array( -// $entityIdField => $object->getId(), -// 'entity_type_id'=> $object->getEntityTypeId(), -// 'attribute_id' => $attribute->getId(), -// 'value' => $this->_prepareValueForSave($value, $attribute), -// 'store_id' => $this->getDefaultStoreId() -// ); -// -// $fields = array(); -// $bind = array(); -// foreach ($row as $k => $v) { -// $fields[] = $this->_getWriteAdapter()->quoteIdentifier($k); -// $bind[':' . $k] = $v; -// } -// -// $sql = sprintf('INSERT IGNORE INTO %s (%s) VALUES(%s)', -// $this->_getWriteAdapter()->quoteIdentifier($attribute->getBackend()->getTable()), -// implode(',', $fields), -// implode(',', array_keys($bind))); -// -// $this->_getWriteAdapter()->query($sql, $bind); -// if (!$lastId = $this->_getWriteAdapter()->lastInsertId()) { -// $select = $this->_getReadAdapter()->select() -// ->from($attribute->getBackend()->getTable(), 'value_id') -// ->where($entityIdField . '=?', $row[$entityIdField]) -// ->where('entity_type_id=?', $row['entity_type_id']) -// ->where('attribute_id=?', $row['attribute_id']) -// ->where('store_id=?', $row['store_id']); -// $lastId = $select->query()->fetchColumn(); -// } -// if ($object->getStoreId() != $this->getDefaultStoreId()) { -// $this->_updateAttribute($object, $attribute, $lastId, $value); -// } -// return $this; - } - - /** - * Update entity attribute value - * - * @param Varien_Object $object - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param mixed $valueId - * @param mixed $value - * @return Mage_Eav_Model_Entity_Abstract - */ - protected function _updateAttribute($object, $attribute, $valueId, $value) - { - return $this->_saveAttributeValue($object, $attribute, $value); -// -// /** -// * If we work in single store mode all values should be saved just -// * for default store id -// * In this case we clear all not default values -// */ -// if (Mage::app()->isSingleStoreMode()) { -// $this->_getWriteAdapter()->delete( -// $attribute->getBackend()->getTable(), -// $this->_getWriteAdapter()->quoteInto('attribute_id=?', $attribute->getId()) . -// $this->_getWriteAdapter()->quoteInto(' AND entity_id=?', $object->getId()) . -// $this->_getWriteAdapter()->quoteInto( -// ' AND store_id!=?', -// Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID -// ) -// ); -// } -// -// /** -// * Update attribute value for store -// */ -// if ($attribute->isScopeStore()) { -// $this->_updateAttributeForStore($object, $attribute, $value, $object->getStoreId()); -// } -// -// /** -// * Update attribute value for website -// */ -// elseif ($attribute->isScopeWebsite()) { -// if ($object->getStoreId() == 0) { -// $this->_updateAttributeForStore($object, $attribute, $value, $object->getStoreId()); -// } else { -// if (is_array($object->getWebsiteStoreIds())) { -// foreach ($object->getWebsiteStoreIds() as $storeId) { -// $this->_updateAttributeForStore($object, $attribute, $value, $storeId); -// } -// } -// } -// } -// else { -// $this->_getWriteAdapter()->update($attribute->getBackend()->getTable(), -// array('value' => $this->_prepareValueForSave($value, $attribute)), -// 'value_id='.(int)$valueId -// ); -// } -// return $this; - } - - /** - * Update attribute value for specific store - * - * @param Mage_Catalog_Model_Abstract $object - * @param object $attribute - * @param mixed $value - * @param int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract - */ - protected function _updateAttributeForStore($object, $attribute, $value, $storeId) - { - $entityIdField = $attribute->getBackend()->getEntityIdField(); - $select = $this->_getWriteAdapter()->select() - ->from($attribute->getBackend()->getTable(), 'value_id') - ->where('entity_type_id=?', $object->getEntityTypeId()) - ->where("$entityIdField=?",$object->getId()) - ->where('store_id=?', $storeId) - ->where('attribute_id=?', $attribute->getId()); - /** - * When value for store exist - */ - if ($valueId = $this->_getWriteAdapter()->fetchOne($select)) { - $this->_getWriteAdapter()->update($attribute->getBackend()->getTable(), - array('value' => $this->_prepareValueForSave($value, $attribute)), - 'value_id='.$valueId - ); - } - else { - $this->_getWriteAdapter()->insert($attribute->getBackend()->getTable(), array( - $entityIdField => $object->getId(), - 'entity_type_id'=> $object->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'value' => $this->_prepareValueForSave($value, $attribute), - 'store_id' => $storeId - )); - } - - return $this; - } - - /** - * Delete entity attribute values - * - * @param Varien_Object $object - * @param string $table - * @param array $info - * @return Varien_Object - */ - protected function _deleteAttributes($object, $table, $info) - { - $entityIdField = $this->getEntityIdField(); - $globalValues = array(); - $websiteAttributes = array(); - $storeAttributes = array(); - - /** - * Separate attributes by scope - */ - foreach ($info as $itemData) { - $attribute = $this->getAttribute($itemData['attribute_id']); - if ($attribute->isScopeStore()) { - $storeAttributes[] = $itemData['attribute_id']; - } - elseif ($attribute->isScopeWebsite()) { - $websiteAttributes[] = $itemData['attribute_id']; - } - else { - $globalValues[] = $itemData['value_id']; - } - } - - /** - * Delete global scope attributes - */ - if (!empty($globalValues)) { - $condition = $this->_getWriteAdapter()->quoteInto('value_id IN (?)', $globalValues); - $this->_getWriteAdapter()->delete($table, $condition); - } - - $condition = $this->_getWriteAdapter()->quoteInto("$entityIdField=?", $object->getId()) - . $this->_getWriteAdapter()->quoteInto(' AND entity_type_id=?', $object->getEntityTypeId()); - /** - * Delete website scope attributes - */ - if (!empty($websiteAttributes)) { - $storeIds = $object->getWebsiteStoreIds(); - if (!empty($storeIds)) { - $delCondition = $condition - . $this->_getWriteAdapter()->quoteInto(' AND attribute_id IN(?)', $websiteAttributes) - . $this->_getWriteAdapter()->quoteInto(' AND store_id IN(?)', $storeIds); - $this->_getWriteAdapter()->delete($table, $delCondition); - } - } - - /** - * Delete store scope attributes - */ - if (!empty($storeAttributes)) { - $delCondition = $condition - . $this->_getWriteAdapter()->quoteInto(' AND attribute_id IN(?)', $storeAttributes) - . $this->_getWriteAdapter()->quoteInto(' AND store_id =?', $object->getStoreId()); - $this->_getWriteAdapter()->delete($table, $delCondition); - } - return $this; - } - - /** - * Retrieve Object instance with original data - * - * @param Varien_Object $object - * @return Varien_Object - */ - protected function _getOrigObject($object) - { - $className = get_class($object); - $origObject = new $className(); - $origObject->setData(array()); - $origObject->setStoreId($object->getStoreId()); - $this->load($origObject, $object->getData($this->getEntityIdField())); - return $origObject; - } - - protected function _collectOrigData($object) - { - $this->loadAllAttributes($object); - - if ($this->getUseDataSharing()) { - $storeId = $object->getStoreId(); - } else { - $storeId = $this->getStoreId(); - } - - $allStores = Mage::getConfig()->getStoresConfigByPath('system/store/id', array(), 'code'); -//echo "
".print_r($allStores ,1)."
"; exit; - $data = array(); - - foreach ($this->getAttributesByTable() as $table=>$attributes) { - $entityIdField = current($attributes)->getBackend()->getEntityIdField(); - - $select = $this->_getReadAdapter()->select() - ->from($table) - ->where($this->getEntityIdField()."=?", $object->getId()); - - $where = $this->_getReadAdapter()->quoteInto("store_id=?", $storeId); - - $globalAttributeIds = array(); - foreach ($attributes as $attrCode=>$attr) { - if ($attr->getIsGlobal()) { - $globalAttributeIds[] = $attr->getId(); - } - } - if (!empty($globalAttributeIds)) { - $where .= ' or '.$this->_getReadAdapter()->quoteInto('attribute_id in (?)', $globalAttributeIds); - } - $select->where($where); - - $values = $this->_getReadAdapter()->fetchAll($select); - - if (empty($values)) { - continue; - } - foreach ($values as $row) { - $data[$this->getAttribute($row['attribute_id'])->getName()][$row['store_id']] = $row; - } - foreach ($attributes as $attrCode=>$attr) { - - } - } - - return $data; - } - - /** - * Check is attribute value empty - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param mixed $value - * @return bool - */ - protected function _isAttributeValueEmpty(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $value) - { - return $value === false; - } - - /** - * Return if attribute exists in original data array. - * Checks also attribute's store scope: - * We should insert on duplicate key update values if we unchecked 'STORE VIEW' checkbox in store view. - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param mixed $value New value of the attribute. - * @param array $origData - * @return bool - */ - protected function _canUpdateAttribute( - Mage_Eav_Model_Entity_Attribute_Abstract $attribute, - $value, - array &$origData) - { - $result = parent::_canUpdateAttribute($attribute, $value, $origData); - if ($result && - ($attribute->isScopeStore() || $attribute->isScopeWebsite()) && - !$this->_isAttributeValueEmpty($attribute, $value) && - $value == $origData[$attribute->getAttributeCode()] && - isset($origData['store_id']) && $origData['store_id'] != $this->getDefaultStoreId() - ) { - return false; - } - return $result; - } - - /** - * Prepare value for save - * - * @param mixed $value - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @return mixed - */ - protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_Abstract $attribute) - { - $type = $attribute->getBackendType(); - if (($type == 'int' || $type == 'decimal' || $type == 'datetime') && $value === '') { - return null; - } - if ($type == 'decimal') { - return Mage::app()->getLocale()->getNumber($value); - } - return $value; - } - - /** - * Retrieve attribute's raw value from DB. - * - * @param int $entityId - * @param int|string|array $attribute atrribute's ids or codes - * @param int|Mage_Core_Model_Store $store - * @return bool|string|array - */ - public function getAttributeRawValue($entityId, $attribute, $store) - { - if (!$entityId || empty($attribute)) { - return false; - } - if (!is_array($attribute)) { - $attribute = array($attribute); - } - $attributesData = array(); - $staticAttributes = array(); - $typedAttributes = array(); - $staticTable = null; - foreach ($attribute as $_attribute) { - /* @var $attribute Mage_Catalog_Model_Entity_Attribute */ - $_attribute = $this->getAttribute($_attribute); - if (!$_attribute) { - continue; - } - $attributeCode = $_attribute->getAttributeCode(); - $attrTable = $_attribute->getBackend()->getTable(); - $isStatic = $_attribute->getBackend()->isStatic(); - if ($isStatic) { - $staticAttributes[] = $attributeCode; - $staticTable = $attrTable; - } - else { - /** - * That structure needed to avoid farther sql joins for getting attribute's code by id - */ - $typedAttributes[$attrTable][$_attribute->getId()] = $attributeCode; - } - - } - /* @var $select Zend_Db_Select */ - $select = $this->_getReadAdapter()->select(); - /** - * Collecting static attributes - */ - if ($staticAttributes) { - $select->from($staticTable, $staticAttributes) - ->where($this->getEntityIdField() . ' = ?', $entityId); - $attributesData = $this->_getReadAdapter()->fetchRow($select); - } - - /** - * Collecting typed attributes, performing separate SQL query for each attribute type table - */ - if ($store instanceof Mage_Core_Model_Store) { - $store = $store->getId(); - } - $store = (int)$store; - if ($typedAttributes) { - foreach ($typedAttributes as $table => $_attributes) { - $select->reset()->from(array('default_value' => $table), array()); - $select->where('default_value.attribute_id IN (?)', array_keys($_attributes)) - ->where('default_value.entity_type_id = ? ', $this->getTypeId()) - ->where('default_value.entity_id = ? ', $entityId) - ->where('default_value.store_id = 0'); - - $joinCondition = $this->_getReadAdapter()->quoteInto( - 'store_value.attribute_id IN (?)', - array_keys($_attributes) - ); - $joinCondition .= ' AND ' . $this->_getReadAdapter()->quoteInto( - 'store_value.entity_type_id = ?', - $this->getTypeId() - ); - $joinCondition .= ' AND ' . $this->_getReadAdapter()->quoteInto('store_value.entity_id = ?', $entityId); - $joinCondition .= ' AND ' . $this->_getReadAdapter()->quoteInto('store_value.store_id = ?', $store); - - $select->joinLeft(array('store_value' => $table), - $joinCondition, - array( - 'attr_value' => 'IFNULL(store_value.value, default_value.value)', - 'default_value.attribute_id' - ) - ); - $result = $this->_getReadAdapter()->fetchAll($select); - foreach ($result as $key => $_attribute) { - $attributeCode = $typedAttributes[$table][$_attribute['attribute_id']]; - $attributesData[$attributeCode] = $_attribute['attr_value']; - } - } - } - if (sizeof($attributesData) == 1) { - $_data = each($attributesData); - $attributesData = $_data[1]; - } - return $attributesData ? $attributesData : false; - } - - /** - * Reset firstly loaded attributes - * - * @param Varien_Object $object - * @param integer $entityId - * @param array|null $attributes - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract - */ - public function load($object, $entityId, $attributes=array()) - { - $this->_attributes = array(); - return parent::load($object, $entityId, $attributes); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Attribute.php index defb971e54..77dd9a0629 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,25 +28,10 @@ /** * Catalog attribute resource model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute extends Mage_Eav_Model_Mysql4_Entity_Attribute +class Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute extends Mage_Catalog_Model_Resource_Attribute { - /** - * Perform actions before object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $applyTo = $object->getApplyTo(); - if (is_array($applyTo)) { - $object->setApplyTo(implode(',', $applyTo)); - } - return parent::_beforeSave($object); - } - - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php index 0eea4783ca..a8f014f514 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php @@ -20,1167 +20,18 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog category model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category extends Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category extends Mage_Catalog_Model_Resource_Category { - /** - * Category tree object - * - * @var Varien_Data_Tree_Db - */ - protected $_tree; - - /** - * Catalog products table name - * - * @var string - */ - protected $_categoryProductTable; - - /** - * Id of 'is_active' category attribute - * - * @var int - */ - protected $_isActiveAttributeId = null; - - /** - * Store id - * - * @var int - */ - protected $_storeId = null; - - /** - * Class constructor - */ - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - $this->setType('catalog_category') - ->setConnection( - $resource->getConnection('catalog_read'), - $resource->getConnection('catalog_write') - ); - $this->_categoryProductTable = $this->getTable('catalog/category_product'); - } - - /** - * Set store Id - * - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Return store id - * - * @return integer - */ - public function getStoreId() - { - if (is_null($this->_storeId)) { - return Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Retrieve category tree object - * - * @return Varien_Data_Tree_Db - */ - protected function _getTree() - { - if (!$this->_tree) { - $this->_tree = Mage::getResourceModel('catalog/category_tree') - ->load(); - } - return $this->_tree; - } - - /** - * Process category data before delete - * update children count for parent category - * delete child categories - * - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _beforeDelete(Varien_Object $object) - { - parent::_beforeDelete($object); - - /** - * Update children count for all parent categories - */ - $parentIds = $object->getParentIds(); - $childDecrease = $object->getChildrenCount() + 1; // +1 is itself - $this->_getWriteAdapter()->update( - $this->getEntityTable(), - array('children_count'=>new Zend_Db_Expr('`children_count`-'.$childDecrease)), - $this->_getWriteAdapter()->quoteInto('entity_id IN(?)', $parentIds) - ); - $this->deleteChildren($object); - return $this; - } - - /** - * Delete children categories of specific category - * - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - public function deleteChildren(Varien_Object $object) - { - /** - * Recursion use a lot of memmory, that why we run one request for delete children - */ - /*if ($child = $this->_getTree()->getNodeById($object->getId())) { - $children = $child->getChildren(); - foreach ($children as $child) { - $childObject = Mage::getModel('catalog/category')->load($child->getId())->delete(); - } - }*/ - - $select = $this->_getWriteAdapter()->select() - ->from($this->getEntityTable(), array('entity_id')) - ->where($this->_getWriteAdapter()->quoteInto('`path` LIKE ?', $object->getPath().'/%')); - - $childrenIds = $this->_getWriteAdapter()->fetchCol($select); - - if (!empty($childrenIds)) { - $this->_getWriteAdapter()->delete( - $this->getEntityTable(), - $this->_getWriteAdapter()->quoteInto('entity_id IN (?)', $childrenIds) - ); - } - - /** - * Add deleted children ids to object - * This data can be used in after delete event - */ - $object->setDeletedChildrenIds($childrenIds); - return $this; - } - - /** - * Process category data before saving - * prepare path and increment children count for parent categories - * - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _beforeSave(Varien_Object $object) - { - parent::_beforeSave($object); - - if (!$object->getId()) { - $object->setPosition($this->_getMaxPosition($object->getPath()) + 1); - $path = explode('/', $object->getPath()); - $level = count($path); - $object->setLevel($level); - if ($level) { - $object->setParentId($path[$level - 1]); - } - $object->setPath($object->getPath() . '/'); - - $toUpdateChild = explode('/',$object->getPath()); - - $this->_getWriteAdapter()->update( - $this->getEntityTable(), - array('children_count'=>new Zend_Db_Expr('`children_count`+1')), - $this->_getWriteAdapter()->quoteInto('entity_id IN(?)', $toUpdateChild) - ); - - } - return $this; - } - - /** - * Process category data after save category object - * save related products ids and update path value - * - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _afterSave(Varien_Object $object) - { - /** - * Add identifier for new category - */ - if (substr($object->getPath(), -1) == '/') { - $object->setPath($object->getPath() . $object->getId()); - $this->_savePath($object); - } - - $this->_saveCategoryProducts($object); - return parent::_afterSave($object); - } - - /** - * Update path field - * - * @param Mage_Catalog_Model_Category $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _savePath($object) - { - if ($object->getId()) { - $this->_getWriteAdapter()->update( - $this->getEntityTable(), - array('path'=>$object->getPath()), - $this->_getWriteAdapter()->quoteInto('entity_id=?', $object->getId()) - ); - } - return $this; - } - - /** - * Get maximum position of child categories by specific tree path - * - * @param string $path - * @return int - */ - protected function _getMaxPosition($path) - { - $select = $this->getReadConnection()->select(); - $select->from($this->getTable('catalog/category'), 'MAX(position)'); - $select->where('path ?', new Zend_Db_Expr("regexp '{$path}/[0-9]+\$'")); - - $result = 0; - try { - $result = (int) $this->getReadConnection()->fetchOne($select); - } catch (Exception $e) { - - } - return $result; - } - - /** - * Save category products relation - * - * @param Mage_Catalog_Model_Category $category - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _saveCategoryProducts($category) - { - $category->setIsChangedProductList(false); - $id = $category->getId(); - /** - * new category-product relationships - */ - $products = $category->getPostedProducts(); - - /** - * Example re-save category - */ - if (is_null($products)) { - return $this; - } - - /** - * old category-product relationships - */ - $oldProducts = $category->getProductsPosition(); - - $insert = array_diff_key($products, $oldProducts); - $delete = array_diff_key($oldProducts, $products); - - /** - * Find product ids which are presented in both arrays - * and saved before (check $oldProducts array) - */ - $update = array_intersect_key($products, $oldProducts); - $update = array_diff_assoc($update, $oldProducts); - - $adapter = $this->_getWriteAdapter(); - - /** - * Delete products from category - */ - if (!empty($delete)) { - $cond = $adapter->quoteInto('product_id IN(?) AND ', array_keys($delete)) - . $adapter->quoteInto('category_id=?', $id); - $adapter->delete($this->_categoryProductTable, $cond); - } - - /** - * Add products to category - */ - if (!empty($insert)) { - $data = array(); - foreach ($insert as $productId => $position) { - $data[] = array( - 'category_id' => $id, - 'product_id' => (int)$productId, - 'position' => (int)$position - ); - } - $adapter->insertMultiple($this->_categoryProductTable, $data); - } - - /** - * Update product positions in category - */ - if (!empty($update)) { - foreach ($update as $productId => $position) { - $where = $adapter->quoteInto('category_id=? AND ', (int)$id) - . $adapter->quoteInto('product_id=?', (int)$productId); - $bind = array('position' => (int)$position); - $adapter->update($this->_categoryProductTable, $bind, $where); - } - } - - if (!empty($insert) || !empty($delete)) { - $productIds = array_unique(array_merge(array_keys($insert), array_keys($delete))); - Mage::dispatchEvent('catalog_category_change_products', array( - 'category' => $category, - 'product_ids' => $productIds - )); - } - - if (!empty($insert) || !empty($update) || !empty($delete)) { - $category->setIsChangedProductList(true); - /** - * Moved to index - */ - //$categoryIds = explode('/', $category->getPath()); - //$this->refreshProductIndex($categoryIds); - - /** - * Setting affected products to category for third party engine index refresh - */ - $productIds = array_keys($insert + $delete + $update); - $category->setAffectedProductIds($productIds); - } - - return $this; - } - - /** - * Get positions of associated to category products - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getProductsPosition($category) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->_categoryProductTable, array('product_id', 'position')) - ->where('category_id=?', $category->getId()); - $positions = $this->_getWriteAdapter()->fetchPairs($select); - return $positions; - } - - /** - * Get chlden categories count - * - * @param int $categoryId - * @return int - */ - public function getChildrenCount($categoryId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getEntityTable(), 'children_count') - ->where('entity_id=?', $categoryId); - - $child = $this->_getReadAdapter()->fetchOne($select); - - return $child; - } - - /** - * Check if category id exist - * - * @param int $id - * @return bool - */ - public function checkId($id) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getEntityTable(), 'entity_id') - ->where('entity_id=?', $id); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Check array of category identifiers - * - * @param array $ids - * @return array - */ - public function verifyIds(array $ids) - { - $validIds = array(); - $select = $this->_getWriteAdapter()->select() - ->from($this->getEntityTable(), 'entity_id') - ->where('entity_id IN(?)', $ids); - $query = $this->_getWriteAdapter()->query($select); - while ($row = $query->fetch()) { - $validIds[] = $row['entity_id']; - } - return $validIds; - } - - /** - * Get count of active/not active children categories - * - * @param Mage_Catalog_Model_Category $category - * @param bool $isActiveFlag - * @return int - */ - public function getChildrenAmount($category, $isActiveFlag = true) - { - $storeId = Mage::app()->getStore()->getId(); - $attributeId = $this->_getIsActiveAttributeId(); - $table = Mage::getSingleton('core/resource')->getTableName('catalog/category') . '_int'; - - $select = $this->_getReadAdapter()->select() - ->from(array('m'=>$this->getEntityTable()), array('COUNT(m.entity_id)')) - ->joinLeft( - array('d'=>$table), - "d.attribute_id = '{$attributeId}' AND d.store_id = 0 AND d.entity_id = m.entity_id", - array() - ) - ->joinLeft( - array('c'=>$table), - "c.attribute_id = '{$attributeId}' AND c.store_id = '{$storeId}' AND c.entity_id = m.entity_id", - array() - ) - ->where('m.path like ?', $category->getPath() . '/%') - ->where('(IF(c.value_id>0, c.value, d.value) = ?)', $isActiveFlag); - - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Get "is_active" attribute identifier - * - * @return int - */ - protected function _getIsActiveAttributeId() - { - if (is_null($this->_isActiveAttributeId)) { - $select = $this->_getReadAdapter()->select() - ->from(array('a'=>$this->getTable('eav/attribute')), array('attribute_id')) - ->join(array('t'=>$this->getTable('eav/entity_type')), 'a.entity_type_id = t.entity_type_id') - ->where('entity_type_code = ?', 'catalog_category') - ->where('attribute_code = ?', 'is_active'); - - $this->_isActiveAttributeId = $this->_getReadAdapter()->fetchOne($select); - } - return $this->_isActiveAttributeId; - } - - public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue) - { - $select = $this->_getReadAdapter()->select() - ->from($attribute->getBackend()->getTable(), array('entity_id')) - ->where('attribute_id = ?', $attribute->getId()) - ->where('value = ?', $expectedValue) - ->where('entity_id in (?)', $entityIdsFilter); - - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Get products count in category - * - * @param unknown_type $category - * @return unknown - */ - public function getProductCount($category) - { - $productTable =Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); - - $select = $this->getReadConnection()->select(); - $select->from( - array('main_table'=>$productTable), - array(new Zend_Db_Expr('COUNT(main_table.product_id)')) - ) - ->where('main_table.category_id = ?', $category->getId()) - ->group('main_table.category_id'); - - $counts =$this->getReadConnection()->fetchOne($select); - - return intval($counts); - } - - /** - * Retrieve categories - * - * @param integer $parent - * @param integer $recursionLevel - * @param boolean|string $sorted - * @param boolean $asCollection - * @param boolean $toLoad - * @return Varien_Data_Tree_Node_Collection|Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function getCategories($parent, $recursionLevel = 0, $sorted=false, $asCollection=false, $toLoad=true) - { - $tree = Mage::getResourceModel('catalog/category_tree'); - /** @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */ - $nodes = $tree->loadNode($parent) - ->loadChildren($recursionLevel) - ->getChildren(); - - $tree->addCollectionData(null, $sorted, $parent, $toLoad, true); - - if ($asCollection) { - return $tree->getCollection(); - } - return $nodes; - } - - /** - * Return parent categories of category - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getParentCategories($category) - { - $pathIds = array_reverse(explode(',', $category->getPathInStore())); - $categories = Mage::getResourceModel('catalog/category_collection') - ->setStore(Mage::app()->getStore()) - ->addAttributeToSelect('name') - ->addAttributeToSelect('url_key') - ->addFieldToFilter('entity_id', array('in'=>$pathIds)) - ->addFieldToFilter('is_active', 1) - ->load() - ->getItems(); - return $categories; - } - - /** - * Return parent category of current category with own custom design settings - * - * @param Mage_Catalog_Model_Category $category - * @return Mage_Catalog_Model_Category - */ - public function getParentDesignCategory($category) - { - $pathIds = array_reverse($category->getPathIds()); - $collection = $category->getCollection() - ->setStore(Mage::app()->getStore()) - ->addAttributeToSelect('custom_design') - ->addAttributeToSelect('custom_design_from') - ->addAttributeToSelect('custom_design_to') - ->addAttributeToSelect('page_layout') - ->addAttributeToSelect('custom_layout_update') - ->addAttributeToSelect('custom_apply_to_products') - ->addFieldToFilter('entity_id', array('in' => $pathIds)) - ->addFieldToFilter('custom_use_parent_settings', 0) - ->addFieldToFilter('level', array('neq' => 0)) - ->setOrder('level', 'DESC') - ->load(); - return $collection->getFirstItem(); - } - - /** - * Return child categories - * - * @param Mage_Catalog_Model_Category $category - * @return unknown - */ - public function getChildrenCategories($category) - { - $collection = $category->getCollection(); - /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */ - $collection->addAttributeToSelect('url_key') - ->addAttributeToSelect('name') - ->addAttributeToSelect('all_children') - ->addAttributeToSelect('is_anchor') - ->addAttributeToFilter('is_active', 1) - ->addIdFilter($category->getChildren()) - ->setOrder('position', 'ASC') - ->joinUrlRewrite() - ->load(); - return $collection; - } - - /** - * Return children ids of category - * - * @param Mage_Catalog_Model_Category $category - * @param boolean $recursive - * @return array - */ - public function getChildren($category, $recursive = true) - { - $attributeId = $this->_getIsActiveAttributeId(); - $select = $this->_getReadAdapter()->select() - ->from(array('m' => $this->getEntityTable()), 'entity_id') - ->joinLeft( - array('d' => $this->getEntityTable() . '_int'), - "d.attribute_id = '{$attributeId}' AND d.store_id = 0 AND d.entity_id = m.entity_id", - array() - ) - ->joinLeft( - array('c' => $this->getEntityTable() . '_int'), - "c.attribute_id = '{$attributeId}' AND c.store_id = '{$category->getStoreId()}' AND c.entity_id = m.entity_id", - array() - ) - ->where('(IF(c.value_id>0, c.value, d.value) = ?)', '1') - ->where('path LIKE ?', "{$category->getPath()}/%"); - if (!$recursive) { - $select->where('level <= ?', $category->getLevel() + 1); - } - $_categories = $this->_getReadAdapter()->fetchAll($select); - $categoriesIds = array(); - foreach ($_categories as $_category) { - $categoriesIds[] = $_category['entity_id']; - } - - return $categoriesIds; - } - - /** - * Return all children ids of category (with category id) - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getAllChildren($category) - { - $children = $this->getChildren($category); - $myId = array($category->getId()); - $children = array_merge($myId, $children); - - return $children; - } - - /** - * Check is category in list of store categories - * - * @param Mage_Catalog_Model_Category $category - * @return boolean - */ - public function isInRootCategoryList($category) - { - $innerSelect = $this->_getReadAdapter()->select() - ->from($this->getEntityTable(), new Zend_Db_Expr("CONCAT(path, '/%')")) - ->where('entity_id = ?', Mage::app()->getStore()->getRootCategoryId()); - $select = $this->_getReadAdapter()->select() - ->from($this->getEntityTable(), 'entity_id') - ->where('entity_id = ?', $category->getId()) - ->where(new Zend_Db_Expr("path LIKE ({$innerSelect->__toString()})")); - return (bool) $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Check category is forbidden to delete. - * - * If category is root and assigned to store group return false - * - * @param integer $categoryId - * @return boolean - */ - public function isForbiddenToDelete($categoryId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('core/store_group'), array('group_id')) - ->where('root_category_id = ?', $categoryId); - if ($this->_getReadAdapter()->fetchOne($select)) { - return true; - } - return false; - } - - /** - * Get category path value by its id - * - * @param int $categoryId - * @return string - */ - public function getCategoryPathById($categoryId) - { - $select = $this->getReadConnection()->select(); - $select->from($this->getEntityTable(), array('path')) - ->where('entity_id = ?', $categoryId); - return $this->getReadConnection()->fetchOne($select); - } - - /** - * Move category to another parent node - * - * @param Mage_Catalog_Model_Category $category - * @param Mage_Catalog_Model_Category $newParent - * @param null|int $afterCategoryId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - public function changeParent(Mage_Catalog_Model_Category $category, Mage_Catalog_Model_Category $newParent, $afterCategoryId=null) - { - $childrenCount = $this->getChildrenCount($category->getId()) + 1; - $table = $this->getEntityTable(); - $adapter = $this->_getWriteAdapter(); - $categoryId = $category->getId(); - /** - * Decrease children count for all old category parent categories - */ - $sql = "UPDATE {$table} SET children_count=children_count-{$childrenCount} WHERE entity_id IN(?)"; - $adapter->query($adapter->quoteInto($sql, $category->getParentIds())); - /** - * Increase children count for new category parents - */ - $sql = "UPDATE {$table} SET children_count=children_count+{$childrenCount} WHERE entity_id IN(?)"; - $adapter->query($adapter->quoteInto($sql, $newParent->getPathIds())); - - $position = $this->_processPositions($category, $newParent, $afterCategoryId); - - $newPath = $newParent->getPath().'/'.$category->getId(); - $newLevel= $newParent->getLevel()+1; - $levelDisposition = $newLevel - $category->getLevel(); - - /** - * Update children nodes path - */ - $sql = "UPDATE {$table} SET - `path` = REPLACE(`path`, '{$category->getPath()}/', '{$newPath}/'), - `level` = `level` + {$levelDisposition} - WHERE ". $adapter->quoteInto('path LIKE ?', $category->getPath().'/%'); - $adapter->query($sql); - /** - * Update moved category data - */ - $data = array('path' => $newPath, 'level' => $newLevel, - 'position'=>$position, 'parent_id'=>$newParent->getId()); - $adapter->update($table, $data, $adapter->quoteInto('entity_id=?', $category->getId())); - - // Update category object to new data - $category->addData($data); - - return $this; - } - - /** - * Process positions of old parent category children and new parent category children. - * Get position for moved category - * - * @param Mage_Catalog_Model_Category $category - * @param Mage_Catalog_Model_Category $newParent - * @param null|int $afterCategoryId - * @return int - */ - protected function _processPositions($category, $newParent, $afterCategoryId) - { - $table = $this->getEntityTable(); - $adapter = $this->_getWriteAdapter(); - - $sql = "UPDATE {$table} SET `position`=`position`-1 WHERE " - . $adapter->quoteInto('parent_id=? AND ', $category->getParentId()) - . $adapter->quoteInto('position>?', $category->getPosition()); - $adapter->query($sql); - - /** - * Prepare position value - */ - if ($afterCategoryId) { - $sql = "SELECT `position` FROM {$table} WHERE entity_id=?"; - $position = $adapter->fetchOne($adapter->quoteInto($sql, $afterCategoryId)); - - $sql = "UPDATE {$table} SET `position`=`position`+1 WHERE " - . $adapter->quoteInto('parent_id=? AND ', $newParent->getId()) - . $adapter->quoteInto('position>?', $position); - $adapter->query($sql); - } elseif ($afterCategoryId !== null) { - $position = 0; - $sql = "UPDATE {$table} SET `position`=`position`+1 WHERE " - . $adapter->quoteInto('parent_id=? AND ', $newParent->getId()) - . $adapter->quoteInto('position>?', $position); - $adapter->query($sql); - } else { - $sql = "SELECT MIN(`position`) FROM {$table} WHERE parent_id=?"; - $position = $adapter->fetchOne($adapter->quoteInto($sql, $newParent->getId())); - } - $position+=1; - - return $position; - } - - - - - - - - - - - - - - - - - /** - * @deprecated - * @param Varien_Object $object - * @return unknown - */ - protected function _saveInStores(Varien_Object $object) - { - if (!$object->getMultistoreSaveFlag()) { - $stores = $object->getStoreIds(); - foreach ($stores as $storeId) { - if ($object->getStoreId() != $storeId) { - $newObject = clone $object; - $newObject->setStoreId($storeId) - ->setMultistoreSaveFlag(true) - ->save(); - } - } - } - return $this; - } - - /** - * @deprecated - */ - protected function _updateCategoryPath($category, $path) - { - return $this; - if ($category->getNotUpdateDepends()) { - return $this; - } - foreach ($path as $pathItem) { - if ($pathItem->getId()>1 && $category->getId() != $pathItem->getId()) { - $category = Mage::getModel('catalog/category') - ->load($pathItem->getId()) - ->save(); - } - } - return $this; - } - - - /** - * @deprecated since 1.1.7 - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _saveCountChidren($object) - { - $chidren = $object->getChildren(); - if (strlen($chidren)>0) { - $chidrenCount = count(explode(',', $chidren)); - } else { - $chidrenCount = 0; - } - $this->_getWriteAdapter()->update($this->getEntityTable(), - array('children_count'=>$chidrenCount), - $this->_getWriteAdapter()->quoteInto('entity_id=?', $object->getId()) - ); - - return $this; - } - - /** - * Get store identifiers where category is presented - * - * @deprecated after 1.3.2.2 moved to model - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getStoreIds($category) - { - if (!$category->getId()) { - return array(); - } - - $nodes = array(); - foreach ($category->getPathIds() as $id) { - $nodes[] = $id; - } - - $stores = array(); - $storeCollection = Mage::getModel('core/store')->getCollection()->loadByCategoryIds($nodes); - foreach ($storeCollection as $store) { - $stores[$store->getId()] = $store->getId(); - } - - $entityStoreId = $category->getStoreId(); - if (!in_array($entityStoreId, $stores)) { - array_unshift($stores, $entityStoreId); - } - if (!in_array(0, $stores)) { - array_unshift($stores, 0); - } - return $stores; - } - - /** - * Move category to another parent - * @deprecated after 1.4.0.0-Alpha we are using changeParent method - * @param int $categoryId - * @param int $newParentId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - public function move($categoryId, $newParentId) - { - $category = Mage::getModel('catalog/category')->load($categoryId); - $oldParent = $category->getParentCategory(); - $newParent = Mage::getModel('catalog/category')->load($newParentId); - - $childrenCount = $this->getChildrenCount($category->getId()) + 1; - - // update children count of new parents - $parentIds = explode('/', $newParent->getPath()); - $this->_getWriteAdapter()->update( - $this->getEntityTable(), - array('children_count' => new Zend_Db_Expr("`children_count` + {$childrenCount}")), - $this->_getWriteAdapter()->quoteInto('entity_id IN (?)', $parentIds) - ); - - // update children count of old parents - $parentIds = explode('/', $oldParent->getPath()); - $this->_getWriteAdapter()->update( - $this->getEntityTable(), - array('children_count' => new Zend_Db_Expr("`children_count` - {$childrenCount}")), - $this->_getWriteAdapter()->quoteInto('entity_id IN (?)', $parentIds) - ); - - // update parent id - $this->_getWriteAdapter()->query("UPDATE - {$this->getEntityTable()} SET parent_id = {$newParent->getId()} - WHERE entity_id = {$categoryId}"); - - return $this; - } - - /** - * Rebuild associated products index - * - * @deprecated after 1.4.0.0-Alpha, functionality moved to Mage_Catalog_Model_Category_Indexer_Produxt - * @param array $categoryIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - public function refreshProductIndex($categoryIds = array(), $productIds = array(), $storeIds = array()) - { - /** - * Prepare visibility and status attributes information - */ - $statusAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'status'); - $visibilityAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'visibility'); - $statusAttributeId = $statusAttribute->getId(); - $visibilityAttributeId = $visibilityAttribute->getId(); - $statusTable = $statusAttribute->getBackend()->getTable(); - $visibilityTable = $visibilityAttribute->getBackend()->getTable(); - - /** - * Select categories data - */ - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/category')) - ->order('level') - ->order('path'); - - if (is_array($categoryIds) && !empty($categoryIds)) { - $select->where('entity_id IN (?)', $categoryIds); - } elseif (is_numeric($categoryIds)) { - $select->where('entity_id=?', $categoryIds); - } - - $categories = $this->_getWriteAdapter()->fetchAll($select); - - $storesCondition = ''; - if (!empty($storeIds)) { - $storesCondition = $this->_getWriteAdapter()->quoteInto( - ' AND s.store_id IN (?)', $storeIds - ); - } - - /** - * Get information about stores root categories - */ - $stores = $this->_getWriteAdapter()->fetchAll(" - SELECT - s.store_id, s.website_id, c.path AS root_path - FROM - {$this->getTable('core/store')} AS s, - {$this->getTable('core/store_group')} AS sg, - {$this->getTable('catalog/category')} AS c - WHERE - sg.group_id=s.group_id - AND c.entity_id=sg.root_category_id - {$storesCondition} - "); - - $indexTable = $this->getTable('catalog/category_product_index'); - - foreach ($stores as $storeData) { - $storeId = $storeData['store_id']; - $websiteId = $storeData['website_id']; - $rootPath = $storeData['root_path']; - - $productCondition = ''; - if (!empty($productIds)) { - $productCondition = $this->_getWriteAdapter()->quoteInto( - ' AND product_id IN (?)', $productIds - ); - } - $insProductCondition = str_replace('product_id', 'cp.product_id', $productCondition); - - foreach ($categories as $category) { - $categoryId = $category['entity_id']; - $path = $category['path']; - - $this->_getWriteAdapter()->delete( - $indexTable, - 'category_id='.$categoryId. ' AND store_id='.$storeId.$productCondition - ); - - if (strpos($path.'/', $rootPath.'/') === false) { - continue; - } - - $query = "INSERT INTO {$indexTable} - (`category_id`, `product_id`, `position`, `is_parent`, `store_id`, `visibility`) - SELECT - {$categoryId}, - cp.product_id, - cp.position, - MAX({$categoryId}=cp.category_id) as is_parent, - {$storeId}, - IF(t_v.value_id>0, t_v.value, t_v_default.value) - FROM - {$this->getTable('catalog/category_product')} AS cp - INNER JOIN {$this->getTable('catalog/product_website')} AS pw - ON pw.product_id=cp.product_id AND pw.website_id={$websiteId} - INNER JOIN {$visibilityTable} AS `t_v_default` - ON (t_v_default.entity_id = cp.product_id) - AND (t_v_default.attribute_id='{$visibilityAttributeId}') - AND t_v_default.store_id=0 - LEFT JOIN {$visibilityTable} AS `t_v` - ON (t_v.entity_id = cp.product_id) - AND (t_v.attribute_id='{$visibilityAttributeId}') - AND (t_v.store_id='{$storeId}') - INNER JOIN {$statusTable} AS `t_s_default` - ON (t_s_default.entity_id = cp.product_id) - AND (t_s_default.attribute_id='{$statusAttributeId}') - AND t_s_default.store_id=0 - LEFT JOIN {$statusTable} AS `t_s` - ON (t_s.entity_id = cp.product_id) - AND (t_s.attribute_id='{$statusAttributeId}') - AND (t_s.store_id='{$storeId}') - WHERE category_id IN( - SELECT entity_id FROM {$this->getTable('catalog/category')} - WHERE entity_id = {$category['entity_id']} OR path LIKE '{$path}/%') - AND (IF(t_s.value_id>0, t_s.value, t_s_default.value)=".Mage_Catalog_Model_Product_Status::STATUS_ENABLED.") - {$insProductCondition} - GROUP BY product_id - ORDER BY is_parent desc"; - - $this->_getWriteAdapter()->query($query); - } - - $this->_refreshRootCategoryProductIndex($productIds, array($storeId)); - } - return $this; - } - - /** - * Refresh Category Product Index for Store Root Catgory - * - * @deprecated after 1.4.0.0-Alpha, functionality moved to Mage_Catalog_Model_Category_Indexer_Produxt - * @param array|int $productIds - * @param array|int $storeIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category - */ - protected function _refreshRootCategoryProductIndex($productIds = array(), $storeIds = array()) - { - if (is_numeric($storeIds)) { - $storeIds = array($storeIds); - } - elseif (!is_array($storeIds) || empty($storeIds)) { - $storeIds = array(); - foreach (Mage::app()->getStores() as $store) { - $storeIds[] = $store->getId(); - } - } - - /** - * Prepare visibility and status attributes information - */ - $status = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'status'); - $visibility = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'visibility'); - $statusTable = $status->getBackend()->getTable(); - $visibilityTable = $visibility->getBackend()->getTable(); - - $indexTable = $this->getTable('catalog/category_product_index'); - - foreach ($storeIds as $storeId) { - $store = Mage::app()->getStore($storeId); - $categoryId = $store->getRootCategoryId(); - - $select = $this->_getWriteAdapter()->select() - ->from(array('e' => $this->getTable('catalog/product')), null) - ->joinLeft( - array('i' => $indexTable), - 'e.entity_id=i.product_id AND i.category_id=' . (int)$categoryId - . ' AND i.store_id=' . (int) $storeId, - array()) - ->joinInner( - array('pw' => $this->getTable('catalog/product_website')), - 'e.entity_id=pw.product_id AND pw.website_id=' . (int)$store->getWebsiteId(), - array()) - ->join( - array('t_v_default' => $visibilityTable), - 't_v_default.entity_id=e.entity_id' - . ' AND t_v_default.attribute_id=' . (int)$visibility->getAttributeId() - . ' AND t_v_default.store_id=0', - array()) - ->joinLeft( - array('t_v' => $visibilityTable), - 't_v.entity_id=e.entity_id' - . ' AND t_v.attribute_id=' . (int)$visibility->getAttributeId() - . ' AND t_v.store_id='. (int)$storeId, - array()) - ->join( - array('t_s_default' => $statusTable), - 't_s_default.entity_id=e.entity_id' - . ' AND t_s_default.attribute_id=' . (int)$status->getAttributeId() - . ' AND t_s_default.store_id=0', - array()) - ->joinLeft( - array('t_s' => $statusTable), - 't_s.entity_id=e.entity_id' - . ' AND t_s.attribute_id=' . (int)$status->getAttributeId() - . ' AND t_s.store_id='. (int)$storeId, - array()) - ->where('i.product_id IS NULL') - ->where('IF(t_s.value_id>0, t_s.value, t_s_default.value)=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - - $select->columns(new Zend_Db_Expr($categoryId)); - $select->columns('e.entity_id'); - $select->columns(new Zend_Db_Expr(0)); - $select->columns(new Zend_Db_Expr(0)); - $select->columns(new Zend_Db_Expr($storeId)); - $select->columns(new Zend_Db_Expr('IF(t_v.value_id>0, t_v.value, t_v_default.value)')); - - if (!empty($productIds)) { - $select->where('e.entity_id IN(?)', $productIds); - } - - $this->_getWriteAdapter()->query($select->insertFromSelect($indexTable)); - } - return $this; - } - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Collection.php index e0ba638338..50c7f3b2ad 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,30 +28,11 @@ /** * Catalog category EAV additional attribute resource collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Collection extends Mage_Eav_Model_Mysql4_Entity_Attribute_Collection +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Collection + extends Mage_Catalog_Model_Resource_Category_Attribute_Collection { - protected function _initSelect() - { - $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable())) - ->where('main_table.entity_type_id=?', Mage::getModel('eav/entity')->setType('catalog_category')->getTypeId()) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'additional_table.attribute_id=main_table.attribute_id' - ); - return $this; - } - - /** - * Specify attribute entity type filter - * - * @param int $typeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Collection - */ - public function setEntityTypeFilter($typeId) - { - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Frontend/Image.php index 30e2190d3d..5b9f4f8b2c 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Frontend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Frontend/Image.php @@ -20,26 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Category image attribute frontend * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team - */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Frontend_Image extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Frontend_Image + extends Mage_Catalog_Model_Resource_Category_Attribute_Frontend_Image { - public function getUrl($object) - { - $url = false; - if ($image = $object->getData($this->getAttribute()->getAttributeCode())) { - $url = Mage::getBaseUrl('media').'catalog/category/'.$image; - } - return $url; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Layout.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Layout.php index 97523185b0..d3e2823f62 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Layout.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Layout.php @@ -20,31 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog category landing page attribute source * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Layout extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Layout + extends Mage_Catalog_Model_Resource_Category_Attribute_Source_Layout { - public function getAllOptions() - { - if (!$this->_options) { - $layouts = array(); - foreach (Mage::getConfig()->getNode('global/cms/layouts')->children() as $layoutName=>$layoutConfig) { - $this->_options[] = array( - 'value'=>$layoutName, - 'label'=>(string)$layoutConfig->label - ); - } - array_unshift($this->_options, array('value'=>'', 'label'=>Mage::helper('catalog')->__('No layout updates'))); - } - return $this->_options; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Mode.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Mode.php index 13a76b92c6..c59b93ccea 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Mode.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Mode.php @@ -20,37 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog category landing page attribute source * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Mode extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Mode + extends Mage_Catalog_Model_Resource_Category_Attribute_Source_Mode { - public function getAllOptions() - { - if (!$this->_options) { - $this->_options = array( - array( - 'value' => Mage_Catalog_Model_Category::DM_PRODUCT, - 'label' => Mage::helper('catalog')->__('Products only'), - ), - array( - 'value' => Mage_Catalog_Model_Category::DM_PAGE, - 'label' => Mage::helper('catalog')->__('Static block only'), - ), - array( - 'value' => Mage_Catalog_Model_Category::DM_MIXED, - 'label' => Mage::helper('catalog')->__('Static block and products'), - ) - ); - } - return $this->_options; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Page.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Page.php index c258e77ccb..8df7860b7a 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Page.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Attribute/Source/Page.php @@ -20,27 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog category landing page attribute source * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Page extends Mage_Eav_Model_Entity_Attribute_Source_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Attribute_Source_Page + extends Mage_Catalog_Model_Resource_Category_Attribute_Source_Page { - public function getAllOptions() - { - if (!$this->_options) { - $this->_options = Mage::getResourceModel('cms/block_collection') - ->load() - ->toOptionArray(); - array_unshift($this->_options, array('value'=>'', 'label'=>Mage::helper('catalog')->__('Please select a static block ...'))); - } - return $this->_options; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Collection.php index 681b6fae31..5932849077 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,321 +28,10 @@ /** * Category resource collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection extends Mage_Catalog_Model_Resource_Category_Collection { - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'catalog_category_collection'; - - /** - * Event object name - * - * @var string - */ - protected $_eventObject = 'category_collection'; - - protected $_productTable; - - /** - * Store id, that we should count products on - * - * @var int - */ - protected $_productStoreId; - - protected $_productWebsiteTable; - - protected $_loadWithProductCount = false; - - /** - * Init collection and determine table names - * - */ - protected function _construct() - { - $this->_init('catalog/category'); - - /** - * @todo Why 'core/resource' is used here ? What if catalog will use another resource ? - */ - $this->_productWebsiteTable = Mage::getSingleton('core/resource')->getTableName('catalog/product_website'); - $this->_productTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); - } - - /** - * Enter description here... - * - * @param array $categoryIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function addIdFilter($categoryIds) - { - if (is_array($categoryIds)) { - if (empty($categoryIds)) { - $condition = ''; - } else { - $condition = array('in' => $categoryIds); - } - } elseif (is_numeric($categoryIds)) { - $condition = $categoryIds; - } elseif (is_string($categoryIds)) { - $ids = explode(',', $categoryIds); - if (empty($ids)) { - $condition = $categoryIds; - } else { - $condition = array('in' => $ids); - } - } - $this->addFieldToFilter('entity_id', $condition); - return $this; - } - - /** - * Enter description here... - * - * @param boolean $flag - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function setLoadProductCount($flag) - { - $this->_loadWithProductCount = $flag; - return $this; - } - - - /** - * Before collection load - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - protected function _beforeLoad() - { - Mage::dispatchEvent($this->_eventPrefix . '_load_before', - array($this->_eventObject => $this)); - return parent::_beforeLoad(); - } - - /** - * After collection load - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - protected function _afterLoad() - { - Mage::dispatchEvent($this->_eventPrefix . '_load_after', - array($this->_eventObject => $this)); - - return parent::_afterLoad(); - } - - /** - * Set id of the store that we should count products on - * - * @param int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function setProductStoreId($storeId) - { - $this->_productStoreId = $storeId; - return $this; - } - - /** - * Get id of the store that we should count products on - * - * @return int - */ - public function getProductStoreId() - { - if (is_null($this->_productStoreId)) { - $this->_productStoreId = 0; - } - return $this->_productStoreId; - } - - /** - * Load collection - * - * @param bool $printQuery - * @param bool $logQuery - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - - if ($this->_loadWithProductCount) { - $this->addAttributeToSelect('all_children'); - $this->addAttributeToSelect('is_anchor'); - } - - parent::load($printQuery, $logQuery); - - if ($this->_loadWithProductCount) { - $this->_loadProductCount(); - } - - return $this; - } - - /** - * Load categories product count - */ - protected function _loadProductCount() - { - $this->loadProductCount($this->_items, true, true); - } - - /** - * Load product count for specified items - * - * @param array $items - * @param boolean $countRegular get product count for regular (non-anchor) categories - * @param boolean $countAnchor get product count for anchor categories - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function loadProductCount($items, $countRegular = true, $countAnchor = true) - { - $anchor = array(); - $regular = array(); - - foreach ($items as $item) { - if ($item->getIsAnchor()) { - $anchor[$item->getId()] = $item; - } else { - $regular[$item->getId()] = $item; - } - } - - if ($countRegular) { - // Retrieve regular categories product counts - $regularIds = array_keys($regular); - if (!empty($regularIds)) { - $select = $this->_conn->select(); - $select->from( - array('main_table'=>$this->_productTable), - array('category_id', new Zend_Db_Expr('COUNT(main_table.product_id)')) - ) - ->where($this->_conn->quoteInto('main_table.category_id IN(?)', $regularIds)) - ->group('main_table.category_id'); - $counts = $this->_conn->fetchPairs($select); - foreach ($regular as $item) { - if (isset($counts[$item->getId()])) { - $item->setProductCount($counts[$item->getId()]); - } else { - $item->setProductCount(0); - } - } - } - } - - if ($countAnchor) { - // Retrieve Anchor categories product counts - foreach ($anchor as $item) { - if ($allChildren = $item->getAllChildren()) { - $select = $this->_conn->select(); - $select->from( - array('main_table' => $this->_productTable), - new Zend_Db_Expr('COUNT( DISTINCT main_table.product_id)') - ) - ->joinInner(array('e' => $this->getTable('catalog/category')), 'main_table.category_id=e.entity_id', array()) - ->where('e.entity_id=? OR ' . $this->_conn->quoteInto('e.path LIKE CONCAT(?)', array($item->getPath(), '/%')), $item->getId()); - $item->setProductCount((int) $this->_conn->fetchOne($select)); - } else { - $item->setProductCount(0); - } - } - } - return $this; - } - - /** - * Enter description here... - * - * @param string $regexp - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function addPathFilter($regexp) - { - $this->getSelect()->where(new Zend_Db_Expr("path regexp '{$regexp}'")); - return $this; - } - - /** - * Joins url rewrite rules to collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function joinUrlRewrite() - { - $storeId = Mage::app()->getStore()->getId(); - $this->joinTable( - 'core/url_rewrite', - 'category_id=entity_id', - array('request_path'), - '{{table}}.is_system=1 AND {{table}}.product_id IS NULL AND {{table}}.store_id="'.$storeId.'" AND id_path LIKE "category/%"', - 'left' - ); - return $this; - } - - public function addIsActiveFilter() - { - $this->addAttributeToFilter('is_active', 1); - Mage::dispatchEvent($this->_eventPrefix . '_add_is_active_filter', - array($this->_eventObject => $this)); - return $this; - } - - public function addNameToResult() - { - $this->addAttributeToSelect('name'); - return $this; - } - - public function addUrlRewriteToResult() - { - $this->joinUrlRewrite(); - return $this; - } - - public function addPathsFilter($paths) - { - if (!is_array($paths)) { - $paths = array($paths); - } - $select = $this->getSelect(); - $orWhere = false; - foreach ($paths as $path) { - if ($orWhere) { - $select->orWhere('e.path LIKE ?', "$path%"); - } else { - $select->where('e.path LIKE ?', "$path%"); - $orWhere = true; - } - } - return $this; - } - - public function addLevelFilter($level) - { - $this->getSelect()->where('e.level <= ?', $level); - return $this; - } - - public function addOrderField($field) - { - $this->setOrder($field, 'ASC'); - return $this; - } - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat.php index 4db1645d88..77c894e85f 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,1264 +28,10 @@ /** * Category flat model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat extends Mage_Catalog_Model_Resource_Category_Flat { - protected $_storeId = null; - - protected $_loaded = false; - - protected $_nodes = array(); - - protected $_columns = null; - - protected $_columnsSql = null; - - protected $_attributeCodes = null; - - /** - * Inactive categories ids - * - * @var array - */ - protected $_inactiveCategoryIds = null; - - protected $_isRebuilt = null; - - /** - * array with root category id per store - * - * @var array - */ - protected $_storesRootCategories; - - protected function _construct() - { - $this->_init('catalog/category_flat', 'entity_id'); - } - - /** - * Set store id - * - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Return store id - * - * @return integer - */ - public function getStoreId() - { - if (is_null($this->_storeId)) { - return Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Get main table name - * - * @return string - */ - public function getMainTable() - { - return $this->getMainStoreTable($this->getStoreId()); - } - - /** - * Return name of table for given $storeId. - * - * @param integer $storeId - * @return string - */ - public function getMainStoreTable($storeId = 0) - { - $table = parent::getMainTable(); - if (is_string($storeId)) { - $storeId = intval($storeId); - } - if ($this->getUseStoreTables() && $storeId) { - $table .= '_store_'.$storeId; - } - return $table; - } - - /** - * Return true if need use for each store different table of flat categoris data. - * - * @return boolean - */ - public function getUseStoreTables() - { - return true; - } - - /** - * Add inactive categories ids - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function addInactiveCategoryIds($ids) - { - if (!is_array($this->_inactiveCategoryIds)) { - $this->_initInactiveCategoryIds(); - } - $this->_inactiveCategoryIds = array_merge($ids, $this->_inactiveCategoryIds); - return $this; - } - - /** - * Retreive inactive categories ids - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _initInactiveCategoryIds() - { - $this->_inactiveCategoryIds = array(); - Mage::dispatchEvent('catalog_category_tree_init_inactive_category_ids', array('tree'=>$this)); - return $this; - } - - /** - * Retreive inactive categories ids - * - * @return array - */ - public function getInactiveCategoryIds() - { - if (!is_array($this->_inactiveCategoryIds)) { - $this->_initInactiveCategoryIds(); - } - - return $this->_inactiveCategoryIds; - } - - /** - * Load nodes by parent id - * - * @param integer $parentId - * @param integer $recursionLevel - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _loadNodes($parentNode = null, $recursionLevel = 0, $storeId = 0) - { - $_conn = $this->_getReadAdapter(); - $startLevel = 1; - $parentPath = ''; - if ($parentNode instanceof Mage_Catalog_Model_Category) { - $parentPath = $parentNode->getPath(); - $startLevel = $parentNode->getLevel(); - } elseif (is_numeric($parentNode)) { - $selectParent = $_conn->select() - ->from($this->getMainStoreTable($storeId)) - ->where('entity_id = ?', $parentNode) - ->where('store_id = ?', $storeId); - if ($parentNode = $_conn->fetchRow($selectParent)) { - $parentPath = $parentNode['path']; - $startLevel = $parentNode['level']; - } - } - $select = $_conn->select() - ->from(array('main_table'=>$this->getMainStoreTable($storeId)), array('main_table.entity_id', 'main_table.name', 'main_table.path', 'main_table.is_active', 'main_table.is_anchor')) - ->joinLeft( - array('url_rewrite'=>$this->getTable('core/url_rewrite')), - 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND url_rewrite.product_id IS NULL AND url_rewrite.store_id="'.$storeId.'" AND url_rewrite.id_path LIKE "category/%"', - array('request_path' => 'url_rewrite.request_path')) - ->where('main_table.is_active = ?', '1') - ->where('main_table.include_in_menu', '1') -// ->order('main_table.path', 'ASC') - ->order('main_table.position', 'ASC'); - - - - if ($parentPath) { - $select->where($_conn->quoteInto("main_table.path like ?", "$parentPath/%")); - } - if ($recursionLevel != 0) { - $select->where("main_table.level <= ?", $startLevel + $recursionLevel); - } - - $inactiveCategories = $this->getInactiveCategoryIds(); - - if (!empty($inactiveCategories)) { - $select->where('main_table.entity_id NOT IN (?)', $inactiveCategories); - } - - $arrNodes = $_conn->fetchAll($select); - $nodes = array(); - foreach ($arrNodes as $node) { - $node['id'] = $node['entity_id']; - $nodes[$node['id']] = Mage::getModel('catalog/category')->setData($node); - } - - return $nodes; - } - - /** - * Creating sorted array of nodes - * - * @param array $children - * @param string $path - * @param Varien_Object $parent - */ - public function addChildNodes($children, $path, $parent) - { - if (isset($children[$path])) { - foreach ($children[$path] as $child) { - $childrenNodes = $parent->getChildrenNodes(); - if ($childrenNodes && isset($childrenNodes[$child->getId()])) { - $childrenNodes[$child['entity_id']]->setChildrenNodes(array($child->getId()=>$child)); - } else { - if ($childrenNodes) { - $childrenNodes[$child->getId()] = $child; - } else { - $childrenNodes = array($child->getId()=>$child); - } - $parent->setChildrenNodes($childrenNodes); - } - - if ($path) { - $childrenPath = explode('/', $path); - } else { - $childrenPath = array(); - } - $childrenPath[] = $child->getId(); - $childrenPath = implode('/', $childrenPath); - $this->addChildNodes($children, $childrenPath, $child); - } - } - } - - /** - * Return sorted array of nodes - * - * @param integer|null $parentId - * @param integer $recursionLevel - * @param integer $storeId - * @return array - */ - public function getNodes($parentId, $recursionLevel = 0, $storeId = 0) - { - if (!$this->_loaded) { - $selectParent = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable($storeId)) - ->where('entity_id = ?', $parentId); - if ($parentNode = $this->_getReadAdapter()->fetchRow($selectParent)) { - $parentNode['id'] = $parentNode['entity_id']; - $parentNode = Mage::getModel('catalog/category')->setData($parentNode); - $this->_nodes[$parentNode->getId()] = $parentNode; - $nodes = $this->_loadNodes($parentNode, $recursionLevel, $storeId); - $childrenItems = array(); - foreach ($nodes as $node) { - $pathToParent = explode('/', $node->getPath()); - array_pop($pathToParent); - $pathToParent = implode('/', $pathToParent); - $childrenItems[$pathToParent][] = $node; - } - $this->addChildNodes($childrenItems, $parentNode->getPath(), $parentNode); - $childrenNodes = $this->_nodes[$parentNode->getId()]; - if ($childrenNodes->getChildrenNodes()) { - $this->_nodes = $childrenNodes->getChildrenNodes(); - } - else { - $this->_nodes = array(); - } - $this->_loaded = true; - } - } - return $this->_nodes; - } - - /** - * Return array or collection of categories - * - * @param integer $parent - * @param integer $recursionLevel - * @param boolean|string $sorted - * @param boolean $asCollection - * @param boolean $toLoad - * @return array|Varien_Data_Collection - */ - public function getCategories($parent, $recursionLevel = 0, $sorted=false, $asCollection=false, $toLoad=true) - { - if ($asCollection) { - $parentPath = $this->_getReadAdapter()->fetchOne(new Zend_Db_Expr(" - SELECT path FROM {$this->getMainStoreTable($this->getStoreId())} WHERE entity_id = {$parent} - ")); - $collection = Mage::getModel('catalog/category')->getCollection() - ->addNameToResult() - ->addUrlRewriteToResult() - ->addParentPathFilter($parentPath) - ->addStoreFilter() - ->addIsActiveFilter() - ->addAttributeToFilter('include_in_menu', 1) - ->addSortedField($sorted); - if ($toLoad) { - return $collection->load(); - } - return $collection; - } - return $this->getNodes($parent, $recursionLevel, Mage::app()->getStore()->getId()); - } - - /** - * Return node with id $nodeId - * - * @param integer $nodeId - * @param array $nodes - * @return Varien_Object - */ - public function getNodeById($nodeId, $nodes = null) - { - if (is_null($nodes)) { - $nodes = $this->getNodes(); - } - if (isset($nodes[$nodeId])) { - return $nodes[$nodeId]; - } - foreach ($nodes as $node) { -// if ($node->getId() == $nodeId) { -// return $node; -// } - if ($node->getChildrenNodes()) { - return $this->getNodeById($nodeId, $node->getChildrenNodes()); - } - } - return array(); - } - - /** - * Check if category flat data is rebuilt - * - * @return bool - */ - public function isRebuilt() - { - if ($this->_isRebuilt === null) { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable(Mage::app()->getDefaultStoreView()->getId()), 'entity_id') - ->limit(1); - try { - $this->_isRebuilt = (bool) $this->_getReadAdapter()->fetchOne($select); - } catch (Exception $e) { - $this->_isRebuilt = false; - } - } - return $this->_isRebuilt; - } - - protected function _getTableSqlSchema($storeId = 0) - { - $storeId = Mage::app()->getStore($storeId)->getId(); - $schema = "CREATE TABLE `{$this->getMainStoreTable($storeId)}` ( - `entity_id` int(10) unsigned not null, - `store_id` smallint(5) unsigned not null default '0', - `parent_id` int(10) unsigned not null default '0', - `path` varchar(255) not null default '', - `level` int(11) not null default '0', - `position` int(11) not null default '0', - `children_count` int(11) not null, - `created_at` datetime not null default '0000-00-00 00:00:00', - `updated_at` datetime not null default '0000-00-00 00:00:00', - KEY `CATEGORY_FLAT_CATEGORY_ID` (`entity_id`), - KEY `CATEGORY_FLAT_STORE_ID` (`store_id`), - KEY `path` (`path`), - KEY `IDX_LEVEL` (`level`), - CONSTRAINT `FK_CATEGORY_FLAT_CATEGORY_ID_STORE_{$storeId}` FOREIGN KEY (`entity_id`) - REFERENCES `{$this->getTable('catalog/category')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `FK_CATEGORY_FLAT_STORE_ID_STORE_{$storeId}` FOREIGN KEY (`store_id`) - REFERENCES `{$this->getTable('core/store')}` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8"; - return $schema; - } - - /** - * Rebuild flat data from eav - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function rebuild($stores = null) - { - if ($stores === null) { - $stores = Mage::app()->getStores(); - } - - if (!is_array($stores)) { - $stores = array($stores); - } - - $rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID; - $categories = array(); - $categoriesIds = array(); - /* @var $store Mage_Core_Model_Store */ - foreach ($stores as $store) { - $this->_createTable($store->getId()); - - if (!isset($categories[$store->getRootCategoryId()])) { - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable('catalog/category')) - ->where('path = ?', (string)$rootId) - ->orWhere('path = ?', "{$rootId}/{$store->getRootCategoryId()}") - ->orWhere('path LIKE ?', "{$rootId}/{$store->getRootCategoryId()}/%"); - $categories[$store->getRootCategoryId()] = $this->_getWriteAdapter()->fetchAll($select); - $categoriesIds[$store->getRootCategoryId()] = array(); - foreach ($categories[$store->getRootCategoryId()] as $category) { - $categoriesIds[$store->getRootCategoryId()][] = $category['entity_id']; - } - } - $categoriesIdsChunks = array_chunk($categoriesIds[$store->getRootCategoryId()], 500); - foreach ($categoriesIdsChunks as $categoriesIdsChunk) { - $attributesData = $this->_getAttributeValues($categoriesIdsChunk, $store->getId()); - $data = array(); - foreach ($categories[$store->getRootCategoryId()] as $category) { - if (!isset($attributesData[$category['entity_id']])) { - continue; - } - $category['store_id'] = $store->getId(); - $data[] = $this->_prepareValuesToInsert( - array_merge($category, $attributesData[$category['entity_id']]) - ); - } - $this->_getWriteAdapter()->insertMultiple($this->getMainStoreTable($store->getId()), $data); - } - } - return $this; - } - - /** - * Prepare array of column and columnValue pairs - * - * @param array $data - * @return array - */ - protected function _prepareValuesToInsert($data) - { - $values = array(); - foreach (array_keys($this->_columns) as $key => $column) { - if (isset($data[$column])) { - $values[$column] = $data[$column]; - } else { - $values[$column] = ''; - } - } - return $values; - } - - /** - * Create Flate Table(s) - * - * @param array|int $stores - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function createTable($stores) - { - return $this->_createTable($stores); - } - - /** - * Creating table and adding attributes as fields to table - * - * @param array|integer $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _createTable($store) - { - $this->_getWriteAdapter()->query("DROP TABLE IF EXISTS `{$this->getMainStoreTable($store)}`;"); - $_tableSql = "CREATE TABLE `{$this->getMainStoreTable($store)}` (\n"; - if ($this->_columnsSql === null || $this->_columnsSql === null) { - $this->_columns = array_merge($this->_getStaticColumns(), $this->_getEavColumns()); - foreach ($this->_columns as $columnName => $columnData) { - $this->_columnsSql .= '`' . $columnName . '` ' . $columnData['type']; - $this->_columnsSql .= $columnData['is_unsigned'] ? ' unsigned' : ''; - $this->_columnsSql .= ($columnData['is_null'] ? '' : ' not null'); - $this->_columnsSql .= ($columnData['default'] === false ? '' : ' default \'' . $columnData['default'] . '\''); - $this->_columnsSql .= ",\n"; - } - } - $_tableSql .= $this->_columnsSql; - $_tableSql .= "PRIMARY KEY (`entity_id`), - KEY `IDX_STORE` (`store_id`), - KEY `IDX_PATH` (`path`), - KEY `IDX_LEVEL` (`level`), - CONSTRAINT `FK_CATEGORY_FLAT_CATEGORY_ID_STORE_{$store}` FOREIGN KEY (`entity_id`) - REFERENCES `{$this->getTable('catalog/category')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `FK_CATEGORY_FLAT_STORE_ID_STORE_{$store}` FOREIGN KEY (`store_id`) - REFERENCES `{$this->getTable('core/store')}` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8"; - $this->_getWriteAdapter()->query($_tableSql); - return $this; - } - - /** - * Return array of static columns - * - * @return array - */ - protected function _getStaticColumns() - { - $columns = array(); - $columnsToSkip = array('entity_type_id', 'attribute_set_id'); - $describe = $this->_getWriteAdapter()->describeTable($this->getTable('catalog/category')); - foreach ($describe as $column) { - if (in_array($column['COLUMN_NAME'], $columnsToSkip)) { - continue; - } - $_type = ''; - $_is_unsigned = ''; - switch ($column['DATA_TYPE']) { - case 'smallint': - case 'int': - $_type = $column['DATA_TYPE'] . '(11)'; - $_is_unsigned = (bool)$column['UNSIGNED']; - if ($column['DEFAULT'] === '') { - $column['DEFAULT'] = null; - } - break; - case 'varchar': - $_type = $column['DATA_TYPE'] . '(' . $column['LENGTH'] . ')'; - $_is_unsigned = null; - break; - case 'datetime': - $_type = $column['DATA_TYPE']; - $_is_unsigned = null; - break; - case 'decimal': - $_type = $column['DATA_TYPE'] . '(' . $column['PRECISION'] . ',' . $column['SCALE'] . ')'; - $_is_unsigned = null; - if ($column['DEFAULT'] === '') { - $column['DEFAULT'] = null; - } - break; - } - $columns[$column['COLUMN_NAME']] = array( - 'type' => $_type, - 'is_unsigned' => $_is_unsigned, - 'is_null' => $column['NULLABLE'], - 'default' => ($column['DEFAULT'] === null ? false : $column['DEFAULT']) - ); - } - $columns['store_id'] = array( - 'type' => 'smallint(5)', - 'is_unsigned' => true, - 'is_null' => false, - 'default' => '0' - ); - return $columns; - } - - /** - * Return array of eav columns, skip attribute with static type - * - * @return array - */ - protected function _getEavColumns() - { - $columns = array(); - $attributes = $this->_getAttributes(); - foreach ($attributes as $attribute) { - if ($attribute['backend_type'] == 'static') { - continue; - } - $columns[$attribute['attribute_code']] = array(); - switch ($attribute['backend_type']) { - case 'varchar': - $columns[$attribute['attribute_code']] = array( - 'type' => 'varchar(255)', - 'is_unsigned' => null, - 'is_null' => false, - 'default' => '' - ); - break; - case 'int': - $columns[$attribute['attribute_code']] = array( - 'type' => 'int(10)', - 'is_unsigned' => null, - 'is_null' => false, - 'default' => '0' - ); - break; - case 'text': - $columns[$attribute['attribute_code']] = array( - 'type' => 'text', - 'is_unsigned' => null, - 'is_null' => true, - 'default' => null - ); - break; - case 'datetime': - $columns[$attribute['attribute_code']] = array( - 'type' => 'datetime', - 'is_unsigned' => null, - 'is_null' => false, - 'default' => '0000-00-00 00:00:00' - ); - break; - case 'decimal': - $columns[$attribute['attribute_code']] = array( - 'type' => 'decimal(12,4)', - 'is_unsigned' => null, - 'is_null' => false, - 'default' => '0.0000' - ); - break; - } - } - return $columns; - } - - /** - * Return array of attribute codes for entity type 'catalog_category' - * - * @return array - */ - protected function _getAttributes() - { - if ($this->_attributeCodes === null) { - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable('eav/entity_type'), array()) - ->join( - $this->getTable('eav/attribute'), - $this->getTable('eav/attribute').'.entity_type_id = '.$this->getTable('eav/entity_type').'.entity_type_id', - $this->getTable('eav/attribute').'.*' - ) - ->where($this->getTable('eav/entity_type').'.entity_type_code=?', 'catalog_category'); - $this->_attributeCodes = array(); - foreach ($this->_getWriteAdapter()->fetchAll($select) as $attribute) { - $this->_attributeCodes[$attribute['attribute_id']] = $attribute; - } - } - return $this->_attributeCodes; - } - - /** - * Return attribute values for given entities and store - * - * @param array $entityIds - * @param integer $store_id - * @return array - */ - protected function _getAttributeValues($entityIds, $store_id) - { - if (!is_array($entityIds)) { - $entityIds = array($entityIds); - } - $values = array(); - - foreach ($entityIds as $entityId) { - $values[$entityId] = array(); - } - $attributes = $this->_getAttributes(); - $attributesType = array( - 'varchar', - 'int', - 'decimal', - 'text', - 'datetime' - ); - foreach ($attributesType as $type) { - foreach ($this->_getAttributeTypeValues($type, $entityIds, $store_id) as $row) { - $values[$row['entity_id']][$attributes[$row['attribute_id']]['attribute_code']] = $row['value']; - } - } - return $values; - } - - /** - * Return attribute values for given entities and store of specific attribute type - * - * @param string $type - * @param array $entityIds - * @param integer $store_id - * @return array - */ - protected function _getAttributeTypeValues($type, $entityIds, $store_id) - { - $select = $this->_getWriteAdapter()->select() - ->from(array('default' => $this->getTable('catalog/category') . '_' . $type), array('entity_id', 'attribute_id')) - ->joinLeft( - array('store' => $this->getTable('catalog/category') . '_' . $type), - '`store`.entity_id = `default`.entity_id AND `store`.attribute_id = `default`.attribute_id AND `store`.store_id = ' . $store_id, - array('value' => new Zend_Db_Expr('IF(`store`.`value_id`>0, `store`.`value`, `default`.`value`)')) - ) - ->where('`default`.entity_id IN (?)', $entityIds) - ->where('`default`.store_id = ?', 0); - return $this->_getWriteAdapter()->fetchAll($select); - } - - /** - * Delete store table(s) of given stores; - * - * @param array|integer $stores - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function deleteStores($stores) - { - $this->_deleteTable($stores); - return $this; - } - - /** - * Delete table(s) of given stores. - * - * @param array|integer $stores - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _deleteTable($stores) - { - if (!is_array($stores)) { - $stores = array($stores); - } - foreach ($stores as $store) { - $_tableExist = $this->_getWriteAdapter()->query( - "DROP TABLE IF EXISTS `{$this->getMainStoreTable($store)}`" - ); - } - return $this; - } - - /** - * Synchronize flat data with eav model for category - * - * @param Varien_Object $category - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _synchronize($category) - { - $table = $this->getMainStoreTable($category->getStoreId()); - $data = $this->_prepareDataForAllFields($category); - $this->_getWriteAdapter()->insertOnDuplicate($table, $data); - return $this; - } - - /** - * Synchronize flat data with eav model. - * - * @param Mage_Catalog_Model_Category|int $category - * @param array $storeIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function synchronize($category = null, $storeIds = array()) - { - if (is_null($category)) { - if (empty($storeIds)) { - $storeIds = null; - } - $stores = $this->getStoresRootCategories($storeIds); - - $storesObjects = array(); - foreach ($stores as $storeId => $rootCategoryId) { - $_store = new Varien_Object(array( - 'store_id' => $storeId, - 'root_category_id' => $rootCategoryId - )); - $_store->setIdFieldName('store_id'); - $storesObjects[] = $_store; - } - - $this->rebuild($storesObjects); - } else if ($category instanceof Mage_Catalog_Model_Category) { - $categoryId = $category->getId(); - foreach ($category->getStoreIds() as $storeId) { - if ($storeId == 0) { - continue; - } - - $attributeValues = $this->_getAttributeValues($categoryId, $storeId); - $data = new Varien_Object($category->getData()); - $data->addData($attributeValues[$categoryId]) - ->setStoreId($storeId); - $this->_synchronize($data); - } - } else if (is_numeric($category)) { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/category')) - ->where('entity_id=?', $category); - $row = $write->fetchRow($select); - if (!$row) { - return $this; - } - - $stores = $this->getStoresRootCategories(); - $path = explode('/', $row['path']); - foreach ($stores as $storeId => $rootCategoryId) { - if (in_array($rootCategoryId, $path)) { - $attributeValues = $this->_getAttributeValues($category, $storeId); - $data = new Varien_Object($row); - $data->addData($attributeValues[$category]) - ->setStoreId($storeId); - $this->_synchronize($data); - } else { - $where = $write->quoteInto('entity_id=?', $category); - $write->delete($this->getMainStoreTable($storeId), $where); - } - } - } - - return $this; - } - - public function removeStores($stores) - { - $this->_deleteTable($stores); - return $this; - } - - /** - * Synchronize flat category data after move by affected category ids - * - * @param array $affectedCategoryIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function move(array $affectedCategoryIds) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/category'), array('entity_id', 'path')) - ->where('entity_id IN(?)', $affectedCategoryIds); - $pairs = $write->fetchPairs($select); - - $pathCond = array($write->quoteInto('entity_id IN(?)', $affectedCategoryIds)); - $parentIds = array(); - - foreach ($pairs as $path) { - $pathCond[] = $write->quoteInto('path LIKE ?', $path . '/%'); - $parentIds = array_merge($parentIds, explode('/', $path)); - } - - $stores = $this->getStoresRootCategories(); - $where = join(' OR ', $pathCond); - $lastId = 0; - while (true) { - $select = $write->select() - ->from($this->getTable('catalog/category')) - ->where('entity_id>?', $lastId) - ->where($where) - ->order('entity_id') - ->limit(500); - $rowSet = $write->fetchAll($select); - - if (!$rowSet) { - break; - } - - $addStores = array(); - $remStores = array(); - - foreach ($rowSet as &$row) { - $lastId = $row['entity_id']; - $path = explode('/', $row['path']); - foreach ($stores as $storeId => $rootCategoryId) { - if (in_array($rootCategoryId, $path)) { - $addStores[$storeId][$row['entity_id']] = $row; - } else { - $remStores[$storeId][] = $row['entity_id']; - } - } - } - - // remove - foreach ($remStores as $storeId => $categoryIds) { - $where = $write->quoteInto('entity_id IN(?)', $categoryIds); - $write->delete($this->getMainStoreTable($storeId), $where); - } - - // add/update - foreach ($addStores as $storeId => $storeCategoryIds) { - $attributeValues = $this->_getAttributeValues(array_keys($storeCategoryIds), $storeId); - foreach ($storeCategoryIds as $row) { - $data = new Varien_Object($row); - $data->addData($attributeValues[$row['entity_id']]) - ->setStoreId($storeId); - $this->_synchronize($data); - } - } - } - - return $this; - } - - /** - * Synchronize flat data with eav after moving category - * - * @param integer $categoryId - * @param integer $prevParentId - * @param integer $parentId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function moveold($categoryId, $prevParentId, $parentId) - { - $_staticFields = array( - 'parent_id', - 'path', - 'level', - 'position', - 'children_count', - 'updated_at' - ); - $prevParent = Mage::getModel('catalog/category')->load($prevParentId); - $parent = Mage::getModel('catalog/category')->load($parentId); - if ($prevParent->getStore()->getWebsiteId() != $parent->getStore()->getWebsiteId()) { - foreach ($prevParent->getStoreIds() as $storeId) { - $this->_getWriteAdapter()->delete( - $this->getMainStoreTable($storeId), - $this->_getWriteAdapter()->quoteInto('entity_id = ?', $categoryId) - ); - } - $categoryPath = $this->_getWriteAdapter()->fetchOne(" - SELECT - path - FROM - {$this->getTable('catalog/category')} - WHERE - entity_id = '$categoryId' - "); - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable('catalog/category'), 'entity_id') - ->where('path LIKE ?', "$categoryPath/%") - ->orWhere('path = ?', $categoryPath); - $_categories = $this->_getWriteAdapter()->fetchAll($select); - foreach ($_categories as $_category) { - foreach ($parent->getStoreIds() as $storeId) { - $_tmpCategory = Mage::getModel('catalog/category') - ->setStoreId($storeId) - ->load($_category['entity_id']); - $this->_synchronize($_tmpCategory); - } - } - } else { - foreach ($parent->getStoreIds() as $store) { - $update = "UPDATE {$this->getMainStoreTable($store)}, {$this->getTable('catalog/category')} SET"; - foreach ($_staticFields as $field) { - $update .= " {$this->getMainStoreTable($store)}.".$field."={$this->getTable('catalog/category')}.".$field.","; - } - $update = substr($update, 0, -1); - $update .= " WHERE {$this->getMainStoreTable($store)}.entity_id = {$this->getTable('catalog/category')}.entity_id AND " . - "({$this->getTable('catalog/category')}.path like '{$parent->getPath()}/%' OR " . - "{$this->getTable('catalog/category')}.path like '{$prevParent->getPath()}/%')"; - $this->_getWriteAdapter()->query($update); - } - } - $prevParent = null; - $parent = null; - $_tmpCategory = null; -// $this->_move($categoryId, $prevParentPath, $parentPath); - return $this; - } - - /** - * Prepare array of category data to insert or update. - * - * array( - * 'field_name' => 'value' - * ) - * - * @param Mage_Catalog_Model_Category $category - * @param array $replaceFields - * @return array - */ - protected function _prepareDataForAllFields($category, $replaceFields = array()) - { - $table = $this->getMainStoreTable($category->getStoreId()); - $this->_getWriteAdapter()->resetDdlCache($table); - $table = $this->_getWriteAdapter()->describeTable($table); - $data = array(); - foreach ($table as $column=>$columnData) { - if (null !== $category->getData($column)) { - if (key_exists($column, $replaceFields)) { - $value = $category->getData($replaceFields[$column]); - } else { - $value = $category->getData($column); - } - if (is_array($value)) { - $value = implode(',', $value); - } - $data[$column] = $value; - } - } - return $data; - } - - /** - * Retrieve attribute instance - * Special for non static flat table - * - * @param mixed $attribute - * @return Mage_Eav_Model_Entity_Attribute_Abstract - */ - public function getAttribute($attribute) - { - return Mage::getSingleton('catalog/config') - ->getAttribute('catalog_category', $attribute); - } - - /** - * Get count of active/not active children categories - * - * @param Mage_Catalog_Model_Category $category - * @param bool $isActiveFlag - * @return integer - */ - public function getChildrenAmount($category, $isActiveFlag = true) - { - $_table = $this->getMainStoreTable($category->getStoreId()); - $select = $this->_getReadAdapter()->select() - ->from($_table, "COUNT({$_table}.entity_id)") - ->where("{$_table}.path LIKE ?", $category->getPath() . '/%') - ->where("{$_table}.is_active = ?", (int) $isActiveFlag); - return (int) $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Get products count in category - * - * @param Mage_Catalog_Model_Category $category - * @return integer - */ - public function getProductCount($category) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/category_product'), "COUNT({$this->getTable('catalog/category_product')}.product_id)") - ->where("{$this->getTable('catalog/category_product')}.category_id = ?", $category->getId()) - ->group("{$this->getTable('catalog/category_product')}.category_id"); - return (int) $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Return parent categories of category - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getParentCategories($category, $isActive = true) - { - $categories = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), array('main_table.entity_id', 'main_table.name')) - ->joinLeft( - array('url_rewrite'=>$this->getTable('core/url_rewrite')), - 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND url_rewrite.product_id IS NULL AND url_rewrite.store_id="'.$category->getStoreId().'" AND url_rewrite.id_path LIKE "category/%"', - array('request_path' => 'url_rewrite.request_path')) - ->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore()))); - if ($isActive) { - $select->where('main_table.is_active = ?', '1'); - } - $select->order('main_table.path ASC'); - $result = $this->_getReadAdapter()->fetchAll($select); - foreach ($result as $row) { - $row['id'] = $row['entity_id']; - $categories[$row['entity_id']] = Mage::getModel('catalog/category')->setData($row); - } - return $categories; - } - - /** - * Return parent category of current category with own custom design settings - * - * @param Mage_Catalog_Model_Category $category - * @return Mage_Catalog_Model_Category - */ - public function getParentDesignCategory($category) - { - $pathIds = array_reverse($category->getPathIds()); - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), '*') - ->where('entity_id IN (?)', $pathIds) - ->where('custom_use_parent_settings = ?', 0) - ->where('level != ?', 0) - ->order('level DESC'); - $result = $this->_getReadAdapter()->fetchRow($select); - return Mage::getModel('catalog/category')->setData($result); - } - - /** - * Return children categories of category - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getChildrenCategories($category) - { -// $node = $this->getNodeById($category->getId()); -// if ($node && $node->getChildrenNodes()) { -// return $node->getChildrenNodes(); -// } - $categories = $this->_loadNodes($category, 1, $category->getStoreId()); - return $categories; - } - - /** - * Check is category in list of store categories - * - * @param Mage_Catalog_Model_Category $category - * @return boolean - */ - public function isInRootCategoryList($category) - { - $innerSelect = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable($category->getStoreId()), new Zend_Db_Expr("CONCAT(path, '/%')")) - ->where('entity_id = ?', Mage::app()->getStore()->getRootCategoryId()); - $select = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable($category->getStoreId()), 'entity_id') - ->where('entity_id = ?', $category->getId()) - ->where(new Zend_Db_Expr("path LIKE ({$innerSelect->__toString()})")); - return (bool) $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Return children ids of category - * - * @param Mage_Catalog_Model_Category $category - * @param integer $level - * @return array - */ - public function getChildren($category, $recursive = true, $isActive = true) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable($category->getStoreId()), 'entity_id') - ->where('path LIKE ?', "{$category->getPath()}/%"); - if (!$recursive) { - $select->where('level <= ?', $category->getLevel() + 1); - } - if ($isActive) { - $select->where('is_active = ?', '1'); - } - $_categories = $this->_getReadAdapter()->fetchAll($select); - $categoriesIds = array(); - foreach ($_categories as $_category) { - $categoriesIds[] = $_category['entity_id']; - } - return $categoriesIds; - } - - /** - * Return all children ids of category (with category id) - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getAllChildren($category) - { - $categoriesIds = $this->getChildren($category); - $myId = array($category->getId()); - $categoriesIds = array_merge($myId, $categoriesIds); - - return $categoriesIds; - } - -/** - * Check if category id exist - * - * @param int $id - * @return bool - */ - public function checkId($id) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainStoreTable($this->getStoreId()), 'entity_id') - ->where('entity_id=?', $id); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Get design update data of parent categories - * - * @param Mage_Catalog_Model_Category $category - * @return array - */ - public function getDesignUpdateData($category) - { - $categories = array(); - $pathIds = array(); - foreach (array_reverse($category->getParentIds()) as $pathId) { - if ($pathId == Mage::app()->getStore()->getRootCategoryId()) { - $pathIds[] = $pathId; - break; - } - $pathIds[] = $pathId; - } - $select = $this->_getReadAdapter()->select() - ->from( - array('main_table' => $this->getMainStoreTable($category->getStoreId())), - array( - 'main_table.entity_id', - 'main_table.custom_design', - 'main_table.custom_design_from', - 'main_table.custom_design_to', - ) - ) - ->where('main_table.entity_id IN (?)', $pathIds) - ->where('main_table.is_active = ?', '1') - ->order('main_table.path DESC'); - $result = $this->_getReadAdapter()->fetchAll($select); - foreach ($result as $row) { - $row['id'] = $row['entity_id']; - $categories[$row['entity_id']] = Mage::getModel('catalog/category')->setData($row); - } - return $categories; - } - - /** - * Retrieve anchors above - * - * @param array $filterIds - * @param int $storeId - * @return array - */ - public function getAnchorsAbove(array $filterIds, $storeId = 0) - { - $select = $this->_getReadAdapter()->select() - ->from(array('e' => $this->getMainStoreTable($storeId)), 'entity_id') - ->where('is_anchor = ?', 1) - ->where('entity_id IN (?)', $filterIds); - - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Retrieve array with root category id per store - * - * @param int|array $storeIds result limitation - * @return array - */ - public function getStoresRootCategories($storeIds = null) - { - if (is_null($this->_storesRootCategories)) { - $select = $this->_getWriteAdapter()->select() - ->from(array('cs' => $this->getTable('core/store')), array('store_id')) - ->join( - array('csg' => $this->getTable('core/store_group')), - 'csg.group_id = cs.group_id', - array('root_category_id')) - ->where('cs.store_id <> ?', 0); - $this->_storesRootCategories = $this->_getWriteAdapter()->fetchPairs($select); - } - - if (!is_null($storeIds)) { - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - - $stores = array(); - foreach ($this->_storesRootCategories as $storeId => $rootId) { - if (in_array($storeId, $storeIds)) { - $stores[$storeId] = $rootId; - } - } - return $stores; - } - - return $this->_storesRootCategories; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat/Collection.php index 5a3b13dfdc..434d2793e1 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Flat/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,316 +28,11 @@ /** * Catalog category flat collection * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection + extends Mage_Catalog_Model_Resource_Category_Flat_Collection { - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'catalog_category_collection'; - - /** - * Event object name - * - * @var string - */ - protected $_eventObject = 'category_collection'; - - - /** - * Store id of application - * - * @var integer - */ - protected $_storeId = null; - - protected function _construct() - { - $this->_init('catalog/category_flat'); - $this->setModel('catalog/category'); - } - - protected function _initSelect() - { - $this->getSelect()->from( - array('main_table' => $this->getResource()->getMainStoreTable($this->getStoreId())), - array('entity_id', 'level', 'path', 'position', 'is_active', 'is_anchor') - ); - return $this; - } - - /** - * Add filter by entity id(s). - * - * @param mixed $categoryIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addIdFilter($categoryIds) - { - if (is_array($categoryIds)) { - if (empty($categoryIds)) { - $condition = ''; - } else { - $condition = array('in' => $categoryIds); - } - } elseif (is_numeric($categoryIds)) { - $condition = $categoryIds; - } elseif (is_string($categoryIds)) { - $ids = explode(',', $categoryIds); - if (empty($ids)) { - $condition = $categoryIds; - } else { - $condition = array('in' => $ids); - } - } - $this->addFieldToFilter('entity_id', $condition); - return $this; - } - - /** - * Before collection load - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - protected function _beforeLoad() - { - Mage::dispatchEvent($this->_eventPrefix . '_load_before', - array($this->_eventObject => $this)); - return parent::_beforeLoad(); - } - - /** - * After collection load - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - protected function _afterLoad() - { - Mage::dispatchEvent($this->_eventPrefix . '_load_after', - array($this->_eventObject => $this)); - - return parent::_afterLoad(); - } - - - /** - * Set store id - * - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Return store id. - * If store id is not set yet, return store of application - * - * @return integer - */ - public function getStoreId() - { - if (is_null($this->_storeId)) { - return Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Add filter by path to collection - * - * @param string $parent - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addParentPathFilter($parent) - { - $this->addFieldToFilter('path', array('like' => "{$parent}/%")); - return $this; - } - - /** - * Add store filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addStoreFilter() - { - $this->addFieldToFilter('main_table.store_id', $this->getStoreId()); - return $this; - } - - /** - * Set field to sort by - * - * @param string $sorted - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addSortedField($sorted) - { - if (is_string($sorted)) { - $this->addOrder($sorted, 'ASC'); - } else { - $this->addOrder('name', 'ASC'); - } - return $this; - } - - public function addIsActiveFilter() - { - $this->addFieldToFilter('is_active', 1); - Mage::dispatchEvent($this->_eventPrefix . '_add_is_active_filter', - array($this->_eventObject => $this)); - return $this; - } - - public function addNameToResult() - { - $this->addAttributeToSelect('name'); - return $this; - } - - /** - * Add attribute to select - * - * @param array|string $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addAttributeToSelect($attribute = '*') - { - if ($attribute == '*') { - // Save previous selected columns - $columns = $this->getSelect()->getPart(Zend_Db_Select::COLUMNS); - $this->getSelect()->reset(Zend_Db_Select::COLUMNS); - foreach ($columns as $column) { - if ($column[0] == 'main_table') { - // If column selected from main table, - // no need to select it again - continue; - } - - // Joined columns - if ($column[2] !== null) { - $expression = array($column[2] => $column[1]); - } else { - $expression = $column[2]; - } - $this->getSelect()->columns($expression, $column[0]); - } - - $this->getSelect()->columns('*', 'main_table'); - return $this; - } - - if (!is_array($attribute)) { - $attribute = array($attribute); - } - - $this->getSelect()->columns($attribute, 'main_table'); - return $this; - } - - /** - * Retrieve resource instance - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function getResource() - { - return parent::getResource(); - } - - /** - * Add attribute to sort order - * - * @param string $attribute - * @param string $dir - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addAttributeToSort($attribute, $dir='asc') - { - if (!is_string($attribute)) { - return $this; - } - $this->setOrder($attribute, $dir); - return $this; - } - - /** - * Emulate simple add attribute filter to collection - * - * @param string $attribute - * @param mixed $condition - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function addAttributeToFilter($attribute, $condition = null) - { - if (!is_string($attribute) || $condition === null) { - return $this; - } - - return $this->addFieldToFilter($attribute, $condition); - } - - public function addUrlRewriteToResult() - { - $storeId = Mage::app()->getStore()->getId(); - $this->getSelect()->joinLeft( - array('url_rewrite' => $this->getTable('core/url_rewrite')), - 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND url_rewrite.product_id IS NULL AND url_rewrite.store_id="'.$storeId.'" AND url_rewrite.id_path LIKE "category/%"', - array('request_path') - ); - return $this; - } - - public function addPathsFilter($paths) - { - if (!is_array($paths)) { - $paths = array($paths); - } - $select = $this->getSelect(); - $orWhere = false; - foreach ($paths as $path) { - if ($orWhere) { - $select->orWhere('main_table.path LIKE ?', "$path%"); - } else { - $select->where('main_table.path LIKE ?', "$path%"); - $orWhere = true; - } - } - return $this; - } - - public function addLevelFilter($level) - { - $this->getSelect()->where('main_table.level <= ?', $level); - return $this; - } - - public function addOrderField($field) - { - $this->setOrder('main_table.' . $field, 'ASC'); - return $this; - } - - /** - * Set collection page start and records to show - * - * @param integer $pageNum - * @param integer $pageSize - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection - */ - public function setPage($pageNum, $pageSize) - { - $this->setCurPage($pageNum) - ->setPageSize($pageSize); - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Indexer/Product.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Indexer/Product.php index db9250165a..048e3b56a9 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Indexer/Product.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Indexer/Product.php @@ -20,911 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product extends Mage_Index_Model_Mysql4_Abstract -{ - protected $_categoryTable; - protected $_categoryProductTable; - protected $_productWebsiteTable; - protected $_storeTable; - protected $_groupTable; - - /** - * Array of info about stores - * - * @var array - */ - protected $_storesInfo; - - protected function _construct() - { - $this->_init('catalog/category_product_index', 'category_id'); - $this->_categoryTable = $this->getTable('catalog/category'); - $this->_categoryProductTable = $this->getTable('catalog/category_product'); - $this->_productWebsiteTable = $this->getTable('catalog/product_website'); - $this->_storeTable = $this->getTable('core/store'); - $this->_groupTable = $this->getTable('core/store_group'); - } - - /** - * Process product save. - * Method is responsible for index support - * when product was saved and assigned categories was changed. - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - public function catalogProductSave(Mage_Index_Model_Event $event) - { - $productId = $event->getEntityPk(); - $data = $event->getNewData(); - - /** - * Check if category ids were updated - */ - if (!isset($data['category_ids'])) { - return $this; - } - - /** - * Select relations to categories - */ - $select = $this->_getWriteAdapter()->select() - ->from(array('cp' => $this->_categoryProductTable), 'category_id') - ->joinInner(array('ce' => $this->_categoryTable), 'ce.entity_id=cp.category_id', 'path') - ->where('cp.product_id=?', $productId); - - /** - * Get information about product categories - */ - $categories = $this->_getWriteAdapter()->fetchPairs($select); - $categoryIds = array(); - $allCategoryIds = array(); - - foreach ($categories as $id=>$path) { - $categoryIds[] = $id; - $allCategoryIds = array_merge($allCategoryIds, explode('/', $path)); - } - $allCategoryIds = array_unique($allCategoryIds); - $allCategoryIds = array_diff($allCategoryIds, $categoryIds); - - /** - * Delete previous index data - */ - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto('product_id=?', $productId) - ); - - $this->_refreshAnchorRelations($allCategoryIds, $productId); - $this->_refreshDirectRelations($categoryIds, $productId); - $this->_refreshRootRelations($productId); - return $this; - } - - /** - * Process Catalog Product mass action - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - public function catalogProductMassAction(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - - /** - * check is product ids were updated - */ - if (!isset($data['product_ids'])) { - return $this; - } - $productIds = $data['product_ids']; - $categoryIds = array(); - $allCategoryIds = array(); - - /** - * Select relations to categories - */ - $adapter = $this->_getWriteAdapter(); - $select = $adapter->select() - ->distinct(true) - ->from(array('cp' => $this->_categoryProductTable), array('category_id')) - ->join( - array('ce' => $this->_categoryTable), - 'ce.entity_id=cp.category_id', - array('path')) - ->where('cp.product_id IN(?)', $productIds); - $pairs = $adapter->fetchPairs($select); - foreach ($pairs as $categoryId => $categoryPath) { - $categoryIds[] = $categoryId; - $allCategoryIds = array_merge($allCategoryIds, explode('/', $categoryPath)); - } - - $allCategoryIds = array_unique($allCategoryIds); - $allCategoryIds = array_diff($allCategoryIds, $categoryIds); - - /** - * Delete previous index data - */ - $this->_getWriteAdapter()->delete( - $this->getMainTable(), $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $productIds) - ); - - $this->_refreshAnchorRelations($allCategoryIds, $productIds); - $this->_refreshDirectRelations($categoryIds, $productIds); - $this->_refreshRootRelations($productIds); - return $this; - } - - /** - * Return array of used root category id - path pairs - * - * @return array - */ - protected function _getRootCategories() - { - $rootCategories = array(); - $stores = $this->_getStoresInfo(); - foreach ($stores as $storeInfo) { - if ($storeInfo['root_id']) { - $rootCategories[$storeInfo['root_id']] = $storeInfo['root_path']; - } - } - - return $rootCategories; - } - - /** - * Process category index after category save - * - * @param Mage_Index_Model_Event $event - */ - public function catalogCategorySave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - - $checkRootCategories = false; - $processRootCategories = false; - $affectedRootCategoryIds = array(); - $rootCategories = $this->_getRootCategories(); - - /** - * Check if we have reindex category move results - */ - if (isset($data['affected_category_ids'])) { - $categoryIds = $data['affected_category_ids']; - $checkRootCategories = true; - } else if (isset($data['products_was_changed'])) { - $categoryIds = array($event->getEntityPk()); - - if (isset($rootCategories[$event->getEntityPk()])) { - $processRootCategories = true; - $affectedRootCategoryIds[] = $event->getEntityPk(); - } - } else { - return; - } - - $select = $this->_getWriteAdapter()->select() - ->from($this->_categoryTable, 'path') - ->where('entity_id IN (?)', $categoryIds); - $paths = $this->_getWriteAdapter()->fetchCol($select); - $allCategoryIds = array(); - foreach ($paths as $path) { - if ($checkRootCategories) { - foreach ($rootCategories as $rootCategoryId => $rootCategoryPath) { - if (strpos($path, sprintf('%d/', $rootCategoryPath)) === 0 || $path == $rootCategoryPath) { - $affectedRootCategoryIds[$rootCategoryId] = $rootCategoryId; - } - } - } - $allCategoryIds = array_merge($allCategoryIds, explode('/', $path)); - } - $allCategoryIds = array_unique($allCategoryIds); - - if ($checkRootCategories && count($affectedRootCategoryIds) > 1) { - $processRootCategories = true; - } - - /** - * retrieve anchor category id - */ - $anchorInfo = $this->_getAnchorAttributeInfo(); - $select = $this->_getReadAdapter()->select() - ->distinct(true) - ->from(array('ce' => $this->_categoryTable), array('entity_id')) - ->joinInner( - array('dca'=>$anchorInfo['table']), - "dca.entity_id=ce.entity_id AND dca.attribute_id={$anchorInfo['id']} AND dca.store_id=0", - array()) - ->where('dca.value=1') - ->where('ce.entity_id IN (?)', $allCategoryIds); - - $anchorIds = $this->_getWriteAdapter()->fetchCol($select); - /** - * delete only anchor id and category ids - */ - $deleteCategoryIds = array_unique(array_merge($anchorIds, $categoryIds)); - - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds) - ); - - $directIds = array_diff($categoryIds, $anchorIds); - if ($anchorIds) { - $this->_refreshAnchorRelations($anchorIds); - } - if ($directIds) { - $this->_refreshDirectRelations($directIds); - } - - /** - * Need to re-index affected root category ids when its are not anchor - */ - if ($processRootCategories) { - $reindexRootCategoryIds = array_diff($affectedRootCategoryIds, $anchorIds); - if ($reindexRootCategoryIds) { - $this->_refreshNotAnchorRootCategories($reindexRootCategoryIds); - } - } - } - - /** - * Reindex not anchor root categories - * - * @param array $categoryIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - protected function _refreshNotAnchorRootCategories(array $categoryIds = null) - { - if (empty($categoryIds)) { - return $this; - } - - // remove anchor relations - $where = array( - 'category_id IN(?)' => $categoryIds, - 'is_parent=?' => 0 - ); - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - - $stores = $this->_getStoresInfo(); - /** - * Build index for each store - */ - foreach ($stores as $storeData) { - $storeId = $storeData['store_id']; - $websiteId = $storeData['website_id']; - $rootPath = $storeData['root_path']; - $rootId = $storeData['root_id']; - if (!in_array($rootId, $categoryIds)) { - continue; - } - - $select = $this->_getWriteAdapter()->select() - ->distinct(true) - ->from(array('cc' => $this->getTable('catalog/category')), null) - ->join( - array('i' => $this->getMainTable()), - 'i.category_id = cc.entity_id and i.store_id = 1', - array()) - ->joinLeft( - array('ie' => $this->getMainTable()), - 'ie.category_id = ' . (int)$rootId . ' AND ie.product_id=i.product_id AND ie.store_id = ' . (int)$storeId, - array()) - ->where('cc.path LIKE ?', $rootPath . '/%') - ->where('ie.category_id IS NULL') - ->columns(array( - 'category_id' => new Zend_Db_Expr($rootId), - 'product_id' => 'i.product_id', - 'position' => new Zend_Db_Expr('0'), - 'is_parent' => new Zend_Db_Expr('0'), - 'store_id' => new Zend_Db_Expr($storeId), - 'visibility' => 'i.visibility' - )); - $query = $select->insertFromSelect($this->getMainTable()); - $this->_getWriteAdapter()->query($query); - - $visibilityInfo = $this->_getVisibilityAttributeInfo(); - $statusInfo = $this->_getStatusAttributeInfo(); - - $select = $this->_getReadAdapter()->select() - ->from(array('pw' => $this->_productWebsiteTable), array()) - ->joinLeft( - array('i' => $this->getMainTable()), - 'i.product_id = pw.product_id AND i.category_id = ' . (int)$rootId . ' AND i.store_id = ' . (int) $storeId, - array()) - ->join( - array('dv' => $visibilityInfo['table']), - "dv.entity_id = pw.product_id AND dv.attribute_id = {$visibilityInfo['id']} AND dv.store_id = 0", - array()) - ->joinLeft( - array('sv' => $visibilityInfo['table']), - "sv.entity_id = pw.product_id AND sv.attribute_id = {$visibilityInfo['id']} AND sv.store_id = " . (int)$storeId, - array()) - ->join( - array('ds' => $statusInfo['table']), - "ds.entity_id = pw.product_id AND ds.attribute_id = {$statusInfo['id']} AND ds.store_id = 0", - array()) - ->joinLeft( - array('ss' => $statusInfo['table']), - "ss.entity_id = pw.product_id AND ss.attribute_id = {$statusInfo['id']} AND ss.store_id = " . (int)$storeId, - array()) - ->where('i.product_id IS NULL') - ->where('pw.website_id=?', $websiteId) - ->where('IF(ss.value_id IS NOT NULL, ss.value, ds.value) = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) - ->columns(array( - 'category_id' => new Zend_Db_Expr($rootId), - 'product_id' => 'pw.product_id', - 'position' => new Zend_Db_Expr('0'), - 'is_parent' => new Zend_Db_Expr('1'), - 'store_id' => new Zend_Db_Expr($storeId), - 'visibility' => 'IF(sv.value_id IS NOT NULL, sv.value, dv.value)' - )); - - $query = $select->insertFromSelect($this->getMainTable()); - $this->_getWriteAdapter()->query($query); - } - - return $this; - } - - /** - * Rebuild index for direct associations categories and products - * - * @param null|array $categoryIds - * @param null|array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - protected function _refreshDirectRelations($categoryIds=null, $productIds=null) - { - if (!$categoryIds && !$productIds) { - return $this; - } - - $visibilityInfo = $this->_getVisibilityAttributeInfo(); - $statusInfo = $this->_getStatusAttributeInfo(); - /** - * Insert direct relations - * product_ids (enabled filter) X category_ids X store_ids - * Validate store root category - */ - $isParent = new Zend_Db_Expr('1 AS is_parent'); - $select = $this->_getWriteAdapter()->select() - ->from(array('cp' => $this->_categoryProductTable), - array('category_id', 'product_id', 'position', $isParent)) - ->joinInner(array('pw' => $this->_productWebsiteTable), 'pw.product_id=cp.product_id', array()) - ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) - ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array('store_id')) - ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', array()) - ->joinInner( - array('ce'=>$this->_categoryTable), - 'ce.entity_id=cp.category_id AND (ce.path LIKE CONCAT(rc.path, \'/%\') OR ce.entity_id=rc.entity_id)', - array()) - ->joinLeft( - array('dv'=>$visibilityInfo['table']), - "dv.entity_id=cp.product_id AND dv.attribute_id={$visibilityInfo['id']} AND dv.store_id=0", - array()) - ->joinLeft( - array('sv'=>$visibilityInfo['table']), - "sv.entity_id=cp.product_id AND sv.attribute_id={$visibilityInfo['id']} AND sv.store_id=s.store_id", - array('visibility' => 'IF(sv.value_id, sv.value, dv.value)')) - ->joinLeft( - array('ds'=>$statusInfo['table']), - "ds.entity_id=cp.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", - array()) - ->joinLeft( - array('ss'=>$statusInfo['table']), - "ss.entity_id=cp.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", - array()) - ->where('IF(ss.value_id, ss.value, ds.value)=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - if ($categoryIds) { - $select->where('cp.category_id IN (?)', $categoryIds); - } - if ($productIds) { - $select->where('cp.product_id IN(?)', $productIds); - } - $sql = $select->insertFromSelect( - $this->getMainTable(), - array('category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'), - true - ); - $this->_getWriteAdapter()->query($sql); - return $this; - } - /** - * Rebuild index for anchor categories and associated t child categories products - * - * @param null | array $categoryIds - * @param null | array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - protected function _refreshAnchorRelations($categoryIds=null, $productIds=null) - { - if (!$categoryIds && !$productIds) { - return $this; - } - - $anchorInfo = $this->_getAnchorAttributeInfo(); - $visibilityInfo = $this->_getVisibilityAttributeInfo(); - $statusInfo = $this->_getStatusAttributeInfo(); - - /** - * Insert anchor categories relations - */ - $isParent = new Zend_Db_Expr('IF (cp.category_id=ce.entity_id, 1, 0) AS is_parent'); - $position = new Zend_Db_Expr('IF (cp.category_id=ce.entity_id, - cp.position, - MIN((cc.position + 1) * (cc.level + 1) * 10000) + cp.position) AS position'); - $select = $this->_getReadAdapter()->select() - ->from(array('ce' => $this->_categoryTable), array('entity_id', 'cp.product_id', $position, $isParent)) - ->joinLeft(array('cc' => $this->_categoryTable), 'cc.path LIKE CONCAT(ce.path, \'/%\')', array()) - ->joinInner(array('cp' => $this->_categoryProductTable), 'cp.category_id=cc.entity_id OR cp.category_id=ce.entity_id', array()) - ->joinInner(array('pw' => $this->_productWebsiteTable), 'pw.product_id=cp.product_id', array()) - ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) - ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array('store_id')) - ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', array()) - ->joinLeft( - array('dca'=>$anchorInfo['table']), - "dca.entity_id=ce.entity_id AND dca.attribute_id={$anchorInfo['id']} AND dca.store_id=0", - array()) - ->joinLeft( - array('sca'=>$anchorInfo['table']), - "sca.entity_id=ce.entity_id AND sca.attribute_id={$anchorInfo['id']} AND sca.store_id=s.store_id", - array()) - ->joinLeft( - array('dv'=>$visibilityInfo['table']), - "dv.entity_id=pw.product_id AND dv.attribute_id={$visibilityInfo['id']} AND dv.store_id=0", - array()) - ->joinLeft( - array('sv'=>$visibilityInfo['table']), - "sv.entity_id=pw.product_id AND sv.attribute_id={$visibilityInfo['id']} AND sv.store_id=s.store_id", - array('visibility' => 'IF(sv.value_id, sv.value, dv.value)')) - ->joinLeft( - array('ds'=>$statusInfo['table']), - "ds.entity_id=pw.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", - array()) - ->joinLeft( - array('ss'=>$statusInfo['table']), - "ss.entity_id=pw.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", - array()) - /** - * Condition for anchor or root category (all products should be assigned to root) - */ - ->where('(ce.path LIKE CONCAT(rc.path, \'/%\') AND IF(sca.value_id, sca.value, dca.value)=1) OR ce.entity_id=rc.entity_id') - ->where('IF(ss.value_id, ss.value, ds.value)=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) - ->group(array('ce.entity_id', 'cp.product_id', 's.store_id')); - if ($categoryIds) { - $select->where('ce.entity_id IN (?)', $categoryIds); - } - if ($productIds) { - $select->where('pw.product_id IN(?)', $productIds); - } - - $sql = $select->insertFromSelect($this->getMainTable()); - $this->_getWriteAdapter()->query($sql); - return $this; - } - - /** - * Add product association with root store category for products which are not assigned to any another category - * - * @param int | array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - protected function _refreshRootRelations($productIds) - { - $visibilityInfo = $this->_getVisibilityAttributeInfo(); - $statusInfo = $this->_getStatusAttributeInfo(); - - /** - * Insert anchor categories relations - */ - $isParent = new Zend_Db_Expr('0'); - $position = new Zend_Db_Expr('0'); - $select = $this->_getReadAdapter()->select() - ->distinct(true) - ->from(array('pw' => $this->_productWebsiteTable), array()) - ->joinInner(array('g' => $this->_groupTable), 'g.website_id=pw.website_id', array()) - ->joinInner(array('s' => $this->_storeTable), 's.group_id=g.group_id', array()) - ->joinInner(array('rc' => $this->_categoryTable), 'rc.entity_id=g.root_category_id', - array('entity_id')) - ->joinLeft( - array('cp' => $this->_categoryProductTable), 'cp.product_id=pw.product_id', - array('pw.product_id', $position, $isParent, 's.store_id') - ) - ->joinLeft( - array('dv' => $visibilityInfo['table']), - "dv.entity_id=pw.product_id AND dv.attribute_id={$visibilityInfo['id']} AND dv.store_id=0", - array()) - ->joinLeft( - array('sv' => $visibilityInfo['table']), - "sv.entity_id=pw.product_id AND sv.attribute_id={$visibilityInfo['id']} AND sv.store_id=s.store_id", - array('visibility' => 'IF(sv.value_id, sv.value, dv.value)')) - ->joinLeft( - array('ds' => $statusInfo['table']), - "ds.entity_id=pw.product_id AND ds.attribute_id={$statusInfo['id']} AND ds.store_id=0", - array()) - ->joinLeft( - array('ss' => $statusInfo['table']), - "ss.entity_id=pw.product_id AND ss.attribute_id={$statusInfo['id']} AND ss.store_id=s.store_id", - array()) - /** - * Condition for anchor or root category (all products should be assigned to root) - */ - ->where('cp.product_id IS NULL') - ->where('IF(ss.value_id, ss.value, ds.value)=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) - ->where('pw.product_id IN(?)', $productIds); - - $sql = $select->insertFromSelect($this->getMainTable()); - $this->_getWriteAdapter()->query($sql); - - $select = $this->_getReadAdapter()->select() - ->from(array('pw' => $this->_productWebsiteTable), array()) - ->joinInner(array('g' => $this->_groupTable), 'g.website_id = pw.website_id', array()) - ->joinInner(array('s' => $this->_storeTable), 's.group_id = g.group_id', array()) - ->joinLeft(array('i' => $this->getMainTable()), 'i.product_id = pw.product_id AND i.category_id = g.root_category_id', array()) - ->joinLeft( - array('dv' => $visibilityInfo['table']), - "dv.entity_id = pw.product_id AND dv.attribute_id = {$visibilityInfo['id']} AND dv.store_id = 0", - array()) - ->joinLeft( - array('sv' => $visibilityInfo['table']), - "sv.entity_id = pw.product_id AND sv.attribute_id = {$visibilityInfo['id']} AND sv.store_id = s.store_id", - array()) - ->join( - array('ds' => $statusInfo['table']), - "ds.entity_id = pw.product_id AND ds.attribute_id = {$statusInfo['id']} AND ds.store_id = 0", - array()) - ->joinLeft( - array('ss' => $statusInfo['table']), - "ss.entity_id = pw.product_id AND ss.attribute_id = {$statusInfo['id']} AND ss.store_id = s.store_id", - array()) - ->where('i.product_id IS NULL') - ->where('IF(ss.value_id IS NOT NULL, ss.value, ds.value)=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) - ->where('pw.product_id IN(?)', $productIds) - ->columns(array( - 'category_id' => 'g.root_category_id', - 'product_id' => 'pw.product_id', - 'position' => $position, - 'is_parent' => new Zend_Db_Expr('1'), - 'store_id' => 's.store_id', - 'visibility' => 'IF(sv.value_id, sv.value, dv.value)' - )); - - $sql = $select->insertFromSelect($this->getMainTable()); - $this->_getWriteAdapter()->query($sql); - - return $this; - } - - /** - * Get is_anchor category attribute information - * - * @return array array('id' => $id, 'table' => $table) - */ - protected function _getAnchorAttributeInfo() - { - $isAnchorAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'is_anchor'); - $info = array( - 'id' => $isAnchorAttribute->getId(), - 'table' => $isAnchorAttribute->getBackend()->getTable() - ); - return $info; - } - - /** - * Get visibility product attribute information - * - * @return array array('id' => $id, 'table' => $table) - */ - protected function _getVisibilityAttributeInfo() - { - $visibilityAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'visibility'); - $info = array( - 'id' => $visibilityAttribute->getId(), - 'table' => $visibilityAttribute->getBackend()->getTable() - ); - return $info; - } - - /** - * Get status product attribute information - * - * @return array array('id' => $id, 'table' => $table) - */ - protected function _getStatusAttributeInfo() - { - $statusAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'status'); - $info = array( - 'id' => $statusAttribute->getId(), - 'table' => $statusAttribute->getBackend()->getTable() - ); - return $info; - } - - /** - * Rebuild all index data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->clearTemporaryIndexTable(); - $idxTable = $this->getIdxTable(); - $idxAdapter = $this->_getIndexAdapter(); - $stores = $this->_getStoresInfo(); - /** - * Build index for each store - */ - foreach ($stores as $storeData) { - $storeId = $storeData['store_id']; - $websiteId = $storeData['website_id']; - $rootPath = $storeData['root_path']; - $rootId = $storeData['root_id']; - /** - * Prepare visibility for all enabled store products - */ - $enabledTable = $this->_prepareEnabledProductsVisibility($websiteId, $storeId); - /** - * Select information about anchor categories - */ - $anchorTable = $this->_prepareAnchorCategories($storeId, $rootPath); - /** - * Add relations between not anchor categories and products - */ - $sql = "INSERT INTO {$idxTable} - SELECT - cp.category_id, cp.product_id, cp.position, 1, {$storeId}, pv.visibility - FROM - {$this->_categoryProductTable} AS cp - INNER JOIN {$enabledTable} AS pv ON pv.product_id=cp.product_id - LEFT JOIN {$anchorTable} AS ac ON ac.category_id=cp.category_id - WHERE - ac.category_id IS NULL"; - $idxAdapter->query($sql); - /** - * Assign products not associated to any category to root category in index - */ - $sql = "INSERT INTO {$idxTable} - SELECT - {$rootId}, pv.product_id, 0, 1, {$storeId}, pv.visibility - FROM - {$enabledTable} AS pv - LEFT JOIN {$this->_categoryProductTable} AS cp ON pv.product_id=cp.product_id - WHERE - cp.product_id IS NULL"; - $idxAdapter->query($sql); - - /** - * Prepare anchor categories products - */ - $anchorProductsTable = $this->_getAnchorCategoriesProductsTemporaryTable(); - $idxAdapter->delete($anchorProductsTable); - - $position = new Zend_Db_Expr('IF (ca.category_id=ce.entity_id, - cp.position, - MIN((ce.position + 1) * (ce.level + 1) * 10000 + cp.position)) - AS position'); - - $sql = "SELECT - STRAIGHT_JOIN DISTINCT - ca.category_id, cp.product_id, $position - FROM {$anchorTable} AS ca - INNER JOIN {$this->_categoryTable} AS ce - ON ce.path LIKE ca.path OR ce.entity_id = ca.category_id - INNER JOIN {$this->_categoryProductTable} AS cp - ON cp.category_id = ce.entity_id - INNER JOIN {$enabledTable} as pv - ON pv.product_id = cp.product_id - GROUP BY ca.category_id, cp.product_id"; - $this->insertFromSelect($sql, $anchorProductsTable, array('category_id', 'product_id', 'position')); - - /** - * Add anchor categories products to index - */ - $sql = "INSERT INTO {$idxTable} - SELECT - ap.category_id, ap.product_id, ap.position, - IF(cp.product_id, 1, 0), {$storeId}, pv.visibility - FROM - {$anchorProductsTable} AS ap - LEFT JOIN {$this->_categoryProductTable} AS cp - ON cp.category_id=ap.category_id AND cp.product_id=ap.product_id - INNER JOIN {$enabledTable} as pv - ON pv.product_id = ap.product_id"; - $idxAdapter->query($sql); - - $select = $idxAdapter->select() - ->from(array('e' => $this->getTable('catalog/product')), null) - ->join( - array('ei' => $enabledTable), - 'ei.product_id = e.entity_id', - array()) - ->joinLeft( - array('i' => $idxTable), - 'i.product_id = e.entity_id AND i.category_id = :category_id AND i.store_id = :store_id', - array()) - ->where('i.product_id IS NULL') - ->columns(array( - 'category_id' => new Zend_Db_Expr($rootId), - 'product_id' => 'e.entity_id', - 'position' => new Zend_Db_Expr('0'), - 'is_parent' => new Zend_Db_Expr('1'), - 'store_id' => new Zend_Db_Expr($storeId), - 'visibility' => 'ei.visibility' - )); - $query = $select->insertFromSelect($idxTable); - $idxAdapter->query($query, array('store_id' => $storeId, 'category_id' => $rootId)); - } - $this->syncData(); - - /** - * Clean up temporary tables - */ - $this->clearTemporaryIndexTable(); - $idxAdapter->delete($enabledTable); - $idxAdapter->delete($anchorTable); - $idxAdapter->delete($anchorProductsTable); - - return $this; - } - - /** - * Get array with store|website|root_categry path information - * - * @return array - */ - protected function _getStoresInfo() - { - if (is_null($this->_storesInfo)) { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from(array('s' => $this->getTable('core/store')), array('store_id', 'website_id')) - ->join( - array('sg' => $this->getTable('core/store_group')), - 'sg.group_id = s.group_id', - array()) - ->join( - array('c' => $this->getTable('catalog/category')), - 'c.entity_id = sg.root_category_id', - array( - 'root_path' => 'path', - 'root_id' => 'entity_id' - ) - ); - $this->_storesInfo = $adapter->fetchAll($select); - } - - return $this->_storesInfo; - } - - /** - * Create temporary table with enabled products visibility info - * - * @return string temporary table name - */ - protected function _prepareEnabledProductsVisibility($websiteId, $storeId) - { - $statusAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'status'); - $visibilityAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'visibility'); - $statusAttributeId = $statusAttribute->getId(); - $visibilityAttributeId = $visibilityAttribute->getId(); - $statusTable = $statusAttribute->getBackend()->getTable(); - $visibilityTable = $visibilityAttribute->getBackend()->getTable(); - - /** - * Prepare temporary table - */ - $tmpTable = $this->_getEnabledProductsTemporaryTable(); - $this->_getIndexAdapter()->delete($tmpTable); - - $sql = "SELECT - pw.product_id AS product_id, - IF(pvs.value_id>0, pvs.value, pvd.value) AS visibility - FROM - {$this->_productWebsiteTable} AS pw - LEFT JOIN {$visibilityTable} AS pvd - ON pvd.entity_id=pw.product_id AND pvd.attribute_id={$visibilityAttributeId} AND pvd.store_id=0 - LEFT JOIN {$visibilityTable} AS pvs - ON pvs.entity_id=pw.product_id AND pvs.attribute_id={$visibilityAttributeId} AND pvs.store_id={$storeId} - LEFT JOIN {$statusTable} AS psd - ON psd.entity_id=pw.product_id AND psd.attribute_id={$statusAttributeId} AND psd.store_id=0 - LEFT JOIN {$statusTable} AS pss - ON pss.entity_id=pw.product_id AND pss.attribute_id={$statusAttributeId} AND pss.store_id={$storeId} - WHERE - pw.website_id={$websiteId} - AND IF(pss.value_id>0, pss.value, psd.value) = " . Mage_Catalog_Model_Product_Status::STATUS_ENABLED; - $this->insertFromSelect($sql, $tmpTable, array('product_id' , 'visibility')); - return $tmpTable; - } - - /** - * Retrieve temporary table of category enabled products - * - * @return string - */ - protected function _getEnabledProductsTemporaryTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/category_product_enabled_indexer_idx'); - } - return $this->getTable('catalog/category_product_enabled_indexer_tmp'); - } - - /** - * Create temporary table with list of anchor categories - * - * @param int $storeId - * @return string temporary table name - */ - protected function _prepareAnchorCategories($storeId, $rootPath) - { - $isAnchorAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'is_anchor'); - $anchorAttributeId = $isAnchorAttribute->getId(); - $anchorTable = $isAnchorAttribute->getBackend()->getTable(); - - $tmpTable = $this->_getAnchorCategoriesTemporaryTable(); - $this->_getIndexAdapter()->delete($tmpTable); - - $sql = "SELECT - ce.entity_id AS category_id, - CONCAT(ce.path, '/%') AS path - FROM - {$this->_categoryTable} as ce - LEFT JOIN {$anchorTable} AS cad - ON cad.entity_id=ce.entity_id AND cad.attribute_id={$anchorAttributeId} AND cad.store_id=0 - LEFT JOIN {$anchorTable} AS cas - ON cas.entity_id=ce.entity_id AND cas.attribute_id={$anchorAttributeId} AND cas.store_id={$storeId} - WHERE - (IF(cas.value_id>0, cas.value, cad.value) = 1 AND ce.path LIKE '{$rootPath}/%') - OR ce.path='{$rootPath}'"; - $this->insertFromSelect($sql, $tmpTable, array('category_id', 'path')); - return $tmpTable; - } - - /** - * Retrieve temporary table of anchor categories - * - * @return string - */ - protected function _getAnchorCategoriesTemporaryTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/category_anchor_indexer_idx'); - } - return $this->getTable('catalog/category_anchor_indexer_idx'); - } - - /** - * Retrieve temporary table of anchor categories products - * - * @return string - */ - protected function _getAnchorCategoriesProductsTemporaryTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/category_anchor_products_indexer_idx'); - } - return $this->getTable('catalog/category_anchor_products_indexer_tmp'); - } - - /** - * Retrieve temporary decimal index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/category_product_indexer_idx'); - } - return $this->getTable('catalog/category_product_indexer_tmp'); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team + */ +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Indexer_Product + extends Mage_Catalog_Model_Resource_Category_Indexer_Product +{ } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Tree.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Tree.php index daae2e88ee..c2da19207f 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Tree.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category/Tree.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,566 +28,10 @@ /** * Category tree model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree extends Varien_Data_Tree_Dbp +class Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree extends Mage_Catalog_Model_Resource_Category_Tree { - - /** - * Categories resource collection - * - * @var Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - protected $_collection; - - /** - * Id of 'is_active' category attribute - * - * @var int - */ - protected $_isActiveAttributeId = null; - - protected $_joinUrlRewriteIntoCollection = false; - - /** - * Inactive categories ids - * - * @var array - */ - protected $_inactiveCategoryIds = null; - - /** - * store id - * - * @var integer - */ - protected $_storeId = null; - - /** - * Enter description here... - * - */ - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - - parent::__construct( - $resource->getConnection('catalog_write'), - $resource->getTableName('catalog/category'), - array( - Varien_Data_Tree_Dbp::ID_FIELD => 'entity_id', - Varien_Data_Tree_Dbp::PATH_FIELD => 'path', - Varien_Data_Tree_Dbp::ORDER_FIELD => 'position', - Varien_Data_Tree_Dbp::LEVEL_FIELD => 'level', - ) - ); - } - - /** - * Set store id - * - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - public function setStoreId($storeId) - { - $this->_storeId = (int) $storeId; - return $this; - } - - /** - * Return store id - * - * @return integer - */ - public function getStoreId() - { - if ($this->_storeId === null) { - $this->_storeId = Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Enter description here... - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection $collection - * @param boolean $sorted - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - public function addCollectionData($collection=null, $sorted=false, $exclude=array(), $toLoad=true, $onlyActive = false) - { - if (is_null($collection)) { - $collection = $this->getCollection($sorted); - } else { - $this->setCollection($collection); - } - - if (!is_array($exclude)) { - $exclude = array($exclude); - } - - $nodeIds = array(); - foreach ($this->getNodes() as $node) { - if (!in_array($node->getId(), $exclude)) { - $nodeIds[] = $node->getId(); - } - } - $collection->addIdFilter($nodeIds); - if ($onlyActive) { - - $disabledIds = $this->_getDisabledIds($collection); - if ($disabledIds) { - $collection->addFieldToFilter('entity_id', array('nin'=>$disabledIds)); - } - $collection->addAttributeToFilter('is_active', 1); - $collection->addAttributeToFilter('include_in_menu', 1); - } - - if ($this->_joinUrlRewriteIntoCollection) { - $collection->joinUrlRewrite(); - $this->_joinUrlRewriteIntoCollection = false; - } - - if($toLoad) { - $collection->load(); - - foreach ($collection as $category) { - if ($this->getNodeById($category->getId())) { - $this->getNodeById($category->getId()) - ->addData($category->getData()); - } - } - - - foreach ($this->getNodes() as $node) { - if (!$collection->getItemById($node->getId()) && $node->getParent()) { - $this->removeNode($node); - } - } - } - - return $this; - } - - /** - * Add inactive categories ids - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - public function addInactiveCategoryIds($ids) - { - if (!is_array($this->_inactiveCategoryIds)) { - $this->_initInactiveCategoryIds(); - } - $this->_inactiveCategoryIds = array_merge($ids, $this->_inactiveCategoryIds); - return $this; - } - - /** - * Retreive inactive categories ids - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat - */ - protected function _initInactiveCategoryIds() - { - $this->_inactiveCategoryIds = array(); - Mage::dispatchEvent('catalog_category_tree_init_inactive_category_ids', array('tree'=>$this)); - return $this; - } - - /** - * Retreive inactive categories ids - * - * @return array - */ - public function getInactiveCategoryIds() - { - if (!is_array($this->_inactiveCategoryIds)) { - $this->_initInactiveCategoryIds(); - } - - return $this->_inactiveCategoryIds; - } - - protected function _getDisabledIds($collection) - { - $storeId = Mage::app()->getStore()->getId(); - - $this->_inactiveItems = $this->getInactiveCategoryIds(); - - - $this->_inactiveItems = array_merge( - $this->_getInactiveItemIds($collection, $storeId), - $this->_inactiveItems - ); - - - $allIds = $collection->getAllIds(); - $disabledIds = array(); - - foreach ($allIds as $id) { - $parents = $this->getNodeById($id)->getPath(); - foreach ($parents as $parent) { - if (!$this->_getItemIsActive($parent->getId(), $storeId)){ - $disabledIds[] = $id; - continue; - } - } - } - return $disabledIds; - } - - protected function _getIsActiveAttributeId() - { - if (is_null($this->_isActiveAttributeId)) { - $select = $this->_conn->select() - ->from(array('a'=>Mage::getSingleton('core/resource')->getTableName('eav/attribute')), array('attribute_id')) - ->join(array('t'=>Mage::getSingleton('core/resource')->getTableName('eav/entity_type')), 'a.entity_type_id = t.entity_type_id') - ->where('entity_type_code = ?', 'catalog_category') - ->where('attribute_code = ?', 'is_active'); - - $this->_isActiveAttributeId = $this->_conn->fetchOne($select); - } - return $this->_isActiveAttributeId; - } - - protected function _getInactiveItemIds($collection, $storeId) - { - $filter = $collection->getAllIdsSql(); - $attributeId = $this->_getIsActiveAttributeId(); - - $table = Mage::getSingleton('core/resource')->getTableName('catalog/category') . '_int'; - $select = $this->_conn->select() - ->from(array('d'=>$table), array('d.entity_id')) - ->where('d.attribute_id = ?', $attributeId) - ->where('d.store_id = ?', 0) - ->where('d.entity_id IN (?)', new Zend_Db_Expr($filter)) - ->joinLeft(array('c'=>$table), "c.attribute_id = '{$attributeId}' AND c.store_id = '{$storeId}' AND c.entity_id = d.entity_id", array()) - ->where('IF(c.value_id>0, c.value, d.value) = ?', 0); - - return $this->_conn->fetchCol($select); - } - - protected function _getItemIsActive($id) - { - if (!in_array($id, $this->_inactiveItems)) { - return true; - } - return false; - } - - - /** - * Get categories collection - * - * @param boolean $sorted - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function getCollection($sorted=false) - { - if (is_null($this->_collection)) { - $this->_collection = $this->_getDefaultCollection($sorted); - } - return $this->_collection; - } - - /** - * Enter description here... - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection $collection - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - public function setCollection($collection) - { - if (!is_null($this->_collection)) { - destruct($this->_collection); - } - $this->_collection = $collection; - return $this; - } - - /** - * Enter description here... - * - * @param boolean $sorted - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - protected function _getDefaultCollection($sorted=false) - { - $this->_joinUrlRewriteIntoCollection = true; - $collection = Mage::getModel('catalog/category')->getCollection(); - /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */ - - $attributes = Mage::getConfig()->getNode('frontend/category/collection/attributes'); - if ($attributes) { - $attributes = $attributes->asArray(); - $attributes = array_keys($attributes); - } - $collection->addAttributeToSelect($attributes); - - if ($sorted) { - if (is_string($sorted)) { - // $sorted is supposed to be attribute name - $collection->addAttributeToSort($sorted); - } else { - $collection->addAttributeToSort('name'); - } - } - - return $collection; - } - - - /** - * Move tree before - * - * @param Varien_Data_Tree_Node $node - * @param Varien_Data_Tree_Node $newParent - * @param Varien_Data_Tree_Node $prevNode - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - protected function _beforeMove($category, $newParent, $prevNode) - { - Mage::dispatchEvent('catalog_category_tree_move_before', - array( - 'category' => $category, - 'prev_parent' => $prevNode, - 'parent' => $newParent - )); - - return $this; - } - - /** - * Executing parents move method and cleaning cache after it - * - */ - public function move($category, $newParent, $prevNode = null) { - - $this->_beforeMove($category, $newParent, $prevNode); - Mage::getResourceSingleton('catalog/category')->move($category->getId(), $newParent->getId()); - parent::move($category, $newParent, $prevNode); - - $this->_afterMove($category, $newParent, $prevNode); - } - - /** - * Move tree after - * - * @param Varien_Data_Tree_Node $node - * @param Varien_Data_Tree_Node $newParent - * @param Varien_Data_Tree_Node $prevNode - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - protected function _afterMove($category, $newParent, $prevNode) - { - Mage::app()->cleanCache(array(Mage_Catalog_Model_Category::CACHE_TAG)); - - Mage::dispatchEvent('catalog_category_tree_move_after', - array( - 'category' => $category, - 'prev_node' => $prevNode, - 'parent' => $newParent - )); - - return $this; - } - - - /** - * Load whole category tree, that will include specified categories ids. - * - * @param array $ids - * @param bool $addCollectionData - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree - */ - public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductCount = true) - { - // load first two levels, if no ids specified - if (empty($ids)) { - $select = $this->_conn->select() - ->from($this->_table, 'entity_id') - ->where('`level` <= 2'); - $ids = $this->_conn->fetchCol($select); - } - if (!is_array($ids)) { - $ids = array($ids); - } - foreach ($ids as $key => $id) { - $ids[$key] = (int)$id; - } - - // collect paths of specified IDs and prepare to collect all their parents and neighbours - $select = $this->_conn->select() - ->from($this->_table, array('path', 'level')) - ->where(sprintf('entity_id IN (%s)', implode(', ', $ids))); - $where = array('`level`=0' => true); - foreach ($this->_conn->fetchAll($select) as $item) { - $path = explode('/', $item['path']); - $level = (int)$item['level']; - while ($level > 0) { - $path[count($path) - 1] = '%'; - $where[sprintf("`level`=%d AND `path` LIKE '%s'", $level, implode('/', $path))] = true; - array_pop($path); - $level--; - } - } - $where = array_keys($where); - - // get all required records - if ($addCollectionData) { - $select = $this->_createCollectionDataSelect(); - } - else { - $select = clone $this->_select; - $select->order($this->_orderField . ' ASC'); - } - $select->where(implode(' OR ', $where)); - - // get array of records and add them as nodes to the tree - $arrNodes = $this->_conn->fetchAll($select); - if (!$arrNodes) { - return false; - } - if ($updateAnchorProductCount) { - $this->_updateAnchorProductCount($arrNodes); - } - $childrenItems = array(); - foreach ($arrNodes as $key => $nodeInfo) { - $pathToParent = explode('/', $nodeInfo[$this->_pathField]); - array_pop($pathToParent); - $pathToParent = implode('/', $pathToParent); - $childrenItems[$pathToParent][] = $nodeInfo; - } - $this->addChildNodes($childrenItems, '', null); - - return $this; - } - - /** - * Load array of category parents - * - * @param string $path - * @param bool $addCollectionData - * @param bool $withRootNode - * @return array - */ - public function loadBreadcrumbsArray($path, $addCollectionData = true, $withRootNode = false) - { - $path = explode('/', $path); - if (!$withRootNode) { - array_shift($path); - } - $result = array(); - if (!empty($path)) { - if ($addCollectionData) { - $select = $this->_createCollectionDataSelect(false); - } - else { - $select = clone $this->_select; - } - $select->where(sprintf('e.entity_id IN (%s)', implode(', ', $path))) - ->order(new Zend_Db_Expr('LENGTH(e.path) ASC')); - $result = $this->_conn->fetchAll($select); - $this->_updateAnchorProductCount($result); - } - return $result; - } - - /** - * Replace products count with self products count, if category is non-anchor - * - * @param array $data - */ - protected function _updateAnchorProductCount(&$data) - { - foreach ($data as $key => $row) { - if (0 === (int)$row['is_anchor']) { - $data[$key]['product_count'] = $row['self_product_count']; - } - } - } - - /** - * Obtain select for categories with attributes. - * - * By default everything from entity table is selected - * + name, is_active and is_anchor - * - * Also the correct product_count is selected, depending on is the category anchor or not. - * - * @param bool $sorted - * @param array $optionalAttributes - * @return Zend_Db_Select - */ - protected function _createCollectionDataSelect($sorted = true, $optionalAttributes = array()) - { - $select = $this->_getDefaultCollection($sorted ? $this->_orderField : false) - ->getSelect(); - // add attributes to select - $attributes = array('name', 'is_active', 'is_anchor'); - if ($optionalAttributes) { - $attributes = array_unique(array_merge($attributes, $optionalAttributes)); - } - foreach ($attributes as $attributeCode) { - $attribute = Mage::getResourceSingleton('catalog/category')->getAttribute($attributeCode); - // join non-static attribute table - if (!$attribute->getBackend()->isStatic()) { - $defaultTableAs = "default_$attributeCode"; - $storeTableAs = "store_$attributeCode"; - $select->joinLeft( - array($defaultTableAs => $attribute->getBackend()->getTable()), - sprintf('`%1$s`.entity_id=e.entity_id AND `%1$s`.attribute_id=%2$d AND `%1$s`.entity_type_id=e.entity_type_id AND `%1$s`.store_id=%3$d', - $defaultTableAs, $attribute->getData('attribute_id'), Mage_Core_Model_App::ADMIN_STORE_ID - ), - array($attributeCode => 'value') - ) - ->joinLeft( - array($storeTableAs => $attribute->getBackend()->getTable()), - sprintf('`%1$s`.entity_id=e.entity_id AND `%1$s`.attribute_id=%2$d AND `%1$s`.entity_type_id=e.entity_type_id AND `%1$s`.store_id=%3$d', - $storeTableAs, $attribute->getData('attribute_id'), $this->getStoreId() - ), - array($attributeCode => new Zend_Db_Expr("IF(LENGTH(`{$storeTableAs}`.value)>0, `{$storeTableAs}`.value, `$defaultTableAs`.value)")) - ); - } - } - - // count children products qty plus self products qty - $categoriesTable = Mage::getSingleton('core/resource')->getTableName('catalog/category'); - $categoriesProductsTable = Mage::getSingleton('core/resource')->getTableName('catalog/category_product'); - $select->joinLeft(array('_category_product' => $categoriesProductsTable), - 'e.entity_id=_category_product.category_id', - array( - 'self_product_count' => new Zend_Db_Expr('COUNT(_category_product.product_id)'), - 'product_count' => new Zend_Db_Expr('(SELECT COUNT(DISTINCT cp.product_id) FROM ' . $categoriesTable . ' ee - LEFT JOIN ' . $categoriesProductsTable . ' cp ON ee.entity_id=cp.category_id - WHERE ee.entity_id=e.entity_id OR ee.path like CONCAT(e.path, \'/%\'))' - ))) - ->group('e.entity_id'); - - return $select; - } - - /** - * Get real existing category ids by specified ids - * - * @param array $ids - * @return array - */ - public function getExistingCategoryIdsBySpecifiedIds($ids) - { - if (empty($ids)) { - return array(); - } - if (!is_array($ids)) { - $ids = array($ids); - } - $select = $this->_conn->select() - ->from($this->_table, array('entity_id')) - ->where(sprintf('entity_id IN (%s)', implode(', ', $ids))); - return $this->_conn->fetchCol($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php index b1a89d8d7c..1d7ca29388 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Collection/Abstract.php @@ -20,165 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog EAV collection resource abstract model - * * Implement using diferent stores for retrieve attribute values * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract extends Mage_Eav_Model_Entity_Collection_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract extends Mage_Catalog_Model_Resource_Collection_Abstract { - protected $_storeId = null; - - public function setStore($store) - { - $this->setStoreId(Mage::app()->getStore($store)->getId()); - return $this; - } - - public function setStoreId($storeId) - { - if ($storeId instanceof Mage_Core_Model_Store) { - $storeId = $storeId->getId(); - } - $this->_storeId = $storeId; - return $this; - } - - public function getStoreId() - { - if (is_null($this->_storeId)) { - $this->setStoreId(Mage::app()->getStore()->getId()); - } - return $this->_storeId; - } - - public function getDefaultStoreId() - { - return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; - } - - /** - * Retrieve attributes load select - * - * @param string $table - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - protected function _getLoadAttributesSelect($table, $attributeIds = array()) - { - if (empty($attributeIds)) { - $attributeIds = $this->_selectAttributes; - } - if ((int) $this->getStoreId()) { - $entityIdField = $this->getEntity()->getEntityIdField(); - $joinCondition = 'store.attribute_id=default.attribute_id - AND store.entity_id=default.entity_id - AND store.store_id='.(int) $this->getStoreId(); - - $select = $this->getConnection()->select() - ->from(array('default'=>$table), array($entityIdField, 'attribute_id', 'default_value'=>'value')) - ->joinLeft( - array('store'=>$table), - $joinCondition, - array( - 'store_value' => 'value', - 'value' => new Zend_Db_Expr('IF(store.value_id>0, store.value, default.value)') - ) - ) - ->where('default.entity_type_id=?', $this->getEntity()->getTypeId()) - ->where("default.$entityIdField in (?)", array_keys($this->_itemsById)) - ->where('default.attribute_id in (?)', $attributeIds) - ->where('default.store_id = 0'); - } - else { - $select = parent::_getLoadAttributesSelect($table) - ->where('store_id=?', $this->getDefaultStoreId()); - } - return $select; - } - - /** - * Initialize entity ubject property value - * - * $valueInfo is _getLoadAttributesSelect fetch result row - * - * @param array $valueInfo - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - /*protected function _setItemAttributeValue($valueInfo) - { - $entityIdField = $this->getEntity()->getEntityIdField(); - $entityId = $valueInfo[$entityIdField]; - if (!isset($this->_items[$entityId])) { - Mage::throwException('Mage_Eav', - Mage::helper('eav')->__('Data integrity: No header row found for attribute.') - ); - } - $attributeCode = $this->getEntity()->getAttribute($valueInfo['attribute_id']) - ->getAttributeCode(); - $this->_items[$entityId]->setData($attributeCode, $valueInfo['value']); - return $this; - }*/ - - /** - * Adding join statement to collection select instance - * - * @param string $method - * @param object $attribute - * @param string $tableAlias - * @param array $condition - * @param string $fieldCode - * @param string $fieldAlias - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - protected function _joinAttributeToSelect($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias) - { - if (isset($this->_joinAttributes[$fieldCode]['store_id'])) { - $store_id = $this->_joinAttributes[$fieldCode]['store_id']; - } else { - $store_id = $this->getStoreId(); - } - - $adapter = $this->getConnection(); - - if ($store_id != $this->getDefaultStoreId() && !$attribute->isScopeGlobal()) { - /** - * Add joining default value for not default store - * if value for store is null - we use default value - */ - $defCondition = '('.join(') AND (', $condition).')'; - $defAlias = $tableAlias.'_default'; - $defFieldCode = $fieldCode.'_default'; - $defFieldAlias= str_replace($tableAlias, $defAlias, $fieldAlias); - - $defCondition = str_replace($tableAlias, $defAlias, $defCondition); - $defCondition.= $adapter->quoteInto( - " AND " . $adapter->quoteColumnAs("$defAlias.store_id", null) . " = ?", - $this->getDefaultStoreId()); - - $this->getSelect()->$method( - array($defAlias => $attribute->getBackend()->getTable()), - $defCondition, - array() - ); - - $method = 'joinLeft'; - $fieldAlias = new Zend_Db_Expr("IF($tableAlias.value_id > 0, $fieldAlias, $defFieldAlias)"); - $this->_joinAttributes[$fieldCode]['condition_alias'] = $fieldAlias; - $this->_joinAttributes[$fieldCode]['attribute'] = $attribute; - } else { - $store_id = $this->getDefaultStoreId(); - } - - $condition[] = $adapter->quoteInto( - $adapter->quoteColumnAs("$tableAlias.store_id", null) . ' = ?', $store_id); - return parent::_joinAttributeToSelect($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Config.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Config.php index 7965de0eda..26c9a3113f 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Config.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,110 +28,10 @@ /** * Catalog Config Resource Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Config extends Mage_Catalog_Model_Resource_Config { - /** - * catalog_product entity type id - * - * @var int - */ - protected $_entityTypeId; - - protected $_storeId = null; - - /** - * Initialize connection - * - */ - protected function _construct() { - $this->_init('eav/attribute', 'attribute_id'); - } - - /** - * Set store id - * - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Config - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Return store id. - * If is not set return current app store - * - * @return integer - */ - public function getStoreId() - { - if ($this->_storeId === null) { - return Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Retrieve catalog_product entity type id - * - * @return int - */ - public function getEntityTypeId() - { - if (is_null($this->_entityTypeId)) { - $this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId(); - } - return $this->_entityTypeId; - } - - /** - * Retrieve Product Attributes Used in Catalog Product listing - * - * @return array - */ - public function getAttributesUsedInListing() { - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getTable('eav/attribute'))) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'main_table.attribute_id = additional_table.attribute_id' - ) - ->joinLeft( - array('al' => $this->getTable('eav/attribute_label')), - 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(), - array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)')) - ) - ->where('main_table.entity_type_id=?', $this->getEntityTypeId()) - ->where('additional_table.used_in_product_listing=?', 1); - return $this->_getReadAdapter()->fetchAll($select); - } - - /** - * Retrieve Used Product Attributes for Catalog Product Listing Sort By - * - * @return array - */ - public function getAttributesUsedForSortBy() { - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getTable('eav/attribute'))) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'main_table.attribute_id = additional_table.attribute_id', - array() - ) - ->joinLeft( - array('al' => $this->getTable('eav/attribute_label')), - 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(), - array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)')) - ) - ->where('main_table.entity_type_id=?', $this->getEntityTypeId()) - ->where('additional_table.used_for_sort_by=?', 1); - return $this->_getReadAdapter()->fetchAll($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php index 0dfabd17aa..7596c69f20 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,78 +32,7 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute + extends Mage_Catalog_Model_Resource_Layer_Filter_Attribute { - /** - * Initialize connection and define main table name - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_eav', 'entity_id'); - } - - /** - * Apply attribute filter to product collection - * - * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter - * @param int $value - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute - */ - public function applyFilterToCollection($filter, $value) - { - $collection = $filter->getLayer()->getProductCollection(); - $attribute = $filter->getAttributeModel(); - $connection = $this->_getReadAdapter(); - $tableAlias = $attribute->getAttributeCode() . '_idx'; - $conditions = array( - "{$tableAlias}.entity_id = e.entity_id", - $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), - $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), - $connection->quoteInto("{$tableAlias}.value = ?", $value) - ); - - $collection->getSelect()->join( - array($tableAlias => $this->getMainTable()), - join(' AND ', $conditions), - array() - ); - - return $this; - } - - /** - * Retrieve array with products counts per attribute option - * - * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter - * @return array - */ - public function getCount($filter) - { - // clone select from collection with filters - $select = clone $filter->getLayer()->getProductCollection()->getSelect(); - // reset columns, order and limitation conditions - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - $connection = $this->_getReadAdapter(); - $attribute = $filter->getAttributeModel(); - $tableAlias = $attribute->getAttributeCode() . '_idx'; - $conditions = array( - "{$tableAlias}.entity_id = e.entity_id", - $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), - $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()), - ); - - $select - ->join( - array($tableAlias => $this->getMainTable()), - join(' AND ', $conditions), - array('value', 'count' => "COUNT({$tableAlias}.entity_id)")) - ->group("{$tableAlias}.value"); - - return $connection->fetchPairs($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Decimal.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Decimal.php index abc424b6ae..0f5a04f16d 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Decimal.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Decimal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,125 +32,7 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Decimal extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Decimal + extends Mage_Catalog_Model_Resource_Layer_Filter_Decimal { - /** - * Initialize connection and define main table name - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_eav_decimal', 'entity_id'); - } - - /** - * Apply attribute filter to product collection - * - * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter - * @param float $range - * @param int $index - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Decimal - */ - public function applyFilterToCollection($filter, $range, $index) - { - $collection = $filter->getLayer()->getProductCollection(); - $attribute = $filter->getAttributeModel(); - $connection = $this->_getReadAdapter(); - $tableAlias = $attribute->getAttributeCode() . '_idx'; - $conditions = array( - "{$tableAlias}.entity_id = e.entity_id", - $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), - $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()) - ); - - $collection->getSelect()->join( - array($tableAlias => $this->getMainTable()), - join(' AND ', $conditions), - array() - ); - - $collection->getSelect() - ->where("{$tableAlias}.value >= ?", ($range * ($index - 1))) - ->where("{$tableAlias}.value < ?", ($range * $index)); - - return $this; - } - - /** - * Retrieve array of minimal and maximal values - * - * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter - * @return array - */ - public function getMinMax($filter) - { - $select = $this->_getSelect($filter); - $adapter = $this->_getReadAdapter(); - - $select->columns(array( - 'min_value' => new Zend_Db_Expr('MIN(decimal_index.value)'), - 'max_value' => new Zend_Db_Expr('MAX(decimal_index.value)'), - )); - - $result = $adapter->fetchRow($select); - - return array($result['min_value'], $result['max_value']); - } - - /** - * Retrieve clean select with joined index table - * - * Joined table has index - * - * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter - * @return Varien_Db_Select - */ - protected function _getSelect($filter) - { - $collection = $filter->getLayer()->getProductCollection(); - - // clone select from collection with filters - $select = clone $collection->getSelect(); - // reset columns, order and limitation conditions - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - $attributeId = $filter->getAttributeModel()->getId(); - $storeId = $collection->getStoreId(); - - $select->join( - array('decimal_index' => $this->getMainTable()), - "e.entity_id=decimal_index.entity_id AND decimal_index.attribute_id={$attributeId}" - . " AND decimal_index.store_id={$storeId}", - array() - ); - - return $select; - } - - /** - * Retrieve array with products counts per range - * - * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter - * @param int $range - * @return array - */ - public function getCount($filter, $range) - { - $select = $this->_getSelect($filter); - $adapter = $this->_getReadAdapter(); - - $countExpr = new Zend_Db_Expr("COUNT(*)"); - $rangeExpr = new Zend_Db_Expr("FLOOR(decimal_index.value / {$range}) + 1"); - - $select->columns(array( - 'range' => $rangeExpr, - 'count' => $countExpr - )); - $select->group('range'); - - return $adapter->fetchPairs($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Price.php index 6169ba56aa..493e5a230c 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Price.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,160 +32,6 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Price extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Price extends Mage_Catalog_Model_Resource_Layer_Filter_Price { - /** - * Initialize connection and define main table name - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_price', 'entity_id'); - } - - /** - * Retrieve joined price index table alias - * - * @return string - */ - protected function _getIndexTableAlias() - { - return 'price_index'; - } - - /** - * Retrieve clean select with joined price index table - * - * @param Mage_Catalog_Model_Layer_Filter_Price $filter - * @return Varien_Db_Select - */ - protected function _getSelect($filter) - { - $collection = $filter->getLayer()->getProductCollection(); - $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); - - // clone select from collection with filters - $select = clone $collection->getSelect(); - // reset columns, order and limitation conditions - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - return $select; - } - - /** - * Prepare response object and dispatch prepare price event - * - * Return response object - * - * @param Mage_Catalog_Model_Layer_Filter_Price $filter - * @param Varien_Db_Select $select - * @return Varien_Object - */ - protected function _dispatchPreparePriceEvent($filter, $select) - { - // prepare response object for event - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - // prepare event arguments - $eventArgs = array( - 'select' => $select, - 'table' => $this->_getIndexTableAlias(), - 'store_id' => $filter->getStoreId(), - 'response_object' => $response - ); - - /** - * @deprecated since 1.3.2.2 - */ - Mage::dispatchEvent('catalogindex_prepare_price_select', $eventArgs); - - /** - * @since 1.4 - */ - Mage::dispatchEvent('catalog_prepare_price_select', $eventArgs); - - return $response; - } - - /** - * Retrieve maximal price for attribute - * - * @param Mage_Catalog_Model_Layer_Filter_Price $filter - * @return float - */ - public function getMaxPrice($filter) - { - $select = $this->_getSelect($filter); - $connection = $this->_getReadAdapter(); - $response = $this->_dispatchPreparePriceEvent($filter, $select); - - $table = $this->_getIndexTableAlias(); - - $additional = join('', $response->getAdditionalCalculations()); - $maxPriceExpr = new Zend_Db_Expr("MAX({$table}.min_price {$additional})"); - - $select->columns(array($maxPriceExpr)); - - return $connection->fetchOne($select) * $filter->getCurrencyRate(); - } - - /** - * Retrieve array with products counts per price range - * - * @param Mage_Catalog_Model_Layer_Filter_Price $filter - * @param int $range - * @return array - */ - public function getCount($filter, $range) - { - $select = $this->_getSelect($filter); - $connection = $this->_getReadAdapter(); - $response = $this->_dispatchPreparePriceEvent($filter, $select); - $table = $this->_getIndexTableAlias(); - - $additional = join('', $response->getAdditionalCalculations()); - $rate = $filter->getCurrencyRate(); - $countExpr = new Zend_Db_Expr('COUNT(*)'); - $rangeExpr = new Zend_Db_Expr("FLOOR((({$table}.min_price {$additional}) * {$rate}) / {$range}) + 1"); - - $select->columns(array( - 'range' => $rangeExpr, - 'count' => $countExpr - )); - $select->group('range'); - - return $connection->fetchPairs($select); - } - - /** - * Apply attribute filter to product collection - * - * @param Mage_Catalog_Model_Layer_Filter_Price $filter - * @param int $range - * @param int $index the range factor - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute - */ - public function applyFilterToCollection($filter, $range, $index) - { - $collection = $filter->getLayer()->getProductCollection(); - $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); - - $select = $collection->getSelect(); - $response = $this->_dispatchPreparePriceEvent($filter, $select); - - $table = $this->_getIndexTableAlias(); - $additional = join('', $response->getAdditionalCalculations()); - $rate = $filter->getCurrencyRate(); - $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); - - $select - ->where($priceExpr . ' >= ?', ($range * ($index - 1))) - ->where($priceExpr . ' < ?', ($range * $index)); - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php index 4ea949a5e2..ee9c92f849 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product entity resource model * @@ -31,537 +32,18 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product extends Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product extends Mage_Catalog_Model_Resource_Product { - protected $_productWebsiteTable; - protected $_productCategoryTable; - - /** - * Initialize resource - */ - public function __construct() - { - parent::__construct(); - $resource = Mage::getSingleton('core/resource'); - $this->setType('catalog_product') - ->setConnection('catalog_read', 'catalog_write'); - $this->_productWebsiteTable = $resource->getTableName('catalog/product_website'); - $this->_productCategoryTable= $resource->getTableName('catalog/category_product'); - } - - /** - * Default product attributes - * - * @return array - */ - protected function _getDefaultAttributes() - { - return array('entity_id', 'entity_type_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at'); - } - - /** - * Retrieve product website identifiers - * - * @param Mage_Catalog_Model_Product|int $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - public function getWebsiteIds($product) - { - if ($product instanceof Mage_Catalog_Model_Product) { - $productId = $product->getId(); - } else { - $productId = $product; - } - - $select = $this->_getWriteAdapter()->select() - ->from($this->_productWebsiteTable, 'website_id') - ->where('product_id = ?', $productId); - return $this->_getWriteAdapter()->fetchCol($select); - } - - /** - * Retrieve product website identifiers by product identifiers - * - * @param array $productIds - * @return array - */ - public function getWebsiteIdsByProductIds($productIds) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->_productWebsiteTable, array('product_id', 'website_ids' =>'GROUP_CONCAT(website_id)')) - ->where('product_id IN (?)', $productIds) - ->group('product_id'); - - return $this->_getWriteAdapter()->fetchAll($select); - } /** - * Retrieve product category identifiers + * Retrieve product entities info * - * @param Mage_Catalog_Model_Product $product * @return array */ - public function getCategoryIds($product) + public function getProductEntitiesInfo() { $select = $this->_getReadAdapter()->select() - ->from($this->_productCategoryTable, 'category_id') - ->where('product_id=?', $product->getId()); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Get product identifier by sku - * - * @param string $sku - * @return int|false - */ - public function getIdBySku($sku) - { - return $this->_getReadAdapter()->fetchOne('select entity_id from '.$this->getEntityTable().' where sku=?',$sku); - } - - /** - * Process product data before save - * - * @param Varien_Object $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - protected function _beforeSave(Varien_Object $object) - { - /** - * Try detect product id by sku if id is not declared - */ - if (!$object->getId() && $object->getSku()) { - $object->setId($this->getIdBySku($object->getSku())); - } - - /** - * Check if declared category ids in object data. - */ - if ($object->hasCategoryIds()) { - $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds( - $object->getCategoryIds() - ); - $object->setCategoryIds($categoryIds); - } - - return parent::_beforeSave($object); - } - - /** - * Save data related with product - * - * @param Varien_Object $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - protected function _afterSave(Varien_Object $product) - { - $this->_saveWebsiteIds($product) - ->_saveCategories($product) - //->refreshIndex($product) - ; - - parent::_afterSave($product); - return $this; - } - - /** - * Save product website relations - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - protected function _saveWebsiteIds($product) - { - $websiteIds = $product->getWebsiteIds(); - $oldWebsiteIds = array(); - - $product->setIsChangedWebsites(false); - - $select = $this->_getWriteAdapter()->select() - ->from($this->_productWebsiteTable) - ->where('product_id=?', $product->getId()); - $query = $this->_getWriteAdapter()->query($select); - while ($row = $query->fetch()) { - $oldWebsiteIds[] = $row['website_id']; - } - - $insert = array_diff($websiteIds, $oldWebsiteIds); - $delete = array_diff($oldWebsiteIds, $websiteIds); - - if (!empty($insert)) { - foreach ($insert as $websiteId) { - $this->_getWriteAdapter()->insert($this->_productWebsiteTable, array( - 'product_id' => $product->getId(), - 'website_id' => $websiteId - )); - } - } - - if (!empty($delete)) { - foreach ($delete as $websiteId) { - $this->_getWriteAdapter()->delete($this->_productWebsiteTable, array( - $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()), - $this->_getWriteAdapter()->quoteInto('website_id=?', $websiteId) - )); - } - } - - if (!empty($insert) || !empty($delete)) { - $product->setIsChangedWebsites(true); - } - - return $this; - } - - /** - * Save product category relations - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - protected function _saveCategories(Varien_Object $object) - { - /** - * If category ids data is not declared we haven't do manipulations - */ - if (!$object->hasCategoryIds()) { - return $this; - } - $categoryIds = $object->getCategoryIds(); - $oldCategoryIds = $this->getCategoryIds($object); - - $object->setIsChangedCategories(false); - - $insert = array_diff($categoryIds, $oldCategoryIds); - $delete = array_diff($oldCategoryIds, $categoryIds); - - $write = $this->_getWriteAdapter(); - if (!empty($insert)) { - $data = array(); - foreach ($insert as $categoryId) { - if (empty($categoryId)) { - continue; - } - $data[] = array( - 'category_id' => (int)$categoryId, - 'product_id' => $object->getId(), - 'position' => 1 - ); - } - if ($data) { - $write->insertMultiple($this->_productCategoryTable, $data); - } - } - - if (!empty($delete)) { - $where = join(' AND ', array( - $write->quoteInto('product_id=?', $object->getId()), - $write->quoteInto('category_id IN(?)', $delete) - )); - $write->delete($this->_productCategoryTable, $where); - } - - if (!empty($insert) || !empty($delete)) { - $object->setAffectedCategoryIds(array_merge($insert, $delete)); - $object->setIsChangedCategories(true); - } - - return $this; - } - - /** - * Refresh Product Enabled Index - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - public function refreshIndex($product) - { - /** - * Ids of all categories where product is assigned (not related with store) - */ - $categoryIds = $product->getCategoryIds(); - - /** - * Clear previos index data related with product - */ - $this->_getWriteAdapter()->delete( - $this->getTable('catalog/category_product_index'), - $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()) - ); - - if (!empty($categoryIds)) { - $categoriesSelect = $this->_getWriteAdapter()->select() - ->from($this->getTable('catalog/category')) - ->where('entity_id IN (?)', $categoryIds); - $categoriesInfo = $this->_getWriteAdapter()->fetchAll($categoriesSelect); - - - $indexCategoryIds = array(); - foreach ($categoriesInfo as $categoryInfo) { - $ids = explode('/', $categoryInfo['path']); - $ids[] = $categoryInfo['entity_id']; - $indexCategoryIds = array_merge($indexCategoryIds, $ids); - } - - $indexCategoryIds = array_unique($indexCategoryIds); - $indexProductIds = array($product->getId()); - Mage::getResourceSingleton('catalog/category') - ->refreshProductIndex($indexCategoryIds, $indexProductIds); - } - else { - $websites = $product->getWebsiteIds(); - if ($websites) { - $storeIds = array(); - foreach ($websites as $websiteId) { - $website = Mage::app()->getWebsite($websiteId); - $storeIds = array_merge($storeIds, $website->getStoreIds()); - } - Mage::getResourceSingleton('catalog/category') - ->refreshProductIndex(array(), array($product->getId()), $storeIds); - } - } - - /** - * Refresh enabled products index (visibility state) - */ - $this->refreshEnabledIndex(null, $product); - return $this; - } - - /** - * Refresh index for visibility of enabled product in store - * if store parameter is null - index will refreshed for all stores - * if product parameter is null - idex will be refreshed for all products - * - * @param Mage_Core_Model_Store $store - * @param Mage_Core_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - public function refreshEnabledIndex($store=null, $product=null) - { - $statusAttribute = $this->getAttribute('status'); - $visibilityAttribute = $this->getAttribute('visibility'); - $statusAttributeId = $statusAttribute->getId(); - $visibilityAttributeId = $visibilityAttribute->getId(); - $statusTable = $statusAttribute->getBackend()->getTable(); - $visibilityTable = $visibilityAttribute->getBackend()->getTable(); - - $indexTable = $this->getTable('catalog/product_enabled_index'); - if (is_null($store) && is_null($product)) { - Mage::throwException( - Mage::helper('catalog')->__('To reindex the enabled product(s), the store or product must be specified.') - ); - } elseif (is_null($product) || is_array($product)) { - $storeId = $store->getId(); - $websiteId = $store->getWebsiteId(); - - $productsCondition = ''; - $deleteCondition = ''; - if (is_array($product) && !empty($product)) { - $productsCondition = $this->_getWriteAdapter()->quoteInto( - ' AND t_v_default.entity_id IN (?)', - $product - ); - $deleteCondition = $this->_getWriteAdapter()->quoteInto(' AND product_id IN (?)', $product); - } - $this->_getWriteAdapter()->delete($indexTable, 'store_id='.$storeId.$deleteCondition); - $query = "INSERT INTO $indexTable - SELECT - t_v_default.entity_id, {$storeId}, IF(t_v.value_id>0, t_v.value, t_v_default.value) - FROM - {$visibilityTable} AS t_v_default - INNER JOIN {$this->getTable('catalog/product_website')} AS w - ON w.product_id=t_v_default.entity_id AND w.website_id={$websiteId} - LEFT JOIN {$visibilityTable} AS `t_v` - ON (t_v.entity_id = t_v_default.entity_id) - AND (t_v.attribute_id='{$visibilityAttributeId}') - AND (t_v.store_id='{$storeId}') - INNER JOIN {$statusTable} AS `t_s_default` - ON (t_s_default.entity_id = t_v_default.entity_id) - AND (t_s_default.attribute_id='{$statusAttributeId}') - AND t_s_default.store_id=0 - LEFT JOIN {$statusTable} AS `t_s` - ON (t_s.entity_id = t_v_default.entity_id) - AND (t_s.attribute_id='{$statusAttributeId}') - AND (t_s.store_id='{$storeId}') - WHERE - t_v_default.attribute_id='{$visibilityAttributeId}' - AND t_v_default.store_id=0{$productsCondition} - AND (IF(t_s.value_id>0, t_s.value, t_s_default.value) = - ".Mage_Catalog_Model_Product_Status::STATUS_ENABLED.")"; - $this->_getWriteAdapter()->query($query); - } - elseif (is_null($store)) { - foreach ($product->getStoreIds() as $storeId) { - $store = Mage::app()->getStore($storeId); - $this->refreshEnabledIndex($store, $product); - } - } - else { - $productId = $product->getId(); - $storeId = $store->getId(); - $this->_getWriteAdapter()->delete($indexTable, 'product_id='.$productId.' AND store_id='.$storeId); - $query = "INSERT INTO $indexTable - SELECT - {$productId}, {$storeId}, IF(t_v.value_id>0, t_v.value, t_v_default.value) - FROM - {$visibilityTable} AS t_v_default - LEFT JOIN {$visibilityTable} AS `t_v` - ON (t_v.entity_id = t_v_default.entity_id) - AND (t_v.attribute_id='{$visibilityAttributeId}') - AND (t_v.store_id='{$storeId}') - INNER JOIN {$statusTable} AS `t_s_default` - ON (t_s_default.entity_id = t_v_default.entity_id) - AND (t_s_default.attribute_id='{$statusAttributeId}') - AND t_s_default.store_id=0 - LEFT JOIN {$statusTable} AS `t_s` - ON (t_s.entity_id = t_v_default.entity_id) - AND (t_s.attribute_id='{$statusAttributeId}') - AND (t_s.store_id='{$storeId}') - WHERE - t_v_default.entity_id={$productId} - AND t_v_default.attribute_id='{$visibilityAttributeId}' AND t_v_default.store_id=0 - AND (IF(t_s.value_id>0, t_s.value, t_s_default.value) = - ".Mage_Catalog_Model_Product_Status::STATUS_ENABLED.")"; - $this->_getWriteAdapter()->query($query); - } - - return $this; - } - - /** - * Get collection of product categories - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function getCategoryCollection($product) - { - $collection = Mage::getResourceModel('catalog/category_collection') - ->joinField('product_id', - 'catalog/category_product', - 'product_id', - 'category_id=entity_id', - null) - ->addFieldToFilter('product_id', (int) $product->getId()); - return $collection; - } - - /** - * Retrieve category ids where product is available - * - * @param Mage_Catalog_Model_Product $object - * @return array - */ - public function getAvailableInCategories($object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/category_product_index'), array('category_id')) - ->where('product_id=?', $object->getEntityId()); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Get default attribute source model - * - * @return string - */ - public function getDefaultAttributeSourceModel() - { - return 'eav/entity_attribute_source_table'; - } - - /** - * Validate all object's attributes against configuration - * - * @todo implement full validation process with errors returning which are ignoring now - * - * @param Varien_Object $object - * @return Varien_Object - */ - public function validate($object) - { -// $this->walkAttributes('backend/beforeSave', array($object)); -// return parent::validate($object); - parent::validate($object); - return $this; - } - - /** - * Check availability display product in category - * - * @param int $categoryId - * @return bool - */ - public function canBeShowInCategory($product, $categoryId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/category_product_index'), 'product_id') - ->where('product_id=?', $product->getId()) - ->where('category_id=?', $categoryId); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Duplicate product store values - * - * @param int $oldId - * @param int $newId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - public function duplicate($oldId, $newId) - { - $adapter = $this->_getWriteAdapter(); - $eavTables = array('datetime', 'decimal', 'int', 'text', 'varchar'); - - // duplicate EAV store values - foreach ($eavTables as $suffix) { - $tableName = $this->getTable('catalog_product_entity_' . $suffix); - $sql = 'REPLACE INTO `' . $tableName . '` ' - . 'SELECT NULL, `entity_type_id`, `attribute_id`, `store_id`, ' . $newId . ', `value`' - . 'FROM `' . $tableName . '` WHERE `entity_id`=' . $oldId . ' AND `store_id`>0'; - $adapter->query($sql); - } - - // set status as disabled - $statusAttribute = $this->getAttribute('status'); - $statusAttributeId = $statusAttribute->getAttributeId(); - $statusAttributeTable = $statusAttribute->getBackend()->getTable(); - $updateCond[] = 'store_id > 0'; - $updateCond[] = $adapter->quoteInto('entity_id = ?', $newId); - $updateCond[] = $adapter->quoteInto('attribute_id = ?', $statusAttributeId); - $adapter->update( - $statusAttributeTable, - array('value' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED), - $updateCond - ); - - return $this; - } - - /** - * Get SKU through product identifiers - * - * @param array $productIds - * @return array - */ - public function getProductsSku(array $productIds) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/product'), array('entity_id', 'sku')) - ->where('entity_id IN (?)', $productIds); + ->from($this->getTable('catalog/product'), array('entity_id', 'type_id', 'attribute_set_id', 'sku')); return $this->_getReadAdapter()->fetchAll($select); } - - /** - * @deprecated after 1.4.2.0 - * @param $object Mage_Catalog_Model_Product - * @return array - */ - public function getParentProductIds($object) - { - return array(); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Action.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Action.php index 555a5e0902..c3d2b111ea 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Action.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,62 +32,6 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Action extends Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Action extends Mage_Catalog_Model_Resource_Product_Action { - /** - * Intialize connection - * - */ - protected function _construct() - { - $resource = Mage::getSingleton('core/resource'); - $this->setType('catalog_product') - ->setConnection( - $resource->getConnection('catalog_read'), - $resource->getConnection('catalog_write') - ); - } - - /** - * Update attribute values for entity list per store - * - * @param array $entityIds - * @param array $attrData - * @param int $storeId - * @return Mage_Catalog_Model_Product_Action - */ - public function updateAttributes($entityIds, $attrData, $storeId) - { - $object = new Varien_Object(); - $object->setIdFieldName('entity_id') - ->setStoreId($storeId); - - $this->_getWriteAdapter()->beginTransaction(); - try { - foreach ($attrData as $attrCode => $value) { - $attribute = $this->getAttribute($attrCode); - if (!$attribute->getAttributeId()) { - continue; - } - - $i = 0; - foreach ($entityIds as $entityId) { - $object->setId($entityId); - // collect data for save - $this->_saveAttributeValue($object, $attribute, $value); - // save collected data every 1000 rows - if ($i % 1000 == 0) { - $this->_processAttributeValues(); - } - } - } - $this->_processAttributeValues(); - $this->_getWriteAdapter()->commit(); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Image.php index 71d6ab3530..b646217923 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Image.php @@ -20,49 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product image attribute backend * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team - */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Image - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image { - public function afterSave($object) - { - $value = $object->getData($this->getAttribute()->getName()); - - if (is_array($value) && !empty($value['delete'])) { - $object->setData($this->getAttribute()->getName(), ''); - $this->getAttribute()->getEntity() - ->saveAttribute($object, $this->getAttribute()->getName()); - return; - } - - try { - $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName()); - $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); - $uploader->setAllowRenameFiles(true); - $uploader->setFilesDispersion(true); - } - catch (Exception $e){ - return $this; - } - $uploader->save(Mage::getStoreConfig('system/filesystem/media') . '/catalog/product'); - - if ($fileName = $uploader->getUploadedFileName()) { - $object->setData($this->getAttribute()->getName(), $fileName); - $this->getAttribute()->getEntity() - ->saveAttribute($object, $this->getAttribute()->getName()); - - } - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Media.php index d55fb9bf98..dcb633ab18 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Media.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Media.php @@ -20,189 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog product media gallery attribute backend resource * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media + extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media { - /** - * Gallery db tables - */ - const GALLERY_TABLE = 'catalog/product_attribute_media_gallery'; - const GALLERY_VALUE_TABLE = 'catalog/product_attribute_media_gallery_value'; - const GALLERY_IMAGE_TABLE = 'catalog/product_attribute_media_gallery_image'; - - protected function _construct() - { - $this->_init(self::GALLERY_TABLE, 'value_id'); - } - - /** - * Load gallery images for product - * - * @param Mage_Catalog_Model_Product $product - * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object - * @return array - */ - public function loadGallery($product, $object) - { - // Select gallery images for product - $select = $this->_getReadAdapter()->select() - ->from( - array('main'=>$this->getMainTable()), - array('value_id', 'value AS file') - ) - ->joinLeft( - array('value'=>$this->getTable(self::GALLERY_VALUE_TABLE)), - 'main.value_id=value.value_id AND value.store_id='.(int)$product->getStoreId(), - array('label','position','disabled') - ) - ->joinLeft( // Joining default values - array('default_value'=>$this->getTable(self::GALLERY_VALUE_TABLE)), - 'main.value_id=default_value.value_id AND default_value.store_id=0', - array( - 'label_default' => 'label', - 'position_default' => 'position', - 'disabled_default' => 'disabled' - ) - ) - ->where('main.attribute_id = ?', $object->getAttribute()->getId()) - ->where('main.entity_id = ?', $product->getId()) - ->order('IF(value.position IS NULL, default_value.position, value.position) ASC'); - - $result = $this->_getReadAdapter()->fetchAll($select); - $this->_removeDuplicates($result); - return $result; - } - - protected function _removeDuplicates(&$result) - { - $fileToId = array(); - - foreach (array_keys($result) as $index) { - if (!isset($fileToId[$result[$index]['file']])) { - $fileToId[$result[$index]['file']] = $result[$index]['value_id']; - } elseif ($fileToId[$result[$index]['file']] != $result[$index]['value_id']) { - $this->deleteGallery($result[$index]['value_id']); - unset($result[$index]); - } - } - - $result = array_values($result); - return $this; - } - - /** - * Insert gallery value to db and retrive last id - * - * @param array $data - * @return interger - */ - public function insertGallery($data) - { - $this->_getWriteAdapter()->insert($this->getMainTable(), $data); - return $this->_getWriteAdapter()->lastInsertId(); - } - - /** - * Delete gallery value in db - * - * @param array|integer $valueId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media - */ - public function deleteGallery($valueId) - { - if (is_array($valueId) && count($valueId)>0) { - $condition = $this->_getWriteAdapter()->quoteInto('value_id IN(?) ', $valueId); - } elseif (!is_array($valueId)) { - $condition = $this->_getWriteAdapter()->quoteInto('value_id = ? ', $valueId); - } else { - return $this; - } - - $this->_getWriteAdapter()->delete($this->getMainTable(), $condition); - return $this; - } - - /** - * Insert gallery value for store to db - * - * @param array $data - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media - */ - public function insertGalleryValueInStore($data) - { - $this->_getWriteAdapter()->insert($this->getTable(self::GALLERY_VALUE_TABLE), $data); - return $this; - } - - /** - * Delete gallery value for store in db - * - * @param integer $valueId - * @param integer $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media - */ - public function deleteGalleryValueInStore($valueId, $storeId) - { - $this->_getWriteAdapter()->delete( - $this->getTable(self::GALLERY_VALUE_TABLE), - 'value_id = ' . (int)$valueId . ' AND store_id = ' . (int)$storeId - ); - - return $this; - } - - /** - * Duplicates gallery db values - * - * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object - * @param array $newFiles - * @param int $originalProductId - * @param int $newProductId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media - */ - public function duplicate($object, $newFiles, $originalProductId, $newProductId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('value_id', 'value')) - ->where('attribute_id = ?', $object->getAttribute()->getId()) - ->where('entity_id = ?', $originalProductId); - - $valueIdMap = array(); - // Duplicate main entries of gallery - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $data = array( - 'attribute_id' => $object->getAttribute()->getId(), - 'entity_id' => $newProductId, - 'value' => (isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value']) - ); - - $valueIdMap[$row['value_id']] = $this->insertGallery($data); - } - - if (count($valueIdMap) == 0) { - return $this; - } - - // Duplicate per store gallery values - $select = $this->_getReadAdapter()->select() - ->from($this->getTable(self::GALLERY_VALUE_TABLE)) - ->where('value_id IN(?)', array_keys($valueIdMap)); - - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $row['value_id'] = $valueIdMap[$row['value_id']]; - $this->insertGalleryValueInStore($row); - } - - return $this; - } -} // Class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media End +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php index f67cd26a43..6c7c64bb2e 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,156 +28,11 @@ /** * Catalog product tier price backend attribute model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice - extends Mage_Core_Model_Mysql4_Abstract + extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('catalog/product_attribute_tier_price', 'value_id'); - } - - /** - * Load Tier Prices for product - * - * @param int $productId - * @param int $websiteId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice - */ - public function loadPriceData($productId, $websiteId = null) - { - $adapter = $this->_getReadAdapter(); - $columns = array( - 'price_id' => $this->getIdFieldName(), - 'website_id' => 'website_id', - 'all_groups' => 'all_groups', - 'cust_group' => 'customer_group_id', - 'price_qty' => 'qty', - 'price' => 'value', - ); - $select = $adapter->select() - ->from($this->getMainTable(), $columns) - ->where('entity_id=?', $productId) - ->order('qty'); - if (!is_null($websiteId)) { - if ($websiteId == '0') { - $select->where('website_id=?', $websiteId); - } else { - $select->where('website_id IN(?)', array('0', $websiteId)); - } - } - - return $adapter->fetchAll($select); - } - - /** - * Delete Tier Prices for product - * - * @param int $productId - * @param int $websiteId - * @param int $priceId - * @return int The number of affected rows - */ - public function deletePriceData($productId, $websiteId = null, $priceId = null) - { - $adapter = $this->_getWriteAdapter(); - $conds = array( - $adapter->quoteInto('entity_id=?', $productId) - ); - if (!is_null($websiteId)) { - $conds[] = $adapter->quoteInto('website_id=?', $websiteId); - } - if (!is_null($priceId)) { - $conds[] = $adapter->quoteInto($this->getIdFieldName() . '=?', $priceId); - } - $where = join(' AND ', $conds); - - return $adapter->delete($this->getMainTable(), $where); - } - - /** - * Save tier price object - * - * @param Varien_Object $priceObject - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice - */ - public function savePriceData(Varien_Object $priceObject) - { - $adapter = $this->_getWriteAdapter(); - $data = $this->_prepareDataForTable($priceObject, $this->getMainTable()); - if (!empty($data[$this->getIdFieldName()])) { - $where = $adapter->quoteInto($this->getIdFieldName() . '=?', $data[$this->getIdFieldName()]); - unset($data[$this->getIdFieldName()]); - $adapter->update($this->getMainTable(), $data, $where); - } else { - $adapter->insert($this->getMainTable(), $data); - } - return $this; - } - - /** - * Load product tier prices - * - * @param Mage_Catalog_Model_Product $product - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @deprecated since 1.3.2.3 - * @return array - */ - public function loadProductPrices($product, $attribute) - { - $websiteId = null; - if ($attribute->isScopeGlobal()) { - $websiteId = 0; - } else if ($product->getStoreId()) { - $websiteId = Mage::app()->getStore($product->getStoreId())->getWebsiteId(); - } - - return $this->loadPriceData($product->getId(), $websiteId); - } - - /** - * Delete product tier price data from storage - * - * @param Mage_Catalog_Model_Product $product - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @deprecated since 1.3.2.3 - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice - */ - public function deleteProductPrices($product, $attribute) - { - $websiteId = null; - if (!$attribute->isScopeGlobal()) { - $storeId = $product->getProductId(); - if ($storeId) { - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - } - } - - $this->deletePriceData($product->getId(), $websiteId); - - return $this; - } - - /** - * Insert product Tier Price to storage - * - * @param Mage_Catalog_Model_Product $product - * @param array $data - * @deprecated since 1.3.2.3 - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice - */ - public function insertProductPrice($product, $data) - { - $priceObject = new Varien_Object($data); - $priceObject->setEntityId($product->getId()); - - return $this->savePriceData($priceObject); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Urlkey.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Urlkey.php index 2aefdbd4e6..f8f455bbff 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Urlkey.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Urlkey.php @@ -20,39 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product url key attribute backend * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ - -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Urlkey extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Urlkey + extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey { - public function beforeSave($object) - { - $attributeName = $this->getAttribute()->getName(); - - $urlKey = $object->getData($attributeName); - if ($urlKey=='') { - $urlKey = $object->getName(); - } - - $object->setData($attributeName, $object->formatUrlKey($urlKey)); - - return $this; - } - - public function afterSave($object) - { - if ($object->dataHasChangedFor($this->getAttribute()->getName())) { - Mage::getSingleton('catalog/url')->refreshProductRewrites(null, $object, true); - } - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Collection.php index 9dc57d713c..f8482c7dfe 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,161 +28,11 @@ /** * Catalog product EAV additional attribute resource collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection extends Mage_Eav_Model_Mysql4_Entity_Attribute_Collection +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection + extends Mage_Catalog_Model_Resource_Product_Attribute_Collection { - /** - * Resource model initialization - */ - public function _construct() - { - $this->_init('catalog/resource_eav_attribute', 'eav/entity_attribute'); - } - - protected function _initSelect() - { - $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable())) - ->where('main_table.entity_type_id=?', Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId()) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'additional_table.attribute_id=main_table.attribute_id' - ); - return $this; - } - - /** - * Specify attribute entity type filter - * - * @param int $typeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function setEntityTypeFilter($typeId) - { - return $this; - } - - /** - * Return array of fields to load attribute values - * - * @return array - */ - protected function _getLoadDataFields() - { - $fields = array_merge( - parent::_getLoadDataFields(), - array( - 'additional_table.is_global', - 'additional_table.is_html_allowed_on_front', - 'additional_table.is_wysiwyg_enabled' - ) - ); - - return $fields; - } - - /** - * Remove price from attribute list - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function removePriceFilter() - { - $this->getSelect()->where('main_table.attribute_code <> ?', 'price'); - return $this; - } - - /** - * Specify "is_visible_in_advanced_search" filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addDisplayInAdvancedSearchFilter() - { - $this->getSelect()->where('additional_table.is_visible_in_advanced_search = ?', 1); - return $this; - } - - /** - * Specify "is_filterable" filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addIsFilterableFilter() - { - $this->getSelect()->where('additional_table.is_filterable > ?', 0); - return $this; - } - - /** - * Add filterable in search filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addIsFilterableInSearchFilter() - { - $this->getSelect()->where('additional_table.is_filterable_in_search > ?', 0); - return $this; - } - - /** - * Specify filter by "is_visible" field - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addVisibleFilter() - { - $this->getSelect()->where('additional_table.is_visible = ?', 1); - return $this; - } - - /** - * Specify "is_searchable" filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addIsSearchableFilter() - { - $this->getSelect()->where('additional_table.is_searchable = ?', 1); - return $this; - } - - /** - * Specify filter for attributes that have to be indexed using advanced index - * - * @param bool $addRequiredCodes - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addToIndexFilter($addRequiredCodes = false) - { - $requiredCodesCondition = ($addRequiredCodes) - ? $this->getConnection()->quoteInto(' OR main_table.attribute_code IN (?)', array('status', 'visibility')) - : ''; - - $this->getSelect()->where('( - additional_table.is_searchable = 1 OR - additional_table.is_visible_in_advanced_search = 1 OR - additional_table.is_filterable > 0 OR - additional_table.is_filterable_in_search = 1'. - $requiredCodesCondition . - ')'); - - return $this; - } - - /** - * Specify filter for attributes used in quick search - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection - */ - public function addSearchableAttributeFilter() - { - $this->getSelect()->where( - 'additional_table.is_searchable = 1 OR '. - $this->getConnection()->quoteInto('main_table.attribute_code IN (?)', array('status', 'visibility')) - ); - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Image.php index 9872fee66d..f2bd5aa734 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Image.php @@ -20,26 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product image attribute frontend * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team - */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Frontend_Image extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Frontend_Image + extends Mage_Catalog_Model_Resource_Product_Attribute_Frontend_Image { - public function getUrl($object) - { - $url = false; - if ($image = $object->getData($this->getAttribute()->getAttributeCode())) { - $url = Mage::getBaseUrl('media').'catalog/product/'.$image; - } - return $url; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Tierprice.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Tierprice.php index 793f2e5579..841b643d05 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Tierprice.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Frontend/Tierprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,11 +28,11 @@ /** * Catalog product attribute tier price frontend model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Frontend_Tierprice extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Frontend_Tierprice + extends Mage_Catalog_Model_Resource_Product_Attribute_Frontend_Tierprice { - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php index 457986df47..27e245a592 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php @@ -20,1842 +20,18 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Collection_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection { - /** - * Catalog Product Flat is enabled cache per store - * - * @var array - */ - protected $_flatEnabled = array(); - - /** - * Product websites table name - * - * @var string - */ - protected $_productWebsiteTable; - - /** - * Product categories table name - * - * @var string - */ - protected $_productCategoryTable; - - /** - * Is add URL rewrites to collection flag - * - * @var bool - */ - protected $_addUrlRewrite = false; - - /** - * Add URL rewrite for category - * - * @var int - */ - protected $_urlRewriteCategory = ''; - - /** - * Is add minimal price to product collection flag - * - * @var bool - */ - protected $_addMinimalPrice = false; - - /** - * Is add final price to product collection flag - * - * @var unknown_type - */ - protected $_addFinalPrice = false; - - /** - * Cache for all ids - * - * @var array - */ - protected $_allIdsCache = null; - - /** - * Is add tax percents to product collection flag - * - * @var bool - */ - protected $_addTaxPercents = false; - - /** - * Product limitation filters - * - * Allowed filters - * store_id int; - * category_id int; - * category_is_anchor int; - * visibility array|int; - * website_ids array|int; - * store_table string; - * use_price_index bool; join price index table flag - * customer_group_id int; required for price; customer group limitation for price - * website_id int; required for price; website limitation for price - * - * @var array - */ - protected $_productLimitationFilters = array(); - - /** - * Category product count select - * - * @var Zend_Db_Select - */ - protected $_productCountSelect = null; - - /** - * @var bool - */ - protected $_isWebsiteFilter = false; - - /** - * Additional field filters, applied in _productLimitationJoinPrice() - * - * @var array - */ - protected $_priceDataFieldFilters = array(); - - /** - * Map of price fields - * - * @var array - */ - protected $_map = array('fields' => array( - 'price' => 'price_index.price', - 'final_price' => 'price_index.final_price', - 'min_price' => 'price_index.min_price', - 'max_price' => 'price_index.max_price', - 'tier_price' => 'price_index.tier_price', - 'special_price' => 'price_index.special_price', - )); - - /** - * Retrieve Catalog Product Flat Helper object - * - * @return Mage_Catalog_Helper_Product_Flat - */ - public function getFlatHelper() - { - return Mage::helper('catalog/product_flat'); - } - - /** - * Retrieve is flat enabled flag - * Return alvays false if magento run admin - * - * @return bool - */ - public function isEnabledFlat() - { - if (Mage::app()->getStore()->isAdmin()) { - return false; - } - if (!isset($this->_flatEnabled[$this->getStoreId()])) { - $this->_flatEnabled[$this->getStoreId()] = $this->getFlatHelper() - ->isEnabled($this->getStoreId()); - } - return $this->_flatEnabled[$this->getStoreId()]; - } - - /** - * Initialize resources - * - */ - protected function _construct() - { - if ($this->isEnabledFlat()) { - $this->_init('catalog/product', 'catalog/product_flat'); - } - else { - $this->_init('catalog/product'); - } - $this->_initTables(); - } - - /** - * Define product website and category product tables - */ - protected function _initTables() - { - $this->_productWebsiteTable = $this->getResource()->getTable('catalog/product_website'); - $this->_productCategoryTable= $this->getResource()->getTable('catalog/category_product'); - } - - /** - * Standard resource collection initalization - * - * @param string $model - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _init($model, $entityModel=null) - { - if ($this->isEnabledFlat()) { - $entityModel = 'catalog/product_flat'; - } - - return parent::_init($model, $entityModel); - } - - /** - * Prepare static entity fields - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _prepareStaticFields() - { - if ($this->isEnabledFlat()) { - return $this; - } - return parent::_prepareStaticFields(); - } - - /** - * Retrieve collection empty item - * Redeclared for specifying id field name without getting resource model inside model - * - * @return Varien_Object - */ - public function getNewEmptyItem() - { - $object = parent::getNewEmptyItem(); - if ($this->isEnabledFlat()) { - $object->setIdFieldName($this->getEntity()->getIdFieldName()); - } - return $object; - } - - /** - * Set entity to use for attributes - * - * @param Mage_Eav_Model_Entity_Abstract $entity - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function setEntity($entity) - { - if ($this->isEnabledFlat() && ($entity instanceof Mage_Core_Model_Mysql4_Abstract)) { - $this->_entity = $entity; - return $this; - } - return parent::setEntity($entity); - } - - /** - * Set Store scope for collection - * - * @param mixed $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function setStore($store) - { - parent::setStore($store); - if ($this->isEnabledFlat()) { - $this->getEntity()->setStoreId($this->getStoreId()); - } - return $this; - } - - /** - * Initialize collection select - * Redeclared for remove entity_type_id condition - * in catalog_product_entity we store just products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _initSelect() - { - if ($this->isEnabledFlat()) { - $this->getSelect() - ->from(array('e' => $this->getEntity()->getFlatTableName()), null) - ->columns(array('status' => new Zend_Db_Expr(Mage_Catalog_Model_Product_Status::STATUS_ENABLED))); - $this->addAttributeToSelect(array('entity_id', 'type_id', 'attribute_set_id')); - if ($this->getFlatHelper()->isAddChildData()) { - $this->getSelect() - ->where('e.is_child=?', 0); - $this->addAttributeToSelect(array('child_id', 'is_child')); - } - } - else { - $this->getSelect()->from(array('e'=>$this->getEntity()->getEntityTable())); - } - return $this; - } - - /** - * Load attributes into loaded entities - * - * @param bool $printQuery - * @param bool $logQuery - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function _loadAttributes($printQuery = false, $logQuery = false) - { - if ($this->isEnabledFlat()) { - return $this; - } - return parent::_loadAttributes($printQuery, $logQuery); - } - - /** - * Add attribute to entities in collection - * - * If $attribute=='*' select all attributes - * - * @param array|string|integer|Mage_Core_Model_Config_Element $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addAttributeToSelect($attribute, $joinType = false) - { - if ($this->isEnabledFlat()) { - if (!is_array($attribute)) { - $attribute = array($attribute); - } - foreach ($attribute as $attributeCode) { - if ($attributeCode == '*') { - foreach ($this->getEntity()->getAllTableColumns() as $column) { - $this->getSelect()->columns('e.'.$column); - $this->_selectAttributes[$column] = $column; - $this->_staticFields[$column] = $column; - } - } - else { - if ($columns = $this->getEntity()->getAttributeForSelect($attributeCode)) { - foreach ($columns as $alias => $column) { - $this->getSelect()->columns(array($alias => 'e.'.$column)); - $this->_selectAttributes[$column] = $column; - $this->_staticFields[$column] = $column; - } - } - } - } - return $this; - } - return parent::addAttributeToSelect($attribute, $joinType); - } - - /** - * Add tax class id attribute to select and join price rules data if needed - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _beforeLoad() - { -// if ($this->_addFinalPrice) { -// $this->_joinPriceRules(); -// } - Mage::dispatchEvent('catalog_product_collection_load_before', array('collection'=>$this)); - - return parent::_beforeLoad(); - } - - /** - * Processing collection items after loading - * Adding url rewrites, minimal prices, final prices, tax percents - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _afterLoad() - { - if ($this->_addUrlRewrite) { - $this->_addUrlRewrite($this->_urlRewriteCategory); - } -// if ($this->_addFinalPrice) { -// $this->_addFinalPrice(); -// } - - $this->_prepareUrlDataObject(); - - if (count($this) > 0) { - Mage::dispatchEvent('catalog_product_collection_load_after', array('collection'=>$this)); - } - - foreach ($this as $product) { - if ($product->isRecurring() && $profile = $product->getRecurringProfile()) { - $product->setRecurringProfile(unserialize($profile)); - } - // Mage::getSilgleton('catalog/product_attribute_backend_recurring')->afterLoad($product); - } - - return $this; - } - - /** - * Prepare Url Data object - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _prepareUrlDataObject() - { - $objects = array(); - /* @var $item Mage_Catalog_Model_Product */ - foreach ($this->_items as $item) { - if ($this->getFlag('do_not_use_category_id')) { - $item->setDoNotUseCategoryId(true); - } - if (!$item->isVisibleInSiteVisibility() && $item->getItemStoreId()) { - $objects[$item->getEntityId()] = $item->getItemStoreId(); - } - } - - if ($objects && $this->hasFlag('url_data_object')) { - $objects = Mage::getResourceSingleton('catalog/url') - ->getRewriteByProductStore($objects); - foreach ($this->_items as $item) { - if (isset($objects[$item->getEntityId()])) { - $object = new Varien_Object($objects[$item->getEntityId()]); - $item->setUrlDataObject($object); - } - } - } - - return $this; - } - - /** - * Add collection filters by identifiers - * - * @param mixed $productId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addIdFilter($productId, $exclude = false) - { - if (empty($productId)) { - $this->_setIsLoaded(true); - return $this; - } - if (is_array($productId)) { - if (!empty($productId)) { - if ($exclude) { - $condition = array('nin'=>$productId); - } else { - $condition = array('in'=>$productId); - } - } - else { - $condition = ''; - } - } - else { - if ($exclude) { - $condition = array('neq'=>$productId); - } else { - $condition = $productId; - } - } - $this->addFieldToFilter('entity_id', $condition); - return $this; - } - - /** - * Adding product website names to result collection - * Add for each product websites information - * - * @return Mage_Catalog_Model_Entity_Product_Collection - */ - public function addWebsiteNamesToResult() - { - $productStores = array(); - foreach ($this as $product) { - $productWebsites[$product->getId()] = array(); - } - - if (!empty($productWebsites)) { - $select = $this->getConnection()->select() - ->from(array('product_website'=>$this->_productWebsiteTable)) - ->join( - array('website'=>$this->getResource()->getTable('core/website')), - 'website.website_id=product_website.website_id', - array('name')) - ->where($this->getConnection()->quoteInto( - 'product_website.product_id IN (?)', - array_keys($productWebsites)) - ) - ->where('website.website_id>0'); - - $data = $this->getConnection()->fetchAll($select); - foreach ($data as $row) { - $productWebsites[$row['product_id']][] = $row['website_id']; - } - } - - foreach ($this as $product) { - if (isset($productWebsites[$product->getId()])) { - $product->setData('websites', $productWebsites[$product->getId()]); - } - } - return $this; - } - - /** - * Add store availability filter. Include availability product - * for store website - * - * @param mixed $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addStoreFilter($store=null) - { - if (is_null($store)) { - $store = $this->getStoreId(); - } - $store = Mage::app()->getStore($store); - - if (!$store->isAdmin()) { - $this->setStoreId($store); - $this->_productLimitationFilters['store_id'] = $store->getId(); - $this->_applyProductLimitations(); - } - - return $this; - } - - /** - * Add website filter to collection - * - * @param Mage_Core_Model_Website|int|string|array $website - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addWebsiteFilter($websites = null) - { - if (!is_array($websites)) { - $websites = array(Mage::app()->getWebsite($websites)->getId()); - } - - $this->_productLimitationFilters['website_ids'] = $websites; - $this->_applyProductLimitations(); - - return $this; - } - - /** - * Specify category filter for product collection - * - * @param Mage_Catalog_Model_Category $category - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addCategoryFilter(Mage_Catalog_Model_Category $category) - { - $this->_productLimitationFilters['category_id'] = $category->getId(); - if ($category->getIsAnchor()) { - unset($this->_productLimitationFilters['category_is_anchor']); - } else { - $this->_productLimitationFilters['category_is_anchor'] = 1; - } - - if ($this->getStoreId() == Mage_Core_Model_App::ADMIN_STORE_ID) { - $this->_applyZeroStoreProductLimitations(); - } else { - $this->_applyProductLimitations(); - } - - return $this; - } - - /** - * Join minimal price attribute to result - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function joinMinimalPrice() - { - $this->addAttributeToSelect('price') - ->addAttributeToSelect('minimal_price'); - return $this; - } - - /** - * Retrieve max value by attribute - * - * @param string $attribute - * @return mixed - */ - public function getMaxAttributeValue($attribute) - { - $select = clone $this->getSelect(); - $attribute = $this->getEntity()->getAttribute($attribute); - $attributeCode = $attribute->getAttributeCode(); - $tableAlias = $attributeCode.'_max_value'; - - $condition = 'e.entity_id='.$tableAlias.'.entity_id - AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) - //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) - ; - - $select->join( - array($tableAlias => $attribute->getBackend()->getTable()), - $condition, - array('max_'.$attributeCode=>new Zend_Db_Expr('MAX('.$tableAlias.'.value)')) - ) - ->group('e.entity_type_id'); - - $data = $this->getConnection()->fetchRow($select); - if (isset($data['max_'.$attributeCode])) { - return $data['max_'.$attributeCode]; - } - return null; - } - - /** - * Retrieve ranging product count for arrtibute range - * - * @param string $attribute - * @param int $range - * @return array - */ - public function getAttributeValueCountByRange($attribute, $range) - { - $select = clone $this->getSelect(); - $attribute = $this->getEntity()->getAttribute($attribute); - $attributeCode = $attribute->getAttributeCode(); - $tableAlias = $attributeCode.'_range_count_value'; - - $condition = 'e.entity_id='.$tableAlias.'.entity_id - AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) - //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) - ; - - $select->reset(Zend_Db_Select::GROUP); - $select->join( - array($tableAlias => $attribute->getBackend()->getTable()), - $condition, - array( - 'count_'.$attributeCode=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), - 'range_'.$attributeCode=>new Zend_Db_Expr('CEIL(('.$tableAlias.'.value+0.01)/'.$range.')') - ) - ) - ->group('range_'.$attributeCode); - - $data = $this->getConnection()->fetchAll($select); - $res = array(); - - foreach ($data as $row) { - $res[$row['range_'.$attributeCode]] = $row['count_'.$attributeCode]; - } - return $res; - } - - /** - * Retrieve product count by some value of attribute - * - * @param string $attribute - * @return array($value=>$count) - */ - public function getAttributeValueCount($attribute) - { - $select = clone $this->getSelect(); - $attribute = $this->getEntity()->getAttribute($attribute); - $attributeCode = $attribute->getAttributeCode(); - $tableAlias = $attributeCode.'_value_count'; - - $select->reset(Zend_Db_Select::GROUP); - $condition = 'e.entity_id='.$tableAlias.'.entity_id - AND '.$this->_getConditionSql($tableAlias.'.attribute_id', $attribute->getId()) - //.' AND '.$this->_getConditionSql($tableAlias.'.store_id', $this->getEntity()->getStoreId()) - ; - - $select->join( - array($tableAlias => $attribute->getBackend()->getTable()), - $condition, - array( - 'count_'.$attributeCode=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), - 'value_'.$attributeCode=>new Zend_Db_Expr($tableAlias.'.value') - ) - ) - ->group('value_'.$attributeCode); - - $data = $this->getConnection()->fetchAll($select); - $res = array(); - - foreach ($data as $row) { - $res[$row['value_'.$attributeCode]] = $row['count_'.$attributeCode]; - } - return $res; - } - - /** - * Return all attribute values as array in form: - * array( - * [entity_id_1] => array( - * [store_id_1] => store_value_1, - * [store_id_2] => store_value_2, - * ... - * [store_id_n] => store_value_n - * ), - * ... - * ) - * - * @param string $attribute attribute code - * @return array - */ - public function getAllAttributeValues($attribute) - { - /** @var Zend_Db_Select */ - $select = clone $this->getSelect(); - $attribute = $this->getEntity()->getAttribute($attribute); - - $select->reset() - ->from($attribute->getBackend()->getTable(), array('entity_id', 'store_id', 'value')) - ->where('attribute_id = ?', $attribute->getId(), Zend_Db::INT_TYPE); - - $data = $this->getConnection()->fetchAll($select); - $res = array(); - - foreach ($data as $row) { - $res[$row['entity_id']][$row['store_id']] = $row['value']; - } - - return $res; - } - - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - - $countSelect->columns('COUNT(DISTINCT e.entity_id)'); - $countSelect->resetJoinLeft(); - - return $countSelect; - } - - /** - * Retrive all ids for collection - * - * @return array - */ - public function getAllIds($limit=null, $offset=null) - { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns('e.'.$this->getEntity()->getIdFieldName()); - $idsSelect->limit($limit, $offset); - $idsSelect->resetJoinLeft(); - - return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); - } - - /** - * Retreive product count select for categories - * - * @return Varien_Db_Select - */ - public function getProductCountSelect() - { - if ($this->_productCountSelect === null) { - $this->_productCountSelect = clone $this->getSelect(); - $this->_productCountSelect->reset(Zend_Db_Select::COLUMNS) - ->reset(Zend_Db_Select::GROUP) - ->reset(Zend_Db_Select::ORDER) - ->distinct(false) - ->join(array('count_table' => $this->getTable('catalog/category_product_index')), - 'count_table.product_id = e.entity_id', - array( - 'count_table.category_id', - 'product_count' => new Zend_Db_Expr('COUNT(DISTINCT count_table.product_id)') - ) - ) - ->where('count_table.store_id = ?', $this->getStoreId()) - ->group('count_table.category_id'); - } - - return $this->_productCountSelect; - } - - /** - * Destruct product count select - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function unsProductCountSelect() - { - $this->_productCountSelect = null; - return $this; - } - - /** - * Adding product count to categories collection - * - * @param Mage_Eav_Model_Entity_Collection_Abstract $categoryCollection - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addCountToCategories($categoryCollection) - { - $isAnchor = array(); - $isNotAnchor = array(); - foreach ($categoryCollection as $category) { - if ($category->getIsAnchor()) { - $isAnchor[] = $category->getId(); - } else { - $isNotAnchor[] = $category->getId(); - } - } - $productCounts = array(); - if ($isAnchor || $isNotAnchor) { - $select = $this->getProductCountSelect(); - - Mage::dispatchEvent( - 'catalog_product_collection_before_add_count_to_categories', - array('collection' => $this) - ); - - if ($isAnchor) { - $anchorStmt = clone $select; - $anchorStmt->limit(); //reset limits - $anchorStmt->where('count_table.category_id in (?)', $isAnchor); - $productCounts += $this->getConnection()->fetchPairs($anchorStmt); - $anchorStmt = null; - } - if ($isNotAnchor) { - $notAnchorStmt = clone $select; - $notAnchorStmt->limit(); //reset limits - $notAnchorStmt->where('count_table.category_id in (?)', $isNotAnchor); - $notAnchorStmt->where('count_table.is_parent=1'); - $productCounts += $this->getConnection()->fetchPairs($notAnchorStmt); - $notAnchorStmt = null; - } - $select = null; - $this->unsProductCountSelect(); - } - - foreach ($categoryCollection as $category) { - $_count = 0; - if (isset($productCounts[$category->getId()])) { - $_count = $productCounts[$category->getId()]; - } - $category->setProductCount($_count); - } -// foreach ($categoryCollection as $category) { -// $select = clone $this->getSelect(); -// $select->reset(Zend_Db_Select::COLUMNS); -// $select->reset(Zend_Db_Select::GROUP); -// $select->reset(Zend_Db_Select::ORDER); -// $select->distinct(false); -// $select->join( -// array('category_count_table' => $this->_productCategoryTable), -// 'category_count_table.product_id=e.entity_id', -// array('count_in_category'=>new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)')) -// ); -// -// if ($category->getIsAnchor()) { -// $select->where($this->getConnection()->quoteInto( -// 'category_count_table.category_id IN(?)', -// explode(',', $category->getAllChildren()) -// )); -// } -// else { -// $select->where($this->getConnection()->quoteInto( -// 'category_count_table.category_id=?', -// $category->getId() -// )); -// } -// $category->setProductCount((int) $this->getConnection()->fetchOne($select)); -// } - return $this; - } - - public function getSetIds() - { - $select = clone $this->getSelect(); - /* @var $select Zend_Db_Select */ - $select->reset(Zend_Db_Select::COLUMNS); - $select->distinct(true); - $select->columns('attribute_set_id'); - return $this->getConnection()->fetchCol($select); - } - - /** - * Return array of unique product type ids in collection - * - * @return array - */ - public function getProductTypeIds() - { - $select = clone $this->getSelect(); - /* @var $select Zend_Db_Select */ - $select->reset(Zend_Db_Select::COLUMNS); - $select->distinct(true); - $select->columns('type_id'); - return $this->getConnection()->fetchCol($select); - } - - /** - * Joins url rewrite rules to collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection - */ - public function joinUrlRewrite() - { - $this->joinTable( - 'core/url_rewrite', - 'entity_id=entity_id', - array('request_path'), - '{{table}}.type='.Mage_Core_Model_Url_Rewrite::TYPE_PRODUCT, - 'left' - ); - - return $this; - } - - /** - * Add URL rewrites data to product - * If collection loadded - run processing else set flag - * - * @param int $categoryId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addUrlRewrite($categoryId = '') - { - $this->_addUrlRewrite = true; - if (Mage::getStoreConfig(Mage_Catalog_Helper_Product::XML_PATH_PRODUCT_URL_USE_CATEGORY, $this->getStoreId())) { - $this->_urlRewriteCategory = $categoryId; - } else { - $this->_urlRewriteCategory = 0; - } - - if ($this->isLoaded()) { - $this->_addUrlRewrite(); - } - - return $this; - } - - /** - * Add URL rewrites to collection - * - */ - protected function _addUrlRewrite() - { - $urlRewrites = null; - if ($this->_cacheConf) { - if (!($urlRewrites = Mage::app()->loadCache($this->_cacheConf['prefix'].'urlrewrite'))) { - $urlRewrites = null; - } else { - $urlRewrites = unserialize($urlRewrites); - } - } - - if (!$urlRewrites) { - $productIds = array(); - foreach($this->getItems() as $item) { - $productIds[] = $item->getEntityId(); - } - if (!count($productIds)) { - return; - } - - $select = $this->getConnection()->select() - ->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path')) - ->where('store_id=?', Mage::app()->getStore()->getId()) - ->where('is_system=?', 1) - ->where('category_id=? OR category_id is NULL', $this->_urlRewriteCategory) - ->where('product_id IN(?)', $productIds) - ->order('category_id DESC'); // more priority is data with category id - $urlRewrites = array(); - - foreach ($this->getConnection()->fetchAll($select) as $row) { - if (!isset($urlRewrites[$row['product_id']])) { - $urlRewrites[$row['product_id']] = $row['request_path']; - } - } - - if ($this->_cacheConf) { - Mage::app()->saveCache( - serialize($urlRewrites), - $this->_cacheConf['prefix'].'urlrewrite', - array_merge($this->_cacheConf['tags'], array(Mage_Catalog_Model_Product_Url::CACHE_TAG)), - $this->_cacheLifetime - ); - } - } - - foreach($this->getItems() as $item) { - if (isset($urlRewrites[$item->getEntityId()])) { - $item->setData('request_path', $urlRewrites[$item->getEntityId()]); - } else { - $item->setData('request_path', false); - } - } - } - - /** - * Add minimal price data to result - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addMinimalPrice() - { - return $this->addPriceData(); - } - - /** - * Add minimal price to product collection - * - * @deprecated sinse 1.3.2.2 - * @see Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::addPriceData - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _addMinimalPrice() - { - return $this; - } - - /** - * Add price data for calculate final price - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addFinalPrice() - { - return $this->addPriceData(); - } - - /** - * Join prices from price rules to products collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _joinPriceRules() - { - if ($this->isEnabledFlat()) { - $customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId(); - $priceColumn = 'e.display_price_group_' . $customerGroup; - $this->getSelect()->columns(array('_rule_price' => $priceColumn)); - - return $this; - } - $wId = Mage::app()->getStore($this->getStoreId())->getWebsite()->getId(); - $gId = Mage::getSingleton('customer/session')->getCustomerGroupId(); - - $storeDate = Mage::app()->getLocale()->storeTimeStamp($this->getStoreId()); - $conditions = "_price_rule.product_id = e.entity_id AND "; - $conditions .= "_price_rule.rule_date = '".$this->getResource()->formatDate($storeDate, false)."' AND "; - $conditions .= "_price_rule.website_id = '{$wId}' AND "; - $conditions .= "_price_rule.customer_group_id = '{$gId}'"; - - $this->getSelect()->joinLeft( - array('_price_rule'=>$this->getTable('catalogrule/rule_product_price')), - $conditions, - array('_rule_price'=>'rule_price') - ); - return $this; - } - - protected function _addFinalPrice() - { - foreach ($this->_items as $product) { - $basePrice = $product->getPrice(); - $specialPrice = $product->getSpecialPrice(); - $specialPriceFrom = $product->getSpecialFromDate(); - $specialPriceTo = $product->getSpecialToDate(); - if ($this->isEnabledFlat()) { - $rulePrice = null; - if ($product->getData('_rule_price') != $basePrice) { - $rulePrice = $product->getData('_rule_price'); - } - } - else { - $rulePrice = $product->getData('_rule_price'); - } - - $finalPrice = $product->getPriceModel()->calculatePrice( - $basePrice, - $specialPrice, - $specialPriceFrom, - $specialPriceTo, - $rulePrice, - null, - null, - $product->getId() - ); - - $product->setCalculatedFinalPrice($finalPrice); - } - } - - public function getAllIdsCache($resetCache = false) - { - $ids = null; - if (!$resetCache) { - $ids = $this->_allIdsCache; - } - - if (is_null($ids)) { - $ids = $this->getAllIds(); - $this->setAllIdsCache($ids); - } - - return $ids; - } - - public function setAllIdsCache($value) - { - $this->_allIdsCache = $value; - return $this; - } - - /** - * Add Price Data to result - * - * @param int $customerGroupId - * @param int $websiteId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addPriceData($customerGroupId = null, $websiteId = null) - { - $this->_productLimitationFilters['use_price_index'] = true; - - if (!isset($this->_productLimitationFilters['customer_group_id']) && is_null($customerGroupId)) { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); - } - if (!isset($this->_productLimitationFilters['website_id']) && is_null($websiteId)) { - $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - } - - if (!is_null($customerGroupId)) { - $this->_productLimitationFilters['customer_group_id'] = $customerGroupId; - } - if (!is_null($websiteId)) { - $this->_productLimitationFilters['website_id'] = $websiteId; - } - - $this->_applyProductLimitations(); - - return $this; - } - - /** - * Add attribute to filter - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract|string $attribute - * @param array $condition - * @param string $joinType - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addAttributeToFilter($attribute, $condition=null, $joinType='inner') - { - if ($this->isEnabledFlat()) { - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { - $attribute = $attribute->getAttributeCode(); - } - - if (is_array($attribute)) { - $sqlArr = array(); - foreach ($attribute as $condition) { - $sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType); - } - $conditionSql = '('.join(') OR (', $sqlArr).')'; - $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); - return $this; - } - - if (!isset($this->_selectAttributes[$attribute])) { - $this->addAttributeToSelect($attribute); - } - - if (isset($this->_selectAttributes[$attribute])) { - $this->getSelect()->where($this->_getConditionSql('e.'.$attribute, $condition)); - } - - return $this; - } - - $this->_allIdsCache = null; - - if (is_string($attribute) && $attribute == 'is_saleable') { - $columns = $this->getSelect()->getPart(Zend_Db_Select::COLUMNS); - foreach ($columns as $columnEntry) { - list($correlationName, $column, $alias) = $columnEntry; - if ($alias == 'is_saleable') { - if ($column instanceof Zend_Db_Expr) { - $field = $column; - } else { - $adapter = $this->getSelect()->getAdapter(); - if (empty($correlationName)) { - $field = $adapter->quoteColumnAs($column, $alias, true); - } else { - $field = $adapter->quoteColumnAs(array($correlationName, $column), $alias, true); - } - } - $this->getSelect()->where("{$field} = ?", $condition); - break; - } - } - - return $this; - } else { - return parent::addAttributeToFilter($attribute, $condition, $joinType); - } - } - - /** - * Add requere tax percent flag for product collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addTaxPercents() - { - $this->_addTaxPercents = true; - return $this; - } - - /** - * Get require tax percent flag value - * - * @return bool - */ - public function requireTaxPercent() - { - return $this->_addTaxPercents; - } - - /** - * @deprecated from 1.3.0 - */ - protected function _addTaxPercents() - { - $classToRate = array(); - $request = Mage::getSingleton('tax/calculation')->getRateRequest(); - foreach ($this as &$item) { - if (null === $item->getTaxClassId()) { - $item->setTaxClassId($item->getMinimalTaxClassId()); - } - if (!isset($classToRate[$item->getTaxClassId()])) { - $request->setProductClassId($item->getTaxClassId()); - $classToRate[$item->getTaxClassId()] = Mage::getSingleton('tax/calculation')->getRate($request); - } - $item->setTaxPercent($classToRate[$item->getTaxClassId()]); - } - } - - /** - * Adding product custom options to result collection - * - * @return Mage_Catalog_Model_Entity_Product_Collection - */ - public function addOptionsToResult() - { - $productIds = array(); - foreach ($this as $product) { - $productIds[] = $product->getId(); - } - if (!empty($productIds)) { - $options = Mage::getModel('catalog/product_option') - ->getCollection() - ->addTitleToResult(Mage::app()->getStore()->getId()) - ->addPriceToResult(Mage::app()->getStore()->getId()) - ->addProductToFilter($productIds) - ->addValuesToResult(); - - foreach ($options as $option) { - if($this->getItemById($option->getProductId())) { - $this->getItemById($option->getProductId())->addOption($option); - } - } - } - - return $this; - } - - /** - * Filter products with required options - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addFilterByRequiredOptions() - { - $this->addAttributeToFilter('required_options', array(array('neq'=>'1'), array('null'=>true)), 'left'); - return $this; - } - - /** - * Set product visibility filter for enabled products - * - * @param array $visibility - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function setVisibility($visibility) - { - $this->_productLimitationFilters['visibility'] = $visibility; - $this->_applyProductLimitations(); - - return $this; - } - - /** - * Add attribute to sort order - * - * @param string $attribute - * @param string $dir - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addAttributeToSort($attribute, $dir='asc') - { - if ($attribute == 'position') { - if (isset($this->_joinFields[$attribute])) { - $this->getSelect()->order("{$attribute} {$dir}"); - return $this; - } - $this->getSelect()->order("cat_index_position {$dir}"); - // optimize if using cat index - $filters = $this->_productLimitationFilters; - if (isset($filters['category_id']) || isset($filters['visibility'])) { - $this->getSelect()->order('cat_index.product_id ' . $dir); - } - else { - $this->getSelect()->order('e.entity_id ' . $dir); - } - - return $this; - } else if($attribute == 'is_saleable'){ - $this->getSelect()->order("is_saleable " . $dir); - return $this; - } - - $storeId = Mage::app()->getStore()->getId(); - if ($attribute == 'price' && $storeId != 0) { - $this->addPriceData(); - $this->getSelect()->order("price_index.min_price {$dir}"); - - return $this; - } - - if ($this->isEnabledFlat()) { - $column = $this->getEntity()->getAttributeSortColumn($attribute); - - if ($column) { - $this->getSelect()->order("e.{$column} {$dir}"); - } - else if (isset($this->_joinFields[$attribute])) { - $this->getSelect()->order($this->_getAttributeFieldName($attribute).' '.$dir); - } - - return $this; - } else { - $attrInstance = $this->getEntity()->getAttribute($attribute); - if ($attrInstance && $attrInstance->usesSource()) { - $attrInstance->getSource() - ->addValueSortToCollection($this, $dir); - return $this; - } - } - - return parent::addAttributeToSort($attribute, $dir); - } - - /** - * Prepare limitation filters - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _prepareProductLimitationFilters() - { - if (isset($this->_productLimitationFilters['visibility']) - && !isset($this->_productLimitationFilters['store_id']) - ) { - $this->_productLimitationFilters['store_id'] = $this->getStoreId(); - } - if (isset($this->_productLimitationFilters['category_id']) - && !isset($this->_productLimitationFilters['store_id']) - ) { - $this->_productLimitationFilters['store_id'] = $this->getStoreId(); - } - if (isset($this->_productLimitationFilters['store_id']) - && isset($this->_productLimitationFilters['visibility']) - && !isset($this->_productLimitationFilters['category_id']) - ) { - $this->_productLimitationFilters['category_id'] = Mage::app() - ->getStore($this->_productLimitationFilters['store_id']) - ->getRootCategoryId(); - } - - return $this; - } - - /** - * Join website product limitation - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _productLimitationJoinWebsite() - { - $joinWebsite = false; - $filters = $this->_productLimitationFilters; - $conditions = array( - 'product_website.product_id=e.entity_id' - ); - if (isset($filters['website_ids'])) { - $joinWebsite = true; - if (count($filters['website_ids']) > 1) { - $this->getSelect()->distinct(true); - } - $conditions[] = $this->getConnection() - ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']); - } - elseif (isset($filters['store_id']) - && (!isset($filters['visibility']) && !isset($filters['category_id'])) - && !$this->isEnabledFlat() - ) { - $joinWebsite = true; - $websiteId = Mage::app()->getStore($filters['store_id'])->getWebsiteId(); - $conditions[] = $this->getConnection() - ->quoteInto('product_website.website_id=?', $websiteId); - } - - $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (isset($fromPart['product_website'])) { - if (!$joinWebsite) { - unset($fromPart['product_website']); - } - else { - $fromPart['product_website']['joinCondition'] = join(' AND ', $conditions); - } - $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); - } - elseif ($joinWebsite) { - $this->getSelect()->join( - array('product_website' => $this->getTable('catalog/product_website')), - join(' AND ', $conditions), - array() - ); - } - - return $this; - } - - /** - * Join additional (alternative) store visibility filter - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _productLimitationJoinStore() - { - $filters = $this->_productLimitationFilters; - if (!isset($filters['store_table'])) { - return $this; - } - - $hasColumn = false; - foreach ($this->getSelect()->getPart(Zend_Db_Select::COLUMNS) as $columnEntry) { - list(,,$alias) = $columnEntry; - if ($alias == 'visibility') { - $hasColumn = true; - } - } - if (!$hasColumn) { - $this->getSelect()->columns('visibility', 'cat_index'); - } - - $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (!isset($fromPart['store_index'])) { - $this->getSelect()->joinLeft( - array('store_index' => $this->getTable('core/store')), - 'store_index.store_id='.$filters['store_table'].'.store_id', - array() - ); - } - if (!isset($fromPart['store_group_index'])) { - $this->getSelect()->joinLeft( - array('store_group_index' => $this->getTable('core/store_group')), - 'store_index.group_id=store_group_index.group_id', - array() - ); - } - if (!isset($fromPart['store_cat_index'])) { - $this->getSelect()->joinLeft( - array('store_cat_index' => $this->getTable('catalog/category_product_index')), - join(' AND ', array( - 'store_cat_index.product_id=e.entity_id', - 'store_cat_index.store_id='.$filters['store_table'].'.store_id', - 'store_cat_index.category_id=store_group_index.root_category_id' - )), - array('store_visibility' => 'visibility') - ); - } - $whereCond = join(' OR ', array( - $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']), - $this->getConnection()->quoteInto('store_cat_index.visibility IN(?)', $filters['visibility']) - )); - - $wherePart = $this->getSelect()->getPart(Zend_Db_Select::WHERE); - $hasCond = false; - foreach ($wherePart as $cond) { - if ($cond == '('.$whereCond.')') { - $hasCond = true; - } - } - - if (!$hasCond) { - $this->getSelect()->where($whereCond); - } - - return $this; - } - - /** - * Join Product Price Table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _productLimitationJoinPrice() - { - $filters = $this->_productLimitationFilters; - if (empty($filters['use_price_index'])) { - return $this; - } - - $connection = $this->getConnection(); - - $joinCond = $joinCond = join(' AND ', array( - 'price_index.entity_id = e.entity_id', - $connection->quoteInto('price_index.website_id = ?', $filters['website_id']), - $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id']) - )); - - $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (!isset($fromPart['price_index'])) { - $minimalExpr = new Zend_Db_Expr( - 'IF(`price_index`.`tier_price`, LEAST(`price_index`.`min_price`, `price_index`.`tier_price`), ' . - '`price_index`.`min_price`)' - ); - $this->getSelect()->join( - array('price_index' => $this->getTable('catalog/product_index_price')), - $joinCond, - array('price', 'tax_class_id', 'final_price', 'minimal_price' => $minimalExpr ,'min_price', 'max_price', - 'tier_price') - ); - - // Set additional field filters - foreach ($this->_priceDataFieldFilters as $filterData) { - $this->getSelect()->where(call_user_func_array('sprintf', $filterData)); - } - } else { - $fromPart['price_index']['joinCondition'] = $joinCond; - $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); - } - - return $this; - } - - /** - * Apply front-end price limitation filters to the collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - * - */ - public function applyFrontendPriceLimitations() - { - $this->_productLimitationFilters['use_price_index'] = true; - if (!isset($this->_productLimitationFilters['customer_group_id'])) { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); - $this->_productLimitationFilters['customer_group_id'] = $customerGroupId; - } - if (!isset($this->_productLimitationFilters['website_id'])) { - $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - $this->_productLimitationFilters['website_id'] = $websiteId; - } - $this->_applyProductLimitations(); - return $this; - } - - /** - * Apply limitation filters to collection - * - * Method allows using one time category product index table (or product website table) - * for different combinations of store_id/category_id/visibility filter states - * - * Method supports multiple changes in one collection object for this parameters - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _applyProductLimitations() - { - $this->_prepareProductLimitationFilters(); - $this->_productLimitationJoinWebsite(); - $this->_productLimitationJoinPrice(); - $filters = $this->_productLimitationFilters; - - if (!isset($filters['category_id']) && !isset($filters['visibility'])) { - return $this; - } - - $conditions = array( - 'cat_index.product_id=e.entity_id', - $this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']) - ); - if (isset($filters['visibility']) && !isset($filters['store_table'])) { - $conditions[] = $this->getConnection() - ->quoteInto('cat_index.visibility IN(?)', $filters['visibility']); - } - $conditions[] = $this->getConnection() - ->quoteInto('cat_index.category_id=?', $filters['category_id']); - if (isset($filters['category_is_anchor'])) { - $conditions[] = $this->getConnection() - ->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']); - } - - $joinCond = join(' AND ', $conditions); - $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (isset($fromPart['cat_index'])) { - $fromPart['cat_index']['joinCondition'] = $joinCond; - $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); - } - else { - $this->getSelect()->join( - array('cat_index' => $this->getTable('catalog/category_product_index')), - $joinCond, - array('cat_index_position' => 'position') - ); - } - - $this->_productLimitationJoinStore(); - - Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array( - 'collection' => $this - )); - - return $this; - } - - /** - * Apply limitation filters to collection base on API - * - * Method allows using one time category product table - * for combinations of category_id filter states - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _applyZeroStoreProductLimitations() - { - $filters = $this->_productLimitationFilters; - - $conditions = array( - 'cat_pro.product_id=e.entity_id', - $this->getConnection()->quoteInto('cat_pro.category_id=?', $filters['category_id']) - ); - $joinCond = join(' AND ', $conditions); - - $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (isset($fromPart['cat_pro'])) { - $fromPart['cat_pro']['joinCondition'] = $joinCond; - $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); - } - else { - $this->getSelect()->join( - array('cat_pro' => $this->getTable('catalog/category_product')), - $joinCond, - array('cat_index_position' => 'position') - ); - } - - return $this; - } - - /** - * Stub method - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function setGeneralDefoultQuery() - { - return $this; - } - - /** - * Add category ids to loaded items - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addCategoryIds() - { - if ($this->getFlag('category_ids_added')) { - return $this; - } - $ids = array_keys($this->_items); - if (empty($ids)) { - return $this; - } - - $select = $this->getConnection()->select(); - - $select->from($this->_productCategoryTable, array('product_id', 'category_id')); - $select->where('product_id IN (?)', $ids); - - $data = $this->getConnection()->fetchAll($select); - - $categoryIds = array(); - foreach ($data as $info) { - if (isset($categoryIds[$info['product_id']])) { - $categoryIds[$info['product_id']][] = $info['category_id']; - } else { - $categoryIds[$info['product_id']] = array($info['category_id']); - } - } - - - foreach ($this->getItems() as $item) { - $productId = $item->getId(); - if (isset($categoryIds[$productId])) { - $item->setCategoryIds($categoryIds[$productId]); - } else { - $item->setCategoryIds(array()); - } - } - - $this->setFlag('category_ids_added', true); - return $this; - } - - /** - * Add tier price data to loaded items - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addTierPriceData() - { - if ($this->getFlag('tier_price_added')) { - return $this; - } - - $tierPrices = array(); - $productIds = array(); - foreach ($this->getItems() as $item) { - $productIds[] = $item->getId(); - $tierPrices[$item->getId()] = array(); - } - if (!$productIds) { - return $this; - } - - /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ - $attribute = $this->getAttribute('tier_price'); - if ($attribute->isScopeGlobal()) { - $websiteId = 0; - } else if ($this->getStoreId()) { - $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - } - - $adapter = $this->getConnection(); - $columns = array( - 'price_id' => 'value_id', - 'website_id' => 'website_id', - 'all_groups' => 'all_groups', - 'cust_group' => 'customer_group_id', - 'price_qty' => 'qty', - 'price' => 'value', - 'product_id' => 'entity_id' - ); - $select = $adapter->select() - ->from($this->getTable('catalog/product_attribute_tier_price'), $columns) - ->where('entity_id IN(?)', $productIds) - ->order(array('entity_id','qty')); - - if ($websiteId == '0') { - $select->where('website_id=?', $websiteId); - } else { - $select->where('website_id IN(?)', array('0', $websiteId)); - } - - foreach ($adapter->fetchAll($select) as $row) { - $tierPrices[$row['product_id']][] = array( - 'website_id' => $row['website_id'], - 'cust_group' => $row['all_groups'] ? Mage_Customer_Model_Group::CUST_GROUP_ALL : $row['cust_group'], - 'price_qty' => $row['price_qty'], - 'price' => $row['price'], - 'website_price' => $row['price'], - - ); - } - - /* @var $backend Mage_Catalog_Model_Product_Attribute_Backend_Tierprice */ - $backend = $attribute->getBackend(); - - foreach ($this->getItems() as $item) { - $data = $tierPrices[$item->getId()]; - if (!empty($data) && $websiteId) { - $data = $backend->preparePriceData($data, $item->getTypeId(), $websiteId); - } - $item->setData('tier_price', $data); - } - - $this->setFlag('tier_price_added', true); - return $this; - } - - /** - * Add field comparison expression - * - * @param string $comparisonFormat - expression for sprintf() - * @param array $fields - list of fields - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function addPriceDataFieldFilter($comparisonFormat, $fields) - { - if (!preg_match('/^%s( (<|>|=|<=|>=|<>) %s)*$/', $comparisonFormat)) { - throw new Exception('Invalid comparison format.'); - } - - if (!is_array($fields)) { - $fields = array($fields); - } - foreach ($fields as $key => $field) { - $fields[$key] = $this->_getMappedField($field); - } - - $this->_priceDataFieldFilters[] = array_merge(array($comparisonFormat), $fields); - return $this; - } - - /** - * Clear collection - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - public function clear() - { - foreach ($this->_items as $i => $item) { - if ($item->hasStockItem()) { - $item->unsStockItem(); - } - $item = $this->_items[$i] = null; - } - - foreach ($this->_itemsById as $i => $item) { - $item = $this->_itemsById[$i] = null; - } - - unset($this->_items, $this->_data, $this->_itemsById); - $this->_data = array(); - $this->_itemsById = array(); - return parent::clear(); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item.php index b8b59df3b8..f05cc12a45 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,222 +28,11 @@ /** * Catalog compare item resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item + extends Mage_Catalog_Model_Resource_Product_Compare_Item { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('catalog/compare_item', 'catalog_compare_item_id'); - } - - /** - * Load object by product - * - * @param Mage_Core_Model_Abstract $object - * @param mixed $product - * @return bool - */ - public function loadByProduct(Mage_Catalog_Model_Product_Compare_Item $object, $product) - { - $read = $this->_getReadAdapter(); - if ($product instanceof Mage_Catalog_Model_Product) { - $productId = $product->getId(); - } - else { - $productId = (int)$product; - } - - $select = $read->select()->from($this->getMainTable()) - ->where('product_id=?', $productId); - - if ($object->getCustomerId()) { - $select->where('customer_id=?', $object->getCustomerId()); - } - else { - $select->where('visitor_id=?', $object->getVisitorId()); - } - - $data = $read->fetchRow($select); - - if (!$data) { - return false; - } - - $object->setData($data); - - $this->_afterLoad($object); - return true; - } - - /** - * Resource retrieve count compare items - * - * @param int $customerId - * @param int $visitorId - * @return int - */ - public function getCount($customerId, $visitorId) - { - $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'COUNT(*)') - ->where('visitor_id=?', $visitorId); - if ($customerId) { - $select->where('customer_id=?', $customerId); - } - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Clean compare table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item - */ - public function clean() - { - while (true) { - $select = $this->_getReadAdapter()->select() - ->from(array('compare_table' => $this->getMainTable()), array('catalog_compare_item_id')) - ->joinLeft( - array('visitor_table' => $this->getTable('log/visitor')), - '`visitor_table`.`visitor_id`=`compare_table`.`visitor_id` AND `compare_table`.`customer_id` IS NULL', - array()) - ->where('compare_table.visitor_id>?', 0) - ->where('`visitor_table`.`visitor_id` IS NULL') - ->limit(100); - $itemIds = $this->_getReadAdapter()->fetchCol($select); - - if (!$itemIds) { - break; - } - - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto('catalog_compare_item_id IN(?)', $itemIds) - ); - } - - return $this; - } - - /** - * Purge visitor data after customer logout - * - * @param Mage_Catalog_Model_Product_Compare_Item $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item - */ - public function purgeVisitorByCustomer($object) - { - if (!$object->getCustomerId()) { - return $this; - } - - $where = $this->_getWriteAdapter()->quoteInto('customer_id=?', $object->getCustomerId()); - $bind = array( - 'visitor_id' => 0, - ); - - $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); - - return $this; - } - - /** - * Update (Merge) customer data from visitor - * - * After Login process - * - * @param Mage_Catalog_Model_Product_Compare_Item $object - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item - */ - public function updateCustomerFromVisitor($object) - { - if (!$object->getCustomerId()) { - return $this; - } - - // collect visitor compared items - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('visitor_id=?', $object->getVisitorId()); - $visitor = $this->_getWriteAdapter()->fetchAll($select); - - // collect customer compared items - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('customer_id=?', $object->getCustomerId()) - ->where('visitor_id<>?', $object->getVisitorId()); - $customer = $this->_getWriteAdapter()->fetchAll($select); - - $products = array(); - $delete = array(); - $update = array(); - foreach ($visitor as $row) { - $products[$row['product_id']] = array( - 'store_id' => $row['store_id'], - 'customer_id' => $object->getCustomerId(), - 'visitor_id' => $object->getVisitorId(), - 'product_id' => $row['product_id'] - ); - $update[$row[$this->getIdFieldName()]] = $row['product_id']; - } - - foreach ($customer as $row) { - if (isset($products[$row['product_id']])) { - $delete[] = $row[$this->getIdFieldName()]; - } - else { - $products[$row['product_id']] = array( - 'store_id' => $row['store_id'], - 'customer_id' => $object->getCustomerId(), - 'visitor_id' => $object->getVisitorId(), - 'product_id' => $row['product_id'] - ); - } - } - - if ($delete) { - $this->_getWriteAdapter()->delete($this->getMainTable(), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $delete)); - } - if ($update) { - foreach ($update as $itemId => $productId) { - $bind = $products[$productId]; - $this->_getWriteAdapter()->update($this->getMainTable(), $bind, - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $itemId)); - } - } - - return $this; - } - - /** - * Clear compare items by visitor and/or customer - * - * @param int $visitorId - * @param int $customerId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item - */ - public function clearItems($visitorId = null, $customerId = null) - { - $where = array(); - if ($customerId) { - $customerId = (int)$customerId; - $where[] = $this->_getWriteAdapter()->quoteInto('customer_id=?', $customerId); - } - if ($visitorId) { - $visitorId = (int)$visitorId; - $where[] = $this->_getWriteAdapter()->quoteInto('visitor_id=?', $visitorId); - } - if (!$where) { - return $this; - } - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item/Collection.php index 11be7990c7..dce5b4dada 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Compare/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,306 +28,11 @@ /** * Catalog Product Compare Items Resource Collection * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection + extends Mage_Catalog_Model_Resource_Product_Compare_Item_Collection { - /** - * Customer Filter - * - * @var int - */ - protected $_customerId = 0; - - /** - * Visitor Filter - * - * @var int - */ - protected $_visitorId = 0; - - /** - * Comparable attributes cache - * - * @var array - */ - protected $_comparableAttributes; - - /** - * Initialize resources - */ - protected function _construct() - { - $this->_init('catalog/product_compare_item', 'catalog/product'); - $this->_initTables(); - } - - /** - * Set customer filter to collection - * - * @param int $customerId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function setCustomerId($customerId) - { - $this->_customerId = $customerId; - $this->_addJoinToSelect(); - return $this; - } - - /** - * Set visitor filter to collection - * - * @param int $visitorId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function setVisitorId($visitorId) - { - $this->_visitorId = $visitorId; - $this->_addJoinToSelect(); - return $this; - } - - /** - * Retrieve customer filter applied to collection - * - * @return int - */ - public function getCustomerId() - { - return $this->_customerId; - } - - /** - * Retrieve visitor filter applied to collection - * - * @return int - */ - public function getVisitorId() - { - return $this->_visitorId; - } - - /** - * Retrieve condition for join filters - * - * @return array|null - */ - public function getConditionForJoin() - { - if ($this->getCustomerId()) { - return array('customer_id' => $this->getCustomerId()); - } - - if ($this->getVisitorId()) { - return array('visitor_id' => $this->getVisitorId()); - } - - return null; - } - - /** - * Add join to select - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function _addJoinToSelect() - { - $this->joinTable( - array('t_compare' => 'catalog/compare_item'), - 'product_id=entity_id', - array( - 'product_id' => 'product_id', - 'customer_id' => 'customer_id', - 'visitor_id' => 'visitor_id', - 'item_store_id' => 'store_id', - 'catalog_compare_item_id' => 'catalog_compare_item_id' - ), - $this->getConditionForJoin() - ); - - $this->_productLimitationFilters['store_table'] = 't_compare'; - - return $this; - } - - /** - * Retrieve comapre products attribute set ids - * - * @return array - */ - protected function _getAttributeSetIds() - { - // prepare compare items table conditions - $compareConds = array( - 'compare.product_id=entity.entity_id', - ); - if ($this->getCustomerId()) { - $compareConds[] = $this->getConnection() - ->quoteInto('compare.customer_id=?', $this->getCustomerId()); - } else { - $compareConds[] = $this->getConnection() - ->quoteInto('compare.visitor_id=?', $this->getVisitorId()); - } - - // prepare website filter - $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - $websiteConds = array( - 'website.product_id=entity.entity_id', - $this->getConnection()->quoteInto('website.website_id=?', $websiteId) - ); - - // retrieve attribute sets - $select = $this->getConnection()->select() - ->distinct(true) - ->from( - array('entity' => $this->getEntity()->getEntityTable()), - 'attribute_set_id') - ->join( - array('website' => $this->getTable('catalog/product_website')), - join(' AND ', $websiteConds), - array()) - ->join( - array('compare' => $this->getTable('catalog/compare_item')), - join(' AND ', $compareConds), - array() - ); - return $this->getConnection()->fetchCol($select); - } - - /** - * Retrieve attribute ids by set ids - * - * @param array $setIds - * @return array - */ - protected function _getAttributeIdsBySetIds(array $setIds) - { - $select = $this->getConnection()->select() - ->distinct(true) - ->from($this->getTable('eav/entity_attribute'), 'attribute_id') - ->where('attribute_set_id IN(?)', $setIds); - return $this->getConnection()->fetchCol($select); - } - - /** - * Retrieve Merged comparable attributes for compared product items - * - * @return array - */ - public function getComparableAttributes() - { - if (is_null($this->_comparableAttributes)) { - $this->_comparableAttributes = array(); - $setIds = $this->_getAttributeSetIds(); - if ($setIds) { - $attributeIds = $this->_getAttributeIdsBySetIds($setIds); - - $select = $this->getConnection()->select() - ->from(array('main_table' => $this->getTable('eav/attribute'))) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'additional_table.attribute_id=main_table.attribute_id' - ) - ->joinLeft( - array('al' => $this->getTable('eav/attribute_label')), - 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(), - array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)')) - ) - ->where('additional_table.is_comparable=?', 1) - ->where('main_table.attribute_id IN(?)', $attributeIds); - $attributesData = $this->getConnection()->fetchAll($select); - if ($attributesData) { - $entityType = 'catalog_product'; - Mage::getSingleton('eav/config') - ->importAttributesData($entityType, $attributesData); - foreach ($attributesData as $data) { - $attribute = Mage::getSingleton('eav/config') - ->getAttribute($entityType, $data['attribute_code']); - $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute; - } - unset($attributesData); - } - } - } - return $this->_comparableAttributes; - } - - /** - * Load Comparable attributes - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function loadComparableAttributes() - { - $comparableAttributes = $this->getComparableAttributes(); - $attributes = array(); - foreach ($comparableAttributes as $attribute) { - $attributes[] = $attribute->getAttributeCode(); - } - $this->addAttributeToSelect($attributes); - - return $this; - } - - /** - * Use product as collection item - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function useProductItem() - { - $this->setObject('catalog/product'); - - $this->setFlag('url_data_object', true); - $this->setFlag('do_not_use_category_id', true); - - return $this; - } - - /** - * Retrieve product ids from collection - * - * @return array - */ - public function getProductIds() - { - $ids = array(); - foreach ($this->getItems() as $item) { - $ids[] = $item->getProductId(); - } - - return $ids; - } - - /** - * Clear compare items by condition - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection - */ - public function clear() - { - Mage::getResourceSingleton('catalog/product_compare_item') - ->clearItems($this->getVisitorId(), $this->getCustomerId()); - Mage::dispatchEvent('catalog_product_compare_item_collection_clear'); - - return $this; - } - - /** - * Retrieve is flat enabled flag - * Overwrite disable flat for compared item if required EAV resource - * - * @return bool - */ - public function isEnabledFlat() - { - if (!Mage::helper('catalog/product_compare')->getAllowUsedFlat()) { - return false; - } - return parent::isEnabledFlat(); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat.php index 527d0a7d8a..d27604e3cf 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,193 +28,10 @@ /** * Catalog Product Flat resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat - extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat extends Mage_Catalog_Model_Resource_Product_Flat { - /** - * Store scope Id - * - * @var int - */ - protected $_storeId; - - /** - * Init connection and resource table - * - */ - protected function _construct() - { - $this->_init('catalog/product_flat', 'entity_id'); - $this->_storeId = Mage::app()->getStore()->getId(); - } - - /** - * Retrieve store for resource model - * - * @return int - */ - public function getStoreId() - { - return $this->_storeId; - } - - /** - * Set store for resource model - * - * @param mixed $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat - */ - public function setStoreId($store) - { - if (is_int($store)) { - $this->_storeId = $store; - } else { - $this->_storeId = Mage::app()->getStore($store)->getId(); - } - return $this; - } - - /** - * Retrieve Flat Table name - * - * @param mixed $store - * @return string - */ - public function getFlatTableName($store = null) - { - if (is_null($store)) { - $store = $this->getStoreId(); - } - return $this->getTable('catalog/product_flat') . '_' . $store; - } - - /** - * Retrieve entity type id - * - * @return int - */ - public function getTypeId() - { - return Mage::getSingleton('catalog/config') - ->getEntityType('catalog_product') - ->getEntityTypeId(); - } - - /** - * Retrieve attribute columns for collection select - * - * @param string $attributeCode - * @return array|null - */ - public function getAttributeForSelect($attributeCode) - { - $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); - if (!isset($describe[$attributeCode])) { - return null; - } - $columns = array($attributeCode => $attributeCode); - - if (isset($describe[$attributeCode . '_value'])) { - $columns[$attributeCode . '_value'] = $attributeCode . '_value'; - } - - return $columns; - } - - /** - * Retrieve Attribute Sort column name - * - * @param string $attributeCode - * @return string - */ - public function getAttributeSortColumn($attributeCode) - { - $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); - if (!isset($describe[$attributeCode])) { - return null; - } - if (isset($describe[$attributeCode . '_value'])) { - return $attributeCode . '_value'; - } - return $attributeCode; - } - - /** - * Retrieve Flat Table columns list - * - * @return array - */ - public function getAllTableColumns() - { - $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); - return array_keys($describe); - } - - /** - * Check whether the attribute is a real field in entity table - * Rewrited for EAV Collection - * - * @param integer|string|Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @return bool - */ - public function isAttributeStatic($attribute) - { - $attributeCode = null; - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Interface) { - $attributeCode = $attribute->getAttributeCode(); - } - elseif (is_string($attribute)) { - $attributeCode = $attribute; - } - elseif (is_numeric($attribute)) { - $attributeCode = $this->getAttribute($attribute) - ->getAttributeCode(); - } - - if ($attributeCode) { - $columns = $this->getAllTableColumns(); - if (in_array($attributeCode, $columns)) { - return true; - } - } - - return false; - } - /** - * Retrieve entity id field name in entity table - * Rewrited for EAV collection compatible - * - * @return string - */ - public function getEntityIdField() - { - return $this->getIdFieldName(); - } - - /** - * Retrieve attribute instance - * Special for non static flat table - * - * @param mixed $attribute - * @return Mage_Eav_Model_Entity_Attribute_Abstract - */ - public function getAttribute($attribute) - { - return Mage::getSingleton('catalog/config') - ->getAttribute('catalog_product', $attribute); - } - - /** - * Retrieve main resource table name - * - * @return string - */ - public function getMainTable() - { - return $this->getFlatTableName($this->getStoreId()); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat/Indexer.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat/Indexer.php index 3ad27b68e3..65e27f11f2 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat/Indexer.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Flat/Indexer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,1194 +28,11 @@ /** * Catalog Product Flat Indexer Resource Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - extends Mage_Core_Model_Mysql4_Abstract + extends Mage_Catalog_Model_Resource_Product_Flat_Indexer { - const XML_NODE_MAX_INDEX_COUNT = 'global/catalog/product/flat/max_index_count'; - const XML_NODE_ATTRIBUTE_NODES = 'global/catalog/product/flat/attribute_nodes'; - - /** - * Attribute codes for flat - * - * @var array - */ - protected $_attributeCodes; - - /** - * Attribute objects for flat cache - * - * @var array - */ - protected $_attributes; - - /** - * Required system attributes for preload - * - * @var array - */ - protected $_systemAttributes = array('status', 'required_options', 'tax_class_id', 'weight'); - - /** - * Eav Catalog_Product Entity Type Id - * - * @var int - */ - protected $_entityTypeId; - - /** - * Flat table columns cache - * - * @var array - */ - protected $_columns; - - /** - * Flat table indexes cache - * - * @var array - */ - protected $_indexes; - - /** - * Product Type Instances cache - * - * @var array - */ - protected $_productTypes; - - /** - * Exists flat tables cache - * - * @var array - */ - protected $_existsFlatTables = array(); - - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - /** - * Rebuild Catalog Product Flat Data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function rebuild($store = null) - { - if (is_null($store)) { - foreach (Mage::app()->getStores() as $store) { - $this->rebuild($store->getId()); - } - $flag = $this->getFlatHelper()->getFlag(); - $flag->setIsBuild(true)->save(); - return $this; - } - - $this->prepareFlatTable($store); - $this->cleanNonWebsiteProducts($store); - $this->updateStaticAttributes($store); - $this->updateEavAttributes($store); - $this->updateEventAttributes($store); - $this->updateRelationProducts($store); - $this->cleanRelationProducts($store); - - return $this; - } - - /** - * Retrieve Catalog Product Flat helper - * - * @return Mage_Catalog_Helper_Product_Flat - */ - public function getFlatHelper() - { - return Mage::helper('catalog/product_flat'); - } - - /** - * Retrieve attribute codes using for flat - * - * @return array - */ - public function getAttributeCodes() - { - if (is_null($this->_attributeCodes)) { - $attributeNodes = Mage::getConfig() - ->getNode(self::XML_NODE_ATTRIBUTE_NODES) - ->children(); - foreach ($attributeNodes as $node) { - $attributes = Mage::getConfig()->getNode((string)$node)->asArray(); - $attributes = array_keys($attributes); - $this->_systemAttributes = array_unique(array_merge($attributes, $this->_systemAttributes)); - } - - $this->_attributeCodes = array(); - $whereCond = array( - $this->_getReadAdapter()->quoteInto('main_table.backend_type=?', 'static'), - $this->_getReadAdapter()->quoteInto('additional_table.used_in_product_listing=?', 1), - $this->_getReadAdapter()->quoteInto('additional_table.used_for_sort_by=?', 1), - $this->_getReadAdapter()->quoteInto('main_table.attribute_code IN(?)', $this->_systemAttributes) - ); - if ($this->getFlatHelper()->isAddFilterableAttributes()) { - $whereCond[] = $this->_getReadAdapter()->quoteInto('additional_table.is_filterable>?', 0); - } - - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getTable('eav/attribute'))) - ->join( - array('additional_table' => $this->getTable('catalog/eav_attribute')), - 'additional_table.attribute_id=main_table.attribute_id' - ) - ->where('main_table.entity_type_id=?', $this->getEntityTypeId()) - ->where(join(' OR ', $whereCond)); - $attributesData = $this->_getReadAdapter()->fetchAll($select); - Mage::getSingleton('eav/config') - ->importAttributesData($this->getEntityType(), $attributesData); - $this->_attributeCodes = array(); - foreach ($attributesData as $data) { - $this->_attributeCodes[$data['attribute_id']] = $data['attribute_code']; - } - unset($attributesData); - } - return $this->_attributeCodes; - } - - /** - * Retrieve entity type - * - * @return string - */ - public function getEntityType() - { - return 'catalog_product'; - } - - /** - * Retrieve Catalog Entity Type Id - * - * @return int - */ - public function getEntityTypeId() - { - if (is_null($this->_entityTypeId)) { - $this->_entityTypeId = Mage::getResourceModel('catalog/config') - ->getEntityTypeId(); - } - return $this->_entityTypeId; - } - - /** - * Retrieve attribute objects for flat - * - * @param bool $cache - * @return array - */ - public function getAttributes() - { - if (is_null($this->_attributes)) { - $attributeCodes = $this->getAttributeCodes(false); - $entity = Mage::getSingleton('eav/config') - ->getEntityType($this->getEntityType()) - ->getEntity(); - foreach ($attributeCodes as $attributeCode) { - $attribute = Mage::getSingleton('eav/config') - ->getAttribute($this->getEntityType(), $attributeCode) - ->setEntity($entity); - try { - // check if exists source and backend model. - // To prevent exception when some module was disabled - $attribute->usesSource() && $attribute->getSource(); - $attribute->getBackend(); - $this->_attributes[$attributeCode] = $attribute; - } catch (Exception $e) { - Mage::logException($e); - } - } - } - return $this->_attributes; - } - - /** - * Retrieve loaded attribute by code - * - * @param string $attributeCode - * @return Mage_Eav_Model_Entity_Attribute - */ - public function getAttribute($attributeCode) - { - $attributes = $this->getAttributes(); - if (!isset($attributes[$attributeCode])) { - $attribute = Mage::getModel('catalog/resource_eav_attribute') - ->loadByCode($this->getEntityTypeId(), $attributeCode); - if (!$attribute->getId()) { - Mage::throwException(Mage::helper('catalog')->__('Invalid attribute %s.', $attributeCode)); - } - $entity = Mage::getSingleton('eav/config') - ->getEntityType($this->getEntityType()) - ->getEntity(); - $attribute->setEntity($entity); - return $attribute; - } - return $attributes[$attributeCode]; - } - - /** - * Retrieve Catalog Product Flat Table name - * - * @param int $store - * @return string - */ - public function getFlatTableName($store) - { - return $this->getTable('catalog/product_flat') . '_' . $store; - } - - /** - * Retrieve catalog product flat table columns array - * - * @return array - */ - public function getFlatColumns() - { - if (is_null($this->_columns)) { - $this->_columns = array(); - $this->_columns['entity_id'] = array( - 'type' => 'int(10)', - 'unsigned' => true, - 'is_null' => false, - 'default' => null, - 'extra' => 'auto_increment' - ); - if ($this->getFlatHelper()->isAddChildData()) { - $this->_columns['child_id'] = array( - 'type' => 'int(10)', - 'unsigned' => true, - 'is_null' => true, - 'default' => null, - 'extra' => null - ); - $this->_columns['is_child'] = array( - 'type' => 'tinyint(1)', - 'unsigned' => true, - 'is_null' => false, - 'default' => 0, - 'extra' => null - ); - } - $this->_columns['attribute_set_id'] = array( - 'type' => 'smallint(5)', - 'unsigned' => true, - 'is_null' => false, - 'default' => 0, - 'extra' => null - ); - $this->_columns['type_id'] = array( - 'type' => 'varchar(32)', - 'unsigned' => false, - 'is_null' => false, - 'default' => 'simple', - 'extra' => null - ); - - foreach ($this->getAttributes() as $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - $columns = $attribute - ->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes()) - ->setFlatAddChildData($this->getFlatHelper()->isAddChildData()) - ->getFlatColumns(); - if (is_null($columns)) { - continue; - } - - $this->_columns = array_merge($this->_columns, $columns); - } - - $columnsObject = new Varien_Object(); - $columnsObject->setColumns($this->_columns); - Mage::dispatchEvent('catalog_product_flat_prepare_columns', array( - 'columns' => $columnsObject - )); - $this->_columns = $columnsObject->getColumns(); - } - return $this->_columns; - } - - /** - * Retrieve catalog product flat table indexes array - * - * @return array - */ - public function getFlatIndexes() - { - if (is_null($this->_indexes)) { - $this->_indexes = array(); - - if ($this->getFlatHelper()->isAddChildData()) { - $this->_indexes['PRIMARY'] = array( - 'type' => 'primary', - 'fields' => array('entity_id', 'child_id') - ); - $this->_indexes['IDX_CHILD'] = array( - 'type' => 'index', - 'fields' => array('child_id') - ); - $this->_indexes['IDX_IS_CHILD'] = array( - 'type' => 'index', - 'fields' => array('entity_id', 'is_child') - ); - } - else { - $this->_indexes['PRIMARY'] = array( - 'type' => 'primary', - 'fields' => array('entity_id') - ); - } - $this->_indexes['IDX_TYPE_ID'] = array( - 'type' => 'index', - 'fields' => array('type_id') - ); - $this->_indexes['IDX_ATRRIBUTE_SET'] = array( - 'type' => 'index', - 'fields' => array('attribute_set_id') - ); - - foreach ($this->getAttributes() as $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - $indexes = $attribute - ->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes()) - ->setFlatAddChildData($this->getFlatHelper()->isAddChildData()) - ->getFlatIndexes(); - if (is_null($indexes)) { - continue; - } - $this->_indexes = array_merge($this->_indexes, $indexes); - } - - $indexesObject = new Varien_Object(); - $indexesObject->setIndexes($this->_indexes); - Mage::dispatchEvent('catalog_product_flat_prepare_indexes', array( - 'indexes' => $indexesObject - )); - $this->_indexes = $indexesObject->getIndexes(); - } - return $this->_indexes; - } - - /** - * Compare Flat style with Describe style columns - * - * If column a different - return false - * - * @param array $column - * @param array $describe - * @return bool - */ - protected function _compareColumnProperties($column, $describe) - { - $type = $column['type']; - $length = null; - $precision = null; - $scale = null; - - $matches = array(); - if (preg_match('/^((?:var)?char)\((\d+)\)/', $type, $matches)) { - $type = $matches[1]; - $length = $matches[2]; - } else if (preg_match('/^decimal\((\d+),(\d+)\)/', $type, $matches)) { - $type = 'decimal'; - $precision = $matches[1]; - $scale = $matches[2]; - } else if (preg_match('/^float\((\d+),(\d+)\)/', $type, $matches)) { - $type = 'float'; - $precision = $matches[1]; - $scale = $matches[2]; - } else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)?/', $type, $matches)) { - $type = $matches[1]; - } - - return ($describe['DATA_TYPE'] == $type) - && ($describe['DEFAULT'] == $column['default']) - && ((bool)$describe['NULLABLE'] == (bool)$column['is_null']) - && ((bool)$describe['UNSIGNED'] == (bool)$column['unsigned']) - && ($describe['LENGTH'] == $length) - && ($describe['SCALE'] == $scale) - && ($describe['PRECISION'] == $precision); - } - - /** - * Retrieve column definition fragment - * - * Example: `field_name` smallint(5) unsigned NOT NULL default '0' - * - * @param string $fieldName - * @param array $fieldProp - * @return string - */ - protected function _sqlColunmDefinition($fieldName, $fieldProp) - { - $fieldNameQuote = $this->_getWriteAdapter()->quoteIdentifier($fieldName); - - /** - * Process the case when 'is_null' prohibits null value, and 'default' proposed to be null - * It just means that default value not specified - */ - if (false === $fieldProp['is_null'] && null === $fieldProp['default']) { - $defaultValue = ''; - } else { - $defaultValue = $fieldProp['default'] === null ? ' DEFAULT NULL' : $this->_getReadAdapter() - ->quoteInto(' DEFAULT ?', $fieldProp['default']); - } - - return "{$fieldNameQuote} {$fieldProp['type']}" - . ($fieldProp['unsigned'] ? ' UNSIGNED' : '') - . ($fieldProp['extra'] ? ' ' . $fieldProp['extra'] : '') - . ($fieldProp['is_null'] === false ? ' NOT NULL' : '') - . $defaultValue; - } - - /** - * Retrieve index definition fragment - * - * Example: INDEX `IDX_NAME` (`field_id`) - * - * @param string $indexName - * @param array $indexProp - * @return string - */ - protected function _sqlIndexDefinition($indexName, $indexProp) - { - $fields = $indexProp['fields']; - if (is_array($fields)) { - $fieldSql = array(); - foreach ($fields as $field) { - $fieldSql[] = $this->_getReadAdapter()->quoteIdentifier($field); - } - $fieldSql = join(',', $fieldSql); - } - else { - $fieldSql = $this->_getReadAdapter()->quoteIdentifier($fields); - } - - $indexNameQuote = $this->_getReadAdapter()->quoteIdentifier($indexName); - switch (strtolower($indexProp['type'])) { - case 'primary': - $condition = 'PRIMARY KEY'; - break; - case 'unique': - $condition = 'UNIQUE ' . $indexNameQuote; - break; - case 'fulltext': - $condition = 'FULLTEXT ' . $indexNameQuote; - break; - default: - $condition = 'INDEX ' . $indexNameQuote; - break; - } - - return sprintf('%s (%s)', $condition, $fieldSql); - } - - /** - * Prepare flat table for store - * - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function prepareFlatTable($store) - { - $columns = $this->getFlatColumns(); - $indexes = $this->getFlatIndexes(); - - $maxIndex = Mage::getConfig()->getNode(self::XML_NODE_MAX_INDEX_COUNT); - - if (count($indexes) > $maxIndex) { - Mage::throwException(Mage::helper('catalog')->__("The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module.", count($indexes), $maxIndex)); - } - - $tableName = $this->getFlatTableName($store); - $tableNameQuote = $this->_getWriteAdapter()->quoteIdentifier($tableName); - if (!$this->_isFlatTableExists($store)) { - $sql = "CREATE TABLE {$tableNameQuote} (\n"; - foreach ($columns as $field => $fieldProp) { - $sql .= sprintf(" %s,\n", - $this->_sqlColunmDefinition($field, $fieldProp)); - } - foreach ($indexes as $indexName => $indexProp) { - $sql .= sprintf(" %s,\n", - $this->_sqlIndexDefinition($indexName, $indexProp)); - } - - $sql .= " CONSTRAINT `FK_CATALOG_PRODUCT_FLAT_{$store}_ENTITY` FOREIGN KEY (`entity_id`)" - . " REFERENCES `{$this->getTable('catalog/product')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE"; - if ($this->getFlatHelper()->isAddChildData()) { - $sql .= ",\n CONSTRAINT `FK_CATALOG_PRODUCT_FLAT_{$store}_CHILD` FOREIGN KEY (`child_id`)" - . " REFERENCES `{$this->getTable('catalog/product')}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE"; - } - $sql .= "\n) ENGINE=InnoDB DEFAULT CHARSET=utf8"; - $this->_getWriteAdapter()->query($sql); - - $this->_existsFlatTables[$store] = true; - } - else { - $this->_getWriteAdapter()->resetDdlCache($tableName); - $describe = $this->_getWriteAdapter()->describeTable($tableName); - $indexList = $this->_getWriteAdapter()->getIndexList($tableName); - - $addColumns = array_diff_key($columns, $describe); - $dropColumns = array_diff_key($describe, $columns); - $modifyColumns = array(); - - $addIndexes = array_diff_key($indexes, $indexList); - $dropIndexes = array_diff_key($indexList, $indexes); - $addConstraints = array(); - - if (!$this->getFlatHelper()->isAddChildData() && isset($describe['is_child'])) { - $this->_getWriteAdapter()->delete($tableName, 'is_child=1'); - $this->_getWriteAdapter()->dropForeignKey($tableName, "FK_CATALOG_PRODUCT_FLAT_{$store}_CHILD"); - } - if ($this->getFlatHelper()->isAddChildData() && !isset($describe['is_child'])) { - $this->_getWriteAdapter()->truncate($tableName); - $dropIndexes['PRIMARY'] = $indexList['PRIMARY']; - $addIndexes['PRIMARY'] = $indexes['PRIMARY']; - $addConstraints["FK_CATALOG_PRODUCT_FLAT_{$store}_CHILD"] = array( - 'table_index' => 'child_id', - 'ref_table' => $this->getTable('catalog/product'), - 'ref_index' => 'entity_id', - 'on_update' => 'CASCADE', - 'on_delete' => 'CASCADE' - ); - } - - foreach ($columns as $field => $fieldProp) { - if (isset($describe[$field]) - && !$this->_compareColumnProperties($fieldProp, $describe[$field])) { - $modifyColumns[$field] = $fieldProp; - } - } - - foreach ($indexList as $indexName => $indexProp) { - if (isset($indexes[$indexName]) && ($indexes[$indexName]['type'] != $indexProp['type'])) { - $dropIndexes[$indexName] = $indexProp; - $addIndexes[$indexName] = $indexes[$indexName]; - } - } - - if ($addColumns or $dropColumns or $modifyColumns or $addIndexes or $dropIndexes) { - $sql = "ALTER TABLE {$tableNameQuote}"; - // drop columns - foreach ($dropColumns as $columnName => $columnProp) { - $columnNameQuote = $this->_getWriteAdapter()->quoteIdentifier($columnName); - $sql .= " DROP COLUMN {$columnNameQuote},"; - } - - // drop indexes - foreach ($dropIndexes as $indexName => $indexProp) { - if ($indexName == 'PRIMARY') { - $sql .= " DROP PRIMARY KEY,"; - } - else { - $indexNameQuote = $this->_getWriteAdapter()->quoteIdentifier($indexName); - $sql .= " DROP INDEX {$indexNameQuote},"; - } - } - - // modify colunm - foreach ($modifyColumns as $columnName => $columnProp) { - $sql .= sprintf(' MODIFY COLUMN %s,', - $this->_sqlColunmDefinition($columnName, $columnProp)); - } - - // add columns - foreach ($addColumns as $columnName => $columnProp) { - $sql .= sprintf(' ADD COLUMN %s', - $this->_sqlColunmDefinition($columnName, $columnProp)); - $afterColumn = $this->_arrayPrevKey($columns, $columnName); - if ($afterColumn) { - $sql .= ' AFTER ' . $this->_getWriteAdapter()->quoteIdentifier($afterColumn); - } - $sql .= ','; - } - // add indexes - foreach ($addIndexes as $indexName => $indexProp) { - $sql .= sprintf(' ADD %s,', - $this->_sqlIndexDefinition($indexName, $indexProp)); - } - $sql = rtrim($sql, ","); - $this->_getWriteAdapter()->query($sql); - } - - foreach ($addConstraints as $constraintName => $constraintProp) { - $this->_getWriteAdapter()->addConstraint( - $constraintName, - $tableName, - $constraintProp['table_index'], - $constraintProp['ref_table'], - $constraintProp['ref_index'], - $constraintProp['on_delete'], - $constraintProp['on_update'] - ); - } - } - - return $this; - } - - /** - * Add or Update static attributes - * - * @param int $store - * @param int|array $productIds update only product(s) - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateStaticAttributes($store, $productIds = null) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $website = Mage::app()->getStore($store)->getWebsite()->getId(); - $status = $this->getAttribute('status'); - /* @var $status Mage_Eav_Model_Entity_Attribute */ - $fieldList = array('entity_id', 'type_id', 'attribute_set_id'); - $colsList = array('entity_id', 'type_id', 'attribute_set_id'); - if ($this->getFlatHelper()->isAddChildData()) { - $fieldList = array_merge($fieldList, array('child_id', 'is_child')); - $isChild = new Zend_Db_Expr('0'); - $colsList = array_merge($colsList, array('entity_id', $isChild)); - } - - $columns = $this->getFlatColumns(); - $select = $this->_getWriteAdapter()->select() - ->from( - array('e' => $this->getTable('catalog/product')), - $colsList) - ->join( - array('wp' => $this->getTable('catalog/product_website')), - "`e`.`entity_id`=`wp`.`product_id` AND `wp`.`website_id`={$website}", - array()) - ->joinLeft( - array('t1' => $status->getBackend()->getTable()), - "`e`.`entity_id`=`t1`.`entity_id`", - array()) - ->joinLeft( - array('t2' => $status->getBackend()->getTable()), - "t2.entity_id = t1.entity_id" - . " AND t1.entity_type_id = t2.entity_type_id" - . " AND t1.attribute_id = t2.attribute_id" - . " AND t2.store_id = {$store}", - array()) - ->where("t1.entity_type_id=?", $status->getEntityTypeId()) - ->where("t1.attribute_id=?", $status->getId()) - ->where("t1.store_id=?", 0) - ->where("IF(`t2`.`value_id`>0, `t2`.`value`, `t1`.`value`)=?", Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - foreach ($this->getAttributes() as $attributeCode => $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - if ($attribute->getBackend()->getType() == 'static') { - if (!isset($columns[$attributeCode])) { - continue; - } - $fieldList[] = $attributeCode; - $select->columns($attributeCode, 'e'); - } - } - - if (!is_null($productIds)) { - $select->where('e.entity_id IN(?)', $productIds); - } - - $sql = $select->insertFromSelect($this->getFlatTableName($store), $fieldList); - $this->_getWriteAdapter()->query($sql); - return $this; - } - - /** - * Remove non website products - * - * @param int $store - * @param int|array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function cleanNonWebsiteProducts($store, $productIds = null) - { - $website = Mage::app()->getStore($store)->getWebsite()->getId(); - - $joinCond = "`e`.`entity_id`=`wp`.`product_id` AND `wp`.`website_id`={$website}"; - if ($this->getFlatHelper()->isAddChildData()) { - $joinCond .= " AND `e`.`child_id`=`wp`.`product_id`"; - } - - $select = $this->_getWriteAdapter()->select() - ->from( - array('e' => $this->getFlatTableName($store)), - null) - ->joinLeft( - array('wp' => $this->getTable('catalog/product_website')), - $joinCond, - array()); - if (!is_null($productIds)) { - $cond = array( - $this->_getWriteAdapter()->quoteInto('e.entity_id IN(?)', $productIds) - ); - if ($this->getFlatHelper()->isAddChildData()) { - $cond[] = $this->_getWriteAdapter()->quoteInto('e.child_id IN(?)', $productIds); - } - $select->where(join(' OR ', $cond)); - } - - $sql = $select->deleteFromSelect('e'); - $this->_getWriteAdapter()->query($sql); - - return $this; - } - - /** - * Update attribute flat data - * - * @param Mage_Eav_Model_Entity_Attribute $attribute - * @param int $store - * @param int|array $productIds update only product(s) - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateAttribute($attribute, $store, $productIds = null) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName($store)); - - if ($attribute->getBackend()->getType() == 'static') { - if (!isset($describe[$attribute->getAttributeCode()])) { - return $this; - } - $select = $this->_getWriteAdapter()->select() - ->join( - array('main_table' => $this->getTable('catalog/product')), - 'main_table.entity_id=e.entity_id ', - array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()) - ); - if ($this->getFlatHelper()->isAddChildData()) { - $select->where("e.is_child=?", 0); - } - if (!is_null($productIds)) { - $select->where('main_table.entity_id IN(?)', $productIds); - } - $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store))); - $this->_getWriteAdapter()->query($sql); - } - else { - $columns = $attribute->getFlatColumns(); - if (!$columns) { - return $this; - } - foreach (array_keys($columns) as $columnName) { - if (!isset($describe[$columnName])) { - return $this; - } - } - - $select = $attribute->getFlatUpdateSelect($store); - if ($select instanceof Varien_Db_Select) { - if (!is_null($productIds)) { - $select->where('e.entity_id IN(?)', $productIds); - } - $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store))); - $this->_getWriteAdapter()->query($sql); - } - } - return $this; - } - - /** - * Update non static EAV attributes flat data - * - * @param int $store - * @param int|array $productIds update only product(s) - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateEavAttributes($store, $productIds = null) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - foreach ($this->getAttributes() as $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - if ($attribute->getBackend()->getType() != 'static') { - $this->updateAttribute($attribute, $store, $productIds); - } - } - return $this; - } - - /** - * Update events observer attributes - * - * @param int $store - * @return Mage_Catalog_Model_Product_Flat_Indexer - */ - public function updateEventAttributes($store = null) - { - Mage::dispatchEvent('catalog_product_flat_rebuild', array( - 'store_id' => $store, - 'table' => $this->getFlatTableName($store) - )); - } - - /** - * Retrieve Product Type Instances - * as key - type code, value - instance model - * - * @return array - */ - public function getProductTypeInstances() - { - if (is_null($this->_productTypes)) { - $this->_productTypes = array(); - $productEmulator = new Varien_Object(); - - foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) { - $productEmulator->setTypeId($typeId); - $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type') - ->factory($productEmulator); - } - } - return $this->_productTypes; - } - - /** - * Update relation products - * - * @param int $store - * @param int|array $productIds Update child product(s) only - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateRelationProducts($store, $productIds = null) - { - if (!$this->getFlatHelper()->isAddChildData()) { - return $this; - } - - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - foreach ($this->getProductTypeInstances() as $typeInstance) { - if (!$typeInstance->isComposite()) { - continue; - } - $relation = $typeInstance->getRelationInfo(); - if ($relation - and $relation->getTable() - and $relation->getParentFieldName() - and $relation->getChildFieldName() - ) { - $columns = $this->getFlatColumns(); - $fieldList = array_keys($columns); - unset($columns['entity_id']); - unset($columns['child_id']); - unset($columns['is_child']); - - $select = $this->_getWriteAdapter()->select() - ->from( - array('t' => $this->getTable($relation->getTable())), - array($relation->getParentFieldName(), $relation->getChildFieldName(), new Zend_Db_Expr('1'))) - ->join( - array('e' => $this->getFlatTableName($store)), - "`e`.`entity_id`=`t`.`{$relation->getChildFieldName()}`", - array_keys($columns) - ); - if (!is_null($relation->getWhere())) { - $select->where($relation->getWhere()); - } - if (!is_null($productIds)) { - $cond = array( - $this->_getWriteAdapter()->quoteInto("{$relation->getChildFieldName()} IN(?)", $productIds), - $this->_getWriteAdapter()->quoteInto("{$relation->getParentFieldName()} IN(?)", $productIds) - ); - - $select->where(join(' OR ', $cond)); - } - $sql = $select->insertFromSelect($this->getFlatTableName($store), $fieldList); - $this->_getWriteAdapter()->query($sql); - } - } - - return $this; - } - - /** - * Update children data from parent - * - * @param int $store - * @param int|array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateChildrenDataFromParent($store, $productIds = null) - { - if (!$this->getFlatHelper()->isAddChildData()) { - return $this; - } - - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $select = $this->_getWriteAdapter()->select(); - foreach (array_keys($this->getFlatColumns()) as $columnName) { - if ($columnName == 'entity_id' || $columnName == 'child_id' || $columnName == 'is_child') { - continue; - } - $select->columns(array($columnName => new Zend_Db_Expr('`t1`.`'. $columnName.'`'))); - } - $select - ->joinLeft( - array('t1' => $this->getFlatTableName($store)), - "`t2`.`child_id`=`t1`.`entity_id` AND `t1`.`is_child`=0", - array()) - ->where('t2.is_child=1'); - - if (!is_null($productIds)) { - $select->where('t2.child_id IN(?)', $productIds); - } - - $sql = $select->crossUpdateFromSelect(array('t2' => $this->getFlatTableName($store))); - $this->_getWriteAdapter()->query($sql); - - return $this; - } - - /** - * Clean unused relation products - * - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function cleanRelationProducts($store) - { - if (!$this->getFlatHelper()->isAddChildData()) { - return $this; - } - - foreach ($this->getProductTypeInstances() as $typeInstance) { - if (!$typeInstance->isComposite()) { - continue; - } - $relation = $typeInstance->getRelationInfo(); - if ($relation - and $relation->getTable() - and $relation->getParentFieldName() - and $relation->getChildFieldName() - ) { - $select = $this->_getWriteAdapter()->select() - ->distinct(true) - ->from( - $this->getTable($relation->getTable()), - "{$relation->getParentFieldName()}" - ) - ; - $joinLeftCond = null; - if (!is_null($relation->getWhere())) { - $select->where($relation->getWhere()); - $joinLeftCond = ' AND ' . $relation->getWhere(); - } - - $entitySelect = new Zend_Db_Expr($select->__toString()); - - $select = $this->_getWriteAdapter()->select() - ->from( - array('e' => $this->getFlatTableName($store)), - null - ) - ->joinLeft( - array('t' => $this->getTable($relation->getTable())), - "e.entity_id=t.{$relation->getParentFieldName()} AND e.child_id=t.{$relation->getChildFieldName()}" - . $joinLeftCond, - array()) - ->where("e.is_child=?", 1) - ->where("e.entity_id IN(?)", $entitySelect) - ->where("t.{$relation->getChildFieldName()} IS NULL"); - - $sql = $select->deleteFromSelect('e'); - $this->_getWriteAdapter()->query($sql); - } - } - - return $this; - } - - /** - * Remove product data from flat - * - * @param int|array $productIds - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function removeProduct($productIds, $store) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $cond = array( - $this->_getWriteAdapter()->quoteInto('entity_id IN(?)', $productIds) - ); - if ($this->getFlatHelper()->isAddChildData()) { - $cond[] = $this->_getWriteAdapter()->quoteInto('child_id IN(?)', $productIds); - } - $cond = join(' OR ', $cond); - $this->_getWriteAdapter()->delete($this->getFlatTableName($store), $cond); - - return $this; - } - - /** - * Remove children from parent product - * - * @param int|array $productIds - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function removeProductChildren($productIds, $store) - { - if (!$this->getFlatHelper()->isAddChildData()) { - return $this; - } - $cond = array( - $this->_getWriteAdapter()->quoteInto('entity_id IN(?)', $productIds), - $this->_getWriteAdapter()->quoteInto('is_child=?', 1), - ); - $this->_getWriteAdapter()->delete($this->getFlatTableName($store), $cond); - - return $this; - } - - /** - * Update flat data for product - * - * @param int|array $productIds - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function updateProduct($productIds, $store) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $this->saveProduct($productIds, $store); - - Mage::dispatchEvent('catalog_product_flat_update_product', array( - 'store_id' => $store, - 'table' => $this->getFlatTableName($store), - 'product_ids' => $productIds - )); - - return $this; - } - - /** - * Save product(s) data for store - * - * @param int|array $productIds - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function saveProduct($productIds, $store) - { - if (!$this->_isFlatTableExists($store)) { - return $this; - } - - $this->updateStaticAttributes($store, $productIds); - $this->updateEavAttributes($store, $productIds); - - return $this; - } - - /** - * Delete flat table process - * - * @param int $store - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer - */ - public function deleteFlatTable($store) - { - if ($this->_isFlatTableExists($store)) { - $tableName = $this->_getWriteAdapter()->quoteIdentifier($this->getFlatTableName($store)); - $sql = sprintf('DROP TABLE IF EXISTS %s', $tableName); - $this->_getWriteAdapter()->query($sql); - } - - return $this; - } - - /** - * Check is flat table for store exists - * - * @param int $store - * @return bool - */ - protected function _isFlatTableExists($store) - { - if (!isset($this->_existsFlatTables[$store])) { - $tableName = $this->getFlatTableName($store); - $tableExistsSql = $this->_getWriteAdapter() - ->quoteInto("SHOW TABLE STATUS LIKE ?", $tableName); - if ($this->_getWriteAdapter()->fetchRow($tableExistsSql)) { - $this->_existsFlatTables[$store] = true; - } else { - $this->_existsFlatTables[$store] = false; - } - } - return $this->_existsFlatTables[$store]; - } - - /** - * Retrieve previous key from array by key - * - * @param array $array - * @param mixed $key - * @return mixed - */ - protected function _arrayPrevKey(array $array, $key) - { - $prev = false; - foreach (array_keys($array) as $k) { - if ($k == $key) { - return $prev; - } - $prev = $k; - } - return false; - } - - /** - * Retrieve next key from array by key - * - * @param array $array - * @param mixed $key - * @return mixed - */ - protected function _arrayNextKey(array $array, $key) - { - $next = false; - foreach (array_keys($array) as $k) { - if ($next === true) { - return $k; - } - if ($k == $key) { - $next = true; - } - } - return false; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Abstract.php index d3f11d0602..111cf69723 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,167 +32,7 @@ * @package Mage_Catalog * @author Magento Core Team */ -abstract class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract - extends Mage_Index_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract + extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract { - /** - * Retrieve catalog_product attribute instance by attribute code - * - * @param string $attributeCode - * @return Mage_Catalog_Model_Resource_Eav_Attribute - */ - protected function _getAttribute($attributeCode) - { - return Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode); - } - - /** - * Add attribute join condition to select and return Zend_Db_Expr - * attribute value definition - * - * If $condition is not empty apply limitation for select - * - * @param Varien_Db_Select $select - * @param string $attrCode the attribute code - * @param string|Zend_Db_Expr $entity the entity field or expression for condition - * @param string|Zend_Db_Expr $store the store field or expression for condition - * @param Zend_Db_Expr $condition the limitation condition - * @param bool $required if required or has condition used INNER join, else - LEFT - * @return Zend_Db_Expr the attribute value expression - */ - protected function _addAttributeToSelect($select, $attrCode, $entity, $store, $condition = null, $required = false) - { - $attribute = $this->_getAttribute($attrCode); - $attributeId = $attribute->getAttributeId(); - $attributeTable = $attribute->getBackend()->getTable(); - $joinType = !is_null($condition) || $required ? 'join' : 'joinLeft'; - - if ($attribute->isScopeGlobal()) { - $alias = 'ta_' . $attrCode; - $select->$joinType( - array($alias => $attributeTable), - "{$alias}.entity_id = {$entity} AND {$alias}.attribute_id = {$attributeId}" - . " AND {$alias}.store_id = 0", - array() - ); - $expression = new Zend_Db_Expr("{$alias}.value"); - } else { - $dAlias = 'tad_' . $attrCode; - $sAlias = 'tas_' . $attrCode; - - $select->$joinType( - array($dAlias => $attributeTable), - "{$dAlias}.entity_id = {$entity} AND {$dAlias}.attribute_id = {$attributeId}" - . " AND {$dAlias}.store_id = 0", - array() - ); - $select->joinLeft( - array($sAlias => $attributeTable), - "{$sAlias}.entity_id = {$entity} AND {$sAlias}.attribute_id = {$attributeId}" - . " AND {$sAlias}.store_id = {$store}", - array() - ); - $expression = new Zend_Db_Expr("IF({$sAlias}.value_id > 0, {$sAlias}.value, {$dAlias}.value)"); - } - - if (!is_null($condition)) { - $select->where("{$expression}{$condition}"); - } - - return $expression; - } - - /** - * Add website data join to select - * - * If add default store join also limitation of only has default store website - * - * Joined table has aliases - * cw for website table, - * csg for store group table (joined by website default group) - * cs for store table (joined by website default store) - * - * @param Varien_Db_Select $select the select object - * @param bool $store add default store join - * @param string|Zend_Db_Expr $joinCondition the limitation for website_id - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract - */ - protected function _addWebsiteJoinToSelect($select, $store = true, $joinCondition = null) - { - if (!is_null($joinCondition)) { - $joinCondition = 'cw.website_id = ' . $joinCondition; - } - - $select->join( - array('cw' => $this->getTable('core/website')), - $joinCondition, - array() - ); - - if ($store) { - $select->join( - array('csg' => $this->getTable('core/store_group')), - 'csg.group_id = cw.default_group_id', - array()) - ->join( - array('cs' => $this->getTable('core/store')), - 'cs.store_id = csg.default_store_id', - array()); - } - - return $this; - } - - /** - * Add join for catalog/product_website table - * - * Joined table has alias pw - * - * @param Varien_Db_Select $select the select object - * @param string|Zend_Db_Expr $website the limitation of website_id - * @param string|Zend_Db_Expr $product the limitation of product_id - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract - */ - protected function _addProductWebsiteJoinToSelect($select, $website, $product) - { - $select->join( - array('pw' => $this->getTable('catalog/product_website')), - "pw.product_id = {$product} AND pw.website_id = {$website}", - array() - ); - - return $this; - } - - /** - * Retrieve product relations by children - * - * @param int|array $childIds - * @return array - */ - public function getRelationsByChild($childIds) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), 'parent_id') - ->where('child_id IN(?)', $childIds); - - return $write->fetchCol($select); - } - - /** - * Retrieve product relations by parents - * - * @param int|array $childIds - * @return array - */ - public function getRelationsByParent($parentIds) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), 'child_id') - ->where('parent_id IN(?)', $parentIds); - - return $write->fetchCol($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav.php index 66dad8cdab..f2c0ad3cec 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,176 +28,10 @@ /** * Catalog Product Eav Indexer Resource Model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav extends Mage_Catalog_Model_Resource_Product_Indexer_Eav { - /** - * EAV Indexers by type - * - * @var array - */ - protected $_types; - - /** - * Define main index table - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_eav', 'entity_id'); - } - - /** - * Retrieve array of EAV type indexers - * - * @return array - */ - public function getIndexers() - { - if (is_null($this->_types)) { - $this->_types = array( - 'source' => Mage::getResourceModel('catalog/product_indexer_eav_source'), - 'decimal' => Mage::getResourceModel('catalog/product_indexer_eav_decimal'), - ); - } - - return $this->_types; - } - - /** - * Retrieve indexer instance by type - * - * @param string $type - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - */ - public function getIndexer($type) - { - $indexers = $this->getIndexers(); - if (!isset($indexers[$type])) { - Mage::throwException(Mage::helper('catalog')->__('Unknown EAV indexer type "%s".', $type)); - } - return $indexers[$type]; - } - - /** - * Process product save. - * Method is responsible for index support - * when product was saved and assigned categories was changed. - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function catalogProductSave(Mage_Index_Model_Event $event) - { - $productId = $event->getEntityPk(); - $data = $event->getNewData(); - - /** - * Check if filterable attribute values were updated - */ - if (!isset($data['reindex_eav'])) { - return $this; - } - - foreach ($this->getIndexers() as $indexer) { - /* @var $indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract */ - $indexer->reindexEntities($productId); - } - - return $this; - } - - /** - * Process Product Delete - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function catalogProductDelete(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_eav_parent_ids'])) { - return $this; - } - - foreach ($this->getIndexers() as $indexer) { - /* @var $indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract */ - $indexer->reindexEntities($data['reindex_eav_parent_ids']); - } - - return $this; - } - - /** - * Process Product Mass Update - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function catalogProductMassAction(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_eav_product_ids'])) { - return $this; - } - - foreach ($this->getIndexers() as $indexer) { - /* @var $indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract */ - $indexer->reindexEntities($data['reindex_eav_product_ids']); - } - - return $this; - } - - /** - * Process Catalog Eav Attribute Save - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function catalogEavAttributeSave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_attribute'])) { - return $this; - } - - $indexer = $this->getIndexer($data['attribute_index_type']); - - $indexer->reindexAttribute($event->getEntityPk(), !empty($data['is_indexable'])); - - return $this; - } - - /** - * Rebuild all index data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function reindexAll() - { - $this->useIdxTable(true); - foreach ($this->getIndexers() as $indexer) { - /* @var $indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract */ - $indexer->reindexAll(); - } - - return $this; - } - - /** - * Retrieve temporary source index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_eav_indexer_idx'); - } - return $this->getTable('catalog/product_eav_indexer_tmp'); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Abstract.php index 1c5919d7f4..e3853c0e9b 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,237 +32,7 @@ * @package Mage_Catalog * @author Magento Core Team */ -abstract class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract + extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract { - /** - * Rebuild all index data - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Decimal - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->clearTemporaryIndexTable(); - $this->_prepareIndex(); - $this->_prepareRelationIndex(); - $this->_removeNotVisibleEntityFromIndex(); - - $this->syncData(); - - return $this; - } - - /** - * Rebuild index data by entities - * - * @param int|array $processIds - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - */ - public function reindexEntities($processIds) - { - $adapter = $this->_getWriteAdapter(); - - $this->clearTemporaryIndexTable(); - - if (!is_array($processIds)) { - $processIds = array($processIds); - } - - $parentIds = $this->getRelationsByChild($processIds); - if ($parentIds) { - $processIds = array_unique(array_merge($processIds, $parentIds)); - } - $childIds = $this->getRelationsByParent($parentIds); - if ($childIds) { - $processIds = array_unique(array_merge($processIds, $childIds)); - } - - $this->_prepareIndex($processIds); - $this->_prepareRelationIndex($processIds); - $this->_removeNotVisibleEntityFromIndex(); - - $adapter->beginTransaction(); - try { - // remove old index - $where = $adapter->quoteInto('entity_id IN(?)', $processIds); - $adapter->delete($this->getMainTable(), $where); - - // insert new index - $this->useDisableKeys(false); - $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); - $this->useDisableKeys(true); - - $adapter->commit(); - } catch (Exception $e) { - $adapter->rollBack(); - throw $e; - } - - return $this; - } - - /** - * Rebuild index data by attribute id - * If attribute is not indexable remove data by attribute - * - * @param int $attributeId - * @param bool $isIndexable - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - */ - public function reindexAttribute($attributeId, $isIndexable = true) - { - if (!$isIndexable) { - $this->_removeAttributeIndexData($attributeId); - } else { - $this->clearTemporaryIndexTable(); - - $this->_prepareIndex(null, $attributeId); - $this->_prepareRelationIndex(); - $this->_removeNotVisibleEntityFromIndex(); - - $this->_synchronizeAttributeIndexData($attributeId); - } - - return $this; - } - - /** - * Prepare data index for indexable attributes - * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Decimal - */ - abstract protected function _prepareIndex($entityIds = null, $attributeId = null); - - /** - * Remove Not Visible products from temporary data index - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - protected function _removeNotVisibleEntityFromIndex() - { - $write = $this->_getWriteAdapter(); - $idxTable = $this->getIdxTable(); - - $select = $write->select() - ->from($idxTable, null); - - $condition = $write->quoteInto('=?',Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE); - $this->_addAttributeToSelect($select, 'visibility', $idxTable.'.entity_id', $idxTable.'.store_id', $condition); - - $query = $select->deleteFromSelect($idxTable); - $write->query($query); - - return $this; - } - - /** - * Prepare data index for product relations - * - * @param array $parentIds the parent entity ids limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - protected function _prepareRelationIndex($parentIds = null) - { - $write = $this->_getWriteAdapter(); - $idxTable = $this->getIdxTable(); - - $select = $write->select() - ->from(array('l' => $this->getTable('catalog/product_relation')), 'parent_id') - ->join( - array('cs' => $this->getTable('core/store')), - '', - array()) - ->join( - array('i' => $idxTable), - 'l.child_id=i.entity_id AND cs.store_id = i.store_id', - array('attribute_id', 'store_id', 'value')); - if (!is_null($parentIds)) { - $select->where('l.parent_id IN(?)', $parentIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('l.parent_id'), - 'website_field' => new Zend_Db_Expr('cs.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertIgnoreFromSelect($idxTable); - $write->query($query); - - return $this; - } - - /** - * Retrieve condition for retrieve indexable attribute select - * - * the catalog/eav_attribute table must have alias is ca - * - * @return string - */ - protected function _getIndexableAttributesCondition() - { - $conditions = array( - 'ca.is_filterable_in_search>0', - 'ca.is_visible_in_advanced_search>0', - 'ca.is_filterable>0' - ); - - return join(' OR ', $conditions); - } - - /** - * Remove index data from index by attribute id - * - * @param int $attributeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - */ - protected function _removeAttributeIndexData($attributeId) - { - $adapter = $this->_getWriteAdapter(); - $adapter->beginTransaction(); - try { - $where = $adapter->quoteInto('attribute_id=?', $attributeId); - $adapter->delete($this->getMainTable(), $where); - $adapter->commit(); - } catch (Exception $e) { - $adapter->rollback(); - throw $e; - } - - return $this; - } - - /** - * Synchronize temporary index table with index table by attribute id - * - * @param int $attributeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract - */ - protected function _synchronizeAttributeIndexData($attributeId) - { - $adapter = $this->_getWriteAdapter(); - $adapter->beginTransaction(); - try { - // remove index by attribute - $where = $adapter->quoteInto('attribute_id=?', $attributeId); - $adapter->delete($this->getMainTable(), $where); - - // insert new index - $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); - - $adapter->commit(); - } catch (Exception $e) { - $adapter->rollback(); - throw $e; - } - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Decimal.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Decimal.php index 6fc3a6c9e6..0cc14b2c1a 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Decimal.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Decimal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,112 +33,6 @@ * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Decimal - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract + extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Decimal { - /** - * Initialize connection and define main index table - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_eav_decimal', 'entity_id'); - } - - /** - * Prepare data index for indexable attributes - * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Decimal - */ - protected function _prepareIndex($entityIds = null, $attributeId = null) - { - $write = $this->_getWriteAdapter(); - $idxTable = $this->getIdxTable(); - // prepare select attributes - if (is_null($attributeId)) { - $attrIds = $this->_getIndexableAttributes(); - } else { - $attrIds = array($attributeId); - } - - if (!$attrIds) { - return $this; - } - - $select = $write->select() - ->from( - array('pdd' => $this->getValueTable('catalog/product', 'decimal')), - array('entity_id', 'attribute_id')) - ->join( - array('cs' => $this->getTable('core/store')), - '', - array('store_id')) - ->joinLeft( - array('pds' => $this->getValueTable('catalog/product', 'decimal')), - 'pds.entity_id = pdd.entity_id AND pds.attribute_id = pdd.attribute_id' - . ' AND pds.store_id=cs.store_id', - array('value' => new Zend_Db_Expr('IF(pds.value_id > 0, pds.value, pdd.value)'))) - ->where('pdd.store_id=?', 0) - ->where('cs.store_id!=?', 0) - ->where('pdd.attribute_id IN(?)', $attrIds) - ->where('IF(pds.value_id > 0, pds.value, pdd.value) IS NOT NULL'); - - $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'pdd.entity_id', 'cs.store_id', $statusCond); - - if (!is_null($entityIds)) { - $select->where('pdd.entity_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('pdd.entity_id'), - 'website_field' => new Zend_Db_Expr('cs.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertFromSelect($idxTable); - $write->query($query); - - return $this; - } - - /** - * Retrieve decimal indexable attributes - * - * @return array - */ - protected function _getIndexableAttributes() - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from(array('ca' => $this->getTable('catalog/eav_attribute')), 'attribute_id') - ->join( - array('ea' => $this->getTable('eav/attribute')), - 'ca.attribute_id = ea.attribute_id', - array()) - ->where('ea.attribute_code<>?', 'price') - ->where($this->_getIndexableAttributesCondition()) - ->where('ea.backend_type=?', 'decimal'); - - return $adapter->fetchCol($select); - } - - /** - * Retrieve temporary decimal index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_eav_decimal_indexer_idx'); - } - return $this->getTable('catalog/product_eav_decimal_indexer_tmp'); - } } - diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Source.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Source.php index 3bd23761fe..4698d34979 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Source.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Eav/Source.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,245 +33,6 @@ * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Source - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Abstract + extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source { - /** - * Initialize connection and define main index table - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_eav', 'entity_id'); - } - - /** - * Retrieve indexable eav attribute ids - * - * @param bool $multiSelect - * @return array - */ - protected function _getIndexableAttributes($multiSelect) - { - $select = $this->_getReadAdapter()->select() - ->from(array('ca' => $this->getTable('catalog/eav_attribute')), 'attribute_id') - ->join( - array('ea' => $this->getTable('eav/attribute')), - 'ca.attribute_id = ea.attribute_id', - array()) - ->where($this->_getIndexableAttributesCondition()); - - if ($multiSelect == true) { - $select->where('ea.backend_type = ?', 'varchar') - ->where('ea.frontend_input = ?', 'multiselect'); - } else { - $select->where('ea.backend_type = ?', 'int') - ->where('ea.frontend_input = ?', 'select'); - } - - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Prepare data index for indexable attributes - * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Decimal - */ - protected function _prepareIndex($entityIds = null, $attributeId = null) - { - $this->_prepareSelectIndex($entityIds, $attributeId); - $this->_prepareMultiselectIndex($entityIds, $attributeId); - - return $this; - } - - - /** - * Prepare data index for indexable select attributes - * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Source - */ - protected function _prepareSelectIndex($entityIds = null, $attributeId = null) - { - $adapter = $this->_getWriteAdapter(); - $idxTable = $this->getIdxTable(); - // prepare select attributes - if (is_null($attributeId)) { - $attrIds = $this->_getIndexableAttributes(false); - } else { - $attrIds = array($attributeId); - } - - if (!$attrIds) { - return $this; - } - - $select = $adapter->select() - ->from( - array('pid' => $this->getValueTable('catalog/product', 'int')), - array('entity_id', 'attribute_id')) - ->join( - array('cs' => $this->getTable('core/store')), - '', - array('store_id')) - ->joinLeft( - array('pis' => $this->getValueTable('catalog/product', 'int')), - 'pis.entity_id = pid.entity_id AND pis.attribute_id = pid.attribute_id' - . ' AND pis.store_id=cs.store_id', - array('value' => new Zend_Db_Expr('IF(pis.value_id > 0, pis.value, pid.value)'))) - ->where('pid.store_id=?', 0) - ->where('cs.store_id!=?', 0) - ->where('pid.attribute_id IN(?)', $attrIds) - ->where('IF(pis.value_id > 0, pis.value, pid.value) IS NOT NULL'); - - $statusCond = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'pid.entity_id', 'cs.store_id', $statusCond); - - if (!is_null($entityIds)) { - $select->where('pid.entity_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('pid.entity_id'), - 'website_field' => new Zend_Db_Expr('cs.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertFromSelect($idxTable); - $adapter->query($query); - - return $this; - } - - /** - * Prepare data index for indexable multiply select attributes - * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - protected function _prepareMultiselectIndex($entityIds = null, $attributeId = null) - { - $adapter = $this->_getWriteAdapter(); - - // prepare multiselect attributes - if (is_null($attributeId)) { - $attrIds = $this->_getIndexableAttributes(true); - } else { - $attrIds = array($attributeId); - } - - if (!$attrIds) { - return $this; - } - - // load attribute options - $options = array(); - $select = $adapter->select() - ->from($this->getTable('eav/attribute_option'), array('attribute_id', 'option_id')) - ->where('attribute_id IN(?)', $attrIds); - $query = $select->query(); - while ($row = $query->fetch()) { - $options[$row['attribute_id']][$row['option_id']] = true; - } - - // prepare get multiselect values query - $select = $adapter->select() - ->from( - array('pvd' => $this->getValueTable('catalog/product', 'varchar')), - array('entity_id', 'attribute_id')) - ->join( - array('cs' => $this->getTable('core/store')), - '', - array('store_id')) - ->joinLeft( - array('pvs' => $this->getValueTable('catalog/product', 'varchar')), - 'pvs.entity_id = pvd.entity_id AND pvs.attribute_id = pvd.attribute_id' - . ' AND pvs.store_id=cs.store_id', - array('value' => new Zend_Db_Expr('IF(pvs.value_id>0, pvs.value, pvd.value)'))) - ->where('pvd.store_id=?', 0) - ->where('cs.store_id!=?', 0) - ->where('pvd.attribute_id IN(?)', $attrIds); - - $statusCond = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'pvd.entity_id', 'cs.store_id', $statusCond); - - if (!is_null($entityIds)) { - $select->where('pvd.entity_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('pvd.entity_id'), - 'website_field' => new Zend_Db_Expr('cs.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $i = 0; - $data = array(); - $query = $select->query(); - while ($row = $query->fetch()) { - $values = explode(',', $row['value']); - foreach ($values as $valueId) { - if (isset($options[$row['attribute_id']][$valueId])) { - $data[] = array( - $row['entity_id'], - $row['attribute_id'], - $row['store_id'], - $valueId - ); - $i ++; - if ($i % 10000 == 0) { - $this->_saveIndexData($data); - $data = array(); - } - } - } - } - - $this->_saveIndexData($data); - unset($options); - unset($data); - - return $this; - } - - /** - * Save a data to temporary source index table - * - * @param array $data - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav_Source - */ - protected function _saveIndexData(array $data) - { - if (!$data) { - return $this; - } - $adapter = $this->_getWriteAdapter(); - $adapter->insertArray($this->getIdxTable(), array('entity_id', 'attribute_id', 'store_id', 'value'), $data); - return $this; - } - - /** - * Retrieve temporary source index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_eav_indexer_idx'); - } - return $this->getTable('catalog/product_eav_indexer_tmp'); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price.php index 4f4d893dfb..65be56043b 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,522 +28,11 @@ /** * Catalog Product Price Indexer Resource Model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price extends Mage_Index_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price + extends Mage_Catalog_Model_Resource_Product_Indexer_Price { - /** - * Default Product Type Price indexer resource model - * - * @var string - */ - protected $_defaultPriceIndexer = 'catalog/product_indexer_price_default'; - - /** - * Product Type Price indexer resource models - * - * @var array - */ - protected $_indexers; - - /** - * Define main index table - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_price', 'entity_id'); - } - - /** - * Retrieve parent ids and types by child id - * - * Return array with key product_id and value as product type id - * - * @param int $childId - * @return array - */ - public function getProductParentsByChild($childId) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from(array('l' => $this->getTable('catalog/product_relation')), array('parent_id')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'l.parent_id=e.entity_id', - array('e.type_id')) - ->where('l.child_id=?', $childId); - return $write->fetchPairs($select); - } - - /** - * Process produce delete - * - * If the deleted product was found in a composite product(s) update it - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - public function catalogProductDelete(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_price_parent_ids'])) { - return $this; - } - - $this->clearTemporaryIndexTable(); - - $processIds = array_keys($data['reindex_price_parent_ids']); - $parentIds = array(); - foreach ($data['reindex_price_parent_ids'] as $parentId => $parentType) { - $parentIds[$parentType][$parentId] = $parentId; - } - - $this->_copyRelationIndexData($processIds); - foreach ($parentIds as $parentType => $entityIds) { - $this->_getIndexer($parentType)->reindexEntity($entityIds); - } - - $this->_copyIndexDataToMainTable($parentIds); - - return $this; - } - - /** - * Copy data from temporary index table to main table by defined ids - * - * @param array $processIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - protected function _copyIndexDataToMainTable($processIds) - { - $write = $this->_getWriteAdapter(); - $write->beginTransaction(); - try { - // remove old index - $where = $write->quoteInto('entity_id IN(?)', $processIds); - $write->delete($this->getMainTable(), $where); - - // remove additional data from index - $where = $write->quoteInto('entity_id NOT IN(?)', $processIds); - $write->delete($this->getIdxTable(), $where); - - // insert new index - $this->useDisableKeys(false); - $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); - $this->useDisableKeys(true); - - $this->commit(); - } catch (Exception $e) { - $this->rollBack(); - throw $e; - } - - return $this; - } - - /** - * Process product save. - * Method is responsible for index support - * when product was saved and changed attribute(s) has an effect on price. - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - public function catalogProductSave(Mage_Index_Model_Event $event) - { - $productId = $event->getEntityPk(); - $data = $event->getNewData(); - - /** - * Check if price attribute values were updated - */ - if (!isset($data['reindex_price'])) { - return $this; - } - - $this->clearTemporaryIndexTable(); - $this->_prepareWebsiteDateTable(); - - $indexer = $this->_getIndexer($data['product_type_id']); - $processIds = array($productId); - if ($indexer->getIsComposite()) { - $this->_copyRelationIndexData($productId); - $this->_prepareTierPriceIndex($productId); - $indexer->reindexEntity($productId); - } else { - $parentIds = $this->getProductParentsByChild($productId); - - if ($parentIds) { - $processIds = array_merge($processIds, array_keys($parentIds)); - $this->_copyRelationIndexData(array_keys($parentIds), $productId); - $this->_prepareTierPriceIndex($processIds); - $indexer->reindexEntity($productId); - - $parentByType = array(); - foreach ($parentIds as $parentId => $parentType) { - $parentByType[$parentType][$parentId] = $parentId; - } - - foreach ($parentByType as $parentType => $entityIds) { - $this->_getIndexer($parentType)->reindexEntity($entityIds); - } - } else { - $this->_prepareTierPriceIndex($productId); - $indexer->reindexEntity($productId); - } - } - - $this->_copyIndexDataToMainTable($processIds); - - return $this; - } - - /** - * Process product mass update action - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - public function catalogProductMassAction(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_price_product_ids'])) { - return $this; - } - - $processIds = $data['reindex_price_product_ids']; - - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product'), 'COUNT(*)'); - $pCount = $write->fetchOne($select); - - // if affected more 30% of all products - run reindex all products - if ($pCount * 0.3 < count($processIds)) { - return $this->reindexAll(); - } - - // calculate relations - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)') - ->where('child_id IN(?)', $processIds); - $aCount = $write->fetchOne($select); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)') - ->where('parent_id IN(?)', $processIds); - $bCount = $write->fetchOne($select); - - // if affected with relations more 30% of all products - run reindex all products - if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) { - return $this->reindexAll(); - } - $this->reindexProductIds($processIds); - return $this; - } - - /** - * Reindex product prices for specified product ids - * - * @param array | int $ids - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - public function reindexProductIds($ids) - { - if (empty($ids)) { - return $this; - } - if (!is_array($ids)) { - $ids = array($ids); - } - $this->clearTemporaryIndexTable(); - $write = $this->_getWriteAdapter(); - // retrieve products types - $select = $write->select() - ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) - ->where('entity_id IN(?)', $ids); - $pairs = $write->fetchPairs($select); - $byType = array(); - foreach ($pairs as $productId => $productType) { - $byType[$productType][$productId] = $productId; - } - - $compositeIds = array(); - $notCompositeIds = array(); - - foreach ($byType as $productType => $entityIds) { - $indexer = $this->_getIndexer($productType); - if ($indexer->getIsComposite()) { - $compositeIds += $entityIds; - } else { - $notCompositeIds += $entityIds; - } - } - - if (!empty($notCompositeIds)) { - $select = $write->select() - ->from( - array('l' => $this->getTable('catalog/product_relation')), - 'parent_id') - ->join( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id = l.parent_id', - array('type_id')) - ->where('l.child_id IN(?)', $notCompositeIds); - $pairs = $write->fetchPairs($select); - foreach ($pairs as $productId => $productType) { - if (!in_array($productId, $ids)) { - $ids[] = $productId; - $byType[$productType][$productId] = $productId; - $compositeIds[$productId] = $productId; - } - } - } - - if (!empty($compositeIds)) { - $this->_copyRelationIndexData($compositeIds, $notCompositeIds); - } - - $indexers = $this->getTypeIndexers(); - foreach ($indexers as $indexer) { - if (!empty($byType[$indexer->getTypeId()])) { - $indexer->reindexEntity($byType[$indexer->getTypeId()]); - } - } - - $this->_copyIndexDataToMainTable($ids); - return $this; - } - - /** - * Retrieve Price indexer by Product Type - * - * @param string $productTypeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - protected function _getIndexer($productTypeId) - { - $types = $this->getTypeIndexers(); - if (!isset($types[$productTypeId])) { - Mage::throwException(Mage::helper('catalog')->__('Unsupported product type "%s".', $productTypeId)); - } - return $types[$productTypeId]; - } - - /** - * Retrieve price indexers per product type - * - * @return array - */ - public function getTypeIndexers() - { - if (is_null($this->_indexers)) { - $this->_indexers = array(); - $types = Mage::getSingleton('catalog/product_type')->getTypesByPriority(); - foreach ($types as $typeId => $typeInfo) { - if (isset($typeInfo['price_indexer'])) { - $modelName = $typeInfo['price_indexer']; - } else { - $modelName = $this->_defaultPriceIndexer; - } - $isComposite = !empty($typeInfo['composite']); - $indexer = Mage::getResourceModel($modelName) - ->setTypeId($typeId) - ->setIsComposite($isComposite); - - $this->_indexers[$typeId] = $indexer; - } - } - - return $this->_indexers; - } - - /** - * Rebuild all index data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->clearTemporaryIndexTable(); - $this->_prepareWebsiteDateTable(); - $this->_prepareTierPriceIndex(); - - $indexers = $this->getTypeIndexers(); - foreach ($indexers as $indexer) { - /* @var $indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface */ - $indexer->reindexAll(); - } - - $this->syncData(); - return $this; - } - - /** - * Retrieve table name for product tier price index - * - * @return string - */ - protected function _getTierPriceIndexTable() - { - return $this->getTable('catalog/product_index_tier_price'); - } - - /** - * Prepare tier price index table - * - * @param int|array $entityIds the entity ids limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - protected function _prepareTierPriceIndex($entityIds = null) - { - $write = $this->_getWriteAdapter(); - $table = $this->_getTierPriceIndexTable(); - $write->delete($table); - - $select = $write->select() - ->from( - array('tp' => $this->getValueTable('catalog/product', 'tier_price')), - array('entity_id')) - ->join( - array('cg' => $this->getTable('customer/customer_group')), - 'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)', - array('customer_group_id')) - ->join( - array('cw' => $this->getTable('core/website')), - 'tp.website_id = 0 OR tp.website_id = cw.website_id', - array('website_id')) - ->join( - array('cwd' => $this->_getWebsiteDateTable()), - 'cw.website_id = cwd.website_id', - array()) - ->where('cw.website_id != 0') - ->columns(new Zend_Db_Expr('MIN(IF(tp.website_id=0, ROUND(tp.value * cwd.rate, 4), tp.value))')) - ->group(array('tp.entity_id', 'cg.customer_group_id', 'cw.website_id')); - - if (!empty($entityIds)) { - $select->where('tp.entity_id IN(?)', $entityIds); - } - - $query = $select->insertFromSelect($table); - $write->query($query); - - return $this; - } - - /** - * Copy relations product index from primary index to temporary index table by parent entity - * - * @param array|int $parentIds - * @package array|int $excludeIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - protected function _copyRelationIndexData($parentIds, $excludeIds = null) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), array('child_id')) - ->where('parent_id IN(?)', $parentIds); - if (!is_null($excludeIds)) { - $select->where('child_id NOT IN(?)', $excludeIds); - } - - $children = $write->fetchCol($select); - - if ($children) { - $select = $write->select() - ->from($this->getMainTable()) - ->where('entity_id IN(?)', $children); - $query = $select->insertFromSelect($this->getIdxTable()); - $write->query($query); - } - - return $this; - } - - /** - * Retrieve website current dates table name - * - * @return string - */ - protected function _getWebsiteDateTable() - { - return $this->getTable('catalog/product_index_website'); - } - - /** - * Prepare website current dates table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareWebsiteDateTable() - { - $write = $this->_getWriteAdapter(); - $baseCurrency = Mage::app()->getBaseCurrencyCode(); - - $select = $write->select() - ->from( - array('cw' => $this->getTable('core/website')), - array('website_id')) - ->join( - array('csg' => $this->getTable('core/store_group')), - 'cw.default_group_id = csg.group_id', - array('store_id' => 'default_store_id')) - ->where('cw.website_id != 0') - ->group('cw.website_id'); - - $data = array(); - foreach ($write->fetchAll($select) as $item) { - /* @var $website Mage_Core_Model_Website */ - $website = Mage::app()->getWebsite($item['website_id']); - - if ($website->getBaseCurrencyCode() != $baseCurrency) { - $rate = Mage::getModel('directory/currency') - ->load($baseCurrency) - ->getRate($website->getBaseCurrencyCode()); - if (!$rate) { - $rate = 1; - } - } else { - $rate = 1; - } - - /* @var $store Mage_Core_Model_Store */ - $store = Mage::app()->getStore($item['store_id']); - if ($store) { - $timestamp = Mage::app()->getLocale()->storeTimeStamp($store); - $data[] = array( - 'website_id' => $website->getId(), - 'date' => $this->formatDate($timestamp, false), - 'rate' => $rate - ); - } - } - - $write->beginTransaction(); - $table = $this->_getWebsiteDateTable(); - $write->delete($table); - - if ($data) { - $write->insertMultiple($table, $data); - } - $write->commit(); - - return $this; - } - - /** - * Retrieve temporary index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_idx'); - } - return $this->getTable('catalog/product_price_indexer_tmp'); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Configurable.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Configurable.php index a80f4f7d04..9e78d2e5ee 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,178 +33,6 @@ * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Configurable - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable { - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareFinalPriceData(); - $this->_applyCustomOption(); - $this->_applyConfigurableOption(); - $this->_movePriceDataToIndexTable(); - - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds) - { - $this->_prepareFinalPriceData($entityIds); - $this->_applyCustomOption(); - $this->_applyConfigurableOption(); - $this->_movePriceDataToIndexTable(); - - return $this; - } - - /** - * Retrieve table name for custom option temporary aggregation data - * - * @return string - */ - protected function _getConfigurableOptionAggregateTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_cfg_option_aggregate_idx'); - } - return $this->getTable('catalog/product_price_indexer_cfg_option_aggregate_tmp'); - } - - /** - * Retrieve table name for custom option prices data - * - * @return string - */ - protected function _getConfigurableOptionPriceTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_cfg_option_idx'); - } - return $this->getTable('catalog/product_price_indexer_cfg_option_tmp'); - } - - /** - * Prepare table structure for custom option temporary aggregation data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareConfigurableOptionAggregateTable() - { - $this->_getWriteAdapter()->delete($this->_getConfigurableOptionAggregateTable()); - return $this; - } - - /** - * Prepare table structure for custom option prices data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareConfigurableOptionPriceTable() - { - $this->_getWriteAdapter()->delete($this->_getConfigurableOptionPriceTable()); - return $this; - } - - /** - * Calculate minimal and maximal prices for configurable product options - * and apply it to final price - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Configurable - */ - protected function _applyConfigurableOption() - { - $write = $this->_getWriteAdapter(); - $coaTable = $this->_getConfigurableOptionAggregateTable(); - $copTable = $this->_getConfigurableOptionPriceTable(); - - $this->_prepareConfigurableOptionAggregateTable(); - $this->_prepareConfigurableOptionPriceTable(); - - $select = $write->select() - ->from(array('i' => $this->_getDefaultFinalPriceTable()), null) - ->join( - array('l' => $this->getTable('catalog/product_super_link')), - 'l.parent_id = i.entity_id', - array('parent_id', 'product_id')) - ->columns(array('customer_group_id', 'website_id'), 'i') - ->join( - array('a' => $this->getTable('catalog/product_super_attribute')), - 'l.parent_id = a.product_id', - array()) - ->join( - array('cp' => $this->getValueTable('catalog/product', 'int')), - 'l.product_id = cp.entity_id AND cp.attribute_id = a.attribute_id AND cp.store_id = 0', - array()) - ->joinLeft( - array('apd' => $this->getTable('catalog/product_super_attribute_pricing')), - 'a.product_super_attribute_id = apd.product_super_attribute_id' - . ' AND apd.website_id = 0 AND cp.value = apd.value_index', - array()) - ->joinLeft( - array('apw' => $this->getTable('catalog/product_super_attribute_pricing')), - 'a.product_super_attribute_id = apw.product_super_attribute_id' - . ' AND apw.website_id = i.website_id AND cp.value = apw.value_index', - array()) - ->join( - array('le' => $this->getTable('catalog/product')), - 'le.entity_id = l.product_id', - array()) - ->columns(new Zend_Db_Expr("SUM(IF((@price:=IF(apw.value_id, apw.pricing_value, apd.pricing_value))" - . " IS NULL, 0, IF(IF(apw.value_id, apw.is_percent, apd.is_percent) = 1, " - . "ROUND(i.price * (@price / 100), 4), @price)))")) - ->columns(new Zend_Db_Expr("IF(i.tier_price IS NOT NULL, SUM(IF((@tier_price:=" - . "IF(apw.value_id, apw.pricing_value, apd.pricing_value)) IS NULL, 0, IF(" - . "IF(apw.value_id, apw.is_percent, apd.is_percent) = 1, " - . "ROUND(i.price * (@tier_price / 100), 4), @tier_price))), NULL)")) - ->where('le.required_options=0') - ->group(array('l.parent_id', 'i.customer_group_id', 'i.website_id', 'l.product_id')); - - $query = $select->insertFromSelect($coaTable); - $write->query($query); - - $select = $write->select() - ->from( - array($coaTable), - array('parent_id', 'customer_group_id', 'website_id', 'MIN(price)', 'MAX(price)', 'MIN(tier_price)')) - ->group(array('parent_id', 'customer_group_id', 'website_id')); - - $query = $select->insertFromSelect($copTable); - $write->query($query); - - $table = array('i' => $this->_getDefaultFinalPriceTable()); - $select = $write->select() - ->join( - array('io' => $copTable), - 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' - .' AND i.website_id = io.website_id', - array()); - $select->columns(array( - 'min_price' => new Zend_Db_Expr('i.min_price + io.min_price'), - 'max_price' => new Zend_Db_Expr('i.max_price + io.max_price'), - 'tier_price' => new Zend_Db_Expr('IF(i.tier_price IS NOT NULL, i.tier_price + io.tier_price, NULL)'), - )); - $query = $select->crossUpdateFromSelect($table); - $write->query($query); - - if ($this->useIdxTable()) { - $write->truncate($coaTable); - $write->truncate($copTable); - } - else { - $write->delete($coaTable); - $write->delete($copTable); - } - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Default.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Default.php index 68381176e9..a6a7af4946 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Default.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Default.php @@ -20,14 +20,13 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Default Product Type Price Indexer Resource model - * * For correctly work need define product type id * * @category Mage @@ -35,526 +34,6 @@ * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract - implements Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default { - /** - * Product type code - * - * @var string - */ - protected $_typeId; - - /** - * Product Type is composite flag - * - * @var bool - */ - protected $_isComposite = false; - - /** - * Define main price index table - * - */ - protected function _construct() - { - $this->_init('catalog/product_index_price', 'entity_id'); - } - - /** - * Set Product Type code - * - * @param string $typeCode - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - public function setTypeId($typeCode) - { - $this->_typeId = $typeCode; - return $this; - } - - /** - * Retrieve Product Type Code - * - * @return string - */ - public function getTypeId() - { - if (is_null($this->_typeId)) { - Mage::throwException(Mage::helper('catalog')->__('A product type is not defined for the indexer.')); - } - return $this->_typeId; - } - - /** - * Set Product Type Composite flag - * - * @param bool $flag - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - public function setIsComposite($flag) - { - $this->_isComposite = (bool)$flag; - return $this; - } - - /** - * Check product type is composite - * - * @return bool - */ - public function getIsComposite() - { - return $this->_isComposite; - } - - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareFinalPriceData(); - $this->_applyCustomOption(); - $this->_movePriceDataToIndexTable(); - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds) - { - $this->useDisableKeys(false); - $this->_prepareFinalPriceData($entityIds); - $this->_applyCustomOption(); - $this->_movePriceDataToIndexTable(); - $this->useDisableKeys(true); - - return $this; - } - - /** - * Retrieve final price temporary index table name - * - * @see _prepareDefaultFinalPriceTable() - * @return string - */ - protected function _getDefaultFinalPriceTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_final_idx'); - } - return $this->getTable('catalog/product_price_indexer_final_tmp'); - } - - /** - * Prepare final price temporary index table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareDefaultFinalPriceTable() - { - $this->_getWriteAdapter()->delete($this->_getDefaultFinalPriceTable()); - return $this; - } - - /** - * Retrieve website current dates table name - * - * @return string - */ - protected function _getWebsiteDateTable() - { - return $this->getTable('catalog/product_index_website'); - } - - /** - * Prepare products default final price in temporary index table - * - * @param int|array $entityIds the entity ids limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareFinalPriceData($entityIds = null) - { - $this->_prepareDefaultFinalPriceTable(); - - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) - ->join( - array('cg' => $this->getTable('customer/customer_group')), - '', - array('customer_group_id')) - ->join( - array('cw' => $this->getTable('core/website')), - '', - array('website_id')) - ->join( - array('cwd' => $this->_getWebsiteDateTable()), - 'cw.website_id = cwd.website_id', - array()) - ->join( - array('csg' => $this->getTable('core/store_group')), - 'csg.website_id = cw.website_id AND cw.default_group_id = csg.group_id', - array()) - ->join( - array('cs' => $this->getTable('core/store')), - 'csg.default_store_id = cs.store_id AND cs.store_id != 0', - array()) - ->join( - array('pw' => $this->getTable('catalog/product_website')), - 'pw.product_id = e.entity_id AND pw.website_id = cw.website_id', - array()) - ->joinLeft( - array('tp' => $this->_getTierPriceIndexTable()), - 'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id' - . ' AND tp.customer_group_id = cg.customer_group_id', - array()) - ->where('e.type_id=?', $this->getTypeId()); - - // add enable products limitation - $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true); - - $taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id'); - $select->columns(array('tax_class_id' => $taxClassId)); - - $price = $this->_addAttributeToSelect($select, 'price', 'e.entity_id', 'cs.store_id'); - $specialPrice = $this->_addAttributeToSelect($select, 'special_price', 'e.entity_id', 'cs.store_id'); - $specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', 'e.entity_id', 'cs.store_id'); - $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id'); - $curentDate = new Zend_Db_Expr('cwd.date'); - - $finalPrice = new Zend_Db_Expr("IF(IF({$specialFrom} IS NULL, 1, " - . "IF(DATE({$specialFrom}) <= {$curentDate}, 1, 0)) > 0 AND IF({$specialTo} IS NULL, 1, " - . "IF(DATE({$specialTo}) >= {$curentDate}, 1, 0)) > 0 AND {$specialPrice} < {$price}, " - . "{$specialPrice}, {$price})"); - $select->columns(array( - 'orig_price' => $price, - 'price' => $finalPrice, - 'min_price' => $finalPrice, - 'max_price' => $finalPrice, - 'tier_price' => new Zend_Db_Expr('tp.min_price'), - 'base_tier' => new Zend_Db_Expr('tp.min_price'), - )); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('e.entity_id'), - 'website_field' => new Zend_Db_Expr('cw.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable()); - $write->query($query); - - /** - * Add possibility modify prices from external events - */ - $select = $write->select() - ->join(array('wd' => $this->_getWebsiteDateTable()), - 'i.website_id = wd.website_id', - array()); - Mage::dispatchEvent('prepare_catalog_product_price_index_table', array( - 'index_table' => array('i' => $this->_getDefaultFinalPriceTable()), - 'select' => $select, - 'entity_id' => 'i.entity_id', - 'customer_group_id' => 'i.customer_group_id', - 'website_id' => 'i.website_id', - 'website_date' => 'wd.date', - 'update_fields' => array('price', 'min_price', 'max_price') - )); - - return $this; - } - - /** - * Retrieve table name for custom option temporary aggregation data - * - * @return string - */ - protected function _getCustomOptionAggregateTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_option_aggregate_idx'); - } - return $this->getTable('catalog/product_price_indexer_option_aggregate_idx'); - } - - /** - * Retrieve table name for custom option prices data - * - * @return string - */ - protected function _getCustomOptionPriceTable() - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_option_idx'); - } - return $this->getTable('catalog/product_price_indexer_option_tmp'); - } - - /** - * Prepare table structure for custom option temporary aggregation data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareCustomOptionAggregateTable() - { - $this->_getWriteAdapter()->delete($this->_getCustomOptionAggregateTable()); - return $this; - } - - /** - * Prepare table structure for custom option prices data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _prepareCustomOptionPriceTable() - { - $this->_getWriteAdapter()->delete($this->_getCustomOptionPriceTable()); - return $this; - } - - /** - * Apply custom option minimal and maximal price to temporary final price index table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _applyCustomOption() - { - $write = $this->_getWriteAdapter(); - $coaTable = $this->_getCustomOptionAggregateTable(); - $copTable = $this->_getCustomOptionPriceTable(); - - $this->_prepareCustomOptionAggregateTable(); - $this->_prepareCustomOptionPriceTable(); - - $select = $write->select() - ->from( - array('i' => $this->_getDefaultFinalPriceTable()), - array('entity_id', 'customer_group_id', 'website_id')) - ->join( - array('cw' => $this->getTable('core/website')), - 'cw.website_id = i.website_id', - array()) - ->join( - array('csg' => $this->getTable('core/store_group')), - 'csg.group_id = cw.default_group_id', - array()) - ->join( - array('cs' => $this->getTable('core/store')), - 'cs.store_id = csg.default_store_id', - array()) - ->join( - array('o' => $this->getTable('catalog/product_option')), - 'o.product_id = i.entity_id', - array('option_id')) - ->join( - array('ot' => $this->getTable('catalog/product_option_type_value')), - 'ot.option_id = o.option_id', - array()) - ->join( - array('otpd' => $this->getTable('catalog/product_option_type_price')), - 'otpd.option_type_id = ot.option_type_id AND otpd.store_id = 0', - array()) - ->joinLeft( - array('otps' => $this->getTable('catalog/product_option_type_price')), - 'otps.option_type_id = otpd.option_type_id AND otpd.store_id = cs.store_id', - array()) - ->group(array('i.entity_id', 'i.customer_group_id', 'i.website_id', 'o.option_id')); - - $minPrice = new Zend_Db_Expr("IF(o.is_require, MIN(IF(IF(otps.option_type_price_id>0, otps.price_type, " - . "otpd.price_type)='fixed', IF(otps.option_type_price_id>0, otps.price, otpd.price), " - . "ROUND(i.price * (IF(otps.option_type_price_id>0, otps.price, otpd.price) / 100), 4))), 0)"); - $tierPrice = new Zend_Db_Expr("IF(i.base_tier IS NOT NULL, IF(o.is_require, " - . "MIN(IF(IF(otps.option_type_price_id>0, otps.price_type, otpd.price_type)='fixed', " - . "IF(otps.option_type_price_id>0, otps.price, otpd.price), " - . "ROUND(i.base_tier * (IF(otps.option_type_price_id>0, otps.price, otpd.price) / 100), 4))), 0), NULL)"); - $maxPrice = new Zend_Db_Expr("IF((o.type='radio' OR o.type='drop_down'), " - . "MAX(IF(IF(otps.option_type_price_id>0, otps.price_type, otpd.price_type)='fixed', " - . "IF(otps.option_type_price_id>0, otps.price, otpd.price), " - . "ROUND(i.price * (IF(otps.option_type_price_id>0, otps.price, otpd.price) / 100), 4))), " - . "SUM(IF(IF(otps.option_type_price_id>0, otps.price_type, otpd.price_type)='fixed', " - . "IF(otps.option_type_price_id>0, otps.price, otpd.price), " - . "ROUND(i.price * (IF(otps.option_type_price_id>0, otps.price, otpd.price) / 100), 4))))"); - - $select->columns(array( - 'min_price' => $minPrice, - 'max_price' => $maxPrice, - 'tier_price' => $tierPrice - )); - - $query = $select->insertFromSelect($coaTable); - $write->query($query); - - $select = $write->select() - ->from( - array('i' => $this->_getDefaultFinalPriceTable()), - array('entity_id', 'customer_group_id', 'website_id')) - ->join( - array('cw' => $this->getTable('core/website')), - 'cw.website_id = i.website_id', - array()) - ->join( - array('csg' => $this->getTable('core/store_group')), - 'csg.group_id = cw.default_group_id', - array()) - ->join( - array('cs' => $this->getTable('core/store')), - 'cs.store_id = csg.default_store_id', - array()) - ->join( - array('o' => $this->getTable('catalog/product_option')), - 'o.product_id = i.entity_id', - array('option_id')) - ->join( - array('opd' => $this->getTable('catalog/product_option_price')), - 'opd.option_id = o.option_id AND opd.store_id = 0', - array()) - ->joinLeft( - array('ops' => $this->getTable('catalog/product_option_price')), - 'ops.option_id = opd.option_id AND ops.store_id = cs.store_id', - array()); - - $minPrice = new Zend_Db_Expr("IF((@price:=IF(IF(ops.option_price_id>0, ops.price_type, opd.price_type)='fixed'," - . " IF(ops.option_price_id>0, ops.price, opd.price), ROUND(i.price * (IF(ops.option_price_id>0, " - . "ops.price, opd.price) / 100), 4))) AND o.is_require, @price,0)"); - $maxPrice = new Zend_Db_Expr("@price"); - $tierPrice = new Zend_Db_Expr("IF(i.base_tier IS NOT NULL, IF((@tier_price:=IF(IF(ops.option_price_id>0, " - . "ops.price_type, opd.price_type)='fixed', IF(ops.option_price_id>0, ops.price, opd.price), " - . "ROUND(i.base_tier * (IF(ops.option_price_id>0, ops.price, opd.price) / 100), 4))) AND o.is_require, " - . "@tier_price, 0), NULL)"); - - $select->columns(array( - 'min_price' => $minPrice, - 'max_price' => $maxPrice, - 'tier_price' => $tierPrice - )); - - $query = $select->insertFromSelect($coaTable); - $write->query($query); - - $select = $write->select() - ->from( - array($coaTable), - array( - 'entity_id', - 'customer_group_id', - 'website_id', - 'min_price' => 'SUM(min_price)', - 'max_price' => 'SUM(max_price)', - 'tier_price' => 'SUM(tier_price)', - )) - ->group(array('entity_id', 'customer_group_id', 'website_id')); - $query = $select->insertFromSelect($copTable); - $write->query($query); - - $table = array('i' => $this->_getDefaultFinalPriceTable()); - $select = $write->select() - ->join( - array('io' => $copTable), - 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' - .' AND i.website_id = io.website_id', - array()); - $select->columns(array( - 'min_price' => new Zend_Db_Expr('i.min_price + io.min_price'), - 'max_price' => new Zend_Db_Expr('i.max_price + io.max_price'), - 'tier_price' => new Zend_Db_Expr('IF(i.tier_price IS NOT NULL, i.tier_price + io.tier_price, NULL)'), - )); - $query = $select->crossUpdateFromSelect($table); - $write->query($query); - - if ($this->useIdxTable()) { - $write->truncate($coaTable); - $write->truncate($copTable); - } - else { - $write->delete($coaTable); - $write->delete($copTable); - } - - return $this; - } - - /** - * Mode Final Prices index to primary temporary index table - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - protected function _movePriceDataToIndexTable() - { - $columns = array( - 'entity_id' => 'entity_id', - 'customer_group_id' => 'customer_group_id', - 'website_id' => 'website_id', - 'tax_class_id' => 'tax_class_id', - 'price' => 'orig_price', - 'final_price' => 'price', - 'min_price' => 'min_price', - 'max_price' => 'max_price', - 'tier_price' => 'tier_price' - ); - - $write = $this->_getWriteAdapter(); - $table = $this->_getDefaultFinalPriceTable(); - $select = $write->select() - ->from($table, $columns); - - $query = $select->insertFromSelect($this->getIdxTable()); - $write->query($query); - - if ($this->useIdxTable()) { - $write->truncate($table); - } - else { - $write->delete($table); - } - - return $this; - } - - /** - * Retrieve table name for product tier price index - * - * @return string - */ - protected function _getTierPriceIndexTable() - { - return $this->getTable('catalog/product_index_tier_price'); - } - - /** - * Register data required by product type process in event object - * - * @param Mage_Index_Model_Event $event - */ - public function registerEvent(Mage_Index_Model_Event $event) - {} - - /** - * Retrieve temporary index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('catalog/product_price_indexer_idx'); - } - return $this->getTable('catalog/product_price_indexer_tmp'); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Grouped.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Grouped.php index 52262a8726..d88ee8fd93 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Grouped.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,94 +33,6 @@ * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Grouped - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped { - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareGroupedProductPriceData(); - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds) - { - $this->_prepareGroupedProductPriceData($entityIds); - - return $this; - } - - /** - * Calculate minimal and maximal prices for Grouped products - * Use calculated price for relation products - * - * @param int|array $entityIds the parent entity ids limitation - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Grouped - */ - protected function _prepareGroupedProductPriceData($entityIds = null) - { - $write = $this->_getWriteAdapter(); - $table = $this->getIdxTable(); - - $select = $write->select() - ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') - ->joinLeft( - array('l' => $this->getTable('catalog/product_link')), - 'e.entity_id = l.product_id AND l.link_type_id=' . Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, - array()) - ->join( - array('cg' => $this->getTable('customer/customer_group')), - '', - array('customer_group_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('website_id', 'cw') - ->joinLeft( - array('le' => $this->getTable('catalog/product')), - 'le.entity_id = l.linked_product_id', - array()) - ->joinLeft( - array('i' => $table), - 'i.entity_id = l.linked_product_id AND i.website_id = cw.website_id' - . ' AND i.customer_group_id = cg.customer_group_id', - array( - 'tax_class_id'=> new Zend_Db_Expr('IFNULL(i.tax_class_id, 0)'), - 'price' => new Zend_Db_Expr('NULL'), - 'final_price' => new Zend_Db_Expr('NULL'), - 'min_price' => new Zend_Db_Expr('MIN(IF(le.required_options = 0, i.min_price, 0))'), - 'max_price' => new Zend_Db_Expr('MAX(IF(le.required_options = 0, i.max_price, 0))'), - 'tier_price' => new Zend_Db_Expr('NULL') - )) - ->group(array('e.entity_id', 'cg.customer_group_id', 'cw.website_id')) - ->where('e.type_id=?', $this->getTypeId()); - - if (!is_null($entityIds)) { - $select->where('l.product_id IN(?)', $entityIds); - } - - /** - * Add additional external limitation - */ - Mage::dispatchEvent('catalog_product_prepare_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('e.entity_id'), - 'website_field' => new Zend_Db_Expr('cw.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $query = $select->insertFromSelect($table); - $write->query($query); - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Interface.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Interface.php index 7f028ae1a4..304605a2f5 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Interface.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Indexer/Price/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,28 +32,7 @@ * @package Mage_Catalog * @author Magento Core Team */ -interface Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Interface { - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexAll(); - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @param bool $hasOptions the entity has custom options flag - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds); - - /** - * Register data required by product type process in event object - * - * @param Mage_Index_Model_Event $event - */ - public function registerEvent(Mage_Index_Model_Event $event); } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link.php index 82b16a2f51..7b041843a0 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,184 +28,10 @@ /** * Catalog product link resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link extends Mage_Catalog_Model_Resource_Product_Link { - /** - * Product Link Attributes Table - * - * @var string - */ - protected $_attributesTable; - - /** - * Define main table name and attributes table - * - */ - protected function _construct() - { - $this->_init('catalog/product_link', 'link_id'); - $this->_attributesTable = $this->getTable('catalog/product_link_attribute'); - } - - /** - * Save Product Links process - * - * @param Mage_Catalog_Model_Product $product - * @param array $data - * @param int $typeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link - */ - public function saveProductLinks($product, $data, $typeId) - { - if (!is_array($data)) { - $data = array(); - } - $attributes = $this->getAttributesByType($typeId); - $deleteCondition = $this->_getWriteAdapter()->quoteInto('product_id=?', $product->getId()) - . $this->_getWriteAdapter()->quoteInto(' AND link_type_id=?', $typeId); - - $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); - - foreach ($data as $linkedProductId => $linkInfo) { - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'product_id' => $product->getId(), - 'linked_product_id' => $linkedProductId, - 'link_type_id' => $typeId - )); - $linkId = $this->_getWriteAdapter()->lastInsertId(); - foreach ($attributes as $attributeInfo) { - $attributeTable = $this->getAttributeTypeTable($attributeInfo['type']); - if ($attributeTable && isset($linkInfo[$attributeInfo['code']])) { - $this->_getWriteAdapter()->insert($attributeTable, array( - 'product_link_attribute_id' => $attributeInfo['id'], - 'link_id' => $linkId, - 'value' => $linkInfo[$attributeInfo['code']] - )); - } - } - } - - /** - * Grouped product relations should be added to relation table - */ - if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) { - - } - - return $this; - } - - /** - * Retrieve product link attributes by link type - * - * @param int $typeId - * @return array - */ - public function getAttributesByType($typeId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->_attributesTable, array( - 'id' => 'product_link_attribute_id', - 'code' => 'product_link_attribute_code', - 'type' => 'data_type' - )) - ->where('link_type_id=?', $typeId); - return $this->_getReadAdapter()->fetchAll($select); - } - - public function getAttributeTypeTable($type) - { - return $this->getTable('catalog/product_link_attribute_'.$type); - } - - /** - * Retrieve Required children ids - * Return grouped array, ex array( - * group => array(ids) - * ) - * - * @param int $parentId - * @param int $typeId - * @return array - */ - public function getChildrenIds($parentId, $typeId) - { - $childrenIds = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('l' => $this->getMainTable()), array('product_id', 'linked_product_id')) - ->where('product_id=?', $parentId) - ->where('link_type_id=?', $typeId); - if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) { - $select->join( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id=l.linked_product_id AND e.required_options=0', - array() - ); - } - - $childrenIds[$typeId] = array(); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $childrenIds[$typeId][$row['linked_product_id']] = $row['linked_product_id']; - } - - return $childrenIds; - } - - /** - * Retrieve parent ids array by requered child - * - * @param int|array $childId - * @param int $typeId - * @return array - */ - public function getParentIdsByChild($childId, $typeId) - { - $parentIds = array(); - - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('product_id', 'linked_product_id')) - ->where('linked_product_id IN(?)', $childId) - ->where('link_type_id=?', $typeId); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $parentIds[] = $row['product_id']; - } - - return $parentIds; - } - - /** - * Save grouped product relations - * - * @param Mage_Catalog_Model_Product $parentProduct - * @param array $data - * @param int $typeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link - */ - public function saveGroupedLinks($product, $data, $typeId) - { - // check for change relations - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), array('linked_product_id')) - ->where('product_id=?', $product->getId()) - ->where('link_type_id=?', $typeId); - $old = $this->_getWriteAdapter()->fetchCol($select); - $new = array_keys($data); - - if (array_diff($old, $new) || array_diff($new, $old)) { - $product->setIsRelationsChanged(true); - } - - // save product links attributes - $this->saveProductLinks($product, $data, $typeId); - - // Grouped product relations should be added to relation table - Mage::getResourceSingleton('catalog/product_relation') - ->processRelations($product->getId(), $new); - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Collection.php index b15fac9aff..85821ec8e5 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,117 +28,11 @@ /** * Catalog product links collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_Catalog_Model_Resource_Product_Link_Collection { - protected $_product; - protected $_linkModel; - protected $_linkTypeId; - - protected function _construct() - { - $this->_init('catalog/product_link'); - } - - /** - * Declare link model and initialize type attributes join - * - * @param Mage_Catalog_Model_Product_Link $linkModel - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Collection - */ - public function setLinkModel($linkModel) - { - $this->_linkModel = $linkModel; - if ($linkModel->getLinkTypeId()) { - $this->_linkTypeId = $linkModel->getLinkTypeId(); - } - return $this; - } - - /** - * Retrieve collection link model - * - * @return Mage_Catalog_Model_Product_Link - */ - public function getLinkModel() - { - return $this->_linkModel; - } - - /** - * Initialize collection parent product and add limitation join - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Collection - */ - public function setProduct($product) - { - $this->_product = $product; - return $this; - } - - /** - * Retrieve collection base product object - * - * @return Mage_Catalog_Model_Product - */ - public function getProduct() - { - return $this->_product; - } - - /** - * Add link's type to filter - * - * @return Mage_Catalog_Model_Product - */ - public function addLinkTypeIdFilter() - { - if ($this->_linkTypeId) { - $this->addFieldToFilter("link_type_id", $this->_linkTypeId); - } - return $this; - } - - /** - * Add product to filter - * - * @return Mage_Catalog_Model_Product - */ - public function addProductIdFilter() - { - if ($this->getProduct() && $this->getProduct()->getId()) { - $this->addFieldToFilter("product_id", $this->getProduct()->getId()); - } - return $this; - } - - /** - * Join attributes - * - * @return Mage_Catalog_Model_Product - */ - public function joinAttributes() - { - if ($this->getLinkModel()) { - $attributes = $this->getLinkModel()->getAttributes(); - $adapter = $this->getConnection(); - foreach ($attributes as $attribute) { - $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']); - $alias = 'link_attribute_' . $attribute['code'] . '_' . $attribute['type']; - $aliasInCondition = $adapter->quoteColumnAs($alias, null); - $this->getSelect()->joinLeft( - array($alias => $table), - $aliasInCondition . '.link_id = main_table.link_id AND ' - . $aliasInCondition . '.product_link_attribute_id = ' . (int) $attribute['id'], - array($attribute['code'] => 'value') - ); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Product/Collection.php index 3d4e53a5ac..27d10354e6 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Product/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Link/Product/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,270 +28,11 @@ /** * Catalog product linked products collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection + extends Mage_Catalog_Model_Resource_Product_Link_Product_Collection { - /** - * Store product model - * - * @var Mage_Catalog_Model_Product - */ - protected $_product; - - /** - * Store product link model - * - * @var Mage_Catalog_Model_Product_Link - */ - protected $_linkModel; - - /** - * Store link type id - * - * @var int - */ - protected $_linkTypeId; - - /** - * Store strong mode flag that determine if needed for inner join or left join of linked products - * - * @var bool - */ - protected $_isStrongMode; - - /** - * Store flag that determine if product filter was enabled - * - * @var bool - */ - protected $_hasLinkFilter = false; - - /** - * Declare link model and initialize type attributes join - * - * @param Mage_Catalog_Model_Product_Link $linkModel - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setLinkModel($linkModel) - { - $this->_linkModel = $linkModel; - if ($linkModel->getLinkTypeId()) { - $this->_linkTypeId = $linkModel->getLinkTypeId(); - } - return $this; - } - - /** - * Enable strong mode for inner join of linked products - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setIsStrongMode() - { - $this->_isStrongMode = true; - return $this; - } - - /** - * Retrieve collection link model - * - * @return Mage_Catalog_Model_Product_Link - */ - public function getLinkModel() - { - return $this->_linkModel; - } - - /** - * Initialize collection parent product and add limitation join - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setProduct($product) - { - $this->_product = $product; - if ($product && $product->getId()) { - $this->_hasLinkFilter = true; - } - return $this; - } - - /** - * Retrieve collection base product object - * - * @return Mage_Catalog_Model_Product - */ - public function getProduct() - { - return $this->_product; - } - - /** - * Exclude products from filter - * - * @param array $products - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addExcludeProductFilter($products) - { - if (!empty($products)) { - if (!is_array($products)) { - $products = array($products); - } - $this->_hasLinkFilter = true; - $this->getSelect()->where('links.linked_product_id NOT IN (?)', $products); - } - return $this; - } - - /** - * Add attribute to sort order - * - * @param string $attribute - * @param string $dir - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addAttributeToSort($attribute, $dir='asc') - { - /** - * Position is not eav attribute (it is links attribute) so we cannot use default attributes to sort - */ - if ($attribute == 'position') { - if ($this->_hasLinkFilter) { - $this->getSelect()->order($attribute.' '.$dir); - } - } - else { - parent::addAttributeToSort($attribute, $dir); - } - return $this; - } - - /** - * Add products to filter - * - * @param array|int|string $products - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function addProductFilter($products) - { - if (is_array($products) && !empty($products)) { - $this->getSelect()->where('links.product_id IN (?)', $products); - $this->_hasLinkFilter = true; - } - elseif (is_string($products) || is_numeric($products)) { - $this->getSelect()->where('links.product_id=?', $products); - $this->_hasLinkFilter = true; - } - return $this; - } - - /** - * Add random sorting order - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setRandomOrder() - { - $this->getSelect()->order(new Zend_Db_Expr('RAND()')); - return $this; - } - - /** - * Setting group by to exclude duplications in collection - * - * @param string $groupBy - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setGroupBy($groupBy = 'e.entity_id') - { - $this->getSelect()->group($groupBy); - return $this; - } - - /** - * Join linked products when specified link model - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - protected function _beforeLoad() - { - if ($this->getLinkModel()) { - $this->_joinLinks(); - } - return parent::_beforeLoad(); - } - - /** - * Join linked products and their attributes - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - protected function _joinLinks() - { - $joinCondition = 'links.linked_product_id = e.entity_id AND links.link_type_id = ' . $this->_linkTypeId; - $joinType = 'join'; - if ($this->getProduct() && $this->getProduct()->getId()) { - if ($this->_isStrongMode) { - $this->getSelect()->where('links.product_id = ?', $this->getProduct()->getId()); - } - else { - $joinType = 'joinLeft'; - $joinCondition.= ' AND links.product_id = ' . $this->getProduct()->getId(); - } - $this->getSelect()->where('e.entity_id != ?', $this->getProduct()->getId()); - } - elseif ($this->_isStrongMode) { - $this->getSelect()->where('e.entity_id = -1'); - } - if($this->_hasLinkFilter) { - $this->getSelect()->$joinType( - array('links' => $this->getTable('catalog/product_link')), - $joinCondition, - array('link_id') - ); - $this->joinAttributes(); - } - return $this; - } - - /** - * Enable sorting products by its position - * - * @param string $dir sort type asc|desc - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection - */ - public function setPositionOrder($dir = 'asc') - { - $this->setOrder('position', $dir); - return $this; - } - - /** - * Join attributes - * - * @return Mage_Catalog_Model_Product - */ - public function joinAttributes() - { - if ($this->getLinkModel()) { - $attributes = $this->getLinkModel()->getAttributes(); - $attributesByType = array(); - foreach ($attributes as $attribute) { - $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']); - $alias = 'link_attribute_'.$attribute['code'].'_'.$attribute['type']; - $this->getSelect()->joinLeft( - array($alias => $table), - $alias.'.link_id=links.link_id AND '.$alias.'.product_link_attribute_id='.$attribute['id'], - array($attribute['code'] => 'value') - ); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option.php index f4a7be58b9..fe8dbb5252 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,292 +28,10 @@ /** * Catalog product custom option resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option extends Mage_Catalog_Model_Resource_Product_Option { - protected function _construct() - { - $this->_init('catalog/product_option', 'option_id'); - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $priceTable = $this->getTable('catalog/product_option_price'); - $titleTable = $this->getTable('catalog/product_option_title'); - - //better to check param 'price' and 'price_type' for saving. If there is not price scip saving price - if ($object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD - || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA - || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE - || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE - || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME - || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME - ) { - - //save for store_id = 0 - if (!$object->getData('scope', 'price')) { - $statement = $this->_getReadAdapter()->select() - ->from($priceTable) - ->where('option_id = '.$object->getId().' AND store_id = ?', 0); - if ($this->_getReadAdapter()->fetchOne($statement)) { - if ($object->getStoreId() == '0') { - $this->_getWriteAdapter()->update( - $priceTable, - array( - 'price' => $object->getPrice(), - 'price_type' => $object->getPriceType() - ), - $this->_getWriteAdapter()->quoteInto('option_id = '.$object->getId().' AND store_id = ?', 0) - ); - } - } else { - $this->_getWriteAdapter()->insert( - $priceTable, - array( - 'option_id' => $object->getId(), - 'store_id' => 0, - 'price' => $object->getPrice(), - 'price_type' => $object->getPriceType() - ) - ); - } - } - - $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); - - if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE - && !$object->getData('scope', 'price')) { - - $baseCurrency = Mage::app()->getBaseCurrencyCode(); - - $storeIds = Mage::app()->getStore($object->getStoreId())->getWebsite()->getStoreIds(); - if (is_array($storeIds)) { - foreach ($storeIds as $storeId) { - if ($object->getPriceType() == 'fixed') { - $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); - $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); - if (!$rate) { - $rate=1; - } - $newPrice = $object->getPrice() * $rate; - } else { - $newPrice = $object->getPrice(); - } - $statement = $this->_getReadAdapter()->select() - ->from($priceTable) - ->where('option_id = '.$object->getId().' AND store_id = ?', $storeId); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - $this->_getWriteAdapter()->update( - $priceTable, - array( - 'price' => $newPrice, - 'price_type' => $object->getPriceType() - ), - $this->_getWriteAdapter()->quoteInto('option_id = '.$object->getId().' AND store_id = ?', $storeId) - ); - } else { - $this->_getWriteAdapter()->insert( - $priceTable, - array( - 'option_id' => $object->getId(), - 'store_id' => $storeId, - 'price' => $newPrice, - 'price_type' => $object->getPriceType() - ) - ); - } - }// end foreach() - } - } elseif ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) { - $this->_getWriteAdapter()->delete( - $priceTable, - $this->_getWriteAdapter()->quoteInto('option_id = '.$object->getId().' AND store_id = ?', $object->getStoreId()) - ); - } - } - - //title - if (!$object->getData('scope', 'title')) { - $statement = $this->_getReadAdapter()->select() - ->from($titleTable) - ->where('option_id = '.$object->getId().' and store_id = ?', 0); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - if ($object->getStoreId() == '0') { - $this->_getWriteAdapter()->update( - $titleTable, - array('title' => $object->getTitle()), - $this->_getWriteAdapter()->quoteInto('option_id='.$object->getId().' AND store_id=?', 0) - ); - } - } else { - $this->_getWriteAdapter()->insert( - $titleTable, - array( - 'option_id' => $object->getId(), - 'store_id' => 0, - 'title' => $object->getTitle() - )); - } - } - - if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) { - $statement = $this->_getReadAdapter()->select() - ->from($titleTable) - ->where('option_id = '.$object->getId().' and store_id = ?', $object->getStoreId()); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - $this->_getWriteAdapter()->update( - $titleTable, - array('title' => $object->getTitle()), - $this->_getWriteAdapter() - ->quoteInto('option_id='.$object->getId().' AND store_id=?', $object->getStoreId())); - } else { - $this->_getWriteAdapter()->insert( - $titleTable, - array( - 'option_id' => $object->getId(), - 'store_id' => $object->getStoreId(), - 'title' => $object->getTitle() - )); - } - } elseif ($object->getData('scope', 'title')) { - $this->_getWriteAdapter()->delete( - $titleTable, - $this->_getWriteAdapter()->quoteInto('option_id = '.$object->getId().' AND store_id = ?', $object->getStoreId()) - ); - } - - return parent::_afterSave($object); - } - - public function deletePrices($option_id) - { - $condition = $this->_getWriteAdapter()->quoteInto('option_id=?', $option_id); - - $this->_getWriteAdapter()->delete( - $this->getTable('catalog/product_option_price'), - $condition); - - return $this; - } - - public function deleteTitles($option_id) - { - $condition = $this->_getWriteAdapter()->quoteInto('option_id=?', $option_id); - - $this->_getWriteAdapter()->delete( - $this->getTable('catalog/product_option_title'), - $condition); - - return $this; - } - - /** - * Duplicate custom options for product - * - * @param Mage_Catalog_Model_Product_Option $object - * @param int $oldProductId - * @param int $newProductId - * @return Mage_Catalog_Model_Product_Option - */ - public function duplicate(Mage_Catalog_Model_Product_Option $object, $oldProductId, $newProductId) - { - $write = $this->_getWriteAdapter(); - $read = $this->_getReadAdapter(); - - $optionsCond = array(); - $optionsData = array(); - - // read and prepare original product options - $select = $read->select() - ->from($this->getTable('catalog/product_option')) - ->where('product_id=?', $oldProductId); - $query = $read->query($select); - while ($row = $query->fetch()) { - $optionsData[$row['option_id']] = $row; - $optionsData[$row['option_id']]['product_id'] = $newProductId; - unset($optionsData[$row['option_id']]['option_id']); - } - - // insert options to duplicated product - foreach ($optionsData as $oId => $data) { - $write->insert($this->getMainTable(), $data); - $optionsCond[$oId] = $write->lastInsertId(); - } - - // copy options prefs - foreach ($optionsCond as $oldOptionId => $newOptionId) { - // title - $table = $this->getTable('catalog/product_option_title'); - $sql = 'REPLACE INTO `' . $table . '` ' - . 'SELECT NULL, ' . $newOptionId . ', `store_id`, `title`' - . 'FROM `' . $table . '` WHERE `option_id`=' . $oldOptionId; - $this->_getWriteAdapter()->query($sql); - - // price - $table = $this->getTable('catalog/product_option_price'); - $sql = 'REPLACE INTO `' . $table . '` ' - . 'SELECT NULL, ' . $newOptionId . ', `store_id`, `price`, `price_type`' - . 'FROM `' . $table . '` WHERE `option_id`=' . $oldOptionId; - $this->_getWriteAdapter()->query($sql); - - $object->getValueInstance()->duplicate($oldOptionId, $newOptionId); - } - - return $object; - } - - /** - * Retrieve option searchable data - * - * @param int $productId - * @param int $storeId - * @return array - */ - public function getSearchableData($productId, $storeId) - { - $searchData = array(); - // retrieve options title - $select = $this->_getReadAdapter()->select() - ->from(array('option' => $this->getMainTable()), null) - ->join( - array('option_title_default' => $this->getTable('catalog/product_option_title')), - 'option_title_default.option_id=option.option_id AND option_title_default.store_id=0', - array()) - ->joinLeft( - array('option_title_store' => $this->getTable('catalog/product_option_title')), - 'option_title_store.option_id=option.option_id AND option_title_store.store_id=' . intval($storeId), - array('title' => 'IFNULL(option_title_store.title, option_title_default.title)')) - ->where('option.product_id=?', $productId); - if ($titles = $this->_getReadAdapter()->fetchCol($select)) { - $searchData = array_merge($searchData, $titles); - } - - //select option type titles - $select = $this->_getReadAdapter()->select() - ->from(array('option' => $this->getMainTable()), null) - ->join( - array('option_type' => $this->getTable('catalog/product_option_type_value')), - 'option_type.option_id=option.option_id', - array()) - ->join( - array('option_title_default' => $this->getTable('catalog/product_option_type_title')), - 'option_title_default.option_type_id=option_type.option_type_id AND option_title_default.store_id=0', - array()) - ->joinLeft( - array('option_title_store' => $this->getTable('catalog/product_option_type_title')), - 'option_title_store.option_type_id=option_type.option_type_id AND option_title_store.store_id=' . intval($storeId), - array('title' => 'IFNULL(option_title_store.title, option_title_default.title)')) - ->where('option.product_id=?', $productId); - if ($titles = $this->_getReadAdapter()->fetchCol($select)) { - $searchData = array_merge($searchData, $titles); - } - - return $searchData; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Collection.php index 941be572f7..1899eaf2a6 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,133 +28,11 @@ /** * Catalog product options collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_Catalog_Model_Resource_Product_Option_Collection { - protected function _construct() - { - $this->_init('catalog/product_option'); - } - - public function getOptions($store_id) - { - $this->getSelect() - ->joinLeft(array('default_option_price'=>$this->getTable('catalog/product_option_price')), - '`default_option_price`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`default_option_price`.store_id=?',0), - array('default_price'=>'price','default_price_type'=>'price_type')) - ->joinLeft(array('store_option_price'=>$this->getTable('catalog/product_option_price')), - '`store_option_price`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`store_option_price`.store_id=?', $store_id), - array('store_price'=>'price','store_price_type'=>'price_type', - 'price'=>new Zend_Db_Expr('IFNULL(`store_option_price`.price,`default_option_price`.price)'), - 'price_type'=>new Zend_Db_Expr('IFNULL(`store_option_price`.price_type,`default_option_price`.price_type)'))) - ->join(array('default_option_title'=>$this->getTable('catalog/product_option_title')), - '`default_option_title`.option_id=`main_table`.option_id', - array('default_title'=>'title')) - ->joinLeft(array('store_option_title'=>$this->getTable('catalog/product_option_title')), - '`store_option_title`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`store_option_title`.store_id=?', $store_id), - array('store_title'=>'title', - 'title'=>new Zend_Db_Expr('IFNULL(`store_option_title`.title,`default_option_title`.title)'))) - ->where('`default_option_title`.store_id=?', 0); - - return $this; - } - - public function addTitleToResult($store_id) - { - $this->getSelect() - ->join(array('default_option_title'=>$this->getTable('catalog/product_option_title')), - '`default_option_title`.option_id=`main_table`.option_id', - array('default_title'=>'title')) - ->joinLeft(array('store_option_title'=>$this->getTable('catalog/product_option_title')), - '`store_option_title`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`store_option_title`.store_id=?', $store_id), - array('store_title'=>'title', - 'title'=>new Zend_Db_Expr('IFNULL(`store_option_title`.title,`default_option_title`.title)'))) - ->where('`default_option_title`.store_id=?', 0); - - return $this; - } - - public function addPriceToResult($store_id) - { - $this->getSelect() - ->joinLeft(array('default_option_price'=>$this->getTable('catalog/product_option_price')), - '`default_option_price`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`default_option_price`.store_id=?',0), - array('default_price'=>'price','default_price_type'=>'price_type')) - ->joinLeft(array('store_option_price'=>$this->getTable('catalog/product_option_price')), - '`store_option_price`.option_id=`main_table`.option_id AND '.$this->getConnection()->quoteInto('`store_option_price`.store_id=?', $store_id), - array('store_price'=>'price','store_price_type'=>'price_type', - 'price'=>new Zend_Db_Expr('IFNULL(`store_option_price`.price,`default_option_price`.price)'), - 'price_type'=>new Zend_Db_Expr('IFNULL(`store_option_price`.price_type,`default_option_price`.price_type)'))); - return $this; - } - - public function addValuesToResult($storeId = null) - { - if (null === $storeId) { - $storeId = Mage::app()->getStore()->getId(); - } - $optionIds = array(); - foreach ($this as $option) { - $optionIds[] = $option->getId(); - } - if (!empty($optionIds)) { - $values = Mage::getModel('catalog/product_option_value') - ->getCollection() - ->addTitleToResult($storeId) - ->addPriceToResult($storeId) - ->addOptionToFilter($optionIds) - ->setOrder('sort_order', 'asc') - ->setOrder('title', 'asc'); - - foreach ($values as $value) { - if($this->getItemById($value->getOptionId())) { - $this->getItemById($value->getOptionId())->addValue($value); - $value->setOption($this->getItemById($value->getOptionId())); - } - } - } - - return $this; - } - - public function addProductToFilter($product) - { - if (empty($product)) { - $this->addFieldToFilter('product_id', ''); - } elseif (is_array($product)) { - $this->addFieldToFilter('product_id', array('in' => $product)); - } elseif ($product instanceof Mage_Catalog_Model_Product) { - $this->addFieldToFilter('product_id', $product->getId()); - } else { - $this->addFieldToFilter('product_id', $product); - } - - return $this; - } - - /** - * Add filtering by option ids - * - * @param mixed $optionIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Collection - */ - public function addIdsToFilter($optionIds) - { - $this->addFieldToFilter('main_table.option_id', $optionIds); - return $this; - } - - /** - * Call of protected method reset - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Collection - */ - public function reset() { - return $this->_reset(); - } - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value.php index 9b250c6587..d5958bab95 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,236 +28,11 @@ /** * Catalog product custom option resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value + extends Mage_Catalog_Model_Resource_Product_Option_Value { - protected function _construct() - { - $this->_init('catalog/product_option_type_value', 'option_type_id'); - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $priceTable = $this->getTable('catalog/product_option_type_price'); - $titleTable = $this->getTable('catalog/product_option_type_title'); - - if (!$object->getData('scope', 'price')) { - //save for store_id = 0 - $statement = $this->_getReadAdapter()->select() - ->from($priceTable) - ->where('option_type_id = '.$object->getId().' AND store_id = ?', 0); - if ($this->_getReadAdapter()->fetchOne($statement)) { - if ($object->getStoreId() == '0') { - $this->_getWriteAdapter()->update( - $priceTable, - array( - 'price' => $object->getPrice(), - 'price_type' => $object->getPriceType() - ), - $this->_getWriteAdapter()->quoteInto('option_type_id = '.$object->getId().' AND store_id = ?', 0) - ); - } - } else { - $this->_getWriteAdapter()->insert( - $priceTable, - array( - 'option_type_id' => $object->getId(), - 'store_id' => 0, - 'price' => $object->getPrice(), - 'price_type' => $object->getPriceType() - ) - ); - } - } - - $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); - - if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE - && !$object->getData('scope', 'price')) { - - $baseCurrency = Mage::app()->getBaseCurrencyCode(); - - $storeIds = $object->getProduct()->getStoreIds(); - if (is_array($storeIds)) { - foreach ($storeIds as $storeId) { - if ($object->getPriceType() == 'fixed') { - $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); - $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); - if (!$rate) { - $rate = 1; - } - $newPrice = $object->getPrice() * $rate; - } else { - $newPrice = $object->getPrice(); - } - $statement = $this->_getReadAdapter()->select() - ->from($priceTable) - ->where('option_type_id = '.$object->getId().' AND store_id = ?', $storeId); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - $this->_getWriteAdapter()->update( - $priceTable, - array( - 'price' => $newPrice, - 'price_type' => $object->getPriceType() - ), - $this->_getWriteAdapter()->quoteInto('option_type_id = '.$object->getId().' AND store_id = ?', $storeId) - ); - } else { - $this->_getWriteAdapter()->insert( - $priceTable, - array( - 'option_type_id' => $object->getId(), - 'store_id' => $storeId, - 'price' => $newPrice, - 'price_type' => $object->getPriceType() - ) - ); - } - }// end of foreach() - } - } elseif ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) { - $this->_getWriteAdapter()->delete( - $priceTable, - $this->_getWriteAdapter()->quoteInto('option_type_id = '.$object->getId().' AND store_id = ?', $object->getStoreId()) - ); - } - - //title - if (!$object->getData('scope', 'title')) { - $statement = $this->_getReadAdapter()->select() - ->from($titleTable) - ->where('option_type_id = '.$object->getId().' AND store_id = ?', 0); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - if ($object->getStoreId() == '0') { - $this->_getWriteAdapter()->update( - $titleTable, - array('title' => $object->getTitle()), - $this->_getWriteAdapter()->quoteInto('option_type_id='.$object->getId().' AND store_id=?', 0) - ); - } - } else { - $this->_getWriteAdapter()->insert( - $titleTable, - array( - 'option_type_id' => $object->getId(), - 'store_id' => 0, - 'title' => $object->getTitle() - )); - } - } - - if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) { - $statement = $this->_getReadAdapter()->select() - ->from($titleTable) - ->where('option_type_id = '.$object->getId().' AND store_id = ?', $object->getStoreId()); - - if ($this->_getReadAdapter()->fetchOne($statement)) { - $this->_getWriteAdapter()->update( - $titleTable, - array('title' => $object->getTitle()), - $this->_getWriteAdapter() - ->quoteInto('option_type_id='.$object->getId().' AND store_id=?', $object->getStoreId())); - } else { - $this->_getWriteAdapter()->insert( - $titleTable, - array( - 'option_type_id' => $object->getId(), - 'store_id' => $object->getStoreId(), - 'title' => $object->getTitle() - )); - } - } elseif ($object->getData('scope', 'title')) { - $this->_getWriteAdapter()->delete( - $titleTable, - $this->_getWriteAdapter()->quoteInto('option_type_id = '.$object->getId().' AND store_id = ?', $object->getStoreId()) - ); - } - - return parent::_afterSave($object); - } - - public function deleteValue($option_id) - { - $condition = $this->_getWriteAdapter()->quoteInto('option_id=?', $option_id); - - $statement = $this->_getReadAdapter()->select() - ->from($this->getTable('catalog/product_option_type_value')) - ->where($condition); - - foreach ($this->_getReadAdapter()->fetchAll($statement) as $optionType) { - $this->deleteValues($optionType['option_type_id']); - } - - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $condition - ); - - return $this; - } - - public function deleteValues($option_type_id) - { - $childCondition = $this->_getWriteAdapter()->quoteInto('option_type_id=?', $option_type_id); - $this->_getWriteAdapter()->delete( - $this->getTable('catalog/product_option_type_price'), - $childCondition - ); - $this->_getWriteAdapter()->delete( - $this->getTable('catalog/product_option_type_title'), - $childCondition - ); - } - - /** - * Duplicate product options value - * - * @param Mage_Catalog_Model_Product_Option_Value $object - * @param int $oldOptionId - * @param int $newOptionId - * @return Mage_Catalog_Model_Product_Option_Value - */ - public function duplicate(Mage_Catalog_Model_Product_Option_Value $object, $oldOptionId, $newOptionId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('option_id=?', $oldOptionId); - $valueData = $this->_getReadAdapter()->fetchAll($select); - - $valueCond = array(); - - foreach ($valueData as $data) { - $optionTypeId = $data[$this->getIdFieldName()]; - unset($data[$this->getIdFieldName()]); - $data['option_id'] = $newOptionId; - - $this->_getWriteAdapter()->insert($this->getMainTable(), $data); - $valueCond[$optionTypeId] = $this->_getWriteAdapter()->lastInsertId(); - } - - unset($valueData); - - foreach ($valueCond as $oldTypeId => $newTypeId) { - // price - $table = $this->getTable('catalog/product_option_type_price'); - $sql = 'REPLACE INTO `' . $table . '` ' - . 'SELECT NULL, ' . $newTypeId . ', `store_id`, `price`, `price_type`' - . 'FROM `' . $table . '` WHERE `option_type_id`=' . $oldTypeId; - $this->_getWriteAdapter()->query($sql); - - // title - $table = $this->getTable('catalog/product_option_type_title'); - $sql = 'REPLACE INTO `' . $table . '` ' - . 'SELECT NULL, ' . $newTypeId . ', `store_id`, `title`' - . 'FROM `' . $table . '` WHERE `option_type_id`=' . $oldTypeId; - $this->_getWriteAdapter()->query($sql); - } - - return $object; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value/Collection.php index 22a1704d3f..8ca73da953 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Value/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,114 +28,11 @@ /** * Catalog product option values collection * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_Catalog_Model_Resource_Product_Option_Value_Collection { - protected function _construct() - { - $this->_init('catalog/product_option_value'); - } - - public function getValues($store_id) - { - $this->getSelect() - ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0), - array('default_price'=>'price','default_price_type'=>'price_type')) - ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id), - array('store_price'=>'price','store_price_type'=>'price_type', - 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'), - 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)'))) - ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`default_value_title`.option_type_id=`main_table`.option_type_id', - array('default_title'=>'title')) - ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id), - array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)'))) - ->where('`default_value_title`.store_id=?',0); - return $this; - } - - public function addTitlesToResult($store_id) - { - $this->getSelect() - ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0), - array('default_price'=>'price','default_price_type'=>'price_type')) - ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id), - array('store_price'=>'price','store_price_type'=>'price_type', - 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'), - 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)'))) - ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`default_value_title`.option_type_id=`main_table`.option_type_id', - array('default_title'=>'title')) - ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id), - array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)'))) - ->where('`default_value_title`.store_id=?',0); - - return $this; - } - - public function addTitleToResult($store_id) - { - $this->getSelect() - ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`default_value_title`.option_type_id=`main_table`.option_type_id', - array('default_title'=>'title')) - ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')), - '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id), - array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)'))) - ->where('`default_value_title`.store_id=?',0); - - return $this; - } - - public function addPriceToResult($store_id) - { - $this->getSelect() - ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0), - array('default_price'=>'price','default_price_type'=>'price_type')) - ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')), - '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id), - array('store_price'=>'price','store_price_type'=>'price_type', - 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'), - 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)'))); - - return $this; - } - - public function getValuesByOption($optionIds, $store_id) - { - if (!is_array($optionIds)) { - $optionIds = array($optionIds); - } - - $this->getSelect() - ->where('`main_table`.option_type_id IN (?)', $optionIds); - - return $this; - } - - public function addOptionToFilter($option) - { - if (empty($option)) { - $this->addFieldToFilter('option_id', ''); - } elseif (is_array($option)) { - $this->addFieldToFilter('option_id', array('in' => $option)); - } elseif ($option instanceof Mage_Catalog_Model_Product_Option) { - $this->addFieldToFilter('option_id', $option->getId()); - } else { - $this->addFieldToFilter('option_id', $option); - } - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Relation.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Relation.php index a5aa2b2a66..6d6e863c87 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Relation.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Relation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,53 +32,6 @@ * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Relation extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Relation extends Mage_Catalog_Model_Resource_Product_Relation { - /** - * Initialize resource model and define main table - * - */ - protected function _construct() - { - $this->_init('catalog/product_relation', 'parent_id'); - } - - /** - * Save (rebuild) product relations - * - * @param int $parentId - * @param array $childIds - * @return Mage_Catalog_Model_Resource_Eav_Product_Relation - */ - public function processRelations($parentId, $childIds) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('child_id')) - ->where('parent_id=?', $parentId); - $old = $this->_getReadAdapter()->fetchCol($select); - $new = $childIds; - - $insert = array_diff($new, $old); - $delete = array_diff($old, $new); - - if (!empty($insert)) { - $insertData = array(); - foreach ($insert as $childId) { - $insertData[] = array( - 'parent_id' => $parentId, - 'child_id' => $childId - ); - } - $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $insertData); - } - if (!empty($delete)) { - $where = join(' AND ', array( - $this->_getWriteAdapter()->quoteInto('parent_id=?', $parentId), - $this->_getWriteAdapter()->quoteInto('child_id IN(?)', $delete) - )); - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - } - - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Status.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Status.php index 62e6119fcc..09974656a1 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Status.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,204 +28,10 @@ /** * Catalog product website resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status extends Mage_Catalog_Model_Resource_Product_Status { - /** - * Product atrribute cache - * - * @var array - */ - protected $_productAttributes = array(); - - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('catalog/product_enabled_index', 'product_id'); - } - - /** - * Retrieve product attribute (public method for status model) - * - * @param string $attributeCode - * @return Mage_Catalog_Model_Resource_Eav_Attribute - */ - public function getProductAttribute($attributeCode) - { - return $this->_getProductAttribute($attributeCode); - } - - /** - * Retrieve product attribute - * - * @return Mage_Eav_Model_Entity_Attribute_Abstract - */ - protected function _getProductAttribute($attribute) - { - if (empty($this->_productAttributes[$attribute])) { - $this->_productAttributes[$attribute] = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attribute); - } - return $this->_productAttributes[$attribute]; - } - - /** - * Refresh enabled index cache - * - * @param int $productId - * @param int $storeId - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status - */ - public function refreshEnabledIndex($productId, $storeId) - { - $statusAttributeId = $this->_getProductAttribute('status')->getId(); - $visibilityAttributeId = $this->_getProductAttribute('visibility')->getId(); - $statusTable = $this->_getProductAttribute('status')->getBackend()->getTable(); - $visibilityTable = $this->_getProductAttribute('visibility')->getBackend()->getTable(); - - $indexTable = $this->getTable('catalog/product_enabled_index'); - - if ($storeId == 0) { - foreach (Mage::app()->getStores() as $store) { - $this->refreshEnabledIndex($productId, $store->getId()); - } - - return $this; - } - - $this->_getWriteAdapter()->delete($indexTable, array( - $this->_getWriteAdapter()->quoteInto('product_id=?', $productId), - $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId) - )); - - $query = "INSERT INTO $indexTable - SELECT - {$productId}, {$storeId}, IF(t_v.value_id>0, t_v.value, t_v_default.value) - FROM - {$visibilityTable} AS t_v_default - LEFT JOIN {$visibilityTable} AS `t_v` - ON (t_v.entity_id = t_v_default.entity_id) AND (t_v.attribute_id='{$visibilityAttributeId}') AND (t_v.store_id='{$storeId}') - INNER JOIN {$statusTable} AS `t_s_default` - ON (t_s_default.entity_id = t_v_default.entity_id) AND (t_s_default.attribute_id='{$statusAttributeId}') AND t_s_default.store_id=0 - LEFT JOIN {$statusTable} AS `t_s` - ON (t_s.entity_id = t_v_default.entity_id) AND (t_s.attribute_id='{$statusAttributeId}') AND (t_s.store_id='{$storeId}') - WHERE - t_v_default.entity_id={$productId} - AND t_v_default.attribute_id='{$visibilityAttributeId}' AND t_v_default.store_id=0 - AND (IF(t_s.value_id>0, t_s.value, t_s_default.value)=".Mage_Catalog_Model_Product_Status::STATUS_ENABLED.")"; - $this->_getWriteAdapter()->query($query); - - return $this; - } - - /** - * Update product status for store - * - * @param int $productId - * @param int $storId - * @param int $value - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status - */ - public function updateProductStatus($productId, $storId, $value) - { - $statusAttributeId = $this->_getProductAttribute('status')->getId(); - $statusEntityTypeId = $this->_getProductAttribute('status')->getEntityTypeId(); - $statusTable = $this->_getProductAttribute('status')->getBackend()->getTable(); - $refreshIndex = true; - - $prop = array( - 'entity_type_id' => $statusEntityTypeId, - 'attribute_id' => $statusAttributeId, - 'store_id' => $storId, - 'entity_id' => $productId, - 'value' => $value - ); - - $select = $this->_getWriteAdapter()->select() - ->from($statusTable) - ->where('attribute_id=?', $statusAttributeId) - ->where('store_id=?', $storId) - ->where('entity_id=?', $productId); - $row = $this->_getWriteAdapter()->fetchRow($select); - - if ($row) { - if ($row['value'] == $value) { - $refreshIndex = false; - } - else { - $this->_getWriteAdapter()->update($statusTable, $prop, $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id'])); - } - } - else { - $this->_getWriteAdapter()->insert($statusTable, $prop); - } - - if ($refreshIndex) { - $this->refreshEnabledIndex($productId, $storId); - } - - return $this; - } - - /** - * Retrieve Product(s) status for store - * Return array where key is a product_id, value - status - * - * @param array|int $productIds - * @param int $storeId - * @return array - */ - public function getProductStatus($productIds, $storeId = null) - { - $statuses = array(); - - $attribute = $this->_getProductAttribute('status'); - $attributeTable = $attribute->getBackend()->getTable(); - - if (!is_array($productIds)) { - $productIds = array($productIds); - } - - if (is_null($storeId) || $storeId == 0) { - $select = $this->_getReadAdapter()->select() - ->from($attributeTable, array('entity_id', 'value')) - ->where('entity_id IN(?)', $productIds) - ->where('attribute_id=?', $attribute->getAttributeId()) - ->where('store_id=?', 0); - $rows = $this->_getWriteAdapter()->fetchPairs($select); - } - else { - $select = $this->_getReadAdapter()->select() - ->from( - array('t1' => $attributeTable), - array('entity_id', 'IF(t2.value_id>0, t2.value, t1.value) as value')) - ->joinLeft( - array('t2' => $attributeTable), - $this->_getReadAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId), - array() - ) - ->where('t1.store_id = ?', 0) - ->where('t1.attribute_id = ?', $attribute->getAttributeId()) - ->where('t1.entity_id IN(?)', $productIds); - $rows = $this->_getWriteAdapter()->fetchPairs($select); - } - - foreach ($productIds as $productId) { - if (isset($rows[$productId])) { - $statuses[$productId] = $rows[$productId]; - } - else { - $statuses[$productId] = -1; - } - } - - return $statuses; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable.php index 3e95d12acd..c8c40901b8 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,121 +28,11 @@ /** * Configurable product type resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable + extends Mage_Catalog_Model_Resource_Product_Type_Configurable { - /** - * Init resource - * - */ - protected function _construct() - { - $this->_init('catalog/product_super_link', 'link_id'); - } - - /** - * Save configurable product relations - * - * @param Mage_Catalog_Model_Product|int $mainProduct the parent id - * @param array $productIds the children id array - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable - */ - public function saveProducts($mainProduct, $productIds) - { - $isProductInstance = false; - if ($mainProduct instanceof Mage_Catalog_Model_Product) { - $mainProductId = $mainProduct->getId(); - $isProductInstance = true; - } else { - $mainProductId = $mainProduct; - } - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'product_id') - ->where('parent_id=?', $mainProductId); - $old = $this->_getReadAdapter()->fetchCol($select); - - $insert = array_diff($productIds, $old); - $delete = array_diff($old, $productIds); - - if ((!empty($insert) || !empty($delete)) && $isProductInstance) { - $mainProduct->setIsRelationsChanged(true); - } - - if (!empty($delete)) { - $where = join(' AND ', array( - $this->_getWriteAdapter()->quoteInto('parent_id=?', $mainProductId), - $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $delete) - )); - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - } - if (!empty($insert)) { - $data = array(); - foreach ($insert as $childId) { - $data[] = array( - 'product_id' => $childId, - 'parent_id' => $mainProductId - ); - } - $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $data); - } - - // configurable product relations should be added to relation table - Mage::getResourceSingleton('catalog/product_relation') - ->processRelations($mainProductId, $productIds); - - return $this; - } - - /** - * Retrieve Required children ids - * Return grouped array, ex array( - * group => array(ids) - * ) - * - * @param int $parentId - * @param bool $required - * @return array - */ - public function getChildrenIds($parentId, $required = true) - { - $childrenIds = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('l' => $this->getMainTable()), array('product_id', 'parent_id')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'e.entity_id=l.product_id AND e.required_options=0', - array() - ) - ->where('parent_id=?', $parentId); - - $childrenIds = array(0 => array()); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $childrenIds[0][$row['product_id']] = $row['product_id']; - } - - return $childrenIds; - } - - /** - * Retrieve parent ids array by requered child - * - * @param int|array $childId - * @return array - */ - public function getParentIdsByChild($childId) - { - $parentIds = array(); - - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('product_id', 'parent_id')) - ->where('product_id IN(?)', $childId); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $parentIds[] = $row['parent_id']; - } - - return $parentIds; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute.php index 7274798275..e4193228ed 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,256 +28,11 @@ /** * Catalog super product attribute resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute + extends Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute { - /** - * Label table name cache - * - * @var string - */ - protected $_labelTable; - - /** - * Price table name cache - * - * @var string - */ - protected $_priceTable; - - /** - * Inititalize connection and define tables - * - */ - protected function _construct() - { - $this->_init('catalog/product_super_attribute', 'product_super_attribute_id'); - $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); - $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); - } - - /** - * Retrieve Catalog Helper - * - * @return Mage_Catalog_Helper_Data - */ - public function getCatalogHelper() - { - return Mage::helper('catalog'); - } - - /** - * Load attribute labels - * - * @deprecated - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute - */ - public function loadLabel($attribute) - { - return $this; - } - - /** - * Load prices - * - * @deprecated - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute - */ - public function loadPrices($attribute) - { - return $this; - } - - /** - * Save Custom labels for Attribute name - * - * @param Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute - */ - public function saveLabel($attribute) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->_labelTable, 'value_id') - ->where('product_super_attribute_id=?', $attribute->getId()) - ->where('store_id=?', (int)$attribute->getStoreId()); - if ($valueId = $this->_getWriteAdapter()->fetchOne($select)) { - $this->_getWriteAdapter()->update($this->_labelTable,array( - 'use_default' => (int) $attribute->getUseDefault(), - 'value'=>$attribute->getLabel() - ), - $this->_getWriteAdapter()->quoteInto('value_id=?', $valueId) - ); - } - else { - $this->_getWriteAdapter()->insert($this->_labelTable, array( - 'product_super_attribute_id' => $attribute->getId(), - 'store_id' => (int) $attribute->getStoreId(), - 'use_default' => (int) $attribute->getUseDefault(), - 'value' => $attribute->getLabel() - )); - } - return $this; - } - - /** - * Save Options prices (Depends from price save scope) - * - * @param Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute - */ - public function savePrices($attribute) - { - $write = $this->_getWriteAdapter(); - // define website id scope - if ($this->getCatalogHelper()->isPriceGlobal()) { - $websiteId = 0; - } else { - $websiteId = Mage::app()->getStore($attribute->getStoreId())->getWebsite()->getId(); - } - - $values = $attribute->getValues(); - if (!is_array($values)) { - $values = array(); - } - - $new = array(); - $old = array(); - - // retrieve old values - $select = $write->select() - ->from($this->_priceTable) - ->where('product_super_attribute_id=?', $attribute->getId()) - ->where('website_id=?', $websiteId); - - $rowSet = $write->fetchAll($select); - foreach ($rowSet as $row) { - $key = join('-', array($row['website_id'], $row['value_index'])); - if (!isset($old[$key])) { - $old[$key] = $row; - } else { - // delete invalid (duplicate row) - $where = $write->quoteInto('value_id=?', $row['value_id']); - $write->delete($this->_priceTable, $where); - } - } - - // prepare new values - foreach ($values as $v) { - if (empty($v['value_index'])) { - continue; - } - $key = join('-', array($websiteId, $v['value_index'])); - $new[$key] = array( - 'value_index' => $v['value_index'], - 'pricing_value' => $v['pricing_value'], - 'is_percent' => $v['is_percent'], - 'website_id' => $websiteId, - 'use_default' => !empty($v['use_default_value']) ? true : false - ); - } - - $insert = array(); - $update = array(); - $delete = array(); - - foreach ($old as $k => $v) { - if (!isset($new[$k])) { - $delete[] = $v['value_id']; - } - } - foreach ($new as $k => $v) { - $needInsert = false; - $needUpdate = false; - $needDelete = false; - - $isGlobal = true; - if (!$this->getCatalogHelper()->isPriceGlobal() && $websiteId != 0) { - $isGlobal = false; - } - - $hasValue = ($isGlobal && !empty($v['pricing_value'])) - || (!$isGlobal && !$v['use_default']); - - if (isset($old[$k])) { - // data changed - $dataChanged = ($old[$k]['is_percent'] != $v['is_percent']) - || ($old[$k]['pricing_value'] != $v['pricing_value']); - if (!$hasValue) { - $needDelete = true; - } else if ($dataChanged) { - $needUpdate = true; - } - } else if ($hasValue) { - $needInsert = true; - } - - if (!$isGlobal && empty($v['pricing_value'])) { - $v['pricing_value'] = 0; - $v['is_percent'] = 0; - } - - if ($needInsert) { - $insert[] = array( - 'product_super_attribute_id' => $attribute->getId(), - 'value_index' => $v['value_index'], - 'is_percent' => $v['is_percent'], - 'pricing_value' => $v['pricing_value'], - 'website_id' => $websiteId - ); - } - if ($needUpdate) { - $update[$old[$k]['value_id']] = array( - 'is_percent' => $v['is_percent'], - 'pricing_value' => $v['pricing_value'] - ); - } - if ($needDelete) { - $delete[] = $old[$k]['value_id']; - } - } - - if (!empty($delete)) { - $where = $write->quoteInto('value_id IN(?)', $delete); - $write->delete($this->_priceTable, $where); - } - if (!empty($update)) { - foreach ($update as $valueId => $bind) { - $where = $write->quoteInto('value_id=?', $valueId); - $write->update($this->_priceTable, $bind, $where); - } - } - if (!empty($insert)) { - $write->insertMultiple($this->_priceTable, $insert); - } - - - return $this; - } - - /** - * Retrieve Used in Configurable Products Attributes - * - * @param int $setId The specific attribute set - * @return array - */ - public function getUsedAttributes($setId) - { - $select = $this->_getReadAdapter()->select() - ->distinct(true) - ->from(array('e' => $this->getTable('catalog/product')), null) - ->join( - array('a' => $this->getMainTable()), - 'e.entity_id=a.product_id', - array('attribute_id') - ) - ->where('e.attribute_set_id=?', $setId) - ->where('e.type_id=?', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE); - - return $this->_getReadAdapter()->fetchCol($select); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute/Collection.php index d8d7e587c6..4be0e95eb6 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,269 +28,11 @@ /** * Catalog Configurable Product Attribute Collection * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection { - /** - * Configurable attributes label table name - * - * @var string - */ - protected $_labelTable; - - /** - * Configurable attributes price table name - * - * @var string - */ - protected $_priceTable; - - /** - * Product instance - * - * @var Mage_Catalog_Model_Product - */ - protected $_product; - - /** - * Initialize connection and define table names - * - */ - protected function _construct() - { - $this->_init('catalog/product_type_configurable_attribute'); - $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); - $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); - } - - /** - * Retrieve catalog helper - * - * @return Mage_Catalog_Helper_Data - */ - public function getHelper() - { - return Mage::helper('catalog'); - } - - /** - * Set Product filter (Configurable) - * - * @param Mage_Catalog_Model_Product $product - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - public function setProductFilter($product) - { - $this->_product = $product; - $this->addFieldToFilter('product_id', $product->getId()); - return $this; - } - - /** - * Set order collection by Position - * - * @param string $dir - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - public function orderByPosition($dir='asc') - { - $this->getSelect()->order('position '.$dir); - return $this; - } - - /** - * Retrieve Store Id - * - * @return int - */ - public function getStoreId() - { - return (int)$this->_product->getStoreId(); - } - - /** - * After load collection process - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - Varien_Profiler::start('TTT1:'.__METHOD__); - $this->_addProductAttributes(); - Varien_Profiler::stop('TTT1:'.__METHOD__); - Varien_Profiler::start('TTT2:'.__METHOD__); - $this->_addAssociatedProductFilters(); - Varien_Profiler::stop('TTT2:'.__METHOD__); - Varien_Profiler::start('TTT3:'.__METHOD__); - $this->_loadLabels(); - Varien_Profiler::stop('TTT3:'.__METHOD__); - Varien_Profiler::start('TTT4:'.__METHOD__); - $this->_loadPrices(); - Varien_Profiler::stop('TTT4:'.__METHOD__); - return $this; - } - - /** - * Add product attributes to collection items - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - protected function _addProductAttributes() - { - foreach ($this->_items as $item) { - $productAttribute = $this->getProduct()->getTypeInstance(true) - ->getAttributeById($item->getAttributeId(), $this->getProduct()); - $item->setProductAttribute($productAttribute); - } - return $this; - } - - /** - * Add Associated Product Filters (From Product Type Instance) - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - public function _addAssociatedProductFilters() - { - $this->getProduct()->getTypeInstance(true) - ->getUsedProducts($this->getColumnValues('attribute_id'), $this->getProduct()); // Filter associated products - return $this; - } - - /** - * Load attribute labels - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - protected function _loadLabels() - { - if ($this->count()) { - $select = $this->getConnection()->select() - ->from(array('default'=>$this->_labelTable)) - ->joinLeft( - array('store' => $this->_labelTable), - 'store.product_super_attribute_id=default.product_super_attribute_id AND store.store_id='.$this->getStoreId(), - array( - 'use_default' => new Zend_Db_Expr('IFNULL(store.use_default, default.use_default)'), - 'label' => new Zend_Db_Expr('IFNULL(store.value, default.value)') - )) - ->where('default.product_super_attribute_id IN (?)', array_keys($this->_items)) - ->where('default.store_id=0'); - foreach ($this->getConnection()->fetchAll($select) as $data) { - $this->getItemById($data['product_super_attribute_id'])->setLabel($data['label']); - $this->getItemById($data['product_super_attribute_id'])->setUseDefault($data['use_default']); - } - } - return $this; - } - - /** - * Load attribute prices information - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection - */ - protected function _loadPrices() - { - if ($this->count()) { - $pricings = array( - 0 => array() - ); - if ($this->getHelper()->isPriceGlobal()) { - $websiteId = 0; - } - else { - $websiteId = (int)Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - $pricing[$websiteId] = array(); - } - $select = $this->getConnection()->select() - ->from(array('price' => $this->_priceTable)) - ->where('price.product_super_attribute_id IN (?)', array_keys($this->_items)); - if ($websiteId > 0) { - $select->where('price.website_id IN(?)', array(0, $websiteId)); - } - else { - $select->where('price.website_id=0'); - } - $query = $this->getConnection()->query($select); - - while ($row = $query->fetch()) { - $pricings[(int)$row['website_id']][] = $row; - } - - $values = array(); - - foreach ($this->_items as $item) { - $productAttribute = $item->getProductAttribute(); - if (!($productAttribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract)) { - continue; - } - $options = $productAttribute->getFrontend()->getSelectOptions(); - foreach ($options as $option) { - foreach ($this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()) as $associatedProduct) { - if (!empty($option['value']) - && $option['value'] == $associatedProduct->getData( - $productAttribute->getAttributeCode())) { - // If option aviable in associated product - if (!isset($values[$item->getId() . ':' . $option['value']])) { - // If option not added, we will add it. - $values[$item->getId() . ':' . $option['value']] = array( - 'product_super_attribute_id' => $item->getId(), - 'value_index' => $option['value'], - 'label' => $option['label'], - 'default_label' => $option['label'], - 'store_label' => $option['label'], - 'is_percent' => 0, - 'pricing_value' => null, - 'use_default_value' => true - ); - } - } - } - } - } - - foreach ($pricings[0] as $pricing) { - // Addding pricing to options - $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; - if (isset($values[$valueKey])) { - $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; - $values[$valueKey]['is_percent'] = $pricing['is_percent']; - $values[$valueKey]['value_id'] = $pricing['value_id']; - $values[$valueKey]['use_default_value'] = true; - } - } - - if ($websiteId && isset($pricings[$websiteId])) { - foreach ($pricings[$websiteId] as $pricing) { - $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; - if (isset($values[$valueKey])) { - $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; - $values[$valueKey]['is_percent'] = $pricing['is_percent']; - $values[$valueKey]['value_id'] = $pricing['value_id']; - $values[$valueKey]['use_default_value'] = false; - } - } - } - - foreach ($values as $data) { - $this->getItemById($data['product_super_attribute_id'])->addPrice($data); - } - } - return $this; - } - - /** - * Retrive product instance - * - * @return Mage_Catalog_Model_Product - */ - public function getProduct() - { - return $this->_product; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Product/Collection.php index 98dea5aca5..ec74d35735 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Product/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Type/Configurable/Product/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,43 +28,11 @@ /** * Catalog super product link collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Product_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection + extends Mage_Catalog_Model_Resource_Product_Type_Configurable_Product_Collection { - protected $_linkTable; - protected function _construct() - { - parent::_construct(); - $this->_linkTable = $this->getTable('catalog/product_super_link'); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->getSelect()->join(array('link_table' => $this->_linkTable), - 'link_table.product_id=e.entity_id', - array('parent_id') - ); - } - - public function setProductFilter($product) - { - $this->getSelect()->where('link_table.parent_id=?', (int) $product->getId()); - return $this; - } - - /** - * Retrieve is flat enabled flag - * Return alvays false if magento run admin - * - * @return bool - */ - public function isEnabledFlat() - { - return false; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Website.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Website.php index 9e5b66c070..9a49a3fc28 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Website.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,131 +28,10 @@ /** * Catalog Product Website Resource Model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website extends Mage_Catalog_Model_Resource_Product_Website { - /** - * Initialize connection and define resource table - * - */ - protected function _construct() - { - $this->_init('catalog/product_website', 'product_id'); - } - - /** - * Get catalog product resource model - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product - */ - protected function _getProductResource() - { - return Mage::getResourceSingleton('catalog/product'); - } - - /** - * Removes products from websites - * - * @param array $websiteIds - * @param array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website - */ - public function removeProducts($websiteIds, $productIds) - { - if (!is_array($websiteIds) || !is_array($productIds) - || count($websiteIds) == 0 || count($productIds) == 0) - { - return $this; - } - - $whereCond = array( - $this->_getWriteAdapter()->quoteInto('website_id IN(?)', $websiteIds), - $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $productIds) - ); - $whereCond = join(' AND ', $whereCond); - - $this->_getWriteAdapter()->beginTransaction(); - try { - $this->_getWriteAdapter()->delete($this->getMainTable(), $whereCond); - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - return $this; - } - - /** - * Add products to websites - * - * @param array $websiteIds - * @param array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website - */ - public function addProducts($websiteIds, $productIds) - { - if (!is_array($websiteIds) || !is_array($productIds) - || count($websiteIds) == 0 || count($productIds) == 0) - { - return $this; - } - - $this->_getWriteAdapter()->beginTransaction(); - - // Before adding of products we should remove it old rows with same ids - $this->removeProducts($websiteIds, $productIds); - try { - foreach ($websiteIds as $websiteId) { - foreach ($productIds as $productId) { - if (!$productId) { - continue; - } - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'product_id' => $productId, - 'website_id' => $websiteId - )); - } - - // Refresh product enabled index - $storeIds = Mage::app()->getWebsite($websiteId)->getStoreIds(); - foreach ($storeIds as $storeId) { - $store = Mage::app()->getStore($storeId); - $this->_getProductResource()->refreshEnabledIndex($store, $productIds); - } - } - - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - return $this; - } - - /** - * Retrieve product(s) website ids. - * - * @param array $productIds - * @return array - */ - public function getWebsites($productIds) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('product_id', 'website_id')) - ->where('product_id IN (?)', $productIds); - $rowset = $this->_getReadAdapter()->fetchAll($select); - - $result = array(); - foreach ($rowset as $row) { - $result[$row['product_id']][] = $row['website_id']; - } - - return $result; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend.php index 16a0854a35..afb13e3ec2 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend.php @@ -20,34 +20,18 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Sendfriend extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('catalog/sendfriend', 'log_id'); - } - - public function getSendCount($model, $ip, $startTime) - { - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getTable('sendfriend')), new Zend_Db_Expr('count(*)')) - ->where('main_table.ip = ?', $ip) - ->where('main_table.time >= ?', $startTime); - - $data = $this->_getReadAdapter()->fetchRow($select); - return $data['count(*)']; - } - - public function deleteLogsBefore($time) - { - $deleted = $this->_getWriteAdapter() - ->delete($this->getTable('sendfriend'), $this->_getWriteAdapter()->quoteInto('time < ?', $time)); - - return $this; - } +/** + * Catalog Eav Sendfriend resource model class + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team + */ +class Mage_Catalog_Model_Resource_Eav_Mysql4_Sendfriend extends Mage_Sendfriend_Model_Resource_Sendfriend +{ } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend/Collection.php index cdfae10ce9..924857418b 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Sendfriend/Collection.php @@ -20,14 +20,19 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Sendfriend_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * Catalog Eav Sendfriend Resource Collection + * + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team + */ +class Mage_Catalog_Model_Resource_Eav_Mysql4_Sendfriend_Collection + extends Mage_Sendfriend_Model_Resource_Sendfriend_Collection { - protected function _construct() - { - $this->_init('catalog/sendfriend'); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Setup.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Setup.php index 95df3cb905..3088ac99b7 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Setup.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,1501 +28,10 @@ /** * Catalog entity setup * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup +class Mage_Catalog_Model_Resource_Eav_Mysql4_Setup extends Mage_Catalog_Model_Resource_Setup { - - /** - * Prepare catalog attribute values to save - * - * @param array $attr - * @return array - */ - protected function _prepareValues($attr) - { - $data = parent::_prepareValues($attr); - $data = array_merge($data, array( - 'frontend_input_renderer' => $this->_getValue($attr, 'input_renderer', ''), - 'source_model' => $this->_getValue($attr, 'source', ''), - 'is_global' => $this->_getValue($attr, 'global', 1), - 'is_visible' => $this->_getValue($attr, 'visible', 1), - 'is_searchable' => $this->_getValue($attr, 'searchable', 0), - 'is_filterable' => $this->_getValue($attr, 'filterable', 0), - 'is_comparable' => $this->_getValue($attr, 'comparable', 0), - 'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0), - 'is_wysiwyg_enabled' => $this->_getValue($attr, 'wysiwyg_enabled', 0), - 'is_html_allowed_on_front' => $this->_getValue($attr, 'is_html_allowed_on_front', 0), - 'is_visible_in_advanced_search' - => $this->_getValue($attr, 'visible_in_advanced_search', 0), - 'is_filterable_in_search' => $this->_getValue($attr, 'filterable_in_search', 0), - 'used_in_product_listing' => $this->_getValue($attr, 'used_in_product_listing', 0), - 'used_for_sort_by' => $this->_getValue($attr, 'used_for_sort_by', 0), - 'apply_to' => $this->_getValue($attr, 'apply_to', ''), - 'position' => $this->_getValue($attr, 'position', 0), - 'is_configurable' => $this->_getValue($attr, 'is_configurable', 1), - 'is_used_for_promo_rules' => $this->_getValue($attr, 'used_for_promo_rules', 0) - )); - return $data; - } - - /** - * Enter description here... - * - * @return array - */ - public function getDefaultEntities() - { - return array( - 'catalog_category' => array( - 'entity_model' => 'catalog/category', - 'attribute_model' => 'catalog/resource_eav_attribute', - 'table' => 'catalog/category', - 'additional_attribute_table' => 'catalog/eav_attribute', - 'entity_attribute_collection' => 'catalog/category_attribute_collection', - 'attributes' => array( - 'name' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Name', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'is_active' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Is Active', - 'input' => 'select', - 'class' => '', - 'source' => 'eav/entity_attribute_source_boolean', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'url_key' => array( - 'label' => 'URL key', - 'backend' => 'catalog/category_attribute_backend_urlkey', - 'required' => false, - ), - 'description' => array( - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Description', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'wysiwyg_enabled' => true, - 'is_html_allowed_on_front' => true, - 'visible_on_front' => false, - 'unique' => false, - ), - 'image' => array( - 'type' => 'varchar', - //'backend' => 'catalog/category_attribute_backend_image', - //'frontend' => 'catalog/category_attribute_frontend_image', - 'backend' => 'catalog/category_attribute_backend_image', - 'frontend' => '', - 'label' => 'Image', - 'input' => 'image', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'meta_title' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Page Title', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'meta_keywords' => array( - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Meta Keywords', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'meta_description' => array( - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Meta Description', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'display_mode' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Display Mode', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/category_attribute_source_mode', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'landing_page' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'CMS Block', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/category_attribute_source_page', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'is_anchor' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Is Anchor', - 'input' => 'select', - 'class' => '', - 'source' => 'eav/entity_attribute_source_boolean', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - - 'path' => array( - 'type' => 'static', - 'backend' => '', - 'frontend' => '', - 'label' => 'Path', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'position' => array( - 'type' => 'static', - 'backend' => '', - 'frontend' => '', - 'label' => 'Position', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'all_children' => array( - 'type' => 'text', - //'backend' => 'catalog/entity_category_attribute_backend_tree_children', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'path_in_store' => array( - 'type' => 'text', - //'backend' => 'catalog/entity_category_attribute_backend_tree_path', - 'backend' => '', - 'frontend' => '', - 'table' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'children' => array( - 'type' => 'text', - //'backend' => 'catalog/entity_category_attribute_backend_tree_children', - 'frontend' => '', - 'table' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'url_path' => array( - 'type' => 'varchar', - 'frontend' => '', - 'table' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => true, - ), - 'custom_design' => array( - 'type' => 'varchar', - 'label' => 'Custom Design', - 'frontend' => '', - 'table' => '', - 'input' => 'select', - 'class' => '', - 'source' => 'core/design_source_design', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'custom_design_apply' => array( - 'type' => 'int', - 'label' => 'Apply To', - 'frontend' => '', - 'table' => '', - 'input' => 'select', - 'class' => '', - 'source' => 'core/design_source_apply', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'custom_design_from' => array( - 'type' => 'datetime', - 'label' => 'Active From', - 'frontend' => '', - 'table' => '', - 'input' => 'date', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'backend' => 'eav/entity_attribute_backend_datetime', - ), - 'custom_design_to' => array( - 'type' => 'datetime', - 'label' => 'Active To', - 'frontend' => '', - 'table' => '', - 'input' => 'date', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'backend' => 'eav/entity_attribute_backend_datetime', - ), - 'page_layout' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Page Layout', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/category_attribute_source_layout', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'custom_layout_update' => array( - 'type' => 'text', - 'label' => 'Custom Layout Update', - 'frontend' => '', - 'table' => '', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'level' => array( - 'type' => 'static', - 'backend' => '', - 'frontend' => '', - 'label' => 'Level', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'children_count' => array( - 'type' => 'static', - 'backend' => '', - 'frontend' => '', - 'label' => 'Children Count', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'available_sort_by' => array( - 'input' => 'multiselect', - 'type' => 'text', - 'label' => 'Available Product Listing Sort By', - 'source' => 'catalog/category_attribute_source_sortby', - 'backend' => 'catalog/category_attribute_backend_sortby', - 'required' => true, - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'input_renderer'=> 'adminhtml/catalog_category_helper_sortby_available', - ), - 'default_sort_by' => array( - 'input' => 'select', - 'label' => 'Default Product Listing Sort By', - 'source' => 'catalog/category_attribute_source_sortby', - 'backend' => 'catalog/category_attribute_backend_sortby', - 'required' => true, - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'input_renderer'=> 'adminhtml/catalog_category_helper_sortby_default', - ), - ), - ), - 'catalog_product' => array( - 'entity_model' => 'catalog/product', - 'attribute_model' => 'catalog/resource_eav_attribute', - 'table' => 'catalog/product', - 'additional_attribute_table' => 'catalog/eav_attribute', - 'entity_attribute_collection' => 'catalog/product_attribute_collection', - 'attributes' => array( - 'name' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Name', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'used_in_product_listing' => true, - 'used_for_sort_by' => true, - 'unique' => false, - ), - 'description' => array( - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Description', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => true, - 'wysiwyg_enabled' => true, - 'is_html_allowed_on_front' => true, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'unique' => false, - ), - 'short_description' => array( - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Short Description', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => true, - 'wysiwyg_enabled' => true, - 'is_html_allowed_on_front' => true, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'sku' => array( - 'type' => 'static', - 'backend' => '', - 'frontend' => '', - 'label' => 'SKU', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => true, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'unique' => true, - ), - 'price' => array( - 'group' => 'Prices', - 'type' => 'decimal', - 'backend' => 'catalog/product_attribute_backend_price', - 'frontend' => '', - 'label' => 'Price', - 'input' => 'price', - 'class' => 'validate-number', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => true, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'used_in_product_listing' => true, - 'used_for_sort_by' => true, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'special_price' => array( - 'group' => 'Prices', - 'type' => 'decimal', - 'backend' => 'catalog/product_attribute_backend_price', - 'frontend' => '', - 'label' => 'Special Price', - 'input' => 'price', - 'class' => 'validate-number', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'special_from_date' => array( - 'group' => 'Prices', - 'type' => 'datetime', - 'backend' => 'catalog/product_attribute_backend_startdate', - 'frontend' => '', - 'label' => 'Special Price From Date', - 'input' => 'date', - 'class' => 'validate-date', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'special_to_date' => array( - 'group' => 'Prices', - 'type' => 'datetime', - 'backend' => 'eav/entity_attribute_backend_datetime', - 'frontend' => '', - 'label' => 'Special Price To Date', - 'input' => 'date', - 'class' => 'validate-date', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'cost' => array( - 'group' => 'Prices', - 'type' => 'decimal', - 'backend' => 'catalog/product_attribute_backend_price', - 'frontend' => '', - 'label' => 'Cost', - 'input' => 'price', - 'class' => 'validate-number', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => true, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple,virtual', - ), - 'weight' => array( - 'type' => 'decimal', - 'backend' => '', - 'frontend' => '', - 'label' => 'Weight', - 'input' => 'text', - 'class' => 'validate-number', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple', - ), - 'manufacturer' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Manufacturer', - 'input' => 'select', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => true, - 'default' => '', - 'searchable' => true, - 'filterable' => true, - 'comparable' => true, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'unique' => false, - 'apply_to' => 'simple', - ), - 'meta_title' => array( - 'group' => 'Meta Information', - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Meta Title', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'meta_keyword' => array( - 'group' => 'Meta Information', - 'type' => 'text', - 'backend' => '', - 'frontend' => '', - 'label' => 'Meta Keywords', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'meta_description' => array( - 'group' => 'Meta Information', - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Meta Description', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'note' => 'Maximum 255 chars', - ), - 'image' => array( - 'group' => 'Images', - 'type' => 'varchar', - //'backend' => 'catalog/entity_product_attribute_backend_image', - 'frontend' => 'catalog/product_attribute_frontend_image', - 'label' => 'Base Image', - 'input' => 'media_image', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'small_image' => array( - 'group' => 'Images', - 'type' => 'varchar', - //'backend' => 'catalog/entity_product_attribute_backend_image', - 'frontend' => 'catalog/product_attribute_frontend_image', - 'label' => 'Small Image', - 'input' => 'media_image', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'thumbnail' => array( - 'group' => 'Images', - 'type' => 'varchar', - //'backend' => 'catalog/entity_product_attribute_backend_image', - 'frontend' => 'catalog/product_attribute_frontend_image', - 'label' => 'Thumbnail', - 'input' => 'media_image', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'media_gallery' => array( - 'group' => 'Images', - 'label' => 'Media Gallery', - 'input' => 'gallery', - 'backend' => 'catalog/product_attribute_backend_media', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'old_id' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'tier_price' => array( - 'group' => 'Prices', - 'type' => 'decimal', - 'backend' => 'catalog/product_attribute_backend_tierprice', - 'label' => 'Tier Price', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_for_price_rules' => false, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'color' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Color', - 'input' => 'select', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => true, - 'default' => '', - 'searchable' => true, - 'filterable' => true, - 'comparable' => true, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'unique' => false, - 'apply_to' => 'simple', - ), - 'news_from_date' => array( - 'type' => 'datetime', - 'group' => 'General', - 'backend' => 'eav/entity_attribute_backend_datetime', - 'frontend' => '', - 'label' => 'Set Product as New from Date', - 'input' => 'date', - 'class' => 'validate-date', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'news_to_date' => array( - 'type' => 'datetime', - 'group' => 'General', - 'backend' => 'eav/entity_attribute_backend_datetime', - 'frontend' => '', - 'label' => 'Set Product as New to Date', - 'input' => 'date', - 'class' => 'validate-date', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'gallery' => array( - 'group' => 'Images', - 'type' => 'varchar', - //'backend' => 'catalog/entity_product_attribute_backend_gallery', - //'table' => 'catalog_product_entity_gallery', - 'frontend' => '', - 'label' => 'Image Gallery', - 'input' => 'gallery', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - ), - 'status' => array( - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Status', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/product_status', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => false, - 'used_in_product_listing' => true, - 'unique' => false, - ), - 'tax_class_id' => array( - 'group' => 'Prices', - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Tax Class', - 'input' => 'select', - 'class' => '', - 'source' => 'tax/class_source_product', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => true, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => true, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'url_key' => array( - 'label' => 'URL key', - 'backend' => 'catalog/product_attribute_backend_urlkey', - 'required' => false, - 'used_in_product_listing' => true, - ), - 'url_path' => array( - 'type' => 'varchar', - 'frontend' => '', - 'table' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => true, - ), - 'minimal_price' => array( - 'group' => 'Prices', - 'type' => 'decimal', - 'backend' => '', - 'frontend' => '', - 'label' => 'Minimal Price', - 'input' => 'price', - 'class' => 'validate-number', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple,configurable,virtual', - ), - 'is_recurring' => array( - 'group' => 'Recurring Profile', - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Enable Recurring Profile', - 'note' => 'Nominal price option may be used for manipulating recurring fees.', - 'input' => 'select', - 'class' => '', - 'source' => 'eav/entity_attribute_source_boolean', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple,virtual', - 'is_configurable' => false - ), - 'recurring_profile' => array( - 'group' => 'Recurring Profile', - 'type' => 'text', - 'backend' => 'catalog/product_attribute_backend_recurring', - 'frontend' => '', - 'label' => 'Recurring Profile', - 'input' => 'text', // doesn't matter - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'simple,virtual', - 'is_configurable' => false - ), - 'visibility' => array( - 'group' => 'General', - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Visibility', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/product_visibility', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '4', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => false, - 'unique' => false, - ), - 'custom_design' => array( - 'type' => 'varchar', - 'label' => 'Custom Design', - 'frontend' => '', - 'table' => '', - 'input' => 'select', - 'class' => '', - 'source' => 'core/design_source_design', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'group' => 'Design', - ), - 'custom_design_from' => array( - 'type' => 'datetime', - 'label' => 'Active From', - 'frontend' => '', - 'table' => '', - 'input' => 'date', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'backend' => 'eav/entity_attribute_backend_datetime', - 'group' => 'Design', - ), - 'custom_design_to' => array( - 'type' => 'datetime', - 'label' => 'Active To', - 'frontend' => '', - 'table' => '', - 'input' => 'date', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'backend' => 'eav/entity_attribute_backend_datetime', - 'group' => 'Design', - ), - 'custom_layout_update' => array( - 'type' => 'text', - 'label' => 'Custom Layout Update', - 'frontend' => '', - 'table' => '', - 'input' => 'textarea', - 'class' => '', - 'source' => '', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'group' => 'Design', - ), - 'page_layout' => array( - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Page Layout', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/product_attribute_source_layout', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'group' => 'Design' - ), - 'options_container' => array( - 'group' => 'Design', - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Display product options in', - 'input' => 'select', - 'class' => '', - 'source' => 'catalog/entity_product_attribute_design_options_container', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => true, - 'required' => false, - 'user_defined' => false, - 'default' => 'container2', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'visible_in_advanced_search' => false, - 'unique' => false, - ), - 'required_options' => array( - 'type' => 'static', - 'visible' => false, - 'default' => false, - 'used_in_product_listing' => true, - 'required' => false, - ), - 'has_options' => array( - 'type' => 'static', - 'visible' =>false, - 'default' => false, - 'required' => false, - ), - 'image_label' => array( - 'type' => 'varchar', - 'label' => 'Image Label', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'searchable' => false, - 'is_configurable' => false, - 'used_in_product_listing' => true, - ), - 'small_image_label' => array( - 'type' => 'varchar', - 'label' => 'Small Image Label', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'searchable' => false, - 'is_configurable' => false, - 'used_in_product_listing' => true, - ), - 'thumbnail_label' => array( - 'type' => 'varchar', - 'label' => 'Thumbnail Label', - 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, - 'visible' => false, - 'required' => false, - 'searchable' => false, - 'is_configurable' => false, - 'used_in_product_listing' => true, - ), - 'created_at' => array( - 'type' => 'static', - 'backend' => 'eav/entity_attribute_backend_time_created', - 'visible' => false, - ), - 'updated_at' => array( - 'type' => 'static', - 'backend' => 'eav/entity_attribute_backend_time_updated', - 'visible' => false, - ) - ), - ), - ); - } - - /** - * Enter description here... - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Setup - */ - public function convertOldTreeToNew() - { - if (!Mage::getModel('catalog/category')->load(1)->getId()) { - Mage::getModel('catalog/category')->setId(1)->setPath(1)->save(); - } - - $categories = array(); - - $select = $this->getConnection()->select(); - $select->from($this->getTable('catalog/category')); - $categories = $this->getConnection()->fetchAll($select); - - if (is_array($categories)) { - foreach ($categories as $category) { - $path = $this->_getCategoryPath($category); - $path = array_reverse($path); - $path = implode('/', $path); - if ($category['entity_id'] != 1 && substr($path, 0, 2) != '1/') { - $path = "1/{$path}"; - } - - $this - ->getConnection() - ->update( - $this->getTable('catalog/category'), - array('path' => $path), - "entity_id = {$category['entity_id']}" - ); - } - } - return $this; - } - - /** - * Enter description here... - * - * @param int $id - * @return array - */ - protected function _getCategoryEntityRow($id) - { - $select = $this->getConnection()->select(); - - $select->from($this->getTable('catalog/category')); - $select->where('entity_id = ?', $id); - - return $this->getConnection()->fetchRow($select); - } - - /** - * Enter description here... - * - * @param array $category - * @param array $path - * @return string - */ - protected function _getCategoryPath($category, $path = array()) - { - $path[] = $category['entity_id']; - - if ($category['parent_id'] != 0) { - $parentCategory = $this->_getCategoryEntityRow($category['parent_id']); - - if ($parentCategory) - $path = $this->_getCategoryPath($parentCategory, $path); - } - - return $path; - } - - /** - * Creates level values for categories and saves them - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Setup - */ - public function rebuildCategoryLevels() - { - $select = $this->getConnection()->select() - ->from($this->getTable('catalog/category')); - - $categories = $this->getConnection()->fetchAll($select); - - foreach ($categories as $category) { - $level = count(explode('/', $category['path']))-1; - $this - ->getConnection() - ->update( - $this->getTable('catalog/category'), - array('level' => $level), - "entity_id = {$category['entity_id']}" - ); - } - return $this; - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php index 80e2c60236..dffeff94ad 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php @@ -20,1243 +20,18 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog url rewrite resource model * - * @category Mage - * @package Mage_Catalog - * @author Magento Core Team + * @category Mage + * @package Mage_Catalog + * @author Magento Core Team */ -class Mage_Catalog_Model_Resource_Eav_Mysql4_Url extends Mage_Core_Model_Mysql4_Abstract +class Mage_Catalog_Model_Resource_Eav_Mysql4_Url extends Mage_Catalog_Model_Resource_Url { - /** - * Stores configuration array - * - * @var array - */ - protected $_stores; - - /** - * Category attribute properties cache - * - * @var array - */ - protected $_categoryAttributes = array(); - - /** - * Product attribute properties cache - * - * @var array - */ - protected $_productAttributes = array(); - - /** - * Limit products for select - * - * @var int - */ - protected $_productLimit = 250; - - /** - * Cache of root category children ids - * - * @var array - */ - protected $_rootChildrenIds = array(); - - /** - * Load core Url rewrite model - * - */ - protected function _construct() - { - $this->_init('core/url_rewrite', 'url_rewrite_id'); - } - - /** - * Retrieve stores array or store model - * - * @param int $storeId - * @return Mage_Core_Model_Store|array - */ - public function getStores($storeId = null) - { - if (is_null($this->_stores)) { - $this->_stores = $this->_prepareStoreRootCategories(Mage::app()->getStores()); - } - if ($storeId && isset($this->_stores[$storeId])) { - return $this->_stores[$storeId]; - } - return $this->_stores; - } - - /** - * Retrieve Category model singleton - * - * @return Mage_Catalog_Model_Category - */ - public function getCategoryModel() - { - return Mage::getSingleton('catalog/category'); - } - - /** - * Retrieve product model singleton - * - * @return Mage_Catalog_Model_Product - */ - public function getProductModel() - { - return Mage::getSingleton('catalog/product'); - } - - /** - * Retrieve rewrite by idPath - * - * @param string $idPath - * @return Varien_Object - */ - public function getRewriteByIdPath($idPath, $storeId) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('store_id=?', $storeId) - ->where('id_path=?', $idPath); - $row = $this->_getWriteAdapter()->fetchRow($select); - - if (!$row) { - return false; - } - $rewrite = new Varien_Object($row); - $rewrite->setIdFieldName($this->getIdFieldName()); - return $rewrite; - } - - /** - * Retrieve rewrite by requestPath - * - * @param string $requestPath - * @return Varien_Object - */ - public function getRewriteByRequestPath($requestPath, $storeId) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('store_id=?', $storeId) - ->where('request_path=?', $requestPath); - $row = $this->_getWriteAdapter()->fetchRow($select); - - if (!$row) { - return false; - } - $rewrite = new Varien_Object($row); - $rewrite->setIdFieldName($this->getIdFieldName()); - return $rewrite; - } - - /** - * Validate array of request paths. Return first not used path in case if validations passed - * - * @param array $paths - * @param int $storeId - * @return false | string - */ - public function checkRequestPaths($paths, $storeId) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), 'request_path') - ->where('store_id=?', $storeId) - ->where('request_path IN (?)', $paths); - $data = $this->_getWriteAdapter()->fetchCol($select); - $paths = array_diff($paths, $data); - if (empty($paths)) { - return false; - } else { - reset($paths); - return current($paths); - } - } - - /** - * Prepare rewrites for condition - * - * @param int $storeId - * @param int|array $categoryIds - * @param int|array $productIds - * @return array - */ - public function prepareRewrites($storeId, $categoryIds = null, $productIds = null) - { - $rewrites = array(); - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('store_id=?', $storeId) - ->where('is_system=?', 1); - - if (is_null($categoryIds)) { - $select->where('category_id IS NULL'); - } - elseif ($categoryIds) { - $catIds = is_array($categoryIds) ? $categoryIds : array($categoryIds); - - // Check maybe we request products and root category id is within categoryIds, - // it's a separate case because root category products are stored with NULL categoryId - if ($productIds) { - $addNullCategory = in_array($this->getStores($storeId)->getRootCategoryId(), $catIds); - } else { - $addNullCategory = false; - } - - // Compose optimal condition - if ($addNullCategory) { - $select->where('category_id IN(?) OR category_id IS NULL', $catIds); - } else { - $select->where('category_id IN(?)', $catIds); - } - } - - if (is_null($productIds)) { - $select->where('product_id IS NULL'); - } - elseif ($productIds) { - $select->where('product_id IN(?)', $productIds); - } - - $query = $this->_getWriteAdapter()->query((string)$select); - - while ($row = $query->fetch()) { - $rewrite = new Varien_Object($row); - $rewrite->setIdFieldName($this->getIdFieldName()); - $rewrites[$rewrite->getIdPath()] = $rewrite; - } - unset($query); - - return $rewrites; - } - - /** - * Save rewrite URL - * - * @param array $rewriteData - * @param Varien_Object $rewriteObject - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function saveRewrite($rewriteData, $rewrite) - { - if ($rewrite && $rewrite->getId()) { - if ($rewriteData['request_path'] != $rewrite->getRequestPath()) { - $where = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $rewrite->getId()); - $this->_getWriteAdapter()->update( - $this->getMainTable(), - $rewriteData, - $where - ); - - // Update existing rewrites history and avoid chain redirects - $where = $this->_getWriteAdapter()->quoteInto('target_path=?', $rewrite->getRequestPath()); - if ($rewrite->getStoreId()) { - $where .= $this->_getWriteAdapter()->quoteInto(' AND store_id=?', $rewrite->getStoreId()); - } - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('target_path' => $rewriteData['request_path']), - $where - ); - } - } - else { - try { - $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData); - } - catch (Exception $e) { - Mage::logException($e); - Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite.')); - } - } - unset($rewriteData); - return $this; - } - - public function saveRewriteHistory($rewriteData) - { - $rewriteData = new Varien_Object($rewriteData); - // check if rewrite exists with save request_path - $rewrite = $this->getRewriteByRequestPath($rewriteData->getRequestPath(), $rewriteData->getStoreId()); - if ($rewrite === false) { - // create permanent redirect - $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData->getData()); - } - - return $this; - } - - /** - * Save category attribute - * - * @param Varien_Object $category - * @param string $attributeCode - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function saveCategoryAttribute(Varien_Object $category, $attributeCode) - { - if (!isset($this->_categoryAttributes[$attributeCode])) { - $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode); - - $this->_categoryAttributes[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal() - ); - unset($attribute); - } - - $attributeTable = $this->_categoryAttributes[$attributeCode]['table']; - - $attributeData = array( - 'entity_type_id' => $this->_categoryAttributes[$attributeCode]['entity_type_id'], - 'attribute_id' => $this->_categoryAttributes[$attributeCode]['attribute_id'], - 'store_id' => $category->getStoreId(), - 'entity_id' => $category->getId(), - 'value' => $category->getData($attributeCode) - ); - - if ($this->_categoryAttributes[$attributeCode]['is_global'] || $category->getStoreId() == 0) { - $attributeData['store_id'] = 0; - } - - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable) - ->where('entity_type_id=?', $attributeData['entity_type_id']) - ->where('attribute_id=?', $attributeData['attribute_id']) - ->where('store_id=?', $attributeData['store_id']) - ->where('entity_id=?', $attributeData['entity_id']); - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']); - $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond); - } - else { - $this->_getWriteAdapter()->insert($attributeTable, $attributeData); - } - - if ($attributeData['store_id'] != 0) { - $attributeData['store_id'] = 0; - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable) - ->where('entity_type_id=?', $attributeData['entity_type_id']) - ->where('attribute_id=?', $attributeData['attribute_id']) - ->where('store_id=?', $attributeData['store_id']) - ->where('entity_id=?', $attributeData['entity_id']); - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']); - $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond); - } - else { - $this->_getWriteAdapter()->insert($attributeTable, $attributeData); - } - } - - unset($attributeData); - return $this; - } - - /** - * Retrieve category attributes - * - * @param string $attributeCode - * @param int|array $categoryIds - * @param int $storeId - * @return array - */ - protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) - { - if (!isset($this->_categoryAttributes[$attributeCode])) { - $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode); - - $this->_categoryAttributes[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal(), - 'is_static' => $attribute->isStatic() - ); - unset($attribute); - } - - if (!is_array($categoryIds)) { - $categoryIds = array($categoryIds); - } - - $attributeTable = $this->_categoryAttributes[$attributeCode]['table']; - if ($this->_categoryAttributes[$attributeCode]['is_static']) { - $select = $this->_getWriteAdapter()->select() - ->from( - $this->getTable('catalog/category'), - array('value'=>$attributeCode, 'entity_id'=>'entity_id') - ) - ->where('entity_id IN(?)', $categoryIds); - } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) { - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable, array('entity_id', 'value')) - ->where('attribute_id = ?', $this->_categoryAttributes[$attributeCode]['attribute_id']) - ->where('store_id=?', 0) - ->where('entity_id IN(?)', $categoryIds); - } else { - $select = $this->_getWriteAdapter()->select() - ->from(array('t1'=>$attributeTable), array('entity_id', 'IF(t2.value_id>0, t2.value, t1.value) as value')) - ->joinLeft( - array('t2'=>$attributeTable), - $this->_getWriteAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId), - array() - ) - ->where('t1.store_id = ?', 0) - ->where('t1.attribute_id = ?', $this->_categoryAttributes[$attributeCode]['attribute_id']) - ->where('t1.entity_id IN(?)', $categoryIds); - } - - - $rowSet = $this->_getWriteAdapter()->fetchAll($select); - - $attributes = array(); - foreach ($rowSet as $row) { - $attributes[$row['entity_id']] = $row['value']; - } - unset($rowSet); - foreach ($categoryIds as $categoryId) { - if (!isset($attributes[$categoryId])) { - $attributes[$categoryId] = null; - } - } - - return $attributes; - } - - /** - * Save product attribute - * - * @param Varien_Object $product - * @param string $attributeCode - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function saveProductAttribute(Varien_Object $product, $attributeCode) - { - if (!isset($this->_productAttributes[$attributeCode])) { - $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode); - - $this->_productAttributes[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal() - ); - unset($attribute); - } - - $attributeTable = $this->_productAttributes[$attributeCode]['table']; - - $attributeData = array( - 'entity_type_id' => $this->_productAttributes[$attributeCode]['entity_type_id'], - 'attribute_id' => $this->_productAttributes[$attributeCode]['attribute_id'], - 'store_id' => $product->getStoreId(), - 'entity_id' => $product->getId(), - 'value' => $product->getData($attributeCode) - ); - - if ($this->_productAttributes[$attributeCode]['is_global'] || $product->getStoreId() == 0) { - $attributeData['store_id'] = 0; - } - - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable) - ->where('entity_type_id=?', $attributeData['entity_type_id']) - ->where('attribute_id=?', $attributeData['attribute_id']) - ->where('store_id=?', $attributeData['store_id']) - ->where('entity_id=?', $attributeData['entity_id']); - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']); - $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond); - } - else { - $this->_getWriteAdapter()->insert($attributeTable, $attributeData); - } - - if ($attributeData['store_id'] != 0) { - $attributeData['store_id'] = 0; - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable) - ->where('entity_type_id=?', $attributeData['entity_type_id']) - ->where('attribute_id=?', $attributeData['attribute_id']) - ->where('store_id=?', $attributeData['store_id']) - ->where('entity_id=?', $attributeData['entity_id']); - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $whereCond = $this->_getWriteAdapter()->quoteInto('value_id=?', $row['value_id']); - $this->_getWriteAdapter()->update($attributeTable, $attributeData, $whereCond); - } - else { - $this->_getWriteAdapter()->insert($attributeTable, $attributeData); - } - } - - unset($attributeData); - return $this; - } - - /** - * Retrieve product attribute - * - * @param string $attributeCode - * @param int|array $productIds - * @param string $storeId - * @return array - */ - public function _getProductAttribute($attributeCode, $productIds, $storeId) - { - if (!isset($this->_productAttributes[$attributeCode])) { - $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode); - - $this->_productAttributes[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal() - ); - unset($attribute); - } - - if (!is_array($productIds)) { - $productIds = array($productIds); - } - - $attributeTable = $this->_productAttributes[$attributeCode]['table']; - if ($this->_productAttributes[$attributeCode]['is_global'] || $storeId == 0) { - $select = $this->_getWriteAdapter()->select() - ->from($attributeTable, array('entity_id', 'value')) - ->where('attribute_id = ?', $this->_productAttributes[$attributeCode]['attribute_id']) - ->where('store_id=?', 0) - ->where('entity_id IN(?)', $productIds); - } - else { - $select = $this->_getWriteAdapter()->select() - ->from(array('t1'=>$attributeTable), array('entity_id', 'IF(t2.value_id>0, t2.value, t1.value) as value')) - ->joinLeft( - array('t2'=>$attributeTable), - $this->_getWriteAdapter()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId), - array() - ) - ->where('t1.store_id = ?', 0) - ->where('t1.attribute_id = ?', $this->_productAttributes[$attributeCode]['attribute_id']) - ->where('t1.entity_id IN(?)', $productIds); - } - - - $rowSet = $this->_getWriteAdapter()->fetchAll($select); - - $attributes = array(); - foreach ($rowSet as $row) { - $attributes[$row['entity_id']] = $row['value']; - } - unset($rowSet); - foreach ($productIds as $productIds) { - if (!isset($attributes[$productIds])) { - $attributes[$productIds] = null; - } - } - - return $attributes; - } - - /** - * Prepare category parentId - * - * @param Varien_Object $category - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - protected function _prepareCategoryParentId(Varien_Object $category) - { - if ($category->getPath() != $category->getId()) { - $split = explode('/', $category->getPath()); - $category->setParentId($split[(count($split) - 2)]); - } - else { - $category->setParentId(0); - } - return $this; - } - - /** - * Prepare stores root categories - * - * @param array $stores - * @return array - */ - protected function _prepareStoreRootCategories($stores) - { - $rootCategoryIds = array(); - foreach ($stores as $store) { - /* @var $store Mage_Core_Model_Store */ - $rootCategoryIds[$store->getRootCategoryId()] = $store->getRootCategoryId(); - } - if ($rootCategoryIds) { - $categories = $this->_getCategories($rootCategoryIds); - } - foreach ($stores as $store) { - /* @var $store Mage_Core_Model_Store */ - if (isset($categories[$store->getRootCategoryId()])) { - $store->setRootCategoryPath($categories[$store->getRootCategoryId()]->getPath()); - $store->setRootCategory($categories[$store->getRootCategoryId()]); - } - else { - unset($stores[$store->getId()]); - } - } - return $stores; - } - - /** - * Retrieve categories objects - * Either $categoryIds or $path (with ending slash) must be specified - * - * @param int|array $categoryIds - * @param int $storeId - * @param string $path - * @return array - */ - protected function _getCategories($categoryIds, $storeId = null, $path = null) - { - $isActiveAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'is_active'); - $categories = array(); - - if (!is_array($categoryIds)) { - $categoryIds = array($categoryIds); - } - - $select = $this->_getWriteAdapter()->select() - ->from(array('main_table' => $this->getTable('catalog/category')), array( - 'main_table.entity_id', - 'main_table.parent_id', - 'main_table.level', - 'is_active' => 'IF(c.value_id>0, c.value, d.value)', - 'main_table.path')); - - if (is_null($path)) { - $select->where('main_table.entity_id IN(?)', $categoryIds); - } else { - // Ensure that path ends with '/', otherwise we can get wrong results - e.g. $path = '1/2' will get '1/20' - if (substr($path, -1) != '/') { - $path .= '/'; - } - - $select - ->where('main_table.path LIKE ?', $path . '%') - ->order('main_table.path'); - } - - $table = $this->getTable('catalog/category') . '_int'; - $select->joinLeft(array('d'=>$table), "d.attribute_id = '{$isActiveAttribute->getId()}' AND d.store_id = 0 AND d.entity_id = main_table.entity_id", array()) - ->joinLeft(array('c'=>$table), "c.attribute_id = '{$isActiveAttribute->getId()}' AND c.store_id = '{$storeId}' AND c.entity_id = main_table.entity_id", array()); - - // Prepare variables for checking whether categories belong to store - if (!is_null($storeId)) { - $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); - $rootCategoryPathLength = strlen($rootCategoryPath); - } - - $rowSet = $this->_getWriteAdapter()->fetchAll($select); - foreach ($rowSet as $row) { - if (!is_null($storeId)) { - // Check the category to be either store's root or its descendant - // First - check that category's start is the same as root category - if (substr($row['path'], 0, $rootCategoryPathLength) != $rootCategoryPath) { - continue; - } - // Second - check non-root category - that it's really a descendant, not a simple string match - if ((strlen($row['path']) > $rootCategoryPathLength) && ($row['path'][$rootCategoryPathLength] != '/')) { - continue; - } - } - - $category = new Varien_Object($row); - $category->setIdFieldName('entity_id'); - $category->setStoreId($storeId); - $this->_prepareCategoryParentId($category); - - $categories[$category->getId()] = $category; - } - unset($rowSet); - - if (!is_null($storeId) && $categories) { - foreach (array('name', 'url_key', 'url_path') as $attributeCode) { - $attributes = $this->_getCategoryAttribute($attributeCode, array_keys($categories), $category->getStoreId()); - foreach ($attributes as $categoryId => $attributeValue) { - $categories[$categoryId]->setData($attributeCode, $attributeValue); - } - } - } - - return $categories; - } - - /** - * Retrieve category data object - * - * @param int $categoryId - * @param int $storeId - * @return Varien_Object - */ - public function getCategory($categoryId, $storeId) - { - if (!$categoryId || !$storeId) { - return false; - } - - $categories = $this->_getCategories($categoryId, $storeId); - if (isset($categories[$categoryId])) { - return $categories[$categoryId]; - } - return false; - } - - /** - * Retrieve categories data objects by their ids. Return only categories that belong to specified store. - * - * @param int|array $categoryIds - * @param int $storeId - * @return array - */ - public function getCategories($categoryIds, $storeId) - { - if (!$categoryIds || !$storeId) { - return false; - } - - return $this->_getCategories($categoryIds, $storeId); - } - - /** - * Retrieve category childs data objects - * - * @param Varien_Object $category - * @return Varien_Object - */ - public function loadCategoryChilds(Varien_Object $category) - { - if (is_null($category->getId()) || is_null($category->getStoreId())) { - return $category; - } - - $categories = $this->_getCategories(null, $category->getStoreId(), $category->getPath() . '/'); - $category->setChilds(array()); - foreach ($categories as $child) { - if (!is_array($child->getChilds())) { - $child->setChilds(array()); - } - if ($child->getParentId() == $category->getId()) { - $category->setChilds($category->getChilds() + array($child->getId() => $child)); - } - else { - if (isset($categories[$child->getParentId()])) { - if (!is_array($categories[$child->getParentId()]->getChilds())) { - $categories[$child->getParentId()]->setChilds(array()); - } - $categories[$child->getParentId()]->setChilds($categories[$child->getParentId()]->getChilds() + array($child->getId() => $child)); - } - } - } - $category->setAllChilds($categories); - - return $category; - } - - /** - * Retrieves all children ids of root category tree - * Actually this routine can be used to get children ids of any category, not only root. - * But as far as result is cached in memory, it's not recommended to do so. - * - * @param Varien_Object $category - * @return Varien_Object - */ - public function getRootChildrenIds($categoryId, $categoryPath, $includeStart = true) - { - if (!isset($this->_rootChildrenIds[$categoryId])) { - // Select all descedant category ids - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from(array($this->getTable('catalog/category')), array('entity_id')) - ->where('path LIKE ?', $categoryPath . '/%'); - - $categoryIds = array(); - $rowSet = $adapter->fetchAll($select); - foreach ($rowSet as $row) { - $categoryIds[$row['entity_id']] = $row['entity_id']; - } - $this->_rootChildrenIds[$categoryId] = $categoryIds; - } - - $categoryIds = $this->_rootChildrenIds[$categoryId]; - if ($includeStart) { - $categoryIds[$categoryId] = $categoryId; - } - return $categoryIds; - } - - /** - * Retrieve category parent path - * - * @param Varien_Object $category - * @return string - */ - public function getCategoryParentPath(Varien_Object $category) - { - $store = Mage::app()->getStore($category->getStoreId()); - if ($category->getId() == $store->getRootCategoryId()) { - return ''; - } - elseif ($category->getParentId() == 1 || $category->getParentId() == $store->getRootCategoryId()) { - return ''; - } - else { - $parentCategory = $this->getCategory($category->getParentId(), $store->getId()); - return $parentCategory->getUrlPath() . '/'; - } - } - - /** - * Retrieve product ids by category - * - * @param Varien_Object|int $category - * @return array - */ - public function getProductIdsByCategory($category) - { - $productIds = array(); - if ($category instanceof Varien_Object) { - $categoryId = $category->getId(); - } - else { - $categoryId = $category; - } - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable('catalog/category_product')) - ->where('category_id=?', $categoryId) - ->order('product_id'); - $rowSet = $this->_getWriteAdapter()->fetchAll($select); - foreach ($rowSet as $row) { - $productIds[$row['product_id']] = $row['product_id']; - } - - return $productIds; - } - - /** - * Retrieve Product data objects - * - * @param int|array $productIds - * @param int $storeId - * @param int $entityId - * @param int $lastEntityId - * @return array - */ - protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId) - { - $products = array(); - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - if (!is_null($productIds)) { - if (!is_array($productIds)) { - $productIds = array($productIds); - } - } - $select = $this->_getWriteAdapter()->select() - ->useStraightJoin(true) - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) - ->join( - array('w' => $this->getTable('catalog/product_website')), - $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId), - array() - ) - ->where('e.entity_id>?', $entityId) - ->order('e.entity_id') - ->limit($this->_productLimit); - if (!is_null($productIds)) { - $select->where('e.entity_id IN(?)', $productIds); - } - - $query = $this->_getWriteAdapter()->query($select); - while ($row = $query->fetch()) { - $product = new Varien_Object($row); - $product->setIdFieldName('entity_id'); - $product->setCategoryIds(array()); - $product->setStoreId($storeId); - $products[$product->getId()] = $product; - $lastEntityId = $product->getId(); - } - - unset($query); - - if ($products) { - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('catalog/category_product'), - array('product_id', 'category_id')) - ->where('product_id IN(?)', array_keys($products)); - $categories = $this->_getReadAdapter()->fetchAll($select); - foreach ($categories as $category) { - $productId = $category['product_id']; - $categoryIds = $products[$productId]->getCategoryIds(); - $categoryIds[] = $category['category_id']; - $products[$productId]->setCategoryIds($categoryIds); - } - - foreach (array('name', 'url_key', 'url_path') as $attributeCode) { - $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId); - foreach ($attributes as $productId => $attributeValue) { - $products[$productId]->setData($attributeCode, $attributeValue); - } - } - } - - return $products; - } - - /** - * Retrieve Product data object - * - * @param int $productId - * @param int $storeId - * @return Varien_Object - */ - public function getProduct($productId, $storeId) - { - $lastId = 0; - $products = $this->_getProducts($productId, $storeId, 0, $lastId); - if (isset($products[$productId])) { - return $products[$productId]; - } - return false; - } - - /** - * Retrieve Product data obects for store - * - * @param int $storeId - * @param int $lastEntityId - * @return array - */ - public function getProductsByStore($storeId, &$lastEntityId) - { - return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId); - } - - /** - * Retrieve Product data objects in category - * - * @param Varien_Object $category - * @param int $lastEntityId - * @return array - */ - public function getProductsByCategory(Varien_Object $category, &$lastEntityId) - { - $productIds = $this->getProductIdsByCategory($category); - if (!$productIds) { - return array(); - } - return $this->_getProducts($productIds, $category->getStoreId(), $lastEntityId, $lastEntityId); - } - - /** - * Find and remove unused products rewrites - a case when products were moved away from the category - * (either to other category or deleted), so rewrite "category_id-product_id" is invalid - * - * @param int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function clearCategoryProduct($storeId) - { - $select = $this->_getWriteAdapter()->select() - ->from(array('tur' => $this->getMainTable()), $this->getIdFieldName()) - ->joinLeft( - array('tcp' => $this->getTable('catalog/category_product')), - 'tur.category_id=tcp.category_id AND tur.product_id=tcp.product_id', - array() - )->where('tur.store_id=?', $storeId) - ->where('tur.category_id IS NOT NULL') - ->where('tur.product_id IS NOT NULL') - ->where('tcp.category_id IS NULL'); - $rowSet = $this->_getWriteAdapter()->fetchAll($select); - $rewriteIds = array(); - foreach ($rowSet as $row) { - $rewriteIds[] = $row[$this->getIdFieldName()]; - } - if ($rewriteIds) { - $where = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $rewriteIds); - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - } - - return $this; - } - - /** - * Remove unused rewrites for product - called after we created all needed rewrites for product and know the categories - * where the product is contained ($excludeCategoryIds), so we can remove all invalid product rewrites that have other category ids - * - * Notice: this routine is not identical to clearCategoryProduct(), because after checking all categories this one removes rewrites - * for product still contained within categories. - * - * @param int $productId Product entity Id - * @param int $storeId Store Id for rewrites - * @param array $excludeCategoryIds Array of category Ids that should be skipped - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function clearProductRewrites($productId, $storeId, $excludeCategoryIds = array()) - { - $adapter = $this->_getWriteAdapter(); - - $where = $adapter->quoteInto('product_id=?', $productId); - $where.= $adapter->quoteInto(' AND store_id=?', $storeId); - - if (!empty($excludeCategoryIds)) { - $where.= $adapter->quoteInto(' AND category_id NOT IN (?)', $excludeCategoryIds); - $where.= ' AND category_id IS NOT NULL'; // If there's at least one category to skip, also skip root category, because product belongs to website - } - - $adapter->delete($this->getMainTable(), $where); - - return $this; - } - - /** - * Finds and deletes all old category and category/product rewrites for store - * left from the times when categories/products belonged to store - * - * @param int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function clearStoreCategoriesInvalidRewrites($storeId) - { - // Form a list of all current store categories ids - $store = $this->getStores($storeId); - $rootCategoryId = $store->getRootCategoryId(); - if (!$rootCategoryId) { - return $this; - } - $categoryIds = $this->getRootChildrenIds($rootCategoryId, $store->getRootCategoryPath()); - - // Remove all store catalog rewrites that are for some category or cartegory/product not within store categories - $adapter = $this->_getWriteAdapter(); - $condition = $adapter->quoteInto('store_id = ?', $storeId); - $condition .= ' AND category_id IS NOT NULL'; // For sure check that it's a catalog rewrite - $condition .= $adapter->quoteInto(' AND category_id NOT IN (?)', $categoryIds); - $adapter->delete($this->getMainTable(), $condition); - - return $this; - } - - /** - * Finds and deletes product rewrites (that are not assigned to any category) for store - * left from the times when product was assigned to this store's website and now is not assigned - * - * Notice: this routine is different from clearProductRewrites() and clearCategoryProduct() because - * it handles direct rewrites to product without defined category (category_id IS NULL) whilst that routines - * handle only product rewrites within categories - * - * @param int $storeId - * @param int|array|null $productId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function clearStoreProductsInvalidRewrites($storeId, $productId = null) - { - $store = $this->getStores($storeId); - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('rewrite' => $this->getMainTable()), $this->getIdFieldName()) - ->joinLeft( - array('website' => $this->getTable('catalog/product_website')), - 'rewrite.product_id=website.product_id AND ' . $read->quoteInto('website.website_id = ?', $store->getWebsiteId()), - array() - )->where('rewrite.store_id=?', $storeId) - ->where('rewrite.category_id IS NULL'); - if ($productId) { - $select->where('rewrite.product_id IN (?)', $productId); - } else { - $select->where('rewrite.product_id IS NOT NULL'); - } - $select->where('website.website_id IS NULL'); - - $rowSet = $read->fetchAll($select); - $rewriteIds = array(); - foreach ($rowSet as $row) { - $rewriteIds[] = $row[$this->getIdFieldName()]; - } - if ($rewriteIds) { - $write =$this->_getWriteAdapter(); - $where = $write->quoteInto($this->getIdFieldName() . ' IN(?)', $rewriteIds); - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - } - - return $this; - } - - /** - * Finds and deletes old rewrites for store - * a) category rewrites left from the times when store had some other root category - * b) product rewrites left from products that once belonged to this site, but then deleted or just removed from website - * - * @param int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function clearStoreInvalidRewrites($storeId) - { - $this->clearStoreCategoriesInvalidRewrites($storeId); - $this->clearStoreProductsInvalidRewrites($storeId); - return $this; - } - - /** - * Delete rewrites for associated to category products - * - * @param int $categoryId - * @param array $productIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function deleteCategoryProductRewrites($categoryId, $productIds) - { - $this->deleteCatagoryProductStoreRewrites($categoryId, $productIds); - return $this; - } - - /** - * Delete URL rewrites for category products of specific store - * - * @param int $categoryId - * @param array|int|null $productIds - * @param null|int $storeId - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url - */ - public function deleteCategoryProductStoreRewrites($categoryId, $productIds=null, $storeId=null) - { - $adapter = $this->_getWriteAdapter(); - - // Notice that we don't include category_id = NULL in case of root category, - // because product removed from all categories but assigned to store's website is still - // assumed to be in root cat. Unassigned products must be removed by other routine. - $condition = $adapter->quoteInto('category_id=?', $categoryId); - if (empty($productIds)) { - $condition.= ' AND product_id IS NOT NULL'; - } else { - $condition.= $adapter->quoteInto(' AND product_id IN (?)', $productIds); - } - - if ($storeId !== null) { - $condition.= $adapter->quoteInto(' AND store_id IN(?)', $storeId); - } - - $adapter->delete($this->getMainTable(), $condition); - return $this; - } - - /** - * Retrieve rewrites and visibility by store - * - * Input array format: - * product_id as key and store_id as value - * - * Output array format (product_id as key) - * store_id int; store id - * visibility int; visibility for store - * url_rewrite string; rewrite URL for store - * - * @param array $products - * @return array - */ - public function getRewriteByProductStore(array $products) - { - $result = array(); - - if (empty($products)) { - return $result; - } - - $select = $this->_getReadAdapter()->select() - ->from( - array('i' => $this->getTable('catalog/category_product_index')), - array('product_id', 'store_id', 'visibility')) - ->joinLeft( - array('r' => $this->getMainTable()), - 'i.product_id = r.product_id AND i.store_id=r.store_id AND r.category_id IS NULL', - array('request_path') - ); - foreach ($products as $productId => $storeId) { - $catId = Mage::app()->getStore($storeId)->getRootCategoryId(); - $cond = join(' AND ', array( - $this->_getReadAdapter()->quoteInto('i.product_id=?', $productId), - $this->_getReadAdapter()->quoteInto('i.store_id=?', $storeId), - $this->_getReadAdapter()->quoteInto('i.category_id=?', $catId), - )); - - $select->orWhere($cond); - } - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $result[$row['product_id']] = array( - 'store_id' => $row['store_id'], - 'visibility' => $row['visibility'], - 'url_rewrite' => $row['request_path'], - ); - } - - return $result; - } - - /** - * Find and return final id path by request path - * Needed for permanent redirect old URLs. - * - * @param string $requestPath - * @param int $storeId - * @param array $_checkedPaths internal varible to prevent infinite loops. - * @return string | bool - */ - public function findFinalTargetPath($requestPath, $storeId, &$_checkedPaths = array()) - { - if (in_array($requestPath, $_checkedPaths)) { - return false; - } - - $_checkedPaths[] = $requestPath; - - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), array('target_path', 'id_path')) - ->where('store_id = ?', $storeId) - ->where('request_path = ?', $requestPath); - - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $idPath = $this->findFinalTargetPath($row['target_path'], $storeId, $_checkedPaths); - if (!$idPath) { - return $row['id_path']; - } else { - return $idPath; - } - } - - return false; - } - - /** - * Delete rewrite path record from the database. - * - * @param string $requestPath - * @param int $storeId - */ - public function deleteRewrite($requestPath, $storeId) - { - $db = $this->_getWriteAdapter(); - $db->delete( - $this->getMainTable(), - "store_id = {$db->quote($storeId)} AND request_path = {$db->quote($requestPath)}" - ); - } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Catalog/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..76d1ea88fe --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,106 @@ + + */ +class Mage_Catalog_Model_Resource_Helper_Mysql4 extends Mage_Eav_Model_Resource_Helper_Mysql4 +{ + + /** + * Returns columns for select + * + * @param string $tableAlias + * @param string $eavType + * @return array + */ + public function attributeSelectFields($tableAlias, $eavType) + { + return '*'; + } + + /** + * Compare Flat style with Describe style columns + * If column a different - return false + * + * @param array $column + * @param array $describe + * @return bool + */ + public function compareIndexColumnProperties($column, $describe) + { + $type = $column['type']; + if (isset($column['length'])) { + $type = sprintf('%s(%s)', $type[0], $column['length']); + } else { + $type = $type[0]; + } + $length = null; + $precision = null; + $scale = null; + + $matches = array(); + if (preg_match('/^((?:var)?char)\((\d+)\)/', $type, $matches)) { + $type = $matches[1]; + $length = $matches[2]; + } else if (preg_match('/^decimal\((\d+),(\d+)\)/', $type, $matches)) { + $type = 'decimal'; + $precision = $matches[1]; + $scale = $matches[2]; + } else if (preg_match('/^float\((\d+),(\d+)\)/', $type, $matches)) { + $type = 'float'; + $precision = $matches[1]; + $scale = $matches[2]; + } else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)?/', $type, $matches)) { + $type = $matches[1]; + } + + return ($describe['DATA_TYPE'] == $type) + && ($describe['DEFAULT'] == $column['default']) + && ((bool)$describe['NULLABLE'] == (bool)$column['nullable']) + && ((bool)$describe['UNSIGNED'] == (bool)$column['unsigned']) + && ($describe['LENGTH'] == $length) + && ($describe['SCALE'] == $scale) + && ($describe['PRECISION'] == $precision); + } + + /** + * Getting condition isNull(f1,f2) IS NOT Null + * + * @param string $field1 + * @param string $field2 + * @return string + */ + public function getIsNullNotNullCondition($field1, $field2) + { + return sprintf('%s IS NOT NULL', $this->_getReadAdapter()->getIfNullSql($field1, $field2)); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php new file mode 100755 index 0000000000..3043ffab85 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php @@ -0,0 +1,109 @@ + + */ +class Mage_Catalog_Model_Resource_Layer_Filter_Attribute extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table name + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_eav', 'entity_id'); + } + + /** + * Apply attribute filter to product collection + * + * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter + * @param int $value + * @return Mage_Catalog_Model_Resource_Layer_Filter_Attribute + */ + public function applyFilterToCollection($filter, $value) + { + $collection = $filter->getLayer()->getProductCollection(); + $attribute = $filter->getAttributeModel(); + $connection = $this->_getReadAdapter(); + $tableAlias = $attribute->getAttributeCode() . '_idx'; + $conditions = array( + "{$tableAlias}.entity_id = e.entity_id", + $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), + $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), + $connection->quoteInto("{$tableAlias}.value = ?", $value) + ); + + $collection->getSelect()->join( + array($tableAlias => $this->getMainTable()), + implode(' AND ', $conditions), + array() + ); + + return $this; + } + + /** + * Retrieve array with products counts per attribute option + * + * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter + * @return array + */ + public function getCount($filter) + { + // clone select from collection with filters + $select = clone $filter->getLayer()->getProductCollection()->getSelect(); + // reset columns, order and limitation conditions + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + $connection = $this->_getReadAdapter(); + $attribute = $filter->getAttributeModel(); + $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode()); + $conditions = array( + "{$tableAlias}.entity_id = e.entity_id", + $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), + $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()), + ); + + $select + ->join( + array($tableAlias => $this->getMainTable()), + join(' AND ', $conditions), + array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)"))) + ->group("{$tableAlias}.value"); + + return $connection->fetchPairs($select); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Decimal.php b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Decimal.php new file mode 100755 index 0000000000..8328c93612 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Decimal.php @@ -0,0 +1,156 @@ + + */ +class Mage_Catalog_Model_Resource_Layer_Filter_Decimal extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table name + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_eav_decimal', 'entity_id'); + } + + /** + * Apply attribute filter to product collection + * + * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter + * @param float $range + * @param int $index + * @return Mage_Catalog_Model_Resource_Layer_Filter_Decimal + */ + public function applyFilterToCollection($filter, $range, $index) + { + $collection = $filter->getLayer()->getProductCollection(); + $attribute = $filter->getAttributeModel(); + $connection = $this->_getReadAdapter(); + $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode()); + $conditions = array( + "{$tableAlias}.entity_id = e.entity_id", + $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), + $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()) + ); + + $collection->getSelect()->join( + array($tableAlias => $this->getMainTable()), + implode(' AND ', $conditions), + array() + ); + + $collection->getSelect() + ->where("{$tableAlias}.value >= ?", ($range * ($index - 1))) + ->where("{$tableAlias}.value < ?", ($range * $index)); + + return $this; + } + + /** + * Retrieve array of minimal and maximal values + * + * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter + * @return array + */ + public function getMinMax($filter) + { + $select = $this->_getSelect($filter); + $adapter = $this->_getReadAdapter(); + + $select->columns(array( + 'min_value' => new Zend_Db_Expr('MIN(decimal_index.value)'), + 'max_value' => new Zend_Db_Expr('MAX(decimal_index.value)'), + )); + + $result = $adapter->fetchRow($select); + + return array($result['min_value'], $result['max_value']); + } + + /** + * Retrieve clean select with joined index table + * Joined table has index + * + * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter + * @return Varien_Db_Select + */ + protected function _getSelect($filter) + { + $collection = $filter->getLayer()->getProductCollection(); + + // clone select from collection with filters + $select = clone $collection->getSelect(); + // reset columns, order and limitation conditions + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + $attributeId = $filter->getAttributeModel()->getId(); + $storeId = $collection->getStoreId(); + + $select->join( + array('decimal_index' => $this->getMainTable()), + 'e.entity_id = decimal_index.entity_id'. + ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . + ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), + array() + ); + + return $select; + } + + /** + * Retrieve array with products counts per range + * + * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter + * @param int $range + * @return array + */ + public function getCount($filter, $range) + { + $select = $this->_getSelect($filter); + $adapter = $this->_getReadAdapter(); + + $countExpr = new Zend_Db_Expr("COUNT(*)"); + $rangeExpr = new Zend_Db_Expr("FLOOR(decimal_index.value / {$range}) + 1"); + + $select->columns(array( + 'decimal_range' => $rangeExpr, + 'count' => $countExpr + )); + $select->group($rangeExpr); + + return $adapter->fetchPairs($select); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Price.php new file mode 100755 index 0000000000..3842effaec --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Price.php @@ -0,0 +1,199 @@ + + */ +class Mage_Catalog_Model_Resource_Layer_Filter_Price extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table name + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_price', 'entity_id'); + } + + /** + * Retrieve joined price index table alias + * + * @return string + */ + protected function _getIndexTableAlias() + { + return 'price_index'; + } + + /** + * Retrieve clean select with joined price index table + * + * @param Mage_Catalog_Model_Layer_Filter_Price $filter + * @return Varien_Db_Select + */ + protected function _getSelect($filter) + { + $collection = $filter->getLayer()->getProductCollection(); + $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); + + // clone select from collection with filters + $select = clone $collection->getSelect(); + // reset columns, order and limitation conditions + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + return $select; + } + + /** + * Prepare response object and dispatch prepare price event + * Return response object + * + * @param Mage_Catalog_Model_Layer_Filter_Price $filter + * @param Varien_Db_Select $select + * @return Varien_Object + */ + protected function _dispatchPreparePriceEvent($filter, $select) + { + // prepare response object for event + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + // prepare event arguments + $eventArgs = array( + 'select' => $select, + 'table' => $this->_getIndexTableAlias(), + 'store_id' => $filter->getStoreId(), + 'response_object' => $response + ); + + /** + * @deprecated since 1.3.2.2 + */ + Mage::dispatchEvent('catalogindex_prepare_price_select', $eventArgs); + + /** + * @since 1.4 + */ + Mage::dispatchEvent('catalog_prepare_price_select', $eventArgs); + + return $response; + } + + /** + * Retrieve maximal price for attribute + * + * @param Mage_Catalog_Model_Layer_Filter_Price $filter + * @return float + */ + public function getMaxPrice($filter) + { + $select = $this->_getSelect($filter); + $connection = $this->_getReadAdapter(); + $response = $this->_dispatchPreparePriceEvent($filter, $select); + + $table = $this->_getIndexTableAlias(); + + $additional = join('', $response->getAdditionalCalculations()); + $maxPriceExpr = new Zend_Db_Expr("MAX({$table}.min_price {$additional})"); + + $select->columns(array($maxPriceExpr)); + + return $connection->fetchOne($select) * $filter->getCurrencyRate(); + } + + /** + * Retrieve array with products counts per price range + * + * @param Mage_Catalog_Model_Layer_Filter_Price $filter + * @param int $range + * @return array + */ + public function getCount($filter, $range) + { + $select = $this->_getSelect($filter); + $connection = $this->_getReadAdapter(); + $response = $this->_dispatchPreparePriceEvent($filter, $select); + $table = $this->_getIndexTableAlias(); + + $additional = join('', $response->getAdditionalCalculations()); + $rate = $filter->getCurrencyRate(); + + /** + * Check and set correct variable values to prevent SQL-injections + */ + $rate = floatval($rate); + $range = floatval($range); + if ($range == 0) { + $range = 1; + } + $countExpr = new Zend_Db_Expr('COUNT(*)'); + $rangeExpr = new Zend_Db_Expr("FLOOR((({$table}.min_price {$additional}) * {$rate}) / {$range}) + 1"); + + $select->columns(array( + 'range' => $rangeExpr, + 'count' => $countExpr + )); + $select->group($rangeExpr); + + return $connection->fetchPairs($select); + } + + /** + * Apply attribute filter to product collection + * + * @param Mage_Catalog_Model_Layer_Filter_Price $filter + * @param int $range + * @param int $index the range factor + * @return Mage_Catalog_Model_Resource_Layer_Filter_Price + */ + public function applyFilterToCollection($filter, $range, $index) + { + $collection = $filter->getLayer()->getProductCollection(); + $collection->addPriceData($filter->getCustomerGroupId(), $filter->getWebsiteId()); + + $select = $collection->getSelect(); + $response = $this->_dispatchPreparePriceEvent($filter, $select); + + $table = $this->_getIndexTableAlias(); + $additional = join('', $response->getAdditionalCalculations()); + $rate = $filter->getCurrencyRate(); + $priceExpr = new Zend_Db_Expr("(({$table}.min_price {$additional}) * {$rate})"); + + $select + ->where($priceExpr . ' >= ?', ($range * ($index - 1))) + ->where($priceExpr . ' < ?', ($range * $index)); + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product.php b/app/code/core/Mage/Catalog/Model/Resource/Product.php new file mode 100755 index 0000000000..ed6fa50309 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product.php @@ -0,0 +1,637 @@ + + */ +class Mage_Catalog_Model_Resource_Product extends Mage_Catalog_Model_Resource_Abstract +{ + /** + * Product to website linkage table + * + * @var string + */ + protected $_productWebsiteTable; + + /** + * Product to category linkage table + * + * @var string + */ + protected $_productCategoryTable; + + /** + * Initialize resource + */ + public function __construct() + { + parent::__construct(); + $this->setType(Mage_Catalog_Model_Product::ENTITY) + ->setConnection('catalog_read', 'catalog_write'); + $this->_productWebsiteTable = $this->getTable('catalog/product_website'); + $this->_productCategoryTable = $this->getTable('catalog/category_product'); + } + + /** + * Default product attributes + * + * @return array + */ + protected function _getDefaultAttributes() + { + return array('entity_id', 'entity_type_id', 'attribute_set_id', 'type_id', 'created_at', 'updated_at'); + } + + /** + * Retrieve product website identifiers + * + * @param Mage_Catalog_Model_Product|int $product + * @return array + */ + public function getWebsiteIds($product) + { + $adapter = $this->_getReadAdapter(); + + if ($product instanceof Mage_Catalog_Model_Product) { + $productId = $product->getId(); + } else { + $productId = $product; + } + + $select = $adapter->select() + ->from($this->_productWebsiteTable, 'website_id') + ->where('product_id = ?', (int)$productId); + + return $adapter->fetchCol($select); + } + + /** + * Retrieve product website identifiers by product identifiers + * + * @param array $productIds + * @return array + */ + public function getWebsiteIdsByProductIds($productIds) + { + $select = $this->_getWriteAdapter()->select() + ->from($this->_productWebsiteTable, array('product_id', 'website_ids' =>'GROUP_CONCAT(website_id)')) + ->where('product_id IN (?)', $productIds) + ->group('product_id'); + + return $this->_getWriteAdapter()->fetchAll($select); + } + + /** + * Retrieve product category identifiers + * + * @param Mage_Catalog_Model_Product $product + * @return array + */ + public function getCategoryIds($product) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->_productCategoryTable, 'category_id') + ->where('product_id = ?', (int)$product->getId()); + + return $adapter->fetchCol($select); + } + + /** + * Get product identifier by sku + * + * @param string $sku + * @return int|false + */ + public function getIdBySku($sku) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getEntityTable(), 'entity_id') + ->where('sku = :sku'); + + $bind = array(':sku' => (string)$sku); + + return $adapter->fetchOne($select, $bind); + } + + /** + * Process product data before save + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Product + */ + protected function _beforeSave(Varien_Object $object) + { + /** + * Try detect product id by sku if id is not declared + */ + if (!$object->getId() && $object->getSku()) { + $object->setId($this->getIdBySku($object->getSku())); + } + + /** + * Check if declared category ids in object data. + */ + if ($object->hasCategoryIds()) { + $categoryIds = Mage::getResourceSingleton('catalog/category')->verifyIds( + $object->getCategoryIds() + ); + $object->setCategoryIds($categoryIds); + } + + return parent::_beforeSave($object); + } + + /** + * Save data related with product + * + * @param Varien_Object $product + * @return Mage_Catalog_Model_Resource_Product + */ + protected function _afterSave(Varien_Object $product) + { + $this->_saveWebsiteIds($product) + ->_saveCategories($product); + + return parent::_afterSave($product); + } + + /** + * Save product website relations + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product + */ + protected function _saveWebsiteIds($product) + { + $websiteIds = $product->getWebsiteIds(); + $oldWebsiteIds = array(); + + $product->setIsChangedWebsites(false); + + $adapter = $this->_getWriteAdapter(); + + $oldWebsiteIds = $this->getWebsiteIds($product); + + $insert = array_diff($websiteIds, $oldWebsiteIds); + $delete = array_diff($oldWebsiteIds, $websiteIds); + + if (!empty($insert)) { + $data = array(); + foreach ($insert as $websiteId) { + $data[] = array( + 'product_id' => (int)$product->getId(), + 'website_id' => (int)$websiteId + ); + } + $adapter->insertMultiple($this->_productWebsiteTable, $data); + } + + if (!empty($delete)) { + foreach ($delete as $websiteId) { + $condition = array( + 'product_id = ?' => (int)$product->getId(), + 'website_id = ?' => (int)$websiteId, + ); + + $adapter->delete($this->_productWebsiteTable, $condition); + } + } + + if (!empty($insert) || !empty($delete)) { + $product->setIsChangedWebsites(true); + } + + return $this; + } + + /** + * Save product category relations + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Product + */ + protected function _saveCategories(Varien_Object $object) + { + /** + * If category ids data is not declared we haven't do manipulations + */ + if (!$object->hasCategoryIds()) { + return $this; + } + $categoryIds = $object->getCategoryIds(); + $oldCategoryIds = $this->getCategoryIds($object); + + $object->setIsChangedCategories(false); + + $insert = array_diff($categoryIds, $oldCategoryIds); + $delete = array_diff($oldCategoryIds, $categoryIds); + + $write = $this->_getWriteAdapter(); + if (!empty($insert)) { + $data = array(); + foreach ($insert as $categoryId) { + if (empty($categoryId)) { + continue; + } + $data[] = array( + 'category_id' => (int)$categoryId, + 'product_id' => (int)$object->getId(), + 'position' => 1 + ); + } + if ($data) { + $write->insertMultiple($this->_productCategoryTable, $data); + } + } + + if (!empty($delete)) { + foreach ($delete as $categoryId) { + $where = array( + 'product_id = ?' => (int)$object->getId(), + 'category_id = ?' => (int)$categoryId, + ); + + $write->delete($this->_productCategoryTable, $where); + } + } + + if (!empty($insert) || !empty($delete)) { + $object->setAffectedCategoryIds(array_merge($insert, $delete)); + $object->setIsChangedCategories(true); + } + + return $this; + } + + /** + * Refresh Product Enabled Index + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product + */ + public function refreshIndex($product) + { + $writeAdapter = $this->_getWriteAdapter(); + + /** + * Ids of all categories where product is assigned (not related with store) + */ + $categoryIds = $product->getCategoryIds(); + + /** + * Clear previous index data related with product + */ + $condition = array('product_id = ?' => (int)$product->getId()); + $writeAdapter->delete($this->getTable('catalog/category_product_index'), $condition); + + /** @var $categoryObject Mage_Catalog_Model_Resource_Category */ + $categoryObject = Mage::getResourceSingleton('catalog/category'); + if (!empty($categoryIds)) { + $categoriesSelect = $writeAdapter->select() + ->from($this->getTable('catalog/category')) + ->where('entity_id IN (?)', $categoryIds); + + $categoriesInfo = $writeAdapter->fetchAll($categoriesSelect); + + $indexCategoryIds = array(); + foreach ($categoriesInfo as $categoryInfo) { + $ids = explode('/', $categoryInfo['path']); + $ids[] = $categoryInfo['entity_id']; + $indexCategoryIds = array_merge($indexCategoryIds, $ids); + } + + $indexCategoryIds = array_unique($indexCategoryIds); + $indexProductIds = array($product->getId()); + + $categoryObject->refreshProductIndex($indexCategoryIds, $indexProductIds); + } else { + $websites = $product->getWebsiteIds(); + + if ($websites) { + $storeIds = array(); + + foreach ($websites as $websiteId) { + $website = Mage::app()->getWebsite($websiteId); + $storeIds = array_merge($storeIds, $website->getStoreIds()); + } + + $categoryObject->refreshProductIndex(array(), array($product->getId()), $storeIds); + } + } + + /** + * Refresh enabled products index (visibility state) + */ + $this->refreshEnabledIndex(null, $product); + + return $this; + } + + /** + * Refresh index for visibility of enabled product in store + * if store parameter is null - index will refreshed for all stores + * if product parameter is null - idex will be refreshed for all products + * + * @param Mage_Core_Model_Store $store + * @param Mage_Catalog_Model_Product $product + * @throws Mage_Core_Exception + * @return Mage_Catalog_Model_Resource_Product + */ + public function refreshEnabledIndex($store = null, $product = null) + { + $statusAttribute = $this->getAttribute('status'); + $visibilityAttribute = $this->getAttribute('visibility'); + $statusAttributeId = $statusAttribute->getId(); + $visibilityAttributeId = $visibilityAttribute->getId(); + $statusTable = $statusAttribute->getBackend()->getTable(); + $visibilityTable = $visibilityAttribute->getBackend()->getTable(); + + $adapter = $this->_getWriteAdapter(); + + $select = $adapter->select(); + $condition = array(); + + $indexTable = $this->getTable('catalog/product_enabled_index'); + if (is_null($store) && is_null($product)) { + Mage::throwException( + Mage::helper('catalog')->__('To reindex the enabled product(s), the store or product must be specified') + ); + } elseif (is_null($product) || is_array($product)) { + $storeId = $store->getId(); + $websiteId = $store->getWebsiteId(); + + if (is_array($product) && !empty($product)) { + $condition[] = $adapter->quoteInto('product_id IN (?)', $product); + } + + $condition[] = $adapter->quoteInto('store_id = ?', $storeId); + + $selectFields = array( + 't_v_default.entity_id', + new Zend_Db_Expr($storeId), + $adapter->getCheckSql('t_v.value_id > 0', 't_v.value', 't_v_default.value'), + ); + + $select->joinInner( + array('w' => $this->getTable('catalog/product_website')), + $adapter->quoteInto( + 'w.product_id = t_v_default.entity_id AND w.website_id = ?', $websiteId + ), + array() + ); + } elseif ($store === null) { + foreach ($product->getStoreIds() as $storeId) { + $store = Mage::app()->getStore($storeId); + $this->refreshEnabledIndex($store, $product); + } + return $this; + } else { + $productId = is_numeric($product) ? $product : $product->getId(); + $storeId = is_numeric($store) ? $store : $store->getId(); + + $condition = array( + 'product_id = ?' => (int)$productId, + 'store_id = ?' => (int)$storeId, + ); + + $selectFields = array( + new Zend_Db_Expr($productId), + new Zend_Db_Expr($storeId), + $adapter->getCheckSql('t_v.value_id > 0', 't_v.value', 't_v_default.value') + ); + + $select->where('t_v_default.entity_id = ?', $productId); + } + + $adapter->delete($indexTable, $condition); + + $select->from(array('t_v_default' => $visibilityTable), $selectFields); + + $visibilityTableJoinCond = array( + 't_v.entity_id = t_v_default.entity_id', + $adapter->quoteInto('t_v.attribute_id = ?', $visibilityAttributeId), + $adapter->quoteInto('t_v.store_id = ?', $storeId), + ); + + $select->joinLeft( + array('t_v' => $visibilityTable), + implode(' AND ', $visibilityTableJoinCond), + array() + ); + + $defaultStatusJoinCond = array( + 't_s_default.entity_id = t_v_default.entity_id', + 't_s_default.store_id = 0', + $adapter->quoteInto('t_s_default.attribute_id = ?', $statusAttributeId), + ); + + $select->joinInner( + array('t_s_default' => $statusTable), + implode(' AND ', $defaultStatusJoinCond), + array() + ); + + + $statusJoinCond = array( + 't_s.entity_id = t_v_default.entity_id', + $adapter->quoteInto('t_s.store_id = ?', $storeId), + $adapter->quoteInto('t_s.attribute_id = ?', $statusAttributeId), + ); + + $select->joinLeft( + array('t_s' => $statusTable), + implode(' AND ', $statusJoinCond), + array() + ); + + $valueCondition = $adapter->getCheckSql('t_s.value_id > 0', 't_s.value', 't_s_default.value'); + + $select->where('t_v_default.attribute_id = ?', $visibilityAttributeId) + ->where('t_v_default.store_id = ?', 0) + ->where(sprintf('%s = ?', $valueCondition), Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + + if (is_array($product) && !empty($product)) { + $select->where('t_v_default.entity_id IN (?)', $product); + } + + $adapter->query($adapter->insertFromSelect($select, $indexTable)); + + + return $this; + } + + /** + * Get collection of product categories + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Category_Collection + */ + public function getCategoryCollection($product) + { + $collection = Mage::getResourceModel('catalog/category_collection') + ->joinField('product_id', + 'catalog/category_product', + 'product_id', + 'category_id = entity_id', + null) + ->addFieldToFilter('product_id', (int)$product->getId()); + return $collection; + } + + /** + * Retrieve category ids where product is available + * + * @param Mage_Catalog_Model_Product $object + * @return array + */ + public function getAvailableInCategories($object) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('catalog/category_product_index'), array('category_id')) + ->where('product_id = ?', (int)$object->getEntityId()); + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Get default attribute source model + * + * @return string + */ + public function getDefaultAttributeSourceModel() + { + return 'eav/entity_attribute_source_table'; + } + + /** + * Check availability display product in category + * + * @param Mage_Catalog_Model_Product $product + * @param int $categoryId + * @return string + */ + public function canBeShowInCategory($product, $categoryId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('catalog/category_product_index'), 'product_id') + ->where('product_id = ?', (int)$categoryId) + ->where('category_id = ?', (int)$product->getId()); + + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Duplicate product store values + * + * @param int $oldId + * @param int $newId + * @return Mage_Catalog_Model_Resource_Product + */ + public function duplicate($oldId, $newId) + { + $adapter = $this->_getWriteAdapter(); + $eavTables = array('datetime', 'decimal', 'int', 'text', 'varchar'); + + $adapter = $this->_getWriteAdapter(); + + // duplicate EAV store values + foreach ($eavTables as $suffix) { + $tableName = $this->getTable(array('catalog/product', $suffix)); + + $select = $adapter->select() + ->from($tableName, array( + 'entity_type_id', + 'attribute_id', + 'store_id', + 'entity_id' => new Zend_Db_Expr($adapter->quote($newId)), + 'value' + )) + ->where('entity_id = ?', $oldId) + ->where('store_id > ?', 0); + + $adapter->query($adapter->insertFromSelect( + $select, + $tableName, + array( + 'entity_type_id', + 'attribute_id', + 'store_id', + 'entity_id', + 'value' + ), + Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE + )); + } + + // set status as disabled + $statusAttribute = $this->getAttribute('status'); + $statusAttributeId = $statusAttribute->getAttributeId(); + $statusAttributeTable = $statusAttribute->getBackend()->getTable(); + $updateCond[] = 'store_id > 0'; + $updateCond[] = $adapter->quoteInto('entity_id = ?', $newId); + $updateCond[] = $adapter->quoteInto('attribute_id = ?', $statusAttributeId); + $adapter->update( + $statusAttributeTable, + array('value' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED), + $updateCond + ); + + return $this; + } + + /** + * Get SKU through product identifiers + * + * @param array $productIds + * @return array + */ + public function getProductsSku(array $productIds) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('catalog/product'), array('entity_id', 'sku')) + ->where('entity_id IN (?)', $productIds); + return $this->_getReadAdapter()->fetchAll($select); + } + + /** + * @deprecated after 1.4.2.0 + * @param $object Mage_Catalog_Model_Product + * @return array + */ + public function getParentProductIds($object) + { + return array(); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php new file mode 100755 index 0000000000..4e341996fe --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Action.php @@ -0,0 +1,94 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Action extends Mage_Catalog_Model_Resource_Abstract +{ + /** + * Intialize connection + * + */ + protected function _construct() + { + $resource = Mage::getSingleton('core/resource'); + $this->setType(Mage_Catalog_Model_Product::ENTITY) + ->setConnection( + $resource->getConnection('catalog_read'), + $resource->getConnection('catalog_write') + ); + } + + /** + * Update attribute values for entity list per store + * + * @param array $entityIds + * @param array $attrData + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Action + */ + public function updateAttributes($entityIds, $attrData, $storeId) + { + $object = new Varien_Object(); + $object->setIdFieldName('entity_id') + ->setStoreId($storeId); + + $this->_getWriteAdapter()->beginTransaction(); + try { + foreach ($attrData as $attrCode => $value) { + $attribute = $this->getAttribute($attrCode); + if (!$attribute->getAttributeId()) { + continue; + } + + $i = 0; + foreach ($entityIds as $entityId) { + $i++; + $object->setId($entityId); + // collect data for save + $this->_saveAttributeValue($object, $attribute, $value); + // save collected data every 1000 rows + if ($i % 1000 == 0) { + $this->_processAttributeValues(); + } + } + $this->_processAttributeValues(); + } + $this->_getWriteAdapter()->commit(); + } catch (Exception $e) { + $this->_getWriteAdapter()->rollBack(); + throw $e; + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Image.php new file mode 100755 index 0000000000..6ea707808c --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Image.php @@ -0,0 +1,73 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * After save + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image + */ + public function afterSave($object) + { + $value = $object->getData($this->getAttribute()->getName()); + + if (is_array($value) && !empty($value['delete'])) { + $object->setData($this->getAttribute()->getName(), ''); + $this->getAttribute()->getEntity() + ->saveAttribute($object, $this->getAttribute()->getName()); + return; + } + + try { + $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName()); + $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); + $uploader->setAllowRenameFiles(true); + $uploader->setFilesDispersion(true); + } catch (Exception $e){ + return $this; + } + $uploader->save(Mage::getBaseDir('media') . '/catalog/product'); + + $fileName = $uploader->getUploadedFileName(); + if ($fileName) { + $object->setData($this->getAttribute()->getName(), $fileName); + $this->getAttribute()->getEntity() + ->saveAttribute($object, $this->getAttribute()->getName()); + } + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Media.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Media.php new file mode 100755 index 0000000000..326d60844c --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Media.php @@ -0,0 +1,228 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media extends Mage_Core_Model_Resource_Db_Abstract +{ + const GALLERY_TABLE = 'catalog/product_attribute_media_gallery'; + const GALLERY_VALUE_TABLE = 'catalog/product_attribute_media_gallery_value'; + const GALLERY_IMAGE_TABLE = 'catalog/product_attribute_media_gallery_image'; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init(self::GALLERY_TABLE, 'value_id'); + } + + /** + * Load gallery images for product + * + * @param Mage_Catalog_Model_Product $product + * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object + * @return array + */ + public function loadGallery($product, $object) + { + $adapter = $this->_getReadAdapter(); + + $positionCheckSql = $adapter->getCheckSql('value.position IS NULL', 'default_value.position', 'value.position'); + + // Select gallery images for product + $select = $adapter->select() + ->from( + array('main'=>$this->getMainTable()), + array('value_id', 'value AS file') + ) + ->joinLeft( + array('value' => $this->getTable(self::GALLERY_VALUE_TABLE)), + $adapter->quoteInto('main.value_id = value.value_id AND value.store_id = ?', (int)$product->getStoreId()), + array('label','position','disabled') + ) + ->joinLeft( // Joining default values + array('default_value' => $this->getTable(self::GALLERY_VALUE_TABLE)), + 'main.value_id = default_value.value_id AND default_value.store_id = 0', + array( + 'label_default' => 'label', + 'position_default' => 'position', + 'disabled_default' => 'disabled' + ) + ) + ->where('main.attribute_id = ?', $object->getAttribute()->getId()) + ->where('main.entity_id = ?', $product->getId()) + ->order($positionCheckSql . ' ' . Varien_Db_Select::SQL_ASC); + + $result = $adapter->fetchAll($select); + $this->_removeDuplicates($result); + return $result; + } + + /** + * Remove duplicates + * + * @param array $result + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media + */ + protected function _removeDuplicates(&$result) + { + $fileToId = array(); + + foreach (array_keys($result) as $index) { + if (!isset($fileToId[$result[$index]['file']])) { + $fileToId[$result[$index]['file']] = $result[$index]['value_id']; + } elseif ($fileToId[$result[$index]['file']] != $result[$index]['value_id']) { + $this->deleteGallery($result[$index]['value_id']); + unset($result[$index]); + } + } + + $result = array_values($result); + return $this; + } + + /** + * Insert gallery value to db and retrive last id + * + * @param array $data + * @return interger + */ + public function insertGallery($data) + { + $adapter = $this->_getWriteAdapter(); + $data = $this->_prepareDataForTable(new Varien_Object($data), $this->getMainTable()); + $adapter->insert($this->getMainTable(), $data); + + return $adapter->lastInsertId($this->getMainTable()); + } + + /** + * Delete gallery value in db + * + * @param array|integer $valueId + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media + */ + public function deleteGallery($valueId) + { + if (is_array($valueId) && count($valueId)>0) { + $condition = $this->_getWriteAdapter()->quoteInto('value_id IN(?) ', $valueId); + } elseif (!is_array($valueId)) { + $condition = $this->_getWriteAdapter()->quoteInto('value_id = ? ', $valueId); + } else { + return $this; + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), $condition); + return $this; + } + + /** + * Insert gallery value for store to db + * + * @param array $data + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media + */ + public function insertGalleryValueInStore($data) + { + $data = $this->_prepareDataForTable(new Varien_Object($data), $this->getTable(self::GALLERY_VALUE_TABLE)); + $this->_getWriteAdapter()->insert($this->getTable(self::GALLERY_VALUE_TABLE), $data); + + return $this; + } + + /** + * Delete gallery value for store in db + * + * @param integer $valueId + * @param integer $storeId + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media + */ + public function deleteGalleryValueInStore($valueId, $storeId) + { + $adapter = $this->_getWriteAdapter(); + + $conditions = implode(' AND ', array( + $adapter->quoteInto('value_id = ?', (int) $valueId), + $adapter->quoteInto('store_id = ?', (int) $storeId), + )); + + $adapter->delete($this->getTable(self::GALLERY_VALUE_TABLE), $conditions); + + return $this; + } + + /** + * Duplicates gallery db values + * + * @param Mage_Catalog_Model_Product_Attribute_Backend_Media $object + * @param array $newFiles + * @param int $originalProductId + * @param int $newProductId + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media + */ + public function duplicate($object, $newFiles, $originalProductId, $newProductId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('value_id', 'value')) + ->where('attribute_id = ?', $object->getAttribute()->getId()) + ->where('entity_id = ?', $originalProductId); + + $valueIdMap = array(); + // Duplicate main entries of gallery + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $data = array( + 'attribute_id' => $object->getAttribute()->getId(), + 'entity_id' => $newProductId, + 'value' => (isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value']) + ); + + $valueIdMap[$row['value_id']] = $this->insertGallery($data); + } + + if (count($valueIdMap) == 0) { + return $this; + } + + // Duplicate per store gallery values + $select = $this->_getReadAdapter()->select() + ->from($this->getTable(self::GALLERY_VALUE_TABLE)) + ->where('value_id IN(?)', array_keys($valueIdMap)); + + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $row['value_id'] = $valueIdMap[$row['value_id']]; + $this->insertGalleryValueInStore($row); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Tierprice.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Tierprice.php new file mode 100755 index 0000000000..023668a3c5 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Tierprice.php @@ -0,0 +1,193 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('catalog/product_attribute_tier_price', 'value_id'); + } + + /** + * Load Tier Prices for product + * + * @param int $productId + * @param int $websiteId + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice + */ + public function loadPriceData($productId, $websiteId = null) + { + $adapter = $this->_getReadAdapter(); + + $columns = array( + 'price_id' => $this->getIdFieldName(), + 'website_id' => 'website_id', + 'all_groups' => 'all_groups', + 'cust_group' => 'customer_group_id', + 'price_qty' => 'qty', + 'price' => 'value', + ); + + $select = $adapter->select() + ->from($this->getMainTable(), $columns) + ->where('entity_id=?', $productId) + ->order('qty'); + + if (!is_null($websiteId)) { + if ($websiteId == '0') { + $select->where('website_id = ?', $websiteId); + } else { + $select->where('website_id IN(?)', array(0, $websiteId)); + } + } + + return $adapter->fetchAll($select); + } + + /** + * Delete Tier Prices for product + * + * @param int $productId + * @param int $websiteId + * @param int $priceId + * @return int The number of affected rows + */ + public function deletePriceData($productId, $websiteId = null, $priceId = null) + { + $adapter = $this->_getWriteAdapter(); + + $conds = array( + $adapter->quoteInto('entity_id = ?', $productId) + ); + + if (!is_null($websiteId)) { + $conds[] = $adapter->quoteInto('website_id = ?', $websiteId); + } + + if (!is_null($priceId)) { + $conds[] = $adapter->quoteInto($this->getIdFieldName() . ' = ?', $priceId); + } + + $where = implode(' AND ', $conds); + + return $adapter->delete($this->getMainTable(), $where); + } + + /** + * Save tier price object + * + * @param Varien_Object $priceObject + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice + */ + public function savePriceData(Varien_Object $priceObject) + { + $adapter = $this->_getWriteAdapter(); + $data = $this->_prepareDataForTable($priceObject, $this->getMainTable()); + + if (!empty($data[$this->getIdFieldName()])) { + $where = $adapter->quoteInto($this->getIdFieldName() . ' = ?', $data[$this->getIdFieldName()]); + unset($data[$this->getIdFieldName()]); + $adapter->update($this->getMainTable(), $data, $where); + } else { + $adapter->insert($this->getMainTable(), $data); + } + return $this; + } + + /** + * Load product tier prices + * + * @deprecated since 1.3.2.3 + * + * @param Mage_Catalog_Model_Product $product + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @return array + */ + public function loadProductPrices($product, $attribute) + { + $websiteId = null; + if ($attribute->isScopeGlobal()) { + $websiteId = 0; + } else if ($product->getStoreId()) { + $websiteId = Mage::app()->getStore($product->getStoreId())->getWebsiteId(); + } + + return $this->loadPriceData($product->getId(), $websiteId); + } + + /** + * Delete product tier price data from storage + * + * @deprecated since 1.3.2.3 + * + * @param Mage_Catalog_Model_Product $product + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice + */ + public function deleteProductPrices($product, $attribute) + { + $websiteId = null; + if (!$attribute->isScopeGlobal()) { + $storeId = $product->getProductId(); + if ($storeId) { + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); + } + } + + $this->deletePriceData($product->getId(), $websiteId); + + return $this; + } + + /** + * Insert product Tier Price to storage + * + * @deprecated since 1.3.2.3 + * + * @param Mage_Catalog_Model_Product $product + * @param array $data + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice + */ + public function insertProductPrice($product, $data) + { + $priceObject = new Varien_Object($data); + $priceObject->setEntityId($product->getId()); + + return $this->savePriceData($priceObject); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Urlkey.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Urlkey.php new file mode 100755 index 0000000000..a5183d0c8c --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Urlkey.php @@ -0,0 +1,71 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Before save + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey + */ + public function beforeSave($object) + { + $attributeName = $this->getAttribute()->getName(); + + $urlKey = $object->getData($attributeName); + if ($urlKey == '') { + $urlKey = $object->getName(); + } + + $object->setData($attributeName, $object->formatUrlKey($urlKey)); + + return $this; + } + + /** + * Refresh product rewrites + * + * @param Varien_Object $object + * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Urlkey + */ + public function afterSave($object) + { + if ($object->dataHasChangedFor($this->getAttribute()->getName())) { + Mage::getSingleton('catalog/url')->refreshProductRewrites(null, $object, true); + } + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php new file mode 100755 index 0000000000..cad040e4d2 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php @@ -0,0 +1,202 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Collection + extends Mage_Eav_Model_Resource_Entity_Attribute_Collection +{ + /** + * Resource model initialization + * + */ + protected function _construct() + { + $this->_init('catalog/resource_eav_attribute', 'eav/entity_attribute'); + } + + /** + * initialize select object + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + protected function _initSelect() + { + $entityTypeId = (int)Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId(); + $columns = $this->getConnection()->describeTable($this->getResource()->getMainTable()); + unset($columns['attribute_id']); + $retColumns = array(); + foreach ($columns as $labelColumn => $columnData) { + $retColumns[$labelColumn] = $labelColumn; + if ($columnData['DATA_TYPE'] == Varien_Db_Ddl_Table::TYPE_TEXT) { + $retColumns[$labelColumn] = Mage::getResourceHelper('core')->castField('main_table.'.$labelColumn); + } + } + $this->getSelect() + ->from(array('main_table' => $this->getResource()->getMainTable()), $retColumns) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'additional_table.attribute_id = main_table.attribute_id' + ) + ->where('main_table.entity_type_id = ?', $entityTypeId); + return $this; + } + + /** + * Specify attribute entity type filter + * + * @param int $typeId + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function setEntityTypeFilter($typeId) + { + return $this; + } + + /** + * Return array of fields to load attribute values + * + * @return array + */ + protected function _getLoadDataFields() + { + $fields = array_merge( + parent::_getLoadDataFields(), + array( + 'additional_table.is_global', + 'additional_table.is_html_allowed_on_front', + 'additional_table.is_wysiwyg_enabled' + ) + ); + + return $fields; + } + + /** + * Remove price from attribute list + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function removePriceFilter() + { + return $this->addFieldToFilter('main_table.attribute_code', array('neq' => 'price')); + } + + /** + * Specify "is_visible_in_advanced_search" filter + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addDisplayInAdvancedSearchFilter() + { + return $this->addFieldToFilter('additional_table.is_visible_in_advanced_search', 1); + } + + /** + * Specify "is_filterable" filter + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addIsFilterableFilter() + { + return $this->addFieldToFilter('additional_table.is_filterable', array('gt' => 0)); + } + + /** + * Add filterable in search filter + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addIsFilterableInSearchFilter() + { + return $this->addFieldToFilter('additional_table.is_filterable_in_search', array('gt' => 0)); + } + + /** + * Specify filter by "is_visible" field + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addVisibleFilter() + { + return $this->addFieldToFilter('additional_table.is_visible', 1); + } + + /** + * Specify "is_searchable" filter + * + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addIsSearchableFilter() + { + return $this->addFieldToFilter('additional_table.is_searchable', 1); + } + + /** + * Specify filter for attributes that have to be indexed + * + * @param bool $addRequiredCodes + * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection + */ + public function addToIndexFilter($addRequiredCodes = false) + { + $conditions = array( + 'additional_table.is_searchable = 1', + 'additional_table.is_visible_in_advanced_search = 1', + 'additional_table.is_filterable > 0', + 'additional_table.is_filterable_in_search = 1' + ); + + if ($addRequiredCodes) { + $conditions[] = $this->getConnection()->quoteInto('main_table.attribute_code IN (?)', array('status', 'visibility')); + } + + $this->getSelect()->where(sprintf('(%s)', implode(' OR ', $conditions))); + + return $this; + } + + /** + * Specify filter for attributes used in quick search + * + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection + */ + public function addSearchableAttributeFilter() + { + $this->getSelect()->where( + 'additional_table.is_searchable = 1 OR '. + $this->getConnection()->quoteInto('main_table.attribute_code IN (?)', array('status', 'visibility')) + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Image.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Image.php new file mode 100755 index 0000000000..bfa659512b --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Image.php @@ -0,0 +1,55 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Attribute_Frontend_Image + extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +{ + const IMAGE_PATH_SEGMENT = 'catalog/product/'; + + /** + * Retreive image url + * + * @param Varien_Object $object + * @return string|false + */ + public function getUrl($object) + { + $url = false; + $image = $object->getData($this->getAttribute()->getAttributeCode()); + if ($image) { + $url = Mage::getBaseUrl('media') . self::IMAGE_PATH_SEGMENT . $image; + } + return $url; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Virtual.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Tierprice.php old mode 100644 new mode 100755 similarity index 74% rename from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Virtual.php rename to app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Tierprice.php index f457d69271..f2db4451b4 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Virtual.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Frontend/Tierprice.php @@ -19,19 +19,20 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Catalog + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Adminhtml block for fieldset of virtual product + * Catalog product attribute tier price frontend model * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Catalog * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Composite_Fieldset_Virtual extends Mage_Adminhtml_Block_Catalog_Product_Composite_Configure +class Mage_Catalog_Model_Resource_Product_Attribute_Frontend_Tierprice + extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract { - } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php new file mode 100755 index 0000000000..b144371c09 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php @@ -0,0 +1,1849 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract +{ + /** + * Catalog Product Flat is enabled cache per store + * + * @var array + */ + protected $_flatEnabled = array(); + + /** + * Product websites table name + * + * @var string + */ + protected $_productWebsiteTable; + + /** + * Product categories table name + * + * @var string + */ + protected $_productCategoryTable; + + /** + * Is add URL rewrites to collection flag + * + * @var bool + */ + protected $_addUrlRewrite = false; + + /** + * Add URL rewrite for category + * + * @var int + */ + protected $_urlRewriteCategory = ''; + + /** + * Is add minimal price to product collection flag + * + * @var bool + */ + protected $_addMinimalPrice = false; + + /** + * Is add final price to product collection flag + * + * @var unknown_type + */ + protected $_addFinalPrice = false; + + /** + * Cache for all ids + * + * @var array + */ + protected $_allIdsCache = null; + + /** + * Is add tax percents to product collection flag + * + * @var bool + */ + protected $_addTaxPercents = false; + + /** + * Product limitation filters + * Allowed filters + * store_id int; + * category_id int; + * category_is_anchor int; + * visibility array|int; + * website_ids array|int; + * store_table string; + * use_price_index bool; join price index table flag + * customer_group_id int; required for price; customer group limitation for price + * website_id int; required for price; website limitation for price + * + * @var array + */ + protected $_productLimitationFilters = array(); + + /** + * Category product count select + * + * @var Zend_Db_Select + */ + protected $_productCountSelect = null; + + /** + * Enter description here ... + * + * @var bool + */ + protected $_isWebsiteFilter = false; + + /** + * Additional field filters, applied in _productLimitationJoinPrice() + * + * @var array + */ + protected $_priceDataFieldFilters = array(); + + /** + * Map of price fields + * + * @var array + */ + protected $_map = array('fields' => array( + 'price' => 'price_index.price', + 'final_price' => 'price_index.final_price', + 'min_price' => 'price_index.min_price', + 'max_price' => 'price_index.max_price', + 'tier_price' => 'price_index.tier_price', + 'special_price' => 'price_index.special_price', + )); + + /** + * Retrieve Catalog Product Flat Helper object + * + * @return Mage_Catalog_Helper_Product_Flat + */ + public function getFlatHelper() + { + return Mage::helper('catalog/product_flat'); + } + + /** + * Retrieve is flat enabled flag + * Return alvays false if magento run admin + * + * @return bool + */ + public function isEnabledFlat() + { + if (Mage::app()->getStore()->isAdmin()) { + return false; + } + if (!isset($this->_flatEnabled[$this->getStoreId()])) { + $this->_flatEnabled[$this->getStoreId()] = $this->getFlatHelper() + ->isEnabled($this->getStoreId()); + } + return $this->_flatEnabled[$this->getStoreId()]; + } + + /** + * Initialize resources + * + */ + protected function _construct() + { + if ($this->isEnabledFlat()) { + $this->_init('catalog/product', 'catalog/product_flat'); + } + else { + $this->_init('catalog/product'); + } + $this->_initTables(); + } + + /** + * Define product website and category product tables + * + */ + protected function _initTables() + { + $this->_productWebsiteTable = $this->getResource()->getTable('catalog/product_website'); + $this->_productCategoryTable= $this->getResource()->getTable('catalog/category_product'); + } + + /** + * Standard resource collection initalization + * + * @param string $model + * @param unknown_type $entityModel + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _init($model, $entityModel = null) + { + if ($this->isEnabledFlat()) { + $entityModel = 'catalog/product_flat'; + } + + return parent::_init($model, $entityModel); + } + + /** + * Prepare static entity fields + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _prepareStaticFields() + { + if ($this->isEnabledFlat()) { + return $this; + } + return parent::_prepareStaticFields(); + } + + /** + * Retrieve collection empty item + * Redeclared for specifying id field name without getting resource model inside model + * + * @return Varien_Object + */ + public function getNewEmptyItem() + { + $object = parent::getNewEmptyItem(); + if ($this->isEnabledFlat()) { + $object->setIdFieldName($this->getEntity()->getIdFieldName()); + } + return $object; + } + + /** + * Set entity to use for attributes + * + * @param Mage_Eav_Model_Entity_Abstract $entity + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function setEntity($entity) + { + if ($this->isEnabledFlat() && ($entity instanceof Mage_Core_Model_Resource_Db_Abstract)) { + $this->_entity = $entity; + return $this; + } + return parent::setEntity($entity); + } + + /** + * Set Store scope for collection + * + * @param mixed $store + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function setStore($store) + { + parent::setStore($store); + if ($this->isEnabledFlat()) { + $this->getEntity()->setStoreId($this->getStoreId()); + } + return $this; + } + + /** + * Initialize collection select + * Redeclared for remove entity_type_id condition + * in catalog_product_entity we store just products + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _initSelect() + { + if ($this->isEnabledFlat()) { + $this->getSelect() + ->from(array('e' => $this->getEntity()->getFlatTableName()), null) + ->columns(array('status' => new Zend_Db_Expr(Mage_Catalog_Model_Product_Status::STATUS_ENABLED))); + $this->addAttributeToSelect(array('entity_id', 'type_id', 'attribute_set_id')); + if ($this->getFlatHelper()->isAddChildData()) { + $this->getSelect() + ->where('e.is_child=?', 0); + $this->addAttributeToSelect(array('child_id', 'is_child')); + } + } else { + $this->getSelect()->from(array('e'=>$this->getEntity()->getEntityTable())); + } + return $this; + } + + /** + * Load attributes into loaded entities + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function _loadAttributes($printQuery = false, $logQuery = false) + { + if ($this->isEnabledFlat()) { + return $this; + } + return parent::_loadAttributes($printQuery, $logQuery); + } + + /** + * Add attribute to entities in collection + * If $attribute=='*' select all attributes + * + * @param array|string|integer|Mage_Core_Model_Config_Element $attribute + * @param false|string $joinType + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addAttributeToSelect($attribute, $joinType = false) + { + if ($this->isEnabledFlat()) { + if (!is_array($attribute)) { + $attribute = array($attribute); + } + foreach ($attribute as $attributeCode) { + if ($attributeCode == '*') { + foreach ($this->getEntity()->getAllTableColumns() as $column) { + $this->getSelect()->columns('e.' . $column); + $this->_selectAttributes[$column] = $column; + $this->_staticFields[$column] = $column; + } + } else { + $columns = $this->getEntity()->getAttributeForSelect($attributeCode); + if ($columns) { + foreach ($columns as $alias => $column) { + $this->getSelect()->columns(array($alias => 'e.' . $column)); + $this->_selectAttributes[$column] = $column; + $this->_staticFields[$column] = $column; + } + } + } + } + return $this; + } + return parent::addAttributeToSelect($attribute, $joinType); + } + + /** + * Add tax class id attribute to select and join price rules data if needed + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _beforeLoad() + { + Mage::dispatchEvent('catalog_product_collection_load_before', array('collection' => $this)); + + return parent::_beforeLoad(); + } + + /** + * Processing collection items after loading + * Adding url rewrites, minimal prices, final prices, tax percents + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _afterLoad() + { + if ($this->_addUrlRewrite) { + $this->_addUrlRewrite($this->_urlRewriteCategory); + } + + $this->_prepareUrlDataObject(); + + if (count($this) > 0) { + Mage::dispatchEvent('catalog_product_collection_load_after', array('collection' => $this)); + } + + foreach ($this as $product) { + if ($product->isRecurring() && $profile = $product->getRecurringProfile()) { + $product->setRecurringProfile(unserialize($profile)); + } + } + + return $this; + } + + /** + * Prepare Url Data object + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _prepareUrlDataObject() + { + $objects = array(); + /** @var $item Mage_Catalog_Model_Product */ + foreach ($this->_items as $item) { + if ($this->getFlag('do_not_use_category_id')) { + $item->setDoNotUseCategoryId(true); + } + if (!$item->isVisibleInSiteVisibility() && $item->getItemStoreId()) { + $objects[$item->getEntityId()] = $item->getItemStoreId(); + } + } + + if ($objects && $this->hasFlag('url_data_object')) { + $objects = Mage::getResourceSingleton('catalog/url') + ->getRewriteByProductStore($objects); + foreach ($this->_items as $item) { + if (isset($objects[$item->getEntityId()])) { + $object = new Varien_Object($objects[$item->getEntityId()]); + $item->setUrlDataObject($object); + } + } + } + + return $this; + } + + /** + * Add collection filters by identifiers + * + * @param mixed $productId + * @param boolean $exclude + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addIdFilter($productId, $exclude = false) + { + if (empty($productId)) { + $this->_setIsLoaded(true); + return $this; + } + if (is_array($productId)) { + if (!empty($productId)) { + if ($exclude) { + $condition = array('nin' => $productId); + } else { + $condition = array('in' => $productId); + } + } else { + $condition = ''; + } + } else { + if ($exclude) { + $condition = array('neq' => $productId); + } else { + $condition = $productId; + } + } + $this->addFieldToFilter('entity_id', $condition); + return $this; + } + + /** + * Adding product website names to result collection + * Add for each product websites information + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addWebsiteNamesToResult() + { + $productWebsites = array(); + foreach ($this as $product) { + $productWebsites[$product->getId()] = array(); + } + + if (!empty($productWebsites)) { + $select = $this->getConnection()->select() + ->from(array('product_website' => $this->_productWebsiteTable)) + ->join( + array('website' => $this->getResource()->getTable('core/website')), + 'website.website_id = product_website.website_id', + array('name')) + ->where('product_website.product_id IN (?)', array_keys($productWebsites)) + ->where('website.website_id > ?', 0); + + $data = $this->getConnection()->fetchAll($select); + foreach ($data as $row) { + $productWebsites[$row['product_id']][] = $row['website_id']; + } + } + + foreach ($this as $product) { + if (isset($productWebsites[$product->getId()])) { + $product->setData('websites', $productWebsites[$product->getId()]); + } + } + return $this; + } + + /** + * Add store availability filter. Include availability product + * for store website + * + * @param mixed $store + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addStoreFilter($store = null) + { + if ($store === null) { + $store = $this->getStoreId(); + } + $store = Mage::app()->getStore($store); + + if (!$store->isAdmin()) { + $this->setStoreId($store); + $this->_productLimitationFilters['store_id'] = $store->getId(); + $this->_applyProductLimitations(); + } + + return $this; + } + + /** + * Add website filter to collection + * + * @param unknown_type $websites + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addWebsiteFilter($websites = null) + { + if (!is_array($websites)) { + $websites = array(Mage::app()->getWebsite($websites)->getId()); + } + + $this->_productLimitationFilters['website_ids'] = $websites; + $this->_applyProductLimitations(); + + return $this; + } + + /** + * Specify category filter for product collection + * + * @param Mage_Catalog_Model_Category $category + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addCategoryFilter(Mage_Catalog_Model_Category $category) + { + $this->_productLimitationFilters['category_id'] = $category->getId(); + if ($category->getIsAnchor()) { + unset($this->_productLimitationFilters['category_is_anchor']); + } else { + $this->_productLimitationFilters['category_is_anchor'] = 1; + } + + if ($this->getStoreId() == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { + $this->_applyZeroStoreProductLimitations(); + } else { + $this->_applyProductLimitations(); + } + + return $this; + } + + /** + * Join minimal price attribute to result + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function joinMinimalPrice() + { + $this->addAttributeToSelect('price') + ->addAttributeToSelect('minimal_price'); + return $this; + } + + /** + * Retrieve max value by attribute + * + * @param string $attribute + * @return mixed + */ + public function getMaxAttributeValue($attribute) + { + $select = clone $this->getSelect(); + $attribute = $this->getEntity()->getAttribute($attribute); + $attributeCode = $attribute->getAttributeCode(); + $tableAlias = $attributeCode . '_max_value'; + $fieldAlias = 'max_' . $attributeCode; + $condition = 'e.entity_id = ' . $tableAlias . '.entity_id + AND '.$this->_getConditionSql($tableAlias . '.attribute_id', $attribute->getId()); + + $select->join( + array($tableAlias => $attribute->getBackend()->getTable()), + $condition, + array($fieldAlias => new Zend_Db_Expr('MAX('.$tableAlias.'.value)')) + ) + ->group('e.entity_type_id'); + + $data = $this->getConnection()->fetchRow($select); + if (isset($data[$fieldAlias])) { + return $data[$fieldAlias]; + } + + return null; + } + + /** + * Retrieve ranging product count for arrtibute range + * + * @param string $attribute + * @param int $range + * @return array + */ + public function getAttributeValueCountByRange($attribute, $range) + { + $select = clone $this->getSelect(); + $attribute = $this->getEntity()->getAttribute($attribute); + $attributeCode = $attribute->getAttributeCode(); + $tableAlias = $attributeCode . '_range_count_value'; + + $condition = 'e.entity_id = ' . $tableAlias . '.entity_id + AND ' . $this->_getConditionSql($tableAlias . '.attribute_id', $attribute->getId()); + + $select->reset(Zend_Db_Select::GROUP); + $select->join( + array($tableAlias => $attribute->getBackend()->getTable()), + $condition, + array( + 'count_' . $attributeCode => new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), + 'range_' . $attributeCode => new Zend_Db_Expr('CEIL((' . $tableAlias . '.value+0.01)/' . $range . ')') + ) + ) + ->group('range_' . $attributeCode); + + $data = $this->getConnection()->fetchAll($select); + $res = array(); + + foreach ($data as $row) { + $res[$row['range_' . $attributeCode]] = $row['count_' . $attributeCode]; + } + return $res; + } + + /** + * Retrieve product count by some value of attribute + * + * @param string $attribute + * @return array($value=>$count) + */ + public function getAttributeValueCount($attribute) + { + $select = clone $this->getSelect(); + $attribute = $this->getEntity()->getAttribute($attribute); + $attributeCode = $attribute->getAttributeCode(); + $tableAlias = $attributeCode . '_value_count'; + + $select->reset(Zend_Db_Select::GROUP); + $condition = 'e.entity_id=' . $tableAlias . '.entity_id + AND '.$this->_getConditionSql($tableAlias . '.attribute_id', $attribute->getId()); + + $select->join( + array($tableAlias => $attribute->getBackend()->getTable()), + $condition, + array( + 'count_' . $attributeCode => new Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'), + 'value_' . $attributeCode => new Zend_Db_Expr($tableAlias . '.value') + ) + ) + ->group('value_' . $attributeCode); + + $data = $this->getConnection()->fetchAll($select); + $res = array(); + + foreach ($data as $row) { + $res[$row['value_' . $attributeCode]] = $row['count_' . $attributeCode]; + } + return $res; + } + + /** + * Return all attribute values as array in form: + * array( + * [entity_id_1] => array( + * [store_id_1] => store_value_1, + * [store_id_2] => store_value_2, + * ... + * [store_id_n] => store_value_n + * ), + * ... + * ) + * + * @param string $attribute attribute code + * @return array + */ + public function getAllAttributeValues($attribute) + { + /** @var $select Varien_Db_Select */ + $select = clone $this->getSelect(); + $attribute = $this->getEntity()->getAttribute($attribute); + + $select->reset() + ->from($attribute->getBackend()->getTable(), array('entity_id', 'store_id', 'value')) + ->where('attribute_id = ?', (int)$attribute->getId()); + + $data = $this->getConnection()->fetchAll($select); + $res = array(); + + foreach ($data as $row) { + $res[$row['entity_id']][$row['store_id']] = $row['value']; + } + + return $res; + } + + /** + * Get SQL for get record count + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $this->_renderFilters(); + + $countSelect = $this->_getClearSelect() + ->columns('COUNT(DISTINCT e.entity_id)') + ->resetJoinLeft(); + return $countSelect; + } + + /** + * Retreive clear select + * + * @return Varien_Db_Select + */ + protected function _getClearSelect() + { + $select = clone $this->getSelect(); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + $select->reset(Zend_Db_Select::COLUMNS); + + return $select; + } + /** + * Retrive all ids for collection + * + * @param unknown_type $limit + * @param unknown_type $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + $idsSelect = $this->_getClearSelect(); + $idsSelect->columns('e.' . $this->getEntity()->getIdFieldName()); + $idsSelect->limit($limit, $offset); + $idsSelect->resetJoinLeft(); + + return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); + } + + /** + * Retreive product count select for categories + * + * @return Varien_Db_Select + */ + public function getProductCountSelect() + { + if ($this->_productCountSelect === null) { + $this->_productCountSelect = clone $this->getSelect(); + $this->_productCountSelect->reset(Zend_Db_Select::COLUMNS) + ->reset(Zend_Db_Select::GROUP) + ->reset(Zend_Db_Select::ORDER) + ->distinct(false) + ->join(array('count_table' => $this->getTable('catalog/category_product_index')), + 'count_table.product_id = e.entity_id', + array( + 'count_table.category_id', + 'product_count' => new Zend_Db_Expr('COUNT(DISTINCT count_table.product_id)') + ) + ) + ->where('count_table.store_id = ?', $this->getStoreId()) + ->group('count_table.category_id'); + } + + return $this->_productCountSelect; + } + + /** + * Destruct product count select + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function unsProductCountSelect() + { + $this->_productCountSelect = null; + return $this; + } + + /** + * Adding product count to categories collection + * + * @param Mage_Eav_Model_Entity_Collection_Abstract $categoryCollection + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addCountToCategories($categoryCollection) + { + $isAnchor = array(); + $isNotAnchor = array(); + foreach ($categoryCollection as $category) { + if ($category->getIsAnchor()) { + $isAnchor[] = $category->getId(); + } else { + $isNotAnchor[] = $category->getId(); + } + } + $productCounts = array(); + if ($isAnchor || $isNotAnchor) { + $select = $this->getProductCountSelect(); + + Mage::dispatchEvent( + 'catalog_product_collection_before_add_count_to_categories', + array('collection' => $this) + ); + + if ($isAnchor) { + $anchorStmt = clone $select; + $anchorStmt->limit(); //reset limits + $anchorStmt->where('count_table.category_id IN (?)', $isAnchor); + $productCounts += $this->getConnection()->fetchPairs($anchorStmt); + $anchorStmt = null; + } + if ($isNotAnchor) { + $notAnchorStmt = clone $select; + $notAnchorStmt->limit(); //reset limits + $notAnchorStmt->where('count_table.category_id IN (?)', $isNotAnchor); + $notAnchorStmt->where('count_table.is_parent = 1'); + $productCounts += $this->getConnection()->fetchPairs($notAnchorStmt); + $notAnchorStmt = null; + } + $select = null; + $this->unsProductCountSelect(); + } + + foreach ($categoryCollection as $category) { + $_count = 0; + if (isset($productCounts[$category->getId()])) { + $_count = $productCounts[$category->getId()]; + } + $category->setProductCount($_count); + } + + return $this; + } + + /** + * Retrieve unique attribute set ids in collection + * + * @return array + */ + public function getSetIds() + { + $select = clone $this->getSelect(); + /** @var $select Varien_Db_Select */ + $select->reset(Zend_Db_Select::COLUMNS); + $select->distinct(true); + $select->columns('attribute_set_id'); + return $this->getConnection()->fetchCol($select); + } + + /** + * Return array of unique product type ids in collection + * + * @return array + */ + public function getProductTypeIds() + { + $select = clone $this->getSelect(); + /** @var $select Varien_Db_Select */ + $select->reset(Zend_Db_Select::COLUMNS); + $select->distinct(true); + $select->columns('type_id'); + return $this->getConnection()->fetchCol($select); + } + + /** + * Joins url rewrite rules to collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function joinUrlRewrite() + { + $this->joinTable( + 'core/url_rewrite', + 'entity_id=entity_id', + array('request_path'), + '{{table}}.type = ' . Mage_Core_Model_Url_Rewrite::TYPE_PRODUCT, + 'left' + ); + + return $this; + } + + /** + * Add URL rewrites data to product + * If collection loadded - run processing else set flag + * + * @param int $categoryId + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addUrlRewrite($categoryId = '') + { + $this->_addUrlRewrite = true; + if (Mage::getStoreConfig(Mage_Catalog_Helper_Product::XML_PATH_PRODUCT_URL_USE_CATEGORY, $this->getStoreId())) { + $this->_urlRewriteCategory = $categoryId; + } else { + $this->_urlRewriteCategory = 0; + } + + if ($this->isLoaded()) { + $this->_addUrlRewrite(); + } + + return $this; + } + + /** + * Add URL rewrites to collection + * + */ + protected function _addUrlRewrite() + { + $urlRewrites = null; + if ($this->_cacheConf) { + if (!($urlRewrites = Mage::app()->loadCache($this->_cacheConf['prefix'] . 'urlrewrite'))) { + $urlRewrites = null; + } else { + $urlRewrites = unserialize($urlRewrites); + } + } + + if (!$urlRewrites) { + $productIds = array(); + foreach($this->getItems() as $item) { + $productIds[] = $item->getEntityId(); + } + if (!count($productIds)) { + return; + } + + $select = $this->getConnection()->select() + ->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path')) + ->where('store_id = ?', Mage::app()->getStore()->getId()) + ->where('is_system = ?', 1) + ->where('category_id = ? OR category_id IS NULL', $this->_urlRewriteCategory) + ->where('product_id IN(?)', $productIds) + ->order('category_id ' . self::SORT_ORDER_DESC); // more priority is data with category id + $urlRewrites = array(); + + foreach ($this->getConnection()->fetchAll($select) as $row) { + if (!isset($urlRewrites[$row['product_id']])) { + $urlRewrites[$row['product_id']] = $row['request_path']; + } + } + + if ($this->_cacheConf) { + Mage::app()->saveCache( + serialize($urlRewrites), + $this->_cacheConf['prefix'] . 'urlrewrite', + array_merge($this->_cacheConf['tags'], array(Mage_Catalog_Model_Product_Url::CACHE_TAG)), + $this->_cacheLifetime + ); + } + } + + foreach($this->getItems() as $item) { + if (isset($urlRewrites[$item->getEntityId()])) { + $item->setData('request_path', $urlRewrites[$item->getEntityId()]); + } else { + $item->setData('request_path', false); + } + } + } + + /** + * Add minimal price data to result + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addMinimalPrice() + { + return $this->addPriceData(); + } + + /** + * Add minimal price to product collection + * + * @deprecated sinse 1.3.2.2 + * @see Mage_Catalog_Model_Resource_Product_Collection::addPriceData + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _addMinimalPrice() + { + return $this; + } + + /** + * Add price data for calculate final price + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addFinalPrice() + { + return $this->addPriceData(); + } + + /** + * Join prices from price rules to products collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _joinPriceRules() + { + if ($this->isEnabledFlat()) { + $customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $priceColumn = 'e.display_price_group_' . $customerGroup; + $this->getSelect()->columns(array('_rule_price' => $priceColumn)); + + return $this; + } + if (!Mage::helper('catalog')->isModuleEnabled('Mage_CatalogRule')) { + return $this; + } + $wId = Mage::app()->getWebsite()->getId(); + $gId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + + $storeDate = Mage::app()->getLocale()->storeTimeStamp($this->getStoreId()); + $conditions = 'price_rule.product_id = e.entity_id AND '; + $conditions .= "price_rule.rule_date = '".$this->getResource()->formatDate($storeDate, false)."' AND "; + $conditions .= $this->getConnection()->quoteInto('price_rule.website_id = ? AND', $wId); + $conditions .= $this->getConnection()->quoteInto('price_rule.customer_group_id = ?', $gId); + + $this->getSelect()->joinLeft( + array('price_rule' => $this->getTable('catalogrule/rule_product_price')), + $conditions, + array('rule_price' => 'rule_price') + ); + return $this; + } + + /** + * Add final price to the product + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _addFinalPrice() + { + foreach ($this->_items as $product) { + $basePrice = $product->getPrice(); + $specialPrice = $product->getSpecialPrice(); + $specialPriceFrom = $product->getSpecialFromDate(); + $specialPriceTo = $product->getSpecialToDate(); + if ($this->isEnabledFlat()) { + $rulePrice = null; + if ($product->getData('_rule_price') != $basePrice) { + $rulePrice = $product->getData('_rule_price'); + } + } else { + $rulePrice = $product->getData('_rule_price'); + } + + $finalPrice = $product->getPriceModel()->calculatePrice( + $basePrice, + $specialPrice, + $specialPriceFrom, + $specialPriceTo, + $rulePrice, + null, + null, + $product->getId() + ); + + $product->setCalculatedFinalPrice($finalPrice); + } + + return $this; + } + + /** + * Retreive all ids + * + * @param boolean $resetCache + * @return array + */ + public function getAllIdsCache($resetCache = false) + { + $ids = null; + if (!$resetCache) { + $ids = $this->_allIdsCache; + } + + if (is_null($ids)) { + $ids = $this->getAllIds(); + $this->setAllIdsCache($ids); + } + + return $ids; + } + + /** + * Set all ids + * + * @param array $value + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function setAllIdsCache($value) + { + $this->_allIdsCache = $value; + return $this; + } + + /** + * Add Price Data to result + * + * @param int $customerGroupId + * @param int $websiteId + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addPriceData($customerGroupId = null, $websiteId = null) + { + $this->_productLimitationFilters['use_price_index'] = true; + + if (!isset($this->_productLimitationFilters['customer_group_id']) && is_null($customerGroupId)) { + $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + } + if (!isset($this->_productLimitationFilters['website_id']) && is_null($websiteId)) { + $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + } + + if (!is_null($customerGroupId)) { + $this->_productLimitationFilters['customer_group_id'] = $customerGroupId; + } + if (!is_null($websiteId)) { + $this->_productLimitationFilters['website_id'] = $websiteId; + } + + $this->_applyProductLimitations(); + + return $this; + } + + /** + * Add attribute to filter + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|string $attribute + * @param array $condition + * @param string $joinType + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner') + { + if ($this->isEnabledFlat()) { + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + $attribute = $attribute->getAttributeCode(); + } + + if (is_array($attribute)) { + $sqlArr = array(); + foreach ($attribute as $condition) { + $sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType); + } + $conditionSql = '('.join(') OR (', $sqlArr).')'; + $this->getSelect()->where($conditionSql); + return $this; + } + + if (!isset($this->_selectAttributes[$attribute])) { + $this->addAttributeToSelect($attribute); + } + + if (isset($this->_selectAttributes[$attribute])) { + $this->getSelect()->where($this->_getConditionSql('e.' . $attribute, $condition)); + } + + return $this; + } + + $this->_allIdsCache = null; + + if (is_string($attribute) && $attribute == 'is_saleable') { + $columns = $this->getSelect()->getPart(Zend_Db_Select::COLUMNS); + foreach ($columns as $columnEntry) { + list($correlationName, $column, $alias) = $columnEntry; + if ($alias == 'is_saleable') { + if ($column instanceof Zend_Db_Expr) { + $field = $column; + } else { + $adapter = $this->getSelect()->getAdapter(); + if (empty($correlationName)) { + $field = $adapter->quoteColumnAs($column, $alias, true); + } else { + $field = $adapter->quoteColumnAs(array($correlationName, $column), $alias, true); + } + } + $this->getSelect()->where("{$field} = ?", $condition); + break; + } + } + + return $this; + } else { + return parent::addAttributeToFilter($attribute, $condition, $joinType); + } + } + + /** + * Add requere tax percent flag for product collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addTaxPercents() + { + $this->_addTaxPercents = true; + return $this; + } + + /** + * Get require tax percent flag value + * + * @return bool + */ + public function requireTaxPercent() + { + return $this->_addTaxPercents; + } + + /** + * Enter description here ... + * + * @deprecated from 1.3.0 + * + */ + protected function _addTaxPercents() + { + $classToRate = array(); + $request = Mage::getSingleton('tax/calculation')->getRateRequest(); + foreach ($this as &$item) { + if (null === $item->getTaxClassId()) { + $item->setTaxClassId($item->getMinimalTaxClassId()); + } + if (!isset($classToRate[$item->getTaxClassId()])) { + $request->setProductClassId($item->getTaxClassId()); + $classToRate[$item->getTaxClassId()] = Mage::getSingleton('tax/calculation')->getRate($request); + } + $item->setTaxPercent($classToRate[$item->getTaxClassId()]); + } + } + + /** + * Adding product custom options to result collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addOptionsToResult() + { + $productIds = array(); + foreach ($this as $product) { + $productIds[] = $product->getId(); + } + if (!empty($productIds)) { + $options = Mage::getModel('catalog/product_option') + ->getCollection() + ->addTitleToResult(Mage::app()->getStore()->getId()) + ->addPriceToResult(Mage::app()->getStore()->getId()) + ->addProductToFilter($productIds) + ->addValuesToResult(); + + foreach ($options as $option) { + if($this->getItemById($option->getProductId())) { + $this->getItemById($option->getProductId())->addOption($option); + } + } + } + + return $this; + } + + /** + * Filter products with required options + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addFilterByRequiredOptions() + { + $this->addAttributeToFilter('required_options', array(array('neq' => '1'), array('null' => true)), 'left'); + return $this; + } + + /** + * Set product visibility filter for enabled products + * + * @param array $visibility + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function setVisibility($visibility) + { + $this->_productLimitationFilters['visibility'] = $visibility; + $this->_applyProductLimitations(); + + return $this; + } + + /** + * Add attribute to sort order + * + * @param string $attribute + * @param string $dir + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) + { + if ($attribute == 'position') { + if (isset($this->_joinFields[$attribute])) { + $this->getSelect()->order("{$attribute} {$dir}"); + return $this; + } + if ($this->isEnabledFlat()) { + $this->getSelect()->order("cat_index_position {$dir}"); + } + // optimize if using cat index + $filters = $this->_productLimitationFilters; + if (isset($filters['category_id']) || isset($filters['visibility'])) { + $this->getSelect()->order('cat_index.product_id ' . $dir); + } else { + $this->getSelect()->order('e.entity_id ' . $dir); + } + + return $this; + } elseif($attribute == 'is_saleable'){ + $this->getSelect()->order("is_saleable " . $dir); + return $this; + } + + $storeId = $this->getStoreId(); + if ($attribute == 'price' && $storeId != 0) { + $this->addPriceData(); + $this->getSelect()->order("price_index.min_price {$dir}"); + + return $this; + } + + if ($this->isEnabledFlat()) { + $column = $this->getEntity()->getAttributeSortColumn($attribute); + + if ($column) { + $this->getSelect()->order("e.{$column} {$dir}"); + } + else if (isset($this->_joinFields[$attribute])) { + $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir); + } + + return $this; + } else { + $attrInstance = $this->getEntity()->getAttribute($attribute); + if ($attrInstance && $attrInstance->usesSource()) { + $attrInstance->getSource() + ->addValueSortToCollection($this, $dir); + return $this; + } + } + + return parent::addAttributeToSort($attribute, $dir); + } + + /** + * Prepare limitation filters + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _prepareProductLimitationFilters() + { + if (isset($this->_productLimitationFilters['visibility']) + && !isset($this->_productLimitationFilters['store_id']) + ) { + $this->_productLimitationFilters['store_id'] = $this->getStoreId(); + } + if (isset($this->_productLimitationFilters['category_id']) + && !isset($this->_productLimitationFilters['store_id']) + ) { + $this->_productLimitationFilters['store_id'] = $this->getStoreId(); + } + if (isset($this->_productLimitationFilters['store_id']) + && isset($this->_productLimitationFilters['visibility']) + && !isset($this->_productLimitationFilters['category_id']) + ) { + $this->_productLimitationFilters['category_id'] = Mage::app() + ->getStore($this->_productLimitationFilters['store_id']) + ->getRootCategoryId(); + } + + return $this; + } + + /** + * Join website product limitation + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _productLimitationJoinWebsite() + { + $joinWebsite = false; + $filters = $this->_productLimitationFilters; + $conditions = array('product_website.product_id = e.entity_id'); + + if (isset($filters['website_ids'])) { + $joinWebsite = true; + if (count($filters['website_ids']) > 1) { + $this->getSelect()->distinct(true); + } + $conditions[] = $this->getConnection() + ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']); + } elseif (isset($filters['store_id']) + && (!isset($filters['visibility']) && !isset($filters['category_id'])) + && !$this->isEnabledFlat() + ) { + $joinWebsite = true; + $websiteId = Mage::app()->getStore($filters['store_id'])->getWebsiteId(); + $conditions[] = $this->getConnection() + ->quoteInto('product_website.website_id = ?', $websiteId); + } + + $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); + if (isset($fromPart['product_website'])) { + if (!$joinWebsite) { + unset($fromPart['product_website']); + } else { + $fromPart['product_website']['joinCondition'] = join(' AND ', $conditions); + } + $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); + } elseif ($joinWebsite) { + $this->getSelect()->join( + array('product_website' => $this->getTable('catalog/product_website')), + join(' AND ', $conditions), + array() + ); + } + + return $this; + } + + /** + * Join additional (alternative) store visibility filter + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _productLimitationJoinStore() + { + $filters = $this->_productLimitationFilters; + if (!isset($filters['store_table'])) { + return $this; + } + + $hasColumn = false; + foreach ($this->getSelect()->getPart(Zend_Db_Select::COLUMNS) as $columnEntry) { + list(,,$alias) = $columnEntry; + if ($alias == 'visibility') { + $hasColumn = true; + } + } + if (!$hasColumn) { + $this->getSelect()->columns('visibility', 'cat_index'); + } + + $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); + if (!isset($fromPart['store_index'])) { + $this->getSelect()->joinLeft( + array('store_index' => $this->getTable('core/store')), + 'store_index.store_id = ' . $filters['store_table'] . '.store_id', + array() + ); + } + if (!isset($fromPart['store_group_index'])) { + $this->getSelect()->joinLeft( + array('store_group_index' => $this->getTable('core/store_group')), + 'store_index.group_id = store_group_index.group_id', + array() + ); + } + if (!isset($fromPart['store_cat_index'])) { + $this->getSelect()->joinLeft( + array('store_cat_index' => $this->getTable('catalog/category_product_index')), + join(' AND ', array( + 'store_cat_index.product_id = e.entity_id', + 'store_cat_index.store_id = ' . $filters['store_table'] . '.store_id', + 'store_cat_index.category_id=store_group_index.root_category_id' + )), + array('store_visibility' => 'visibility') + ); + } + // Avoid column duplication problems + Mage::getResourceHelper('core')->prepareColumnsList($this->getSelect()); + + $whereCond = join(' OR ', array( + $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']), + $this->getConnection()->quoteInto('store_cat_index.visibility IN(?)', $filters['visibility']) + )); + + $wherePart = $this->getSelect()->getPart(Zend_Db_Select::WHERE); + $hasCond = false; + foreach ($wherePart as $cond) { + if ($cond == '(' . $whereCond . ')') { + $hasCond = true; + } + } + + if (!$hasCond) { + $this->getSelect()->where($whereCond); + } + + return $this; + } + + /** + * Join Product Price Table + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _productLimitationJoinPrice() + { + $filters = $this->_productLimitationFilters; + if (empty($filters['use_price_index'])) { + return $this; + } + + $helper = Mage::getResourceHelper('core'); + $connection = $this->getConnection(); + $select = $this->getSelect(); + $joinCond = join(' AND ', array( + 'price_index.entity_id = e.entity_id', + $connection->quoteInto('price_index.website_id = ?', $filters['website_id']), + $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id']) + )); + + $fromPart = $select->getPart(Zend_Db_Select::FROM); + if (!isset($fromPart['price_index'])) { + $least = $connection->getLeastSql(array('price_index.min_price', 'price_index.tier_price')); + $minimalExpr = $connection->getCheckSql('price_index.tier_price IS NOT NULL', $least, 'price_index.min_price'); + $colls = array('price', 'tax_class_id', 'final_price', + 'minimal_price' => $minimalExpr , 'min_price', 'max_price', 'tier_price'); + $select->join( + array('price_index' => $this->getTable('catalog/product_index_price')), + $joinCond, + $colls + ); + // Set additional field filters + foreach ($this->_priceDataFieldFilters as $filterData) { + $select->where(call_user_func_array('sprintf', $filterData)); + } + } else { + $fromPart['price_index']['joinCondition'] = $joinCond; + $select->setPart(Zend_Db_Select::FROM, $fromPart); + } + //Clean duplicated fields + $helper->prepareColumnsList($select); + + + return $this; + } + + /** + * Apply front-end price limitation filters to the collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function applyFrontendPriceLimitations() + { + $this->_productLimitationFilters['use_price_index'] = true; + if (!isset($this->_productLimitationFilters['customer_group_id'])) { + $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $this->_productLimitationFilters['customer_group_id'] = $customerGroupId; + } + if (!isset($this->_productLimitationFilters['website_id'])) { + $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + $this->_productLimitationFilters['website_id'] = $websiteId; + } + $this->_applyProductLimitations(); + return $this; + } + + /** + * Apply limitation filters to collection + * Method allows using one time category product index table (or product website table) + * for different combinations of store_id/category_id/visibility filter states + * Method supports multiple changes in one collection object for this parameters + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _applyProductLimitations() + { + $this->_prepareProductLimitationFilters(); + $this->_productLimitationJoinWebsite(); + $this->_productLimitationJoinPrice(); + $filters = $this->_productLimitationFilters; + + if (!isset($filters['category_id']) && !isset($filters['visibility'])) { + return $this; + } + + $conditions = array( + 'cat_index.product_id=e.entity_id', + $this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']) + ); + if (isset($filters['visibility']) && !isset($filters['store_table'])) { + $conditions[] = $this->getConnection() + ->quoteInto('cat_index.visibility IN(?)', $filters['visibility']); + } + $conditions[] = $this->getConnection() + ->quoteInto('cat_index.category_id=?', $filters['category_id']); + if (isset($filters['category_is_anchor'])) { + $conditions[] = $this->getConnection() + ->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']); + } + + $joinCond = join(' AND ', $conditions); + $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); + if (isset($fromPart['cat_index'])) { + $fromPart['cat_index']['joinCondition'] = $joinCond; + $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); + } + else { + $this->getSelect()->join( + array('cat_index' => $this->getTable('catalog/category_product_index')), + $joinCond, + array('cat_index_position' => 'position') + ); + } + + $this->_productLimitationJoinStore(); + + Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array( + 'collection' => $this + )); + + return $this; + } + + /** + * Apply limitation filters to collection base on API + * Method allows using one time category product table + * for combinations of category_id filter states + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + protected function _applyZeroStoreProductLimitations() + { + $filters = $this->_productLimitationFilters; + + $conditions = array( + 'cat_pro.product_id=e.entity_id', + $this->getConnection()->quoteInto('cat_pro.category_id=?', $filters['category_id']) + ); + $joinCond = join(' AND ', $conditions); + + $fromPart = $this->getSelect()->getPart(Zend_Db_Select::FROM); + if (isset($fromPart['cat_pro'])) { + $fromPart['cat_pro']['joinCondition'] = $joinCond; + $this->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart); + } + else { + $this->getSelect()->join( + array('cat_pro' => $this->getTable('catalog/category_product')), + $joinCond, + array('cat_index_position' => 'position') + ); + } + + return $this; + } + + /** + * Add category ids to loaded items + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addCategoryIds() + { + if ($this->getFlag('category_ids_added')) { + return $this; + } + $ids = array_keys($this->_items); + if (empty($ids)) { + return $this; + } + + $select = $this->getConnection()->select(); + + $select->from($this->_productCategoryTable, array('product_id', 'category_id')); + $select->where('product_id IN (?)', $ids); + + $data = $this->getConnection()->fetchAll($select); + + $categoryIds = array(); + foreach ($data as $info) { + if (isset($categoryIds[$info['product_id']])) { + $categoryIds[$info['product_id']][] = $info['category_id']; + } else { + $categoryIds[$info['product_id']] = array($info['category_id']); + } + } + + + foreach ($this->getItems() as $item) { + $productId = $item->getId(); + if (isset($categoryIds[$productId])) { + $item->setCategoryIds($categoryIds[$productId]); + } else { + $item->setCategoryIds(array()); + } + } + + $this->setFlag('category_ids_added', true); + return $this; + } + + /** + * Add tier price data to loaded items + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function addTierPriceData() + { + if ($this->getFlag('tier_price_added')) { + return $this; + } + + $tierPrices = array(); + $productIds = array(); + foreach ($this->getItems() as $item) { + $productIds[] = $item->getId(); + $tierPrices[$item->getId()] = array(); + } + if (!$productIds) { + return $this; + } + + /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ + $attribute = $this->getAttribute('tier_price'); + if ($attribute->isScopeGlobal()) { + $websiteId = 0; + } else if ($this->getStoreId()) { + $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + } + + $adapter = $this->getConnection(); + $columns = array( + 'price_id' => 'value_id', + 'website_id' => 'website_id', + 'all_groups' => 'all_groups', + 'cust_group' => 'customer_group_id', + 'price_qty' => 'qty', + 'price' => 'value', + 'product_id' => 'entity_id' + ); + $select = $adapter->select() + ->from($this->getTable('catalog/product_attribute_tier_price'), $columns) + ->where('entity_id IN(?)', $productIds) + ->order(array('entity_id','qty')); + + if ($websiteId == '0') { + $select->where('website_id = ?', $websiteId); + } else { + $select->where('website_id IN(?)', array('0', $websiteId)); + } + + foreach ($adapter->fetchAll($select) as $row) { + $tierPrices[$row['product_id']][] = array( + 'website_id' => $row['website_id'], + 'cust_group' => $row['all_groups'] ? Mage_Customer_Model_Group::CUST_GROUP_ALL : $row['cust_group'], + 'price_qty' => $row['price_qty'], + 'price' => $row['price'], + 'website_price' => $row['price'], + + ); + } + + /* @var $backend Mage_Catalog_Model_Product_Attribute_Backend_Tierprice */ + $backend = $attribute->getBackend(); + + foreach ($this->getItems() as $item) { + $data = $tierPrices[$item->getId()]; + if (!empty($data) && $websiteId) { + $data = $backend->preparePriceData($data, $item->getTypeId(), $websiteId); + } + $item->setData('tier_price', $data); + } + + $this->setFlag('tier_price_added', true); + return $this; + } + + /** + * Add field comparison expression + * + * @param string $comparisonFormat - expression for sprintf() + * @param array $fields - list of fields + * @return Mage_Catalog_Model_Resource_Product_Collection + * @throws Exception + */ + public function addPriceDataFieldFilter($comparisonFormat, $fields) + { + if (!preg_match('/^%s( (<|>|=|<=|>=|<>) %s)*$/', $comparisonFormat)) { + throw new Exception('Invalid comparison format.'); + } + + if (!is_array($fields)) { + $fields = array($fields); + } + foreach ($fields as $key => $field) { + $fields[$key] = $this->_getMappedField($field); + } + + $this->_priceDataFieldFilters[] = array_merge(array($comparisonFormat), $fields); + return $this; + } + + /** + * Clear collection + * + * @return Mage_Catalog_Model_Resource_Product_Collection + */ + public function clear() + { + foreach ($this->_items as $i => $item) { + if ($item->hasStockItem()) { + $item->unsStockItem(); + } + $item = $this->_items[$i] = null; + } + + foreach ($this->_itemsById as $i => $item) { + $item = $this->_itemsById[$i] = null; + } + + unset($this->_items, $this->_data, $this->_itemsById); + $this->_data = array(); + $this->_itemsById = array(); + return parent::clear(); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item.php new file mode 100755 index 0000000000..fec7641a0b --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item.php @@ -0,0 +1,247 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Compare_Item extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('catalog/compare_item', 'catalog_compare_item_id'); + } + + /** + * Load object by product + * + * @param Mage_Core_Model_Abstract $object + * @param mixed $product + * @return bool + */ + public function loadByProduct(Mage_Catalog_Model_Product_Compare_Item $object, $product) + { + $read = $this->_getReadAdapter(); + if ($product instanceof Mage_Catalog_Model_Product) { + $productId = $product->getId(); + } else { + $productId = $product; + } + $select = $read->select()->from($this->getMainTable()) + ->where('product_id = ?', (int)$productId); + + if ($object->getCustomerId()) { + $select->where('customer_id = ?', (int)$object->getCustomerId()); + } else { + $select->where('visitor_id = ?', (int)$object->getVisitorId()); + } + + $data = $read->fetchRow($select); + + if (!$data) { + return false; + } + + $object->setData($data); + + $this->_afterLoad($object); + return true; + } + + /** + * Resource retrieve count compare items + * + * @param int $customerId + * @param int $visitorId + * @return int + */ + public function getCount($customerId, $visitorId) + { + $bind = array('visitore_id' => (int)$visitorId); + $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'COUNT(*)') + ->where('visitor_id = :visitore_id'); + if ($customerId) { + $bind['customer_id'] = (int)$customerId; + $select->where('customer_id = :customer_id'); + } + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Clean compare table + * + * @return Mage_Catalog_Model_Resource_Product_Compare_Item + */ + public function clean() + { + while (true) { + $select = $this->_getReadAdapter()->select() + ->from(array('compare_table' => $this->getMainTable()), array('catalog_compare_item_id')) + ->joinLeft( + array('visitor_table' => $this->getTable('log/visitor')), + 'visitor_table.visitor_id=compare_table.visitor_id AND compare_table.customer_id IS NULL', + array()) + ->where('compare_table.visitor_id > ?', 0) + ->where('visitor_table.visitor_id IS NULL') + ->limit(100); + $itemIds = $this->_getReadAdapter()->fetchCol($select); + + if (!$itemIds) { + break; + } + + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + $this->_getWriteAdapter()->quoteInto('catalog_compare_item_id IN(?)', $itemIds) + ); + } + + return $this; + } + + /** + * Purge visitor data after customer logout + * + * @param Mage_Catalog_Model_Product_Compare_Item $object + * @return Mage_Catalog_Model_Resource_Product_Compare_Item + */ + public function purgeVisitorByCustomer($object) + { + if (!$object->getCustomerId()) { + return $this; + } + + $where = $this->_getWriteAdapter()->quoteInto('customer_id=?', $object->getCustomerId()); + $bind = array( + 'visitor_id' => 0, + ); + + $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); + + return $this; + } + + /** + * Update (Merge) customer data from visitor + * After Login process + * + * @param Mage_Catalog_Model_Product_Compare_Item $object + * @return Mage_Catalog_Model_Resource_Product_Compare_Item + */ + public function updateCustomerFromVisitor($object) + { + if (!$object->getCustomerId()) { + return $this; + } + + // collect visitor compared items + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable()) + ->where('visitor_id=?', $object->getVisitorId()); + $visitor = $this->_getWriteAdapter()->fetchAll($select); + + // collect customer compared items + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable()) + ->where('customer_id = ?', $object->getCustomerId()) + ->where('visitor_id != ?', $object->getVisitorId()); + $customer = $this->_getWriteAdapter()->fetchAll($select); + + $products = array(); + $delete = array(); + $update = array(); + foreach ($visitor as $row) { + $products[$row['product_id']] = array( + 'store_id' => $row['store_id'], + 'customer_id' => $object->getCustomerId(), + 'visitor_id' => $object->getVisitorId(), + 'product_id' => $row['product_id'] + ); + $update[$row[$this->getIdFieldName()]] = $row['product_id']; + } + + foreach ($customer as $row) { + if (isset($products[$row['product_id']])) { + $delete[] = $row[$this->getIdFieldName()]; + } + else { + $products[$row['product_id']] = array( + 'store_id' => $row['store_id'], + 'customer_id' => $object->getCustomerId(), + 'visitor_id' => $object->getVisitorId(), + 'product_id' => $row['product_id'] + ); + } + } + + if ($delete) { + $this->_getWriteAdapter()->delete($this->getMainTable(), + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $delete)); + } + if ($update) { + foreach ($update as $itemId => $productId) { + $bind = $products[$productId]; + $this->_getWriteAdapter()->update($this->getMainTable(), $bind, + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $itemId)); + } + } + + return $this; + } + + /** + * Clear compare items by visitor and/or customer + * + * @param int $visitorId + * @param int $customerId + * @return Mage_Catalog_Model_Resource_Product_Compare_Item + */ + public function clearItems($visitorId = null, $customerId = null) + { + $where = array(); + if ($customerId) { + $customerId = (int)$customerId; + $where[] = $this->_getWriteAdapter()->quoteInto('customer_id = ?', $customerId); + } + if ($visitorId) { + $visitorId = (int)$visitorId; + $where[] = $this->_getWriteAdapter()->quoteInto('visitor_id = ?', $visitorId); + } + if (!$where) { + return $this; + } + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item/Collection.php new file mode 100755 index 0000000000..0cd9ed0416 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item/Collection.php @@ -0,0 +1,333 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Customer Filter + * + * @var int + */ + protected $_customerId = 0; + + /** + * Visitor Filter + * + * @var int + */ + protected $_visitorId = 0; + + /** + * Comparable attributes cache + * + * @var array + */ + protected $_comparableAttributes; + + /** + * Initialize resources + */ + protected function _construct() + { + $this->_init('catalog/product_compare_item', 'catalog/product'); + $this->_initTables(); + } + + /** + * Set customer filter to collection + * + * @param int $customerId + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function setCustomerId($customerId) + { + $this->_customerId = (int)$customerId; + $this->_addJoinToSelect(); + return $this; + } + + /** + * Set visitor filter to collection + * + * @param int $visitorId + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function setVisitorId($visitorId) + { + $this->_visitorId = (int)$visitorId; + $this->_addJoinToSelect(); + return $this; + } + + /** + * Retrieve customer filter applied to collection + * + * @return int + */ + public function getCustomerId() + { + return $this->_customerId; + } + + /** + * Retrieve visitor filter applied to collection + * + * @return int + */ + public function getVisitorId() + { + return $this->_visitorId; + } + + /** + * Retrieve condition for join filters + * + * @return array|null + */ + public function getConditionForJoin() + { + if ($this->getCustomerId()) { + return array('customer_id' => $this->getCustomerId()); + } + + if ($this->getVisitorId()) { + return array('visitor_id' => $this->getVisitorId()); + } + + return null; + } + + /** + * Add join to select + * + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function _addJoinToSelect() + { + $this->joinTable( + array('t_compare' => 'catalog/compare_item'), + 'product_id=entity_id', + array( + 'product_id' => 'product_id', + 'customer_id' => 'customer_id', + 'visitor_id' => 'visitor_id', + 'item_store_id' => 'store_id', + 'catalog_compare_item_id' => 'catalog_compare_item_id' + ), + $this->getConditionForJoin() + ); + + $this->_productLimitationFilters['store_table'] = 't_compare'; + + return $this; + } + + /** + * Retrieve comapre products attribute set ids + * + * @return array + */ + protected function _getAttributeSetIds() + { + // prepare compare items table conditions + $compareConds = array( + 'compare.product_id=entity.entity_id', + ); + if ($this->getCustomerId()) { + $compareConds[] = $this->getConnection() + ->quoteInto('compare.customer_id = ?', $this->getCustomerId()); + } else { + $compareConds[] = $this->getConnection() + ->quoteInto('compare.visitor_id = ?', $this->getVisitorId()); + } + + // prepare website filter + $websiteId = (int)Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + $websiteConds = array( + 'website.product_id = entity.entity_id', + $this->getConnection()->quoteInto('website.website_id = ?', $websiteId) + ); + + // retrieve attribute sets + $select = $this->getConnection()->select() + ->distinct(true) + ->from( + array('entity' => $this->getEntity()->getEntityTable()), + 'attribute_set_id') + ->join( + array('website' => $this->getTable('catalog/product_website')), + join(' AND ', $websiteConds), + array()) + ->join( + array('compare' => $this->getTable('catalog/compare_item')), + join(' AND ', $compareConds), + array() + ); + return $this->getConnection()->fetchCol($select); + } + + /** + * Retrieve attribute ids by set ids + * + * @param array $setIds + * @return array + */ + protected function _getAttributeIdsBySetIds(array $setIds) + { + $select = $this->getConnection()->select() + ->distinct(true) + ->from($this->getTable('eav/entity_attribute'), 'attribute_id') + ->where('attribute_set_id IN(?)', $setIds); + return $this->getConnection()->fetchCol($select); + } + + /** + * Retrieve Merged comparable attributes for compared product items + * + * @return array + */ + public function getComparableAttributes() + { + if (is_null($this->_comparableAttributes)) { + $this->_comparableAttributes = array(); + $setIds = $this->_getAttributeSetIds(); + if ($setIds) { + $attributeIds = $this->_getAttributeIdsBySetIds($setIds); + + $select = $this->getConnection()->select() + ->from(array('main_table' => $this->getTable('eav/attribute'))) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'additional_table.attribute_id=main_table.attribute_id' + ) + ->joinLeft( + array('al' => $this->getTable('eav/attribute_label')), + 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(), + array('store_label' => $this->getConnection()->getCheckSql('al.value IS NULL', 'main_table.frontend_label', 'al.value')) + ) + ->where('additional_table.is_comparable=?', 1) + ->where('main_table.attribute_id IN(?)', $attributeIds); + $attributesData = $this->getConnection()->fetchAll($select); + if ($attributesData) { + $entityType = Mage_Catalog_Model_Product::ENTITY; + Mage::getSingleton('eav/config') + ->importAttributesData($entityType, $attributesData); + foreach ($attributesData as $data) { + $attribute = Mage::getSingleton('eav/config') + ->getAttribute($entityType, $data['attribute_code']); + $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute; + } + unset($attributesData); + } + } + } + return $this->_comparableAttributes; + } + + /** + * Load Comparable attributes + * + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function loadComparableAttributes() + { + $comparableAttributes = $this->getComparableAttributes(); + $attributes = array(); + foreach ($comparableAttributes as $attribute) { + $attributes[] = $attribute->getAttributeCode(); + } + $this->addAttributeToSelect($attributes); + + return $this; + } + + /** + * Use product as collection item + * + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function useProductItem() + { + $this->setObject('catalog/product'); + + $this->setFlag('url_data_object', true); + $this->setFlag('do_not_use_category_id', true); + + return $this; + } + + /** + * Retrieve product ids from collection + * + * @return array + */ + public function getProductIds() + { + $ids = array(); + foreach ($this->getItems() as $item) { + $ids[] = $item->getProductId(); + } + + return $ids; + } + + /** + * Clear compare items by condition + * + * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection + */ + public function clear() + { + Mage::getResourceSingleton('catalog/product_compare_item') + ->clearItems($this->getVisitorId(), $this->getCustomerId()); + Mage::dispatchEvent('catalog_product_compare_item_collection_clear'); + + return $this; + } + + /** + * Retrieve is flat enabled flag + * Overwrite disable flat for compared item if required EAV resource + * + * @return bool + */ + public function isEnabledFlat() + { + if (!Mage::helper('catalog/product_compare')->getAllowUsedFlat()) { + return false; + } + return parent::isEnabledFlat(); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat.php new file mode 100755 index 0000000000..84fb0d8ceb --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat.php @@ -0,0 +1,220 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Flat extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Store scope Id + * + * @var int + */ + protected $_storeId; + + /** + * Init connection and resource table + * + */ + protected function _construct() + { + $this->_init('catalog/product_flat', 'entity_id'); + $this->_storeId = (int)Mage::app()->getStore()->getId(); + } + + /** + * Retrieve store for resource model + * + * @return int + */ + public function getStoreId() + { + return $this->_storeId; + } + + /** + * Set store for resource model + * + * @param mixed $store + * @return Mage_Catalog_Model_Resource_Product_Flat + */ + public function setStoreId($store) + { + if (is_int($store)) { + $this->_storeId = $store; + } else { + $this->_storeId = (int)Mage::app()->getStore($store)->getId(); + } + return $this; + } + + /** + * Retrieve Flat Table name + * + * @param mixed $store + * @return string + */ + public function getFlatTableName($store = null) + { + if ($store === null) { + $store = $this->getStoreId(); + } + return $this->getTable(array('catalog/product_flat', $store)); + } + + /** + * Retrieve entity type id + * + * @return int + */ + public function getTypeId() + { + return Mage::getSingleton('catalog/config') + ->getEntityType(Mage_Catalog_Model_Product::ENTITY) + ->getEntityTypeId(); + } + + /** + * Retrieve attribute columns for collection select + * + * @param string $attributeCode + * @return array|null + */ + public function getAttributeForSelect($attributeCode) + { + $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); + if (!isset($describe[$attributeCode])) { + return null; + } + $columns = array($attributeCode => $attributeCode); + + $attributeIndex = sprintf('%s_value', $attributeCode); + if (isset($describe[$attributeIndex])) { + $columns[$attributeIndex] = $attributeIndex; + } + + return $columns; + } + + /** + * Retrieve Attribute Sort column name + * + * @param string $attributeCode + * @return string + */ + public function getAttributeSortColumn($attributeCode) + { + $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); + if (!isset($describe[$attributeCode])) { + return null; + } + $attributeIndex = sprintf('%s_value', $attributeCode); + if (isset($describe[$attributeIndex])) { + return $attributeIndex; + } + return $attributeCode; + } + + /** + * Retrieve Flat Table columns list + * + * @return array + */ + public function getAllTableColumns() + { + $describe = $this->_getWriteAdapter()->describeTable($this->getFlatTableName()); + return array_keys($describe); + } + + /** + * Check whether the attribute is a real field in entity table + * Rewrited for EAV Collection + * + * @param integer|string|Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return bool + */ + public function isAttributeStatic($attribute) + { + $attributeCode = null; + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Interface) { + $attributeCode = $attribute->getAttributeCode(); + } elseif (is_string($attribute)) { + $attributeCode = $attribute; + } elseif (is_numeric($attribute)) { + $attributeCode = $this->getAttribute($attribute) + ->getAttributeCode(); + } + + if ($attributeCode) { + $columns = $this->getAllTableColumns(); + if (in_array($attributeCode, $columns)) { + return true; + } + } + + return false; + } + + /** + * Retrieve entity id field name in entity table + * Rewrited for EAV collection compatible + * + * @return string + */ + public function getEntityIdField() + { + return $this->getIdFieldName(); + } + + /** + * Retrieve attribute instance + * Special for non static flat table + * + * @param mixed $attribute + * @return Mage_Eav_Model_Entity_Attribute_Abstract + */ + public function getAttribute($attribute) + { + return Mage::getSingleton('catalog/config') + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attribute); + } + + /** + * Retrieve main resource table name + * + * @return string + */ + public function getMainTable() + { + return $this->getFlatTableName($this->getStoreId()); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php new file mode 100755 index 0000000000..8688abd9f2 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php @@ -0,0 +1,1259 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Flat_Indexer extends Mage_Core_Model_Resource_Db_Abstract +{ + const XML_NODE_MAX_INDEX_COUNT = 'global/catalog/product/flat/max_index_count'; + const XML_NODE_ATTRIBUTE_NODES = 'global/catalog/product/flat/attribute_nodes'; + + /** + * Attribute codes for flat + * + * @var array + */ + protected $_attributeCodes; + + /** + * Attribute objects for flat cache + * + * @var array + */ + protected $_attributes; + + /** + * Required system attributes for preload + * + * @var array + */ + protected $_systemAttributes = array('status', 'required_options', 'tax_class_id', 'weight'); + + /** + * Eav Catalog_Product Entity Type Id + * + * @var int + */ + protected $_entityTypeId; + + /** + * Flat table columns cache + * + * @var array + */ + protected $_columns; + + /** + * Flat table indexes cache + * + * @var array + */ + protected $_indexes; + + /** + * Product Type Instances cache + * + * @var array + */ + protected $_productTypes; + + /** + * Exists flat tables cache + * + * @var array + */ + protected $_existsFlatTables = array(); + + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Rebuild Catalog Product Flat Data + * + * @param Mage_Core_Model_Store|int $store + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function rebuild($store = null) + { + if ($store === null) { + foreach (Mage::app()->getStores() as $store) { + $this->rebuild($store->getId()); + } + $flag = $this->getFlatHelper()->getFlag(); + $flag->setIsBuild(true)->save(); + + return $this; + } + + $storeId = (int)Mage::app()->getStore($store)->getId(); + + $this->prepareFlatTable($storeId); + $this->cleanNonWebsiteProducts($storeId); + $this->updateStaticAttributes($storeId); + $this->updateEavAttributes($storeId); + $this->updateEventAttributes($storeId); + $this->updateRelationProducts($storeId); + $this->cleanRelationProducts($storeId); + + return $this; + } + + /** + * Retrieve Catalog Product Flat helper + * + * @return Mage_Catalog_Helper_Product_Flat + */ + public function getFlatHelper() + { + return Mage::helper('catalog/product_flat'); + } + + /** + * Retrieve attribute codes using for flat + * + * @return array + */ + public function getAttributeCodes() + { + if ($this->_attributeCodes === null) { + $adapter = $this->_getReadAdapter(); + $this->_attributeCodes = array(); + + $attributeNodes = Mage::getConfig() + ->getNode(self::XML_NODE_ATTRIBUTE_NODES) + ->children(); + foreach ($attributeNodes as $node) { + $attributes = Mage::getConfig()->getNode((string)$node)->asArray(); + $attributes = array_keys($attributes); + $this->_systemAttributes = array_unique(array_merge($attributes, $this->_systemAttributes)); + } + + $bind = array( + 'backend_type' => Mage_Eav_Model_Entity_Attribute_Abstract::TYPE_STATIC, + 'entity_type_id' => $this->getEntityTypeId() + ); + + $select = $adapter->select() + ->from(array('main_table' => $this->getTable('eav/attribute'))) + ->join( + array('additional_table' => $this->getTable('catalog/eav_attribute')), + 'additional_table.attribute_id = main_table.attribute_id' + ) + ->where('main_table.entity_type_id = :entity_type_id'); + $whereCondition = array( + 'main_table.backend_type = :backend_type', + $adapter->quoteInto('additional_table.used_in_product_listing = ?', 1), + $adapter->quoteInto('additional_table.used_for_sort_by = ?', 1), + $adapter->quoteInto('main_table.attribute_code IN(?)', $this->_systemAttributes) + ); + if ($this->getFlatHelper()->isAddFilterableAttributes()) { + $whereCondition[] = $adapter->quoteInto('additional_table.is_filterable > ?', 0); + } + + $select->where(implode(' OR ', $whereCondition)); + $attributesData = $adapter->fetchAll($select, $bind); + Mage::getSingleton('eav/config') + ->importAttributesData($this->getEntityType(), $attributesData); + + foreach ($attributesData as $data) { + $this->_attributeCodes[$data['attribute_id']] = $data['attribute_code']; + } + unset($attributesData); + } + + return $this->_attributeCodes; + } + + /** + * Retrieve entity type + * + * @return string + */ + public function getEntityType() + { + return Mage_Catalog_Model_Product::ENTITY; + } + + /** + * Retrieve Catalog Entity Type Id + * + * @return int + */ + public function getEntityTypeId() + { + if ($this->_entityTypeId === null) { + $this->_entityTypeId = Mage::getResourceModel('catalog/config') + ->getEntityTypeId(); + } + return $this->_entityTypeId; + } + + /** + * Retrieve attribute objects for flat + * + * @return array + */ + public function getAttributes() + { + if ($this->_attributes === null) { + $this->_attributes = array(); + $attributeCodes = $this->getAttributeCodes(); + $entity = Mage::getSingleton('eav/config') + ->getEntityType($this->getEntityType()) + ->getEntity(); + + foreach ($attributeCodes as $attributeCode) { + $attribute = Mage::getSingleton('eav/config') + ->getAttribute($this->getEntityType(), $attributeCode) + ->setEntity($entity); + try { + // check if exists source and backend model. + // To prevent exception when some module was disabled + $attribute->usesSource() && $attribute->getSource(); + $attribute->getBackend(); + $this->_attributes[$attributeCode] = $attribute; + } catch (Exception $e) { + Mage::logException($e); + } + } + } + + return $this->_attributes; + } + + /** + * Retrieve loaded attribute by code + * + * @param string $attributeCode + * @throws Mage_Core_Exception + * @return Mage_Eav_Model_Entity_Attribute + */ + public function getAttribute($attributeCode) + { + $attributes = $this->getAttributes(); + if (!isset($attributes[$attributeCode])) { + $attribute = Mage::getModel('catalog/resource_eav_attribute') + ->loadByCode($this->getEntityTypeId(), $attributeCode); + if (!$attribute->getId()) { + Mage::throwException(Mage::helper('catalog')->__('Invalid attribute %s', $attributeCode)); + } + $entity = Mage::getSingleton('eav/config') + ->getEntityType($this->getEntityType()) + ->getEntity(); + $attribute->setEntity($entity); + + return $attribute; + } + + return $attributes[$attributeCode]; + } + + /** + * Retrieve Catalog Product Flat Table name + * + * @param int $storeId + * @return string + */ + public function getFlatTableName($storeId) + { + return sprintf('%s_%s', $this->getTable('catalog/product_flat'), $storeId); + } + + /** + * Retrieve catalog product flat table columns array + * + * @return array + */ + public function getFlatColumns() + { + if ($this->_columns === null) { + $this->_columns = array(); + $this->_columns['entity_id'] = array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'length' => null, + 'unsigned' => true, + 'nullable' => false, + 'default' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ); + if ($this->getFlatHelper()->isAddChildData()) { + $this->_columns['child_id'] = array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'length' => null, + 'unsigned' => true, + 'nullable' => true, + 'default' => null, + 'primary' => true, + 'comment' => 'Child Id' + ); + $this->_columns['is_child'] = array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'length' => 1, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Checks If Entity Is Child' + ); + } + $this->_columns['attribute_set_id'] = array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'length' => 5, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Set Id' + ); + $this->_columns['type_id'] = array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'unsigned' => false, + 'nullable' => false, + 'default' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, + 'comment' => 'Type Id' + ); + + foreach ($this->getAttributes() as $attribute) { + /** @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ + $columns = $attribute + ->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes()) + ->setFlatAddChildData($this->getFlatHelper()->isAddChildData()) + ->getFlatColumns(); + if ($columns !== null) { + $this->_columns = array_merge($this->_columns, $columns); + } + } + + $columnsObject = new Varien_Object(); + $columnsObject->setColumns($this->_columns); + Mage::dispatchEvent('catalog_product_flat_prepare_columns', array( + 'columns' => $columnsObject + )); + $this->_columns = $columnsObject->getColumns(); + } + + return $this->_columns; + } + + /** + * Retrieve catalog product flat table indexes array + * + * @return array + */ + public function getFlatIndexes() + { + if ($this->_indexes === null) { + $this->_indexes = array(); + + if ($this->getFlatHelper()->isAddChildData()) { + $this->_indexes['PRIMARY'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY, + 'fields' => array('entity_id', 'child_id') + ); + $this->_indexes['IDX_CHILD'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, + 'fields' => array('child_id') + ); + $this->_indexes['IDX_IS_CHILD'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, + 'fields' => array('entity_id', 'is_child') + ); + } else { + $this->_indexes['PRIMARY'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY, + 'fields' => array('entity_id') + ); + } + $this->_indexes['IDX_TYPE_ID'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, + 'fields' => array('type_id') + ); + $this->_indexes['IDX_ATTRIBUTE_SET'] = array( + 'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, + 'fields' => array('attribute_set_id') + ); + + foreach ($this->getAttributes() as $attribute) { + /** @var $attribute Mage_Eav_Model_Entity_Attribute */ + $indexes = $attribute + ->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes()) + ->setFlatAddChildData($this->getFlatHelper()->isAddChildData()) + ->getFlatIndexes(); + if ($indexes !== null) { + $this->_indexes = array_merge($this->_indexes, $indexes); + } + } + + $indexesObject = new Varien_Object(); + $indexesObject->setIndexes($this->_indexes); + Mage::dispatchEvent('catalog_product_flat_prepare_indexes', array( + 'indexes' => $indexesObject + )); + $this->_indexes = $indexesObject->getIndexes(); + } + + return $this->_indexes; + } + + /** + * Compare Flat style with Describe style columns + * If column a different - return false + * + * @param array $column + * @param array $describe + * @return bool + */ + protected function _compareColumnProperties($column, $describe) + { + return Mage::getResourceHelper('catalog')->compareIndexColumnProperties($column, $describe); + } + + /** + * Retrieve column definition fragment + * @deprecated since 1.5.0.0 + * + * Example: `field_name` smallint(5) unsigned NOT NULL default '0' + * + * @param string $fieldName + * @param array $fieldProp + * @return string + */ + protected function _sqlColunmDefinition($fieldName, $fieldProp) + { + $fieldNameQuote = $this->_getWriteAdapter()->quoteIdentifier($fieldName); + + /** + * Process the case when 'is_null' prohibits null value, and 'default' proposed to be null + * It just means that default value not specified + */ + if ($fieldProp['is_null'] === false && $fieldProp['default'] === null) { + $defaultValue = ''; + } else { + $defaultValue = $fieldProp['default'] === null ? ' DEFAULT NULL' : $this->_getReadAdapter() + ->quoteInto(' DEFAULT ?', $fieldProp['default']); + } + + return "{$fieldNameQuote} {$fieldProp['type']}" + . ($fieldProp['unsigned'] ? ' UNSIGNED' : '') + . ($fieldProp['extra'] ? ' ' . $fieldProp['extra'] : '') + . ($fieldProp['is_null'] === false ? ' NOT NULL' : '') + . $defaultValue; + } + + /** + * Retrieve index definition fragment + * @deprecated since 1.5.0.0 + * + * Example: INDEX `IDX_NAME` (`field_id`) + * + * @param string $indexName + * @param array $indexProp + * @return string + */ + protected function _sqlIndexDefinition($indexName, $indexProp) + { + $fields = $indexProp['fields']; + if (is_array($fields)) { + $fieldSql = array(); + foreach ($fields as $field) { + $fieldSql[] = $this->_getReadAdapter()->quoteIdentifier($field); + } + $fieldSql = join(',', $fieldSql); + } + else { + $fieldSql = $this->_getReadAdapter()->quoteIdentifier($fields); + } + + $indexNameQuote = $this->_getReadAdapter()->quoteIdentifier($indexName); + switch (strtolower($indexProp['type'])) { + case 'primary': + $condition = 'PRIMARY KEY'; + break; + case 'unique': + $condition = 'UNIQUE ' . $indexNameQuote; + break; + case 'fulltext': + $condition = 'FULLTEXT ' . $indexNameQuote; + break; + default: + $condition = 'INDEX ' . $indexNameQuote; + break; + } + + return sprintf('%s (%s)', $condition, $fieldSql); + } + + /** + * Retrieve UNIQUE HASH for a Table foreign key + * + * @param string $priTableName the target table name + * @param string $priColumnName the target table column name + * @param string $refTableName the reference table name + * @param string $refColumnName the reference table column name + * @return string + */ + public function getFkName($priTableName, $priColumnName, $refTableName, $refColumnName) + { + return Mage::getSingleton('core/resource') + ->getFkName($priTableName, $priColumnName, $refTableName, $refColumnName); + } + + /** + * Prepare flat table for store + * + * @param int $storeId + * @throws Mage_Core_Exception + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function prepareFlatTable($storeId) + { + $columns = $this->getFlatColumns(); + $indexes = $this->getFlatIndexes(); + $maxIndex = Mage::getConfig()->getNode(self::XML_NODE_MAX_INDEX_COUNT); + + if (count($indexes) > $maxIndex) { + Mage::throwException(Mage::helper('catalog')->__("The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module", count($indexes), $maxIndex)); + } + + $adapter = $this->_getWriteAdapter(); + $tableName = $this->getFlatTableName($storeId); + /* + * Apply new names For indexes; + */ + $indexNames = array(); + $indexProps = array_values($indexes); + foreach ($indexProps as $propId => $indexProp) { + $indexNames[$propId] = $adapter->getIndexName($tableName, $indexProp['fields'], $indexProp['type']); + } + $indexes = array_combine($indexNames, $indexProps); + + $foreignEntityKey = $this->getFkName($tableName, 'entity_id', 'catalog/product', 'entity_id'); + $foreignChildKey = $this->getFkName($tableName, 'child_id', 'catalog/product', 'entity_id'); + + if (!$this->_isFlatTableExists($storeId)) { + /** @var $table Varien_Db_Ddl_Table */ + $table = $adapter->newTable($tableName); + foreach ($columns as $fieldName => $fieldProp) { + $table->addColumn($fieldName, $fieldProp['type'], isset($fieldProp['length']) ? $fieldProp['length'] : null, array( + 'nullable' => isset($fieldProp['nullable']) ? (bool)$fieldProp['nullable'] : false, + 'unsigned' => isset($fieldProp['unsigned']) ? (bool)$fieldProp['unsigned'] : false, + 'default' => isset($fieldProp['default']) ? $fieldProp['default'] : false, + 'primary' => false, + ), isset($fieldProp['comment']) ? $fieldProp['comment'] : $fieldName); + } + + foreach ($indexes as $indexName => $indexProp) { + if ($indexName == 'PRIMARY') { + continue; + } + $table->addIndex($indexName, $indexProp['fields'], array('type' => $indexProp['type'])); + } + + $table->addForeignKey($foreignEntityKey, + 'entity_id', $this->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); + + if ($this->getFlatHelper()->isAddChildData()) { + $table->addForeignKey($foreignChildKey, + 'child_id', $this->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); + } + $table->setComment("Catalog Product Flat (Store {$storeId})"); + + $adapter->createTable($table); + + $this->_existsFlatTables[$storeId] = true; + } else { + $adapter->resetDdlCache($tableName); + $describe = $adapter->describeTable($tableName); + $indexList = $adapter->getIndexList($tableName); + $addColumns = array_diff_key($columns, $describe); + $dropColumns = array_diff_key($describe, $columns); + $modifyColumns = array(); + + $addIndexes = array_diff_key($indexes, $indexList); + $dropIndexes = array_diff_key($indexList, $indexes); + $addConstraints = array(); + + $addConstraints[$foreignEntityKey] = array( + 'table_index' => 'entity_id', + 'ref_table' => $this->getTable('catalog/product'), + 'ref_index' => 'entity_id', + 'on_update' => Varien_Db_Ddl_Table::ACTION_CASCADE, + 'on_delete' => Varien_Db_Ddl_Table::ACTION_CASCADE + ); + + $isAddChildData = $this->getFlatHelper()->isAddChildData(); + if (!$isAddChildData && isset($describe['is_child'])) { + $adapter->delete($tableName, array('is_child = ?' => 1)); + $adapter->dropForeignKey($tableName, $foreignChildKey); + } + if ($isAddChildData && !isset($describe['is_child'])) { + $adapter->truncateTable($tableName); + $dropIndexes['PRIMARY'] = $indexList['PRIMARY']; + $addIndexes['PRIMARY'] = $indexes['PRIMARY']; + + $addConstraints[$foreignChildKey] = array( + 'table_index' => 'child_id', + 'ref_table' => $this->getTable('catalog/product'), + 'ref_index' => 'entity_id', + 'on_update' => Varien_Db_Ddl_Table::ACTION_CASCADE, + 'on_delete' => Varien_Db_Ddl_Table::ACTION_CASCADE + ); + } + + foreach ($columns as $field => $fieldProp) { + if (isset($describe[$field]) + && !$this->_compareColumnProperties($fieldProp, $describe[$field])) { + $modifyColumns[$field] = $fieldProp; + } + } + + foreach ($indexList as $indexName => $indexProp) { + if (isset($indexes[$indexName]) && ($indexes[$indexName]['type'] != $indexProp['type'])) { + $dropIndexes[$indexName] = $indexProp; + $addIndexes[$indexName] = $indexes[$indexName]; + } + } + + foreach (array_keys($adapter->getForeignKeys($tableName)) as $constraintName) { + $adapter->dropForeignKey($tableName, $constraintName); + } + // drop indexes + foreach (array_keys($dropIndexes) as $indexName) { + $adapter->dropIndex($tableName, $indexName); + } + + // drop columns + foreach (array_keys($dropColumns) as $columnName) { + $adapter->dropColumn($tableName, $columnName); + } + + // modify column + foreach ($modifyColumns as $columnName => $columnProp) { + $columnProp = array_change_key_case($columnProp, CASE_UPPER); + if (!isset($columnProp['COMMENT'])) { + $columnProp['COMMENT'] = ucwords(str_replace('_', ' ', $columnName)); + } + $adapter->changeColumn($tableName, $columnName, $columnName, $columnProp); + } + // add columns + foreach ($addColumns as $columnName => $columnProp) { + $columnProp = array_change_key_case($columnProp, CASE_UPPER); + if (!isset($columnProp['COMMENT'])) { + $columnProp['COMMENT'] = ucwords(str_replace('_', ' ', $columnName)); + } + $adapter->addColumn($tableName, $columnName, $columnProp); + } + + // add indexes + foreach ($addIndexes as $indexName => $indexProp) { + $adapter->addIndex($tableName, $indexName, $indexProp['fields'], $indexProp['type']); + } + + foreach ($addConstraints as $constraintName => $constraintProp) { + $adapter->addForeignKey($constraintName, $tableName, + $constraintProp['table_index'], + $constraintProp['ref_table'], + $constraintProp['ref_index'], + $constraintProp['on_delete'], + $constraintProp['on_update'] + ); + } + } + + return $this; + } + + /** + * Add or Update static attributes + * + * @param int $storeId + * @param int|array $productIds update only product(s) + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateStaticAttributes($storeId, $productIds = null) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $websiteId = (int)Mage::app()->getStore($storeId)->getWebsite()->getId(); + /* @var $status Mage_Eav_Model_Entity_Attribute */ + $status = $this->getAttribute('status'); + + $fieldList = array('entity_id', 'type_id', 'attribute_set_id'); + $colsList = array('entity_id', 'type_id', 'attribute_set_id'); + if ($this->getFlatHelper()->isAddChildData()) { + $fieldList = array_merge($fieldList, array('child_id', 'is_child')); + $isChild = new Zend_Db_Expr('0'); + $colsList = array_merge($colsList, array('entity_id', $isChild)); + } + + $columns = $this->getFlatColumns(); + $bind = array( + 'website_id' => $websiteId, + 'store_id' => $storeId, + 'entity_type_id' => (int)$status->getEntityTypeId(), + 'attribute_id' => (int)$status->getId() + ); + + $fieldExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + $select = $this->_getWriteAdapter()->select() + ->from(array('e' => $this->getTable('catalog/product')), $colsList) + ->join( + array('wp' => $this->getTable('catalog/product_website')), + 'e.entity_id = wp.product_id AND wp.website_id = :website_id', + array()) + ->joinLeft( + array('t1' => $status->getBackend()->getTable()), + 'e.entity_id = t1.entity_id', + array()) + ->joinLeft( + array('t2' => $status->getBackend()->getTable()), + 't2.entity_id = t1.entity_id' + . ' AND t1.entity_type_id = t2.entity_type_id' + . ' AND t1.attribute_id = t2.attribute_id' + . ' AND t2.store_id = :store_id', + array()) + ->where('t1.entity_type_id = :entity_type_id') + ->where('t1.attribute_id = :attribute_id') + ->where('t1.store_id = ?', Mage_Core_Model_App::ADMIN_STORE_ID) + ->where("{$fieldExpr} = ?", Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + foreach ($this->getAttributes() as $attributeCode => $attribute) { + /** @var $attribute Mage_Eav_Model_Entity_Attribute */ + if ($attribute->getBackend()->getType() == 'static') { + if (!isset($columns[$attributeCode])) { + continue; + } + $fieldList[] = $attributeCode; + $select->columns($attributeCode, 'e'); + } + } + + if ($productIds !== null) { + $select->where('e.entity_id IN(?)', $productIds); + } + + $sql = $select->insertFromSelect($this->getFlatTableName($storeId), $fieldList); + $adapter->query($sql, $bind); + + return $this; + } + + /** + * Remove non website products + * + * @param int $storeId + * @param int|array $productIds + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function cleanNonWebsiteProducts($storeId, $productIds = null) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + + $websiteId = (int)Mage::app()->getStore($storeId)->getWebsite()->getId(); + $adapter = $this->_getWriteAdapter(); + + $joinCondition = array( + 'e.entity_id = wp.product_id', + 'wp.website_id = :website_id' + ); + if ($this->getFlatHelper()->isAddChildData()) { + $joinCondition[] = 'e.child_id = wp.product_id'; + } + $bind = array('website_id' => $websiteId); + $select = $adapter->select() + ->from(array('e' => $this->getFlatTableName($storeId)), null) + ->joinLeft( + array('wp' => $this->getTable('catalog/product_website')), + implode(' AND ', $joinCondition), + array()); + if ($productIds !== null) { + $condition = array( + $adapter->quoteInto('e.entity_id IN(?)', $productIds) + ); + if ($this->getFlatHelper()->isAddChildData()) { + $condition[] = $adapter->quoteInto('e.child_id IN(?)', $productIds); + } + $select->where(implode(' OR ', $condition)); + } + + $sql = $select->deleteFromSelect('e'); + $adapter->query($sql, $bind); + + return $this; + } + + /** + * Update attribute flat data + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param int $storeId + * @param int|array $productIds update only product(s) + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateAttribute($attribute, $storeId, $productIds = null) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $flatTableName = $this->getFlatTableName($storeId); + $describe = $adapter->describeTable($flatTableName); + + if ($attribute->getBackend()->getType() == 'static') { + if (!isset($describe[$attribute->getAttributeCode()])) { + return $this; + } + + $select = $adapter->select() + ->join( + array('main_table' => $this->getTable('catalog/product')), + 'main_table.entity_id = e.entity_id', + array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()) + ); + if ($this->getFlatHelper()->isAddChildData()) { + $select->where('e.is_child = ?', 0); + } + if ($productIds !== null) { + $select->where('main_table.entity_id IN(?)', $productIds); + } + + $sql = $select->crossUpdateFromSelect(array('e' => $flatTableName)); + $adapter->query($sql); + } else { + $columns = $attribute->getFlatColumns(); + if (!$columns) { + return $this; + } + foreach (array_keys($columns) as $columnName) { + if (!isset($describe[$columnName])) { + return $this; + } + } + + $select = $attribute->getFlatUpdateSelect($storeId); + if ($select instanceof Varien_Db_Select) { + if ($productIds !== null) { + $select->where('e.entity_id IN(?)', $productIds); + } + + $sql = $select->crossUpdateFromSelect(array('e' => $flatTableName)); + $adapter->query($sql); + } + } + + return $this; + } + + /** + * Update non static EAV attributes flat data + * + * @param int $storeId + * @param int|array $productIds update only product(s) + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateEavAttributes($storeId, $productIds = null) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + + foreach ($this->getAttributes() as $attribute) { + /* @var $attribute Mage_Eav_Model_Entity_Attribute */ + if ($attribute->getBackend()->getType() != 'static') { + $this->updateAttribute($attribute, $storeId, $productIds); + } + } + return $this; + } + + /** + * Update events observer attributes + * + * @param int $storeId + */ + public function updateEventAttributes($storeId = null) + { + Mage::dispatchEvent('catalog_product_flat_rebuild', array( + 'store_id' => $storeId, + 'table' => $this->getFlatTableName($storeId) + )); + } + + /** + * Retrieve Product Type Instances + * as key - type code, value - instance model + * + * @return array + */ + public function getProductTypeInstances() + { + if ($this->_productTypes === null) { + $this->_productTypes = array(); + $productEmulator = new Varien_Object(); + + foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) { + $productEmulator->setTypeId($typeId); + $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type') + ->factory($productEmulator); + } + } + return $this->_productTypes; + } + + /** + * Update relation products + * + * @param int $storeId + * @param int|array $productIds Update child product(s) only + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateRelationProducts($storeId, $productIds = null) + { + if (!$this->getFlatHelper()->isAddChildData() || !$this->_isFlatTableExists($storeId)) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + + foreach ($this->getProductTypeInstances() as $typeInstance) { + if (!$typeInstance->isComposite()) { + continue; + } + $relation = $typeInstance->getRelationInfo(); + if ($relation + && $relation->getTable() + && $relation->getParentFieldName() + && $relation->getChildFieldName() + ) { + $columns = $this->getFlatColumns(); + $fieldList = array_keys($columns); + unset($columns['entity_id']); + unset($columns['child_id']); + unset($columns['is_child']); + + $select = $adapter->select() + ->from( + array('t' => $this->getTable($relation->getTable())), + array($relation->getParentFieldName(), $relation->getChildFieldName(), new Zend_Db_Expr('1'))) + ->join( + array('e' => $this->getFlatTableName($storeId)), + "e.entity_id = t.{$relation->getChildFieldName()}", + array_keys($columns) + ); + if ($relation->getWhere() !== null) { + $select->where($relation->getWhere()); + } + if ($productIds !== null) { + $cond = array( + $adapter->quoteInto("{$relation->getChildFieldName()} IN(?)", $productIds), + $adapter->quoteInto("{$relation->getParentFieldName()} IN(?)", $productIds) + ); + + $select->where(implode(' OR ', $cond)); + } + $sql = $select->insertFromSelect($this->getFlatTableName($storeId), $fieldList); + $adapter->query($sql); + } + } + + return $this; + } + + /** + * Update children data from parent + * + * @param int $storeId + * @param int|array $productIds + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateChildrenDataFromParent($storeId, $productIds = null) + { + if (!$this->getFlatHelper()->isAddChildData() || !$this->_isFlatTableExists($storeId)) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + + $select = $adapter->select(); + foreach (array_keys($this->getFlatColumns()) as $columnName) { + if ($columnName == 'entity_id' || $columnName == 'child_id' || $columnName == 'is_child') { + continue; + } + $select->columns(array($columnName => new Zend_Db_Expr('t1.' . $columnName))); + } + $select + ->joinLeft( + array('t1' => $this->getFlatTableName($storeId)), + $adapter->quoteInto('t2.child_id = t1.entity_id AND t1.is_child = ?', 0), + array()) + ->where('t2.is_child = ?', 1); + + if ($productIds !== null) { + $select->where('t2.child_id IN(?)', $productIds); + } + + $sql = $select->crossUpdateFromSelect(array('t2' => $this->getFlatTableName($storeId))); + $adapter->query($sql); + + return $this; + } + + /** + * Clean unused relation products + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function cleanRelationProducts($storeId) + { + if (!$this->getFlatHelper()->isAddChildData()) { + return $this; + } + + foreach ($this->getProductTypeInstances() as $typeInstance) { + if (!$typeInstance->isComposite()) { + continue; + } + $adapter = $this->_getWriteAdapter(); + $relation = $typeInstance->getRelationInfo(); + if ($relation + && $relation->getTable() + && $relation->getParentFieldName() + && $relation->getChildFieldName() + ) { + $select = $this->_getWriteAdapter()->select() + ->distinct(true) + ->from( + $this->getTable($relation->getTable()), + "{$relation->getParentFieldName()}" + ); + $joinLeftCond = array( + "e.entity_id = t.{$relation->getParentFieldName()}", + "e.child_id = t.{$relation->getChildFieldName()}" + ); + if ($relation->getWhere() !== null) { + $select->where($relation->getWhere()); + $joinLeftCond[] = $relation->getWhere(); + } + + $entitySelect = new Zend_Db_Expr($select->__toString()); + + $select = $adapter->select() + ->from(array('e' => $this->getFlatTableName($storeId)), null) + ->joinLeft( + array('t' => $this->getTable($relation->getTable())), + implode(' AND ', $joinLeftCond), + array()) + ->where('e.is_child = ?', 1) + ->where('e.entity_id IN(?)', $entitySelect) + ->where("t.{$relation->getChildFieldName()} IS NULL"); + + $sql = $select->deleteFromSelect('e'); + $adapter->query($sql); + } + } + + return $this; + } + + /** + * Remove product data from flat + * + * @param int|array $productIds + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function removeProduct($productIds, $storeId) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $cond = array( + $adapter->quoteInto('entity_id IN(?)', $productIds) + ); + if ($this->getFlatHelper()->isAddChildData()) { + $cond[] = $adapter->quoteInto('child_id IN(?)', $productIds); + } + $cond = implode(' OR ', $cond); + $adapter->delete($this->getFlatTableName($storeId), $cond); + + return $this; + } + + /** + * Remove children from parent product + * + * @param int|array $productIds + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function removeProductChildren($productIds, $storeId) + { + if (!$this->getFlatHelper()->isAddChildData()) { + return $this; + } + $whereExpr = array( + 'entity_id IN(?)' => $productIds, + 'is_child = ?' => 1 + ); + $this->_getWriteAdapter()->delete($this->getFlatTableName($storeId), $whereExpr); + + return $this; + } + + /** + * Update flat data for product + * + * @param int|array $productIds + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function updateProduct($productIds, $storeId) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + + $this->saveProduct($productIds, $storeId); + + Mage::dispatchEvent('catalog_product_flat_update_product', array( + 'store_id' => $storeId, + 'table' => $this->getFlatTableName($storeId), + 'product_ids' => $productIds + )); + + return $this; + } + + /** + * Save product(s) data for store + * + * @param int|array $productIds + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function saveProduct($productIds, $storeId) + { + if (!$this->_isFlatTableExists($storeId)) { + return $this; + } + + $this->updateStaticAttributes($storeId, $productIds); + $this->updateEavAttributes($storeId, $productIds); + + return $this; + } + + /** + * Delete flat table process + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer + */ + public function deleteFlatTable($storeId) + { + if ($this->_isFlatTableExists($storeId)) { + $this->_getWriteAdapter()->dropTable($this->getFlatTableName($storeId)); + } + + return $this; + } + + /** + * Check is flat table for store exists + * + * @param int $storeId + * @return bool + */ + protected function _isFlatTableExists($storeId) + { + if (!isset($this->_existsFlatTables[$storeId])) { + $tableName = $this->getFlatTableName($storeId); + $isTableExists = $this->_getWriteAdapter()->isTableExists($tableName); + + $this->_existsFlatTables[$storeId] = $isTableExists ? true : false; + } + + return $this->_existsFlatTables[$storeId]; + } + + /** + * Retrieve previous key from array by key + * + * @param array $array + * @param mixed $key + * @return mixed + */ + protected function _arrayPrevKey(array $array, $key) + { + $prev = false; + foreach (array_keys($array) as $k) { + if ($k == $key) { + return $prev; + } + $prev = $k; + } + return false; + } + + /** + * Retrieve next key from array by key + * + * @param array $array + * @param mixed $key + * @return mixed + */ + protected function _arrayNextKey(array $array, $key) + { + $next = false; + foreach (array_keys($array) as $k) { + if ($next === true) { + return $k; + } + if ($k == $key) { + $next = true; + } + } + return false; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Abstract.php new file mode 100755 index 0000000000..c225408cb6 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Abstract.php @@ -0,0 +1,203 @@ + + */ +abstract class Mage_Catalog_Model_Resource_Product_Indexer_Abstract extends Mage_Index_Model_Resource_Abstract +{ + /** + * Retrieve catalog_product attribute instance by attribute code + * + * @param string $attributeCode + * @return Mage_Catalog_Model_Resource_Eav_Attribute + */ + protected function _getAttribute($attributeCode) + { + return Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); + } + + /** + * Add attribute join condition to select and return Zend_Db_Expr + * attribute value definition + * If $condition is not empty apply limitation for select + * + * @param Varien_Db_Select $select + * @param string $attrCode the attribute code + * @param string|Zend_Db_Expr $entity the entity field or expression for condition + * @param string|Zend_Db_Expr $store the store field or expression for condition + * @param Zend_Db_Expr $condition the limitation condition + * @param bool $required if required or has condition used INNER join, else - LEFT + * @return Zend_Db_Expr the attribute value expression + */ + protected function _addAttributeToSelect($select, $attrCode, $entity, $store, $condition = null, $required = false) + { + $attribute = $this->_getAttribute($attrCode); + $attributeId = $attribute->getAttributeId(); + $attributeTable = $attribute->getBackend()->getTable(); + $adapter = $this->_getReadAdapter(); + $joinType = !is_null($condition) || $required ? 'join' : 'joinLeft'; + + if ($attribute->isScopeGlobal()) { + $alias = 'ta_' . $attrCode; + $select->$joinType( + array($alias => $attributeTable), + "{$alias}.entity_id = {$entity} AND {$alias}.attribute_id = {$attributeId}" + . " AND {$alias}.store_id = 0", + array() + ); + $expression = new Zend_Db_Expr("{$alias}.value"); + } else { + $dAlias = 'tad_' . $attrCode; + $sAlias = 'tas_' . $attrCode; + + $select->$joinType( + array($dAlias => $attributeTable), + "{$dAlias}.entity_id = {$entity} AND {$dAlias}.attribute_id = {$attributeId}" + . " AND {$dAlias}.store_id = 0", + array() + ); + $select->joinLeft( + array($sAlias => $attributeTable), + "{$sAlias}.entity_id = {$entity} AND {$sAlias}.attribute_id = {$attributeId}" + . " AND {$sAlias}.store_id = {$store}", + array() + ); + $expression = $adapter->getCheckSql($adapter->getIfNullSql("{$sAlias}.value_id", -1) . ' > 0', + "{$sAlias}.value", "{$dAlias}.value"); + } + + if (!is_null($condition)) { + $select->where("{$expression}{$condition}"); + } + + return $expression; + } + + /** + * Add website data join to select + * If add default store join also limitation of only has default store website + * Joined table has aliases + * cw for website table, + * csg for store group table (joined by website default group) + * cs for store table (joined by website default store) + * + * @param Varien_Db_Select $select the select object + * @param bool $store add default store join + * @param string|Zend_Db_Expr $joinCondition the limitation for website_id + * @return Mage_Catalog_Model_Resource_Product_Indexer_Abstract + */ + protected function _addWebsiteJoinToSelect($select, $store = true, $joinCondition = null) + { + if (!is_null($joinCondition)) { + $joinCondition = 'cw.website_id = ' . $joinCondition; + } + + $select->join( + array('cw' => $this->getTable('core/website')), + $joinCondition, + array() + ); + + if ($store) { + $select->join( + array('csg' => $this->getTable('core/store_group')), + 'csg.group_id = cw.default_group_id', + array()) + ->join( + array('cs' => $this->getTable('core/store')), + 'cs.store_id = csg.default_store_id', + array()); + } + + return $this; + } + + /** + * Add join for catalog/product_website table + * Joined table has alias pw + * + * @param Varien_Db_Select $select the select object + * @param string|Zend_Db_Expr $website the limitation of website_id + * @param string|Zend_Db_Expr $product the limitation of product_id + * @return Mage_Catalog_Model_Resource_Product_Indexer_Abstract + */ + protected function _addProductWebsiteJoinToSelect($select, $website, $product) + { + $select->join( + array('pw' => $this->getTable('catalog/product_website')), + "pw.product_id = {$product} AND pw.website_id = {$website}", + array() + ); + + return $this; + } + + /** + * Retrieve product relations by children + * + * @param int|array $childIds + * @return array + */ + public function getRelationsByChild($childIds) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), 'parent_id') + ->where('child_id IN(?)', $childIds); + + return $write->fetchCol($select); + } + + /** + * Retrieve product relations by parents + * + * @param int|array $parentIds + * @return array + */ + public function getRelationsByParent($parentIds) + { + if (!is_array($parentIds)) { + $parentIds = array($parentIds); + } + + $result = array(); + if (!empty($parentIds)) { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), 'child_id') + ->where('parent_id IN(?)', $parentIds); + $result = $write->fetchCol($select); + } + + return $result; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php new file mode 100755 index 0000000000..cfdcca1c13 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php @@ -0,0 +1,204 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Eav extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract +{ + /** + * EAV Indexers by type + * + * @var array + */ + protected $_types; + + /** + * Define main index table + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_eav', 'entity_id'); + } + + /** + * Retrieve array of EAV type indexers + * + * @return array + */ + public function getIndexers() + { + if (is_null($this->_types)) { + $this->_types = array( + 'source' => Mage::getResourceModel('catalog/product_indexer_eav_source'), + 'decimal' => Mage::getResourceModel('catalog/product_indexer_eav_decimal'), + ); + } + + return $this->_types; + } + + /** + * Retrieve indexer instance by type + * + * @param string $type + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + public function getIndexer($type) + { + $indexers = $this->getIndexers(); + if (!isset($indexers[$type])) { + Mage::throwException(Mage::helper('catalog')->__('Unknown EAV indexer type "%s".', $type)); + } + return $indexers[$type]; + } + + /** + * Process product save. + * Method is responsible for index support + * when product was saved and assigned categories was changed. + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav + */ + public function catalogProductSave(Mage_Index_Model_Event $event) + { + $productId = $event->getEntityPk(); + $data = $event->getNewData(); + + /** + * Check if filterable attribute values were updated + */ + if (!isset($data['reindex_eav'])) { + return $this; + } + + foreach ($this->getIndexers() as $indexer) { + /** @var $indexer Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract */ + $indexer->reindexEntities($productId); + } + + return $this; + } + + /** + * Process Product Delete + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav + */ + public function catalogProductDelete(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_eav_parent_ids'])) { + return $this; + } + + foreach ($this->getIndexers() as $indexer) { + /** @var $indexer Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract */ + $indexer->reindexEntities($data['reindex_eav_parent_ids']); + } + + return $this; + } + + /** + * Process Product Mass Update + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav + */ + public function catalogProductMassAction(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_eav_product_ids'])) { + return $this; + } + + foreach ($this->getIndexers() as $indexer) { + /** @var $indexer Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract */ + $indexer->reindexEntities($data['reindex_eav_product_ids']); + } + + return $this; + } + + /** + * Process Catalog Eav Attribute Save + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav + */ + public function catalogEavAttributeSave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_attribute'])) { + return $this; + } + + $indexer = $this->getIndexer($data['attribute_index_type']); + + $indexer->reindexAttribute($event->getEntityPk(), !empty($data['is_indexable'])); + + return $this; + } + + /** + * Rebuild all index data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav + */ + public function reindexAll() + { + $this->useIdxTable(true); + foreach ($this->getIndexers() as $indexer) { + /** @var $indexer Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract */ + $indexer->reindexAll(); + } + + return $this; + } + + /** + * Retrieve temporary source index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_eav_indexer_idx'); + } + return $this->getTable('catalog/product_eav_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php new file mode 100755 index 0000000000..63ec5f66a4 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php @@ -0,0 +1,274 @@ + + */ +abstract class Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract +{ + /** + * Rebuild all index data + * + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->clearTemporaryIndexTable(); + $this->_prepareIndex(); + $this->_prepareRelationIndex(); + $this->_removeNotVisibleEntityFromIndex(); + + $this->syncData(); + + return $this; + } + + /** + * Rebuild index data by entities + * + * + * @param int|array $processIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + * @throws Exception + */ + public function reindexEntities($processIds) + { + $adapter = $this->_getWriteAdapter(); + + $this->clearTemporaryIndexTable(); + + if (!is_array($processIds)) { + $processIds = array($processIds); + } + + $parentIds = $this->getRelationsByChild($processIds); + if ($parentIds) { + $processIds = array_unique(array_merge($processIds, $parentIds)); + } + $childIds = $this->getRelationsByParent($parentIds); + if ($childIds) { + $processIds = array_unique(array_merge($processIds, $childIds)); + } + + $this->_prepareIndex($processIds); + $this->_prepareRelationIndex($processIds); + $this->_removeNotVisibleEntityFromIndex(); + + $adapter->beginTransaction(); + try { + // remove old index + $where = $adapter->quoteInto('entity_id IN(?)', $processIds); + $adapter->delete($this->getMainTable(), $where); + + // insert new index + $this->useDisableKeys(false); + $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); + $this->useDisableKeys(true); + + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Rebuild index data by attribute id + * If attribute is not indexable remove data by attribute + * + * + * @param int $attributeId + * @param bool $isIndexable + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + public function reindexAttribute($attributeId, $isIndexable = true) + { + if (!$isIndexable) { + $this->_removeAttributeIndexData($attributeId); + } else { + $this->clearTemporaryIndexTable(); + + $this->_prepareIndex(null, $attributeId); + $this->_prepareRelationIndex(); + $this->_removeNotVisibleEntityFromIndex(); + + $this->_synchronizeAttributeIndexData($attributeId); + } + + return $this; + } + + /** + * Prepare data index for indexable attributes + * + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation + */ + abstract protected function _prepareIndex($entityIds = null, $attributeId = null); + + /** + * Remove Not Visible products from temporary data index + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + protected function _removeNotVisibleEntityFromIndex() + { + $write = $this->_getWriteAdapter(); + $idxTable = $this->getIdxTable(); + + $select = $write->select() + ->from($idxTable, null); + + $condition = $write->quoteInto('=?',Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE); + $this->_addAttributeToSelect($select, 'visibility', $idxTable . '.entity_id', $idxTable . '.store_id', $condition); + + $query = $select->deleteFromSelect($idxTable); + $write->query($query); + + return $this; + } + + /** + * Prepare data index for product relations + * + * @param array $parentIds the parent entity ids limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + protected function _prepareRelationIndex($parentIds = null) + { + $write = $this->_getWriteAdapter(); + $idxTable = $this->getIdxTable(); + + $select = $write->select() + ->from(array('l' => $this->getTable('catalog/product_relation')), 'parent_id') + ->join( + array('cs' => $this->getTable('core/store')), + '', + array()) + ->join( + array('i' => $idxTable), + 'l.child_id = i.entity_id AND cs.store_id = i.store_id', + array('attribute_id', 'store_id', 'value')) + ->group(array( + 'l.parent_id', 'i.attribute_id', 'i.store_id', 'i.value' + )); + if (!is_null($parentIds)) { + $select->where('l.parent_id IN(?)', $parentIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('l.parent_id'), + 'website_field' => new Zend_Db_Expr('cs.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $query = $write->insertFromSelect($select, $idxTable, array(), Varien_Db_Adapter_Interface::INSERT_IGNORE); + $write->query($query); + + return $this; + } + + /** + * Retrieve condition for retrieve indexable attribute select + * the catalog/eav_attribute table must have alias is ca + * + * @return string + */ + protected function _getIndexableAttributesCondition() + { + $conditions = array( + 'ca.is_filterable_in_search > 0', + 'ca.is_visible_in_advanced_search > 0', + 'ca.is_filterable > 0' + ); + + return implode(' OR ', $conditions); + } + + /** + * Remove index data from index by attribute id + * + * @param int $attributeId + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + */ + protected function _removeAttributeIndexData($attributeId) + { + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + try { + $where = $adapter->quoteInto('attribute_id = ?', $attributeId); + $adapter->delete($this->getMainTable(), $where); + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + + return $this; + } + + /** + * Synchronize temporary index table with index table by attribute id + * + * @param int $attributeId + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract + * @throws Exception + */ + protected function _synchronizeAttributeIndexData($attributeId) + { + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + try { + // remove index by attribute + $where = $adapter->quoteInto('attribute_id = ?', $attributeId); + $adapter->delete($this->getMainTable(), $where); + + // insert new index + $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); + + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Decimal.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Decimal.php new file mode 100755 index 0000000000..5fe0f2c3e9 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Decimal.php @@ -0,0 +1,145 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Eav_Decimal + extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract +{ + /** + * Initialize connection and define main index table + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_eav_decimal', 'entity_id'); + } + + /** + * Prepare data index for indexable attributes + * + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Decimal + */ + protected function _prepareIndex($entityIds = null, $attributeId = null) + { + $write = $this->_getWriteAdapter(); + $idxTable = $this->getIdxTable(); + // prepare select attributes + if (is_null($attributeId)) { + $attrIds = $this->_getIndexableAttributes(); + } else { + $attrIds = array($attributeId); + } + + if (!$attrIds) { + return $this; + } + + $productValueExpression = $write->getCheckSql('pds.value_id > 0', 'pds.value', 'pdd.value'); + $select = $write->select() + ->from( + array('pdd' => $this->getValueTable('catalog/product', 'decimal')), + array('entity_id', 'attribute_id')) + ->join( + array('cs' => $this->getTable('core/store')), + '', + array('store_id')) + ->joinLeft( + array('pds' => $this->getValueTable('catalog/product', 'decimal')), + 'pds.entity_id = pdd.entity_id AND pds.attribute_id = pdd.attribute_id' + . ' AND pds.store_id=cs.store_id', + array('value' => $productValueExpression)) + ->where('pdd.store_id=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) + ->where('cs.store_id!=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) + ->where('pdd.attribute_id IN(?)', $attrIds) + ->where("{$productValueExpression} IS NOT NULL"); + + $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'pdd.entity_id', 'cs.store_id', $statusCond); + + if (!is_null($entityIds)) { + $select->where('pdd.entity_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('pdd.entity_id'), + 'website_field' => new Zend_Db_Expr('cs.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $query = $select->insertFromSelect($idxTable); + $write->query($query); + + return $this; + } + + /** + * Retrieve decimal indexable attributes + * + * @return array + */ + protected function _getIndexableAttributes() + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from(array('ca' => $this->getTable('catalog/eav_attribute')), 'attribute_id') + ->join( + array('ea' => $this->getTable('eav/attribute')), + 'ca.attribute_id = ea.attribute_id', + array()) + ->where('ea.attribute_code != ?', 'price') + ->where($this->_getIndexableAttributesCondition()) + ->where('ea.backend_type=?', 'decimal'); + + return $adapter->fetchCol($select); + } + + /** + * Retrieve temporary decimal index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_eav_decimal_indexer_idx'); + } + return $this->getTable('catalog/product_eav_decimal_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Source.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Source.php new file mode 100755 index 0000000000..e3cd627844 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Source.php @@ -0,0 +1,293 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source + extends Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract +{ + /** + * Initialize connection and define main index table + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_eav', 'entity_id'); + } + + /** + * Retrieve indexable eav attribute ids + * + * @param bool $multiSelect + * @return array + */ + protected function _getIndexableAttributes($multiSelect) + { + $select = $this->_getReadAdapter()->select() + ->from(array('ca' => $this->getTable('catalog/eav_attribute')), 'attribute_id') + ->join( + array('ea' => $this->getTable('eav/attribute')), + 'ca.attribute_id = ea.attribute_id', + array()) + ->where($this->_getIndexableAttributesCondition()); + + if ($multiSelect == true) { + $select->where('ea.backend_type = ?', 'varchar') + ->where('ea.frontend_input = ?', 'multiselect'); + } else { + $select->where('ea.backend_type = ?', 'int') + ->where('ea.frontend_input = ?', 'select'); + } + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Prepare data index for indexable attributes + * + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source + */ + protected function _prepareIndex($entityIds = null, $attributeId = null) + { + $this->_prepareSelectIndex($entityIds, $attributeId); + $this->_prepareMultiselectIndex($entityIds, $attributeId); + + return $this; + } + + /** + * Prepare data index for indexable select attributes + * + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source + */ + protected function _prepareSelectIndex($entityIds = null, $attributeId = null) + { + $adapter = $this->_getWriteAdapter(); + $idxTable = $this->getIdxTable(); + // prepare select attributes + if (is_null($attributeId)) { + $attrIds = $this->_getIndexableAttributes(false); + } else { + $attrIds = array($attributeId); + } + + if (!$attrIds) { + return $this; + } + + /**@var $subSelect Varien_Db_Select*/ + $subSelect = $adapter->select() + ->from( + array('s' => $this->getTable('core/store')), + array('store_id', 'website_id') + ) + ->joinLeft( + array('d' => $this->getValueTable('catalog/product', 'int')), + '1 = 1 AND d.store_id = 0', + array('entity_id', 'attribute_id', 'value') + ) + ->where('s.store_id != 0'); + + /**@var $select Varien_Db_Select*/ + $select = $adapter->select() + ->from( + array('pid' => new Zend_Db_Expr(sprintf('(%s)',$subSelect->assemble()))), + array() + ) + ->joinLeft( + array('pis' => $this->getValueTable('catalog/product', 'int')), + 'pis.entity_id = pid.entity_id AND pis.attribute_id = pid.attribute_id AND pis.store_id = pid.store_id', + array() + ) + ->columns( + array( + 'pid.entity_id', + 'pid.attribute_id', + 'pid.store_id', + 'value' => $adapter->getIfNullSql('pis.value', 'pid.value') + ) + ) + ->where('pid.attribute_id IN(?)', $attrIds); + + $select->where(Mage::getResourceHelper('catalog')->getIsNullNotNullCondition('pis.value', 'pid.value')); + + if (!is_null($entityIds)) { + $select->where('pid.entity_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('pid.entity_id'), + 'website_field' => new Zend_Db_Expr('pid.website_id'), + 'store_field' => new Zend_Db_Expr('pid.store_id') + )); + + $query = $select->insertFromSelect($idxTable); + $adapter->query($query); + + return $this; + } + + /** + * Prepare data index for indexable multiply select attributes + * + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source + */ + protected function _prepareMultiselectIndex($entityIds = null, $attributeId = null) + { + $adapter = $this->_getWriteAdapter(); + + // prepare multiselect attributes + if (is_null($attributeId)) { + $attrIds = $this->_getIndexableAttributes(true); + } else { + $attrIds = array($attributeId); + } + + if (!$attrIds) { + return $this; + } + + // load attribute options + $options = array(); + $select = $adapter->select() + ->from($this->getTable('eav/attribute_option'), array('attribute_id', 'option_id')) + ->where('attribute_id IN(?)', $attrIds); + $query = $select->query(); + while ($row = $query->fetch()) { + $options[$row['attribute_id']][$row['option_id']] = true; + } + + // prepare get multiselect values query + $productValueExpression = $adapter->getCheckSql('pvs.value_id > 0', 'pvs.value', 'pvd.value'); + $select = $adapter->select() + ->from( + array('pvd' => $this->getValueTable('catalog/product', 'varchar')), + array('entity_id', 'attribute_id')) + ->join( + array('cs' => $this->getTable('core/store')), + '', + array('store_id')) + ->joinLeft( + array('pvs' => $this->getValueTable('catalog/product', 'varchar')), + 'pvs.entity_id = pvd.entity_id AND pvs.attribute_id = pvd.attribute_id' + . ' AND pvs.store_id=cs.store_id', + array('value' => $productValueExpression)) + ->where('pvd.store_id=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) + ->where('cs.store_id!=?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) + ->where('pvd.attribute_id IN(?)', $attrIds); + + $statusCond = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'pvd.entity_id', 'cs.store_id', $statusCond); + + if (!is_null($entityIds)) { + $select->where('pvd.entity_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('pvd.entity_id'), + 'website_field' => new Zend_Db_Expr('cs.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $i = 0; + $data = array(); + $query = $select->query(); + while ($row = $query->fetch()) { + $values = explode(',', $row['value']); + foreach ($values as $valueId) { + if (isset($options[$row['attribute_id']][$valueId])) { + $data[] = array( + $row['entity_id'], + $row['attribute_id'], + $row['store_id'], + $valueId + ); + $i ++; + if ($i % 10000 == 0) { + $this->_saveIndexData($data); + $data = array(); + } + } + } + } + + $this->_saveIndexData($data); + unset($options); + unset($data); + + return $this; + } + + /** + * Save a data to temporary source index table + * + * @param array $data + * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source + */ + protected function _saveIndexData(array $data) + { + if (!$data) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $adapter->insertArray($this->getIdxTable(), array('entity_id', 'attribute_id', 'store_id', 'value'), $data); + return $this; + } + + /** + * Retrieve temporary source index table name + * + * @param unknown_type $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_eav_indexer_idx'); + } + return $this->getTable('catalog/product_eav_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price.php new file mode 100755 index 0000000000..4c112ddf6d --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price.php @@ -0,0 +1,555 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Price extends Mage_Index_Model_Resource_Abstract +{ + /** + * Default Product Type Price indexer resource model + * + * @var string + */ + protected $_defaultPriceIndexer = 'catalog/product_indexer_price_default'; + + /** + * Product Type Price indexer resource models + * + * @var array + */ + protected $_indexers; + + /** + * Define main index table + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_price', 'entity_id'); + } + + /** + * Retrieve parent ids and types by child id + * Return array with key product_id and value as product type id + * + * @param int $childId + * @return array + */ + public function getProductParentsByChild($childId) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from(array('l' => $this->getTable('catalog/product_relation')), array('parent_id')) + ->join( + array('e' => $this->getTable('catalog/product')), + 'l.parent_id = e.entity_id', + array('e.type_id')) + ->where('l.child_id = ?', $childId); + + return $write->fetchPairs($select); + } + + /** + * Process produce delete + * If the deleted product was found in a composite product(s) update it + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + public function catalogProductDelete(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_price_parent_ids'])) { + return $this; + } + + $this->clearTemporaryIndexTable(); + + $processIds = array_keys($data['reindex_price_parent_ids']); + $parentIds = array(); + foreach ($data['reindex_price_parent_ids'] as $parentId => $parentType) { + $parentIds[$parentType][$parentId] = $parentId; + } + + $this->_copyRelationIndexData($processIds); + foreach ($parentIds as $parentType => $entityIds) { + $this->_getIndexer($parentType)->reindexEntity($entityIds); + } + + $this->_copyIndexDataToMainTable($parentIds); + + return $this; + } + + /** + * Copy data from temporary index table to main table by defined ids + * + * @param array $processIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + * @throws Exception + */ + protected function _copyIndexDataToMainTable($processIds) + { + $write = $this->_getWriteAdapter(); + $write->beginTransaction(); + try { + // remove old index + $where = $write->quoteInto('entity_id IN(?)', $processIds); + $write->delete($this->getMainTable(), $where); + + // remove additional data from index + $where = $write->quoteInto('entity_id NOT IN(?)', $processIds); + $write->delete($this->getIdxTable(), $where); + + // insert new index + $this->useDisableKeys(false); + $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); + $this->useDisableKeys(true); + + $this->commit(); + } catch (Exception $e) { + $this->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Process product save. + * Method is responsible for index support + * when product was saved and changed attribute(s) has an effect on price. + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + public function catalogProductSave(Mage_Index_Model_Event $event) + { + $productId = $event->getEntityPk(); + $data = $event->getNewData(); + + /** + * Check if price attribute values were updated + */ + if (!isset($data['reindex_price'])) { + return $this; + } + + $this->clearTemporaryIndexTable(); + $this->_prepareWebsiteDateTable(); + + $indexer = $this->_getIndexer($data['product_type_id']); + $processIds = array($productId); + if ($indexer->getIsComposite()) { + $this->_copyRelationIndexData($productId); + $this->_prepareTierPriceIndex($productId); + $indexer->reindexEntity($productId); + } else { + $parentIds = $this->getProductParentsByChild($productId); + + if ($parentIds) { + $processIds = array_merge($processIds, array_keys($parentIds)); + $this->_copyRelationIndexData(array_keys($parentIds), $productId); + $this->_prepareTierPriceIndex($processIds); + $indexer->reindexEntity($productId); + + $parentByType = array(); + foreach ($parentIds as $parentId => $parentType) { + $parentByType[$parentType][$parentId] = $parentId; + } + + foreach ($parentByType as $parentType => $entityIds) { + $this->_getIndexer($parentType)->reindexEntity($entityIds); + } + } else { + $this->_prepareTierPriceIndex($productId); + $indexer->reindexEntity($productId); + } + } + + $this->_copyIndexDataToMainTable($processIds); + + return $this; + } + + /** + * Process product mass update action + * + * @param Mage_Index_Model_Event $event + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + public function catalogProductMassAction(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_price_product_ids'])) { + return $this; + } + + $processIds = $data['reindex_price_product_ids']; + + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/product'), 'COUNT(*)'); + $pCount = $write->fetchOne($select); + + // if affected more 30% of all products - run reindex all products + if ($pCount * 0.3 < count($processIds)) { + return $this->reindexAll(); + } + + // calculate relations + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)') + ->where('child_id IN(?)', $processIds); + $aCount = $write->fetchOne($select); + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)') + ->where('parent_id IN(?)', $processIds); + $bCount = $write->fetchOne($select); + + // if affected with relations more 30% of all products - run reindex all products + if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) { + return $this->reindexAll(); + } + $this->reindexProductIds($processIds); + return $this; + } + + /** + * Reindex product prices for specified product ids + * + * @param array | int $ids + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + public function reindexProductIds($ids) + { + if (empty($ids)) { + return $this; + } + if (!is_array($ids)) { + $ids = array($ids); + } + $this->clearTemporaryIndexTable(); + $write = $this->_getWriteAdapter(); + // retrieve products types + $select = $write->select() + ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) + ->where('entity_id IN(?)', $ids); + $pairs = $write->fetchPairs($select); + $byType = array(); + foreach ($pairs as $productId => $productType) { + $byType[$productType][$productId] = $productId; + } + + $compositeIds = array(); + $notCompositeIds = array(); + + foreach ($byType as $productType => $entityIds) { + $indexer = $this->_getIndexer($productType); + if ($indexer->getIsComposite()) { + $compositeIds += $entityIds; + } else { + $notCompositeIds += $entityIds; + } + } + + if (!empty($notCompositeIds)) { + $select = $write->select() + ->from( + array('l' => $this->getTable('catalog/product_relation')), + 'parent_id') + ->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = l.parent_id', + array('type_id')) + ->where('l.child_id IN(?)', $notCompositeIds); + $pairs = $write->fetchPairs($select); + foreach ($pairs as $productId => $productType) { + if (!in_array($productId, $ids)) { + $ids[] = $productId; + $byType[$productType][$productId] = $productId; + $compositeIds[$productId] = $productId; + } + } + } + + if (!empty($compositeIds)) { + $this->_copyRelationIndexData($compositeIds, $notCompositeIds); + } + + $indexers = $this->getTypeIndexers(); + foreach ($indexers as $indexer) { + if (!empty($byType[$indexer->getTypeId()])) { + $indexer->reindexEntity($byType[$indexer->getTypeId()]); + } + } + + $this->_copyIndexDataToMainTable($ids); + return $this; + } + + /** + * Retrieve Price indexer by Product Type + * + * @param string $productTypeId + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Interface + * @throws Mage_Core_Exception + */ + protected function _getIndexer($productTypeId) + { + $types = $this->getTypeIndexers(); + if (!isset($types[$productTypeId])) { + Mage::throwException(Mage::helper('catalog')->__('Unsupported product type "%s".', $productTypeId)); + } + return $types[$productTypeId]; + } + + /** + * Retrieve price indexers per product type + * + * @return array + */ + public function getTypeIndexers() + { + if (is_null($this->_indexers)) { + $this->_indexers = array(); + $types = Mage::getSingleton('catalog/product_type')->getTypesByPriority(); + foreach ($types as $typeId => $typeInfo) { + if (isset($typeInfo['price_indexer'])) { + $modelName = $typeInfo['price_indexer']; + } else { + $modelName = $this->_defaultPriceIndexer; + } + $isComposite = !empty($typeInfo['composite']); + $indexer = Mage::getResourceModel($modelName) + ->setTypeId($typeId) + ->setIsComposite($isComposite); + + $this->_indexers[$typeId] = $indexer; + } + } + + return $this->_indexers; + } + + /** + * Rebuild all index data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->clearTemporaryIndexTable(); + $this->_prepareWebsiteDateTable(); + $this->_prepareTierPriceIndex(); + + $indexers = $this->getTypeIndexers(); + foreach ($indexers as $indexer) { + /** @var $indexer Mage_Catalog_Model_Resource_Product_Indexer_Price_Interface */ + $indexer->reindexAll(); + } + + $this->syncData(); + return $this; + } + + /** + * Retrieve table name for product tier price index + * + * @return string + */ + protected function _getTierPriceIndexTable() + { + return $this->getTable('catalog/product_index_tier_price'); + } + + /** + * Prepare tier price index table + * + * @param int|array $entityIds the entity ids limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + protected function _prepareTierPriceIndex($entityIds = null) + { + $write = $this->_getWriteAdapter(); + $table = $this->_getTierPriceIndexTable(); + $write->delete($table); + + $websiteExpression = $write->getCheckSql('tp.website_id = 0', 'ROUND(tp.value * cwd.rate, 4)', 'tp.value'); + $select = $write->select() + ->from( + array('tp' => $this->getValueTable('catalog/product', 'tier_price')), + array('entity_id')) + ->join( + array('cg' => $this->getTable('customer/customer_group')), + 'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)', + array('customer_group_id')) + ->join( + array('cw' => $this->getTable('core/website')), + 'tp.website_id = 0 OR tp.website_id = cw.website_id', + array('website_id')) + ->join( + array('cwd' => $this->_getWebsiteDateTable()), + 'cw.website_id = cwd.website_id', + array()) + ->where('cw.website_id != 0') + ->columns(new Zend_Db_Expr("MIN({$websiteExpression})")) + ->group(array('tp.entity_id', 'cg.customer_group_id', 'cw.website_id')); + + if (!empty($entityIds)) { + $select->where('tp.entity_id IN(?)', $entityIds); + } + + $query = $select->insertFromSelect($table); + $write->query($query); + + return $this; + } + + /** + * Copy relations product index from primary index to temporary index table by parent entity + * + * @package array|int $excludeIds + * + * @param array|int $parentIds + * @param unknown_type $excludeIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + protected function _copyRelationIndexData($parentIds, $excludeIds = null) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), array('child_id')) + ->where('parent_id IN(?)', $parentIds); + if (!empty($excludeIds)) { + $select->where('child_id NOT IN(?)', $excludeIds); + } + + $children = $write->fetchCol($select); + + if ($children) { + $select = $write->select() + ->from($this->getMainTable()) + ->where('entity_id IN(?)', $children); + $query = $select->insertFromSelect($this->getIdxTable(), array(), false); + $write->query($query); + } + + return $this; + } + + /** + * Retrieve website current dates table name + * + * @return string + */ + protected function _getWebsiteDateTable() + { + return $this->getTable('catalog/product_index_website'); + } + + /** + * Prepare website current dates table + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price + */ + protected function _prepareWebsiteDateTable() + { + $write = $this->_getWriteAdapter(); + $baseCurrency = Mage::app()->getBaseCurrencyCode(); + + $select = $write->select() + ->from( + array('cw' => $this->getTable('core/website')), + array('website_id')) + ->join( + array('csg' => $this->getTable('core/store_group')), + 'cw.default_group_id = csg.group_id', + array('store_id' => 'default_store_id')) + ->where('cw.website_id != 0'); + + + $data = array(); + foreach ($write->fetchAll($select) as $item) { + /** @var $website Mage_Core_Model_Website */ + $website = Mage::app()->getWebsite($item['website_id']); + + if ($website->getBaseCurrencyCode() != $baseCurrency) { + $rate = Mage::getModel('directory/currency') + ->load($baseCurrency) + ->getRate($website->getBaseCurrencyCode()); + if (!$rate) { + $rate = 1; + } + } else { + $rate = 1; + } + + /** @var $store Mage_Core_Model_Store */ + $store = Mage::app()->getStore($item['store_id']); + if ($store) { + $timestamp = Mage::app()->getLocale()->storeTimeStamp($store); + $data[] = array( + 'website_id' => $website->getId(), + 'website_date' => $this->formatDate($timestamp, false), + 'rate' => $rate + ); + } + } + + $write->beginTransaction(); + $table = $this->_getWebsiteDateTable(); + $write->delete($table); + + if ($data) { + $write->insertMultiple($table, $data); + } + $write->commit(); + + return $this; + } + + /** + * Retrieve temporary index table name + * + * @param unknown_type $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_idx'); + } + return $this->getTable('catalog/product_price_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Configurable.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Configurable.php new file mode 100755 index 0000000000..25c69dfd03 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Configurable.php @@ -0,0 +1,221 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default +{ + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareFinalPriceData(); + $this->_applyCustomOption(); + $this->_applyConfigurableOption(); + $this->_movePriceDataToIndexTable(); + + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + */ + public function reindexEntity($entityIds) + { + $this->_prepareFinalPriceData($entityIds); + $this->_applyCustomOption(); + $this->_applyConfigurableOption(); + $this->_movePriceDataToIndexTable(); + + return $this; + } + + /** + * Retrieve table name for custom option temporary aggregation data + * + * @return string + */ + protected function _getConfigurableOptionAggregateTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_cfg_option_aggregate_idx'); + } + return $this->getTable('catalog/product_price_indexer_cfg_option_aggregate_tmp'); + } + + /** + * Retrieve table name for custom option prices data + * + * @return string + */ + protected function _getConfigurableOptionPriceTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_cfg_option_idx'); + } + return $this->getTable('catalog/product_price_indexer_cfg_option_tmp'); + } + + /** + * Prepare table structure for custom option temporary aggregation data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + */ + protected function _prepareConfigurableOptionAggregateTable() + { + $this->_getWriteAdapter()->delete($this->_getConfigurableOptionAggregateTable()); + return $this; + } + + /** + * Prepare table structure for custom option prices data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + */ + protected function _prepareConfigurableOptionPriceTable() + { + $this->_getWriteAdapter()->delete($this->_getConfigurableOptionPriceTable()); + return $this; + } + + /** + * Calculate minimal and maximal prices for configurable product options + * and apply it to final price + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Configurable + */ + protected function _applyConfigurableOption() + { + $write = $this->_getWriteAdapter(); + $coaTable = $this->_getConfigurableOptionAggregateTable(); + $copTable = $this->_getConfigurableOptionPriceTable(); + + $this->_prepareConfigurableOptionAggregateTable(); + $this->_prepareConfigurableOptionPriceTable(); + + $select = $write->select() + ->from(array('i' => $this->_getDefaultFinalPriceTable()), array()) + ->join( + array('l' => $this->getTable('catalog/product_super_link')), + 'l.parent_id = i.entity_id', + array('parent_id', 'product_id')) + ->columns(array('customer_group_id', 'website_id'), 'i') + ->join( + array('a' => $this->getTable('catalog/product_super_attribute')), + 'l.parent_id = a.product_id', + array()) + ->join( + array('cp' => $this->getValueTable('catalog/product', 'int')), + 'l.product_id = cp.entity_id AND cp.attribute_id = a.attribute_id AND cp.store_id = 0', + array()) + ->joinLeft( + array('apd' => $this->getTable('catalog/product_super_attribute_pricing')), + 'a.product_super_attribute_id = apd.product_super_attribute_id' + . ' AND apd.website_id = 0 AND cp.value = apd.value_index', + array()) + ->joinLeft( + array('apw' => $this->getTable('catalog/product_super_attribute_pricing')), + 'a.product_super_attribute_id = apw.product_super_attribute_id' + . ' AND apw.website_id = i.website_id AND cp.value = apw.value_index', + array()) + ->join( + array('le' => $this->getTable('catalog/product')), + 'le.entity_id = l.product_id', + array()) + + ->where('le.required_options=0') + ->group(array('l.parent_id', 'i.customer_group_id', 'i.website_id', 'l.product_id')); + + $priceExpression = $write->getCheckSql('apw.value_id IS NOT NULL', 'apw.pricing_value', 'apd.pricing_value'); + $percenExpr = $write->getCheckSql('apw.value_id IS NOT NULL', 'apw.is_percent', 'apd.is_percent'); + $roundExpr = "ROUND(i.price * ({$priceExpression} / 100), 4)"; + $roundPriceExpr = $write->getCheckSql("{$percenExpr} = 1", $roundExpr, $priceExpression); + $priceColumn = $write->getCheckSql("{$priceExpression} IS NULL", '0', $roundPriceExpr); + $priceColumn = new Zend_Db_Expr("SUM({$priceColumn})"); + + $tierPrice = $priceExpression; + $tierRoundPriceExp = $write->getCheckSql("{$percenExpr} = 1", $roundExpr, $tierPrice); + $tierPriceExp = $write->getCheckSql("{$tierPrice} IS NULL", '0', $tierRoundPriceExp); + $tierPriceColumn = $write->getCheckSql("MIN(i.tier_price) IS NOT NULL", "SUM({$tierPriceExp})", 'NULL'); + + $select->columns(array( + 'price' => $priceColumn, + 'tier_price' => $tierPriceColumn + )); + + $query = $select->insertFromSelect($coaTable); + $write->query($query); + + $select = $write->select() + ->from( + array($coaTable), + array('parent_id', 'customer_group_id', 'website_id', 'MIN(price)', 'MAX(price)', 'MIN(tier_price)')) + ->group(array('parent_id', 'customer_group_id', 'website_id')); + + $query = $select->insertFromSelect($copTable); + $write->query($query); + + $table = array('i' => $this->_getDefaultFinalPriceTable()); + $select = $write->select() + ->join( + array('io' => $copTable), + 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' + .' AND i.website_id = io.website_id', + array()); + $select->columns(array( + 'min_price' => new Zend_Db_Expr('i.min_price + io.min_price'), + 'max_price' => new Zend_Db_Expr('i.max_price + io.max_price'), + 'tier_price' => $write->getCheckSql('i.tier_price IS NOT NULL', 'i.tier_price + io.tier_price', 'NULL'), + )); + + $query = $select->crossUpdateFromSelect($table); + $write->query($query); + + if ($this->useIdxTable()) { + $write->truncateTable($coaTable); + $write->truncateTable($copTable); + } else { + $write->delete($coaTable); + $write->delete($copTable); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Default.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Default.php new file mode 100755 index 0000000000..d9f4a53f6b --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Default.php @@ -0,0 +1,579 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract + implements Mage_Catalog_Model_Resource_Product_Indexer_Price_Interface +{ + /** + * Product type code + * + * @var string + */ + protected $_typeId; + + /** + * Product Type is composite flag + * + * @var bool + */ + protected $_isComposite = false; + + /** + * Define main price index table + * + */ + protected function _construct() + { + $this->_init('catalog/product_index_price', 'entity_id'); + } + + /** + * Set Product Type code + * + * @param string $typeCode + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + public function setTypeId($typeCode) + { + $this->_typeId = $typeCode; + return $this; + } + + /** + * Retrieve Product Type Code + * + * @return string + */ + public function getTypeId() + { + if (is_null($this->_typeId)) { + Mage::throwException(Mage::helper('catalog')->__('A product type is not defined for the indexer.')); + } + return $this->_typeId; + } + + /** + * Set Product Type Composite flag + * + * @param bool $flag + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + public function setIsComposite($flag) + { + $this->_isComposite = (bool)$flag; + return $this; + } + + /** + * Check product type is composite + * + * @return bool + */ + public function getIsComposite() + { + return $this->_isComposite; + } + + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareFinalPriceData(); + $this->_applyCustomOption(); + $this->_movePriceDataToIndexTable(); + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + public function reindexEntity($entityIds) + { + $this->useDisableKeys(false); + $this->_prepareFinalPriceData($entityIds); + $this->_applyCustomOption(); + $this->_movePriceDataToIndexTable(); + $this->useDisableKeys(true); + + return $this; + } + + /** + * Retrieve final price temporary index table name + * + * @see _prepareDefaultFinalPriceTable() + * + * @return string + */ + protected function _getDefaultFinalPriceTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_final_idx'); + } + return $this->getTable('catalog/product_price_indexer_final_tmp'); + } + + /** + * Prepare final price temporary index table + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _prepareDefaultFinalPriceTable() + { + $this->_getWriteAdapter()->delete($this->_getDefaultFinalPriceTable()); + return $this; + } + + /** + * Retrieve website current dates table name + * + * @return string + */ + protected function _getWebsiteDateTable() + { + return $this->getTable('catalog/product_index_website'); + } + + /** + * Prepare products default final price in temporary index table + * + * @param int|array $entityIds the entity ids limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _prepareFinalPriceData($entityIds = null) + { + $this->_prepareDefaultFinalPriceTable(); + + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) + ->join( + array('cg' => $this->getTable('customer/customer_group')), + '', + array('customer_group_id')) + ->join( + array('cw' => $this->getTable('core/website')), + '', + array('website_id')) + ->join( + array('cwd' => $this->_getWebsiteDateTable()), + 'cw.website_id = cwd.website_id', + array()) + ->join( + array('csg' => $this->getTable('core/store_group')), + 'csg.website_id = cw.website_id AND cw.default_group_id = csg.group_id', + array()) + ->join( + array('cs' => $this->getTable('core/store')), + 'csg.default_store_id = cs.store_id AND cs.store_id != 0', + array()) + ->join( + array('pw' => $this->getTable('catalog/product_website')), + 'pw.product_id = e.entity_id AND pw.website_id = cw.website_id', + array()) + ->joinLeft( + array('tp' => $this->_getTierPriceIndexTable()), + 'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id' + . ' AND tp.customer_group_id = cg.customer_group_id', + array()) + ->where('e.type_id = ?', $this->getTypeId()); + + // add enable products limitation + $statusCond = $write->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true); + if (Mage::helper('core')->isModuleEnabled('Mage_Tax')) { + $taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id'); + } else { + $taxClassId = new Zend_Db_Expr('0'); + } + $select->columns(array('tax_class_id' => $taxClassId)); + + $price = $this->_addAttributeToSelect($select, 'price', 'e.entity_id', 'cs.store_id'); + $specialPrice = $this->_addAttributeToSelect($select, 'special_price', 'e.entity_id', 'cs.store_id'); + $specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', 'e.entity_id', 'cs.store_id'); + $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id'); + $currentDate = $write->getDatePartSql('cwd.website_date'); + + $specialFromDate = $write->getDatePartSql($specialFrom); + $specialToDate = $write->getDatePartSql($specialFrom); + + $specialFromUse = $write->getCheckSql("{$specialFromDate} <= {$currentDate}", '1', '0'); + $specialToUse = $write->getCheckSql("{$specialToDate} >= {$currentDate}", '1', '0'); + $specialFromHas = $write->getCheckSql("{$specialFrom} IS NULL", '1', "{$specialFromUse}"); + $specialToHas = $write->getCheckSql("{$specialTo} IS NULL", '1', "{$specialToUse}"); + $finalPrice = $write->getCheckSql("{$specialFromHas} > 0 AND {$specialToHas} > 0" + . " AND {$specialPrice} < {$price}", $specialPrice, $price); + + $select->columns(array( + 'orig_price' => $price, + 'price' => $finalPrice, + 'min_price' => $finalPrice, + 'max_price' => $finalPrice, + 'tier_price' => new Zend_Db_Expr('tp.min_price'), + 'base_tier' => new Zend_Db_Expr('tp.min_price'), + )); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('e.entity_id'), + 'website_field' => new Zend_Db_Expr('cw.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), array(), false); + $write->query($query); + + /** + * Add possibility modify prices from external events + */ + $select = $write->select() + ->join(array('wd' => $this->_getWebsiteDateTable()), + 'i.website_id = wd.website_id', + array()); + Mage::dispatchEvent('prepare_catalog_product_price_index_table', array( + 'index_table' => array('i' => $this->_getDefaultFinalPriceTable()), + 'select' => $select, + 'entity_id' => 'i.entity_id', + 'customer_group_id' => 'i.customer_group_id', + 'website_id' => 'i.website_id', + 'website_date' => 'wd.website_date', + 'update_fields' => array('price', 'min_price', 'max_price') + )); + + return $this; + } + + /** + * Retrieve table name for custom option temporary aggregation data + * + * @return string + */ + protected function _getCustomOptionAggregateTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_option_aggregate_idx'); + } + return $this->getTable('catalog/product_price_indexer_option_aggregate_idx'); + } + + /** + * Retrieve table name for custom option prices data + * + * @return string + */ + protected function _getCustomOptionPriceTable() + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_option_idx'); + } + return $this->getTable('catalog/product_price_indexer_option_tmp'); + } + + /** + * Prepare table structure for custom option temporary aggregation data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _prepareCustomOptionAggregateTable() + { + $this->_getWriteAdapter()->delete($this->_getCustomOptionAggregateTable()); + return $this; + } + + /** + * Prepare table structure for custom option prices data + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _prepareCustomOptionPriceTable() + { + $this->_getWriteAdapter()->delete($this->_getCustomOptionPriceTable()); + return $this; + } + + /** + * Apply custom option minimal and maximal price to temporary final price index table + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _applyCustomOption() + { + $write = $this->_getWriteAdapter(); + $coaTable = $this->_getCustomOptionAggregateTable(); + $copTable = $this->_getCustomOptionPriceTable(); + + $this->_prepareCustomOptionAggregateTable(); + $this->_prepareCustomOptionPriceTable(); + + $select = $write->select() + ->from( + array('i' => $this->_getDefaultFinalPriceTable()), + array('entity_id', 'customer_group_id', 'website_id')) + ->join( + array('cw' => $this->getTable('core/website')), + 'cw.website_id = i.website_id', + array()) + ->join( + array('csg' => $this->getTable('core/store_group')), + 'csg.group_id = cw.default_group_id', + array()) + ->join( + array('cs' => $this->getTable('core/store')), + 'cs.store_id = csg.default_store_id', + array()) + ->join( + array('o' => $this->getTable('catalog/product_option')), + 'o.product_id = i.entity_id', + array('option_id')) + ->join( + array('ot' => $this->getTable('catalog/product_option_type_value')), + 'ot.option_id = o.option_id', + array()) + ->join( + array('otpd' => $this->getTable('catalog/product_option_type_price')), + 'otpd.option_type_id = ot.option_type_id AND otpd.store_id = 0', + array()) + ->joinLeft( + array('otps' => $this->getTable('catalog/product_option_type_price')), + 'otps.option_type_id = otpd.option_type_id AND otpd.store_id = cs.store_id', + array()) + ->group(array('i.entity_id', 'i.customer_group_id', 'i.website_id', 'o.option_id')); + + $optPriceType = $write->getCheckSql('otps.option_type_price_id > 0', 'otps.price_type', 'otpd.price_type'); + $optPriceValue = $write->getCheckSql('otps.option_type_price_id > 0', 'otps.price', 'otpd.price'); + $minPriceRound = new Zend_Db_Expr("ROUND(i.price * ({$optPriceValue} / 100), 4)"); + $minPriceExpr = $write->getCheckSql("{$optPriceType} = 'fixed'", $optPriceValue, $minPriceRound); + $minPriceMin = new Zend_Db_Expr("MIN({$minPriceExpr})"); + $minPrice = $write->getCheckSql("MIN(o.is_require) = 1", $minPriceMin, '0'); + + $tierPriceRound = new Zend_Db_Expr("ROUND(i.base_tier * ({$optPriceValue} / 100), 4)"); + $tierPriceExpr = $write->getCheckSql("{$optPriceType} = 'fixed'", $optPriceValue, $tierPriceRound); + $tierPriceMin = new Zend_Db_Expr("MIN($tierPriceExpr)"); + $tierPriceValue = $write->getCheckSql("MIN(o.is_require) > 0", $tierPriceMin, 0); + $tierPrice = $write->getCheckSql("MIN(i.base_tier) IS NOT NULL", $tierPriceValue, "NULL"); + + $maxPriceRound = new Zend_Db_Expr("ROUND(i.price * ({$optPriceValue} / 100), 4)"); + $maxPriceExpr = $write->getCheckSql("{$optPriceType} = 'fixed'", $optPriceValue, $maxPriceRound); + //$tierPriceMin = new Zend_Db_Expr("MIN($tierPriceExpr)"); + $maxPrice = $write->getCheckSql("(MIN(o.type)='radio' OR MIN(o.type)='drop_down')", + "MAX($maxPriceExpr)", "SUM($maxPriceExpr)"); + + $select->columns(array( + 'min_price' => $minPrice, + 'max_price' => $maxPrice, + 'tier_price' => $tierPrice + )); + + $query = $select->insertFromSelect($coaTable); + $write->query($query); + + $select = $write->select() + ->from( + array('i' => $this->_getDefaultFinalPriceTable()), + array('entity_id', 'customer_group_id', 'website_id')) + ->join( + array('cw' => $this->getTable('core/website')), + 'cw.website_id = i.website_id', + array()) + ->join( + array('csg' => $this->getTable('core/store_group')), + 'csg.group_id = cw.default_group_id', + array()) + ->join( + array('cs' => $this->getTable('core/store')), + 'cs.store_id = csg.default_store_id', + array()) + ->join( + array('o' => $this->getTable('catalog/product_option')), + 'o.product_id = i.entity_id', + array('option_id')) + ->join( + array('opd' => $this->getTable('catalog/product_option_price')), + 'opd.option_id = o.option_id AND opd.store_id = 0', + array()) + ->joinLeft( + array('ops' => $this->getTable('catalog/product_option_price')), + 'ops.option_id = opd.option_id AND ops.store_id = cs.store_id', + array()); + + $optPriceType = $write->getCheckSql('ops.option_price_id > 0', 'ops.price_type', 'opd.price_type'); + $optPriceValue = $write->getCheckSql('ops.option_price_id > 0', 'ops.price', 'opd.price'); + + $minPriceRound = new Zend_Db_Expr("ROUND(i.price * ({$optPriceValue} / 100), 4)"); + $priceExpr = $write->getCheckSql("{$optPriceType} = 'fixed'", $optPriceValue, $minPriceRound); + $minPrice = $write->getCheckSql("{$priceExpr} > 0 AND o.is_require > 1", $priceExpr, 0); + + $maxPrice = $priceExpr; + + $tierPriceRound = new Zend_Db_Expr("ROUND(i.base_tier * ({$optPriceValue} / 100), 4)"); + $tierPriceExpr = $write->getCheckSql("{$optPriceType} = 'fixed'", $optPriceValue, $tierPriceRound); + $tierPriceValue = $write->getCheckSql("{$tierPriceExpr} > 0 AND o.is_require > 0", $tierPriceExpr, 0); + $tierPrice = $write->getCheckSql("i.base_tier IS NOT NULL", $tierPriceValue, "NULL"); + + $select->columns(array( + 'min_price' => $minPrice, + 'max_price' => $maxPrice, + 'tier_price' => $tierPrice + )); + + $query = $select->insertFromSelect($coaTable); + $write->query($query); + + $select = $write->select() + ->from( + array($coaTable), + array( + 'entity_id', + 'customer_group_id', + 'website_id', + 'min_price' => 'SUM(min_price)', + 'max_price' => 'SUM(max_price)', + 'tier_price' => 'SUM(tier_price)', + )) + ->group(array('entity_id', 'customer_group_id', 'website_id')); + $query = $select->insertFromSelect($copTable); + $write->query($query); + + $table = array('i' => $this->_getDefaultFinalPriceTable()); + $select = $write->select() + ->join( + array('io' => $copTable), + 'i.entity_id = io.entity_id AND i.customer_group_id = io.customer_group_id' + .' AND i.website_id = io.website_id', + array()); + $select->columns(array( + 'min_price' => new Zend_Db_Expr('i.min_price + io.min_price'), + 'max_price' => new Zend_Db_Expr('i.max_price + io.max_price'), + 'tier_price' => $write->getCheckSql('i.tier_price IS NOT NULL', 'i.tier_price + io.tier_price', 'NULL'), + )); + $query = $select->crossUpdateFromSelect($table); + $write->query($query); + + if ($this->useIdxTable()) { + $write->truncateTable($coaTable); + $write->truncateTable($copTable); + } else { + $write->delete($coaTable); + $write->delete($copTable); + } + + return $this; + } + + /** + * Mode Final Prices index to primary temporary index table + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Default + */ + protected function _movePriceDataToIndexTable() + { + $columns = array( + 'entity_id' => 'entity_id', + 'customer_group_id' => 'customer_group_id', + 'website_id' => 'website_id', + 'tax_class_id' => 'tax_class_id', + 'price' => 'orig_price', + 'final_price' => 'price', + 'min_price' => 'min_price', + 'max_price' => 'max_price', + 'tier_price' => 'tier_price' + ); + + $write = $this->_getWriteAdapter(); + $table = $this->_getDefaultFinalPriceTable(); + $select = $write->select() + ->from($table, $columns); + + $query = $select->insertFromSelect($this->getIdxTable(), array(), false); + $write->query($query); + + if ($this->useIdxTable()) { + $write->truncateTable($table); + } else { + $write->delete($table); + } + + return $this; + } + + /** + * Retrieve table name for product tier price index + * + * @return string + */ + protected function _getTierPriceIndexTable() + { + return $this->getTable('catalog/product_index_tier_price'); + } + + /** + * Register data required by product type process in event object + * + * @param Mage_Index_Model_Event $event + */ + public function registerEvent(Mage_Index_Model_Event $event) + { + + } + + /** + * Retrieve temporary index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('catalog/product_price_indexer_idx'); + } + return $this->getTable('catalog/product_price_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Grouped.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Grouped.php new file mode 100755 index 0000000000..484947ec9a --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Grouped.php @@ -0,0 +1,128 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped + extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default +{ + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareGroupedProductPriceData(); + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped + */ + public function reindexEntity($entityIds) + { + $this->_prepareGroupedProductPriceData($entityIds); + + return $this; + } + + /** + * Calculate minimal and maximal prices for Grouped products + * Use calculated price for relation products + * + * @param int|array $entityIds the parent entity ids limitation + * @return Mage_Catalog_Model_Resource_Product_Indexer_Price_Grouped + */ + protected function _prepareGroupedProductPriceData($entityIds = null) + { + $write = $this->_getWriteAdapter(); + $table = $this->getIdxTable(); + + $select = $write->select() + ->from(array('e' => $this->getTable('catalog/product')), 'entity_id') + ->joinLeft( + array('l' => $this->getTable('catalog/product_link')), + 'e.entity_id = l.product_id AND l.link_type_id=' . Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, + array()) + ->join( + array('cg' => $this->getTable('customer/customer_group')), + '', + array('customer_group_id')); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $minCheckSql = $write->getCheckSql('le.required_options = 0', 'i.min_price', 0); + $maxCheckSql = $write->getCheckSql('le.required_options = 0', 'i.max_price', 0); + $select->columns('website_id', 'cw') + ->joinLeft( + array('le' => $this->getTable('catalog/product')), + 'le.entity_id = l.linked_product_id', + array()) + ->joinLeft( + array('i' => $table), + 'i.entity_id = l.linked_product_id AND i.website_id = cw.website_id' + . ' AND i.customer_group_id = cg.customer_group_id', + array( + 'tax_class_id'=> $this->_getReadAdapter()->getCheckSql('MIN(i.tax_class_id) IS NULL', '0', 'MIN(i.tax_class_id)'), + 'price' => new Zend_Db_Expr('NULL'), + 'final_price' => new Zend_Db_Expr('NULL'), + 'min_price' => new Zend_Db_Expr('MIN(' . $minCheckSql . ')'), + 'max_price' => new Zend_Db_Expr('MAX(' . $maxCheckSql . ')'), + 'tier_price' => new Zend_Db_Expr('NULL') + )) + ->group(array('e.entity_id', 'cg.customer_group_id', 'cw.website_id')) + ->where('e.type_id=?', $this->getTypeId()); + + if (!is_null($entityIds)) { + $select->where('l.product_id IN(?)', $entityIds); + } + + /** + * Add additional external limitation + */ + Mage::dispatchEvent('catalog_product_prepare_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('e.entity_id'), + 'website_field' => new Zend_Db_Expr('cw.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $query = $select->insertFromSelect($table); + $write->query($query); + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Interface.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Interface.php new file mode 100755 index 0000000000..f590e1b3b4 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Interface.php @@ -0,0 +1,59 @@ + + */ +interface Mage_Catalog_Model_Resource_Product_Indexer_Price_Interface +{ + /** + * Reindex temporary (price result data) for all products + * + */ + public function reindexAll() +; + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + */ + public function reindexEntity($entityIds) +; + + /** + * Register data required by product type process in event object + * + * @param Mage_Index_Model_Event $event + */ + public function registerEvent(Mage_Index_Model_Event $event) +; +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Link.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Link.php new file mode 100755 index 0000000000..adf3a329e8 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Link.php @@ -0,0 +1,279 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Link extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Product Link Attributes Table + * + * @var string + */ + protected $_attributesTable; + + /** + * Define main table name and attributes table + */ + protected function _construct() + { + $this->_init('catalog/product_link', 'link_id'); + $this->_attributesTable = $this->getTable('catalog/product_link_attribute'); + } + + /** + * Save Product Links process + * + * @param Mage_Catalog_Model_Product $product + * @param array $data + * @param int $typeId + * @return Mage_Catalog_Model_Resource_Product_Link + */ + public function saveProductLinks($product, $data, $typeId) + { + if (!is_array($data)) { + $data = array(); + } + + $attributes = $this->getAttributesByType($typeId); + $adapter = $this->_getWriteAdapter(); + + $bind = array( + ':product_id' => (int)$product->getId(), + ':link_type_id' => (int)$typeId + ); + $select = $adapter->select() + ->from($this->getMainTable(), array('linked_product_id', 'link_id')) + ->where('product_id = :product_id') + ->where('link_type_id = :link_type_id'); + + $links = $adapter->fetchPairs($select, $bind); + + $deleteIds = array(); + foreach($links as $linkedProductId => $linkId) { + if (!isset($data[$linkedProductId])) { + $deleteIds[] = (int)$linkId; + } + } + if (!empty($deleteIds)) { + $adapter->delete($this->getMainTable(), array( + 'link_id IN (?)' => $deleteIds, + )); + } + + foreach ($data as $linkedProductId => $linkInfo) { + $linkId = null; + if (isset($links[$linkedProductId])) { + $linkId = $links[$linkedProductId]; + unset($links[$linkedProductId]); + } else { + $bind = array( + 'product_id' => $product->getId(), + 'linked_product_id' => $linkedProductId, + 'link_type_id' => $typeId + ); + $adapter->insert($this->getMainTable(), $bind); + $linkId = $adapter->lastInsertId($this->getMainTable()); + } + + foreach ($attributes as $attributeInfo) { + $attributeTable = $this->getAttributeTypeTable($attributeInfo['type']); + if ($attributeTable) { + if (isset($linkInfo[$attributeInfo['code']])) { + $value = $this->_prepareAttributeValue($attributeInfo['type'], + $linkInfo[$attributeInfo['code']]); + $bind = array( + 'product_link_attribute_id' => $attributeInfo['id'], + 'link_id' => $linkId, + 'value' => $value + ); + $adapter->insertOnDuplicate($attributeTable, $bind, array('value')); + } else { + $adapter->delete($attributeTable, array( + 'link_id = ?' => $linkId, + 'product_link_attribute_id = ?' => $attributeInfo['id'] + )); + } + } + } + } + + return $this; + } + + /** + * Prepare link attribute value by attribute type + * + * @param string $type + * @param mixed $value + * @return mixed + */ + protected function _prepareAttributeValue($type, $value) + { + if ($type == 'int') { + $value = (int)$value; + } elseif ($type == 'decimal') { + $value = (float)sprintf('%F', $value); + } + return $value; + } + + /** + * Retrieve product link attributes by link type + * + * @param int $typeId + * @return array + */ + public function getAttributesByType($typeId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->_attributesTable, array( + 'id' => 'product_link_attribute_id', + 'code' => 'product_link_attribute_code', + 'type' => 'data_type' + )) + ->where('link_type_id = ?', $typeId); + return $adapter->fetchAll($select); + } + + /** + * Returns table for link attribute by attribute type + * + * @param string $type + * @return string + */ + public function getAttributeTypeTable($type) + { + return $this->getTable('catalog/product_link_attribute_' . $type); + } + + /** + * Retrieve Required children ids + * Return grouped array, ex array( + * group => array(ids) + * ) + * + * @param int $parentId + * @param int $typeId + * @return array + */ + public function getChildrenIds($parentId, $typeId) + { + $adapter = $this->_getReadAdapter(); + $childrenIds = array(); + $bind = array( + ':product_id' => (int)$parentId, + ':link_type_id' => (int)$typeId + ); + $select = $adapter->select() + ->from(array('l' => $this->getMainTable()), array('linked_product_id')) + ->where('product_id = :product_id') + ->where('link_type_id = :link_type_id'); + if ($typeId == Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED) { + $select->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = l.linked_product_id AND e.required_options = 0', + array() + ); + } + + $childrenIds[$typeId] = array(); + $result = $adapter->fetchAll($select, $bind); + foreach ($result as $row) { + $childrenIds[$typeId][$row['linked_product_id']] = $row['linked_product_id']; + } + + return $childrenIds; + } + + /** + * Retrieve parent ids array by required child + * + * @param int|array $childId + * @param int $typeId + * @return array + */ + public function getParentIdsByChild($childId, $typeId) + { + $parentIds = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('product_id', 'linked_product_id')) + ->where('linked_product_id IN(?)', $childId) + ->where('link_type_id = ?', $typeId); + + $result = $adapter->fetchAll($select); + foreach ($result as $row) { + $parentIds[] = $row['product_id']; + } + + return $parentIds; + } + + /** + * Save grouped product relations + * + * @param Mage_Catalog_Model_Product $product + * @param array $data + * @param int $typeId + * @return Mage_Catalog_Model_Resource_Product_Link + */ + public function saveGroupedLinks($product, $data, $typeId) + { + $adapter = $this->_getWriteAdapter(); + // check for change relations + $bind = array( + 'product_id' => (int)$product->getId(), + 'link_type_id' => (int)$typeId + ); + $select = $adapter->select() + ->from($this->getMainTable(), array('linked_product_id')) + ->where('product_id = :product_id') + ->where('link_type_id = :link_type_id'); + $old = $adapter->fetchCol($select, $bind); + $new = array_keys($data); + + if (array_diff($old, $new) || array_diff($new, $old)) { + $product->setIsRelationsChanged(true); + } + + // save product links attributes + $this->saveProductLinks($product, $data, $typeId); + + // Grouped product relations should be added to relation table + Mage::getResourceSingleton('catalog/product_relation') + ->processRelations($product->getId(), $new); + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Collection.php new file mode 100755 index 0000000000..97ad1ab3b7 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Collection.php @@ -0,0 +1,166 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Link_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Product object + * + * @var Mage_Catalog_Model_Product + */ + protected $_product; + + /** + * Product Link model class + * + * @var Mage_Catalog_Model_Product_Link + */ + protected $_linkModel; + + /** + * Product Link Type identifier + * + * @var Mage_Catalog_Model_Product_Type + */ + protected $_linkTypeId; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('catalog/product_link'); + } + + /** + * Declare link model and initialize type attributes join + * + * @param Mage_Catalog_Model_Product_Link $linkModel + * @return Mage_Catalog_Model_Resource_Product_Link_Collection + */ + public function setLinkModel(Mage_Catalog_Model_Product_Link $linkModel) + { + $this->_linkModel = $linkModel; + if ($linkModel->hasLinkTypeId()) { + $this->_linkTypeId = $linkModel->getLinkTypeId(); + } + return $this; + } + + /** + * Retrieve collection link model + * + * @return Mage_Catalog_Model_Product_Link + */ + public function getLinkModel() + { + return $this->_linkModel; + } + + /** + * Initialize collection parent product and add limitation join + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product_Link_Collection + */ + public function setProduct(Mage_Catalog_Model_Product $product) + { + $this->_product = $product; + return $this; + } + + /** + * Retrieve collection base product object + * + * @return Mage_Catalog_Model_Product + */ + public function getProduct() + { + return $this->_product; + } + + /** + * Add link's type to filter + * + * @return Mage_Catalog_Model_Resource_Product_Link_Collection + */ + public function addLinkTypeIdFilter() + { + if ($this->_linkTypeId) { + $this->addFieldToFilter('link_type_id', array('eq' => $this->_linkTypeId)); + } + return $this; + } + + /** + * Add product to filter + * + * @return Mage_Catalog_Model_Resource_Product_Link_Collection + */ + public function addProductIdFilter() + { + if ($this->getProduct() && $this->getProduct()->getId()) { + $this->addFieldToFilter('product_id', array('eq' => $this->getProduct()->getId())); + } + return $this; + } + + /** + * Join attributes + * + * @return Mage_Catalog_Model_Resource_Product_Link_Collection + */ + public function joinAttributes() + { + if (!$this->getLinkModel()) { + return $this; + } + $attributes = $this->getLinkModel()->getAttributes(); + $adapter = $this->getConnection(); + foreach ($attributes as $attribute) { + $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']); + $alias = sprintf('link_attribute_%s_%s', $attribute['code'], $attribute['type']); + + $aliasInCondition = $adapter->quoteColumnAs($alias, null); + $this->getSelect()->joinLeft( + array($alias => $table), + $aliasInCondition . '.link_id = main_table.link_id AND ' + . $aliasInCondition . '.product_link_attribute_id = ' . (int) $attribute['id'], + array($attribute['code'] => 'value') + ); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Product/Collection.php new file mode 100755 index 0000000000..79a3a29511 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Link/Product/Collection.php @@ -0,0 +1,296 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Link_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Store product model + * + * @var Mage_Catalog_Model_Product + */ + protected $_product; + + /** + * Store product link model + * + * @var Mage_Catalog_Model_Product_Link + */ + protected $_linkModel; + + /** + * Store link type id + * + * @var int + */ + protected $_linkTypeId; + + /** + * Store strong mode flag that determine if needed for inner join or left join of linked products + * + * @var bool + */ + protected $_isStrongMode; + + /** + * Store flag that determine if product filter was enabled + * + * @var bool + */ + protected $_hasLinkFilter = false; + + /** + * Declare link model and initialize type attributes join + * + * @param Mage_Catalog_Model_Product_Link $linkModel + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setLinkModel(Mage_Catalog_Model_Product_Link $linkModel) + { + $this->_linkModel = $linkModel; + if ($linkModel->getLinkTypeId()) { + $this->_linkTypeId = $linkModel->getLinkTypeId(); + } + return $this; + } + + /** + * Enable strong mode for inner join of linked products + * + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setIsStrongMode() + { + $this->_isStrongMode = true; + return $this; + } + + /** + * Retrieve collection link model + * + * @return Mage_Catalog_Model_Product_Link + */ + public function getLinkModel() + { + return $this->_linkModel; + } + + /** + * Initialize collection parent product and add limitation join + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setProduct(Mage_Catalog_Model_Product $product) + { + $this->_product = $product; + if ($product && $product->getId()) { + $this->_hasLinkFilter = true; + } + return $this; + } + + /** + * Retrieve collection base product object + * + * @return Mage_Catalog_Model_Product + */ + public function getProduct() + { + return $this->_product; + } + + /** + * Exclude products from filter + * + * @param array $products + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function addExcludeProductFilter($products) + { + if (!empty($products)) { + if (!is_array($products)) { + $products = array($products); + } + $this->_hasLinkFilter = true; + $this->getSelect()->where('links.linked_product_id NOT IN (?)', $products); + } + return $this; + } + + /** + * Add products to filter + * + * @param array|int|string $products + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function addProductFilter($products) + { + if (!empty($products)) { + if (!is_array($products)) { + $products = array($products); + } + $this->getSelect()->where('links.product_id IN (?)', $products); + $this->_hasLinkFilter = true; + } + + return $this; + } + + /** + * Add random sorting order + * + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setRandomOrder() + { + $this->getSelect()->orderRand('main_table.entity_id'); + return $this; + } + + /** + * Setting group by to exclude duplications in collection + * + * @param string $groupBy + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setGroupBy($groupBy = 'e.entity_id') + { + $this->getSelect()->group($groupBy); + + /* + * Allow Analytic functions usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Join linked products when specified link model + * + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + protected function _beforeLoad() + { + if ($this->getLinkModel()) { + $this->_joinLinks(); + } + return parent::_beforeLoad(); + } + + /** + * Join linked products and their attributes + * + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + protected function _joinLinks() + { + $select = $this->getSelect(); + $adapter = $select->getAdapter(); + + $joinCondition = array( + 'links.linked_product_id = e.entity_id', + $adapter->quoteInto('links.link_type_id = ?', $this->_linkTypeId) + ); + $joinType = 'join'; + if ($this->getProduct() && $this->getProduct()->getId()) { + $productId = $this->getProduct()->getId(); + if ($this->_isStrongMode) { + $this->getSelect()->where('links.product_id = ?', (int)$productId); + } else { + $joinType = 'joinLeft'; + $joinCondition[] = $adapter->quoteInto('links.product_id = ?', $productId); + } + $this->addFieldToFilter('entity_id', array('neq' => $productId)); + } else if ($this->_isStrongMode) { + $this->addFieldToFilter('entity_id', array('eq' => -1)); + } + if($this->_hasLinkFilter) { + $select->$joinType( + array('links' => $this->getTable('catalog/product_link')), + implode(' AND ', $joinCondition), + array('link_id') + ); + $this->joinAttributes(); + } + return $this; + } + + + + /** + * Enable sorting products by its position + * + * @param string $dir sort type asc|desc + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function setPositionOrder($dir = self::SORT_ORDER_ASC) + { + if ($this->_hasLinkFilter) { + $this->getSelect()->order('position ' . $dir); + } + return $this; + } + + /** + * Join attributes + * + * @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection + */ + public function joinAttributes() + { + if (!$this->getLinkModel()) { + return $this; + } + $attributes = $this->getLinkModel()->getAttributes(); + + $attributesByType = array(); + foreach ($attributes as $attribute) { + $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']); + $alias = sprintf('link_attribute_%s_%s', $attribute['code'], $attribute['type']); + + $joinCondiotion = array( + "{$alias}.link_id = links.link_id", + $this->getSelect()->getAdapter()->quoteInto("{$alias}.product_link_attribute_id = ?", $attribute['id']) + ); + $this->getSelect()->joinLeft( + array($alias => $table), + implode(' AND ', $joinCondiotion), + array($attribute['code'] => 'value') + ); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Option.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Option.php new file mode 100755 index 0000000000..1d1fc3e160 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Option.php @@ -0,0 +1,511 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and initialize connection + * + */ + protected function _construct() + { + $this->_init('catalog/product_option', 'option_id'); + } + + /** + * Save options store data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $this->_saveValuePrices($object); + $this->_saveValueTitles($object); + + return parent::_afterSave($object); + } + + /** + * Save value prices + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Product_Option + */ + protected function _saveValuePrices(Mage_Core_Model_Abstract $object) + { + $priceTable = $this->getTable('catalog/product_option_price'); + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + /* + * Better to check param 'price' and 'price_type' for saving. + * If there is not price skip saving price + */ + + if ($object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FIELD + || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_AREA + || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE + || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE + || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME + || $object->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME + ) { + //save for store_id = 0 + if (!$object->getData('scope', 'price')) { + $statement = $readAdapter->select() + ->from($priceTable, 'option_id') + ->where('option_id = ?', $object->getId()) + ->where('store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + $optionId = $readAdapter->fetchOne($statement); + + if ($optionId) { + if ($object->getStoreId() == '0') { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'price' => $object->getPrice(), + 'price_type' => $object->getPriceType()) + ), + $priceTable + ); + + $writeAdapter->update( + $priceTable, + $data, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + ) + ); + } + } else { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'option_id' => $object->getId(), + 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + 'price' => $object->getPrice(), + 'price_type' => $object->getPriceType() + ) + ), + $priceTable + ); + $writeAdapter->insert($priceTable, $data); + } + } + + $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); + + if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE + && !$object->getData('scope', 'price')) { + + $baseCurrency = Mage::app()->getBaseCurrencyCode(); + + $storeIds = Mage::app()->getStore($object->getStoreId())->getWebsite()->getStoreIds(); + if (is_array($storeIds)) { + foreach ($storeIds as $storeId) { + if ($object->getPriceType() == 'fixed') { + $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); + $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); + if (!$rate) { + $rate=1; + } + $newPrice = $object->getPrice() * $rate; + } else { + $newPrice = $object->getPrice(); + } + + $statement = $readAdapter->select() + ->from($priceTable) + ->where('option_id = ?', $object->getId()) + ->where('store_id = ?', $storeId); + + if ($readAdapter->fetchOne($statement)) { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'price' => $newPrice, + 'price_type' => $object->getPriceType() + ) + ), + $priceTable + ); + + $writeAdapter->update( + $priceTable, + $data, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => $storeId + ) + ); + } else { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'option_id' => $object->getId(), + 'store_id' => $storeId, + 'price' => $newPrice, + 'price_type' => $object->getPriceType() + ) + ), + $priceTable + ); + $writeAdapter->insert($priceTable, $data); + } + }// end foreach() + } + } elseif ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) { + $writeAdapter->delete( + $priceTable, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => $object->getStoreId() + ) + ); + } + } + + return $this; + } + + /** + * Save titles + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Catalog_Model_Resource_Product_Option + */ + protected function _saveValueTitles(Mage_Core_Model_Abstract $object) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + $titleTable = $this->getTable('catalog/product_option_title'); + + //title + if (!$object->getData('scope', 'title')) { + $statement = $readAdapter->select() + ->from($titleTable) + ->where('option_id = ?', $object->getId()) + ->where('store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + if ($readAdapter->fetchOne($statement)) { + if ($object->getStoreId() == '0') { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'title' => $object->getTitle() + ) + ), + $titleTable + ); + + $writeAdapter->update( + $titleTable, + $data, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID + ) + ); + } + } else { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'option_id' => $object->getId(), + 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + 'title' => $object->getTitle() + ) + ), + $titleTable + ); + + $writeAdapter->insert($titleTable, $data); + } + } + + if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) { + $statement = $readAdapter->select() + ->from($titleTable) + ->where('option_id = ?', $object->getId()) + ->where('store_id = ?', $object->getStoreId()); + + if ($readAdapter->fetchOne($statement)) { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'title' => $object->getTitle() + ) + ), + $titleTable + ); + + $writeAdapter->update( + $titleTable, + $data, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => $object->getStoreId() + ) + ); + } else { + $data = $this->_prepareDataForTable( + new Varien_Object( + array( + 'option_id' => $object->getId(), + 'store_id' => $object->getStoreId(), + 'title' => $object->getTitle() + ) + ), + $titleTable + ); + $writeAdapter->insert($titleTable, $data); + } + } elseif ($object->getData('scope', 'title')) { + $writeAdapter->delete( + $titleTable, + array( + 'option_id = ?' => $object->getId(), + 'store_id = ?' => $object->getStoreId() + ) + ); + } + } + + /** + * Delete prices + * + * @param int $optionId + * @return Mage_Catalog_Model_Resource_Product_Option + */ + public function deletePrices($optionId) + { + $this->_getWriteAdapter()->delete( + $this->getTable('catalog/product_option_price'), + array( + 'option_id = ?' => $optionId + ) + ); + + return $this; + } + + /** + * Delete titles + * + * @param int $optionId + * @return Mage_Catalog_Model_Resource_Product_Option + */ + public function deleteTitles($optionId) + { + $this->_getWriteAdapter()->delete( + $this->getTable('catalog/product_option_title'), + array( + 'option_id = ?' => $optionId + ) + ); + + return $this; + } + + /** + * Duplicate custom options for product + * + * @param Mage_Catalog_Model_Product_Option $object + * @param int $oldProductId + * @param int $newProductId + * @return Mage_Catalog_Model_Product_Option + */ + public function duplicate(Mage_Catalog_Model_Product_Option $object, $oldProductId, $newProductId) + { + $write = $this->_getWriteAdapter(); + $read = $this->_getReadAdapter(); + + $optionsCond = array(); + $optionsData = array(); + + // read and prepare original product options + $select = $read->select() + ->from($this->getTable('catalog/product_option')) + ->where('product_id = ?', $oldProductId); + + $query = $read->query($select); + + while ($row = $query->fetch()) { + $optionsData[$row['option_id']] = $row; + $optionsData[$row['option_id']]['product_id'] = $newProductId; + unset($optionsData[$row['option_id']]['option_id']); + } + + // insert options to duplicated product + foreach ($optionsData as $oId => $data) { + $write->insert($this->getMainTable(), $data); + $optionsCond[$oId] = $write->lastInsertId($this->getMainTable()); + } + + // copy options prefs + foreach ($optionsCond as $oldOptionId => $newOptionId) { + // title + $table = $this->getTable('catalog/product_option_title'); + + $select = $this->_getReadAdapter()->select() + ->from($table, array(new Zend_Db_Expr($newOptionId), 'store_id', 'title')) + ->where('option_id = ?', $oldOptionId); + + $insertSelect = $write->insertFromSelect( + $select, + $table, + array('option_id', 'store_id', 'title'), + Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE + ); + $write->query($insertSelect); + + // price + $table = $this->getTable('catalog/product_option_price'); + + $select = $read->select() + ->from($table, array(new Zend_Db_Expr($newOptionId), 'store_id', 'price', 'price_type')) + ->where('option_id = ?', $oldOptionId); + + $insertSelect = $write->insertFromSelect( + $select, $table, + array( + 'option_id', + 'store_id', + 'price', + 'price_type' + ), + Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE + ); + $write->query($insertSelect); + + $object->getValueInstance()->duplicate($oldOptionId, $newOptionId); + } + + return $object; + } + + /** + * Retrieve option searchable data + * + * @param int $productId + * @param int $storeId + * @return array + */ + public function getSearchableData($productId, $storeId) + { + $searchData = array(); + + $adapter = $this->_getReadAdapter(); + + $titleCheckSql = $adapter->getCheckSql( + 'option_title_store.title IS NULL', + 'option_title_default.title', + 'option_title_store.title' + ); + + + // retrieve options title + + $defaultOptionJoin = implode( + ' AND ', + array('option_title_default.option_id=option.option_id', + $adapter->quoteInto('option_title_default.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)) + ); + + $storeOptionJoin = implode( + ' AND ', + array( + 'option_title_store.option_id=option.option_id', + $adapter->quoteInto('option_title_store.store_id = ?', (int) $storeId)) + ); + + $select = $adapter->select() + ->from(array('option' => $this->getMainTable()), null) + ->join( + array('option_title_default' => $this->getTable('catalog/product_option_title')), + $defaultOptionJoin, + array() + ) + ->joinLeft( + array('option_title_store' => $this->getTable('catalog/product_option_title')), + $storeOptionJoin, + array('title' => $titleCheckSql) + ) + ->where('option.product_id = ?', $productId); + + if ($titles = $adapter->fetchCol($select)) { + $searchData = array_merge($searchData, $titles); + } + + //select option type titles + + $defaultOptionJoin = implode( + ' AND ', array( + 'option_title_default.option_type_id=option_type.option_type_id', + $adapter->quoteInto('option_title_default.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID)) + ); + + $storeOptionJoin = implode( + ' AND ', array( + 'option_title_store.option_type_id = option_type.option_type_id', + $adapter->quoteInto('option_title_store.store_id = ?', (int) $storeId)) + ); + + $select = $adapter->select() + ->from(array('option' => $this->getMainTable()), null) + ->join( + array('option_type' => $this->getTable('catalog/product_option_type_value')), + 'option_type.option_id=option.option_id', + array() + ) + ->join( + array('option_title_default' => $this->getTable('catalog/product_option_type_title')), + $defaultOptionJoin, + array() + ) + ->joinLeft( + array('option_title_store' => $this->getTable('catalog/product_option_type_title')), + $storeOptionJoin, + array('title' => $titleCheckSql) + ) + ->where('option.product_id = ?', $productId); + + if ($titles = $adapter->fetchCol($select)) { + $searchData = array_merge($searchData, $titles); + } + + return $searchData; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Collection.php new file mode 100755 index 0000000000..985b497f19 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Collection.php @@ -0,0 +1,197 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('catalog/product_option'); + } + + /** + * Adds title, price & price_type attributes to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function getOptions($storeId) + { + $this->addPriceToResult($storeId) + ->addTitleToResult($storeId); + + return $this; + } + + /** + * Add title to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function addTitleToResult($storeId) + { + $productOptionTitleTable = $this->getTable('catalog/product_option_title'); + $adapter = $this->getConnection(); + $titleExpr = $adapter->getCheckSql('store_option_title.title IS NULL', 'default_option_title.title', 'store_option_title.title'); + + $this->getSelect() + ->join(array('default_option_title' => $productOptionTitleTable), + 'default_option_title.option_id = main_table.option_id', + array('default_title' => 'title')) + ->joinLeft(array('store_option_title' => $productOptionTitleTable), + 'store_option_title.option_id = main_table.option_id AND ' . $adapter->quoteInto('store_option_title.store_id = ?', $storeId), + array( + 'store_title' => 'title', + 'title' => $titleExpr + )) + ->where('default_option_title.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + return $this; + } + + /** + * Add price to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function addPriceToResult($storeId) + { + $productOptionPriceTable = $this->getTable('catalog/product_option_price'); + $adapter = $this->getConnection(); + $priceExpr = $adapter->getCheckSql('store_option_price.price IS NULL', 'default_option_price.price', 'store_option_price.price'); + $priceTypeExpr = $adapter->getCheckSql('store_option_price.price_type IS NULL', 'default_option_price.price_type', 'store_option_price.price_type'); + + $this->getSelect() + ->joinLeft(array('default_option_price' => $productOptionPriceTable), + 'default_option_price.option_id = main_table.option_id AND ' . $adapter->quoteInto('default_option_price.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID), + array( + 'default_price' => 'price', + 'default_price_type' => 'price_type' + )) + ->joinLeft(array('store_option_price' => $productOptionPriceTable), + 'store_option_price.option_id = main_table.option_id AND ' . $adapter->quoteInto('store_option_price.store_id = ?', $storeId), + array( + 'store_price' => 'price', + 'store_price_type' => 'price_type', + 'price' => $priceExpr, + 'price_type' => $priceTypeExpr + )); + + return $this; + } + + /** + * Add value to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function addValuesToResult($storeId = null) + { + if ($storeId === null) { + $storeId = Mage::app()->getStore()->getId(); + } + $optionIds = array(); + foreach ($this as $option) { + $optionIds[] = $option->getId(); + } + if (!empty($optionIds)) { + /** @var $values Mage_Catalog_Model_Option_Value_Collection */ + $values = Mage::getModel('catalog/product_option_value') + ->getCollection() + ->addTitleToResult($storeId) + ->addPriceToResult($storeId) + ->addOptionToFilter($optionIds) + ->setOrder('sort_order', self::SORT_ORDER_ASC) + ->setOrder('title', self::SORT_ORDER_ASC); + + foreach ($values as $value) { + $optionId = $value->getOptionId(); + if($this->getItemById($optionId)) { + $this->getItemById($optionId)->addValue($value); + $value->setOption($this->getItemById($optionId)); + } + } + } + + return $this; + } + + /** + * Add product_id filter to select + * + * @param array|Mage_Catalog_Model_Product|int $product + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function addProductToFilter($product) + { + if (empty($product)) { + $this->addFieldToFilter('product_id', ''); + } elseif (is_array($product)) { + $this->addFieldToFilter('product_id', array('in' => $product)); + } elseif ($product instanceof Mage_Catalog_Model_Product) { + $this->addFieldToFilter('product_id', $product->getId()); + } else { + $this->addFieldToFilter('product_id', $product); + } + + return $this; + } + + /** + * Add filtering by option ids + * + * @param mixed $optionIds + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Collection + */ + public function addIdsToFilter($optionIds) + { + $this->addFieldToFilter('main_table.option_id', $optionIds); + return $this; + } + + /** + * Call of protected method reset + * + * @return Mage_Catalog_Model_Resource_Product_Option_Collection + */ + public function reset() + { + return $this->_reset(); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value.php new file mode 100755 index 0000000000..e89a84e722 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value.php @@ -0,0 +1,350 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Option_Value extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and initialize connection + * + */ + protected function _construct() + { + $this->_init('catalog/product_option_type_value', 'option_type_id'); + } + + + /** + * Proceeed operations after object is saved + * Save options store data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $this->_saveValuePrices($object); + $this->_saveValueTitles($object); + + return parent::_afterSave($object); + } + + /** + * Save option value price data + * + * @param Mage_Core_Model_Abstract $object + */ + protected function _saveValuePrices(Mage_Core_Model_Abstract $object) + { + $priceTable = $this->getTable('catalog/product_option_type_price'); + + $price = (float)sprintf('%F', $object->getPrice()); + $priceType = $object->getPriceType(); + + if (!$object->getData('scope', 'price')) { + //save for store_id = 0 + $select = $this->_getReadAdapter()->select() + ->from($priceTable, 'option_type_id') + ->where('option_type_id = ?', (int)$object->getId()) + ->where('store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + $optionTypeId = $this->_getReadAdapter()->fetchOne($select); + + if ($optionTypeId) { + if ($object->getStoreId() == '0') { + $bind = array( + 'price' => $price, + 'price_type' => $priceType + ); + $where = array( + 'option_type_id = ?' => $optionTypeId, + 'store_id = ?' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID + ); + + $this->_getWriteAdapter()->update($priceTable, $bind, $where); + } + } else { + $bind = array( + 'option_type_id' => (int)$object->getId(), + 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + 'price' => $price, + 'price_type' => $priceType + ); + $this->_getWriteAdapter()->insert($priceTable, $bind); + } + } + + $scope = (int)Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); + + if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE + && !$object->getData('scope', 'price')) { + + $baseCurrency = Mage::app()->getBaseCurrencyCode(); + + $storeIds = $object->getProduct()->getStoreIds(); + if (is_array($storeIds)) { + foreach ($storeIds as $storeId) { + if ($priceType == 'fixed') { + $storeCurrency = Mage::app()->getStore($storeId)->getBaseCurrencyCode(); + $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($storeCurrency); + if (!$rate) { + $rate = 1; + } + $newPrice = $price * $rate; + } else { + $newPrice = $price; + } + + $select = $this->_getReadAdapter()->select() + ->from($priceTable, 'option_type_id') + ->where('option_type_id = ?', (int)$object->getId()) + ->where('store_id = ?', (int)$storeId); + $optionTypeId = $this->_getReadAdapter()->fetchOne($select); + + if ($optionTypeId) { + $bind = array( + 'price' => $newPrice, + 'price_type' => $priceType + ); + $where = array( + 'option_type_id = ?' => (int)$optionTypeId, + 'store_id = ?' => (int)$storeId + ); + + $this->_getWriteAdapter()->update($priceTable, $bind, $where); + } else { + $bind = array( + 'option_type_id' => (int)$object->getId(), + 'store_id' => (int)$storeId, + 'price' => $newPrice, + 'price_type' => $priceType + ); + + $this->_getWriteAdapter()->insert($priceTable, $bind); + } + }// end of foreach() + } + } else if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) { + $where = array( + 'option_type_id = ?' => (int)$object->getId(), + 'store_id = ?' => (int)$object->getStoreId(), + ); + $this->_getWriteAdapter()->delete($priceTable, $where); + } + + } + + + /** + * Save option value title data + * + * @param Mage_Core_Model_Abstract $object + */ + protected function _saveValueTitles(Mage_Core_Model_Abstract $object) + { + $titleTable = $this->getTable('catalog/product_option_type_title'); + + if (!$object->getData('scope', 'title')) { + $select = $this->_getReadAdapter()->select() + ->from($titleTable) + ->where('option_type_id = ?', (int)$object->getId()) + ->where('store_id = ?', 0); + $optionTypeId = $this->_getReadAdapter()->fetchOne($select); + + if ($optionTypeId) { + if ($object->getStoreId() == '0') { + $where = array( + 'option_type_id = ?' => (int)$optionTypeId, + 'store_id = ?' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID + ); + $bind = array( + 'title' => $object->getTitle() + ); + $this->_getWriteAdapter()->update($titleTable, $bind, $where); + } + } else { + $bind = array( + 'option_type_id' => (int)$object->getId(), + 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, + 'title' => $object->getTitle() + ); + $this->_getWriteAdapter()->insert($titleTable, $bind); + } + } + + if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) { + $select = $this->_getReadAdapter()->select() + ->from($titleTable) + ->where('option_type_id = ?', (int)$object->getId()) + ->where('store_id = ?', (int)$object->getStoreId()); + $optionTypeId = $this->_getReadAdapter()->fetchOne($select); + + if ($optionTypeId) { + $bind = array( + 'title' => $object->getTitle() + ); + $where = array( + 'option_type_id = ?' => (int)$optionTypeId, + 'store_id = ?' => (int)$object->getStoreId() + ); + $this->_getWriteAdapter()->update($titleTable, $bind, $where); + } else { + $bind = array( + 'option_type_id' => (int)$object->getId(), + 'store_id' => (int)$object->getStoreId(), + 'title' => $object->getTitle() + ); + $this->_getWriteAdapter()->insert($titleTable, $bind); + } + } else if ($object->getData('scope', 'title')) { + $where = array( + 'option_type_id = ?' => (int)$optionTypeId, + 'store_id = ?' => (int)$object->getStoreId() + ); + $this->_getWriteAdapter()->delete($titleTable, $where); + } + } + + + /** + * Delete values by option id + * + * @param int $optionId + * @return Mage_Catalog_Model_Resource_Product_Option_Value + */ + public function deleteValue($optionId) + { + $statement = $this->_getReadAdapter()->select() + ->from($this->getTable('catalog/product_option_type_value')) + ->where('option_id = ?', $optionId); + + $rowSet = $this->_getReadAdapter()->fetchAll($statement); + + foreach ($rowSet as $optionType) { + $this->deleteValues($optionType['option_type_id']); + } + + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + array( + 'option_id = ?' => $optionId, + ) + ); + + return $this; + } + + /** + * Delete values by option type + * + * @param int $optionTypeId + */ + public function deleteValues($optionTypeId) + { + $condition = array( + 'option_type_id = ?' => $optionTypeId + ); + + $this->_getWriteAdapter()->delete( + $this->getTable('catalog/product_option_type_price'), + $condition + ); + + $this->_getWriteAdapter()->delete( + $this->getTable('catalog/product_option_type_title'), + $condition + ); + } + + /** + * Duplicate product options value + * + * @param Mage_Catalog_Model_Product_Option_Value $object + * @param int $oldOptionId + * @param int $newOptionId + * @return Mage_Catalog_Model_Product_Option_Value + */ + public function duplicate(Mage_Catalog_Model_Product_Option_Value $object, $oldOptionId, $newOptionId) + { + $writeAdapter = $this->_getWriteAdapter(); + $readAdapter = $this->_getReadAdapter(); + $select = $readAdapter->select() + ->from($this->getMainTable()) + ->where('option_id = ?', $oldOptionId); + $valueData = $readAdapter->fetchAll($select); + + $valueCond = array(); + + foreach ($valueData as $data) { + $optionTypeId = $data[$this->getIdFieldName()]; + unset($data[$this->getIdFieldName()]); + $data['option_id'] = $newOptionId; + + $writeAdapter->insert($this->getMainTable(), $data); + $valueCond[$optionTypeId] = $writeAdapter->lastInsertId($this->getMainTable()); + } + + unset($valueData); + + foreach ($valueCond as $oldTypeId => $newTypeId) { + // price + $priceTable = $this->getTable('catalog/product_option_type_price'); + $columns= array( + new Zend_Db_Expr($newTypeId), + 'store_id', 'price', 'price_type' + ); + + $select = $readAdapter->select() + ->from($priceTable, array()) + ->where('option_type_id = ?', $oldTypeId) + ->columns($columns); + $insertSelect = $writeAdapter->insertFromSelect($select, $priceTable, array('option_type_id', 'store_id', 'price', 'price_type')); + $writeAdapter->query($insertSelect); + + // title + $titleTable = $this->getTable('catalog/product_option_type_title'); + $columns= array( + new Zend_Db_Expr($newTypeId), + 'store_id', 'title' + ); + + $select = $this->_getReadAdapter()->select() + ->from($titleTable, array()) + ->where('option_type_id = ?', $oldTypeId) + ->columns($columns); + $insertSelect = $writeAdapter->insertFromSelect($select, $titleTable, array('option_type_id', 'store_id', 'title')); + $writeAdapter->query($insertSelect); + } + + return $object; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value/Collection.php new file mode 100755 index 0000000000..6226d30823 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Value/Collection.php @@ -0,0 +1,242 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Option_Value_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('catalog/product_option_value'); + } + + /** + * Add price, title to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function getValues($storeId) + { + $this->addPriceToResult($storeId) + ->addTitleToResult($storeId); + + return $this; + } + + /** + * Add titles to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function addTitlesToResult($storeId) + { + $adapter = $this->getConnection(); + $optionTypePriceTable = $this->getTable('catalog/product_option_type_price'); + $optionTitleTable = $this->getTable('catalog/product_option_type_title'); + $priceExpr = $adapter->getCheckSql( + 'store_value_price.price IS NULL', + 'default_value_price.price', + 'store_value_price.price' + ); + $priceTypeExpr = $adapter->getCheckSql( + 'store_value_price.price_type IS NULL', + 'default_value_price.price_type', + 'store_value_price.price_type' + ); + $titleExpr = $adapter->getCheckSql( + 'store_value_title.title IS NULL', + 'default_value_title.title', + 'store_value_title.title' + ); + $joinExprDefaultPrice = 'default_value_price.option_type_id = main_table.option_type_id AND ' + . $adapter->quoteInto('default_value_price.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + $joinExprStorePrice = 'store_value_price.option_type_id = main_table.option_type_id AND ' + . $adapter->quoteInto('store_value_price.store_id = ?', $storeId); + + $joinExprTitle = 'store_value_title.option_type_id = main_table.option_type_id AND ' + . $adapter->quoteInto('store_value_title.store_id = ?', $storeId); + + $this->getSelect() + ->joinLeft( + array('default_value_price' => $optionTypePriceTable), + $joinExprDefaultPrice, + array('default_price'=>'price','default_price_type'=>'price_type') + ) + ->joinLeft( + array('store_value_price' => $optionTypePriceTable), + $joinExprStorePrice, + array( + 'store_price' => 'price', + 'store_price_type' => 'price_type', + 'price' => $priceExpr, + 'price_type' => $priceTypeExpr + ) + ) + ->join( + array('default_value_title' => $optionTitleTable), + 'default_value_title.option_type_id = main_table.option_type_id', + array('default_title' => 'title') + ) + ->joinLeft( + array('store_value_title' => $optionTitleTable), + $joinExprTitle, + array( + 'store_title' => 'title', + 'title' => $titleExpr) + ) + ->where('default_value_title.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + return $this; + } + + /** + * Add title result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function addTitleToResult($storeId) + { + $optionTitleTable = $this->getTable('catalog/product_option_type_title'); + $titleExpr = $this->getConnection() + ->getCheckSql('store_value_title.title IS NULL', 'default_value_title.title', 'store_value_title.title'); + + $joinExpr = 'store_value_title.option_type_id = main_table.option_type_id AND ' + . $this->getConnection()->quoteInto('store_value_title.store_id = ?', $storeId); + $this->getSelect() + ->join( + array('default_value_title' => $optionTitleTable), + 'default_value_title.option_type_id = main_table.option_type_id', + array('default_title' => 'title') + ) + ->joinLeft( + array('store_value_title' => $optionTitleTable), + $joinExpr, + array( + 'store_title' => 'title', + 'title' => $titleExpr + ) + ) + ->where('default_value_title.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + return $this; + } + + /** + * Add price to result + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function addPriceToResult($storeId) + { + $optionTypeTable = $this->getTable('catalog/product_option_type_price'); + $priceExpr = $this->getConnection() + ->getCheckSql('store_value_price.price IS NULL', 'default_value_price.price', 'store_value_price.price'); + $priceTypeExpr = $this->getConnection() + ->getCheckSql( + 'store_value_price.price_type IS NULL', + 'default_value_price.price_type', + 'store_value_price.price_type' + ); + + $joinExprDefault = 'default_value_price.option_type_id = main_table.option_type_id AND ' + . $this->getConnection()->quoteInto('default_value_price.store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + $joinExprStore = 'store_value_price.option_type_id = main_table.option_type_id AND ' + . $this->getConnection()->quoteInto('store_value_price.store_id = ?', $storeId); + $this->getSelect() + ->joinLeft( + array('default_value_price' => $optionTypeTable), + $joinExprDefault, + array( + 'default_price' => 'price', + 'default_price_type'=>'price_type' + ) + ) + ->joinLeft( + array('store_value_price' => $optionTypeTable), + $joinExprStore, + array( + 'store_price' => 'price', + 'store_price_type' => 'price_type', + 'price' => $priceExpr, + 'price_type' => $priceTypeExpr + ) + ); + + return $this; + } + + /** + * Add option filter + * + * @param array $optionIds + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function getValuesByOption($optionIds, $storeId = null) + { + if (!is_array($optionIds)) { + $optionIds = array($optionIds); + } + + return $this->addFieldToFilter('main_table.option_type_id', array('in' => $optionIds)); + } + + /** + * Add option to filter + * + * @param array|Mage_Catalog_Model_Product_Option|int $option + * @return Mage_Catalog_Model_Resource_Product_Option_Value_Collection + */ + public function addOptionToFilter($option) + { + if (empty($option)) { + $this->addFieldToFilter('option_id', ''); + } elseif (is_array($option)) { + $this->addFieldToFilter('option_id', array('in' => $option)); + } elseif ($option instanceof Mage_Catalog_Model_Product_Option) { + $this->addFieldToFilter('option_id', $option->getId()); + } else { + $this->addFieldToFilter('option_id', $option); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Relation.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Relation.php new file mode 100755 index 0000000000..6b02d2f703 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Relation.php @@ -0,0 +1,84 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Relation extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource model and define main table + * + */ + protected function _construct() + { + $this->_init('catalog/product_relation', 'parent_id'); + } + + /** + * Save (rebuild) product relations + * + * @param int $parentId + * @param array $childIds + * @return Mage_Catalog_Model_Resource_Product_Relation + */ + public function processRelations($parentId, $childIds) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('child_id')) + ->where('parent_id = ?', $parentId); + $old = $this->_getReadAdapter()->fetchCol($select); + $new = $childIds; + + $insert = array_diff($new, $old); + $delete = array_diff($old, $new); + + if (!empty($insert)) { + $insertData = array(); + foreach ($insert as $childId) { + $insertData[] = array( + 'parent_id' => $parentId, + 'child_id' => $childId + ); + } + $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $insertData); + } + if (!empty($delete)) { + $where = join(' AND ', array( + $this->_getWriteAdapter()->quoteInto('parent_id = ?', $parentId), + $this->_getWriteAdapter()->quoteInto('child_id IN(?)', $delete) + )); + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Status.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Status.php new file mode 100755 index 0000000000..873c1afc01 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Status.php @@ -0,0 +1,214 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Status extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Product atrribute cache + * + * @var array + */ + protected $_productAttributes = array(); + + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('catalog/product_enabled_index', 'product_id'); + } + + /** + * Retrieve product attribute (public method for status model) + * + * @param string $attributeCode + * @return Mage_Catalog_Model_Resource_Eav_Attribute + */ + public function getProductAttribute($attributeCode) + { + return $this->_getProductAttribute($attributeCode); + } + + /** + * Retrieve product attribute + * + * @param unknown_type $attribute + * @return Mage_Eav_Model_Entity_Attribute_Abstract + */ + protected function _getProductAttribute($attribute) + { + if (empty($this->_productAttributes[$attribute])) { + $this->_productAttributes[$attribute] = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attribute); + } + return $this->_productAttributes[$attribute]; + } + + /** + * Refresh enabled index cache + * + * @param int $productId + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Product_Status + */ + public function refreshEnabledIndex($productId, $storeId) + { + if ($storeId == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { + foreach (Mage::app()->getStores() as $store) { + $this->refreshEnabledIndex($productId, $store->getId()); + } + + return $this; + } + + Mage::getResourceSingleton('catalog/product')->refreshEnabledIndex($storeId, $productId); + + return $this; + } + + /** + * Update product status for store + * + * @param int $productId + * @param int $storId + * @param int $value + * @return Mage_Catalog_Model_Resource_Product_Status + */ + public function updateProductStatus($productId, $storeId, $value) + { + $statusAttributeId = $this->_getProductAttribute('status')->getId(); + $statusEntityTypeId = $this->_getProductAttribute('status')->getEntityTypeId(); + $statusTable = $this->_getProductAttribute('status')->getBackend()->getTable(); + $refreshIndex = true; + $adapter = $this->_getWriteAdapter(); + + $data = new Varien_Object(array( + 'entity_type_id' => $statusEntityTypeId, + 'attribute_id' => $statusAttributeId, + 'store_id' => $storeId, + 'entity_id' => $productId, + 'value' => $value + )); + + $data = $this->_prepareDataForTable($data, $statusTable); + + $select = $adapter->select() + ->from($statusTable) + ->where('attribute_id = :attribute_id') + ->where('store_id = :store_id') + ->where('entity_id = :product_id'); + + $binds = array( + 'attribute_id' => $statusAttributeId, + 'store_id' => $storeId, + 'product_id' => $productId + ); + + $row = $adapter->fetchRow($select); + + if ($row) { + if ($row['value'] == $value) { + $refreshIndex = false; + } else { + $condition = array('value_id = ?' => $row['value_id']); + $adapter->update($statusTable, $data, $condition); + } + } else { + $adapter->insert($statusTable, $data); + } + + if ($refreshIndex) { + $this->refreshEnabledIndex($productId, $storeId); + } + + return $this; + } + + /** + * Retrieve Product(s) status for store + * Return array where key is a product_id, value - status + * + * @param array|int $productIds + * @param int $storeId + * @return array + */ + public function getProductStatus($productIds, $storeId = null) + { + $statuses = array(); + + $attribute = $this->_getProductAttribute('status'); + $attributeTable = $attribute->getBackend()->getTable(); + $adapter = $this->_getReadAdapter(); + + if (!is_array($productIds)) { + $productIds = array($productIds); + } + + if ($storeId === null || $storeId == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) { + $select = $adapter->select() + ->from($attributeTable, array('entity_id', 'value')) + ->where('entity_id IN (?)', $productIds) + ->where('attribute_id = ?', $attribute->getAttributeId()) + ->where('store_id = ?', Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); + + $rows = $adapter->fetchPairs($select); + } else { + $valueCheckSql = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + + $select = $adapter->select() + ->from( + array('t1' => $attributeTable), + array('value' => $valueCheckSql)) + ->joinLeft( + array('t2' => $attributeTable), + 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id = ' . (int)$storeId, + array('t1.entity_id') + ) + ->where('t1.store_id = ?', Mage_Core_Model_App::ADMIN_STORE_ID) + ->where('t1.attribute_id = ?', $attribute->getAttributeId()) + ->where('t1.entity_id IN(?)', $productIds); + $rows = $adapter->fetchPairs($select); + } + + foreach ($productIds as $productId) { + if (isset($rows[$productId])) { + $statuses[$productId] = $rows[$productId]; + } else { + $statuses[$productId] = -1; + } + } + + return $statuses; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable.php new file mode 100755 index 0000000000..458e2a84ea --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable.php @@ -0,0 +1,148 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Type_Configurable extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init resource + * + */ + protected function _construct() + { + $this->_init('catalog/product_super_link', 'link_id'); + } + + /** + * Save configurable product relations + * + * @param Mage_Catalog_Model_Product|int $mainProduct the parent id + * @param array $productIds the children id array + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable + */ + public function saveProducts($mainProduct, $productIds) + { + $isProductInstance = false; + if ($mainProduct instanceof Mage_Catalog_Model_Product) { + $mainProductId = $mainProduct->getId(); + $isProductInstance = true; + } else { + $mainProductId = $mainProduct; + } + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'product_id') + ->where('parent_id = ?', $mainProductId); + $old = $this->_getReadAdapter()->fetchCol($select); + + $insert = array_diff($productIds, $old); + $delete = array_diff($old, $productIds); + + if ((!empty($insert) || !empty($delete)) && $isProductInstance) { + $mainProduct->setIsRelationsChanged(true); + } + + if (!empty($delete)) { + $where = array( + 'parent_id = ?' => $mainProductId, + 'product_id IN(?)' => $delete + ); + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + } + if (!empty($insert)) { + $data = array(); + foreach ($insert as $childId) { + $data[] = array( + 'product_id' => (int)$childId, + 'parent_id' => (int)$mainProductId + ); + } + $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $data); + } + + // configurable product relations should be added to relation table + Mage::getResourceSingleton('catalog/product_relation') + ->processRelations($mainProductId, $productIds); + + return $this; + } + + /** + * Retrieve Required children ids + * Return grouped array, ex array( + * group => array(ids) + * ) + * + * @param int $parentId + * @param bool $required + * @return array + */ + public function getChildrenIds($parentId, $required = true) + { + $childrenIds = array(); + $select = $this->_getReadAdapter()->select() + ->from(array('l' => $this->getMainTable()), array('product_id', 'parent_id')) + ->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = l.product_id AND e.required_options = 0', + array() + ) + ->where('parent_id = ?', $parentId); + + $childrenIds = array(0 => array()); + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $childrenIds[0][$row['product_id']] = $row['product_id']; + } + + return $childrenIds; + } + + /** + * Retrieve parent ids array by requered child + * + * @param int|array $childId + * @return array + */ + public function getParentIdsByChild($childId) + { + $parentIds = array(); + + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('product_id', 'parent_id')) + ->where('product_id IN(?)', $childId); + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $parentIds[] = $row['parent_id']; + } + + return $parentIds; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute.php new file mode 100755 index 0000000000..23ba8222fc --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute.php @@ -0,0 +1,304 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Label table name cache + * + * @var string + */ + protected $_labelTable; + + /** + * Price table name cache + * + * @var string + */ + protected $_priceTable; + + /** + * Inititalize connection and define tables + * + */ + protected function _construct() + { + $this->_init('catalog/product_super_attribute', 'product_super_attribute_id'); + $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); + $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); + } + + /** + * Retrieve Catalog Helper + * + * @return Mage_Catalog_Helper_Data + */ + public function getCatalogHelper() + { + return Mage::helper('catalog'); + } + + /** + * Load attribute labels + * @deprecated + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute + */ + public function loadLabel($attribute) + { + return $this; + } + + /** + * Load prices + * @deprecated + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute + */ + public function loadPrices($attribute) + { + return $this; + } + + /** + * Save Custom labels for Attribute name + * + * @param Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute + */ + public function saveLabel($attribute) + { + $adapter = $this->_getWriteAdapter(); + + $select = $adapter->select() + ->from($this->_labelTable, 'value_id') + ->where('product_super_attribute_id = :product_super_attribute_id') + ->where('store_id = :store_id'); + $bind = array( + 'product_super_attribute_id' => (int)$attribute->getId(), + 'store_id' => (int)$attribute->getStoreId() + ); + $valueId = $adapter->fetchOne($select, $bind); + if ($valueId) { + $adapter->update( + $this->_labelTable, + array( + 'use_default' => (int) $attribute->getUseDefault(), + 'value' => $attribute->getLabel() + ), + $adapter->quoteInto('value_id = ?', (int) $valueId) + ); + } else { + $adapter->insert( + $this->_labelTable, + array( + 'product_super_attribute_id' => (int) $attribute->getId(), + 'store_id' => (int) $attribute->getStoreId(), + 'use_default' => (int) $attribute->getUseDefault(), + 'value' => $attribute->getLabel() + ) + ); + } + return $this; + } + + /** + * Save Options prices (Depends from price save scope) + * + * @param Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute + */ + public function savePrices($attribute) + { + $write = $this->_getWriteAdapter(); + // define website id scope + if ($this->getCatalogHelper()->isPriceGlobal()) { + $websiteId = 0; + } else { + $websiteId = (int)Mage::app()->getStore($attribute->getStoreId())->getWebsite()->getId(); + } + + $values = $attribute->getValues(); + if (!is_array($values)) { + $values = array(); + } + + $new = array(); + $old = array(); + + // retrieve old values + $select = $write->select() + ->from($this->_priceTable) + ->where('product_super_attribute_id = :product_super_attribute_id') + ->where('website_id = :website_id'); + + $bind = array( + 'product_super_attribute_id' => (int)$attribute->getId(), + 'website_id' => $websiteId + ); + $rowSet = $write->fetchAll($select, $bind); + foreach ($rowSet as $row) { + $key = implode('-', array($row['website_id'], $row['value_index'])); + if (!isset($old[$key])) { + $old[$key] = $row; + } else { + // delete invalid (duplicate row) + $where = $write->quoteInto('value_id = ?', $row['value_id']); + $write->delete($this->_priceTable, $where); + } + } + + // prepare new values + foreach ($values as $v) { + if (empty($v['value_index'])) { + continue; + } + $key = implode('-', array($websiteId, $v['value_index'])); + $new[$key] = array( + 'value_index' => $v['value_index'], + 'pricing_value' => $v['pricing_value'], + 'is_percent' => $v['is_percent'], + 'website_id' => $websiteId, + 'use_default' => !empty($v['use_default_value']) ? true : false + ); + } + + $insert = array(); + $update = array(); + $delete = array(); + + foreach ($old as $k => $v) { + if (!isset($new[$k])) { + $delete[] = $v['value_id']; + } + } + foreach ($new as $k => $v) { + $needInsert = false; + $needUpdate = false; + $needDelete = false; + + $isGlobal = true; + if (!$this->getCatalogHelper()->isPriceGlobal() && $websiteId != 0) { + $isGlobal = false; + } + + $hasValue = ($isGlobal && !empty($v['pricing_value'])) + || (!$isGlobal && !$v['use_default']); + + if (isset($old[$k])) { + // data changed + $dataChanged = ($old[$k]['is_percent'] != $v['is_percent']) + || ($old[$k]['pricing_value'] != $v['pricing_value']); + if (!$hasValue) { + $needDelete = true; + } else if ($dataChanged) { + $needUpdate = true; + } + } else if ($hasValue) { + $needInsert = true; + } + + if (!$isGlobal && empty($v['pricing_value'])) { + $v['pricing_value'] = 0; + $v['is_percent'] = 0; + } + + if ($needInsert) { + $insert[] = array( + 'product_super_attribute_id' => $attribute->getId(), + 'value_index' => $v['value_index'], + 'is_percent' => $v['is_percent'], + 'pricing_value' => $v['pricing_value'], + 'website_id' => $websiteId + ); + } + if ($needUpdate) { + $update[$old[$k]['value_id']] = array( + 'is_percent' => $v['is_percent'], + 'pricing_value' => $v['pricing_value'] + ); + } + if ($needDelete) { + $delete[] = $old[$k]['value_id']; + } + } + + if (!empty($delete)) { + $where = $write->quoteInto('value_id IN(?)', $delete); + $write->delete($this->_priceTable, $where); + } + if (!empty($update)) { + foreach ($update as $valueId => $bind) { + $where = $write->quoteInto('value_id=?', $valueId); + $write->update($this->_priceTable, $bind, $where); + } + } + if (!empty($insert)) { + $write->insertMultiple($this->_priceTable, $insert); + } + + + return $this; + } + + /** + * Retrieve Used in Configurable Products Attributes + * + * @param int $setId The specific attribute set + * @return array + */ + public function getUsedAttributes($setId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->distinct(true) + ->from(array('e' => $this->getTable('catalog/product')), null) + ->join( + array('a' => $this->getMainTable()), + 'e.entity_id = a.product_id', + array('attribute_id') + ) + ->where('e.attribute_set_id = :attribute_set_id') + ->where('e.type_id = :type_id'); + + $bind = array( + 'attribute_set_id' => $setId, + 'type_id' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, + ); + + return $adapter->fetchCol($select, $bind); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php new file mode 100755 index 0000000000..6d5ef31f89 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Attribute/Collection.php @@ -0,0 +1,311 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Configurable attributes label table name + * + * @var string + */ + protected $_labelTable; + + /** + * Configurable attributes price table name + * + * @var string + */ + protected $_priceTable; + + /** + * Product instance + * + * @var Mage_Catalog_Model_Product + */ + protected $_product; + + /** + * Initialize connection and define table names + * + */ + protected function _construct() + { + $this->_init('catalog/product_type_configurable_attribute'); + $this->_labelTable = $this->getTable('catalog/product_super_attribute_label'); + $this->_priceTable = $this->getTable('catalog/product_super_attribute_pricing'); + } + + /** + * Retrieve catalog helper + * + * @return Mage_Catalog_Helper_Data + */ + public function getHelper() + { + return Mage::helper('catalog'); + } + + /** + * Set Product filter (Configurable) + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + public function setProductFilter($product) + { + $this->_product = $product; + return $this->addFieldToFilter('product_id', $product->getId()); + } + + /** + * Set order collection by Position + * + * @param string $dir + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + public function orderByPosition($dir = self::SORT_ORDER_ASC) + { + $this->setOrder('position ', $dir); + return $this; + } + + /** + * Retrieve Store Id + * + * @return int + */ + public function getStoreId() + { + return (int)$this->_product->getStoreId(); + } + + /** + * After load collection process + * + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + Varien_Profiler::start('TTT1:'.__METHOD__); + $this->_addProductAttributes(); + Varien_Profiler::stop('TTT1:'.__METHOD__); + Varien_Profiler::start('TTT2:'.__METHOD__); + $this->_addAssociatedProductFilters(); + Varien_Profiler::stop('TTT2:'.__METHOD__); + Varien_Profiler::start('TTT3:'.__METHOD__); + $this->_loadLabels(); + Varien_Profiler::stop('TTT3:'.__METHOD__); + Varien_Profiler::start('TTT4:'.__METHOD__); + $this->_loadPrices(); + Varien_Profiler::stop('TTT4:'.__METHOD__); + return $this; + } + + /** + * Add product attributes to collection items + * + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + protected function _addProductAttributes() + { + foreach ($this->_items as $item) { + $productAttribute = $this->getProduct()->getTypeInstance(true) + ->getAttributeById($item->getAttributeId(), $this->getProduct()); + $item->setProductAttribute($productAttribute); + } + return $this; + } + + /** + * Add Associated Product Filters (From Product Type Instance) + * + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + public function _addAssociatedProductFilters() + { + $this->getProduct()->getTypeInstance(true) + ->getUsedProducts($this->getColumnValues('attribute_id'), $this->getProduct()); // Filter associated products + return $this; + } + + /** + * Load attribute labels + * + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + protected function _loadLabels() + { + if ($this->count()) { + $useDefaultCheck = $this->getConnection()->getCheckSql( + 'store.use_default IS NULL', + 'def.use_default', + 'store.use_default' + ); + + $labelCheck = $this->getConnection()->getCheckSql( + 'store.value IS NULL', + 'def.value', + 'store.value' + ); + + $select = $this->getConnection()->select() + ->from(array('def' => $this->_labelTable)) + ->joinLeft( + array('store' => $this->_labelTable), + $this->getConnection()->quoteInto('store.product_super_attribute_id = def.product_super_attribute_id AND store.store_id = ?', $this->getStoreId()), + array( + 'use_default' => $useDefaultCheck, + 'label' => $labelCheck + )) + ->where('def.product_super_attribute_id IN (?)', array_keys($this->_items)) + ->where('def.store_id = ?', 0); + + $result = $this->getConnection()->fetchAll($select); + foreach ($result as $data) { + $this->getItemById($data['product_super_attribute_id'])->setLabel($data['label']); + $this->getItemById($data['product_super_attribute_id'])->setUseDefault($data['use_default']); + } + } + return $this; + } + + /** + * Load attribute prices information + * + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection + */ + protected function _loadPrices() + { + if ($this->count()) { + $pricings = array( + 0 => array() + ); + + if ($this->getHelper()->isPriceGlobal()) { + $websiteId = 0; + } else { + $websiteId = (int)Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + $pricing[$websiteId] = array(); + } + + $select = $this->getConnection()->select() + ->from(array('price' => $this->_priceTable)) + ->where('price.product_super_attribute_id IN (?)', array_keys($this->_items)); + + if ($websiteId > 0) { + $select->where('price.website_id IN(?)', array(0, $websiteId)); + } else { + $select->where('price.website_id = ?', 0); + } + + $query = $this->getConnection()->query($select); + + while ($row = $query->fetch()) { + $pricings[(int)$row['website_id']][] = $row; + } + + $values = array(); + + foreach ($this->_items as $item) { + $productAttribute = $item->getProductAttribute(); + if (!($productAttribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract)) { + continue; + } + $options = $productAttribute->getFrontend()->getSelectOptions(); + foreach ($options as $option) { + foreach ($this->getProduct()->getTypeInstance(true)->getUsedProducts(null, $this->getProduct()) as $associatedProduct) { + if (!empty($option['value']) + && $option['value'] == $associatedProduct->getData( + $productAttribute->getAttributeCode())) { + // If option available in associated product + if (!isset($values[$item->getId() . ':' . $option['value']])) { + // If option not added, we will add it. + $values[$item->getId() . ':' . $option['value']] = array( + 'product_super_attribute_id' => $item->getId(), + 'value_index' => $option['value'], + 'label' => $option['label'], + 'default_label' => $option['label'], + 'store_label' => $option['label'], + 'is_percent' => 0, + 'pricing_value' => null, + 'use_default_value' => true + ); + } + } + } + } + } + + foreach ($pricings[0] as $pricing) { + // Addding pricing to options + $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; + if (isset($values[$valueKey])) { + $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; + $values[$valueKey]['is_percent'] = $pricing['is_percent']; + $values[$valueKey]['value_id'] = $pricing['value_id']; + $values[$valueKey]['use_default_value'] = true; + } + } + + if ($websiteId && isset($pricings[$websiteId])) { + foreach ($pricings[$websiteId] as $pricing) { + $valueKey = $pricing['product_super_attribute_id'] . ':' . $pricing['value_index']; + if (isset($values[$valueKey])) { + $values[$valueKey]['pricing_value'] = $pricing['pricing_value']; + $values[$valueKey]['is_percent'] = $pricing['is_percent']; + $values[$valueKey]['value_id'] = $pricing['value_id']; + $values[$valueKey]['use_default_value'] = false; + } + } + } + + foreach ($values as $data) { + $this->getItemById($data['product_super_attribute_id'])->addPrice($data); + } + } + return $this; + } + + /** + * Retrive product instance + * + * @return Mage_Catalog_Model_Product + */ + public function getProduct() + { + return $this->_product; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Product/Collection.php new file mode 100755 index 0000000000..fd4dd4f18c --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Type/Configurable/Product/Collection.php @@ -0,0 +1,91 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Type_Configurable_Product_Collection + extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Link table name + * + * @var string + */ + protected $_linkTable; + + /** + * Assign link table name + */ + protected function _construct() + { + parent::_construct(); + $this->_linkTable = $this->getTable('catalog/product_super_link'); + } + + /** + * Init select + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Product_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->getSelect()->join(array('link_table' => $this->_linkTable), + 'link_table.product_id = e.entity_id', + array('parent_id') + ); + + return $this; + } + + /** + * Set Product filter to result + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Catalog_Model_Resource_Product_Type_Configurable_Product_Collection + */ + public function setProductFilter($product) + { + $this->getSelect()->where('link_table.parent_id = ?', (int) $product->getId()); + return $this; + } + + /** + * Retrieve is flat enabled flag + * Return alvays false if magento run admin + * + * @return bool + */ + public function isEnabledFlat() + { + return false; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Website.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Website.php new file mode 100755 index 0000000000..b8e48ba586 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Website.php @@ -0,0 +1,159 @@ + + */ +class Mage_Catalog_Model_Resource_Product_Website extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define resource table + * + */ + protected function _construct() + { + $this->_init('catalog/product_website', 'product_id'); + } + + /** + * Get catalog product resource model + * + * @return Mage_Catalog_Model_Resource_Product + */ + protected function _getProductResource() + { + return Mage::getResourceSingleton('catalog/product'); + } + + /** + * Removes products from websites + * + * @param array $websiteIds + * @param array $productIds + * @return Mage_Catalog_Model_Resource_Product_Website + * @throws Exception + */ + public function removeProducts($websiteIds, $productIds) + { + if (!is_array($websiteIds) || !is_array($productIds) + || count($websiteIds) == 0 || count($productIds) == 0) + { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + $whereCond = array( + $adapter->quoteInto('website_id IN(?)', $websiteIds), + $adapter->quoteInto('product_id IN(?)', $productIds) + ); + $whereCond = join(' AND ', $whereCond); + + $adapter->beginTransaction(); + try { + $adapter->delete($this->getMainTable(), $whereCond); + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Add products to websites + * + * @param array $websiteIds + * @param array $productIds + * @return Mage_Catalog_Model_Resource_Product_Website + * @throws Exception + */ + public function addProducts($websiteIds, $productIds) + { + if (!is_array($websiteIds) || !is_array($productIds) + || count($websiteIds) == 0 || count($productIds) == 0) + { + return $this; + } + + $this->_getWriteAdapter()->beginTransaction(); + + // Before adding of products we should remove it old rows with same ids + $this->removeProducts($websiteIds, $productIds); + try { + foreach ($websiteIds as $websiteId) { + foreach ($productIds as $productId) { + if (!$productId) { + continue; + } + $this->_getWriteAdapter()->insert($this->getMainTable(), array( + 'product_id' => (int) $productId, + 'website_id' => (int) $websiteId + )); + } + + // Refresh product enabled index + $storeIds = Mage::app()->getWebsite($websiteId)->getStoreIds(); + foreach ($storeIds as $storeId) { + $store = Mage::app()->getStore($storeId); + $this->_getProductResource()->refreshEnabledIndex($store, $productIds); + } + } + + $this->_getWriteAdapter()->commit(); + } catch (Exception $e) { + $this->_getWriteAdapter()->rollBack(); + throw $e; + } + return $this; + } + + /** + * Retrieve product(s) website ids. + * + * @param array $productIds + * @return array + */ + public function getWebsites($productIds) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('product_id', 'website_id')) + ->where('product_id IN (?)', $productIds); + $rowset = $this->_getReadAdapter()->fetchAll($select); + + $result = array(); + foreach ($rowset as $row) { + $result[$row['product_id']][] = $row['website_id']; + } + + return $result; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Setup.php b/app/code/core/Mage/Catalog/Model/Resource/Setup.php new file mode 100755 index 0000000000..33f2a8223e --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Setup.php @@ -0,0 +1,931 @@ + + */ +class Mage_Catalog_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup +{ + /** + * Prepare catalog attribute values to save + * + * @param array $attr + * @return array + */ + protected function _prepareValues($attr) + { + $data = parent::_prepareValues($attr); + $data = array_merge($data, array( + 'frontend_input_renderer' => $this->_getValue($attr, 'input_renderer'), + 'is_global' => $this->_getValue($attr, 'global', Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL), + 'is_visible' => $this->_getValue($attr, 'visible', 1), + 'is_searchable' => $this->_getValue($attr, 'searchable', 0), + 'is_filterable' => $this->_getValue($attr, 'filterable', 0), + 'is_comparable' => $this->_getValue($attr, 'comparable', 0), + 'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0), + 'is_wysiwyg_enabled' => $this->_getValue($attr, 'wysiwyg_enabled', 0), + 'is_html_allowed_on_front' => $this->_getValue($attr, 'is_html_allowed_on_front', 0), + 'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0), + 'is_filterable_in_search' => $this->_getValue($attr, 'filterable_in_search', 0), + 'used_in_product_listing' => $this->_getValue($attr, 'used_in_product_listing', 0), + 'used_for_sort_by' => $this->_getValue($attr, 'used_for_sort_by', 0), + 'apply_to' => $this->_getValue($attr, 'apply_to'), + 'position' => $this->_getValue($attr, 'position', 0), + 'is_configurable' => $this->_getValue($attr, 'is_configurable', 1), + 'is_used_for_promo_rules' => $this->_getValue($attr, 'used_for_promo_rules', 0) + )); + return $data; + } + + /** + * Default entites and attributes + * + * @return array + */ + public function getDefaultEntities() + { + return array( + 'catalog_category' => array( + 'entity_model' => 'catalog/category', + 'attribute_model' => 'catalog/resource_eav_attribute', + 'table' => 'catalog/category', + 'additional_attribute_table' => 'catalog/eav_attribute', + 'entity_attribute_collection' => 'catalog/category_attribute_collection', + 'default_group' => 'General Information', + 'attributes' => array( + 'name' => array( + 'type' => 'varchar', + 'label' => 'Name', + 'input' => 'text', + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'is_active' => array( + 'type' => 'int', + 'label' => 'Is Active', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'url_key' => array( + 'type' => 'varchar', + 'label' => 'URL key', + 'input' => 'text', + 'backend' => 'catalog/category_attribute_backend_urlkey', + 'required' => false, + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'description' => array( + 'type' => 'text', + 'label' => 'Description', + 'input' => 'textarea', + 'required' => false, + 'sort_order' => 4, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'wysiwyg_enabled' => true, + 'is_html_allowed_on_front' => true, + 'group' => 'General Information', + ), + 'image' => array( + 'type' => 'varchar', + 'label' => 'Image', + 'input' => 'image', + 'backend' => 'catalog/category_attribute_backend_image', + 'required' => false, + 'sort_order' => 5, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'meta_title' => array( + 'type' => 'varchar', + 'label' => 'Page Title', + 'input' => 'text', + 'required' => false, + 'sort_order' => 6, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'meta_keywords' => array( + 'type' => 'text', + 'label' => 'Meta Keywords', + 'input' => 'textarea', + 'required' => false, + 'sort_order' => 7, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'meta_description' => array( + 'type' => 'text', + 'label' => 'Meta Description', + 'input' => 'textarea', + 'required' => false, + 'sort_order' => 8, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'display_mode' => array( + 'type' => 'varchar', + 'label' => 'Display Mode', + 'input' => 'select', + 'source' => 'catalog/category_attribute_source_mode', + 'required' => false, + 'sort_order' => 10, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Display Settings', + ), + 'landing_page' => array( + 'type' => 'int', + 'label' => 'CMS Block', + 'input' => 'select', + 'source' => 'catalog/category_attribute_source_page', + 'required' => false, + 'sort_order' => 20, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Display Settings', + ), + 'is_anchor' => array( + 'type' => 'int', + 'label' => 'Is Anchor', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => false, + 'sort_order' => 30, + 'group' => 'Display Settings', + ), + 'path' => array( + 'type' => 'static', + 'label' => 'Path', + 'required' => false, + 'sort_order' => 12, + 'visible' => false, + 'group' => 'General Information', + ), + 'position' => array( + 'type' => 'static', + 'label' => 'Position', + 'required' => false, + 'sort_order' => 13, + 'visible' => false, + 'group' => 'General Information', + ), + 'all_children' => array( + 'type' => 'text', + 'required' => false, + 'sort_order' => 14, + 'visible' => false, + 'group' => 'General Information', + ), + 'path_in_store' => array( + 'type' => 'text', + 'required' => false, + 'sort_order' => 15, + 'visible' => false, + 'group' => 'General Information', + ), + 'children' => array( + 'type' => 'text', + 'required' => false, + 'sort_order' => 16, + 'visible' => false, + 'group' => 'General Information', + ), + 'url_path' => array( + 'type' => 'varchar', + 'required' => false, + 'sort_order' => 17, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'group' => 'General Information', + ), + 'custom_design' => array( + 'type' => 'varchar', + 'label' => 'Custom Design', + 'input' => 'select', + 'source' => 'core/design_source_design', + 'required' => false, + 'sort_order' => 10, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'custom_design_from' => array( + 'type' => 'datetime', + 'label' => 'Active From', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 30, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'custom_design_to' => array( + 'type' => 'datetime', + 'label' => 'Active To', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 40, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'page_layout' => array( + 'type' => 'varchar', + 'label' => 'Page Layout', + 'input' => 'select', + 'source' => 'catalog/category_attribute_source_layout', + 'required' => false, + 'sort_order' => 50, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'custom_layout_update' => array( + 'type' => 'text', + 'label' => 'Custom Layout Update', + 'input' => 'textarea', + 'backend' => 'catalog/attribute_backend_customlayoutupdate', + 'required' => false, + 'sort_order' => 60, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'level' => array( + 'type' => 'static', + 'label' => 'Level', + 'required' => false, + 'sort_order' => 24, + 'visible' => false, + 'group' => 'General Information', + ), + 'children_count' => array( + 'type' => 'static', + 'label' => 'Children Count', + 'required' => false, + 'sort_order' => 25, + 'visible' => false, + 'group' => 'General Information', + ), + 'available_sort_by' => array( + 'type' => 'text', + 'label' => 'Available Product Listing Sort By', + 'input' => 'multiselect', + 'source' => 'catalog/category_attribute_source_sortby', + 'backend' => 'catalog/category_attribute_backend_sortby', + 'sort_order' => 40, + 'input_renderer' => 'adminhtml/catalog_category_helper_sortby_available', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Display Settings', + ), + 'default_sort_by' => array( + 'type' => 'varchar', + 'label' => 'Default Product Listing Sort By', + 'input' => 'select', + 'source' => 'catalog/category_attribute_source_sortby', + 'backend' => 'catalog/category_attribute_backend_sortby', + 'sort_order' => 50, + 'input_renderer' => 'adminhtml/catalog_category_helper_sortby_default', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Display Settings', + ), + 'include_in_menu' => array( + 'type' => 'int', + 'label' => 'Include in Navigation Menu', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'default' => '1', + 'sort_order' => 10, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information', + ), + 'custom_use_parent_settings' => array( + 'type' => 'int', + 'label' => 'Use Parent Category Settings', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => false, + 'sort_order' => 5, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'custom_apply_to_products' => array( + 'type' => 'int', + 'label' => 'Apply To Products', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => false, + 'sort_order' => 6, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Custom Design', + ), + 'filter_price_range' => array( + 'type' => 'int', + 'label' => 'Layered Navigation Price Step', + 'input' => 'text', + 'required' => false, + 'sort_order' => 51, + 'input_renderer' => 'adminhtml/catalog_category_helper_pricestep', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Display Settings', + ), + ) + ), + 'catalog_product' => array( + 'entity_model' => 'catalog/product', + 'attribute_model' => 'catalog/resource_eav_attribute', + 'table' => 'catalog/product', + 'additional_attribute_table' => 'catalog/eav_attribute', + 'entity_attribute_collection' => 'catalog/product_attribute_collection', + 'attributes' => array( + 'name' => array( + 'type' => 'varchar', + 'label' => 'Name', + 'input' => 'text', + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'searchable' => true, + 'visible_in_advanced_search' => true, + 'used_in_product_listing' => true, + 'used_for_sort_by' => true, + ), + 'description' => array( + 'type' => 'text', + 'label' => 'Description', + 'input' => 'textarea', + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'searchable' => true, + 'comparable' => true, + 'wysiwyg_enabled' => true, + 'is_html_allowed_on_front' => true, + 'visible_in_advanced_search' => true, + ), + 'short_description' => array( + 'type' => 'text', + 'label' => 'Short Description', + 'input' => 'textarea', + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'searchable' => true, + 'comparable' => true, + 'wysiwyg_enabled' => true, + 'is_html_allowed_on_front' => true, + 'visible_in_advanced_search' => true, + 'used_in_product_listing' => true, + ), + 'sku' => array( + 'type' => 'static', + 'label' => 'SKU', + 'input' => 'text', + 'backend' => 'catalog/product_attribute_backend_sku', + 'unique' => true, + 'sort_order' => 4, + 'searchable' => true, + 'comparable' => true, + 'visible_in_advanced_search' => true, + ), + 'price' => array( + 'type' => 'decimal', + 'label' => 'Price', + 'input' => 'price', + 'backend' => 'catalog/product_attribute_backend_price', + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'searchable' => true, + 'filterable' => true, + 'visible_in_advanced_search' => true, + 'used_in_product_listing' => true, + 'used_for_sort_by' => true, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'special_price' => array( + 'type' => 'decimal', + 'label' => 'Special Price', + 'input' => 'price', + 'backend' => 'catalog/product_attribute_backend_price', + 'required' => false, + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'used_in_product_listing' => true, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'special_from_date' => array( + 'type' => 'datetime', + 'label' => 'Special Price From Date', + 'input' => 'date', + 'backend' => 'catalog/product_attribute_backend_startdate', + 'required' => false, + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'used_in_product_listing' => true, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'special_to_date' => array( + 'type' => 'datetime', + 'label' => 'Special Price To Date', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 4, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'used_in_product_listing' => true, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'cost' => array( + 'type' => 'decimal', + 'label' => 'Cost', + 'input' => 'price', + 'backend' => 'catalog/product_attribute_backend_price', + 'required' => false, + 'user_defined' => true, + 'sort_order' => 5, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'apply_to' => 'simple,virtual', + 'group' => 'Prices', + ), + 'weight' => array( + 'type' => 'decimal', + 'label' => 'Weight', + 'input' => 'text', + 'sort_order' => 5, + 'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, + ), + 'manufacturer' => array( + 'type' => 'int', + 'label' => 'Manufacturer', + 'input' => 'select', + 'required' => false, + 'user_defined' => true, + 'searchable' => true, + 'filterable' => true, + 'comparable' => true, + 'visible_in_advanced_search' => true, + 'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, + ), + 'meta_title' => array( + 'type' => 'varchar', + 'label' => 'Meta Title', + 'input' => 'text', + 'required' => false, + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Meta Information', + ), + 'meta_keyword' => array( + 'type' => 'text', + 'label' => 'Meta Keywords', + 'input' => 'textarea', + 'required' => false, + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Meta Information', + ), + 'meta_description' => array( + 'type' => 'varchar', + 'label' => 'Meta Description', + 'input' => 'textarea', + 'required' => false, + 'note' => 'Maximum 255 chars', + 'class' => 'validate-length maximum-length-255', + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Meta Information', + ), + 'image' => array( + 'type' => 'varchar', + 'label' => 'Base Image', + 'input' => 'media_image', + 'frontend' => 'catalog/product_attribute_frontend_image', + 'required' => false, + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Images', + ), + 'small_image' => array( + 'type' => 'varchar', + 'label' => 'Small Image', + 'input' => 'media_image', + 'frontend' => 'catalog/product_attribute_frontend_image', + 'required' => false, + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'used_in_product_listing' => true, + 'group' => 'Images', + ), + 'thumbnail' => array( + 'type' => 'varchar', + 'label' => 'Thumbnail', + 'input' => 'media_image', + 'frontend' => 'catalog/product_attribute_frontend_image', + 'required' => false, + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'used_in_product_listing' => true, + 'group' => 'Images', + ), + 'media_gallery' => array( + 'type' => 'varchar', + 'label' => 'Media Gallery', + 'input' => 'gallery', + 'backend' => 'catalog/product_attribute_backend_media', + 'required' => false, + 'sort_order' => 4, + 'group' => 'Images', + ), + 'old_id' => array( + 'type' => 'int', + 'required' => false, + 'sort_order' => 6, + 'visible' => false, + ), + 'tier_price' => array( + 'type' => 'decimal', + 'label' => 'Tier Price', + 'input' => 'text', + 'backend' => 'catalog/product_attribute_backend_tierprice', + 'required' => false, + 'sort_order' => 6, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'color' => array( + 'type' => 'int', + 'label' => 'Color', + 'input' => 'select', + 'required' => false, + 'user_defined' => true, + 'searchable' => true, + 'filterable' => true, + 'comparable' => true, + 'visible_in_advanced_search' => true, + 'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, + ), + 'news_from_date' => array( + 'type' => 'datetime', + 'label' => 'Set Product as New from Date', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 7, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'used_in_product_listing' => true, + ), + 'news_to_date' => array( + 'type' => 'datetime', + 'label' => 'Set Product as New to Date', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 8, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'used_in_product_listing' => true, + ), + 'gallery' => array( + 'type' => 'varchar', + 'label' => 'Image Gallery', + 'input' => 'gallery', + 'required' => false, + 'sort_order' => 5, + 'group' => 'Images', + ), + 'status' => array( + 'type' => 'int', + 'label' => 'Status', + 'input' => 'select', + 'source' => 'catalog/product_status', + 'sort_order' => 9, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'searchable' => true, + 'used_in_product_listing' => true, + ), + 'url_key' => array( + 'type' => 'varchar', + 'label' => 'URL key', + 'input' => 'text', + 'backend' => 'catalog/product_attribute_backend_urlkey', + 'required' => false, + 'sort_order' => 10, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'used_in_product_listing' => true, + ), + 'url_path' => array( + 'type' => 'varchar', + 'required' => false, + 'sort_order' => 11, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + ), + 'minimal_price' => array( + 'type' => 'decimal', + 'label' => 'Minimal Price', + 'input' => 'price', + 'required' => false, + 'sort_order' => 7, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'apply_to' => 'simple,configurable,virtual', + 'group' => 'Prices', + ), + 'is_recurring' => array( + 'type' => 'int', + 'label' => 'Enable Recurring Profile', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => false, + 'note' => 'Products with recurring profile participate in catalog as nominal items.', + 'sort_order' => 1, + 'apply_to' => 'simple,virtual', + 'is_configurable' => false, + 'group' => 'Recurring Profile', + ), + 'recurring_profile' => array( + 'type' => 'text', + 'label' => 'Recurring Payment Profile', + 'input' => 'text', + 'backend' => 'catalog/product_attribute_backend_recurring', + 'required' => false, + 'sort_order' => 2, + 'apply_to' => 'simple,virtual', + 'is_configurable' => false, + 'group' => 'Recurring Profile', + ), + 'visibility' => array( + 'type' => 'int', + 'label' => 'Visibility', + 'input' => 'select', + 'source' => 'catalog/product_visibility', + 'default' => '4', + 'sort_order' => 12, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + ), + 'custom_design' => array( + 'type' => 'varchar', + 'label' => 'Custom Design', + 'input' => 'select', + 'source' => 'core/design_source_design', + 'required' => false, + 'sort_order' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'custom_design_from' => array( + 'type' => 'datetime', + 'label' => 'Active From', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 2, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'custom_design_to' => array( + 'type' => 'datetime', + 'label' => 'Active To', + 'input' => 'date', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 3, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'custom_layout_update' => array( + 'type' => 'text', + 'label' => 'Custom Layout Update', + 'input' => 'textarea', + 'backend' => 'catalog/attribute_backend_customlayoutupdate', + 'required' => false, + 'sort_order' => 4, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'page_layout' => array( + 'type' => 'varchar', + 'label' => 'Page Layout', + 'input' => 'select', + 'source' => 'catalog/product_attribute_source_layout', + 'required' => false, + 'sort_order' => 5, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'category_ids' => array( + 'type' => 'static', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'required' => false, + 'sort_order' => 13, + 'visible' => false, + ), + 'options_container' => array( + 'type' => 'varchar', + 'label' => 'Display product options in', + 'input' => 'select', + 'source' => 'catalog/entity_product_attribute_design_options_container', + 'required' => false, + 'default' => 'container2', + 'sort_order' => 6, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'Design', + ), + 'required_options' => array( + 'type' => 'static', + 'input' => 'text', + 'required' => false, + 'sort_order' => 14, + 'visible' => false, + 'used_in_product_listing' => true, + ), + 'has_options' => array( + 'type' => 'static', + 'input' => 'text', + 'required' => false, + 'sort_order' => 15, + 'visible' => false, + ), + 'image_label' => array( + 'type' => 'varchar', + 'label' => 'Image Label', + 'input' => 'text', + 'required' => false, + 'sort_order' => 16, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'used_in_product_listing' => true, + 'is_configurable' => false, + ), + 'small_image_label' => array( + 'type' => 'varchar', + 'label' => 'Small Image Label', + 'input' => 'text', + 'required' => false, + 'sort_order' => 17, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'used_in_product_listing' => true, + 'is_configurable' => false, + ), + 'thumbnail_label' => array( + 'type' => 'varchar', + 'label' => 'Thumbnail Label', + 'input' => 'text', + 'required' => false, + 'sort_order' => 18, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'used_in_product_listing' => true, + 'is_configurable' => false, + ), + 'created_at' => array( + 'type' => 'static', + 'input' => 'text', + 'backend' => 'eav/entity_attribute_backend_time_created', + 'sort_order' => 19, + 'visible' => false, + ), + 'updated_at' => array( + 'type' => 'static', + 'input' => 'text', + 'backend' => 'eav/entity_attribute_backend_time_updated', + 'sort_order' => 20, + 'visible' => false, + ), + ) + ) + ); + } + + /** + * Converts old tree to new + * + * @deprecated since 1.5.0.0 + * @return Mage_Catalog_Model_Resource_Setup + */ + public function convertOldTreeToNew() + { + if (!Mage::getModel('catalog/category')->load(1)->getId()) { + Mage::getModel('catalog/category')->setId(1)->setPath(1)->save(); + } + + $categories = array(); + + $select = $this->getConnection()->select(); + $select->from($this->getTable('catalog/category')); + $categories = $this->getConnection()->fetchAll($select); + + if (is_array($categories)) { + foreach ($categories as $category) { + $path = $this->_getCategoryPath($category); + $path = array_reverse($path); + $path = implode('/', $path); + if ($category['entity_id'] != 1 && substr($path, 0, 2) != '1/') { + $path = "1/{$path}"; + } + + $this + ->getConnection() + ->update( + $this->getTable('catalog/category'), + array('path' => $path), + array('entity_id = ?' => $category['entity_id']) + ); + } + } + return $this; + } + + /** + * Returns category entity row by category id + * + * @param int $entityId + * @return array + */ + protected function _getCategoryEntityRow($entityId) + { + $select = $this->getConnection()->select(); + + $select->from($this->getTable('catalog/category')); + $select->where('entity_id = :entity_id'); + + return $this->getConnection()->fetchRow($select, array('entity_id' => $entityId)); + } + + /** + * Returns category path as array + * + * @param array $category + * @param array $path + * @return string + */ + protected function _getCategoryPath($category, $path = array()) + { + $path[] = $category['entity_id']; + + if ($category['parent_id'] != 0) { + $parentCategory = $this->_getCategoryEntityRow($category['parent_id']); + if ($parentCategory) { + $path = $this->_getCategoryPath($parentCategory, $path); + } + } + + return $path; + } + + /** + * Creates level values for categories and saves them + * + * @deprecated since 1.5.0.0 + * @return Mage_Catalog_Model_Resource_Setup + */ + public function rebuildCategoryLevels() + { + $adapter = $this->getConnection(); + $select = $adapter->select() + ->from($this->getTable('catalog/category')); + + $categories = $adapter->fetchAll($select); + + foreach ($categories as $category) { + $level = count(explode('/', $category['path']))-1; + $adapter->update( + $this->getTable('catalog/category'), + array('level' => $level), + array('entity_id = ?' => $category['entity_id']) + ); + } + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Url.php b/app/code/core/Mage/Catalog/Model/Resource/Url.php new file mode 100755 index 0000000000..f3a9843f41 --- /dev/null +++ b/app/code/core/Mage/Catalog/Model/Resource/Url.php @@ -0,0 +1,1318 @@ + + */ +class Mage_Catalog_Model_Resource_Url extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Stores configuration array + * + * @var array + */ + protected $_stores; + + /** + * Category attribute properties cache + * + * @var array + */ + protected $_categoryAttributes = array(); + + /** + * Product attribute properties cache + * + * @var array + */ + protected $_productAttributes = array(); + + /** + * Limit products for select + * + * @var int + */ + protected $_productLimit = 250; + + /** + * Cache of root category children ids + * + * @var array + */ + protected $_rootChildrenIds = array(); + + /** + * Load core Url rewrite model + * + */ + protected function _construct() + { + $this->_init('core/url_rewrite', 'url_rewrite_id'); + } + + /** + * Retrieve stores array or store model + * + * @param int $storeId + * @return Mage_Core_Model_Store|array + */ + public function getStores($storeId = null) + { + if ($this->_stores === null) { + $this->_stores = $this->_prepareStoreRootCategories(Mage::app()->getStores()); + } + if ($storeId && isset($this->_stores[$storeId])) { + return $this->_stores[$storeId]; + } + return $this->_stores; + } + + /** + * Retrieve Category model singleton + * + * @return Mage_Catalog_Model_Category + */ + public function getCategoryModel() + { + return Mage::getSingleton('catalog/category'); + } + + /** + * Retrieve product model singleton + * + * @return Mage_Catalog_Model_Product + */ + public function getProductModel() + { + return Mage::getSingleton('catalog/product'); + } + + /** + * Retrieve rewrite by idPath + * + * @param string $idPath + * @param int $storeId + * @return Varien_Object|false + */ + public function getRewriteByIdPath($idPath, $storeId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('store_id = :store_id') + ->where('id_path = :id_path'); + $bind = array( + 'store_id' => (int)$storeId, + 'id_path' => $idPath + ); + $row = $adapter->fetchRow($select, $bind); + + if (!$row) { + return false; + } + $rewrite = new Varien_Object($row); + $rewrite->setIdFieldName($this->getIdFieldName()); + + return $rewrite; + } + + /** + * Retrieve rewrite by requestPath + * + * @param string $requestPath + * @param int $storeId + * @return Varien_Object|false + */ + public function getRewriteByRequestPath($requestPath, $storeId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('store_id = :store_id') + ->where('request_path = :request_path'); + $bind = array( + 'request_path' => $requestPath, + 'store_id' => (int)$storeId + ); + $row = $adapter->fetchRow($select, $bind); + + if (!$row) { + return false; + } + $rewrite = new Varien_Object($row); + $rewrite->setIdFieldName($this->getIdFieldName()); + + return $rewrite; + } + + /** + * Validate array of request paths. Return first not used path in case if validations passed + * + * @param array $paths + * @param int $storeId + * @return false | string + */ + public function checkRequestPaths($paths, $storeId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), 'request_path') + ->where('store_id = :store_id') + ->where('request_path IN (?)', $paths); + $data = $adapter->fetchCol($select, array('store_id' => $storeId)); + $paths = array_diff($paths, $data); + if (empty($paths)) { + return false; + } + reset($paths); + + return current($paths); + } + + /** + * Prepare rewrites for condition + * + * @param int $storeId + * @param int|array $categoryIds + * @param int|array $productIds + * @return array + */ + public function prepareRewrites($storeId, $categoryIds = null, $productIds = null) + { + $rewrites = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('store_id = :store_id') + ->where('is_system = ?', 1); + $bind = array('store_id' => $storeId); + if ($categoryIds === null) { + $select->where('category_id IS NULL'); + } elseif ($categoryIds) { + $catIds = is_array($categoryIds) ? $categoryIds : array($categoryIds); + + // Check maybe we request products and root category id is within categoryIds, + // it's a separate case because root category products are stored with NULL categoryId + if ($productIds) { + $addNullCategory = in_array($this->getStores($storeId)->getRootCategoryId(), $catIds); + } else { + $addNullCategory = false; + } + + // Compose optimal condition + if ($addNullCategory) { + $select->where('category_id IN(?) OR category_id IS NULL', $catIds); + } else { + $select->where('category_id IN(?)', $catIds); + } + } + + if ($productIds === null) { + $select->where('product_id IS NULL'); + } elseif ($productIds) { + $select->where('product_id IN(?)', $productIds); + } + + $rowSet = $adapter->fetchAll($select, $bind); + + foreach ($rowSet as $row) { + $rewrite = new Varien_Object($row); + $rewrite->setIdFieldName($this->getIdFieldName()); + $rewrites[$rewrite->getIdPath()] = $rewrite; + } + + return $rewrites; + } + + /** + * Save rewrite URL + * + * @param array $rewriteData + * @param int|Varien_Object $rewrite + * @return Mage_Catalog_Model_Resource_Url + */ + public function saveRewrite($rewriteData, $rewrite) + { + $adapter = $this->_getWriteAdapter(); + if ($rewrite && $rewrite->getId()) { + if ($rewriteData['request_path'] != $rewrite->getRequestPath()) { + $where = array($this->getIdFieldName() . '=?' => $rewrite->getId()); + $adapter->update($this->getMainTable(), $rewriteData, $where); + + // Update existing rewrites history and avoid chain redirects + $where = array('target_path = ?' => $rewrite->getRequestPath()); + if ($rewrite->getStoreId()) { + $where['store_id = ?'] = (int)$rewrite->getStoreId(); + } + $adapter->update( + $this->getMainTable(), + array('target_path' => $rewriteData['request_path']), + $where + ); + } + } else { + try { + $adapter->insert($this->getMainTable(), $rewriteData); + } catch (Exception $e) { + Mage::logException($e); + Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite')); + } + } + unset($rewriteData); + + return $this; + } + + /** + * Saves rewrite history + * + * @param array $rewriteData + * @return Mage_Catalog_Model_Resource_Url + */ + public function saveRewriteHistory($rewriteData) + { + $rewriteData = new Varien_Object($rewriteData); + // check if rewrite exists with save request_path + $rewrite = $this->getRewriteByRequestPath($rewriteData->getRequestPath(), $rewriteData->getStoreId()); + if ($rewrite === false) { + // create permanent redirect + $this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData->getData()); + } + + return $this; + } + + /** + * Save category attribute + * + * @param Varien_Object $category + * @param string $attributeCode + * @return Mage_Catalog_Model_Resource_Url + */ + public function saveCategoryAttribute(Varien_Object $category, $attributeCode) + { + $adapter = $this->_getWriteAdapter(); + if (!isset($this->_categoryAttributes[$attributeCode])) { + $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode); + + $this->_categoryAttributes[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal() + ); + unset($attribute); + } + + $attributeTable = $this->_categoryAttributes[$attributeCode]['table']; + + $attributeData = array( + 'entity_type_id' => $this->_categoryAttributes[$attributeCode]['entity_type_id'], + 'attribute_id' => $this->_categoryAttributes[$attributeCode]['attribute_id'], + 'store_id' => $category->getStoreId(), + 'entity_id' => $category->getId(), + 'value' => $category->getData($attributeCode) + ); + + if ($this->_categoryAttributes[$attributeCode]['is_global'] || $category->getStoreId() == 0) { + $attributeData['store_id'] = 0; + } + + $select = $adapter->select() + ->from($attributeTable) + ->where('entity_type_id = ?', (int)$attributeData['entity_type_id']) + ->where('attribute_id = ?', (int)$attributeData['attribute_id']) + ->where('store_id = ?', (int)$attributeData['store_id']) + ->where('entity_id = ?', (int)$attributeData['entity_id']); + + $row = $adapter->fetchRow($select); + $whereCond = array('value_id = ?' => $row['value_id']); + if ($row) { + $adapter->update($attributeTable, $attributeData, $whereCond); + } else { + $adapter->insert($attributeTable, $attributeData); + } + + if ($attributeData['store_id'] != 0) { + $attributeData['store_id'] = 0; + $select = $adapter->select() + ->from($attributeTable) + ->where('entity_type_id = ?', (int)$attributeData['entity_type_id']) + ->where('attribute_id = ?', (int)$attributeData['attribute_id']) + ->where('store_id = ?', (int)$attributeData['store_id']) + ->where('entity_id = ?', (int)$attributeData['entity_id']); + + $row = $adapter->fetchRow($select); + if ($row) { + $whereCond = array('value_id = ?' => $row['value_id']); + $adapter->update($attributeTable, $attributeData, $whereCond); + } else { + $adapter->insert($attributeTable, $attributeData); + } + } + unset($attributeData); + + return $this; + } + + /** + * Retrieve category attributes + * + * @param string $attributeCode + * @param int|array $categoryIds + * @param int $storeId + * @return array + */ + protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) + { + $adapter = $this->_getWriteAdapter(); + if (!isset($this->_categoryAttributes[$attributeCode])) { + $attribute = $this->getCategoryModel()->getResource()->getAttribute($attributeCode); + + $this->_categoryAttributes[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal(), + 'is_static' => $attribute->isStatic() + ); + unset($attribute); + } + + if (!is_array($categoryIds)) { + $categoryIds = array($categoryIds); + } + + $attributeTable = $this->_categoryAttributes[$attributeCode]['table']; + $select = $adapter->select(); + $bind = array(); + if ($this->_categoryAttributes[$attributeCode]['is_static']) { + $select + ->from( + $this->getTable('catalog/category'), + array('value' => $attributeCode, 'entity_id' => 'entity_id') + ) + ->where('entity_id IN(?)', $categoryIds); + } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) { + $select + ->from($attributeTable, array('entity_id', 'value')) + ->where('attribute_id = :attribute_id') + ->where('store_id = ?', 0) + ->where('entity_id IN(?)', $categoryIds); + $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id']; + } else { + $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + $select + ->from( + array('t1' => $attributeTable), + array('entity_id', 'value' => $valueExpr) + ) + ->joinLeft( + array('t2' => $attributeTable), + 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id = :store_id', + array() + ) + ->where('t1.store_id = ?', 0) + ->where('t1.attribute_id = :attribute_id') + ->where('t1.entity_id IN(?)', $categoryIds); + + $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id']; + $bind['store_id'] = $storeId; + } + + $rowSet = $adapter->fetchAll($select, $bind); + + $attributes = array(); + foreach ($rowSet as $row) { + $attributes[$row['entity_id']] = $row['value']; + } + unset($rowSet); + foreach ($categoryIds as $categoryId) { + if (!isset($attributes[$categoryId])) { + $attributes[$categoryId] = null; + } + } + + return $attributes; + } + + /** + * Save product attribute + * + * @param Varien_Object $product + * @param string $attributeCode + * @return Mage_Catalog_Model_Resource_Url + */ + public function saveProductAttribute(Varien_Object $product, $attributeCode) + { + $adapter = $this->_getWriteAdapter(); + if (!isset($this->_productAttributes[$attributeCode])) { + $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode); + + $this->_productAttributes[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal() + ); + unset($attribute); + } + + $attributeTable = $this->_productAttributes[$attributeCode]['table']; + + $attributeData = array( + 'entity_type_id' => $this->_productAttributes[$attributeCode]['entity_type_id'], + 'attribute_id' => $this->_productAttributes[$attributeCode]['attribute_id'], + 'store_id' => $product->getStoreId(), + 'entity_id' => $product->getId(), + 'value' => $product->getData($attributeCode) + ); + + if ($this->_productAttributes[$attributeCode]['is_global'] || $product->getStoreId() == 0) { + $attributeData['store_id'] = 0; + } + + $select = $adapter->select() + ->from($attributeTable) + ->where('entity_type_id = ?', (int)$attributeData['entity_type_id']) + ->where('attribute_id = ?', (int)$attributeData['attribute_id']) + ->where('store_id = ?', (int)$attributeData['store_id']) + ->where('entity_id = ?', (int)$attributeData['entity_id']); + + $row = $adapter->fetchRow($select); + if ($row) { + $whereCond = array('value_id = ?' => $row['value_id']); + $adapter->update($attributeTable, $attributeData, $whereCond); + } else { + $adapter->insert($attributeTable, $attributeData); + } + + if ($attributeData['store_id'] != 0) { + $attributeData['store_id'] = 0; + $select = $adapter->select() + ->from($attributeTable) + ->where('entity_type_id = ?', (int)$attributeData['entity_type_id']) + ->where('attribute_id = ?', (int)$attributeData['attribute_id']) + ->where('store_id = ?', (int)$attributeData['store_id']) + ->where('entity_id = ?', (int)$attributeData['entity_id']); + + $row = $adapter->fetchRow($select); + if ($row) { + $whereCond = array('value_id = ?' => $row['value_id']); + $adapter->update($attributeTable, $attributeData, $whereCond); + } else { + $adapter->insert($attributeTable, $attributeData); + } + } + unset($attributeData); + + return $this; + } + + /** + * Retrieve product attribute + * + * @param string $attributeCode + * @param int|array $productIds + * @param string $storeId + * @return array + */ + public function _getProductAttribute($attributeCode, $productIds, $storeId) + { + $adapter = $this->_getReadAdapter(); + if (!isset($this->_productAttributes[$attributeCode])) { + $attribute = $this->getProductModel()->getResource()->getAttribute($attributeCode); + + $this->_productAttributes[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal() + ); + unset($attribute); + } + + if (!is_array($productIds)) { + $productIds = array($productIds); + } + $bind = array('attribute_id' => $this->_productAttributes[$attributeCode]['attribute_id']); + $select = $adapter->select(); + $attributeTable = $this->_productAttributes[$attributeCode]['table']; + if ($this->_productAttributes[$attributeCode]['is_global'] || $storeId == 0) { + $select + ->from($attributeTable, array('entity_id', 'value')) + ->where('attribute_id = :attribute_id') + ->where('store_id = ?', 0) + ->where('entity_id IN(?)', $productIds); + } else { + $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + $select + ->from( + array('t1' => $attributeTable), + array('entity_id', 'value' => $valueExpr) + ) + ->joinLeft( + array('t2' => $attributeTable), + 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=:store_id', + array() + ) + ->where('t1.store_id = ?', 0) + ->where('t1.attribute_id = :attribute_id') + ->where('t1.entity_id IN(?)', $productIds); + $bind['store_id'] = $storeId; + } + + $rowSet = $adapter->fetchAll($select, $bind); + + $attributes = array(); + foreach ($rowSet as $row) { + $attributes[$row['entity_id']] = $row['value']; + } + unset($rowSet); + foreach ($productIds as $productIds) { + if (!isset($attributes[$productIds])) { + $attributes[$productIds] = null; + } + } + + return $attributes; + } + + /** + * Prepare category parentId + * + * @param Varien_Object $category + * @return Mage_Catalog_Model_Resource_Url + */ + protected function _prepareCategoryParentId(Varien_Object $category) + { + if ($category->getPath() != $category->getId()) { + $split = explode('/', $category->getPath()); + $category->setParentId($split[(count($split) - 2)]); + } else { + $category->setParentId(0); + } + return $this; + } + + /** + * Prepare stores root categories + * + * @param array $stores + * @return array + */ + protected function _prepareStoreRootCategories($stores) + { + $rootCategoryIds = array(); + foreach ($stores as $store) { + /* @var $store Mage_Core_Model_Store */ + $rootCategoryIds[$store->getRootCategoryId()] = $store->getRootCategoryId(); + } + if ($rootCategoryIds) { + $categories = $this->_getCategories($rootCategoryIds); + } + foreach ($stores as $store) { + /* @var $store Mage_Core_Model_Store */ + $rootCategoryId = $store->getRootCategoryId(); + if (isset($categories[$rootCategoryId])) { + $store->setRootCategoryPath($categories[$rootCategoryId]->getPath()); + $store->setRootCategory($categories[$rootCategoryId]); + } else { + unset($stores[$store->getId()]); + } + } + return $stores; + } + + /** + * Retrieve categories objects + * Either $categoryIds or $path (with ending slash) must be specified + * + * @param int|array $categoryIds + * @param int $storeId + * @param string $path + * @return array + */ + protected function _getCategories($categoryIds, $storeId = null, $path = null) + { + $isActiveAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active'); + $categories = array(); + $adapter = $this->_getReadAdapter(); + + if (!is_array($categoryIds)) { + $categoryIds = array($categoryIds); + } + $isActiveExpr = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'c.value'); + $select = $adapter->select() + ->from(array('main_table' => $this->getTable('catalog/category')), array( + 'main_table.entity_id', + 'main_table.parent_id', + 'main_table.level', + 'is_active' => $isActiveExpr, + 'main_table.path')); + + // Prepare variables for checking whether categories belong to store + if ($path === null) { + $select->where('main_table.entity_id IN(?)', $categoryIds); + } else { + // Ensure that path ends with '/', otherwise we can get wrong results - e.g. $path = '1/2' will get '1/20' + if (substr($path, -1) != '/') { + $path .= '/'; + } + + $select + ->where('main_table.path LIKE ?', $path . '%') + ->order('main_table.path'); + } + $table = $this->getTable(array('catalog/category', 'int')); + $select->joinLeft(array('d' => $table), + 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = main_table.entity_id', + array() + ) + ->joinLeft(array('c' => $table), + 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = main_table.entity_id', + array() + ); + + if ($storeId !== null) { + $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); + $rootCategoryPathLength = strlen($rootCategoryPath); + } + $bind = array( + 'attribute_id' => (int)$isActiveAttribute->getId(), + 'store_id' => (int)$storeId + ); + + $rowSet = $adapter->fetchAll($select, $bind); + foreach ($rowSet as $row) { + if ($storeId !== null) { + // Check the category to be either store's root or its descendant + // First - check that category's start is the same as root category + if (substr($row['path'], 0, $rootCategoryPathLength) != $rootCategoryPath) { + continue; + } + // Second - check non-root category - that it's really a descendant, not a simple string match + if ((strlen($row['path']) > $rootCategoryPathLength) + && ($row['path'][$rootCategoryPathLength] != '/')) { + continue; + } + } + + $category = new Varien_Object($row); + $category->setIdFieldName('entity_id'); + $category->setStoreId($storeId); + $this->_prepareCategoryParentId($category); + + $categories[$category->getId()] = $category; + } + unset($rowSet); + + if ($storeId !== null && $categories) { + foreach (array('name', 'url_key', 'url_path') as $attributeCode) { + $attributes = $this->_getCategoryAttribute($attributeCode, array_keys($categories), $category->getStoreId()); + foreach ($attributes as $categoryId => $attributeValue) { + $categories[$categoryId]->setData($attributeCode, $attributeValue); + } + } + } + + return $categories; + } + + /** + * Retrieve category data object + * + * @param int $categoryId + * @param int $storeId + * @return Varien_Object + */ + public function getCategory($categoryId, $storeId) + { + if (!$categoryId || !$storeId) { + return false; + } + + $categories = $this->_getCategories($categoryId, $storeId); + if (isset($categories[$categoryId])) { + return $categories[$categoryId]; + } + return false; + } + + /** + * Retrieve categories data objects by their ids. Return only categories that belong to specified store. + * + * @param int|array $categoryIds + * @param int $storeId + * @return array + */ + public function getCategories($categoryIds, $storeId) + { + if (!$categoryIds || !$storeId) { + return false; + } + + return $this->_getCategories($categoryIds, $storeId); + } + + /** + * Retrieve category childs data objects + * + * @param Varien_Object $category + * @return Varien_Object + */ + public function loadCategoryChilds(Varien_Object $category) + { + if ($category->getId() === null || $category->getStoreId() === null) { + return $category; + } + + $categories = $this->_getCategories(null, $category->getStoreId(), $category->getPath() . '/'); + $category->setChilds(array()); + foreach ($categories as $child) { + if (!is_array($child->getChilds())) { + $child->setChilds(array()); + } + if ($child->getParentId() == $category->getId()) { + $category->setChilds($category->getChilds() + array($child->getId() => $child)); + } else { + if (isset($categories[$child->getParentId()])) { + if (!is_array($categories[$child->getParentId()]->getChilds())) { + $categories[$child->getParentId()]->setChilds(array()); + } + $categories[$child->getParentId()]->setChilds( + $categories[$child->getParentId()]->getChilds() + array($child->getId() => $child) + ); + } + } + } + $category->setAllChilds($categories); + + return $category; + } + + /** + * Retrieves all children ids of root category tree + * Actually this routine can be used to get children ids of any category, not only root. + * But as far as result is cached in memory, it's not recommended to do so. + * + * @param Varien_Object $category + * @return Varien_Object + */ + public function getRootChildrenIds($categoryId, $categoryPath, $includeStart = true) + { + if (!isset($this->_rootChildrenIds[$categoryId])) { + // Select all descedant category ids + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from(array($this->getTable('catalog/category')), array('entity_id')) + ->where('path LIKE ?', $categoryPath . '/%'); + + $categoryIds = array(); + $rowSet = $adapter->fetchAll($select); + foreach ($rowSet as $row) { + $categoryIds[$row['entity_id']] = $row['entity_id']; + } + $this->_rootChildrenIds[$categoryId] = $categoryIds; + } + + $categoryIds = $this->_rootChildrenIds[$categoryId]; + if ($includeStart) { + $categoryIds[$categoryId] = $categoryId; + } + return $categoryIds; + } + + /** + * Retrieve category parent path + * + * @param Varien_Object $category + * @return string + */ + public function getCategoryParentPath(Varien_Object $category) + { + $store = Mage::app()->getStore($category->getStoreId()); + + if ($category->getId() == $store->getRootCategoryId()) { + return ''; + } elseif ($category->getParentId() == 1 || $category->getParentId() == $store->getRootCategoryId()) { + return ''; + } + + $parentCategory = $this->getCategory($category->getParentId(), $store->getId()); + return $parentCategory->getUrlPath() . '/'; + } + + /** + * Retrieve product ids by category + * + * @param Varien_Object|int $category + * @return array + */ + public function getProductIdsByCategory($category) + { + if ($category instanceof Varien_Object) { + $categoryId = $category->getId(); + } else { + $categoryId = $category; + } + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('catalog/category_product'), array('product_id')) + ->where('category_id = :category_id') + ->order('product_id'); + $bind = array('category_id' => $categoryId); + + return $adapter->fetchCol($select, $bind); + } + + /** + * Retrieve Product data objects + * + * @param int|array $productIds + * @param int $storeId + * @param int $entityId + * @param int $lastEntityId + * @return array + */ + protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId) + { + $products = array(); + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); + $adapter = $this->_getReadAdapter(); + if ($productIds !== null) { + if (!is_array($productIds)) { + $productIds = array($productIds); + } + } + $bind = array( + 'website_id' => (int)$websiteId, + 'entity_id' => (int)$entityId, + ); + $select = $adapter->select() + ->useStraightJoin(true) + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')) + ->join( + array('w' => $this->getTable('catalog/product_website')), + 'e.entity_id = w.product_id AND w.website_id = :website_id', + array() + ) + ->where('e.entity_id > :entity_id') + ->order('e.entity_id') + ->limit($this->_productLimit); + if ($productIds !== null) { + $select->where('e.entity_id IN(?)', $productIds); + } + + $rowSet = $adapter->fetchAll($select, $bind); + foreach ($rowSet as $row) { + $product = new Varien_Object($row); + $product->setIdFieldName('entity_id'); + $product->setCategoryIds(array()); + $product->setStoreId($storeId); + $products[$product->getId()] = $product; + $lastEntityId = $product->getId(); + } + + unset($rowSet); + + if ($products) { + $select = $adapter->select() + ->from( + $this->getTable('catalog/category_product'), + array('product_id', 'category_id') + ) + ->where('product_id IN(?)', array_keys($products)); + $categories = $adapter->fetchAll($select); + foreach ($categories as $category) { + $productId = $category['product_id']; + $categoryIds = $products[$productId]->getCategoryIds(); + $categoryIds[] = $category['category_id']; + $products[$productId]->setCategoryIds($categoryIds); + } + + foreach (array('name', 'url_key', 'url_path') as $attributeCode) { + $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId); + foreach ($attributes as $productId => $attributeValue) { + $products[$productId]->setData($attributeCode, $attributeValue); + } + } + } + + return $products; + } + + /** + * Retrieve Product data object + * + * @param int $productId + * @param int $storeId + * @return Varien_Object + */ + public function getProduct($productId, $storeId) + { + $entityId = 0; + $products = $this->_getProducts($productId, $storeId, 0, $entityId); + if (isset($products[$productId])) { + return $products[$productId]; + } + return false; + } + + /** + * Retrieve Product data obects for store + * + * @param int $storeId + * @param int $lastEntityId + * @return array + */ + public function getProductsByStore($storeId, &$lastEntityId) + { + return $this->_getProducts(null, $storeId, $lastEntityId, $lastEntityId); + } + + /** + * Retrieve Product data objects in category + * + * @param Varien_Object $category + * @param int $lastEntityId + * @return array + */ + public function getProductsByCategory(Varien_Object $category, &$lastEntityId) + { + $productIds = $this->getProductIdsByCategory($category); + if (!$productIds) { + return array(); + } + return $this->_getProducts($productIds, $category->getStoreId(), $lastEntityId, $lastEntityId); + } + + /** + * Find and remove unused products rewrites - a case when products were moved away from the category + * (either to other category or deleted), so rewrite "category_id-product_id" is invalid + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Url + */ + public function clearCategoryProduct($storeId) + { + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from(array('tur' => $this->getMainTable()), $this->getIdFieldName()) + ->joinLeft( + array('tcp' => $this->getTable('catalog/category_product')), + 'tur.category_id = tcp.category_id AND tur.product_id = tcp.product_id', + array() + ) + ->where('tur.store_id = :store_id') + ->where('tur.category_id IS NOT NULL') + ->where('tur.product_id IS NOT NULL') + ->where('tcp.category_id IS NULL'); + $rewriteIds = $adapter->fetchCol($select, array('store_id' => $storeId)); + if ($rewriteIds) { + $where = array($this->getIdFieldName() . ' IN(?)' => $rewriteIds); + $adapter->delete($this->getMainTable(), $where); + } + + return $this; + } + + /** + * Remove unused rewrites for product - called after we created all needed rewrites for product and know the categories + * where the product is contained ($excludeCategoryIds), so we can remove all invalid product rewrites that have other category ids + * + * Notice: this routine is not identical to clearCategoryProduct(), because after checking all categories this one removes rewrites + * for product still contained within categories. + * + * @param int $productId Product entity Id + * @param int $storeId Store Id for rewrites + * @param array $excludeCategoryIds Array of category Ids that should be skipped + * @return Mage_Catalog_Model_Resource_Url + */ + public function clearProductRewrites($productId, $storeId, $excludeCategoryIds = array()) + { + $where = array( + 'product_id = ?' => $productId, + 'store_id = ?' => $storeId + ); + + if (!empty($excludeCategoryIds)) { + $where['category_id NOT IN (?)'] = $excludeCategoryIds; + $where[] = 'category_id IS NOT NULL'; // If there's at least one category to skip, also skip root category, because product belongs to website + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + + return $this; + } + + /** + * Finds and deletes all old category and category/product rewrites for store + * left from the times when categories/products belonged to store + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url + */ + public function clearStoreCategoriesInvalidRewrites($storeId) + { + // Form a list of all current store categories ids + $store = $this->getStores($storeId); + $rootCategoryId = $store->getRootCategoryId(); + if (!$rootCategoryId) { + return $this; + } + $categoryIds = $this->getRootChildrenIds($rootCategoryId, $store->getRootCategoryPath()); + + // Remove all store catalog rewrites that are for some category or cartegory/product not within store categories + $where = array( + 'store_id = ?' => $storeId, + 'category_id IS NOT NULL', // For sure check that it's a catalog rewrite + 'category_id NOT IN (?)' => $categoryIds + ); + + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + + return $this; + } + + /** + * Finds and deletes product rewrites (that are not assigned to any category) for store + * left from the times when product was assigned to this store's website and now is not assigned + * + * Notice: this routine is different from clearProductRewrites() and clearCategoryProduct() because + * it handles direct rewrites to product without defined category (category_id IS NULL) whilst that routines + * handle only product rewrites within categories + * + * @param int $storeId + * @param int|array|null $productId + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url + */ + public function clearStoreProductsInvalidRewrites($storeId, $productId = null) + { + $store = $this->getStores($storeId); + $adapter = $this->_getReadAdapter(); + $bind = array( + 'website_id' => (int)$store->getWebsiteId(), + 'store_id' => (int)$storeId + ); + $select = $adapter->select() + ->from(array('rewrite' => $this->getMainTable()), $this->getIdFieldName()) + ->joinLeft( + array('website' => $this->getTable('catalog/product_website')), + 'rewrite.product_id = website.product_id AND website.website_id = :website_id', + array() + )->where('rewrite.store_id = :store_id') + ->where('rewrite.category_id IS NULL'); + if ($productId) { + $select->where('rewrite.product_id IN (?)', $productId); + } else { + $select->where('rewrite.product_id IS NOT NULL'); + } + $select->where('website.website_id IS NULL'); + + $rewriteIds = $adapter->fetchCol($select, $bind); + if ($rewriteIds) { + $where = array($this->getIdFieldName() . ' IN(?)' => $rewriteIds); + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + } + + return $this; + } + + /** + * Finds and deletes old rewrites for store + * a) category rewrites left from the times when store had some other root category + * b) product rewrites left from products that once belonged to this site, but then deleted or just removed from website + * + * @param int $storeId + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Url + */ + public function clearStoreInvalidRewrites($storeId) + { + $this->clearStoreCategoriesInvalidRewrites($storeId); + $this->clearStoreProductsInvalidRewrites($storeId); + return $this; + } + + /** + * Delete rewrites for associated to category products + * + * @param int $categoryId + * @param array $productIds + * @return Mage_Catalog_Model_Resource_Url + */ + public function deleteCategoryProductRewrites($categoryId, $productIds) + { + $this->deleteCategoryProductStoreRewrites($categoryId, $productIds); + return $this; + } + + /** + * Delete URL rewrites for category products of specific store + * + * @param int $categoryId + * @param array|int|null $productIds + * @param null|int $storeId + * @return Mage_Catalog_Model_Resource_Url + */ + public function deleteCategoryProductStoreRewrites($categoryId, $productIds = null, $storeId = null) + { + // Notice that we don't include category_id = NULL in case of root category, + // because product removed from all categories but assigned to store's website is still + // assumed to be in root cat. Unassigned products must be removed by other routine. + $condition = array('category_id = ?' => $categoryId); + if (empty($productIds)) { + $condition[] = 'product_id IS NOT NULL'; + } else { + $condition['product_id IN (?)'] = $productIds; + } + + if ($storeId !== null) { + $condition['store_id IN(?)'] = $storeId; + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), $condition); + return $this; + } + + /** + * Retrieve rewrites and visibility by store + * Input array format: + * product_id as key and store_id as value + * Output array format (product_id as key) + * store_id int; store id + * visibility int; visibility for store + * url_rewrite string; rewrite URL for store + * + * @param array $products + * @return array + */ + public function getRewriteByProductStore(array $products) + { + $result = array(); + + if (empty($products)) { + return $result; + } + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from( + array('i' => $this->getTable('catalog/category_product_index')), + array('product_id', 'store_id', 'visibility') + ) + ->joinLeft( + array('r' => $this->getMainTable()), + 'i.product_id = r.product_id AND i.store_id=r.store_id AND r.category_id IS NULL', + array('request_path') + ); + + $bind = array(); + foreach ($products as $productId => $storeId) { + $catId = Mage::app()->getStore($storeId)->getRootCategoryId(); + $productBind = 'product_id' . $productId; + $storeBind = 'store_id' . $storeId; + $catBind = 'category_id' . $catId; + $cond = '(' . implode(' AND ', array( + 'i.product_id = :' . $productBind, + 'i.store_id = :' . $storeBind, + 'i.category_id = :' . $catBind, + )) . ')'; + $bind[$productBind] = $productId; + $bind[$storeBind] = $storeId; + $bind[$catBind] = $catId; + $select->orWhere($cond); + } + + $rowSet = $adapter->fetchAll($select, $bind); + foreach ($rowSet as $row) { + $result[$row['product_id']] = array( + 'store_id' => $row['store_id'], + 'visibility' => $row['visibility'], + 'url_rewrite' => $row['request_path'], + ); + } + + return $result; + } + + /** + * Find and return final id path by request path + * Needed for permanent redirect old URLs. + * + * @param string $requestPath + * @param int $storeId + * @param array $_checkedPaths internal varible to prevent infinite loops. + * @return string | bool + */ + public function findFinalTargetPath($requestPath, $storeId, &$_checkedPaths = array()) + { + if (in_array($requestPath, $_checkedPaths)) { + return false; + } + + $_checkedPaths[] = $requestPath; + + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable(), array('target_path', 'id_path')) + ->where('store_id = ?', $storeId) + ->where('request_path = ?', $requestPath); + + if ($row = $this->_getWriteAdapter()->fetchRow($select)) { + $idPath = $this->findFinalTargetPath($row['target_path'], $storeId, $_checkedPaths); + if (!$idPath) { + return $row['id_path']; + } else { + return $idPath; + } + } + + return false; + } + + /** + * Delete rewrite path record from the database. + * + * @param string $requestPath + * @param int $storeId + * @return void + */ + public function deleteRewrite($requestPath, $storeId) + { + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + array( + 'store_id = ?' => $store_id, + 'request_path = ?' => $requestPath + ) + ); + } +} diff --git a/app/code/core/Mage/Catalog/Model/Sendfriend.php b/app/code/core/Mage/Catalog/Model/Sendfriend.php deleted file mode 100644 index 44df6f197e..0000000000 --- a/app/code/core/Mage/Catalog/Model/Sendfriend.php +++ /dev/null @@ -1,267 +0,0 @@ -_init('catalog/sendfriend'); - } - - public function toOptionArray() - { - if(!$collection = Mage::registry('config_system_email_template')) { - $collection = Mage::getResourceModel('core/email_template_collection') - ->load(); - - Mage::register('config_system_email_template', $collection); - } - $options = $collection->toOptionArray(); - array_unshift($options, array('value'=>'', 'label'=>'')); - return $options; - } - - public function send() - { - $errors = array(); - - $this->_emailModel = Mage::getModel('core/email_template'); - - $this->_emailModel->load($this->getTemplate()); - if (!$this->_emailModel->getId()) { - Mage::throwException( - Mage::helper('catalog')->__('Invalid transactional email code.') - ); - } - - $this->_emailModel->setSenderName(strip_tags($this->_sender['name'])); - $this->_emailModel->setSenderEmail(strip_tags($this->_sender['email'])); - - foreach ($this->_emails as $k=>$email) { - if (!$this->_sendOne($email, $this->_names[$k])) { - $errors[] = $email; - } - } - - if (count($errors)) { - Mage::throwException( - Mage::helper('catalog')->__('Email to %s was not sent.', implode(', ', $errors)) - ); - } - } - - public function canSend() - { - if (!$this->canEmailToFriend()) { - Mage::throwException( - Mage::helper('catalog')->__('You cannot email this product to a friend.') - ); - } - - if ($this->_getSendToFriendCheckType()) { - $amount = $this->_amountByCookies(); - } else { - $amount = $this->_amountByIp(); - } - - if ($amount >= $this->getMaxSendsToFriend()){ - Mage::throwException( - Mage::helper('catalog')->__('You have exceeded limit of %d sends in an hour.', $this->getMaxSendsToFriend()) - ); - } - - $maxRecipients = $this->getMaxRecipients(); - if (count($this->_emails) > $maxRecipients) { - Mage::throwException( - Mage::helper('catalog')->__('You cannot send more than %d emails at a time.', $this->getMaxRecipients()) - ); - } - - if (count($this->_emails) < 1) { - Mage::throwException( - Mage::helper('catalog')->__('You have to specify at least one recipient.') - ); - } - - if (!$this->getTemplate()){ - Mage::throwException( - Mage::helper('catalog')->__('The email template is not specified by administrator.') - ); - } - - return true; - } - - public function setIp($ip) - { - $this->_ip = $ip; - } - - public function setRecipients($recipients) - { - $this->_emails = array_unique($recipients['email']); - $this->_names = $recipients['name']; - } - - public function setProduct($product){ - $this->_product = $product; - } - - public function setSender($sender){ - $this->_sender = $sender; - } - - public function getSendCount($ip, $startTime) - { - $count = $this->_getResource()->getSendCount($this, $ip, $startTime); - return $count; - } - - /** - * Get max allowed uses of "Send to Friend" function per hour - * - * @return integer - */ - public function getMaxSendsToFriend() - { - return max(0, (int) Mage::getStoreConfig('sendfriend/email/max_per_hour')); - } - - /** - * Get current "Send to friend" template - * - * @return string - */ - public function getTemplate() - { - return Mage::getStoreConfig('sendfriend/email/template'); - } - - /** - * Get max allowed recipients for "Send to a Friend" function - * - * @return integer - */ - public function getMaxRecipients() - { - return max(0, (int) Mage::getStoreConfig('sendfriend/email/max_recipients')); - } - - /** - * Check if user is allowed to email product to a friend - * - * @return boolean - */ - public function canEmailToFriend() - { - if (!Mage::getStoreConfig('sendfriend/email/enabled')) { - return false; - } - if (!Mage::getStoreConfig('sendfriend/email/allow_guest') - && !Mage::getSingleton('customer/session')->isLoggedIn()) { - return false; - } - return true; - } - - private function _sendOne($email, $name){ - $email = trim($email); - - $vars = array( - 'senderName' => strip_tags($this->_sender['name']), - 'senderEmail' => strip_tags($this->_sender['email']), - 'receiverName' => strip_tags($name), - 'receiverEmail' => strip_tags($email), - 'product' => $this->_product, - 'message' => strip_tags($this->_sender['message']) - ); - - if (!$this->_emailModel->send(strip_tags($email), strip_tags($name), $vars)){ - return false; - } - - return true; - } - - /** - * Get check type for "Send to Friend" function - * - * @return integer - */ - private function _getSendToFriendCheckType() - { - return max(0, (int) Mage::getStoreConfig('sendfriend/email/check_by')); - } - - private function _amountByCookies() - { - $newTimes = array(); - $oldTimes = Mage::app()->getCookie()->get($this->_cookieName); - if ($oldTimes){ - $oldTimes = explode(',', $oldTimes); - foreach ($oldTimes as $time){ - if (is_numeric($time) && $time >= time()-$this->_period){ - $newTimes[] = $time; - } - } - } - $amount = count($newTimes); - - $newTimes[] = time(); - Mage::app()->getCookie() - ->set($this->_cookieName, implode(',', $newTimes), $this->_period); - - return $amount; - } - - private function _amountByIp() - { - $this->_deleteLogsBefore(time() - $this->_period); - - $amount = $this->getSendCount($this->_ip, time() - $this->_period); - - $this->setData(array('ip'=>$this->_ip, 'time'=>time())); - $this->save(); - - return $amount; - } - - private function _deleteLogsBefore($time) - { - $this->_getResource()->deleteLogsBefore($time); - return $this; - } -} diff --git a/app/code/core/Mage/Catalog/Model/Session.php b/app/code/core/Mage/Catalog/Model/Session.php index 9d3b36e03d..f36cb475c5 100644 --- a/app/code/core/Mage/Catalog/Model/Session.php +++ b/app/code/core/Mage/Catalog/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Category/Flat.php b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Category/Flat.php index 9f4b91ecd7..1f273bf6f3 100644 --- a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Category/Flat.php +++ b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Category/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Product/Flat.php b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Product/Flat.php index 7ce9843acb..7452f08687 100644 --- a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Product/Flat.php +++ b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Product/Flat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php index 51b40dd77e..7b441286bf 100644 --- a/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php +++ b/app/code/core/Mage/Catalog/Model/System/Config/Backend/Catalog/Url/Rewrite/Suffix.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Template/Filter.php b/app/code/core/Mage/Catalog/Model/Template/Filter.php index 2bf51d8d00..220bc994b0 100644 --- a/app/code/core/Mage/Catalog/Model/Template/Filter.php +++ b/app/code/core/Mage/Catalog/Model/Template/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/Model/Url.php b/app/code/core/Mage/Catalog/Model/Url.php index 93d0ce8597..179148716e 100644 --- a/app/code/core/Mage/Catalog/Model/Url.php +++ b/app/code/core/Mage/Catalog/Model/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/controllers/CategoryController.php b/app/code/core/Mage/Catalog/controllers/CategoryController.php index 336f85565e..160a8ed5c8 100644 --- a/app/code/core/Mage/Catalog/controllers/CategoryController.php +++ b/app/code/core/Mage/Catalog/controllers/CategoryController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/controllers/IndexController.php b/app/code/core/Mage/Catalog/controllers/IndexController.php index 9a983f98e5..e62be35372 100644 --- a/app/code/core/Mage/Catalog/controllers/IndexController.php +++ b/app/code/core/Mage/Catalog/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/controllers/Product/CompareController.php b/app/code/core/Mage/Catalog/controllers/Product/CompareController.php index dfc69837fa..1476ba3828 100644 --- a/app/code/core/Mage/Catalog/controllers/Product/CompareController.php +++ b/app/code/core/Mage/Catalog/controllers/Product/CompareController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/controllers/ProductController.php b/app/code/core/Mage/Catalog/controllers/ProductController.php index 6ae39275da..b6b35dc3f5 100644 --- a/app/code/core/Mage/Catalog/controllers/ProductController.php +++ b/app/code/core/Mage/Catalog/controllers/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -64,7 +64,7 @@ protected function _initProduct() */ protected function _initProductLayout($product) { - Mage::helper('catalog/product')->initProductLayout($product, $this); + Mage::helper('catalog/product_view')->initProductLayout($product, $this); return $this; } diff --git a/app/code/core/Mage/Catalog/controllers/Seo/SitemapController.php b/app/code/core/Mage/Catalog/controllers/Seo/SitemapController.php index 15e0643d73..9c0d2e7b17 100644 --- a/app/code/core/Mage/Catalog/controllers/Seo/SitemapController.php +++ b/app/code/core/Mage/Catalog/controllers/Seo/SitemapController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/data/catalog_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Catalog/data/catalog_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..ed19de87ba --- /dev/null +++ b/app/code/core/Mage/Catalog/data/catalog_setup/data-install-1.6.0.0.php @@ -0,0 +1,213 @@ +load(1) + ->setId(1) + ->setStoreId(0) + ->setPath(1) + ->setLevel(0) + ->setPosition(0) + ->setChildrenCount(0) + ->setName('Root Catalog') + ->setInitialSetupFlag(true) + ->save(); + +/* @var $category Mage_Catalog_Model_Category */ +$category = Mage::getModel('catalog/category'); + +$category->setStoreId(0) + ->setName('Default Category') + ->setDisplayMode('PRODUCTS') + ->setAttributeSetId($category->getDefaultAttributeSetId()) + ->setIsActive(1) + ->setPath('1') + ->setInitialSetupFlag(true) + ->save(); + +$installer->setConfigData(Mage_Catalog_Helper_Category::XML_PATH_CATEGORY_ROOT_ID, $category->getId()); + +$installer->addAttributeGroup(Mage_Catalog_Model_Product::ENTITY, 'Default', 'Design', 6); + +$entityTypeId = $installer->getEntityTypeId(Mage_Catalog_Model_Category::ENTITY); +$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); +$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); + +// update General Group +//$installer->updateAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'attribute_group_name', 'General Information'); +$installer->updateAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'sort_order', '10'); + +$groups = array( + 'display' => array( + 'name' => 'Display Settings', + 'sort' => 20, + 'id' => null + ), + 'design' => array( + 'name' => 'Custom Design', + 'sort' => 30, + 'id' => null + ) +); + +foreach ($groups as $k => $groupProp) { + $installer->addAttributeGroup($entityTypeId, $attributeSetId, $groupProp['name'], $groupProp['sort']); + $groups[$k]['id'] = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['name']); +} + +// update attributes group and sort +$attributes = array( + 'custom_design' => array( + 'group' => 'design', + 'sort' => 10 + ), +// 'custom_design_apply' => array( +// 'group' => 'design', +// 'sort' => 20 +// ), + 'custom_design_from' => array( + 'group' => 'design', + 'sort' => 30 + ), + 'custom_design_to' => array( + 'group' => 'design', + 'sort' => 40 + ), + 'page_layout' => array( + 'group' => 'design', + 'sort' => 50 + ), + 'custom_layout_update' => array( + 'group' => 'design', + 'sort' => 60 + ), + 'display_mode' => array( + 'group' => 'display', + 'sort' => 10 + ), + 'landing_page' => array( + 'group' => 'display', + 'sort' => 20 + ), + 'is_anchor' => array( + 'group' => 'display', + 'sort' => 30 + ), + 'available_sort_by' => array( + 'group' => 'display', + 'sort' => 40 + ), + 'default_sort_by' => array( + 'group' => 'display', + 'sort' => 50 + ), +); + +foreach ($attributes as $attributeCode => $attributeProp) { + $installer->addAttributeToGroup( + $entityTypeId, + $attributeSetId, + $groups[$attributeProp['group']]['id'], + $attributeCode, + $attributeProp['sort'] + ); +} + +/** + * Install product link types + */ +$data = array( + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED, + 'code' => 'relation' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, + 'code' => 'super' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL, + 'code' => 'up_sell' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL, + 'code' => 'cross_sell' + ), +); + +foreach ($data as $bind) { + $installer->getConnection()->insertForce($installer->getTable('catalog/product_link_type'), $bind); +} + +/** + * install product link attributes + */ +$data = array( + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, + 'product_link_attribute_code' => 'qty', + 'data_type' => 'decimal' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ), + array( + 'link_type_id' => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL, + 'product_link_attribute_code' => 'position', + 'data_type' => 'int' + ), +); + +$installer->getConnection()->insertMultiple($installer->getTable('catalog/product_link_attribute'), $data); + +/** + * Remove Catalog specified attribute options (columns) from eav/attribute table + * + */ +$describe = $installer->getConnection()->describeTable($installer->getTable('catalog/eav_attribute')); +foreach ($describe as $columnData) { + if ($columnData['COLUMN_NAME'] == 'attribute_id') { + continue; + } + $installer->getConnection()->dropColumn($installer->getTable('eav/attribute'), $columnData['COLUMN_NAME']); +} + diff --git a/app/code/core/Mage/Catalog/etc/adminhtml.xml b/app/code/core/Mage/Catalog/etc/adminhtml.xml index 753a1217ea..a4bd242d21 100644 --- a/app/code/core/Mage/Catalog/etc/adminhtml.xml +++ b/app/code/core/Mage/Catalog/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Catalog/etc/api.xml b/app/code/core/Mage/Catalog/etc/api.xml index 0888eab4a2..b90b159f7e 100644 --- a/app/code/core/Mage/Catalog/etc/api.xml +++ b/app/code/core/Mage/Catalog/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Catalog/etc/config.xml b/app/code/core/Mage/Catalog/etc/config.xml index 63909c43fa..f6674c03f4 100644 --- a/app/code/core/Mage/Catalog/etc/config.xml +++ b/app/code/core/Mage/Catalog/etc/config.xml @@ -21,17 +21,16 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.0.44 + 1.6.0.0 - @@ -39,8 +38,8 @@ 1 1 - - + + @@ -48,23 +47,23 @@ 1 1 - - + + 1 - - + + 1 1 - - + + @@ -72,8 +71,8 @@ 1 1 - - + + @@ -81,120 +80,253 @@ 1 1 - - + + 1 1 - - - - + + + + 1 1 - - + + 1 1 - - - - + + + + - - 1 - 1 - 1 - - 1 - 1 - 1 - 11 - 11 - 11 - 11 - 11 - 11 - 11 - - 1 - 11 - - 111 - 1 - 1 - 1 - - 1 - 11 - 11 - 1 - 1 - 1 - 1 - 1 - 11 + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + - Mage_Catalog_Model - catalog_resource_eav_mysql4 + catalog_resource - - - Mage_Catalog_Model_Resource_Eav_Mysql4 + + Mage_Catalog_Model_Resource + catalog_mysql4 - catalog_product_entity
- catalog_category_entity
- catalog_category_product
- catalog_category_product_index
- catalog_compare_item
- catalog_product_website
- catalog_product_enabled_index
- catalog_product_link_type
- catalog_product_link
- catalog_product_link_attribute
- catalog_product_link_attribute_decimal
- catalog_product_link_attribute_int
- catalog_product_link_attribute_varchar
- catalog_product_super_attribute
- catalog_product_super_attribute_label
- catalog_product_super_attribute_pricing
- catalog_product_super_link
- catalog_product_entity_tier_price
- catalog_product_entity_media_gallery
- catalog_product_entity_media_gallery_value
- catalog_product_option
- catalog_product_option_price
- catalog_product_option_title
- catalog_product_option_type_value
- catalog_product_option_type_price
- catalog_product_option_type_title
- catalog_category_flat
- catalog_product_flat
- catalog_eav_attribute
- catalog_product_relation
- catalog_product_index_eav
- catalog_product_index_eav_decimal
- catalog_product_index_price
- catalog_product_index_tier_price
- catalog_product_index_website
+ + catalog_product_entity
+
+ + catalog_category_entity
+
+ + catalog_category_product
+
+ + catalog_category_product_index
+
+ + catalog_compare_item
+
+ + catalog_product_website
+
+ + catalog_product_enabled_index
+
+ + catalog_product_link_type
+
+ + catalog_product_link
+
+ + catalog_product_link_attribute
+
+ + catalog_product_link_attribute_decimal
+
+ + catalog_product_link_attribute_int
+
+ + catalog_product_link_attribute_varchar
+
+ + catalog_product_super_attribute
+
+ + catalog_product_super_attribute_label
+
+ + catalog_product_super_attribute_pricing
+
+ + catalog_product_super_link
+
+ + catalog_product_entity_tier_price
+
+ + catalog_product_entity_media_gallery
+
+ + catalog_product_entity_media_gallery_value
+
+ + catalog_product_option
+
+ + catalog_product_option_price
+
+ + catalog_product_option_title
+
+ + catalog_product_option_type_value
+
+ + catalog_product_option_type_price
+
+ + catalog_product_option_type_title
+
+ + catalog_category_flat
+
+ + catalog_product_flat
+
+ + catalog_eav_attribute
+
+ + catalog_product_relation
+
+ + catalog_product_index_eav
+
+ + catalog_product_index_eav_decimal
+
+ + catalog_product_index_price
+
+ + catalog_product_index_tier_price
+
+ + catalog_product_index_website
+
catalog_product_index_price_cfg_opt_agr_idx
@@ -268,18 +400,20 @@ catalog_category_anc_products_index_tmp
-
+
Mage_Catalog - Mage_Catalog_Model_Resource_Eav_Mysql4_Setup + Mage_Catalog_Model_Resource_Setup - Mage_Catalog_Block + + Mage_Catalog_Block + @@ -304,122 +438,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -429,7 +447,6 @@ - @@ -474,7 +491,8 @@ container1 - + + container2 @@ -609,7 +627,6 @@ - @@ -677,42 +694,42 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + + + - 0 - grid-list 9,15,30 @@ -730,7 +747,6 @@ 2 - .html .html @@ -749,11 +765,6 @@ auto 100 - @@ -764,12 +775,15 @@ - - 0 2 * * * - catalog/product_indexer_price::reindexAll + + 0 2 * * * + + + catalog/product_indexer_price::reindexAll + diff --git a/app/code/core/Mage/Catalog/etc/convert.xml b/app/code/core/Mage/Catalog/etc/convert.xml index 00c5a017ed..d661e84f4a 100644 --- a/app/code/core/Mage/Catalog/etc/convert.xml +++ b/app/code/core/Mage/Catalog/etc/convert.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Catalog/etc/system.xml b/app/code/core/Mage/Catalog/etc/system.xml index 972ff2baf4..613ebfd61b 100644 --- a/app/code/core/Mage/Catalog/etc/system.xml +++ b/app/code/core/Mage/Catalog/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Catalog/etc/widget.xml b/app/code/core/Mage/Catalog/etc/widget.xml index 535d4bc560..e9e644136d 100644 --- a/app/code/core/Mage/Catalog/etc/widget.xml +++ b/app/code/core/Mage/Catalog/etc/widget.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/install-1.6.0.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..d0fe3dfb33 --- /dev/null +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/install-1.6.0.0.php @@ -0,0 +1,3190 @@ +startSetup(); + +/** + * Create table 'catalog/product' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Set ID') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => Mage_Catalog_Model_Product_Type::DEFAULT_TYPE, + ), 'Type ID') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'SKU') + ->addColumn('has_options', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Has Options') + ->addColumn('required_options', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Required Options') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Creation Time') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Update Time') + ->addIndex($installer->getIdxName('catalog/product', array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName('catalog/product', array('attribute_set_id')), + array('attribute_set_id')) + ->addIndex($installer->getIdxName('catalog/product', array('sku')), + array('sku')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product', + 'attribute_set_id', + 'eav/attribute_set', + 'attribute_set_id' + ), + 'attribute_set_id', $installer->getTable('eav/attribute_set'), 'attribute_set_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Table'); +$installer->getConnection()->createTable($table); + + + +/** + * Create table array('catalog/product', 'datetime') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'datetime'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'datetime'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'datetime'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'datetime'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'datetime'), array('entity_id')), + array('entity_id')) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'datetime'), + 'attribute_id', + 'eav/attribute', + 'attribute_id' + ), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'datetime'), + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'datetime'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Datetime Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/product', 'decimal') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'decimal'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'decimal'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'decimal'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'decimal'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'decimal'), array('attribute_id')), + array('attribute_id')) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'decimal'), + 'attribute_id', + 'eav/attribute', + 'attribute_id' + ), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'decimal'), + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName(array('catalog/product', 'decimal'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Decimal Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/product', 'int') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'int'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'int'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'int'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'int'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'int'), array('entity_id')), + array('entity_id')) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'int'), + 'attribute_id', + 'eav/attribute', + 'attribute_id' + ), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'int'), + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('catalog/product', 'int'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Integer Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/product', 'text') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'text'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'text'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'text'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'text'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'text'), array('entity_id')), + array('entity_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'text'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'text'), 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName(array('catalog/product', 'text'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Text Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/product', 'varchar') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'varchar'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'varchar'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'varchar'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'varchar'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'varchar'), array('entity_id')), + array('entity_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Varchar Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/product', 'gallery') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/product', 'gallery'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/product', 'gallery'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/product', 'gallery'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'gallery'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/product', 'gallery'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Gallery Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attriute Set ID') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Parent Category ID') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Creation Time') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Update Time') + ->addColumn('path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Tree Path') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Position') + ->addColumn('level', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Tree Level') + ->addColumn('children_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Child Count') + ->addIndex($installer->getIdxName('catalog/category', array('level')), + array('level')) + ->setComment('Catalog Category Table'); +$installer->getConnection()->createTable($table); + + +/** + * Create table array('catalog/category', 'datetime') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/category', 'datetime'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/category', 'datetime'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/category', 'datetime'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'datetime'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'datetime'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'entity_id', 'catalog/category', 'entity_id'), + 'entity_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Datetime Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/category', 'decimal') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/category', 'decimal'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/category', 'decimal'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/category', 'decimal'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'decimal'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'decimal'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'entity_id', 'catalog/category', 'entity_id'), + 'entity_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Decimal Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/category', 'int') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/category', 'int'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/category', 'int'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/category', 'int'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'int'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'int'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'entity_id', 'catalog/category', 'entity_id'), + 'entity_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Integer Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/category', 'text') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/category', 'text'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/category', 'text'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/category', 'text'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'text'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'text'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'entity_id', 'catalog/category', 'entity_id'), + 'entity_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Text Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('catalog/category', 'varchar') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('catalog/category', 'varchar'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + array('catalog/category', 'varchar'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName(array('catalog/category', 'varchar'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'varchar'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('catalog/category', 'varchar'), array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'entity_id', 'catalog/category', 'entity_id'), + 'entity_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Varchar Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Product ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Position') +/* ->addIndex($installer->getIdxName('catalog/category_product', array('category_id')), + array('category_id'))*/ + ->addIndex($installer->getIdxName('catalog/category_product', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('catalog/category_product', 'category_id', 'catalog/category', 'entity_id'), + 'category_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/category_product', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product To Category Linkage Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product_index' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product_index')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Product ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Position') + ->addColumn('is_parent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Parent') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Visibility') + ->addIndex( + $installer->getIdxName( + 'catalog/category_product_index', + array('product_id', 'store_id', 'category_id', 'visibility') + ), + array('product_id', 'store_id', 'category_id', 'visibility')) + ->addIndex( + $installer->getIdxName( + 'catalog/category_product_index', + array('store_id', 'category_id', 'visibility', 'is_parent', 'position') + ), + array('store_id', 'category_id', 'visibility', 'is_parent', 'position')) + ->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'category_id', 'catalog/category', 'entity_id'), + 'category_id', $installer->getTable('catalog/category'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Category Product Index'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/compare_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/compare_item')) + ->addColumn('catalog_compare_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Compare Item ID') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Visitor ID') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store ID') + ->addIndex($installer->getIdxName('catalog/compare_item', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('catalog/compare_item', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('catalog/compare_item', array('visitor_id', 'product_id')), + array('visitor_id', 'product_id')) + ->addIndex($installer->getIdxName('catalog/compare_item', array('customer_id', 'product_id')), + array('customer_id', 'product_id')) + ->addIndex($installer->getIdxName('catalog/compare_item', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('catalog/compare_item', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/compare_item', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/compare_item', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Compare Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_website' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_website')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addIndex($installer->getIdxName('catalog/product_website', array('website_id')), + array('website_id')) + ->addForeignKey($installer->getFkName('catalog/product_website', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_website', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product To Website Linkage Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_enabled_index' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_enabled_index')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Product ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Visibility') + ->addIndex($installer->getIdxName('catalog/product_enabled_index', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName('catalog/product_enabled_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/product_enabled_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Visibility Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link_type' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link_type')) + ->addColumn('link_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link Type ID') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => '', + ), 'Code') + ->setComment('Catalog Product Link Type Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link')) + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('linked_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Linked Product ID') + ->addColumn('link_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Link Type ID') + ->addIndex( + $installer->getIdxName( + 'catalog/product_link', + array('link_type_id', 'product_id', 'linked_product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('link_type_id', 'product_id', 'linked_product_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_link', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('catalog/product_link', array('linked_product_id')), + array('linked_product_id')) + ->addIndex($installer->getIdxName('catalog/product_link', array('link_type_id')), + array('link_type_id')) + ->addForeignKey( + $installer->getFkName('catalog/product_link', 'linked_product_id', 'catalog/product', 'entity_id'), + 'linked_product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/product_link', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/product_link', 'link_type_id', 'catalog/product_link_type', 'link_type_id'), + 'link_type_id', $installer->getTable('catalog/product_link_type'), 'link_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product To Product Linkage Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link_attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link_attribute')) + ->addColumn('product_link_attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Link Attribute ID') + ->addColumn('link_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Link Type ID') + ->addColumn('product_link_attribute_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => '', + ), 'Product Link Attribute Code') + ->addColumn('data_type', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => '', + ), 'Data Type') + ->addIndex($installer->getIdxName('catalog/product_link_attribute', array('link_type_id')), + array('link_type_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute', + 'link_type_id', + 'catalog/product_link_type', + 'link_type_id' + ), + 'link_type_id', $installer->getTable('catalog/product_link_type'), 'link_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Link Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link_attribute_decimal' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link_attribute_decimal')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('product_link_attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Product Link Attribute ID') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'unsigned' => true, + ), 'Link ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_link_attribute_decimal', array('product_link_attribute_id')), + array('product_link_attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_link_attribute_decimal', array('link_id')), + array('link_id')) + ->addIndex( + $installer->getIdxName( + 'catalog/product_link_attribute_decimal', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_decimal', + 'link_id', + 'catalog/product_link', + 'link_id' + ), + 'link_id', $installer->getTable('catalog/product_link'), 'link_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_decimal', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + 'product_link_attribute_id', $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Link Decimal Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link_attribute_int' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link_attribute_int')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('product_link_attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Product Link Attribute ID') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'unsigned' => true, + ), 'Link ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_link_attribute_int', array('product_link_attribute_id')), + array('product_link_attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_link_attribute_int', array('link_id')), + array('link_id')) + ->addIndex( + $installer->getIdxName( + 'catalog/product_link_attribute_int', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_int', + 'link_id', + 'catalog/product_link', + 'link_id' + ), + 'link_id', $installer->getTable('catalog/product_link'), 'link_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_int', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + 'product_link_attribute_id', $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Link Integer Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_link_attribute_varchar' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_link_attribute_varchar')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('product_link_attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Link Attribute ID') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'unsigned' => true, + ), 'Link ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_link_attribute_varchar', array('product_link_attribute_id')), + array('product_link_attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_link_attribute_varchar', array('link_id')), + array('link_id')) + ->addIndex( + $installer->getIdxName( + 'catalog/product_link_attribute_varchar', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_varchar', + 'link_id', + 'catalog/product_link', + 'link_id' + ), + 'link_id', $installer->getTable('catalog/product_link'), 'link_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_varchar', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + 'product_link_attribute_id', $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Link Varchar Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_super_attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_super_attribute')) + ->addColumn('product_super_attribute_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Super Attribute ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addIndex($installer->getIdxName('catalog/product_super_attribute', array('product_id')), + array('product_id')) + ->addForeignKey( + $installer->getFkName('catalog/product_super_attribute', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Catalog Product Super Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_super_attribute_label' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_super_attribute_label')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('product_super_attribute_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Super Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('use_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Use Default Value') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value') + ->addIndex( + $installer->getIdxName( + 'catalog/product_super_attribute_label', + array('product_super_attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_super_attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_super_attribute_label', array('product_super_attribute_id')), + array('product_super_attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_super_attribute_label', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_super_attribute_label', + 'product_super_attribute_id', + 'catalog/product_super_attribute', + 'product_super_attribute_id' + ), + 'product_super_attribute_id', $installer->getTable('catalog/product_super_attribute'), + 'product_super_attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('catalog/product_super_attribute_label', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Super Attribute Label Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_super_attribute_pricing' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_super_attribute_pricing')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('product_super_attribute_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Super Attribute ID') + ->addColumn('value_index', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Value Index') + ->addColumn('is_percent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Is Percent') + ->addColumn('pricing_value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Pricing Value') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website ID') + ->addIndex($installer->getIdxName('catalog/product_super_attribute_pricing', array('product_super_attribute_id')), + array('product_super_attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_super_attribute_pricing', array('website_id')), + array('website_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_super_attribute_pricing', + 'website_id', + 'core/website', + 'website_id' + ), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_super_attribute_pricing', + 'product_super_attribute_id', + 'catalog/product_super_attribute', + 'product_super_attribute_id' + ), + 'product_super_attribute_id', + $installer->getTable('catalog/product_super_attribute'), + 'product_super_attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Super Attribute Pricing Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_super_link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_super_link')) + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Parent ID') + ->addIndex($installer->getIdxName('catalog/product_super_link', array('parent_id')), + array('parent_id')) + ->addIndex($installer->getIdxName('catalog/product_super_link', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('catalog/product_super_link', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_super_link', 'parent_id', 'catalog/product', 'entity_id'), + 'parent_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Super Link Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_attribute_tier_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_attribute_tier_price')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('all_groups', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Applicable To All Customer Groups') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Group ID') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '1.0000', + ), 'QTY') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Value') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Website ID') + ->addIndex( + $installer->getIdxName( + 'catalog/product_attribute_tier_price', + array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_attribute_tier_price', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_attribute_tier_price', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalog/product_attribute_tier_price', array('website_id')), + array('website_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_tier_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_tier_price', + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_tier_price', + 'website_id', + 'core/website', + 'website_id' + ), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Tier Price Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_attribute_media_gallery' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_attribute_media_gallery')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute ID') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_attribute_media_gallery', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_attribute_media_gallery', array('entity_id')), + array('entity_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_media_gallery', + 'attribute_id', + 'eav/attribute', + 'attribute_id' + ), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_media_gallery', + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Media Gallery Attribute Backend Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_attribute_media_gallery_value' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_attribute_media_gallery_value')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Value ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store ID') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Label') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Position') + ->addColumn('disabled', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Disabled') + ->addIndex($installer->getIdxName('catalog/product_attribute_media_gallery_value', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_media_gallery_value', + 'value_id', + 'catalog/product_attribute_media_gallery', + 'value_id' + ), + 'value_id', $installer->getTable('catalog/product_attribute_media_gallery'), 'value_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_media_gallery_value', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Media Gallery Attribute Value Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Type') + ->addColumn('is_require', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Is Required') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'SKU') + ->addColumn('max_characters', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Max Characters') + ->addColumn('file_extension', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'File Extension') + ->addColumn('image_size_x', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Image Size X') + ->addColumn('image_size_y', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Image Size Y') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex($installer->getIdxName('catalog/product_option', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('catalog/product_option', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option_price')) + ->addColumn('option_price_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Price ID') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('price_type', Varien_Db_Ddl_Table::TYPE_TEXT, 7, array( + 'nullable' => false, + 'default' => 'fixed', + ), 'Price Type') + ->addIndex( + $installer->getIdxName( + 'catalog/product_option_price', + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_option_price', array('option_id')), + array('option_id')) + ->addIndex($installer->getIdxName('catalog/product_option_price', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_price', + 'option_id', + 'catalog/product_option', + 'option_id' + ), + 'option_id', $installer->getTable('catalog/product_option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_price', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Price Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option_title')) + ->addColumn('option_title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Title ID') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Title') + ->addIndex( + $installer->getIdxName( + 'catalog/product_option_title', + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_option_title', array('option_id')), + array('option_id')) + ->addIndex($installer->getIdxName('catalog/product_option_title', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_title', + 'option_id', + 'catalog/product_option', + 'option_id' + ), + 'option_id', $installer->getTable('catalog/product_option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_title', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Title Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option_type_value' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option_type_value')) + ->addColumn('option_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Type ID') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option ID') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'SKU') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex($installer->getIdxName('catalog/product_option_type_value', array('option_id')), + array('option_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_value', + 'option_id', + 'catalog/product_option', + 'option_id' + ), + 'option_id', $installer->getTable('catalog/product_option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Type Value Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option_type_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option_type_price')) + ->addColumn('option_type_price_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Type Price ID') + ->addColumn('option_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option Type ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('price_type', Varien_Db_Ddl_Table::TYPE_TEXT, 7, array( + 'nullable' => false, + 'default' => 'fixed', + ), 'Price Type') + ->addIndex( + $installer->getIdxName( + 'catalog/product_option_type_price', + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_type_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_option_type_price', array('option_type_id')), + array('option_type_id')) + ->addIndex($installer->getIdxName('catalog/product_option_type_price', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_price', + 'option_type_id', + 'catalog/product_option_type_value', + 'option_type_id' + ), + 'option_type_id', $installer->getTable('catalog/product_option_type_value'), 'option_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_price', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Type Price Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_option_type_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_option_type_title')) + ->addColumn('option_type_title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Type Title ID') + ->addColumn('option_type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option Type ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Title') + ->addIndex( + $installer->getIdxName( + 'catalog/product_option_type_title', + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_type_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalog/product_option_type_title', array('option_type_id')), + array('option_type_id')) + ->addIndex($installer->getIdxName('catalog/product_option_type_title', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_title', + 'option_type_id', + 'catalog/product_option_type_value', + 'option_type_id' + ), + 'option_type_id', $installer->getTable('catalog/product_option_type_value'), 'option_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_option_type_title', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Option Type Title Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/eav_attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/eav_attribute')) + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('frontend_input_renderer', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Frontend Input Renderer') + ->addColumn('is_global', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Global') + ->addColumn('is_visible', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Visible') + ->addColumn('is_searchable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Searchable') + ->addColumn('is_filterable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Filterable') + ->addColumn('is_comparable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Comparable') + ->addColumn('is_visible_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible On Front') + ->addColumn('is_html_allowed_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is HTML Allowed On Front') + ->addColumn('is_used_for_price_rules', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Used For Price Rules') + ->addColumn('is_filterable_in_search', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Filterable In Search') + ->addColumn('used_in_product_listing', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Used In Product Listing') + ->addColumn('used_for_sort_by', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Used For Sorting') + ->addColumn('is_configurable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Configurable') + ->addColumn('apply_to', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Apply To') + ->addColumn('is_visible_in_advanced_search', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible In Advanced Search') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('is_wysiwyg_enabled', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is WYSIWYG Enabled') + ->addColumn('is_used_for_promo_rules', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Used For Promo Rules') + ->addIndex($installer->getIdxName('catalog/eav_attribute', array('used_for_sort_by')), + array('used_for_sort_by')) + ->addIndex($installer->getIdxName('catalog/eav_attribute', array('used_in_product_listing')), + array('used_in_product_listing')) + ->addForeignKey($installer->getFkName('catalog/eav_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog EAV Attribute Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_relation' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_relation')) + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Parent ID') + ->addColumn('child_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Child ID') + ->addIndex($installer->getIdxName('catalog/product_relation', array('child_id')), + array('child_id')) + ->addForeignKey($installer->getFkName('catalog/product_relation', 'child_id', 'catalog/product', 'entity_id'), + 'child_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_relation', 'parent_id', 'catalog/product', 'entity_id'), + 'parent_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Relation Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_index_eav' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_index_eav')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_index_eav', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav', array('value')), + array('value')) + ->addForeignKey( + $installer->getFkName('catalog/product_index_eav', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_index_eav', 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('catalog/product_index_eav', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product EAV Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_index_eav_decimal' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_index_eav_decimal')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_index_eav_decimal', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav_decimal', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav_decimal', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_index_eav_decimal', array('value')), + array('value')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_eav_decimal', + 'attribute_id', + 'eav/attribute', + 'attribute_id' + ), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_eav_decimal', + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_eav_decimal', + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product EAV Decimal Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_index_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_index_price')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('final_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Final Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addIndex($installer->getIdxName('catalog/product_index_price', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalog/product_index_price', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('catalog/product_index_price', array('min_price')), + array('min_price')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_price', + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_price', + 'website_id', + 'core/website', + 'website_id' + ), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Price Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_index_tier_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_index_tier_price')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addIndex($installer->getIdxName('catalog/product_index_tier_price', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalog/product_index_tier_price', array('website_id')), + array('website_id')) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_tier_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_tier_price', + 'entity_id', + 'catalog/product', + 'entity_id' + ), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'catalog/product_index_tier_price', + 'website_id', + 'core/website', + 'website_id' + ), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Tier Price Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_index_website' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_index_website')) + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('website_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Website Date') + ->addColumn('rate', Varien_Db_Ddl_Table::TYPE_FLOAT, null, array( + 'default' => '1.0000', + ), 'Rate') + ->addIndex($installer->getIdxName('catalog/product_index_website', array('website_date')), + array('website_date')) + ->addForeignKey( + $installer->getFkName('catalog/product_index_website', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog Product Website Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_cfg_option_aggregate_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_cfg_option_aggregate_idx')) + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Parent ID') + ->addColumn('child_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Child ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Config Option Aggregate Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_cfg_option_aggregate_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_cfg_option_aggregate_tmp')) + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Parent ID') + ->addColumn('child_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Child ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Config Option Aggregate Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_cfg_option_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_cfg_option_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Config Option Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_cfg_option_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_cfg_option_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Config Option Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_final_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_final_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class ID') + ->addColumn('orig_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Original Price') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('base_tier', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tier') + ->setComment('Catalog Product Price Indexer Final Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_final_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_final_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class ID') + ->addColumn('orig_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Original Price') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addColumn('base_tier', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tier') + ->setComment('Catalog Product Price Indexer Final Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_option_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_option_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Option Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_option_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_option_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Option Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_option_aggregate_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_option_aggregate_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Option Aggregate Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_option_aggregate_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_option_aggregate_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Option ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->setComment('Catalog Product Price Indexer Option Aggregate Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_eav_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_eav_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_idx', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_idx', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_idx', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_idx', array('value')), + array('value')) + ->setComment('Catalog Product EAV Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_eav_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_eav_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_tmp', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_tmp', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_tmp', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_indexer_tmp', array('value')), + array('value')) + ->setComment('Catalog Product EAV Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_eav_decimal_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_eav_decimal_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('value')), + array('value')) + ->setComment('Catalog Product EAV Decimal Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_eav_decimal_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_eav_decimal_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'primary' => true, + ), 'Value') + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('value')), + array('value')) + ->setComment('Catalog Product EAV Decimal Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('final_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Final Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addIndex($installer->getIdxName('catalog/product_price_indexer_idx', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalog/product_price_indexer_idx', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('catalog/product_price_indexer_idx', array('min_price')), + array('min_price')) + ->setComment('Catalog Product Price Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/product_price_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/product_price_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Tax Class ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('final_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Final Price') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Min Price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Max Price') + ->addColumn('tier_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tier Price') + ->addIndex($installer->getIdxName('catalog/product_price_indexer_tmp', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalog/product_price_indexer_tmp', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('catalog/product_price_indexer_tmp', array('min_price')), + array('min_price')) + ->setComment('Catalog Product Price Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product_indexer_idx')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('is_parent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Parent') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Visibility') + ->addIndex( + $installer->getIdxName( + 'catalog/category_product_indexer_idx', + array('product_id', 'category_id', 'store_id') + ), + array('product_id', 'category_id', 'store_id')) + ->setComment('Catalog Category Product Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product_indexer_tmp')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Position') + ->addColumn('is_parent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Parent') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Visibility') + ->setComment('Catalog Category Product Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product_enabled_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product_enabled_indexer_idx')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Visibility') + ->addIndex($installer->getIdxName('catalog/category_product_enabled_indexer_idx', array('product_id')), + array('product_id')) + ->setComment('Catalog Category Product Enabled Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_product_enabled_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_product_enabled_indexer_tmp')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('visibility', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Visibility') + ->addIndex($installer->getIdxName('catalog/category_product_enabled_indexer_tmp', array('product_id')), + array('product_id')) + ->setComment('Catalog Category Product Enabled Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_anchor_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_anchor_indexer_idx')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Path') + ->addIndex($installer->getIdxName('catalog/category_anchor_indexer_idx', array('category_id')), + array('category_id')) + ->setComment('Catalog Category Anchor Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_anchor_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_anchor_indexer_tmp')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Path') + ->addIndex($installer->getIdxName('catalog/category_anchor_indexer_tmp', array('category_id')), + array('category_id')) + ->setComment('Catalog Category Anchor Indexer Temp Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_anchor_products_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_anchor_products_indexer_idx')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Position') + ->setComment('Catalog Category Anchor Product Indexer Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalog/category_anchor_products_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalog/category_anchor_products_indexer_tmp')) + ->addColumn('category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Category ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->setComment('Catalog Category Anchor Product Indexer Temp Table'); +$installer->getConnection()->createTable($table); + + +/** + * Modify core/url_rewrite table + * + */ +$installer->getConnection()->addColumn($installer->getTable('core/url_rewrite'), 'category_id', array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => true, + 'comment' => 'Category Id' +)); +$installer->getConnection()->addColumn($installer->getTable('core/url_rewrite'), 'product_id', array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => true, + 'comment' => 'Product Id' +)); +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/url_rewrite', 'category_id', 'catalog/category', 'entity_id'), + $installer->getTable('core/url_rewrite'), 'category_id', + $installer->getTable('catalog/category'), 'entity_id'); +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/url_rewrite', 'product_id', 'catalog/category', 'entity_id'), + $installer->getTable('core/url_rewrite'), 'product_id', + $installer->getTable('catalog/product'), 'entity_id'); + +$installer->endSetup(); + +$installer->installEntities(); diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.57-0.7.58.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.57-0.7.58.php new file mode 100644 index 0000000000..6feaaf30e9 --- /dev/null +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.57-0.7.58.php @@ -0,0 +1,153 @@ +getEntityTypeId('catalog_category'); +$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); +$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); + +// update General Group +$installer->updateAttributeGroup( + $entityTypeId, + $attributeSetId, + $attributeGroupId, + 'attribute_group_name', + 'General Information' +); +$installer->updateAttributeGroup( + $entityTypeId, + $attributeSetId, + $attributeGroupId, + 'sort_order', + '10' +); + +// Add groups +$groups = array( + 'display' => array( + 'name' => 'Display Settings', + 'sort' => 20, + 'id' => null + ), + 'design' => array( + 'name' => 'Custom Design', + 'sort' => 30, + 'id' => null + ) +); + +foreach ($groups as $k => $groupProp) { + //if ($k == 'display') continue; + //$installer->getConnection()->raw_query("INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`) VALUES (null, ".$attributeSetId.", '".$groupProp['name']."', ".$groupProp['sort'].");"); + $installer->addAttributeGroup($entityTypeId, $attributeSetId, $groupProp['name'], $groupProp['sort']); + $groups[$k]['id'] = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $groupProp['name']); +} + +// Add Catalog Default Sort Attributes +$installer->addAttribute($entityTypeId, 'available_sort_by', array( + 'input' => 'multiselect', + 'type' => 'text', + 'label' => 'Available Product Listing Sort By', + 'source' => 'catalog/category_attribute_source_sortby', + 'backend' => 'catalog/category_attribute_backend_sortby', + 'required' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => 1, + 'input_renderer'=> 'adminhtml/catalog_category_helper_sortby_available', +)); +$installer->addAttribute($entityTypeId, 'default_sort_by', array( + 'input' => 'select', + 'label' => 'Default Product Listing Sort By', + 'source' => 'catalog/category_attribute_source_sortby', + 'backend' => 'catalog/category_attribute_backend_sortby', + 'required' => 1, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => 1, + 'input_renderer'=> 'adminhtml/catalog_category_helper_sortby_default', +)); + +// update attributes group and sort +$attributes = array( + 'custom_design' => array( + 'group' => 'design', + 'sort' => 10 + ), + 'custom_design_apply' => array( + 'group' => 'design', + 'sort' => 20 + ), + 'custom_design_from' => array( + 'group' => 'design', + 'sort' => 30 + ), + 'custom_design_to' => array( + 'group' => 'design', + 'sort' => 40 + ), + 'page_layout' => array( + 'group' => 'design', + 'sort' => 50 + ), + 'custom_layout_update' => array( + 'group' => 'design', + 'sort' => 60 + ), + 'display_mode' => array( + 'group' => 'display', + 'sort' => 10 + ), + 'landing_page' => array( + 'group' => 'display', + 'sort' => 20 + ), + 'is_anchor' => array( + 'group' => 'display', + 'sort' => 30 + ), + 'available_sort_by' => array( + 'group' => 'display', + 'sort' => 40 + ), + 'default_sort_by' => array( + 'group' => 'display', + 'sort' => 50 + ), +); + +foreach ($attributes as $attributeCode => $attributeProp) { + $installer->addAttributeToGroup( + $entityTypeId, + $attributeSetId, + $groups[$attributeProp['group']]['id'], + $attributeCode, + $attributeProp['sort'] + ); +} +*/ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.63-0.7.64.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.63-0.7.64.php new file mode 100644 index 0000000000..1c76eae2e2 --- /dev/null +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-0.7.63-0.7.64.php @@ -0,0 +1,54 @@ +startSetup(); +/* +$installer->addAttribute('catalog_product', 'page_layout', array( + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Page Layout', + 'input' => 'select', + 'class' => '', + 'source' => 'catalog/product_attribute_source_layout', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => true, + 'required' => false, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'group' => 'Design' +)); + +$installer->endSetup(); +*/ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.28-1.4.0.0.29.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.28-1.4.0.0.29.php new file mode 100644 index 0000000000..3f05909063 --- /dev/null +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.28-1.4.0.0.29.php @@ -0,0 +1,100 @@ +startSetup(); + +$entityTypeId = $installer->getEntityTypeId('catalog_category'); +$designApplyAttributeId = $installer->getAttributeId($entityTypeId, 'custom_design_apply'); +$designAttributeId = $installer->getAttributeId($entityTypeId, 'custom_design'); +$catalogCategoryEntityIntTable = $installer->getAttributeTable($entityTypeId, $designApplyAttributeId); +$eavAttributeTable = $installer->getTable('eav/attribute'); + +$installer->addAttribute($entityTypeId, 'custom_use_parent_settings', array( + 'type' => 'int', + 'input' => 'select', + 'label' => 'Use Parent Category Settings', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => 0, + 'group' => 'Custom Design', + 'sort_order' => '5', + 'global' => 0 +)); +$installer->addAttribute($entityTypeId, 'custom_apply_to_products', array( + 'type' => 'int', + 'input' => 'select', + 'label' => 'Apply To Products', + 'source' => 'eav/entity_attribute_source_boolean', + 'required' => 0, + 'group' => 'Custom Design', + 'sort_order' => '6', + 'global' => 0 +)); +$useParentSettingsAttributeId = $installer->getAttributeId($entityTypeId, 'custom_use_parent_settings'); +$applyToProductsAttributeId = $installer->getAttributeId($entityTypeId, 'custom_apply_to_products'); + + + +$attributeIdExpr = new Zend_Db_Expr( + 'IF (e_a.attribute_id = e.attribute_id,'. + $useParentSettingsAttributeId.', '. + $applyToProductsAttributeId .')'); +$productValueExpr = new Zend_Db_Expr('IF (e.value IN (1,3), 1, 0)'); +$valueExpr = new Zend_Db_Expr('IF (e_a.attribute_id = e.attribute_id, 1, '. $productValueExpr .')'); +$select = $installer->getConnection()->select() + ->from( + array('e' => $catalogCategoryEntityIntTable), + array( + 'entity_type_id', + 'attribute_id' => $attributeIdExpr, + 'store_id', + 'entity_id', + 'value' => $valueExpr + ) + ) + ->joinCross( + array('e_a' => $eavAttributeTable), + array()) + ->where('e_a.attribute_id IN (?)', array($designApplyAttributeId, $designAttributeId)) + ->where('e.attribute_id = ?', $designApplyAttributeId) + ->order(array('e.entity_id', 'attribute_id')); + +$insertArray = array( + 'entity_type_id', + 'attribute_id', + 'store_id', + 'entity_id', + 'value' +); + +$sqlQuery = $select->insertFromSelect($catalogCategoryEntityIntTable, $insertArray, false); +$installer->getConnection()->query($sqlQuery); + +$installer->endSetup(); +*/ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php index d0ffeba93b..deddc36d25 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-data-upgrade-1.4.0.0.42-1.4.0.0.43.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-0.7.0.php index 4bae218f93..6bf2c410ec 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-1.4.0.0.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-1.4.0.0.0.php index 46aa147f1c..88d6979554 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-1.4.0.0.0.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-1.4.0.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.6.40-0.7.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.6.40-0.7.0.php index 157cd6eb5f..6e31c3ecb6 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.6.40-0.7.0.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.6.40-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.0-0.7.1.php index 7ab8c28b11..78c7d35ee4 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.1-0.7.2.php index 917d571aea..01fd6b9bf2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.11-0.7.12.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.11-0.7.12.php index b4dab7b943..53f4ae982c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.11-0.7.12.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.11-0.7.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.12-0.7.13.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.12-0.7.13.php index 460f9d0664..540e2fbef1 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.12-0.7.13.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.12-0.7.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.13-0.7.14.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.13-0.7.14.php index 94215d482b..7f2be06fa1 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.13-0.7.14.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.13-0.7.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.14-0.7.15.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.14-0.7.15.php index 416c242e95..abe09fc0c9 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.14-0.7.15.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.14-0.7.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $this->startSetup()->run(" diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.15-0.7.16.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.15-0.7.16.php index 32737f5a60..69a837124e 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.15-0.7.16.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.15-0.7.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.16-0.7.17.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.16-0.7.17.php index 460f9d0664..540e2fbef1 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.16-0.7.17.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.16-0.7.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.17-0.7.18.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.17-0.7.18.php index f821b97d8b..7c31310eb2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.17-0.7.18.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.17-0.7.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.18-0.7.19.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.18-0.7.19.php index 74fcc6d29b..d745f64557 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.18-0.7.19.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.18-0.7.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.19-0.7.20.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.19-0.7.20.php index b4dab7b943..53f4ae982c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.19-0.7.20.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.19-0.7.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.2-0.7.3.php index 69f1bf1341..fe4f27dcd1 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.20-0.7.21.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.20-0.7.21.php index 91915fc46d..72d8a63b4c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.20-0.7.21.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.20-0.7.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.21-0.7.22.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.21-0.7.22.php index c9a2e1e383..cb62213b4d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.21-0.7.22.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.21-0.7.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.22-0.7.23.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.22-0.7.23.php index 4460503a12..b8ea5e46a3 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.22-0.7.23.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.22-0.7.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.23-0.7.24.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.23-0.7.24.php index e96ce82e9e..9fbe3d7a11 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.23-0.7.24.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.23-0.7.24.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.24-0.7.25.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.24-0.7.25.php index 45fb3dd973..dbdf53a88d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.24-0.7.25.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.24-0.7.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.25-0.7.26.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.25-0.7.26.php index 45fb3dd973..dbdf53a88d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.25-0.7.26.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.25-0.7.26.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.26-0.7.27.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.26-0.7.27.php index cba27c31c0..01edee2106 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.26-0.7.27.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.26-0.7.27.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.27-0.7.28.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.27-0.7.28.php index 7751ae3ea1..de04c9e51f 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.27-0.7.28.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.27-0.7.28.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.28-0.7.29.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.28-0.7.29.php index 62a86cc842..0ba063d5c7 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.28-0.7.29.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.28-0.7.29.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.29-0.7.30.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.29-0.7.30.php index ffac7f5e6d..8c93dcf8dc 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.29-0.7.30.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.29-0.7.30.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.30-0.7.31.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.30-0.7.31.php index 31ba1c9675..a72ce9b841 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.30-0.7.31.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.30-0.7.31.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.31-0.7.32.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.31-0.7.32.php index 7fe37daba0..51d2b37087 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.31-0.7.32.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.31-0.7.32.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.32-0.7.33.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.32-0.7.33.php index bb8043a759..d92a1e2c51 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.32-0.7.33.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.32-0.7.33.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.33-0.7.34.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.33-0.7.34.php index 1306399a45..8b9b6be773 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.33-0.7.34.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.33-0.7.34.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -38,7 +38,7 @@ )) ->group('category_id') ->group('product_id') - ->having($installer->getConnection()->quoteInto('cnt > ?', 1)); + ->having('cnt > 1'); $rowSet = $installer->getConnection()->fetchAll($select); foreach ($rowSet as $row) { diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.34-0.7.35.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.34-0.7.35.php index 6af1399550..e1f48535d0 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.34-0.7.35.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.34-0.7.35.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.35-0.7.36.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.35-0.7.36.php index c85e65dbc6..a3789d007d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.35-0.7.36.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.35-0.7.36.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.36-0.7.37.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.36-0.7.37.php index a50f2721ae..31dc90572d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.36-0.7.37.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.36-0.7.37.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.37-0.7.38.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.37-0.7.38.php index 5a651b1c2f..3155815a04 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.37-0.7.38.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.37-0.7.38.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.38-0.7.39.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.38-0.7.39.php index b6d4f2fcf2..fd32195db2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.38-0.7.39.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.38-0.7.39.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.39-0.7.40.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.39-0.7.40.php index aa52128ef6..2ab0af7b32 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.39-0.7.40.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.39-0.7.40.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.4-0.7.5.php index e1e67e7f9d..35b3cc6ef8 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.40-0.7.41.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.40-0.7.41.php index d31b7a620e..fa4ab4206c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.40-0.7.41.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.40-0.7.41.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.41-0.7.42.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.41-0.7.42.php index 719e502796..da47025772 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.41-0.7.42.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.41-0.7.42.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.43-0.7.44.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.43-0.7.44.php index dc37803394..0034e6b0d4 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.43-0.7.44.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.43-0.7.44.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.44-0.7.45.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.44-0.7.45.php index 867fa10a42..89f50a37c9 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.44-0.7.45.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.44-0.7.45.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.45-0.7.46.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.45-0.7.46.php index f99d36d8ba..74447cf2f6 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.45-0.7.46.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.45-0.7.46.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.46-0.7.47.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.46-0.7.47.php index f1aecf086a..60408d785c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.46-0.7.47.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.46-0.7.47.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.47-0.7.48.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.47-0.7.48.php index e10bd74748..bda58a54f0 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.47-0.7.48.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.47-0.7.48.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.48-0.7.49.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.48-0.7.49.php index b76f6b1529..78b85584a4 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.48-0.7.49.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.48-0.7.49.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.49-0.7.50.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.49-0.7.50.php index 488eebd572..bf781a972d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.49-0.7.50.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.49-0.7.50.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.5-0.7.6.php index c50a94c895..67e9e1381d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.50-0.7.51.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.50-0.7.51.php index 45d0fa02ee..df5054c58e 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.50-0.7.51.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.50-0.7.51.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.51-0.7.52.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.51-0.7.52.php index d9ac5b5f34..8ae585a8fe 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.51-0.7.52.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.51-0.7.52.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.52-0.7.53.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.52-0.7.53.php index ad3e23f2bd..4eb59833f2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.52-0.7.53.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.52-0.7.53.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.53-0.7.54.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.53-0.7.54.php index 3524725466..af53b6ec0a 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.53-0.7.54.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.53-0.7.54.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.54-0.7.55.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.54-0.7.55.php index e822f2a614..843366d7fb 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.54-0.7.55.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.54-0.7.55.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.55-0.7.56.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.55-0.7.56.php index 4a809c59b0..134c00b270 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.55-0.7.56.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.55-0.7.56.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.56-0.7.57.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.56-0.7.57.php index 807fa1f4bc..c005fce7c7 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.56-0.7.57.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.56-0.7.57.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.57-0.7.58.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.57-0.7.58.php index bb220f8f88..50adf24602 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.57-0.7.58.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.57-0.7.58.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -29,6 +29,13 @@ $installer->startSetup(); +/* + * Fix unknown issue on MySQL 4.1.x, + * After removing foreign key on some table and try to insert data to other table with auto increment on primary key + * DB engine generates "Duplicate entry '1' for key 1" error + */ +$installer->getConnection()->closeConnection(); + // Add listing and sort attribute properties $installer->getConnection()->addColumn( $installer->getTable('eav/attribute'), diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.58-0.7.59.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.58-0.7.59.php index d3cdd2acec..8ff901af30 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.58-0.7.59.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.58-0.7.59.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.59-0.7.60.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.59-0.7.60.php index 7f6050bbd3..d498d02ba2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.59-0.7.60.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.59-0.7.60.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.6-0.7.7.php index b4dab7b943..53f4ae982c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.60-0.7.61.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.60-0.7.61.php index 910c6bc598..b6a529848c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.60-0.7.61.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.60-0.7.61.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.61-0.7.62.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.61-0.7.62.php index 0efd8eb23a..439a634622 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.61-0.7.62.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.61-0.7.62.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.62-0.7.63.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.62-0.7.63.php index 85069d55dc..1941f598bc 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.62-0.7.63.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.62-0.7.63.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.63-0.7.64.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.63-0.7.64.php index 4adf074866..13cd7213cc 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.63-0.7.64.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.63-0.7.64.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.64-0.7.65.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.64-0.7.65.php index ca168561b7..3ae3beda42 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.64-0.7.65.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.64-0.7.65.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.65-0.7.66.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.65-0.7.66.php index 8b61bef664..064a314d71 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.65-0.7.66.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.65-0.7.66.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.66-0.7.67.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.66-0.7.67.php index 22a1f03e68..037affdb44 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.66-0.7.67.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.66-0.7.67.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.67-0.7.68.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.67-0.7.68.php index ef5584aa55..3e5faed8eb 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.67-0.7.68.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.67-0.7.68.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.68-0.7.69.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.68-0.7.69.php index 04d0572a93..1116f829b5 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.68-0.7.69.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.68-0.7.69.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.69-0.7.70.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.69-0.7.70.php index de0c9f94f4..2cf711ebb5 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.69-0.7.70.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.69-0.7.70.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.7-0.7.8.php index 4eb2d388cf..690f41ec23 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.70-0.7.71.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.70-0.7.71.php index 7506963f29..52699ea1c1 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.70-0.7.71.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.70-0.7.71.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.71-0.7.72.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.71-0.7.72.php index b8178d6c85..371602cbdd 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.71-0.7.72.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.71-0.7.72.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.72-0.7.73.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.72-0.7.73.php index 243e3db042..43b803768a 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.72-0.7.73.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.72-0.7.73.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.73-1.4.0.0.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.73-1.4.0.0.0.php index 60102b12bd..279ac3e1c2 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.73-1.4.0.0.0.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.73-1.4.0.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.8-0.7.9.php index 2c0255d7d9..90e011788f 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php index 7430222c7f..a9841093ac 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php index ca8238bf8b..104b1405db 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.10-1.4.0.0.11.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.10-1.4.0.0.11.php index 3653938b5d..2477bba491 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.10-1.4.0.0.11.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.10-1.4.0.0.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.11-1.4.0.0.12.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.11-1.4.0.0.12.php index b78f997e9d..8db9134557 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.11-1.4.0.0.12.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.11-1.4.0.0.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.12-1.4.0.0.13.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.12-1.4.0.0.13.php index 5933a983a4..9d59d50359 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.12-1.4.0.0.13.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.12-1.4.0.0.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.13-1.4.0.0.14.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.13-1.4.0.0.14.php index 42c020a21c..c8013e91bd 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.13-1.4.0.0.14.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.13-1.4.0.0.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.14-1.4.0.0.15.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.14-1.4.0.0.15.php index f841f1d336..76dfc35c19 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.14-1.4.0.0.15.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.14-1.4.0.0.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.15-1.4.0.0.16.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.15-1.4.0.0.16.php index 4f91101b7f..c3e37708f7 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.15-1.4.0.0.16.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.15-1.4.0.0.16.php @@ -20,6 +20,6 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.16-1.4.0.0.17.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.16-1.4.0.0.17.php index b7e8abbb5f..de686afb13 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.16-1.4.0.0.17.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.16-1.4.0.0.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.17-1.4.0.0.18.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.17-1.4.0.0.18.php index 528e264fe7..3071c0117a 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.17-1.4.0.0.18.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.17-1.4.0.0.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.18-1.4.0.0.19.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.18-1.4.0.0.19.php index 8931f5c9c6..25feae14c4 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.18-1.4.0.0.19.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.18-1.4.0.0.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.19-1.4.0.0.20.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.19-1.4.0.0.20.php index 390623b1b5..88f3d1ac7e 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.19-1.4.0.0.20.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.19-1.4.0.0.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php index 975eff3398..8ab4cfc1d6 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.20-1.4.0.0.21.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.20-1.4.0.0.21.php index 12291b37e6..5ca7ebe451 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.20-1.4.0.0.21.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.20-1.4.0.0.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.21-1.4.0.0.22.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.21-1.4.0.0.22.php index 006cb5783f..6fbc9cf2eb 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.21-1.4.0.0.22.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.21-1.4.0.0.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.22-1.4.0.0.23.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.22-1.4.0.0.23.php index ade1be567c..3216db631a 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.22-1.4.0.0.23.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.22-1.4.0.0.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.23-1.4.0.0.24.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.23-1.4.0.0.24.php index 847f0fb042..9f9ccbe190 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.23-1.4.0.0.24.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.23-1.4.0.0.24.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.24-1.4.0.0.25.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.24-1.4.0.0.25.php index 8dae940ebf..4d33dba8f5 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.24-1.4.0.0.25.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.24-1.4.0.0.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.25-1.4.0.0.26.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.25-1.4.0.0.26.php index 9918049826..b40ff8e5f9 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.25-1.4.0.0.26.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.25-1.4.0.0.26.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.26-1.4.0.0.27.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.26-1.4.0.0.27.php index 55de68a78b..a289453e05 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.26-1.4.0.0.27.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.26-1.4.0.0.27.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.27-1.4.0.0.28.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.27-1.4.0.0.28.php index de5565a17f..02b947582b 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.27-1.4.0.0.28.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.27-1.4.0.0.28.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.28-1.4.0.0.29.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.28-1.4.0.0.29.php index ec3974fdde..4cde6df1a0 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.28-1.4.0.0.29.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.28-1.4.0.0.29.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php index 03504dc52a..a91dc113a8 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.30-1.4.0.0.31.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.30-1.4.0.0.31.php index 0411fac099..b700014d1f 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.30-1.4.0.0.31.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.30-1.4.0.0.31.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.31-1.4.0.0.32.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.31-1.4.0.0.32.php index 65692d1768..046bdbf242 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.31-1.4.0.0.32.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.31-1.4.0.0.32.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.32-1.4.0.0.33.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.32-1.4.0.0.33.php index 126bbe7054..a643d749cf 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.32-1.4.0.0.33.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.32-1.4.0.0.33.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.33-1.4.0.0.34.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.33-1.4.0.0.34.php index 67abc28bfe..9836d22647 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.33-1.4.0.0.34.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.33-1.4.0.0.34.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.34-1.4.0.0.35.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.34-1.4.0.0.35.php index 93a766ecb4..98241accba 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.34-1.4.0.0.35.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.34-1.4.0.0.35.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.35-1.4.0.0.36.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.35-1.4.0.0.36.php index 16d5ab491a..b33ceb4e93 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.35-1.4.0.0.36.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.35-1.4.0.0.36.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.36-1.4.0.0.37.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.36-1.4.0.0.37.php index 1e28615552..567fcf53be 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.36-1.4.0.0.37.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.36-1.4.0.0.37.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.37-1.4.0.0.38.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.37-1.4.0.0.38.php index bedd8d98d5..792468a94e 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.37-1.4.0.0.38.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.37-1.4.0.0.38.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.38-1.4.0.0.39.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.38-1.4.0.0.39.php index 05d539ad21..e9c4800c03 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.38-1.4.0.0.39.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.38-1.4.0.0.39.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.39-1.4.0.0.40.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.39-1.4.0.0.40.php index fdbbe38a5a..2aacd514c7 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.39-1.4.0.0.40.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.39-1.4.0.0.40.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php index 990f720b85..0e538319bd 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.40-1.4.0.0.41.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.40-1.4.0.0.41.php index fa3c51535d..0550111a49 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.40-1.4.0.0.41.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.40-1.4.0.0.41.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.41-1.4.0.0.42.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.41-1.4.0.0.42.php index 5ba4473bb1..e72953925d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.41-1.4.0.0.42.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.41-1.4.0.0.42.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.43-1.4.0.0.44.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.43-1.4.0.0.44.php index d2c48cdb46..64738d26ba 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.43-1.4.0.0.44.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.43-1.4.0.0.44.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php index 78f67f6c33..cf41288ac9 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.6-1.4.0.0.7.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.6-1.4.0.0.7.php index 0e1a5f90b8..80f263bb08 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.6-1.4.0.0.7.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.6-1.4.0.0.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php index 2bfaf600d2..3246f8712c 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.8-1.4.0.0.9.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.8-1.4.0.0.9.php index 734d964217..1c27fd369d 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.8-1.4.0.0.9.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.8-1.4.0.0.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.9-1.4.0.0.10.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.9-1.4.0.0.10.php index 70488d33da..56c56f08ff 100644 --- a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.9-1.4.0.0.10.php +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.4.0.0.9-1.4.0.0.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..2b12fbec2b --- /dev/null +++ b/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,6068 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/category_product'), + 'CATALOG_CATEGORY_PRODUCT_CATEGORY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/category_product'), + 'CATALOG_CATEGORY_PRODUCT_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/category_product_index'), + 'FK_CATALOG_CATEGORY_PROD_IDX_CATEGORY_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/category_product_index'), + 'FK_CATALOG_CATEGORY_PROD_IDX_PROD_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/category_product_index'), + 'FK_CATEGORY_PRODUCT_INDEX_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/eav_attribute'), + 'FK_CATALOG_EAV_ATTRIBUTE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_enabled_index'), + 'FK_CATALOG_PRODUCT_ENABLED_INDEX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_enabled_index'), + 'FK_CATALOG_PRODUCT_ENABLED_INDEX_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product'), + 'FK_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product'), + 'FK_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_media_gallery'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_media_gallery'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_media_gallery_value'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_VALUE_GALLERY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_media_gallery_value'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_VALUE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PRODUCT_ENTITY_TIER_PRICE_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PRODUCT_TIER_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PROD_ENTITY_TIER_PRICE_PROD_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav_decimal'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav_decimal'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_DECIMAL_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_eav_decimal'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_DECIMAL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_tier_price'), + 'FK_CATALOG_PRODUCT_INDEX_TIER_PRICE_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_tier_price'), + 'FK_CATALOG_PRODUCT_INDEX_TIER_PRICE_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_tier_price'), + 'FK_CATALOG_PRODUCT_INDEX_TIER_PRICE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_index_website'), + 'FK_CATALOG_PRODUCT_INDEX_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link'), + 'FK_PRODUCT_LINK_LINKED_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link'), + 'FK_PRODUCT_LINK_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link'), + 'FK_PRODUCT_LINK_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute'), + 'FK_ATTRIBUTE_PRODUCT_LINK_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_decimal'), + 'FK_DECIMAL_LINK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_decimal'), + 'FK_DECIMAL_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_int'), + 'FK_INT_PRODUCT_LINK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_int'), + 'FK_INT_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_varchar'), + 'FK_VARCHAR_LINK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_link_attribute_varchar'), + 'FK_VARCHAR_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option'), + 'FK_CATALOG_PRODUCT_OPTION_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_price'), + 'FK_CATALOG_PRODUCT_OPTION_PRICE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_price'), + 'FK_CATALOG_PRODUCT_OPTION_PRICE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_title'), + 'FK_CATALOG_PRODUCT_OPTION_TITLE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_title'), + 'FK_CATALOG_PRODUCT_OPTION_TITLE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_type_price'), + 'FK_CATALOG_PRODUCT_OPTION_TYPE_PRICE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_type_price'), + 'FK_CATALOG_PRODUCT_OPTION_TYPE_PRICE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_type_title'), + 'FK_CATALOG_PRODUCT_OPTION_TYPE_TITLE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_type_title'), + 'FK_CATALOG_PRODUCT_OPTION_TYPE_TITLE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_option_type_value'), + 'FK_CATALOG_PRODUCT_OPTION_TYPE_VALUE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_relation'), + 'FK_CATALOG_PRODUCT_RELATION_CHILD' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_relation'), + 'FK_CATALOG_PRODUCT_RELATION_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute'), + 'FK_SUPER_PRODUCT_ATTRIBUTE_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute_label'), + 'FK_CATALOG_PROD_SUPER_ATTR_LABEL_ATTR' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute_label'), + 'FK_CATALOG_PROD_SUPER_ATTR_LABEL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'CATALOG_PRODUCT_SUPER_ATTRIBUTE_PRICING_IBFK_1' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'FK_CATALOG_PRODUCT_SUPER_PRICE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'FK_SUPER_PRODUCT_ATTRIBUTE_PRICING' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_link'), + 'CATALOG_PRODUCT_SUPER_LINK_IBFK_1' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_link'), + 'CATALOG_PRODUCT_SUPER_LINK_IBFK_2' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_link'), + 'FK_SUPER_PRODUCT_LINK_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_super_link'), + 'FK_SUPER_PRODUCT_LINK_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_website'), + 'FK_CATALOG_PRODUCT_WEBSITE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalog/product_website'), + 'FK_CATALOG_WEBSITE_PRODUCT_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_CATALOG_CATEGORY_ENTITY_DATETIME_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_CATALOG_CATEGORY_ENTITY_DATETIME_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_CATALOG_CATEGORY_ENTITY_DATETIME_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_CATALOG_CATEGORY_ENTITY_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_CATALOG_CATEGORY_ENTITY_DECIMAL_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_CATALOG_CATEGORY_ENTITY_DECIMAL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'int')), + 'FK_CATALOG_CATEGORY_EMTITY_INT_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'int')), + 'FK_CATALOG_CATEGORY_EMTITY_INT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'int')), + 'FK_CATALOG_CATEGORY_EMTITY_INT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'text')), + 'FK_CATALOG_CATEGORY_ENTITY_TEXT_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'text')), + 'FK_CATALOG_CATEGORY_ENTITY_TEXT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'text')), + 'FK_CATALOG_CATEGORY_ENTITY_TEXT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_CATALOG_CATEGORY_ENTITY_VARCHAR_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PRODUCT_ENTITY_DATETIME_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PROD_ENTITY_DATETIME_PROD_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PRODUCT_ENTITY_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PRODUCT_ENTITY_DECIMAL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PROD_ENTITY_DECIMAL_PROD_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_CATALOG_PRODUCT_ENTITY_GALLERY_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_CATALOG_PRODUCT_ENTITY_GALLERY_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_CATALOG_PRODUCT_ENTITY_GALLERY_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PROD_ENTITY_VARCHAR_PROD_ENTITY' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute'), + 'IDX_USED_FOR_SORT_BY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute'), + 'IDX_USED_IN_PRODUCT_LISTING' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_anchor_indexer_idx'), + 'IDX_CATEGORY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_anchor_indexer_tmp'), + 'IDX_CATEGORY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category'), + 'IDX_LEVEL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product'), + 'UNQ_CATEGORY_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product'), + 'CATALOG_CATEGORY_PRODUCT_CATEGORY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product'), + 'CATALOG_CATEGORY_PRODUCT_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_index'), + 'UNQ_CATEGORY_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_index'), + 'FK_CATALOG_CATEGORY_PRODUCT_INDEX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_index'), + 'FK_CATALOG_CATEGORY_PRODUCT_INDEX_CATEGORY_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_index'), + 'IDX_JOIN' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_index'), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_enabled_indexer_idx'), + 'IDX_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_enabled_indexer_tmp'), + 'IDX_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/category_product_indexer_idx'), + 'IDX_PRODUCT_CATEGORY_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/compare_item'), + 'IDX_VISITOR_PRODUCTS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/compare_item'), + 'IDX_CUSTOMER_PRODUCTS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/compare_item'), + 'FK_CATALOG_COMPARE_ITEM_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/eav_attribute'), + 'IDX_USED_FOR_SORT_BY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/eav_attribute'), + 'IDX_USED_IN_PRODUCT_LISTING' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_enabled_index'), + 'UNQ_PRODUCT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_enabled_index'), + 'IDX_PRODUCT_VISIBILITY_IN_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_enabled_index'), + 'FK_CATALOG_PRODUCT_ENABLED_INDEX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product'), + 'FK_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product'), + 'FK_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product'), + 'SKU' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_media_gallery'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_media_gallery'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_media_gallery_value'), + 'FK_CATALOG_PRODUCT_MEDIA_GALLERY_VALUE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + 'UNQ_CATALOG_PRODUCT_TIER_PRICE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PRODUCT_ENTITY_TIER_PRICE_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PRODUCT_ENTITY_TIER_PRICE_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + 'FK_CATALOG_PRODUCT_TIER_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + 'IDX_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + 'IDX_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + 'IDX_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_price'), + 'IDX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_price'), + 'IDX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_price'), + 'IDX_MIN_PRICE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + 'IDX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + 'IDX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + 'IDX_MIN_PRICE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + 'IDX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + 'IDX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + 'IDX_MIN_PRICE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_tier_price'), + 'FK_CATALOG_PRODUCT_INDEX_TIER_PRICE_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_tier_price'), + 'FK_CATALOG_PRODUCT_INDEX_TIER_PRICE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_index_website'), + 'IDX_DATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link'), + 'IDX_UNIQUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link'), + 'FK_LINK_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link'), + 'FK_LINKED_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link'), + 'FK_PRODUCT_LINK_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute'), + 'FK_ATTRIBUTE_PRODUCT_LINK_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_decimal'), + 'FK_DECIMAL_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_decimal'), + 'FK_DECIMAL_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_int'), + 'UNQ_PRODUCT_LINK_ATTRIBUTE_ID_LINK_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_int'), + 'FK_INT_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_int'), + 'FK_INT_PRODUCT_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_varchar'), + 'FK_VARCHAR_PRODUCT_LINK_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_link_attribute_varchar'), + 'FK_VARCHAR_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option'), + 'CATALOG_PRODUCT_OPTION_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_price'), + 'UNQ_OPTION_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_price'), + 'CATALOG_PRODUCT_OPTION_PRICE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_price'), + 'CATALOG_PRODUCT_OPTION_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_title'), + 'UNQ_OPTION_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_title'), + 'CATALOG_PRODUCT_OPTION_TITLE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_title'), + 'CATALOG_PRODUCT_OPTION_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_price'), + 'UNQ_OPTION_TYPE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_price'), + 'CATALOG_PRODUCT_OPTION_TYPE_PRICE_OPTION_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_price'), + 'CATALOG_PRODUCT_OPTION_TYPE_PRICE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_title'), + 'UNQ_OPTION_TYPE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_title'), + 'CATALOG_PRODUCT_OPTION_TYPE_TITLE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_title'), + 'CATALOG_PRODUCT_OPTION_TYPE_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_option_type_value'), + 'CATALOG_PRODUCT_OPTION_TYPE_VALUE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_relation'), + 'IDX_CHILD' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute'), + 'UNQ_PRODUCT_ID_ATTRIBUTE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute'), + 'FK_SUPER_PRODUCT_ATTRIBUTE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_label'), + 'FK_CATALOG_PRODUCT_SUPER_ATTRIBUTE_LABEL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_label'), + 'UNQ_ATTRIBUTE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_label'), + 'FK_SUPER_PRODUCT_ATTRIBUTE_LABEL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_label'), + 'FK_CATALOG_PROD_SUPER_ATTR_LABEL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'UNQ_PRODUCT_SUPER_ATTRIBUTE_ID_VALUE_INDEX_WEBSITE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'FK_SUPER_PRODUCT_ATTRIBUTE_PRICING' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + 'FK_CATALOG_PRODUCT_SUPER_PRICE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_link'), + 'UNQ_PRODUCT_ID_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_link'), + 'FK_SUPER_PRODUCT_LINK_PARENT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_super_link'), + 'FK_CATALOG_PRODUCT_SUPER_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalog/product_website'), + 'FK_CATALOG_PRODUCT_WEBSITE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'datetime')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_ATTRIBUTE_DATETIME_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_CATALOG_CATEGORY_ENTITY_DATETIME_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'datetime')), + 'FK_CATALOG_CATEGORY_ENTITY_DATETIME_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'decimal')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_ATTRIBUTE_DECIMAL_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_CATALOG_CATEGORY_ENTITY_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'decimal')), + 'FK_CATALOG_CATEGORY_ENTITY_DECIMAL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'int')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'int')), + 'FK_ATTRIBUTE_INT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'int')), + 'FK_CATALOG_CATEGORY_EMTITY_INT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'int')), + 'FK_CATALOG_CATEGORY_EMTITY_INT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'text')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'text')), + 'FK_ATTRIBUTE_TEXT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'text')), + 'FK_CATALOG_CATEGORY_ENTITY_TEXT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'text')), + 'FK_CATALOG_CATEGORY_ENTITY_TEXT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'varchar')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_ATTRIBUTE_VARCHAR_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/category', 'varchar')), + 'FK_CATALOG_CATEGORY_ENTITY_VARCHAR_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'datetime')), + 'IDX_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PRODUCT_ENTITY_DATETIME_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'datetime')), + 'FK_CATALOG_PRODUCT_ENTITY_DATETIME_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'decimal')), + 'IDX_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PRODUCT_ENTITY_DECIMAL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PRODUCT_ENTITY_DECIMAL_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'decimal')), + 'FK_CATALOG_PRODUCT_ENTITY_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'gallery')), + 'IDX_BASE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_ATTRIBUTE_GALLERY_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_CATALOG_CATEGORY_ENTITY_GALLERY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'gallery')), + 'FK_CATALOG_CATEGORY_ENTITY_GALLERY_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'int')), + 'IDX_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'int')), + 'FK_CATALOG_PRODUCT_ENTITY_INT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'text')), + 'IDX_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'text')), + 'FK_CATALOG_PRODUCT_ENTITY_TEXT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'varchar')), + 'IDX_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('catalog/product', 'varchar')), + 'FK_CATALOG_PRODUCT_ENTITY_VARCHAR_PRODUCT_ENTITY' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('catalog/product') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type ID' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Set ID' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'default' => 'simple', + 'comment' => 'Type ID' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'SKU' + ), + 'has_options' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Has Options' + ), + 'required_options' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Required Options' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Creation Time' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Update Time' + ) + ), + 'comment' => 'Catalog Product Table' + ), + $installer->getTable('catalog/category') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type ID' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attriute Set ID' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent Category ID' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Creation Time' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Update Time' + ), + 'path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Tree Path' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'level' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Tree Level' + ), + 'children_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Child Count' + ) + ), + 'comment' => 'Catalog Category Table' + ), + $installer->getTable('catalog/category_product') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ) + ), + 'comment' => 'Catalog Product To Category Linkage Table' + ), + $installer->getTable('catalog/category_product_index') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Position' + ), + 'is_parent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Parent' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Category Product Index' + ), + $installer->getTable('catalog/compare_item') => array( + 'columns' => array( + 'catalog_compare_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Compare Item ID' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visitor ID' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store ID' + ) + ), + 'comment' => 'Catalog Compare Table' + ), + $installer->getTable('catalog/product_website') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ) + ), + 'comment' => 'Catalog Product To Website Linkage Table' + ), + $installer->getTable('catalog/product_enabled_index') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Product Visibility Index Table' + ), + $installer->getTable('catalog/product_link_type') => array( + 'columns' => array( + 'link_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link Type ID' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Code' + ) + ), + 'comment' => 'Catalog Product Link Type Table' + ), + $installer->getTable('catalog/product_link') => array( + 'columns' => array( + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'linked_product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Linked Product ID' + ), + 'link_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link Type ID' + ) + ), + 'comment' => 'Catalog Product To Product Linkage Table' + ), + $installer->getTable('catalog/product_link_attribute') => array( + 'columns' => array( + 'product_link_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Link Attribute ID' + ), + 'link_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link Type ID' + ), + 'product_link_attribute_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Product Link Attribute Code' + ), + 'data_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Data Type' + ) + ), + 'comment' => 'Catalog Product Link Attribute Table' + ), + $installer->getTable('catalog/product_link_attribute_decimal') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'product_link_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Product Link Attribute ID' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Link Decimal Attribute Table' + ), + $installer->getTable('catalog/product_link_attribute_int') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'product_link_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Product Link Attribute ID' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Link Integer Attribute Table' + ), + $installer->getTable('catalog/product_link_attribute_varchar') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'product_link_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Link Attribute ID' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Link Varchar Attribute Table' + ), + $installer->getTable('catalog/product_super_attribute') => array( + 'columns' => array( + 'product_super_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Super Attribute ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ) + ), + 'comment' => 'Catalog Product Super Attribute Table' + ), + $installer->getTable('catalog/product_super_attribute_label') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'product_super_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Super Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'use_default' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Use Default Value' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Super Attribute Label Table' + ), + $installer->getTable('catalog/product_super_attribute_pricing') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'product_super_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Super Attribute ID' + ), + 'value_index' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Value Index' + ), + 'is_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Is Percent' + ), + 'pricing_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Pricing Value' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website ID' + ) + ), + 'comment' => 'Catalog Product Super Attribute Pricing Table' + ), + $installer->getTable('catalog/product_super_link') => array( + 'columns' => array( + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent ID' + ) + ), + 'comment' => 'Catalog Product Super Link Table' + ), + $installer->getTable('catalog/product_attribute_tier_price') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'all_groups' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Applicable To All Customer Groups' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '1.0000', + 'comment' => 'QTY' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Value' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website ID' + ) + ), + 'comment' => 'Catalog Product Tier Price Attribute Backend Table' + ), + $installer->getTable('catalog/product_attribute_media_gallery') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Media Gallery Attribute Backend Table' + ), + $installer->getTable('catalog/product_attribute_media_gallery_value') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Value ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Label' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Position' + ), + 'disabled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Disabled' + ) + ), + 'comment' => 'Catalog Product Media Gallery Attribute Value Table' + ), + $installer->getTable('catalog/product_option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Type' + ), + 'is_require' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Required' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'SKU' + ), + 'max_characters' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Max Characters' + ), + 'file_extension' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'File Extension' + ), + 'image_size_x' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Image Size X' + ), + 'image_size_y' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Image Size Y' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Catalog Product Option Table' + ), + $installer->getTable('catalog/product_option_price') => array( + 'columns' => array( + 'option_price_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Price ID' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 7, + 'nullable' => false, + 'default' => 'fixed', + 'comment' => 'Price Type' + ) + ), + 'comment' => 'Catalog Product Option Price Table' + ), + $installer->getTable('catalog/product_option_title') => array( + 'columns' => array( + 'option_title_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Title ID' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Title' + ) + ), + 'comment' => 'Catalog Product Option Title Table' + ), + $installer->getTable('catalog/product_option_type_value') => array( + 'columns' => array( + 'option_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Type ID' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option ID' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'SKU' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Catalog Product Option Type Value Table' + ), + $installer->getTable('catalog/product_option_type_price') => array( + 'columns' => array( + 'option_type_price_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Type Price ID' + ), + 'option_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option Type ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'price_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 7, + 'nullable' => false, + 'default' => 'fixed', + 'comment' => 'Price Type' + ) + ), + 'comment' => 'Catalog Product Option Type Price Table' + ), + $installer->getTable('catalog/product_option_type_title') => array( + 'columns' => array( + 'option_type_title_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Type Title ID' + ), + 'option_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option Type ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Title' + ) + ), + 'comment' => 'Catalog Product Option Type Title Table' + ), + $installer->getTable('catalog/eav_attribute') => array( + 'columns' => array( + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'frontend_input_renderer' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Frontend Input Renderer' + ), + 'is_global' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Global' + ), + 'is_visible' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Visible' + ), + 'is_searchable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Searchable' + ), + 'is_filterable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Filterable' + ), + 'is_comparable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Comparable' + ), + 'is_visible_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Visible On Front' + ), + 'is_html_allowed_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is HTML Allowed On Front' + ), + 'is_used_for_price_rules' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Used For Price Rules' + ), + 'is_filterable_in_search' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Filterable In Search' + ), + 'used_in_product_listing' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Used In Product Listing' + ), + 'used_for_sort_by' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Used For Sorting' + ), + 'is_configurable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Configurable' + ), + 'apply_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Apply To' + ), + 'is_visible_in_advanced_search' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Visible In Advanced Search' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'is_wysiwyg_enabled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is WYSIWYG Enabled' + ), + 'is_used_for_promo_rules' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Used For Promo Rules' + ) + ), + 'comment' => 'Catalog EAV Attribute Table' + ), + $installer->getTable('catalog/product_relation') => array( + 'columns' => array( + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Parent ID' + ), + 'child_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Child ID' + ) + ), + 'comment' => 'Catalog Product Relation Table' + ), + $installer->getTable('catalog/product_index_eav') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Index Table' + ), + $installer->getTable('catalog/product_index_eav_decimal') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'primary' => true, + 'default' => '0.0000', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Decimal Index Table' + ), + $installer->getTable('catalog/product_index_price') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'final_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Final Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Index Table' + ), + $installer->getTable('catalog/product_index_tier_price') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ) + ), + 'comment' => 'Catalog Product Tier Price Index Table' + ), + $installer->getTable('catalog/product_index_website') => array( + 'columns' => array( + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_FLOAT, + 'default' => '1', + 'comment' => 'Rate' + ) + ), + 'comment' => 'Catalog Product Website Index Table' + ), + $installer->getTable('catalog/product_price_indexer_cfg_option_aggregate_idx') => array( + 'columns' => array( + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Parent ID' + ), + 'child_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Child ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Config Option Aggregate Index ' + ), + $installer->getTable('catalog/product_price_indexer_cfg_option_aggregate_tmp') => array( + 'columns' => array( + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Parent ID' + ), + 'child_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Child ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Config Option Aggregate Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_price_indexer_cfg_option_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Config Option Index Table' + ), + $installer->getTable('catalog/product_price_indexer_cfg_option_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Config Option Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_price_indexer_final_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class ID' + ), + 'orig_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Original Price' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'base_tier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tier' + ) + ), + 'comment' => 'Catalog Product Price Indexer Final Index Table' + ), + $installer->getTable('catalog/product_price_indexer_final_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class ID' + ), + 'orig_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Original Price' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ), + 'base_tier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tier' + ) + ), + 'comment' => 'Catalog Product Price Indexer Final Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_price_indexer_option_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Option Index Table' + ), + $installer->getTable('catalog/product_price_indexer_option_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Option Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_price_indexer_option_aggregate_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Option Aggregate Index Table' + ), + $installer->getTable('catalog/product_price_indexer_option_aggregate_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Option ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Option Aggregate Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_eav_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Indexer Index Table' + ), + $installer->getTable('catalog/product_eav_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_eav_decimal_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'primary' => true, + 'default' => '0.0000', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Decimal Indexer Index Table' + ), + $installer->getTable('catalog/product_eav_decimal_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'primary' => true, + 'default' => '0.0000', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product EAV Decimal Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/product_price_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'final_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Final Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Index Table' + ), + $installer->getTable('catalog/product_price_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Tax Class ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'final_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Final Price' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Min Price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Max Price' + ), + 'tier_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tier Price' + ) + ), + 'comment' => 'Catalog Product Price Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/category_product_indexer_idx') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'is_parent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Parent' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Category Product Indexer Index Table' + ), + $installer->getTable('catalog/category_product_indexer_tmp') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Position' + ), + 'is_parent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Parent' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Category Product Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/category_product_enabled_indexer_idx') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Category Product Enabled Indexer Index Table' + ), + $installer->getTable('catalog/category_product_enabled_indexer_tmp') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'visibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visibility' + ) + ), + 'comment' => 'Catalog Category Product Enabled Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/category_anchor_indexer_idx') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Path' + ) + ), + 'comment' => 'Catalog Category Anchor Indexer Index Table' + ), + $installer->getTable('catalog/category_anchor_indexer_tmp') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Path' + ) + ), + 'comment' => 'Catalog Category Anchor Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable('catalog/category_anchor_products_indexer_idx') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Position' + ) + ), + 'comment' => 'Catalog Category Anchor Product Indexer Index Table' + ), + $installer->getTable('catalog/category_anchor_products_indexer_tmp') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Category ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ) + ), + 'comment' => 'Catalog Category Anchor Product Indexer Temp Table', + 'engine' => 'InnoDB' + ), + $installer->getTable(array('catalog/product','datetime')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Datetime Attribute Backend Table' + ), + $installer->getTable(array('catalog/product','decimal')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Decimal Attribute Backend Table' + ), + $installer->getTable(array('catalog/product','int')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Integer Attribute Backend Table' + ), + $installer->getTable(array('catalog/product','text')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Text Attribute Backend Table' + ), + $installer->getTable(array('catalog/product','varchar')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Varchar Attribute Backend Table' + ), + $installer->getTable(array('catalog/product','gallery')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Position' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Product Gallery Attribute Backend Table' + ), + $installer->getTable(array('catalog/category','datetime')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Category Datetime Attribute Backend Table' + ), + $installer->getTable(array('catalog/category','decimal')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Category Decimal Attribute Backend Table' + ), + $installer->getTable(array('catalog/category','int')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Category Integer Attribute Backend Table' + ), + $installer->getTable(array('catalog/category','text')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Category Text Attribute Backend Table' + ), + $installer->getTable(array('catalog/category','varchar')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value ID' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type ID' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity ID' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value' + ) + ), + 'comment' => 'Catalog Category Varchar Attribute Backend Table' + ), + $installer->getTable('core/url_rewrite') => array( + 'columns' => array( + 'category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => true, + 'comment' => 'Category Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => true, + 'comment' => 'Product Id' + ) + ) + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('catalog/product_index_website'), + 'date', + 'website_date', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Website Date' + ) +); + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_anchor_indexer_idx'), + $installer->getIdxName('catalog/category_anchor_indexer_idx', array('category_id')), + array('category_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_anchor_indexer_tmp'), + $installer->getIdxName('catalog/category_anchor_indexer_tmp', array('category_id')), + array('category_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category'), + $installer->getIdxName('catalog/category', array('level')), + array('level') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product'), + 'PRIMARY', + array('category_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product'), + $installer->getIdxName('catalog/category_product', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_index'), + 'PRIMARY', + array('category_id', 'product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_index'), + $installer->getIdxName( + 'catalog/category_product_index', + array('product_id', 'store_id', 'category_id', 'visibility') + ), + array('product_id', 'store_id', 'category_id', 'visibility') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_index'), + $installer->getIdxName( + 'catalog/category_product_index', + array('store_id', 'category_id', 'visibility', 'is_parent', 'position') + ), + array('store_id', 'category_id', 'visibility', 'is_parent', 'position') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_index'), + $installer->getIdxName( + 'catalog/category_product_index', + array('product_id', 'store_id', 'category_id', 'visibility') + ), + array('product_id', 'store_id', 'category_id', 'visibility') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_enabled_indexer_idx'), + $installer->getIdxName('catalog/category_product_enabled_indexer_idx', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_enabled_indexer_tmp'), + $installer->getIdxName('catalog/category_product_enabled_indexer_tmp', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/category_product_indexer_idx'), + $installer->getIdxName('catalog/category_product_indexer_idx', array('product_id', 'category_id', 'store_id')), + array('product_id', 'category_id', 'store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/compare_item'), + $installer->getIdxName('catalog/compare_item', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/compare_item'), + $installer->getIdxName('catalog/compare_item', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/compare_item'), + $installer->getIdxName('catalog/compare_item', array('visitor_id', 'product_id')), + array('visitor_id', 'product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/compare_item'), + $installer->getIdxName('catalog/compare_item', array('customer_id', 'product_id')), + array('customer_id', 'product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/compare_item'), + $installer->getIdxName('catalog/compare_item', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/eav_attribute'), + $installer->getIdxName('catalog/eav_attribute', array('used_for_sort_by')), + array('used_for_sort_by') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/eav_attribute'), + $installer->getIdxName('catalog/eav_attribute', array('used_in_product_listing')), + array('used_in_product_listing') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_enabled_index'), + $installer->getIdxName('catalog/product_enabled_index', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_enabled_index'), + 'PRIMARY', + array('product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product'), + $installer->getIdxName('catalog/product', array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product'), + $installer->getIdxName('catalog/product', array('attribute_set_id')), + array('attribute_set_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product'), + $installer->getIdxName('catalog/product', array('sku')), + array('sku') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_media_gallery'), + $installer->getIdxName('catalog/product_attribute_media_gallery', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_media_gallery'), + $installer->getIdxName('catalog/product_attribute_media_gallery', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_media_gallery_value'), + $installer->getIdxName('catalog/product_attribute_media_gallery_value', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + $installer->getIdxName( + 'catalog/product_attribute_tier_price', + array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id') + ), + array('entity_id', 'all_groups', 'customer_group_id', 'qty', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + $installer->getIdxName('catalog/product_attribute_tier_price', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + $installer->getIdxName('catalog/product_attribute_tier_price', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_attribute_tier_price'), + $installer->getIdxName('catalog/product_attribute_tier_price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav'), + $installer->getIdxName('catalog/product_index_eav', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav'), + $installer->getIdxName('catalog/product_index_eav', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav'), + $installer->getIdxName('catalog/product_index_eav', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav'), + $installer->getIdxName('catalog/product_index_eav', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + $installer->getIdxName('catalog/product_index_eav_decimal', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + $installer->getIdxName('catalog/product_index_eav_decimal', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + $installer->getIdxName('catalog/product_index_eav_decimal', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_eav_decimal'), + $installer->getIdxName('catalog/product_index_eav_decimal', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_idx'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_idx', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_decimal_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_decimal_indexer_tmp', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + $installer->getIdxName('catalog/product_eav_indexer_idx', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + $installer->getIdxName('catalog/product_eav_indexer_idx', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + $installer->getIdxName('catalog/product_eav_indexer_idx', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_idx'), + $installer->getIdxName('catalog/product_eav_indexer_idx', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_indexer_tmp', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_indexer_tmp', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_indexer_tmp', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_eav_indexer_tmp'), + $installer->getIdxName('catalog/product_eav_indexer_tmp', array('value')), + array('value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_price'), + $installer->getIdxName('catalog/product_index_price', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_price'), + $installer->getIdxName('catalog/product_index_price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_price'), + $installer->getIdxName('catalog/product_index_price', array('min_price')), + array('min_price') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + $installer->getIdxName('catalog/product_price_indexer_idx', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + $installer->getIdxName('catalog/product_price_indexer_idx', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_idx'), + $installer->getIdxName('catalog/product_price_indexer_idx', array('min_price')), + array('min_price') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + $installer->getIdxName('catalog/product_price_indexer_tmp', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + $installer->getIdxName('catalog/product_price_indexer_tmp', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_price_indexer_tmp'), + $installer->getIdxName('catalog/product_price_indexer_tmp', array('min_price')), + array('min_price') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_tier_price'), + $installer->getIdxName('catalog/product_index_tier_price', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_tier_price'), + $installer->getIdxName('catalog/product_index_tier_price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_index_website'), + $installer->getIdxName('catalog/product_index_website', array('website_date')), + array('website_date') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link'), + $installer->getIdxName( + 'catalog/product_link', + array('link_type_id', 'product_id', 'linked_product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('link_type_id', 'product_id', 'linked_product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link'), + $installer->getIdxName('catalog/product_link', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link'), + $installer->getIdxName('catalog/product_link', array('linked_product_id')), + array('linked_product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link'), + $installer->getIdxName('catalog/product_link', array('link_type_id')), + array('link_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute'), + $installer->getIdxName('catalog/product_link_attribute', array('link_type_id')), + array('link_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_decimal'), + $installer->getIdxName( + 'catalog/product_link_attribute_decimal', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_decimal'), + $installer->getIdxName('catalog/product_link_attribute_decimal', array('product_link_attribute_id')), + array('product_link_attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_decimal'), + $installer->getIdxName('catalog/product_link_attribute_decimal', array('link_id')), + array('link_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_int'), + $installer->getIdxName( + 'catalog/product_link_attribute_int', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_int'), + $installer->getIdxName('catalog/product_link_attribute_int', array('product_link_attribute_id')), + array('product_link_attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_int'), + $installer->getIdxName('catalog/product_link_attribute_int', array('link_id')), + array('link_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_varchar'), + $installer->getIdxName( + 'catalog/product_link_attribute_varchar', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_varchar'), + $installer->getIdxName('catalog/product_link_attribute_varchar', array('product_link_attribute_id')), + array('product_link_attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_varchar'), + $installer->getIdxName('catalog/product_link_attribute_varchar', array('link_id')), + array('link_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option'), + $installer->getIdxName('catalog/product_option', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_price'), + $installer->getIdxName( + 'catalog/product_option_price', + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_price'), + $installer->getIdxName('catalog/product_option_price', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_price'), + $installer->getIdxName('catalog/product_option_price', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_title'), + $installer->getIdxName( + 'catalog/product_option_title', + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_title'), + $installer->getIdxName('catalog/product_option_title', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_title'), + $installer->getIdxName('catalog/product_option_title', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_price'), + $installer->getIdxName( + 'catalog/product_option_type_price', + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_price'), + $installer->getIdxName('catalog/product_option_type_price', array('option_type_id')), + array('option_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_price'), + $installer->getIdxName('catalog/product_option_type_price', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_title'), + $installer->getIdxName( + 'catalog/product_option_type_title', + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('option_type_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_title'), + $installer->getIdxName('catalog/product_option_type_title', array('option_type_id')), + array('option_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_title'), + $installer->getIdxName('catalog/product_option_type_title', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_option_type_value'), + $installer->getIdxName('catalog/product_option_type_value', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_relation'), + $installer->getIdxName('catalog/product_relation', array('child_id')), + array('child_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute'), + $installer->getIdxName( + 'catalog/product_super_attribute', + array('product_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute'), + $installer->getIdxName('catalog/product_super_attribute', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_label'), + $installer->getIdxName( + 'catalog/product_super_attribute_label', + array('product_super_attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_super_attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_label'), + $installer->getIdxName('catalog/product_super_attribute_label', array('product_super_attribute_id')), + array('product_super_attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_label'), + $installer->getIdxName('catalog/product_super_attribute_label', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + $installer->getIdxName( + 'catalog/product_super_attribute_pricing', + array('product_super_attribute_id', 'value_index', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_super_attribute_id', 'value_index', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + $installer->getIdxName('catalog/product_super_attribute_pricing', array('product_super_attribute_id')), + array('product_super_attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + $installer->getIdxName('catalog/product_super_attribute_pricing', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_link'), + $installer->getIdxName( + 'catalog/product_super_link', + array('product_id', 'parent_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'parent_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_link'), + $installer->getIdxName('catalog/product_super_link', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_link'), + $installer->getIdxName('catalog/product_super_link', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_website'), + $installer->getIdxName('catalog/product_website', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'datetime')), + $installer->getIdxName( + array('catalog/category', 'datetime'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'datetime')), + $installer->getIdxName(array('catalog/category', 'datetime'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'datetime')), + $installer->getIdxName(array('catalog/category', 'datetime'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'datetime')), + $installer->getIdxName(array('catalog/category', 'datetime'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'decimal')), + $installer->getIdxName( + array('catalog/category', 'decimal'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'decimal')), + $installer->getIdxName(array('catalog/category', 'decimal'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'decimal')), + $installer->getIdxName(array('catalog/category', 'decimal'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'decimal')), + $installer->getIdxName(array('catalog/category', 'decimal'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'int')), + $installer->getIdxName( + array('catalog/category', 'int'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'int')), + $installer->getIdxName(array('catalog/category', 'int'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'int')), + $installer->getIdxName(array('catalog/category', 'int'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'int')), + $installer->getIdxName(array('catalog/category', 'int'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'text')), + $installer->getIdxName( + array('catalog/category', 'text'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'text')), + $installer->getIdxName(array('catalog/category', 'text'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'text')), + $installer->getIdxName(array('catalog/category', 'text'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'text')), + $installer->getIdxName(array('catalog/category', 'text'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'varchar')), + $installer->getIdxName( + array('catalog/category', 'varchar'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'varchar')), + $installer->getIdxName(array('catalog/category', 'varchar'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'varchar')), + $installer->getIdxName(array('catalog/category', 'varchar'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/category', 'varchar')), + $installer->getIdxName(array('catalog/category', 'varchar'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'datetime')), + $installer->getIdxName( + array('catalog/product', 'datetime'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'datetime')), + $installer->getIdxName(array('catalog/product', 'datetime'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'datetime')), + $installer->getIdxName(array('catalog/product', 'datetime'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'datetime')), + $installer->getIdxName(array('catalog/product', 'datetime'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'decimal')), + $installer->getIdxName( + array('catalog/product', 'decimal'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'decimal')), + $installer->getIdxName(array('catalog/product', 'decimal'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'decimal')), + $installer->getIdxName(array('catalog/product', 'decimal'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'decimal')), + $installer->getIdxName(array('catalog/product', 'decimal'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'gallery')), + $installer->getIdxName( + array('catalog/product', 'gallery'), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'gallery')), + $installer->getIdxName(array('catalog/product', 'gallery'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'gallery')), + $installer->getIdxName(array('catalog/product', 'gallery'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'gallery')), + $installer->getIdxName(array('catalog/product', 'gallery'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'int')), + $installer->getIdxName( + array('catalog/product', 'int'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'int')), + $installer->getIdxName(array('catalog/product', 'int'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'int')), + $installer->getIdxName(array('catalog/product', 'int'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'int')), + $installer->getIdxName(array('catalog/product', 'int'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'text')), + $installer->getIdxName( + array('catalog/product', 'text'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'text')), + $installer->getIdxName(array('catalog/product', 'text'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'text')), + $installer->getIdxName(array('catalog/product', 'text'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'text')), + $installer->getIdxName(array('catalog/product', 'text'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'varchar')), + $installer->getIdxName( + array('catalog/product', 'varchar'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'varchar')), + $installer->getIdxName(array('catalog/product', 'varchar'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'varchar')), + $installer->getIdxName(array('catalog/product', 'varchar'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('catalog/product', 'varchar')), + $installer->getIdxName(array('catalog/product', 'varchar'), array('entity_id')), + array('entity_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/category_product', 'category_id', 'catalog/category', 'entity_id'), + $installer->getTable('catalog/category_product'), + 'category_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/category_product', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/category_product'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'category_id', 'catalog/category', 'entity_id'), + $installer->getTable('catalog/category_product_index'), + 'category_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/category_product_index'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/category_product_index', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/category_product_index'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/compare_item', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('catalog/compare_item'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/compare_item', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/compare_item'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/compare_item', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/compare_item'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/eav_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('catalog/eav_attribute'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_enabled_index', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_enabled_index'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_enabled_index', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_enabled_index'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id'), + $installer->getTable('catalog/product'), + 'attribute_set_id', + $installer->getTable('eav_attribute_set'), + 'attribute_set_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product', 'entity_type_id', 'eav_entity_type', 'entity_type_id'), + $installer->getTable('catalog/product'), + 'entity_type_id', + $installer->getTable('eav_entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_attribute_media_gallery', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('catalog/product_attribute_media_gallery'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_attribute_media_gallery', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_attribute_media_gallery'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_media_gallery_value', + 'value_id', + 'catalog/product_attribute_media_gallery', + 'value_id' + ), + $installer->getTable('catalog/product_attribute_media_gallery_value'), + 'value_id', + $installer->getTable('catalog/product_attribute_media_gallery'), + 'value_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_attribute_media_gallery_value', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_attribute_media_gallery_value'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_attribute_tier_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + $installer->getTable('catalog/product_attribute_tier_price'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_attribute_tier_price', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_attribute_tier_price'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_attribute_tier_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_attribute_tier_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('catalog/product_index_eav'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_index_eav'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_index_eav'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav_decimal', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('catalog/product_index_eav_decimal'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav_decimal', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_index_eav_decimal'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_eav_decimal', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_index_eav_decimal'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_index_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + $installer->getTable('catalog/product_index_price'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_price', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_index_price'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_index_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_index_tier_price', + 'customer_group_id', + 'customer/customer_group', + 'customer_group_id' + ), + $installer->getTable('catalog/product_index_tier_price'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_tier_price', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_index_tier_price'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_tier_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_index_tier_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_index_website', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_index_website'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link', 'linked_product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_link'), + 'linked_product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_link'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link', 'link_type_id', 'catalog/product_link_type', 'link_type_id'), + $installer->getTable('catalog/product_link'), + 'link_type_id', + $installer->getTable('catalog/product_link_type'), + 'link_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute', + 'link_type_id', + 'catalog/product_link_type', + 'link_type_id' + ), + $installer->getTable('catalog/product_link_attribute'), + 'link_type_id', + $installer->getTable('catalog/product_link_type'), + 'link_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link_attribute_decimal', 'link_id', 'catalog/product_link', 'link_id'), + $installer->getTable('catalog/product_link_attribute_decimal'), + 'link_id', + $installer->getTable('catalog/product_link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_decimal', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + $installer->getTable('catalog/product_link_attribute_decimal'), + 'product_link_attribute_id', + $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_int', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + $installer->getTable('catalog/product_link_attribute_int'), + 'product_link_attribute_id', + $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link_attribute_int', 'link_id', 'catalog/product_link', 'link_id'), + $installer->getTable('catalog/product_link_attribute_int'), + 'link_id', + $installer->getTable('catalog/product_link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_link_attribute_varchar', 'link_id', 'catalog/product_link', 'link_id'), + $installer->getTable('catalog/product_link_attribute_varchar'), + 'link_id', + $installer->getTable('catalog/product_link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_varchar', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + $installer->getTable('catalog/product_link_attribute_varchar'), + 'product_link_attribute_id', + $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_option'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_price', 'option_id', 'catalog/product_option', 'option_id'), + $installer->getTable('catalog/product_option_price'), + 'option_id', + $installer->getTable('catalog/product_option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_price', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_option_price'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_title', 'option_id', 'catalog/product_option', 'option_id'), + $installer->getTable('catalog/product_option_title'), + 'option_id', + $installer->getTable('catalog/product_option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_option_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_price', + 'option_type_id', + 'catalog/product_option_type_value', + 'option_type_id' + ), + $installer->getTable('catalog/product_option_type_price'), + 'option_type_id', + $installer->getTable('catalog/product_option_type_value'), + 'option_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_type_price', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_option_type_price'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_option_type_title', + 'option_type_id', + 'catalog/product_option_type_value', + 'option_type_id' + ), + $installer->getTable('catalog/product_option_type_title'), + 'option_type_id', + $installer->getTable('catalog/product_option_type_value'), + 'option_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_type_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_option_type_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_option_type_value', 'option_id', 'catalog/product_option', 'option_id'), + $installer->getTable('catalog/product_option_type_value'), + 'option_id', + $installer->getTable('catalog/product_option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_relation', 'child_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_relation'), + 'child_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_relation', 'parent_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_relation'), + 'parent_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_super_attribute', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_super_attribute'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_super_attribute_label', + 'product_super_attribute_id', + 'catalog/product_super_attribute', + 'product_super_attribute_id' + ), + $installer->getTable('catalog/product_super_attribute_label'), + 'product_super_attribute_id', + $installer->getTable('catalog/product_super_attribute'), + 'product_super_attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_super_attribute_label', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalog/product_super_attribute_label'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_super_attribute_pricing', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_super_attribute_pricing'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_super_attribute_pricing', + 'product_super_attribute_id', + 'catalog/product_super_attribute', + 'product_super_attribute_id' + ), + $installer->getTable('catalog/product_super_attribute_pricing'), + 'product_super_attribute_id', + $installer->getTable('catalog/product_super_attribute'), + 'product_super_attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_super_link', 'parent_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_super_link'), + 'parent_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_super_link', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_super_link'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_website', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalog/product_website'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalog/product_website', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalog/product_website'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/category', 'datetime')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'entity_id', 'catalog/category', 'entity_id'), + $installer->getTable(array('catalog/category', 'datetime')), + 'entity_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'datetime'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/category', 'datetime')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/category', 'decimal')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'entity_id', 'catalog/category', 'entity_id'), + $installer->getTable(array('catalog/category', 'decimal')), + 'entity_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'decimal'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/category', 'decimal')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/category', 'int')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'entity_id', 'catalog/category', 'entity_id'), + $installer->getTable(array('catalog/category', 'int')), + 'entity_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'int'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/category', 'int')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/category', 'text')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'entity_id', 'catalog/category', 'entity_id'), + $installer->getTable(array('catalog/category', 'text')), + 'entity_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'text'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/category', 'text')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/category', 'varchar')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'entity_id', 'catalog/category', 'entity_id'), + $installer->getTable(array('catalog/category', 'varchar')), + 'entity_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/category', 'varchar'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/category', 'varchar')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'datetime'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'datetime')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'datetime'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'datetime')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'datetime'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'datetime')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'decimal'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'decimal')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'decimal'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'decimal')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'decimal'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'decimal')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'gallery')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'gallery')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'gallery'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'gallery')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'int'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'int')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'int'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'int')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'int'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'int')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'text'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'text')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'text'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'text')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'text'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'text')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable(array('catalog/product', 'varchar')), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable(array('catalog/product', 'varchar')), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('catalog/product', 'varchar'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('catalog/product', 'varchar')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogIndex/Model/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Aggregation.php index 5917fa4ca1..380ceaa94d 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Aggregation.php +++ b/app/code/core/Mage/CatalogIndex/Model/Aggregation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,19 @@ * Index data aggregation model * * Allow cache some aggregated data with tag dependency + * + * @method Mage_CatalogIndex_Model_Resource_Aggregation _getResource() + * @method Mage_CatalogIndex_Model_Resource_Aggregation getResource() + * @method int getStoreId() + * @method Mage_CatalogIndex_Model_Aggregation setStoreId(int $value) + * @method string getCreatedAt() + * @method Mage_CatalogIndex_Model_Aggregation setCreatedAt(string $value) + * @method string getKey() + * @method Mage_CatalogIndex_Model_Aggregation setKey(string $value) + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team */ class Mage_CatalogIndex_Model_Aggregation extends Mage_Core_Model_Abstract { @@ -91,13 +104,13 @@ public function saveCacheData($data, $key, $tags, $store=null) } /** - * Delete cached aggreagation data + * Delete cached aggregation data * * @param array $tags * @param int|null|string $store * @return Mage_CatalogIndex_Model_Aggregation */ - public function clearCacheData($tags=array(), $store=null) + public function clearCacheData($tags = array(), $store = null) { $tags = $this->_processTags($tags); if ($store !== null) { diff --git a/app/code/core/Mage/CatalogIndex/Model/Attribute.php b/app/code/core/Mage/CatalogIndex/Model/Attribute.php index 5327b059b2..b3242cb281 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Attribute.php +++ b/app/code/core/Mage/CatalogIndex/Model/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,18 @@ /** * Attribute index model * + * @method Mage_CatalogIndex_Model_Resource_Attribute _getResource() + * @method Mage_CatalogIndex_Model_Resource_Attribute getResource() + * @method Mage_CatalogIndex_Model_Attribute setEntityId(int $value) + * @method int getAttributeId() + * @method Mage_CatalogIndex_Model_Attribute setAttributeId(int $value) + * @method int getStoreId() + * @method Mage_CatalogIndex_Model_Attribute setStoreId(int $value) + * @method int getValue() + * @method Mage_CatalogIndex_Model_Attribute setValue(int $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Attribute extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Flag.php b/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Flag.php index 6a2d14f826..030faef71f 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Flag.php +++ b/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Kill/Flag.php b/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Kill/Flag.php index c4bb82e2a2..20ff328fbf 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Kill/Flag.php +++ b/app/code/core/Mage/CatalogIndex/Model/Catalog/Index/Kill/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Data/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Data/Abstract.php index 37a6264db4..015c775794 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Data/Abstract.php +++ b/app/code/core/Mage/CatalogIndex/Model/Data/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -152,10 +152,10 @@ protected function fetchLinkInformation($store, $settings, $type, $suppliedId) public function getFinalPrice($product, $store, $group) { $basePrice = $specialPrice = $specialPriceFrom = $specialPriceTo = null; - $priceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price'); - $specialPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'special_price'); - $specialPriceFromId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'special_from_date'); - $specialPriceToId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'special_to_date'); + $priceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price'); + $specialPriceId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'special_price'); + $specialPriceFromId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'special_from_date'); + $specialPriceToId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'special_to_date'); $attributes = array($priceId, $specialPriceId, $specialPriceFromId, $specialPriceToId); @@ -194,8 +194,8 @@ public function getFinalPrice($product, $store, $group) public function getMinimalPrice($products, $store) { $priceAttributes = array( - Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tier_price'), - Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price')); + Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price'), + Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price')); $data = $this->getResource()->getMinimalPrice($products, $priceAttributes, $store->getId()); @@ -216,7 +216,7 @@ public function getMinimalPrice($products, $store) */ public function getTaxClassId($productId, $store) { - $attributeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tax_class_id'); + $attributeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tax_class_id'); $taxClassId = $this->getResource()->getAttributeData(array($productId), array($attributeId), $store->getId()); if (is_array($taxClassId) && isset($taxClassId[0]['value'])) { $taxClassId = $taxClassId[0]['value']; diff --git a/app/code/core/Mage/CatalogIndex/Model/Data/Configurable.php b/app/code/core/Mage/CatalogIndex/Model/Data/Configurable.php index 1f94fbc209..a7c092d0fc 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Data/Configurable.php +++ b/app/code/core/Mage/CatalogIndex/Model/Data/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Data/Grouped.php b/app/code/core/Mage/CatalogIndex/Model/Data/Grouped.php index ae6f86ed2a..ccbad03c72 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Data/Grouped.php +++ b/app/code/core/Mage/CatalogIndex/Model/Data/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Data/Simple.php b/app/code/core/Mage/CatalogIndex/Model/Data/Simple.php index a07bce7c32..203c82f492 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Data/Simple.php +++ b/app/code/core/Mage/CatalogIndex/Model/Data/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Data/Virtual.php b/app/code/core/Mage/CatalogIndex/Model/Data/Virtual.php index 055c8fa3a8..90902cbd9b 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Data/Virtual.php +++ b/app/code/core/Mage/CatalogIndex/Model/Data/Virtual.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Indexer.php index 43d21b8345..4e0d63c1a2 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,28 @@ /** * CatalogIndex Index operation model * - * @category Mage - * @package Mage_CatalogIndex - * @author Magento Core Team + * @method Mage_CatalogIndex_Model_Resource_Indexer _getResource() + * @method Mage_CatalogIndex_Model_Resource_Indexer getResource() + * @method int getEntityTypeId() + * @method Mage_CatalogIndex_Model_Indexer setEntityTypeId(int $value) + * @method int getAttributeSetId() + * @method Mage_CatalogIndex_Model_Indexer setAttributeSetId(int $value) + * @method string getTypeId() + * @method Mage_CatalogIndex_Model_Indexer setTypeId(string $value) + * @method string getSku() + * @method Mage_CatalogIndex_Model_Indexer setSku(string $value) + * @method int getHasOptions() + * @method Mage_CatalogIndex_Model_Indexer setHasOptions(int $value) + * @method int getRequiredOptions() + * @method Mage_CatalogIndex_Model_Indexer setRequiredOptions(int $value) + * @method string getCreatedAt() + * @method Mage_CatalogIndex_Model_Indexer setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_CatalogIndex_Model_Indexer setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team */ class Mage_CatalogIndex_Model_Indexer extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Abstract.php index 8772582f75..b516141019 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Abstract.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Eav.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Eav.php index 3ad0c19332..56012946cf 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Eav.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Eav.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,18 @@ /** * Catalog indexer eav processor * + * @method Mage_CatalogIndex_Model_Resource_Indexer_Eav _getResource() + * @method Mage_CatalogIndex_Model_Resource_Indexer_Eav getResource() + * @method Mage_CatalogIndex_Model_Indexer_Eav setEntityId(int $value) + * @method int getAttributeId() + * @method Mage_CatalogIndex_Model_Indexer_Eav setAttributeId(int $value) + * @method int getStoreId() + * @method Mage_CatalogIndex_Model_Indexer_Eav setStoreId(int $value) + * @method int getValue() + * @method Mage_CatalogIndex_Model_Indexer_Eav setValue(int $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Indexer_Eav extends Mage_CatalogIndex_Model_Indexer_Abstract diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Interface.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Interface.php index 3c74d88b9e..5ef4751350 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Interface.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php index 4a0a53c125..3dddaf5c5d 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,22 @@ /** * Catalog indexer price processor * + * @method Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice _getResource() + * @method Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice getResource() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setEntityId(int $value) + * @method int getCustomerGroupId() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setCustomerGroupId(int $value) + * @method float getQty() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setQty(float $value) + * @method float getValue() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setValue(float $value) + * @method int getTaxClassId() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setTaxClassId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogIndex_Model_Indexer_Minimalprice setWebsiteId(int $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Indexer_Abstract @@ -49,7 +65,7 @@ public function getTierPriceAttribute() { $data = $this->getData('tier_price_attribute'); if (is_null($data)) { - $data = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'tier_price'); + $data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price'); $this->setData('tier_price_attribute', $data); } return $data; @@ -59,7 +75,7 @@ public function getPriceAttribute() { $data = $this->getData('price_attribute'); if (is_null($data)) { - $data = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'price'); + $data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'price'); $this->setData('price_attribute', $data); } return $data; diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Price.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Price.php index 1ad69fc968..cf95d4eb49 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Price.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,28 @@ /** * Catalog indexer price processor * + * @method Mage_CatalogIndex_Model_Resource_Indexer_Price _getResource() + * @method Mage_CatalogIndex_Model_Resource_Indexer_Price getResource() + * @method Mage_CatalogIndex_Model_Indexer_Price setEntityId(int $value) + * @method int getCustomerGroupId() + * @method Mage_CatalogIndex_Model_Indexer_Price setCustomerGroupId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogIndex_Model_Indexer_Price setWebsiteId(int $value) + * @method int getTaxClassId() + * @method Mage_CatalogIndex_Model_Indexer_Price setTaxClassId(int $value) + * @method float getPrice() + * @method Mage_CatalogIndex_Model_Indexer_Price setPrice(float $value) + * @method float getFinalPrice() + * @method Mage_CatalogIndex_Model_Indexer_Price setFinalPrice(float $value) + * @method float getMinPrice() + * @method Mage_CatalogIndex_Model_Indexer_Price setMinPrice(float $value) + * @method float getMaxPrice() + * @method Mage_CatalogIndex_Model_Indexer_Price setMaxPrice(float $value) + * @method float getTierPrice() + * @method Mage_CatalogIndex_Model_Indexer_Price setTierPrice(float $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Indexer_Price extends Mage_CatalogIndex_Model_Indexer_Abstract diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer/Tierprice.php b/app/code/core/Mage/CatalogIndex/Model/Indexer/Tierprice.php index 2623b58073..4e2dd30ab5 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer/Tierprice.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer/Tierprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,28 @@ /** * Tier Price indexer * + * @method Mage_CatalogIndex_Model_Resource_Indexer_Price _getResource() + * @method Mage_CatalogIndex_Model_Resource_Indexer_Price getResource() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setEntityId(int $value) + * @method int getCustomerGroupId() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setCustomerGroupId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setWebsiteId(int $value) + * @method int getTaxClassId() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setTaxClassId(int $value) + * @method float getPrice() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setPrice(float $value) + * @method float getFinalPrice() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setFinalPrice(float $value) + * @method float getMinPrice() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setMinPrice(float $value) + * @method float getMaxPrice() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setMaxPrice(float $value) + * @method float getTierPrice() + * @method Mage_CatalogIndex_Model_Indexer_Tierprice setTierPrice(float $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Indexer_Tierprice extends Mage_CatalogIndex_Model_Indexer_Abstract diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Abstract.php index 7e814928ad..c55af91ab0 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Abstract.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,33 +28,10 @@ /** * Index resource model abstraction * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Abstract extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Abstract extends Mage_CatalogIndex_Model_Resource_Abstract { - protected $_storeId = 0; - protected $_websiteId = null; - - protected function _construct() { - return parent::_construct(); - } - - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - } - - public function getStoreId() - { - return $this->_storeId; - } - - public function getWebsiteId() - { - if (is_null($this->_websiteId)) { - $result = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); - $this->_websiteId = $result; - } - return $this->_websiteId; - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Aggregation.php index 8d4fbf12c0..364e667897 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Aggregation.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Aggregation.php @@ -20,208 +20,18 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogIndex_Model_Mysql4_Aggregation extends Mage_Core_Model_Mysql4_Abstract -{ - protected $_tagTable; - protected $_toTagTable; - - /** - * Initialize resource tables - */ - protected function _construct() - { - $this->_init('catalogindex/aggregation', 'aggregation_id'); - $this->_tagTable = $this->getTable('catalogindex/aggregation_tag'); - $this->_toTagTable = $this->getTable('catalogindex/aggregation_to_tag'); - } - - /** - * Get aggregated cache data by data key and store - * - * @param string $key - * @param int $store - * @return array - */ - public function getCacheData($key, $storeId) - { - $select = $this->_getReadAdapter()->select() - ->from(array('a'=>$this->getMainTable()), 'data') - ->where('a.store_id=?', $storeId) - ->where('a.key=?', $key); - $data = $this->_getReadAdapter()->fetchOne($select); - if ($data) { - $data = unserialize($data); - } else { - $data = array(); - } - return $data; - } - - /** - * Save data to aggreagation table with tags relations - * - * @param array $data - * @param string $key - * @param array|string $tags - * @param int $storeId - * @return Mage_CatalogIndex_Model_Mysql4_Aggregation - */ - public function saveCacheData($data, $key, $tags, $storeId) - { - $data = serialize($data); - $tags = $this->_getTagIds($tags); - - /* - $select = $this->_getWriteAdapter()->select() - ->from(array('a'=>$this->getMainTable()), $this->getIdFieldName()) - ->where('a.store_id=?', $storeId) - ->where('a.key=?', $key); - - $id = $this->_getWriteAdapter()->fetchOne($select); - if ($id) { - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('data'=>$data), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $id) - ); - } else { - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'store_id' => $storeId, - 'created_at'=> $this->formatDate(time()), - 'key' => $key, - 'data' => $data - )); - $id = $this->_getWriteAdapter()->lastInsertId(); - } - */ - - $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), array( - 'store_id' => $storeId, - 'created_at'=> $this->formatDate(time()), - 'key' => $key, - 'data' => $data - ), array('created_at', 'data')); - - $id = $this->_getWriteAdapter()->lastInsertId(); - - $this->_saveTagRelations($id, $tags); - return $this; - } - - public function clearCacheData($tags, $storeId) - { - $conditions = array(); - if (!$write = $this->_getWriteAdapter()) { - return $this; - } - if (!empty($tags)) { - $tagIds = $this->_getTagIds($tags); - $select = $write->select() - ->from($this->_toTagTable, 'aggregation_id') - ->where('tag_id IN (?)', $tagIds); - $conditions[] = $write->quoteInto('aggregation_id IN ?', $select); - } - - if ($storeId !== null) { - $conditions[] = $write->quoteInto('store_id=?', $storeId); - } - - $write->delete($this->getMainTable(), implode(' AND ', $conditions)); - return $this; - } - /** - * Save related tags for aggreagation data - * - * @param int $aggregationId - * @param array $tags - * @return Mage_CatalogIndex_Model_Mysql4_Aggregation - */ - protected function _saveTagRelations($aggregationId, $tags) - { - $query = "REPLACE INTO `{$this->_toTagTable}` (aggregation_id, tag_id) VALUES "; - $data = array(); - foreach ($tags as $tagId) { - $data[] = $aggregationId.','.$tagId; - } - $query.= '(' . implode('),(', $data) . ')'; - $this->_getWriteAdapter()->query($query); - return $this; - } - - /** - * Get identifiers of tags - * if some tags not exist they will be added - * - * @param array $tags - * @return array - */ - protected function _getTagIds($tags) - { - if (!is_array($tags)) { - $tags = array($tags); - } - - $select = $this->_getReadAdapter()->select() - ->from(array('tags'=>$this->_tagTable), array('tag_code', 'tag_id')) - ->where('tags.tag_code IN (?)', $tags); - - $tagIds = $this->_getReadAdapter()->fetchPairs($select); - - /** - * Detect new tags - */ - $newTags = array_diff($tags, array_keys($tagIds)); - if (!empty($newTags)) { - $this->_addTags($newTags); - $select->reset(Zend_Db_Select::WHERE) - ->where('tags.tag_code IN (?)', $newTags); - $newTags = $this->_getReadAdapter()->fetchPairs($select); - $tagIds = array_merge($tagIds, $newTags); - } - return $tagIds; - } - - /** - * Insert tags to tag table - * - * @param string | array $tags - * @return Mage_CatalogIndex_Model_Mysql4_Aggregation - */ - protected function _addTags($tags) - { - if (is_array($tags)) { - $tags = array_unique($tags); - foreach ($tags as $index => $tag) { - $tags[$index] = $this->_getWriteAdapter()->quote($tag); - } - $query = "INSERT INTO `{$this->_tagTable}` (tag_code) VALUES (".implode('),(', $tags).")"; - $this->_getWriteAdapter()->query($query); - } - else { - $this->_getWriteAdapter()->insert($this->_tagTable, array( - 'tag_code' => $tags - )); - } - return $this; - } - - public function getProductCategoryPaths($productIds) - { - $select = $this->_getReadAdapter()->select() - ->from(array('cat'=>$this->getTable('catalog/category')), 'path') - ->joinInner( - array('cat_prod'=>$this->getTable('catalog/category_product')), - $this->_getReadAdapter()->quoteInto( - 'cat.entity_id=cat_prod.category_id AND cat_prod.product_id IN (?)', - $productIds - ), - array() - ); - return $this->_getReadAdapter()->fetchCol($select); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team + */ +class Mage_CatalogIndex_Model_Mysql4_Aggregation extends Mage_CatalogIndex_Model_Resource_Aggregation +{ } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Attribute.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Attribute.php index 074c4d58b5..59c2e67656 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Attribute.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,76 +28,10 @@ /** * Attribute index resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Attribute extends Mage_CatalogIndex_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Attribute extends Mage_CatalogIndex_Model_Resource_Attribute { - protected function _construct() - { - $this->_init('catalogindex/eav', 'index_id'); - } - - public function getFilteredEntities($attribute, $filter, $entityFilter) - { - $select = $this->_getReadAdapter()->select(); - - $select - ->from($this->getMainTable(), 'entity_id') - ->distinct(true) - ->where('entity_id in (?)', $entityFilter) - ->where('store_id = ?', $this->getStoreId()) - ->where('attribute_id = ?', $attribute->getId()) - ->where('value = ?', $filter); - - return $this->_getReadAdapter()->fetchCol($select); - } - - public function getCount($attribute, $entitySelect) - { - $select = clone $entitySelect; - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - $fields = array('count'=>'COUNT(index.entity_id)', 'index.value'); - - $select->columns($fields) - ->join(array('index'=>$this->getMainTable()), 'index.entity_id=e.entity_id', array()) - ->where('index.store_id = ?', $this->getStoreId()) - ->where('index.attribute_id = ?', $attribute->getId()) - ->group('index.value'); - - $select = $select->__toString(); -// $alias = $this->_getReadAdapter()->quoteTableAs($this->getMainTable(), 'index'); - $result = $this->_getReadAdapter()->fetchAll($select); - - $counts = array(); - foreach ($result as $row) { - $counts[$row['value']] = $row['count']; - } - return $counts; - } - - public function applyFilterToCollection($collection, $attribute, $value) - { - /** - * Will be used after SQL review - */ -// if ($collection->isEnabledFlat()) { -// $collection->getSelect()->where("e.{$attribute->getAttributeCode()}=?", $value); -// return $this; -// } - - $alias = 'attr_index_'.$attribute->getId(); - $collection->getSelect()->join( - array($alias => $this->getMainTable()), - $alias.'.entity_id=e.entity_id', - array() - ) - ->where($alias.'.store_id = ?', $this->getStoreId()) - ->where($alias.'.attribute_id = ?', $attribute->getId()) - ->where($alias.'.value = ?', $value); - return $this; - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Abstract.php index bbb2f67c57..68375eeea5 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Abstract.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Abstract.php @@ -20,280 +20,18 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogIndex_Model_Mysql4_Data_Abstract extends Mage_Core_Model_Mysql4_Abstract -{ - /** - * Attribute id by code cache - * - * @var array - */ - protected $_attributeCodeIds = array(); - - /** - * Link select object - * - * @var Zend_Db_Select - */ - protected $_linkSelect = null; - - /** - * Set link select - * - * @param Zend_Db_Select $select - */ - protected function _setLinkSelect($select) - { - $this->_linkSelect = $select; - return $this; - } - - /** - * Get link select - * - * @return Zend_Db_Select $select - */ - protected function _getLinkSelect() - { - return $this->_linkSelect; - } - - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - /** - * Retreive specified attribute data for specified products from specified store - * - * @param array $products - * @param array $attributes - * @param int $store - */ - public function getAttributeData($products, $attributes, $store) - { - $suffixes = array('decimal', 'varchar', 'int', 'text', 'datetime'); - if (!is_array($products)) { - $products = new Zend_Db_Expr($products); - } - $result = array(); - foreach ($suffixes as $suffix) { - $tableName = "{$this->getTable('catalog/product')}_{$suffix}"; - $condition = "product.entity_id = c.entity_id AND c.store_id = {$store} AND c.attribute_id = d.attribute_id"; - $defaultCondition = "product.entity_id = d.entity_id AND d.store_id = 0"; - $fields = array( - 'entity_id', - 'type_id', - 'attribute_id' => 'IF(c.value_id>0, c.attribute_id, d.attribute_id)', - 'value' => 'IF(c.value_id>0, c.value, d.value)' - ); - - $select = $this->_getReadAdapter()->select() - ->from(array('product'=>$this->getTable('catalog/product')), $fields) - ->where('product.entity_id in (?)', $products) - ->joinRight(array('d'=>$tableName), $defaultCondition, array()) - ->joinLeft(array('c'=>$tableName), $condition, array()) - ->where('c.attribute_id IN (?) OR d.attribute_id IN (?)', $attributes); - $part = $this->_getReadAdapter()->fetchAll($select); - - if (is_array($part)) { - $result = array_merge($result, $part); - } - } - - return $result; - } - - /** - * Returns an array of product children/parents - * - * @param int $store - * @param string $table - * @param string $idField - * @param string $whereField - * @param int $id - * @param array $additionalWheres - * @return mixed - */ - public function fetchLinkInformation($store, $table, $idField, $whereField, $id, $additionalWheres = array()) - { - $idsConditionSymbol = "= ?"; - if (is_array($id)) { - $idsConditionSymbol = "in (?)"; - } - - $select = $this->_getReadAdapter()->select(); - $select->from(array('l'=>$this->getTable($table)), array("l.{$idField}")) - ->where("l.{$whereField} {$idsConditionSymbol}", $id); - foreach ($additionalWheres as $field=>$condition) { - $select->where("l.$field = ?", $condition); - } - - // add status filter - $this->_addAttributeFilter($select, 'status', 'l', $idField, $store, - Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - // add website filter - if ($websiteId = Mage::app()->getStore($store)->getWebsiteId()) { - $select->join( - array('w' => $this->getTable('catalog/product_website')), - "l.{$idField}=w.product_id AND w.website_id={$websiteId}", - array() - ); - } - - $this->_setLinkSelect($select); - $this->_prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres); - - return $this->_getWriteAdapter()->fetchCol($this->_getLinkSelect()); - } - - /** - * Prepare select statement before 'fetchLinkInformation' function result fetch - * - * @param int $store - * @param string $table - * @param string $idField - * @param string $whereField - * @param int $id - * @param array $additionalWheres - */ - protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) {} - - /** - * Return minimal prices for specified products - * - * @param array $products - * @param array $priceAttributes - * @param int $store - * @return mixed - */ - public function getMinimalPrice($products, $priceAttributes, $store) - { - $website = Mage::app()->getStore($store)->getWebsiteId(); - - $fields = array('customer_group_id', 'minimal_value'=>'MIN(value)'); - $select = $this->_getReadAdapter()->select() - ->from(array('base'=>$this->getTable('catalogindex/price')), $fields) - ->where('base.entity_id in (?)', $products) - ->where('base.attribute_id in (?)', $priceAttributes) - ->where('base.website_id = ?', $website) - ->group('base.customer_group_id'); - return $this->_getReadAdapter()->fetchAll($select); - } - - /** - * Return tier prices for specified product in specified website - * - * @param array $products - * @param int $website - * @return mixed - */ - public function getTierPrices($products, $website) - { - $fields = array( - 'entity_id', - 'type_id', - 'c.customer_group_id', - 'c.qty', - 'c.value', - 'c.all_groups', - ); - $condition = "product.entity_id = c.entity_id"; - - $select = $this->_getReadAdapter()->select() - ->from(array('product'=>$this->getTable('catalog/product')), $fields) - ->joinLeft(array('c'=>"{$this->getTable('catalog/product')}_tier_price"), $condition, array()) - ->where('product.entity_id in (?)', $products); - if (Mage::helper('catalog')->isPriceGlobal()) - { - $select->where('c.website_id=?', 0); - } - elseif (Mage::app()->getWebsite($website)->getBaseCurrencyCode() != Mage::app()->getBaseCurrencyCode()) { - $select->where('c.website_id=?', $website); - } - else { - $select->where('c.website_id IN(?)', array(0, $website)); - } - - return $this->_getReadAdapter()->fetchAll($select); - } - - /** - * Add attribute filter to select - * - * @param Varien_Db_Select $select - * @param string $attributeCode - * @param string $table the main table name or alias - * @param string $field entity_id field name - * @param int $store - * @param int|string|array $value the filter value - * @return Mage_CatalogIndex_Model_Mysql4_Data_Abstract - */ - protected function _addAttributeFilter(Varien_Db_Select $select, $attributeCode, $table, $field, $store, $value) - { - $adapter = $this->_getReadAdapter(); - $attribute = Mage::getSingleton('eav/config') - ->getAttribute('catalog_product', $attributeCode); - /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ - $attributeTable = $attribute->getBackend()->getTable(); - if ($attribute->getBackendType() == 'static') { - $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); - $joinCond = join(' AND ', array( - sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias) - )); - $select - ->join( - array($tableAlias => $attributeTable), - $joinCond, - array()) - ->where(sprintf('%s.%s IN(?)', $tableAlias, $attribute->getAttributeCode()), $value); - } - elseif ($attribute->isScopeGlobal()) { - $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); - $joinCond = join(' AND ', array( - sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias), - $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableAlias), $attribute->getAttributeId()), - $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableAlias), 0) - )); - $select - ->join( - array($tableAlias => $attributeTable), - $joinCond, - array()) - ->where(sprintf('%s.value IN(?)', $tableAlias), $value); - } - else { - $tableGlobal = sprintf('t_global_%s', $attribute->getAttributeCode()); - $tableStore = sprintf('t_store_%s', $attribute->getAttributeCode()); - $joinCondGlobal = join(' AND ', array( - sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableGlobal), - $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableGlobal), $attribute->getAttributeId()), - $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableGlobal), 0) - )); - $joinCondStore = join(' AND ', array( - sprintf('`%s`.`entity_id`=`%s`.`entity_id`', $tableGlobal, $tableStore), - sprintf('`%s`.`attribute_id`=`%s`.`attribute_id`', $tableGlobal, $tableStore), - $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableStore), $store) - )); - $whereCond = sprintf('IF(`%s`.`value_id`>0, `%s`.`value`, `%s`.`value`) IN(?)', - $tableStore, $tableStore, $tableGlobal); - - $select - ->join( - array($tableGlobal => $attributeTable), - $joinCondGlobal, - array()) - ->joinLeft( - array($tableStore => $attributeTable), - $joinCondStore, - array()) - ->where($whereCond, $value); - } - - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team + */ +class Mage_CatalogIndex_Model_Mysql4_Data_Abstract extends Mage_CatalogIndex_Model_Resource_Data_Abstract +{ } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Configurable.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Configurable.php index c7a17adb3e..85e2ecd48d 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Configurable.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Configurable.php @@ -20,24 +20,18 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogIndex_Model_Mysql4_Data_Configurable extends Mage_CatalogIndex_Model_Mysql4_Data_Abstract + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team + */ +class Mage_CatalogIndex_Model_Mysql4_Data_Configurable extends Mage_CatalogIndex_Model_Resource_Data_Configurable { - /** - * Prepare select statement before 'fetchLinkInformation' function result fetch - * - * @param int $store - * @param string $table - * @param string $idField - * @param string $whereField - * @param int $id - * @param array $additionalWheres - */ - protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) - { - $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Grouped.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Grouped.php index 532570acda..d0cbbab81e 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Grouped.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Data/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,101 +28,10 @@ /** * CatalogIndex Grouped Products Data Retriever Resource Model * - * @category Mage - * @package Mage_CatalogIndex - * @author Magento Core Team + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Data_Grouped extends Mage_CatalogIndex_Model_Mysql4_Data_Abstract +class Mage_CatalogIndex_Model_Mysql4_Data_Grouped extends Mage_CatalogIndex_Model_Resource_Data_Grouped { - /** - * Return minimal prices for specified products - * - * @param array $products - * @param array $priceAttributes - * @param int $store - * @return array - */ - public function getMinimalPrice($products, $priceAttributes, $store) - { - $result = array(); - $store = Mage::app()->getStore($store); - - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('catalogindex/price'), array( - 'customer_group_id', 'value', 'tax_class_id')) - ->where('entity_id IN(?)', $products) - ->where('attribute_id IN(?)', $priceAttributes) - ->where('website_id=?', $store->getWebsiteId()); - $prices = $select->query()->fetchAll(); - - $groups = Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups(); - foreach ($groups as $group) { - $resultMinimal = null; - $resultTaxClassId = 0; - $taxClassId = 0; - $customerGroup = $group->getId(); - - $typedProducts = Mage::getSingleton('catalogindex/retreiver') - ->assignProductTypes($products); - foreach ($typedProducts as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - foreach ($typeIds as $id) { - $finalPrice = $retreiver->getFinalPrice($id, $store, $group); - if ((null === $resultMinimal) || ($finalPrice < $resultMinimal)) { - $resultMinimal = $finalPrice; - $resultTaxClassId = $retreiver->getTaxClassId($id, $store); - } - - $tiers = $retreiver->getTierPrices($id, $store); - foreach ($tiers as $tier) { - if ($tier['customer_group_id'] != $customerGroup && !$tier['all_groups']) { - continue; - } - if ((null === $resultMinimal) || ($tier['value'] < $resultMinimal)) { - $resultMinimal = $tier['value']; - $resultTaxClassId = $retreiver->getTaxClassId($tier['entity_id'], $store); - } - } - } - } - - foreach ($prices as $one) { - if ($one['customer_group_id'] != $customerGroup) { - continue; - } - - if ((null === $resultMinimal) || ($one['value'] < $resultMinimal)) { - $resultMinimal = $one['value']; - $taxClassId = $one['tax_class_id']; - } else { - $taxClassId = $resultTaxClassId; - } - } - - if (!is_null($resultMinimal)){ - $result[] = array( - 'customer_group_id' => $customerGroup, - 'minimal_value' => $resultMinimal, - 'tax_class_id' => $taxClassId - ); - } - } - - return $result; - } - - /** - * Prepare select statement before 'fetchLinkInformation' function result fetch - * - * @param int $store - * @param string $table - * @param string $idField - * @param string $whereField - * @param int $id - * @param array $additionalWheres - */ - protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) - { - $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer.php index 8971fdde5f..2a6a930bdf 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,642 +28,10 @@ /** * Reindexer resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Indexer extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Indexer extends Mage_CatalogIndex_Model_Resource_Indexer { - protected $_insertData = array(); - protected $_tableFields = array(); - protected $_attributeCache = array(); - - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - protected function _loadAttribute($id) - { - if (!isset($this->_attributeCache[$id])) { - $this->_attributeCache[$id] = Mage::getModel('eav/entity_attribute')->load($id); - } - - return $this->_attributeCache[$id]; - } - - /** - * Delete index data by specific conditions - * - * @param bool $eav clear eav index data flag - * @param bool $price clear price index data flag - * @param bool $minimal clear minimal price index data flag - * @param bool $finalPrice clear final price index data flag - * @param bool $tierPrice clear tier price index data flag - * @param mixed $products applicable products - * @param mixed $store applicable stores - */ - public function clear($eav = true, $price = true, $minimal = true, $finalPrice = true, $tierPrice = true, $products = null, $store = null) - { - $suffix = ''; - $priceSuffix = ''; - $tables = array('eav'=>'catalogindex/eav', 'price'=>'catalogindex/price'); - if (!is_null($products)) { - if ($products instanceof Mage_Catalog_Model_Product) { - $products = $products->getId(); - } elseif ($products instanceof Mage_Catalog_Model_Product_Condition_Interface) { - $suffix = 'entity_id IN ('.$products->getIdsSelect($this->_getWriteAdapter())->__toString().')'; - } - else if (!is_numeric($products) && !is_array($products)) { - Mage::throwException('Invalid products supplied for indexing'); - } - if (empty($suffix)) { - $suffix = $this->_getWriteAdapter()->quoteInto('entity_id in (?)', $products); - } - } - if (!is_null($store)) { - $websiteIds = array(); - - if ($store instanceof Mage_Core_Model_Store) { - $store = $store->getId(); - $websiteIds[] = Mage::app()->getStore($store)->getWebsiteId(); - } else if ($store instanceof Mage_Core_Model_Mysql4_Store_Collection) { - $store = $store->getAllIds(); - foreach ($store as $one) { - $websiteIds[] = Mage::app()->getStore($one)->getWebsiteId(); - } - } else if (is_array($store)) { - $resultStores = array(); - foreach ($store as $s) { - if ($s instanceof Mage_Core_Model_Store) { - $resultStores[] = $s->getId(); - $websiteIds[] = $s->getWebsiteId(); - } elseif (is_numeric($s)) { - $websiteIds[] = Mage::app()->getStore($s)->getWebsiteId(); - $resultStores[] = $s; - } - } - $store = $resultStores; - } - - if ($suffix) { - $suffix .= ' AND '; - } - - $priceSuffix = $suffix . $this->_getWriteAdapter()->quoteInto('website_id in (?)', $websiteIds); - $suffix .= $this->_getWriteAdapter()->quoteInto('store_id in (?)', $store); - - } - - if ($tierPrice) { - $tables['tierPrice'] = 'catalogindex/price'; - $tierPrice = array(Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tier_price')); - } - if ($finalPrice) { - $tables['finalPrice'] = 'catalogindex/price'; - $tierPrice = array(Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price')); - } - if ($minimal) { - $tables['minimal'] = 'catalogindex/minimal_price'; - } - - - foreach ($tables as $variable=>$table) { - $variable = $$variable; - $suffixToInsert = $suffix; - if (in_array($table, $this->_getPriceTables())) { - $suffixToInsert = $priceSuffix; - } - - if ($variable === true) { - $query = "DELETE FROM {$this->getTable($table)} "; - if ($suffixToInsert) { - $query .= "WHERE {$suffixToInsert}"; - } - - $this->_getWriteAdapter()->query($query); - } else if (is_array($variable) && count($variable)) { - $query = "DELETE FROM {$this->getTable($table)} WHERE "; - $query .= $this->_getWriteAdapter()->quoteInto("attribute_id in (?)", $variable); - if ($suffixToInsert) { - $query .= " AND {$suffixToInsert}"; - } - - $this->_getWriteAdapter()->query($query); - } - } - } - - /** - * Get tables which are used for index related with price - * - * @return array - */ - protected function _getPriceTables() - { - return array('catalogindex/price', 'catalogindex/minimal_price'); - } - - /** - * Reindex data for tier prices - * - * @param array $products array of product ids - * @param Mage_Core_Model_Store $store - * @param int | null $forcedId identifier of "parent" product - * - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function reindexTiers($products, $store, $forcedId = null) - { - $websiteId = $store->getWebsiteId(); - $attribute = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'tier_price'); - $this->_beginInsert( - 'catalogindex/price', - array('entity_id', 'attribute_id', 'value', 'website_id', 'customer_group_id', 'qty') - ); - - /** - * Get information about product types - * array ( - * $productType => array() - * ) - */ - $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); - if (is_null($forcedId)) { - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_TIERS)) { - foreach ($typeIds as $id) { - $children = $retreiver->getChildProductIds($store, $id); - if ($children) { - $this->reindexTiers($children, $store, $id); - } - } - } - } - } - - $attributeIndex = $this->getTierData($products, $store); - foreach ($attributeIndex as $index) { - $type = $index['type_id']; - $id = (is_null($forcedId) ? $index['entity_id'] : $forcedId); - if ($id && $index['value']) { - if ($index['all_groups'] == 1) { - foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { - $this->_insert('catalogindex/price', array( - $id, - $attribute, - $index['value'], - $websiteId, - (int) $group->getId(), - (int) $index['qty'] - )); - } - } else { - $this->_insert('catalogindex/price', array( - $id, - $attribute, - $index['value'], - $websiteId, - (int) $index['customer_group_id'], - (int) $index['qty'] - )); - } - } - } - $this->_commitInsert('catalogindex/price'); - return $this; - } - - /** - * Reindex product prices - * - * @param array | int $products product ids - * @param array $attributeIds - * @param Mage_Core_Model_Store $store - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function reindexPrices($products, $attributeIds, $store) - { - $this->reindexAttributes($products, $attributeIds, $store, null, 'catalogindex/price', true); - return $this; - } - - /** - * Reindex product final prices - * - * @param array $products array of product ids - * @param Mage_Core_Model_Store $store - * @param int | null $forcedId identifier of "parent" product - * - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function reindexFinalPrices($products, $store, $forcedId = null) - { - $priceAttribute = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', 'price'); - $this->_beginInsert('catalogindex/price', array( - 'entity_id', - 'website_id', - 'customer_group_id', - 'value', - 'attribute_id', - 'tax_class_id' - )); - - $productTypes = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); - foreach ($productTypes as $type=>$products) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - foreach ($products as $product) { - if (is_null($forcedId)) { - if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { - $children = $retreiver->getChildProductIds($store, $product); - if ($children) { - $this->reindexFinalPrices($children, $store, $product); - } - } - } - foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { - $finalPrice = $retreiver->getFinalPrice($product, $store, $group); - $taxClassId = $retreiver->getTaxClassId($product, $store); - $id = $product; - if (!is_null($forcedId)) { - $id = $forcedId; - } - - if (false !== $finalPrice && false !== $id && false !== $priceAttribute) { - $this->_insert('catalogindex/price', array( - $id, - $store->getWebsiteId(), - $group->getId(), - $finalPrice, - $priceAttribute, - $taxClassId - )); - } - } - } - } - $this->_commitInsert('catalogindex/price'); - return $this; - } - - /** - * Reindex product minimal prices - * - * @param array $products array of product ids - * @param Mage_Core_Model_Store $store - * - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function reindexMinimalPrices($products, $store) - { - $this->_beginInsert('catalogindex/minimal_price', array( - 'website_id', - 'entity_id', - 'customer_group_id', - 'value', - 'tax_class_id' - )); - $this->clear(false, false, true, false, false, $products, $store); - $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); - - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - - foreach ($typeIds as $id) { - $minimal = array(); - if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { - $children = $retreiver->getChildProductIds($store, $id); - if ($children) { - $minimal = $this->getMinimalPrice(array($type=>$children), $store); - } - } else { - $minimal = $this->getMinimalPrice(array($type=>array($id)), $store); - } - - if (is_array($minimal)) { - foreach ($minimal as $price) { - if (!isset($price['tax_class_id'])) { - $price['tax_class_id'] = 0; - } - $this->_insert('catalogindex/minimal_price', array( - $store->getWebsiteId(), - $id, - $price['customer_group_id'], - $price['minimal_value'], - $price['tax_class_id'] - )); - } - } - } - } - - $this->_commitInsert('catalogindex/minimal_price'); - return $this; - } - - /** - * Reindex attributes data - * - * @param array $products - * @param array $attributeIds - * @param mixed $store - * @param int|null $forcedId - * @param string $table - * @param bool $storeIsWebsite - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function reindexAttributes($products, $attributeIds, $store, $forcedId = null, $table = 'catalogindex/eav', $storeIsWebsite = false) - { - $storeField = 'store_id'; - $websiteId = null; - if ($storeIsWebsite) { - $storeField = 'website_id'; - if ($store instanceof Mage_Core_Model_Store) { - $websiteId = $store->getWebsiteId(); - } else { - $websiteId = Mage::app()->getStore($store)->getWebsiteId(); - } - } - - $this->_beginInsert($table, array('entity_id', 'attribute_id', 'value', $storeField)); - - $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); - - if (is_null($forcedId)) { - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_ATTRIBUTES)) { - foreach ($typeIds as $id) { - $children = $retreiver->getChildProductIds($store, $id); - if ($children) { - $this->reindexAttributes($children, $attributeIds, $store, $id, $table, $storeIsWebsite); - } - } - } - } - } - - $attributeIndex = $this->getProductData($products, $attributeIds, $store); - foreach ($attributeIndex as $index) { - $type = $index['type_id']; - $id = (is_null($forcedId) ? $index['entity_id'] : $forcedId); - - if ($id && $index['attribute_id'] && isset($index['value'])) { - $attribute = $this->_loadAttribute($index['attribute_id']); - if ($attribute->getFrontendInput() == 'multiselect') { - $index['value'] = explode(',', $index['value']); - } - - if (is_array($index['value'])) { - foreach ($index['value'] as $value) { - $this->_insert($table, array( - $id, - $index['attribute_id'], - $value, - (is_null($websiteId) ? $store->getId() : $websiteId) - )); - } - } else { - $this->_insert($table, array( - $id, - $index['attribute_id'], - $index['value'], - (is_null($websiteId) ? $store->getId() : $websiteId) - )); - } - } - } - - $this->_commitInsert($table); - return $this; - } - - /** - * Get tier prices data by set of products - * - * @param array $products - * @param Mage_Core_Model_Store $store - * @return array - */ - public function getTierData($products, $store){ - $result = array(); - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - $byType = $retreiver->getTierPrices($typeIds, $store); - if ($byType) { - $result = array_merge($result, $byType); - } - } - return $result; - } - - /** - * Get minimal prices by set of the products - * - * @param arary $products - * @param Mage_Core_Model_Store $store - * @return array - */ - public function getMinimalPrice($products, $store) - { - $result = array(); - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - $byType = $retreiver->getMinimalPrice($typeIds, $store); - if ($byType) { - $result = array_merge($result, $byType); - } - } - return $result; - } - - /** - * Get data for products - * - * @param array $products - * @param array $attributeIds - * @param Mage_Core_Model_Store $store - * @return array - */ - public function getProductData($products, $attributeIds, $store){ - $result = array(); - foreach ($products as $type=>$typeIds) { - $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); - $byType = $retreiver->getAttributeData($typeIds, $attributeIds, $store); - if ($byType) { - $result = array_merge($result, $byType); - } - } - return $result; - } - - /** - * Prepare base information for data insert - * - * @param string $table - * @param array $fields - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - protected function _beginInsert($table, $fields){ - $this->_tableFields[$table] = $fields; - return $this; - } - - /** - * Put data into table - * - * @param string $table - * @param bool $forced - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - protected function _commitInsert($table, $forced = true){ - if (isset($this->_insertData[$table]) && count($this->_insertData[$table]) && ($forced || count($this->_insertData[$table]) >= 100)) { - $query = 'REPLACE INTO ' . $this->getTable($table) . ' (' . implode(', ', $this->_tableFields[$table]) . ') VALUES '; - $separator = ''; - foreach ($this->_insertData[$table] as $row) { - $rowString = $this->_getWriteAdapter()->quoteInto('(?)', $row); - $query .= $separator . $rowString; - $separator = ', '; - } - $this->_getWriteAdapter()->query($query); - $this->_insertData[$table] = array(); - } - return $this; - } - - /** - * Insert data to table - * - * @param string $table - * @param array $data - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - protected function _insert($table, $data) { - $this->_insertData[$table][] = $data; - $this->_commitInsert($table, false); - return $this; - } - - /** - * Add price columns for catalog product flat table - * - * @param Varien_Object $object - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function prepareCatalogProductFlatColumns(Varien_Object $object) - { - $columns = $object->getColumns(); - - foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { - $columnName = 'display_price_group_' . $group->getId(); - $columns[$columnName] = array( - 'type' => 'decimal(12,4)', - 'unsigned' => false, - 'is_null' => true, - 'default' => null, - 'extra' => null - ); - } - - $object->setColumns($columns); - - return $this; - } - - /** - * Add price indexes for catalog product flat table - * - * @param Varien_Object $object - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function prepareCatalogProductFlatIndexes(Varien_Object $object) - { - $indexes = $object->getIndexes(); - - foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { - $columnName = 'display_price_group_' . $group->getId(); - $indexName = 'IDX_DISPLAY_PRICE_GROUP_' . $group->getId(); - $indexes[$indexName] = array( - 'type' => 'index', - 'fields' => array($columnName) - ); - } - - $object->setIndexes($indexes); - - return $this; - } - - /** - * Update prices for Catalog Product flat - * - * @param int $storeId - * @param string $tableName - * @return Mage_CatalogIndex_Model_Mysql4_Indexer - */ - public function updateCatalogProductFlat($storeId, $productIds = null, $tableName = null) - { - if (is_null($tableName)) { - $tableName = $this->getTable('catalog/product_flat') . '_' . $storeId; - } - $addChildData = Mage::helper('catalog/product_flat')->isAddChildData(); - - $priceAttribute = Mage::getSingleton('eav/entity_attribute') - ->getIdByCode('catalog_product', 'price'); - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - - foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { - $columnName = 'display_price_group_' . $group->getId(); - - /** - * Update prices of main products in flat table - */ - $select = $this->_getWriteAdapter()->select() - ->join( - array('p' => $this->getTable('catalogindex/price')), - "`e`.`entity_id`=`p`.`entity_id`" - . " AND `p`.`attribute_id`={$priceAttribute}" - . " AND `p`.`customer_group_id`={$group->getId()}" - . " AND `p`.`website_id`={$websiteId}", - array($columnName => 'value')); - if ($addChildData) { - $select->where('e.is_child=?', 0); - } - - if ($productIds instanceof Mage_Catalog_Model_Product_Condition_Interface) { - $select->where('e.entity_id IN ('.$productIds->getIdsSelect($this->_getWriteAdapter())->__toString().')'); - } elseif (!is_null($productIds)) { - $select->where("e.entity_id IN(?)", $productIds); - } - - $sql = $select->crossUpdateFromSelect(array('e' => $tableName)); - $this->_getWriteAdapter()->query($sql); - - if ($addChildData) { - /** - * Update prices for children products in flat table - */ - $select = $this->_getWriteAdapter()->select() - ->join( - array('p' => $this->getTable('catalogindex/price')), - "`e`.`child_id`=`p`.`entity_id`" - . " AND `p`.`attribute_id`={$priceAttribute}" - . " AND `p`.`customer_group_id`={$group->getId()}" - . " AND `p`.`website_id`={$websiteId}", - array($columnName => 'value')) - ->where('e.is_child=?', 1); - - if ($productIds instanceof Mage_Catalog_Model_Product_Condition_Interface) { - $select->where('e.child_id IN ('.$productIds->getIdsSelect($this->_getWriteAdapter())->__toString().')'); - } elseif (!is_null($productIds)) { - $select->where("e.child_id IN(?)", $productIds); - } - - $sql = $select->crossUpdateFromSelect(array('e' => $tableName)); - $this->_getWriteAdapter()->query($sql); - } - - } - - return $this; - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Abstract.php index 975079972e..46d4dea0ec 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Abstract.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,90 +28,10 @@ /** * Indexer resource model abstraction * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract extends Mage_CatalogIndex_Model_Resource_Indexer_Abstract { - /** - * should be defined because abstract - */ - protected function _construct() - { - - } - - public function saveIndex($data, $storeId, $productId) - { - return $this->saveIndices(array($data), $storeId, $productId); - } - - public function saveIndices(array $data, $storeId, $productId) - { - $this->_executeReplace($data, $storeId, $productId); - } - - protected function _executeReplace($data, $storeId, $productId) - { - $this->beginTransaction(); - try { - foreach ($data as $row) { - $row[$this->_entityIdFieldName] = $productId; - $this->_getWriteAdapter()->insert($this->getMainTable(), $row); - } - $this->commit(); - } catch (Exception $e) { - $this->rollBack(); - throw $e; - } - - return $this; - } - - public function cleanup($productId, $storeId = null, $attributeId = null) - { - $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_entityIdFieldName} = ?", $productId); - - if (!is_null($storeId)) - $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_storeIdFieldName} = ?", $storeId); - - if (!is_null($attributeId)) - $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_attributeIdFieldName} = ?", $attributeId); - - $conditions = implode (' AND ', $conditions); - $this->_getWriteAdapter()->delete($this->getMainTable(), $conditions); - } - - public function loadAttributeCodesByCondition($conditions) - { - $table = $this->getTable('eav/attribute'); - $select = $this->_getReadAdapter()->select(); - $select->from(array('main_table' => $table), 'attribute_id') - ->join(array('additional_table' => $this->getTable('catalog/eav_attribute')), 'additional_table.attribute_id=main_table.attribute_id'); - $select->distinct(true); - - if (is_array($conditions)) { - foreach ($conditions as $k=>$condition) { - if (is_array($condition)) { - if ($k == 'or') { - $function = 'where'; - foreach ($condition as $field=>$value) { - if (is_array($value)) - $select->$function("{$field} in (?)", $value); - else - $select->$function("{$field} = ?", $value); - - $function = 'orWhere'; - } - } else { - $select->where("{$k} in (?)", $condition); - } - } else { - $select->where("{$k} = ?", $condition); - } - } - } else { - $select->where($conditions); - } - return $this->_getReadAdapter()->fetchCol($select); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Eav.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Eav.php index dbbd65335f..b010796d92 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Eav.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Eav.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,10 @@ /** * Eav indexer resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Indexer_Eav extends Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract +class Mage_CatalogIndex_Model_Mysql4_Indexer_Eav extends Mage_CatalogIndex_Model_Resource_Indexer_Eav { - protected function _construct() - { - $this->_init('catalogindex/eav', 'index_id'); - - $this->_entityIdFieldName = 'entity_id'; - $this->_attributeIdFieldName = 'attribute_id'; - $this->_storeIdFieldName = 'store_id'; - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Minimalprice.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Minimalprice.php index c112151475..7a4d694d97 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Minimalprice.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Minimalprice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,41 +28,10 @@ /** * Price indexer resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract +class Mage_CatalogIndex_Model_Mysql4_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice { - protected function _construct() - { - $this->_init('catalogindex/minimal_price', 'index_id'); - - $this->_entityIdFieldName = 'entity_id'; - $this->_storeIdFieldName = 'store_id'; - } - - public function getMinimalValue($conditions) - { - $select = $this->_getReadAdapter()->select(); - $select->from($this->getTable('catalogindex/price'), 'MIN(value)'); - foreach ($conditions as $field=>$value) { - $condition = "{$field} = ?"; - if (is_array($value)) - $condition = "{$field} in (?)"; - - $select->where($condition, $value); - } - - return $this->_getReadAdapter()->fetchOne($select); - } - - public function cleanup($productId, $storeId = null, $attributeId = null) - { - $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_entityIdFieldName} = ?", $productId); - - if (!is_null($storeId)) - $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_storeIdFieldName} = ?", $storeId); - - $conditions = implode (' AND ', $conditions); - $this->_getWriteAdapter()->delete($this->getMainTable(), $conditions); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Price.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Price.php index 15075bbc81..53b74c0571 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Price.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Indexer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,10 @@ /** * Price indexer resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Indexer_Price extends Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract +class Mage_CatalogIndex_Model_Mysql4_Indexer_Price extends Mage_CatalogIndex_Model_Resource_Indexer_Price { - protected function _construct() - { - $this->_init('catalogindex/price', 'index_id'); - - $this->_entityIdFieldName = 'entity_id'; - $this->_attributeIdFieldName = 'attribute_id'; - $this->_storeIdFieldName = 'store_id'; - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Price.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Price.php index 54cddc28c5..73bdd1c711 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Price.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,198 +28,10 @@ /** * Price index resource model * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Price extends Mage_CatalogIndex_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Price extends Mage_CatalogIndex_Model_Resource_Price { - protected $_rate = 1; - protected $_customerGroupId; - protected $_taxRates = null; - - protected function _construct() - { - $this->_init('catalogindex/price', 'index_id'); - } - - public function setRate($rate) - { - $this->_rate = $rate; - } - - public function getRate() - { - if (!$this->_rate) { - $this->_rate = 1; - } - return $this->_rate; - } - - public function setCustomerGroupId($customerGroupId) - { - $this->_customerGroupId = $customerGroupId; - } - - public function getCustomerGroupId() - { - return $this->_customerGroupId; - } - - public function getMaxValue($attribute = null, $entitySelect) - { - $select = clone $entitySelect; - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array()); - - if ($attribute->getAttributeCode() == 'price') { - $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); - $args = array( - 'select'=>$select, - 'table'=>'price_table', - 'store_id'=>$this->getStoreId(), - 'response_object'=>$response, - ); - Mage::dispatchEvent('catalogindex_prepare_price_select', $args); - } - - $select - ->columns("MAX(price_table.value".implode('', $response->getAdditionalCalculations()).")") - ->where('price_table.website_id = ?', $this->getWebsiteId()) - ->where('price_table.attribute_id = ?', $attribute->getId()); - - return $this->_getReadAdapter()->fetchOne($select)*$this->getRate(); - } - - public function getCount($range, $attribute, $entitySelect) - { - $select = clone $entitySelect; - $select->reset(Zend_Db_Select::COLUMNS); - $select->reset(Zend_Db_Select::ORDER); - $select->reset(Zend_Db_Select::LIMIT_COUNT); - $select->reset(Zend_Db_Select::LIMIT_OFFSET); - - $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array()); - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - if ($attribute->getAttributeCode() == 'price') { - $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); - $args = array( - 'select'=>$select, - 'table'=>'price_table', - 'store_id'=>$this->getStoreId(), - 'response_object'=>$response, - ); - Mage::dispatchEvent('catalogindex_prepare_price_select', $args); - } - - - $fields = array('count'=>'COUNT(DISTINCT price_table.entity_id)', 'range'=>"FLOOR(((price_table.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()})/{$range})+1"); - - $select->columns($fields) - ->group('range') - ->where('price_table.website_id = ?', $this->getWebsiteId()) - ->where('price_table.attribute_id = ?', $attribute->getId()); - - - $result = $this->_getReadAdapter()->fetchAll($select); - - $counts = array(); - foreach ($result as $row) { - $counts[$row['range']] = $row['count']; - } - - return $counts; - } - - public function getFilteredEntities($range, $index, $attribute, $entityIdsFilter, $tableName = 'price_table') - { - $select = $this->_getReadAdapter()->select(); - $select->from(array($tableName=>$this->getMainTable()), $tableName . '.entity_id'); - - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - $select - ->distinct(true) - ->where($tableName . '.entity_id in (?)', $entityIdsFilter) - ->where($tableName . '.website_id = ?', $this->getWebsiteId()) - ->where($tableName . '.attribute_id = ?', $attribute->getId()); - - if ($attribute->getAttributeCode() == 'price') { - $select->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId()); - $args = array( - 'select'=>$select, - 'table'=>$tableName, - 'store_id'=>$this->getStoreId(), - 'response_object'=>$response, - ); - Mage::dispatchEvent('catalogindex_prepare_price_select', $args); - } - - $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range); - $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range); - - - return $this->_getReadAdapter()->fetchCol($select); - } - - public function applyFilterToCollection($collection, $attribute, $range, $index, $tableName = 'price_table') - { - /** - * Distinct required for removing duplicates in case when we have grouped products - * which contain multiple rows for one product id - */ - $collection->getSelect()->distinct(true); - $tableName = $tableName.'_'.$attribute->getAttributeCode(); - $collection->getSelect()->joinLeft( - array($tableName => $this->getMainTable()), - $tableName .'.entity_id=e.entity_id', - array() - ); - - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - $collection->getSelect() - ->where($tableName . '.website_id = ?', $this->getWebsiteId()) - ->where($tableName . '.attribute_id = ?', $attribute->getId()); - - if ($attribute->getAttributeCode() == 'price') { - $collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId()); - $args = array( - 'select'=>$collection->getSelect(), - 'table'=>$tableName, - 'store_id'=>$this->getStoreId(), - 'response_object'=>$response, - ); - - Mage::dispatchEvent('catalogindex_prepare_price_select', $args); - } - - $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range); - $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range); - - return $this; - } - - public function getMinimalPrices($ids) - { - if (!$ids) { - return array(); - } - $select = $this->_getReadAdapter()->select(); - $select->from(array('price_table'=>$this->getTable('catalogindex/minimal_price')), - array('price_table.entity_id', 'value'=>"(price_table.value)", 'tax_class_id'=>'(price_table.tax_class_id)')) - ->where('price_table.entity_id in (?)', $ids) - ->where('price_table.website_id = ?', $this->getWebsiteId()) - ->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); - return $this->_getReadAdapter()->fetchAll($select); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Retreiver.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Retreiver.php index 2feee937b4..69333eaa57 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Retreiver.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Retreiver.php @@ -20,33 +20,18 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Index type retreiver resource model * - * @author Magento Core Team + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team */ -class Mage_CatalogIndex_Model_Mysql4_Retreiver extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogIndex_Model_Mysql4_Retreiver extends Mage_CatalogIndex_Model_Resource_Retreiver { - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - /** - * Return id-type pairs - * - * @param array $ids - * @return array - */ - public function getProductTypes($ids) - { - $select = $this->_getReadAdapter()->select() - ->from(array('main_table'=>$this->getTable('catalog/product')), array('id'=>'main_table.entity_id', 'type'=>'main_table.type_id')) - ->where('main_table.entity_id in (?)', $ids); - return $this->_getReadAdapter()->fetchAll($select); - } } diff --git a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Setup.php b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Setup.php index bdaa6e622f..c79aa20948 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/CatalogIndex/Model/Mysql4/Setup.php @@ -20,44 +20,18 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogIndex_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup -{ - protected $_storeToWebsite = null; - - public function convertStoreToWebsite($table) - { - $assignment = $this->_getStoreToWebsiteAssignments(); - foreach ($assignment as $website=>$stores) { - $this->_setWebsiteInfo($table, $website, $stores); - } - return $this; - } - - protected function _getStoreToWebsiteAssignments() - { - if (is_null($this->_storeToWebsite)) { - $this->_storeToWebsite = array(); - $websiteCollection = Mage::getModel('core/website')->getCollection(); - foreach ($websiteCollection as $website) { - $this->_storeToWebsite[$website->getId()] = $website->getStoreIds(); - } - } - return $this->_storeToWebsite; - } - - protected function _setWebsiteInfo($table, $websiteId, $storeIds) - { - $this->getConnection()->update( - $table, - array('website_id'=>$websiteId), - $this->getConnection()->quoteInto('store_id IN (?)', $storeIds) - ); - - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team + */ +class Mage_CatalogIndex_Model_Mysql4_Setup extends Mage_CatalogIndex_Model_Resource_Setup +{ } diff --git a/app/code/core/Mage/CatalogIndex/Model/Observer.php b/app/code/core/Mage/CatalogIndex/Model/Observer.php index e1d959c5d7..77d4637832 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Observer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/Model/Price.php b/app/code/core/Mage/CatalogIndex/Model/Price.php index 280292107f..af73f50098 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Price.php +++ b/app/code/core/Mage/CatalogIndex/Model/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,28 @@ /** * Price index model * + * @method Mage_CatalogIndex_Model_Resource_Price _getResource() + * @method Mage_CatalogIndex_Model_Resource_Price getResource() + * @method Mage_CatalogIndex_Model_Price setEntityId(int $value) + * @method int getCustomerGroupId() + * @method Mage_CatalogIndex_Model_Price setCustomerGroupId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogIndex_Model_Price setWebsiteId(int $value) + * @method int getTaxClassId() + * @method Mage_CatalogIndex_Model_Price setTaxClassId(int $value) + * @method float getPrice() + * @method Mage_CatalogIndex_Model_Price setPrice(float $value) + * @method float getFinalPrice() + * @method Mage_CatalogIndex_Model_Price setFinalPrice(float $value) + * @method float getMinPrice() + * @method Mage_CatalogIndex_Model_Price setMinPrice(float $value) + * @method float getMaxPrice() + * @method Mage_CatalogIndex_Model_Price setMaxPrice(float $value) + * @method float getTierPrice() + * @method Mage_CatalogIndex_Model_Price setTierPrice(float $value) + * + * @category Mage + * @package Mage_CatalogIndex * @author Magento Core Team */ class Mage_CatalogIndex_Model_Price extends Mage_Core_Model_Abstract @@ -60,7 +82,7 @@ public function applyFilterToCollection($collection, $attribute, $range, $index) return $this->_getResource()->applyFilterToCollection($collection, $attribute, $range, $index); } - public function addMinimalPrices(Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection) + public function addMinimalPrices(Mage_Catalog_Model_Resource_Product_Collection $collection) { $minimalPrices = $this->_getResource()->getMinimalPrices($collection->getLoadedIds()); diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Abstract.php new file mode 100755 index 0000000000..e4830d5d4f --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Abstract.php @@ -0,0 +1,84 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + protected $_storeId = 0; + + protected $_websiteId = null; + + /** + * Initialize model + * + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _construct() + { + return parent::_construct(); + } + + /** + * storeId setter + * + * @param int $storeId + */ + public function setStoreId($storeId) + { + $this->_storeId = $storeId; + } + + /** + * storeId getter + * + * @return int + */ + public function getStoreId() + { + return $this->_storeId; + } + + /** + * websiteId getter + * + * @return int + */ + public function getWebsiteId() + { + if (is_null($this->_websiteId)) { + $result = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); + $this->_websiteId = $result; + } + return $this->_websiteId; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php new file mode 100755 index 0000000000..b4026c9c8a --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php @@ -0,0 +1,260 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Aggregation extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Table name of catalogindex/aggregation_tag table + * + * @var string + */ + protected $_tagTable; + + /** + * Table name of catalogindex/aggregation_to_tag table + * + * @var string + */ + protected $_toTagTable; + + /** + * Initialize resource tables + * + */ + protected function _construct() + { + $this->_init('catalogindex/aggregation', 'aggregation_id'); + $this->_tagTable = $this->getTable('catalogindex/aggregation_tag'); + $this->_toTagTable = $this->getTable('catalogindex/aggregation_to_tag'); + } + + /** + * Get aggregated cache data by data key and store + * + * @param string $key + * @param int $storeId + * @return array + */ + public function getCacheData($key, $storeId) + { + $select = $this->_getReadAdapter()->select() + ->from(array('a'=>$this->getMainTable()), 'data') + ->where('a.store_id=?', $storeId) + ->where('a.key=?', $key); + $data = $this->_getReadAdapter()->fetchOne($select); + if ($data) { + $data = unserialize($data); + } else { + $data = array(); + } + return $data; + } + + /** + * Save data to aggreagation table with tags relations + * + * @param array $data + * @param string $key + * @param array|string $tags + * @param int $storeId + * @return Mage_CatalogIndex_Model_Resource_Aggregation + */ + public function saveCacheData($data, $key, $tags, $storeId) + { + $data = serialize($data); + $tags = $this->_getTagIds($tags); + + /* + $select = $this->_getWriteAdapter()->select() + ->from(array('a'=>$this->getMainTable()), $this->getIdFieldName()) + ->where('a.store_id=?', $storeId) + ->where('a.key=?', $key); + + $id = $this->_getWriteAdapter()->fetchOne($select); + if ($id) { + $this->_getWriteAdapter()->update( + $this->getMainTable(), + array('data'=>$data), + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $id) + ); + } else { + $this->_getWriteAdapter()->insert($this->getMainTable(), array( + 'store_id' => $storeId, + 'created_at'=> $this->formatDate(time()), + 'key' => $key, + 'data' => $data + )); + $id = $this->_getWriteAdapter()->lastInsertId(); + } + */ + + $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), array( + 'store_id' => $storeId, + 'created_at'=> $this->formatDate(time()), + 'key' => $key, + 'data' => $data + ), array('created_at', 'data')); + + $id = $this->_getWriteAdapter()->lastInsertId($this->getMainTable()); + + $this->_saveTagRelations($id, $tags); + return $this; + } + + /** + * Clear data in cache + * + * @param array $tags + * @param int|null|string $storeId + * @return Mage_CatalogIndex_Model_Resource_Aggregation + */ + public function clearCacheData($tags, $storeId) + { + $conditions = array(); + if (!$write = $this->_getWriteAdapter()) { + return $this; + } + if (!empty($tags)) { + $tagIds = $this->_getTagIds($tags); + $select = $write->select() + ->from($this->_toTagTable, 'aggregation_id') + ->where('tag_id IN (?)', $tagIds); + $conditions[] = $write->quoteInto('aggregation_id IN ?', $select); + } + + if ($storeId !== null) { + $conditions[] = $write->quoteInto('store_id=?', $storeId); + } + + $write->delete($this->getMainTable(), implode(' AND ', $conditions)); + return $this; + } + + /** + * Save related tags for aggreagation data + * + * @param int $aggregationId + * @param array $tags + * @return Mage_CatalogIndex_Model_Resource_Aggregation + */ + protected function _saveTagRelations($aggregationId, $tags) + { + $query = "REPLACE INTO `{$this->_toTagTable}` (aggregation_id, tag_id) VALUES "; + $data = array(); + foreach ($tags as $tagId) { + $data[] = $aggregationId.','.$tagId; + } + $query.= '(' . implode('),(', $data) . ')'; + $this->_getWriteAdapter()->query($query); + return $this; + } + + /** + * Get identifiers of tags + * if some tags not exist they will be added + * + * @param array $tags + * @return array + */ + protected function _getTagIds($tags) + { + if (!is_array($tags)) { + $tags = array($tags); + } + + $select = $this->_getReadAdapter()->select() + ->from(array('tags'=>$this->_tagTable), array('tag_code', 'tag_id')) + ->where('tags.tag_code IN (?)', $tags); + + $tagIds = $this->_getReadAdapter()->fetchPairs($select); + + /** + * Detect new tags + */ + $newTags = array_diff($tags, array_keys($tagIds)); + if (!empty($newTags)) { + $this->_addTags($newTags); + $select->reset(Zend_Db_Select::WHERE) + ->where('tags.tag_code IN (?)', $newTags); + $newTags = $this->_getReadAdapter()->fetchPairs($select); + $tagIds = array_merge($tagIds, $newTags); + } + return $tagIds; + } + + /** + * Insert tags to tag table + * + * @param string | array $tags + * @return Mage_CatalogIndex_Model_Resource_Aggregation + */ + protected function _addTags($tags) + { + if (is_array($tags)) { + $tags = array_unique($tags); + foreach ($tags as $index => $tag) { + $tags[$index] = $this->_getWriteAdapter()->quote($tag); + } + $query = "INSERT INTO `{$this->_tagTable}` (tag_code) VALUES (".implode('),(', $tags).")"; + $this->_getWriteAdapter()->query($query); + } + else { + $this->_getWriteAdapter()->insert($this->_tagTable, array( + 'tag_code' => $tags + )); + } + return $this; + } + + /** + * ProductCategoryPaths getter + * + * @param array $productIds + * @return array + */ + public function getProductCategoryPaths($productIds) + { + $select = $this->_getReadAdapter()->select() + ->from(array('cat'=>$this->getTable('catalog/category')), 'path') + ->joinInner( + array('cat_prod'=>$this->getTable('catalog/category_product')), + $this->_getReadAdapter()->quoteInto( + 'cat.entity_id=cat_prod.category_id AND cat_prod.product_id IN (?)', + $productIds + ), + array() + ); + return $this->_getReadAdapter()->fetchCol($select); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Attribute.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Attribute.php new file mode 100755 index 0000000000..411cb3583e --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Attribute.php @@ -0,0 +1,132 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Attribute extends Mage_CatalogIndex_Model_Resource_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogindex/eav', 'index_id'); + } + + /** + * Enter description here ... + * + * @param unknown_type $attribute + * @param unknown_type $filter + * @param unknown_type $entityFilter + * @return unknown + */ + public function getFilteredEntities($attribute, $filter, $entityFilter) + { + $select = $this->_getReadAdapter()->select(); + + $select + ->from($this->getMainTable(), 'entity_id') + ->distinct(true) + ->where('entity_id in (?)', $entityFilter) + ->where('store_id = ?', $this->getStoreId()) + ->where('attribute_id = ?', $attribute->getId()) + ->where('value = ?', $filter); + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Enter description here ... + * + * @param unknown_type $attribute + * @param unknown_type $entitySelect + * @return unknown + */ + public function getCount($attribute, $entitySelect) + { + $select = clone $entitySelect; + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + $fields = array('count'=>'COUNT(index.entity_id)', 'index.value'); + + $select->columns($fields) + ->join(array('index'=>$this->getMainTable()), 'index.entity_id=e.entity_id', array()) + ->where('index.store_id = ?', $this->getStoreId()) + ->where('index.attribute_id = ?', $attribute->getId()) + ->group('index.value'); + + $select = $select->__toString(); +// $alias = $this->_getReadAdapter()->quoteTableAs($this->getMainTable(), 'index'); + $result = $this->_getReadAdapter()->fetchAll($select); + + $counts = array(); + foreach ($result as $row) { + $counts[$row['value']] = $row['count']; + } + return $counts; + } + + /** + * Enter description here ... + * + * @param unknown_type $collection + * @param unknown_type $attribute + * @param unknown_type $value + * @return Mage_CatalogIndex_Model_Resource_Attribute + */ + public function applyFilterToCollection($collection, $attribute, $value) + { + /** + * Will be used after SQL review + */ +// if ($collection->isEnabledFlat()) { +// $collection->getSelect()->where("e.{$attribute->getAttributeCode()}=?", $value); +// return $this; +// } + + $alias = 'attr_index_'.$attribute->getId(); + $collection->getSelect()->join( + array($alias => $this->getMainTable()), + $alias.'.entity_id=e.entity_id', + array() + ) + ->where($alias.'.store_id = ?', $this->getStoreId()) + ->where($alias.'.attribute_id = ?', $attribute->getId()) + ->where($alias.'.value = ?', $value); + return $this; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Abstract.php new file mode 100755 index 0000000000..2c844b6611 --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Abstract.php @@ -0,0 +1,315 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Data_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Attribute id by code cache + * + * @var array + */ + protected $_attributeCodeIds = array(); + + /** + * Link select object + * + * @var Zend_Db_Select + */ + protected $_linkSelect = null; + + /** + * Set link select + * + * @param Zend_Db_Select $select + * @return Mage_CatalogIndex_Model_Resource_Data_Abstract + */ + protected function _setLinkSelect($select) + { + $this->_linkSelect = $select; + return $this; + } + + /** + * Get link select + * + * @return Zend_Db_Select $select + */ + protected function _getLinkSelect() + { + return $this->_linkSelect; + } + + /** + * Init resource + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Retreive specified attribute data for specified products from specified store + * + * @param array $products + * @param array $attributes + * @param int $store + * @return unknown + */ + public function getAttributeData($products, $attributes, $store) + { + $suffixes = array('decimal', 'varchar', 'int', 'text', 'datetime'); + if (!is_array($products)) { + $products = new Zend_Db_Expr($products); + } + $result = array(); + foreach ($suffixes as $suffix) { + $tableName = "{$this->getTable('catalog/product')}_{$suffix}"; + $condition = "product.entity_id = c.entity_id AND c.store_id = {$store} AND c.attribute_id = d.attribute_id"; + $defaultCondition = "product.entity_id = d.entity_id AND d.store_id = 0"; + $fields = array( + 'entity_id', + 'type_id', + 'attribute_id' => 'IF(c.value_id > 0, c.attribute_id, d.attribute_id)', + 'value' => 'IF(c.value_id > 0, c.value, d.value)' + ); + + $select = $this->_getReadAdapter()->select() + ->from(array('product'=>$this->getTable('catalog/product')), $fields) + ->where('product.entity_id in (?)', $products) + ->joinRight(array('d'=>$tableName), $defaultCondition, array()) + ->joinLeft(array('c'=>$tableName), $condition, array()) + ->where('c.attribute_id IN (?) OR d.attribute_id IN (?)', $attributes); + $part = $this->_getReadAdapter()->fetchAll($select); + + if (is_array($part)) { + $result = array_merge($result, $part); + } + } + + return $result; + } + + /** + * Returns an array of product children/parents + * + * @param int $store + * @param string $table + * @param string $idField + * @param string $whereField + * @param int $id + * @param array $additionalWheres + * @return mixed + */ + public function fetchLinkInformation($store, $table, $idField, $whereField, $id, $additionalWheres = array()) + { + $idsConditionSymbol = "= ?"; + if (is_array($id)) { + $idsConditionSymbol = "in (?)"; + } + + $select = $this->_getReadAdapter()->select(); + $select->from(array('l'=>$this->getTable($table)), array("l.{$idField}")) + ->where("l.{$whereField} {$idsConditionSymbol}", $id); + foreach ($additionalWheres as $field=>$condition) { + $select->where("l.$field = ?", $condition); + } + + // add status filter + $this->_addAttributeFilter($select, 'status', 'l', $idField, $store, + Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + // add website filter + if ($websiteId = Mage::app()->getStore($store)->getWebsiteId()) { + $select->join( + array('w' => $this->getTable('catalog/product_website')), + "l.{$idField}=w.product_id AND w.website_id={$websiteId}", + array() + ); + } + + $this->_setLinkSelect($select); + $this->_prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres); + + return $this->_getWriteAdapter()->fetchCol($this->_getLinkSelect()); + } + + /** + * Prepare select statement before 'fetchLinkInformation' function result fetch + * + * @param int $store + * @param string $table + * @param string $idField + * @param string $whereField + * @param int $id + * @param array $additionalWheres + */ + protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) + { + + } + + /** + * Return minimal prices for specified products + * + * @param array $products + * @param array $priceAttributes + * @param int $store + * @return mixed + */ + public function getMinimalPrice($products, $priceAttributes, $store) + { + $website = Mage::app()->getStore($store)->getWebsiteId(); + + $fields = array('customer_group_id', 'minimal_value'=>'MIN(value)'); + $select = $this->_getReadAdapter()->select() + ->from(array('base'=>$this->getTable('catalogindex/price')), $fields) + ->where('base.entity_id in (?)', $products) + ->where('base.attribute_id in (?)', $priceAttributes) + ->where('base.website_id = ?', $website) + ->group('base.customer_group_id'); + return $this->_getReadAdapter()->fetchAll($select); + } + + /** + * Return tier prices for specified product in specified website + * + * @param array $products + * @param int $website + * @return mixed + */ + public function getTierPrices($products, $website) + { + $fields = array( + 'entity_id', + 'type_id', + 'c.customer_group_id', + 'c.qty', + 'c.value', + 'c.all_groups', + ); + $condition = "product.entity_id = c.entity_id"; + + $select = $this->_getReadAdapter()->select() + ->from(array('product'=>$this->getTable('catalog/product')), $fields) + ->joinLeft(array('c'=>"{$this->getTable('catalog/product')}_tier_price"), $condition, array()) + ->where('product.entity_id in (?)', $products); + if (Mage::helper('catalog')->isPriceGlobal()) + { + $select->where('c.website_id=?', 0); + } + elseif (Mage::app()->getWebsite($website)->getBaseCurrencyCode() != Mage::app()->getBaseCurrencyCode()) { + $select->where('c.website_id=?', $website); + } + else { + $select->where('c.website_id IN(?)', array(0, $website)); + } + + return $this->_getReadAdapter()->fetchAll($select); + } + + /** + * Add attribute filter to select + * + * @param Varien_Db_Select $select + * @param string $attributeCode + * @param string $table the main table name or alias + * @param string $field entity_id field name + * @param int $store + * @param int|string|array $value the filter value + * @return Mage_CatalogIndex_Model_Resource_Data_Abstract + */ + protected function _addAttributeFilter(Varien_Db_Select $select, $attributeCode, $table, $field, $store, $value) + { + $adapter = $this->_getReadAdapter(); + $attribute = Mage::getSingleton('eav/config') + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode); + /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ + $attributeTable = $attribute->getBackend()->getTable(); + if ($attribute->getBackendType() == 'static') { + $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); + $joinCond = join(' AND ', array( + sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias) + )); + $select + ->join( + array($tableAlias => $attributeTable), + $joinCond, + array()) + ->where(sprintf('%s.%s IN(?)', $tableAlias, $attribute->getAttributeCode()), $value); + } + elseif ($attribute->isScopeGlobal()) { + $tableAlias = sprintf('t_%s', $attribute->getAttributeCode()); + $joinCond = join(' AND ', array( + sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableAlias), + $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableAlias), $attribute->getAttributeId()), + $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableAlias), 0) + )); + $select + ->join( + array($tableAlias => $attributeTable), + $joinCond, + array()) + ->where(sprintf('%s.value IN(?)', $tableAlias), $value); + } + else { + $tableGlobal = sprintf('t_global_%s', $attribute->getAttributeCode()); + $tableStore = sprintf('t_store_%s', $attribute->getAttributeCode()); + $joinCondGlobal = join(' AND ', array( + sprintf('`%s`.`%s`=`%s`.`entity_id`', $table, $field, $tableGlobal), + $adapter->quoteInto(sprintf('`%s`.`attribute_id`=?', $tableGlobal), $attribute->getAttributeId()), + $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableGlobal), 0) + )); + $joinCondStore = join(' AND ', array( + sprintf('`%s`.`entity_id`=`%s`.`entity_id`', $tableGlobal, $tableStore), + sprintf('`%s`.`attribute_id`=`%s`.`attribute_id`', $tableGlobal, $tableStore), + $adapter->quoteInto(sprintf('`%s`.`store_id`=?', $tableStore), $store) + )); + $whereCond = sprintf('IF(`%s`.`value_id`>0, `%s`.`value`, `%s`.`value`) IN(?)', + $tableStore, $tableStore, $tableGlobal); + + $select + ->join( + array($tableGlobal => $attributeTable), + $joinCondGlobal, + array()) + ->joinLeft( + array($tableStore => $attributeTable), + $joinCondStore, + array()) + ->where($whereCond, $value); + } + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Configurable.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Configurable.php new file mode 100755 index 0000000000..9b43003ded --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Configurable.php @@ -0,0 +1,51 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Data_Configurable extends Mage_CatalogIndex_Model_Resource_Data_Abstract +{ + /** + * Prepare select statement before 'fetchLinkInformation' function result fetch + * + * @param int $store + * @param string $table + * @param string $idField + * @param string $whereField + * @param int $id + * @param array $additionalWheres + */ + protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) + { + $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Grouped.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Grouped.php new file mode 100755 index 0000000000..b02910e711 --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Data/Grouped.php @@ -0,0 +1,128 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Data_Grouped extends Mage_CatalogIndex_Model_Resource_Data_Abstract +{ + /** + * Return minimal prices for specified products + * + * @param array $products + * @param array $priceAttributes + * @param int $store + * @return array + */ + public function getMinimalPrice($products, $priceAttributes, $store) + { + $result = array(); + $store = Mage::app()->getStore($store); + + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('catalogindex/price'), array( + 'customer_group_id', 'value', 'tax_class_id')) + ->where('entity_id IN(?)', $products) + ->where('attribute_id IN(?)', $priceAttributes) + ->where('website_id=?', $store->getWebsiteId()); + $prices = $select->query()->fetchAll(); + + $groups = Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups(); + foreach ($groups as $group) { + $resultMinimal = null; + $resultTaxClassId = 0; + $taxClassId = 0; + $customerGroup = $group->getId(); + + $typedProducts = Mage::getSingleton('catalogindex/retreiver') + ->assignProductTypes($products); + foreach ($typedProducts as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + foreach ($typeIds as $id) { + $finalPrice = $retreiver->getFinalPrice($id, $store, $group); + if ((null === $resultMinimal) || ($finalPrice < $resultMinimal)) { + $resultMinimal = $finalPrice; + $resultTaxClassId = $retreiver->getTaxClassId($id, $store); + } + + $tiers = $retreiver->getTierPrices($id, $store); + foreach ($tiers as $tier) { + if ($tier['customer_group_id'] != $customerGroup && !$tier['all_groups']) { + continue; + } + if ((null === $resultMinimal) || ($tier['value'] < $resultMinimal)) { + $resultMinimal = $tier['value']; + $resultTaxClassId = $retreiver->getTaxClassId($tier['entity_id'], $store); + } + } + } + } + + foreach ($prices as $one) { + if ($one['customer_group_id'] != $customerGroup) { + continue; + } + + if ((null === $resultMinimal) || ($one['value'] < $resultMinimal)) { + $resultMinimal = $one['value']; + $taxClassId = $one['tax_class_id']; + } else { + $taxClassId = $resultTaxClassId; + } + } + + if (!is_null($resultMinimal)){ + $result[] = array( + 'customer_group_id' => $customerGroup, + 'minimal_value' => $resultMinimal, + 'tax_class_id' => $taxClassId + ); + } + } + + return $result; + } + + /** + * Prepare select statement before 'fetchLinkInformation' function result fetch + * + * @param int $store + * @param string $table + * @param string $idField + * @param string $whereField + * @param int $id + * @param array $additionalWheres + */ + protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array()) + { + $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php new file mode 100755 index 0000000000..d8164471af --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer.php @@ -0,0 +1,704 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Indexer extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Enter description here ... + * + * @var unknown + */ + protected $_insertData = array(); + + /** + * Enter description here ... + * + * @var unknown + */ + protected $_tableFields = array(); + + /** + * Enter description here ... + * + * @var unknown + */ + protected $_attributeCache = array(); + + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Enter description here ... + * + * @param unknown_type $id + * @return unknown + */ + protected function _loadAttribute($id) + { + if (!isset($this->_attributeCache[$id])) { + $this->_attributeCache[$id] = Mage::getModel('eav/entity_attribute')->load($id); + } + + return $this->_attributeCache[$id]; + } + + /** + * Delete index data by specific conditions + * + * @param bool $eav clear eav index data flag + * @param bool $price clear price index data flag + * @param bool $minimal clear minimal price index data flag + * @param bool $finalPrice clear final price index data flag + * @param bool $tierPrice clear tier price index data flag + * @param mixed $products applicable products + * @param mixed $store applicable stores + */ + public function clear($eav = true, $price = true, $minimal = true, $finalPrice = true, $tierPrice = true, + $products = null, $store = null) + { + $suffix = ''; + $priceSuffix = ''; + $tables = array('eav'=>'catalogindex/eav', 'price'=>'catalogindex/price'); + if (!is_null($products)) { + if ($products instanceof Mage_Catalog_Model_Product) { + $products = $products->getId(); + } elseif ($products instanceof Mage_Catalog_Model_Product_Condition_Interface) { + $suffix = 'entity_id IN ('.$products->getIdsSelect($this->_getWriteAdapter())->__toString().')'; + } + else if (!is_numeric($products) && !is_array($products)) { + Mage::throwException('Invalid products supplied for indexing'); + } + if (empty($suffix)) { + $suffix = $this->_getWriteAdapter()->quoteInto('entity_id in (?)', $products); + } + } + if (!is_null($store)) { + $websiteIds = array(); + + if ($store instanceof Mage_Core_Model_Store) { + $store = $store->getId(); + $websiteIds[] = Mage::app()->getStore($store)->getWebsiteId(); + } else if ($store instanceof Mage_Core_Model_Resource_Store_Collection) { + $store = $store->getAllIds(); + foreach ($store as $one) { + $websiteIds[] = Mage::app()->getStore($one)->getWebsiteId(); + } + } else if (is_array($store)) { + $resultStores = array(); + foreach ($store as $s) { + if ($s instanceof Mage_Core_Model_Store) { + $resultStores[] = $s->getId(); + $websiteIds[] = $s->getWebsiteId(); + } elseif (is_numeric($s)) { + $websiteIds[] = Mage::app()->getStore($s)->getWebsiteId(); + $resultStores[] = $s; + } + } + $store = $resultStores; + } + + if ($suffix) { + $suffix .= ' AND '; + } + + $priceSuffix = $suffix . $this->_getWriteAdapter()->quoteInto('website_id in (?)', $websiteIds); + $suffix .= $this->_getWriteAdapter()->quoteInto('store_id in (?)', $store); + + } + + if ($tierPrice) { + $tables['tierPrice'] = 'catalogindex/price'; + $tierPrice = array(Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price')); + } + if ($finalPrice) { + $tables['finalPrice'] = 'catalogindex/price'; + $tierPrice = array(Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price')); + } + if ($minimal) { + $tables['minimal'] = 'catalogindex/minimal_price'; + } + + + foreach ($tables as $variable=>$table) { + $variable = $$variable; + $suffixToInsert = $suffix; + if (in_array($table, $this->_getPriceTables())) { + $suffixToInsert = $priceSuffix; + } + + if ($variable === true) { + $query = "DELETE FROM {$this->getTable($table)} "; + if ($suffixToInsert) { + $query .= "WHERE {$suffixToInsert}"; + } + + $this->_getWriteAdapter()->query($query); + } else if (is_array($variable) && count($variable)) { + $query = "DELETE FROM {$this->getTable($table)} WHERE "; + $query .= $this->_getWriteAdapter()->quoteInto("attribute_id in (?)", $variable); + if ($suffixToInsert) { + $query .= " AND {$suffixToInsert}"; + } + + $this->_getWriteAdapter()->query($query); + } + } + } + + /** + * Get tables which are used for index related with price + * + * @return array + */ + protected function _getPriceTables() + { + return array('catalogindex/price', 'catalogindex/minimal_price'); + } + + /** + * Reindex data for tier prices + * + * @param array $products array of product ids + * @param Mage_Core_Model_Store $store + * @param int | null $forcedId identifier of "parent" product + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function reindexTiers($products, $store, $forcedId = null) + { + $websiteId = $store->getWebsiteId(); + $attribute = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price'); + $this->_beginInsert( + 'catalogindex/price', + array('entity_id', 'attribute_id', 'value', 'website_id', 'customer_group_id', 'qty') + ); + + /** + * Get information about product types + * array ( + * $productType => array() + * ) + */ + $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); + if (is_null($forcedId)) { + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_TIERS)) { + foreach ($typeIds as $id) { + $children = $retreiver->getChildProductIds($store, $id); + if ($children) { + $this->reindexTiers($children, $store, $id); + } + } + } + } + } + + $attributeIndex = $this->getTierData($products, $store); + foreach ($attributeIndex as $index) { + $type = $index['type_id']; + $id = (is_null($forcedId) ? $index['entity_id'] : $forcedId); + if ($id && $index['value']) { + if ($index['all_groups'] == 1) { + foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { + $this->_insert('catalogindex/price', array( + $id, + $attribute, + $index['value'], + $websiteId, + (int) $group->getId(), + (int) $index['qty'] + )); + } + } else { + $this->_insert('catalogindex/price', array( + $id, + $attribute, + $index['value'], + $websiteId, + (int) $index['customer_group_id'], + (int) $index['qty'] + )); + } + } + } + $this->_commitInsert('catalogindex/price'); + return $this; + } + + /** + * Reindex product prices + * + * @param array | int $products product ids + * @param array $attributeIds + * @param Mage_Core_Model_Store $store + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function reindexPrices($products, $attributeIds, $store) + { + $this->reindexAttributes($products, $attributeIds, $store, null, 'catalogindex/price', true); + return $this; + } + + /** + * Reindex product final prices + * + * @param array $products array of product ids + * @param Mage_Core_Model_Store $store + * @param int | null $forcedId identifier of "parent" product + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function reindexFinalPrices($products, $store, $forcedId = null) + { + $priceAttribute = Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price'); + $this->_beginInsert('catalogindex/price', array( + 'entity_id', + 'website_id', + 'customer_group_id', + 'value', + 'attribute_id', + 'tax_class_id' + )); + + $productTypes = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); + foreach ($productTypes as $type=>$products) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + foreach ($products as $product) { + if (is_null($forcedId)) { + if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { + $children = $retreiver->getChildProductIds($store, $product); + if ($children) { + $this->reindexFinalPrices($children, $store, $product); + } + } + } + foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { + $finalPrice = $retreiver->getFinalPrice($product, $store, $group); + $taxClassId = $retreiver->getTaxClassId($product, $store); + $id = $product; + if (!is_null($forcedId)) { + $id = $forcedId; + } + + if (false !== $finalPrice && false !== $id && false !== $priceAttribute) { + $this->_insert('catalogindex/price', array( + $id, + $store->getWebsiteId(), + $group->getId(), + $finalPrice, + $priceAttribute, + $taxClassId + )); + } + } + } + } + $this->_commitInsert('catalogindex/price'); + return $this; + } + + /** + * Reindex product minimal prices + * + * @param array $products array of product ids + * @param Mage_Core_Model_Store $store + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function reindexMinimalPrices($products, $store) + { + $this->_beginInsert('catalogindex/minimal_price', array( + 'website_id', + 'entity_id', + 'customer_group_id', + 'value', + 'tax_class_id' + )); + $this->clear(false, false, true, false, false, $products, $store); + $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); + + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + + foreach ($typeIds as $id) { + $minimal = array(); + if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_PRICES)) { + $children = $retreiver->getChildProductIds($store, $id); + if ($children) { + $minimal = $this->getMinimalPrice(array($type=>$children), $store); + } + } else { + $minimal = $this->getMinimalPrice(array($type=>array($id)), $store); + } + + if (is_array($minimal)) { + foreach ($minimal as $price) { + if (!isset($price['tax_class_id'])) { + $price['tax_class_id'] = 0; + } + $this->_insert('catalogindex/minimal_price', array( + $store->getWebsiteId(), + $id, + $price['customer_group_id'], + $price['minimal_value'], + $price['tax_class_id'] + )); + } + } + } + } + + $this->_commitInsert('catalogindex/minimal_price'); + return $this; + } + + /** + * Reindex attributes data + * + * @param array $products + * @param array $attributeIds + * @param mixed $store + * @param int|null $forcedId + * @param string $table + * @param bool $storeIsWebsite + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function reindexAttributes($products, $attributeIds, $store, $forcedId = null, $table = 'catalogindex/eav', + $storeIsWebsite = false) + { + $storeField = 'store_id'; + $websiteId = null; + if ($storeIsWebsite) { + $storeField = 'website_id'; + if ($store instanceof Mage_Core_Model_Store) { + $websiteId = $store->getWebsiteId(); + } else { + $websiteId = Mage::app()->getStore($store)->getWebsiteId(); + } + } + + $this->_beginInsert($table, array('entity_id', 'attribute_id', 'value', $storeField)); + + $products = Mage::getSingleton('catalogindex/retreiver')->assignProductTypes($products); + + if (is_null($forcedId)) { + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + if ($retreiver->areChildrenIndexable(Mage_CatalogIndex_Model_Retreiver::CHILDREN_FOR_ATTRIBUTES)) { + foreach ($typeIds as $id) { + $children = $retreiver->getChildProductIds($store, $id); + if ($children) { + $this->reindexAttributes($children, $attributeIds, $store, $id, $table, $storeIsWebsite); + } + } + } + } + } + + $attributeIndex = $this->getProductData($products, $attributeIds, $store); + foreach ($attributeIndex as $index) { + $type = $index['type_id']; + $id = (is_null($forcedId) ? $index['entity_id'] : $forcedId); + + if ($id && $index['attribute_id'] && isset($index['value'])) { + $attribute = $this->_loadAttribute($index['attribute_id']); + if ($attribute->getFrontendInput() == 'multiselect') { + $index['value'] = explode(',', $index['value']); + } + + if (is_array($index['value'])) { + foreach ($index['value'] as $value) { + $this->_insert($table, array( + $id, + $index['attribute_id'], + $value, + (is_null($websiteId) ? $store->getId() : $websiteId) + )); + } + } else { + $this->_insert($table, array( + $id, + $index['attribute_id'], + $index['value'], + (is_null($websiteId) ? $store->getId() : $websiteId) + )); + } + } + } + + $this->_commitInsert($table); + return $this; + } + + /** + * Get tier prices data by set of products + * + * @param array $products + * @param Mage_Core_Model_Store $store + * @return array + */ + public function getTierData($products, $store) + { + $result = array(); + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + $byType = $retreiver->getTierPrices($typeIds, $store); + if ($byType) { + $result = array_merge($result, $byType); + } + } + return $result; + } + + /** + * Get minimal prices by set of the products + * + * @param arary $products + * @param Mage_Core_Model_Store $store + * @return array + */ + public function getMinimalPrice($products, $store) + { + $result = array(); + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + $byType = $retreiver->getMinimalPrice($typeIds, $store); + if ($byType) { + $result = array_merge($result, $byType); + } + } + return $result; + } + + /** + * Get data for products + * + * @param array $products + * @param array $attributeIds + * @param Mage_Core_Model_Store $store + * @return array + */ + public function getProductData($products, $attributeIds, $store) + { + $result = array(); + foreach ($products as $type=>$typeIds) { + $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type); + $byType = $retreiver->getAttributeData($typeIds, $attributeIds, $store); + if ($byType) { + $result = array_merge($result, $byType); + } + } + return $result; + } + + /** + * Prepare base information for data insert + * + * @param string $table + * @param array $fields + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + protected function _beginInsert($table, $fields) + { + $this->_tableFields[$table] = $fields; + return $this; + } + + /** + * Put data into table + * + * @param string $table + * @param bool $forced + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + protected function _commitInsert($table, $forced = true) + { + if (isset($this->_insertData[$table]) && count($this->_insertData[$table]) && ($forced || count($this->_insertData[$table]) >= 100)) { + $query = 'REPLACE INTO ' . $this->getTable($table) . ' (' . implode(', ', $this->_tableFields[$table]) . ') VALUES '; + $separator = ''; + foreach ($this->_insertData[$table] as $row) { + $rowString = $this->_getWriteAdapter()->quoteInto('(?)', $row); + $query .= $separator . $rowString; + $separator = ', '; + } + $this->_getWriteAdapter()->query($query); + $this->_insertData[$table] = array(); + } + return $this; + } + + /** + * Insert data to table + * + * @param string $table + * @param array $data + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + protected function _insert($table, $data) + { + $this->_insertData[$table][] = $data; + $this->_commitInsert($table, false); + return $this; + } + + /** + * Add price columns for catalog product flat table + * + * @param Varien_Object $object + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function prepareCatalogProductFlatColumns(Varien_Object $object) + { + $columns = $object->getColumns(); + + foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { + $columnName = 'display_price_group_' . $group->getId(); + $columns[$columnName] = array( + 'type' => 'decimal(12,4)', + 'unsigned' => false, + 'nullable' => true, + 'default' => null, + 'extra' => null, + 'comment' => $columnName . ' column' + ); + } + + $object->setColumns($columns); + + return $this; + } + + /** + * Add price indexes for catalog product flat table + * + * @param Varien_Object $object + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function prepareCatalogProductFlatIndexes(Varien_Object $object) + { + $indexes = $object->getIndexes(); + + foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { + $columnName = 'display_price_group_' . $group->getId(); + $indexName = 'IDX_DISPLAY_PRICE_GROUP_' . $group->getId(); + $indexes[$indexName] = array( + 'type' => 'index', + 'fields' => array($columnName) + ); + } + + $object->setIndexes($indexes); + + return $this; + } + + /** + * Update prices for Catalog Product flat + * + * @param int $storeId + * @param unknown_type $productIds + * @param string $tableName + * @return Mage_CatalogIndex_Model_Resource_Indexer + */ + public function updateCatalogProductFlat($storeId, $productIds = null, $tableName = null) + { + if (is_null($tableName)) { + $tableName = $this->getTable('catalog/product_flat') . '_' . $storeId; + } + $addChildData = Mage::helper('catalog/product_flat')->isAddChildData(); + + $priceAttribute = Mage::getSingleton('eav/entity_attribute') + ->getIdByCode(Mage_Catalog_Model_Product::ENTITY, 'price'); + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); + + foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { + $columnName = 'display_price_group_' . $group->getId(); + + /** + * Update prices of main products in flat table + */ + $select = $this->_getWriteAdapter()->select() + ->join( + array('p' => $this->getTable('catalogindex/price')), + "`e`.`entity_id`=`p`.`entity_id`" + . " AND `p`.`attribute_id`={$priceAttribute}" + . " AND `p`.`customer_group_id`={$group->getId()}" + . " AND `p`.`website_id`={$websiteId}", + array($columnName => 'value')); + if ($addChildData) { + $select->where('e.is_child=?', 0); + } + + if ($productIds instanceof Mage_Catalog_Model_Product_Condition_Interface) { + $select->where('e.entity_id IN ('.$productIds->getIdsSelect($this->_getWriteAdapter())->__toString().')'); + } elseif (!is_null($productIds)) { + $select->where("e.entity_id IN(?)", $productIds); + } + + $sql = $select->crossUpdateFromSelect(array('e' => $tableName)); + $this->_getWriteAdapter()->query($sql); + + if ($addChildData) { + /** + * Update prices for children products in flat table + */ + $select = $this->_getWriteAdapter()->select() + ->join( + array('p' => $this->getTable('catalogindex/price')), + "`e`.`child_id`=`p`.`entity_id`" + . " AND `p`.`attribute_id`={$priceAttribute}" + . " AND `p`.`customer_group_id`={$group->getId()}" + . " AND `p`.`website_id`={$websiteId}", + array($columnName => 'value')) + ->where('e.is_child=?', 1); + + if ($productIds instanceof Mage_Catalog_Model_Product_Condition_Interface) { + $select->where('e.child_id IN ('.$productIds->getIdsSelect($this->_getWriteAdapter())->__toString().')'); + } elseif (!is_null($productIds)) { + $select->where("e.child_id IN(?)", $productIds); + } + + $sql = $select->crossUpdateFromSelect(array('e' => $tableName)); + $this->_getWriteAdapter()->query($sql); + } + + } + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Abstract.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Abstract.php new file mode 100755 index 0000000000..92e46acf54 --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Abstract.php @@ -0,0 +1,156 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Indexer_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * should be defined because abstract + * + */ + protected function _construct() + { + + } + + /** + * Enter description here ... + * + * @param unknown_type $data + * @param unknown_type $storeId + * @param unknown_type $productId + * @return unknown + */ + public function saveIndex($data, $storeId, $productId) + { + return $this->saveIndices(array($data), $storeId, $productId); + } + + /** + * Enter description here ... + * + * @param array $data + * @param unknown_type $storeId + * @param unknown_type $productId + */ + public function saveIndices(array $data, $storeId, $productId) + { + $this->_executeReplace($data, $storeId, $productId); + } + + /** + * Enter description here ... + * + * @param unknown_type $data + * @param unknown_type $storeId + * @param unknown_type $productId + * @return Mage_CatalogIndex_Model_Resource_Indexer_Abstract + */ + protected function _executeReplace($data, $storeId, $productId) + { + $this->beginTransaction(); + try { + foreach ($data as $row) { + $row[$this->_entityIdFieldName] = $productId; + $this->_getWriteAdapter()->insert($this->getMainTable(), $row); + } + $this->commit(); + } catch (Exception $e) { + $this->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $productId + * @param unknown_type $storeId + * @param unknown_type $attributeId + */ + public function cleanup($productId, $storeId = null, $attributeId = null) + { + $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_entityIdFieldName} = ?", $productId); + + if (!is_null($storeId)) + $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_storeIdFieldName} = ?", $storeId); + + if (!is_null($attributeId)) + $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_attributeIdFieldName} = ?", $attributeId); + + $conditions = implode (' AND ', $conditions); + $this->_getWriteAdapter()->delete($this->getMainTable(), $conditions); + } + + /** + * Enter description here ... + * + * @param unknown_type $conditions + * @return unknown + */ + public function loadAttributeCodesByCondition($conditions) + { + $table = $this->getTable('eav/attribute'); + $select = $this->_getReadAdapter()->select(); + $select->from(array('main_table' => $table), 'attribute_id') + ->join(array('additional_table' => $this->getTable('catalog/eav_attribute')), 'additional_table.attribute_id=main_table.attribute_id'); + $select->distinct(true); + + if (is_array($conditions)) { + foreach ($conditions as $k=>$condition) { + if (is_array($condition)) { + if ($k == 'or') { + $function = 'where'; + foreach ($condition as $field=>$value) { + if (is_array($value)) + $select->$function("{$field} in (?)", $value); + else + $select->$function("{$field} = ?", $value); + + $function = 'orWhere'; + } + } else { + $select->where("{$k} in (?)", $condition); + } + } else { + $select->where("{$k} = ?", $condition); + } + } + } else { + $select->where($conditions); + } + return $this->_getReadAdapter()->fetchCol($select); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Eav.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Eav.php new file mode 100755 index 0000000000..a57a9609f9 --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Eav.php @@ -0,0 +1,49 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Indexer_Eav extends Mage_CatalogIndex_Model_Resource_Indexer_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogindex/eav', 'index_id'); + + $this->_entityIdFieldName = 'entity_id'; + $this->_attributeIdFieldName = 'attribute_id'; + $this->_storeIdFieldName = 'store_id'; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Minimalprice.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Minimalprice.php new file mode 100755 index 0000000000..7345fb132f --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Minimalprice.php @@ -0,0 +1,87 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Indexer_Minimalprice extends Mage_CatalogIndex_Model_Resource_Indexer_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogindex/minimal_price', 'index_id'); + + $this->_entityIdFieldName = 'entity_id'; + $this->_storeIdFieldName = 'store_id'; + } + + /** + * Enter description here ... + * + * @param unknown_type $conditions + * @return unknown + */ + public function getMinimalValue($conditions) + { + $select = $this->_getReadAdapter()->select(); + $select->from($this->getTable('catalogindex/price'), 'MIN(value)'); + foreach ($conditions as $field=>$value) { + $condition = "{$field} = ?"; + if (is_array($value)) + $condition = "{$field} in (?)"; + + $select->where($condition, $value); + } + + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Enter description here ... + * + * @param unknown_type $productId + * @param unknown_type $storeId + * @param unknown_type $attributeId + */ + public function cleanup($productId, $storeId = null, $attributeId = null) + { + $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_entityIdFieldName} = ?", $productId); + + if (!is_null($storeId)) + $conditions[] = $this->_getWriteAdapter()->quoteInto("{$this->_storeIdFieldName} = ?", $storeId); + + $conditions = implode (' AND ', $conditions); + $this->_getWriteAdapter()->delete($this->getMainTable(), $conditions); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Price.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Price.php new file mode 100755 index 0000000000..36a00c35fe --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Price.php @@ -0,0 +1,49 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Indexer_Price extends Mage_CatalogIndex_Model_Resource_Indexer_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogindex/price', 'index_id'); + + $this->_entityIdFieldName = 'entity_id'; + $this->_attributeIdFieldName = 'attribute_id'; + $this->_storeIdFieldName = 'store_id'; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Price.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Price.php new file mode 100755 index 0000000000..0efdb50c9e --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Price.php @@ -0,0 +1,309 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Price extends Mage_CatalogIndex_Model_Resource_Abstract +{ + /** + * Enter description here ... + * + * @var unknown + */ + protected $_rate = 1; + + /** + * Enter description here ... + * + * @var unknown + */ + protected $_customerGroupId; + + /** + * Enter description here ... + * + * @var unknown + */ + protected $_taxRates = null; + + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogindex/price', 'index_id'); + } + + /** + * Enter description here ... + * + * @param unknown_type $rate + */ + public function setRate($rate) + { + $this->_rate = $rate; + } + + /** + * Enter description here ... + * + * @return unknown + */ + public function getRate() + { + if (!$this->_rate) { + $this->_rate = 1; + } + return $this->_rate; + } + + /** + * Enter description here ... + * + * @param unknown_type $customerGroupId + */ + public function setCustomerGroupId($customerGroupId) + { + $this->_customerGroupId = $customerGroupId; + } + + /** + * Enter description here ... + * + * @return unknown + */ + public function getCustomerGroupId() + { + return $this->_customerGroupId; + } + + /** + * Enter description here ... + * + * @param unknown_type $attribute + * @param unknown_type $entitySelect + * @return unknown + */ + public function getMaxValue($attribute, $entitySelect) + { + $select = clone $entitySelect; + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array()); + + if ($attribute->getAttributeCode() == 'price') { + $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); + $args = array( + 'select'=>$select, + 'table'=>'price_table', + 'store_id'=>$this->getStoreId(), + 'response_object'=>$response, + ); + Mage::dispatchEvent('catalogindex_prepare_price_select', $args); + } + + $select + ->columns("MAX(price_table.value".implode('', $response->getAdditionalCalculations()).")") + ->where('price_table.website_id = ?', $this->getWebsiteId()) + ->where('price_table.attribute_id = ?', $attribute->getId()); + + return $this->_getReadAdapter()->fetchOne($select)*$this->getRate(); + } + + /** + * Enter description here ... + * + * @param unknown_type $range + * @param unknown_type $attribute + * @param unknown_type $entitySelect + * @return unknown + */ + public function getCount($range, $attribute, $entitySelect) + { + $select = clone $entitySelect; + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::ORDER); + $select->reset(Zend_Db_Select::LIMIT_COUNT); + $select->reset(Zend_Db_Select::LIMIT_OFFSET); + + $select->join(array('price_table'=>$this->getMainTable()), 'price_table.entity_id=e.entity_id', array()); + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + if ($attribute->getAttributeCode() == 'price') { + $select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); + $args = array( + 'select'=>$select, + 'table'=>'price_table', + 'store_id'=>$this->getStoreId(), + 'response_object'=>$response, + ); + Mage::dispatchEvent('catalogindex_prepare_price_select', $args); + } + + + $fields = array('count'=>'COUNT(DISTINCT price_table.entity_id)', 'range'=>"FLOOR(((price_table.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()})/{$range})+1"); + + $select->columns($fields) + ->group('range') + ->where('price_table.website_id = ?', $this->getWebsiteId()) + ->where('price_table.attribute_id = ?', $attribute->getId()); + + + $result = $this->_getReadAdapter()->fetchAll($select); + + $counts = array(); + foreach ($result as $row) { + $counts[$row['range']] = $row['count']; + } + + return $counts; + } + + /** + * Enter description here ... + * + * @param unknown_type $range + * @param unknown_type $index + * @param unknown_type $attribute + * @param unknown_type $entityIdsFilter + * @param unknown_type $tableName + * @return unknown + */ + public function getFilteredEntities($range, $index, $attribute, $entityIdsFilter, $tableName = 'price_table') + { + $select = $this->_getReadAdapter()->select(); + $select->from(array($tableName=>$this->getMainTable()), $tableName . '.entity_id'); + + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + $select + ->distinct(true) + ->where($tableName . '.entity_id in (?)', $entityIdsFilter) + ->where($tableName . '.website_id = ?', $this->getWebsiteId()) + ->where($tableName . '.attribute_id = ?', $attribute->getId()); + + if ($attribute->getAttributeCode() == 'price') { + $select->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId()); + $args = array( + 'select'=>$select, + 'table'=>$tableName, + 'store_id'=>$this->getStoreId(), + 'response_object'=>$response, + ); + Mage::dispatchEvent('catalogindex_prepare_price_select', $args); + } + + $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range); + $select->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range); + + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Enter description here ... + * + * @param unknown_type $collection + * @param unknown_type $attribute + * @param unknown_type $range + * @param unknown_type $index + * @param unknown_type $tableName + * @return Mage_CatalogIndex_Model_Resource_Price + */ + public function applyFilterToCollection($collection, $attribute, $range, $index, $tableName = 'price_table') + { + /** + * Distinct required for removing duplicates in case when we have grouped products + * which contain multiple rows for one product id + */ + $collection->getSelect()->distinct(true); + $tableName = $tableName.'_'.$attribute->getAttributeCode(); + $collection->getSelect()->joinLeft( + array($tableName => $this->getMainTable()), + $tableName .'.entity_id=e.entity_id', + array() + ); + + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + $collection->getSelect() + ->where($tableName . '.website_id = ?', $this->getWebsiteId()) + ->where($tableName . '.attribute_id = ?', $attribute->getId()); + + if ($attribute->getAttributeCode() == 'price') { + $collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId()); + $args = array( + 'select'=>$collection->getSelect(), + 'table'=>$tableName, + 'store_id'=>$this->getStoreId(), + 'response_object'=>$response, + ); + + Mage::dispatchEvent('catalogindex_prepare_price_select', $args); + } + + $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) >= ?", ($index-1)*$range); + $collection->getSelect()->where("(({$tableName}.value".implode('', $response->getAdditionalCalculations()).")*{$this->getRate()}) < ?", $index*$range); + + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $ids + * @return unknown + */ + public function getMinimalPrices($ids) + { + if (!$ids) { + return array(); + } + $select = $this->_getReadAdapter()->select(); + $select->from(array('price_table'=>$this->getTable('catalogindex/minimal_price')), + array('price_table.entity_id', 'value'=>"(price_table.value)", 'tax_class_id'=>'(price_table.tax_class_id)')) + ->where('price_table.entity_id in (?)', $ids) + ->where('price_table.website_id = ?', $this->getWebsiteId()) + ->where('price_table.customer_group_id = ?', $this->getCustomerGroupId()); + return $this->_getReadAdapter()->fetchAll($select); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Retreiver.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Retreiver.php new file mode 100755 index 0000000000..1bbbc7e45c --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Retreiver.php @@ -0,0 +1,59 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Retreiver extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Return id-type pairs + * + * @param array $ids + * @return array + */ + public function getProductTypes($ids) + { + $select = $this->_getReadAdapter()->select() + ->from(array('main_table'=>$this->getTable('catalog/product')), array('id'=>'main_table.entity_id', 'type'=>'main_table.type_id')) + ->where('main_table.entity_id in (?)', $ids); + return $this->_getReadAdapter()->fetchAll($select); + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Setup.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Setup.php new file mode 100755 index 0000000000..3801a70d70 --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Setup.php @@ -0,0 +1,95 @@ + + */ +class Mage_CatalogIndex_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup +{ + /** + * Enter description here ... + * + * @var unknown + */ + protected $_storeToWebsite = null; + + /** + * Enter description here ... + * + * @param unknown_type $table + * @return Mage_CatalogIndex_Model_Resource_Setup + */ + public function convertStoreToWebsite($table) + { + $assignment = $this->_getStoreToWebsiteAssignments(); + foreach ($assignment as $website=>$stores) { + $this->_setWebsiteInfo($table, $website, $stores); + } + return $this; + } + + /** + * Enter description here ... + * + * @return unknown + */ + protected function _getStoreToWebsiteAssignments() + { + if (is_null($this->_storeToWebsite)) { + $this->_storeToWebsite = array(); + $websiteCollection = Mage::getModel('core/website')->getCollection(); + foreach ($websiteCollection as $website) { + $this->_storeToWebsite[$website->getId()] = $website->getStoreIds(); + } + } + + return $this->_storeToWebsite; + } + + /** + * Enter description here ... + * + * @param unknown_type $table + * @param unknown_type $websiteId + * @param unknown_type $storeIds + * @return Mage_CatalogIndex_Model_Resource_Setup + */ + protected function _setWebsiteInfo($table, $websiteId, $storeIds) + { + $this->getConnection()->update( + $table, + array('website_id'=>$websiteId), + $this->getConnection()->quoteInto('store_id IN (?)', $storeIds) + ); + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogIndex/Model/Retreiver.php b/app/code/core/Mage/CatalogIndex/Model/Retreiver.php index 59c65cca03..56895c8a67 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Retreiver.php +++ b/app/code/core/Mage/CatalogIndex/Model/Retreiver.php @@ -20,14 +20,35 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Index data retreiver factory * - * @author Magento Core Team + * @method Mage_CatalogIndex_Model_Resource_Retreiver _getResource() + * @method Mage_CatalogIndex_Model_Resource_Retreiver getResource() + * @method int getEntityTypeId() + * @method Mage_CatalogIndex_Model_Retreiver setEntityTypeId(int $value) + * @method int getAttributeSetId() + * @method Mage_CatalogIndex_Model_Retreiver setAttributeSetId(int $value) + * @method string getTypeId() + * @method Mage_CatalogIndex_Model_Retreiver setTypeId(string $value) + * @method string getSku() + * @method Mage_CatalogIndex_Model_Retreiver setSku(string $value) + * @method int getHasOptions() + * @method Mage_CatalogIndex_Model_Retreiver setHasOptions(int $value) + * @method int getRequiredOptions() + * @method Mage_CatalogIndex_Model_Retreiver setRequiredOptions(int $value) + * @method string getCreatedAt() + * @method Mage_CatalogIndex_Model_Retreiver setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_CatalogIndex_Model_Retreiver setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_CatalogIndex + * @author Magento Core Team */ class Mage_CatalogIndex_Model_Retreiver extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/CatalogIndex/etc/config.xml b/app/code/core/Mage/CatalogIndex/etc/config.xml index 62aae34be1..6abeb397c0 100644 --- a/app/code/core/Mage/CatalogIndex/etc/config.xml +++ b/app/code/core/Mage/CatalogIndex/etc/config.xml @@ -21,249 +21,235 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.10 + 1.6.0.0 - - catalogindex/indexer_eav - catalogindex/indexer_price - catalogindex/indexer_tierprice - catalogindex/indexer_minimalprice + + catalogindex/indexer_eav + + + catalogindex/indexer_price + + + catalogindex/indexer_tierprice + + + catalogindex/indexer_minimalprice + - - - - - - - - - - - - - - - - - - - - - - - - Mage_CatalogIndex_Model - catalogindex_mysql4 + catalogindex_resource - - Mage_CatalogIndex_Model_Mysql4 + + Mage_CatalogIndex_Model_Resource + catalogindex_mysql4 - catalog_product_index_eav
- catalog_product_index_price
- catalogindex_minimal_price
- catalogindex_aggregation
- catalogindex_aggregation_tag
- catalogindex_aggregation_to_tag
+ + catalog_product_index_eav
+
+ + catalog_product_index_price
+
+ + catalogindex_minimal_price
+
+ + catalogindex_aggregation
+
+ + catalogindex_aggregation_tag
+
+ + catalogindex_aggregation_to_tag
+
-
+
- Mage_CatalogIndex - Mage_CatalogIndex_Model_Mysql4_Setup + Mage_CatalogIndex_Model_Resource_Setup - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - -
- - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + +
diff --git a/app/code/core/Mage/Shipping/Model/Rule/Action/Carrier.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/install-1.6.0.0.php similarity index 79% rename from app/code/core/Mage/Shipping/Model/Rule/Action/Carrier.php rename to app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/install-1.6.0.0.php index a92706ae72..fdb1df2f3d 100644 --- a/app/code/core/Mage/Shipping/Model/Rule/Action/Carrier.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/install-1.6.0.0.php @@ -19,13 +19,15 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_CatalogIndex + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ -class Mage_Sales_Model_Shipping_Rule_Action_Carrier extends Mage_Sales_Model_Shipping_Rule_Action_Abstract -{ +$installer->startSetup(); -} + +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-install-0.7.0.php index 1677081746..ab666a45ca 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.0-0.7.1.php index c09dae8108..e7e6c70f80 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.1-0.7.2.php index a227f30281..71017f251c 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.2-0.7.3.php index 50266179c6..99f9287439 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.3-0.7.4.php index b3005a5414..cf29d5ee11 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.4-0.7.5.php index 159250c145..9a89156fd4 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.5-0.7.6.php index 3b055f27a5..f59d3d365d 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.6-0.7.7.php index 40ed7479df..d31e69e90b 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.7-0.7.8.php index 8e872ce2f2..2fa8f01642 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.8-0.7.9.php index 9c98bef4a1..c72ff88f1d 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.9-0.7.10.php index 089481324b..14aaf2e636 100644 --- a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogIndex - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..385eadb55b --- /dev/null +++ b/app/code/core/Mage/CatalogIndex/sql/catalogindex_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,195 @@ +startSetup(); + +/* +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_ATTRIBUTE' +); + +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_ENTITY' +); + +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_eav'), + 'FK_CATALOG_PRODUCT_INDEX_EAV_STORE' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_eav', 'attribute_id', 'eav_attribute', 'attribute_id'), + $installer->getTable('catalog_product_index_eav'), + 'attribute_id', + $installer->getTable('eav_attribute'), + 'attribute_id' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_eav', 'entity_id', 'catalog_product_entity', 'entity_id'), + $installer->getTable('catalog_product_index_eav'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_eav', 'store_id', 'core_store', 'store_id'), + $installer->getTable('catalog_product_index_eav'), + 'store_id', + $installer->getTable('core_store'), + 'store_id' +); + +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_CUSTOMER_GROUP' +); + +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_ENTITY' +); + +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('catalog_product_index_price'), + 'FK_CATALOG_PRODUCT_INDEX_PRICE_WEBSITE' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_price', 'customer_group_id', 'customer_group', 'customer_group_id'), + $installer->getTable('catalog_product_index_price'), + 'customer_group_id', + $installer->getTable('customer_group'), + 'customer_group_id' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_price', 'entity_id', 'catalog_product_entity', 'entity_id'), + $installer->getTable('catalog_product_index_price'), + 'entity_id', + $installer->getTable('catalog_product_entity'), + 'entity_id' +); + +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('catalog_product_index_price', 'website_id', 'core_website', 'website_id'), + $installer->getTable('catalog_product_index_price'), + 'website_id', + $installer->getTable('core_website'), + 'website_id' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_eav'), + 'IDX_ENTITY' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_eav'), + 'IDX_ATTRIBUTE' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_eav'), + 'IDX_STORE' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_eav'), + 'IDX_VALUE' +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_eav'), + $installer->getIdxName('catalog_product_index_eav', array('entity_id')), + array('entity_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_eav'), + $installer->getIdxName('catalog_product_index_eav', array('attribute_id')), + array('attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_eav'), + $installer->getIdxName('catalog_product_index_eav', array('store_id')), + array('store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_eav'), + $installer->getIdxName('catalog_product_index_eav', array('value')), + array('value'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_price'), + 'IDX_CUSTOMER_GROUP' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_price'), + 'IDX_WEBSITE' +); + +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('catalog_product_index_price'), + 'IDX_MIN_PRICE' +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_price'), + $installer->getIdxName('catalog_product_index_price', array('customer_group_id')), + array('customer_group_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_price'), + $installer->getIdxName('catalog_product_index_price', array('website_id')), + array('website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +$connection = $installer->getConnection()->addIndex( + $installer->getTable('catalog_product_index_price'), + $installer->getIdxName('catalog_product_index_price', array('min_price')), + array('min_price'), + Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX +); + +*/ +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Customergroup.php b/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Customergroup.php index 82ec8c4c3b..ca64efbc85 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Customergroup.php +++ b/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Customergroup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Minsaleqty.php b/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Minsaleqty.php index dddac8c659..3859a0a0ea 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Minsaleqty.php +++ b/app/code/core/Mage/CatalogInventory/Block/Adminhtml/Form/Field/Minsaleqty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Qtyincrements.php b/app/code/core/Mage/CatalogInventory/Block/Qtyincrements.php index 9789602127..41b19aeb4d 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Qtyincrements.php +++ b/app/code/core/Mage/CatalogInventory/Block/Qtyincrements.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Abstract.php b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Abstract.php index d4106bce93..8eb3caa7ee 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Abstract.php +++ b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Composite.php b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Composite.php index 5dfa49eef2..fa27818018 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Composite.php +++ b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Composite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Default.php b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Default.php index d6091c984d..a49c189822 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Default.php +++ b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Configurable.php b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Configurable.php index 70f6e4da29..69c47d2773 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Configurable.php +++ b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Grouped.php b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Grouped.php index 087614b7e3..09a40c590d 100644 --- a/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Grouped.php +++ b/app/code/core/Mage/CatalogInventory/Block/Stockqty/Type/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Helper/Data.php b/app/code/core/Mage/CatalogInventory/Helper/Data.php index 1266194a3d..5c67576daa 100644 --- a/app/code/core/Mage/CatalogInventory/Helper/Data.php +++ b/app/code/core/Mage/CatalogInventory/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Helper/Minsaleqty.php b/app/code/core/Mage/CatalogInventory/Helper/Minsaleqty.php index bea9b52d12..108e994ff5 100644 --- a/app/code/core/Mage/CatalogInventory/Helper/Minsaleqty.php +++ b/app/code/core/Mage/CatalogInventory/Helper/Minsaleqty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/Indexer/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Indexer/Stock.php index 643d0da641..b3774f91c3 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Indexer/Stock.php +++ b/app/code/core/Mage/CatalogInventory/Model/Indexer/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,19 @@ /** * CatalogInventory Stock Status Indexer Model * + * @method Mage_CatalogInventory_Model_Resource_Indexer_Stock _getResource() + * @method Mage_CatalogInventory_Model_Resource_Indexer_Stock getResource() + * @method int getProductId() + * @method Mage_CatalogInventory_Model_Indexer_Stock setProductId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogInventory_Model_Indexer_Stock setWebsiteId(int $value) + * @method int getStockId() + * @method Mage_CatalogInventory_Model_Indexer_Stock setStockId(int $value) + * @method float getQty() + * @method Mage_CatalogInventory_Model_Indexer_Stock setQty(float $value) + * @method int getStockStatus() + * @method Mage_CatalogInventory_Model_Indexer_Stock setStockStatus(int $value) + * * @category Mage * @package Mage_CatalogInventory * @author Magento Core Team diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock.php index 0d3ed53de0..4acbb00e49 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,373 +32,6 @@ * @package Mage_CatalogInventory * @author Magento Core Team */ -class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract +class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock extends Mage_CatalogInventory_Model_Resource_Indexer_Stock { - /** - * Stock Indexer models per product type - * Sorted by priority - * - * @var array - */ - protected $_indexers; - - /** - * Default Stock Indexer resource model name - * - * @var string - */ - protected $_defaultIndexer = 'cataloginventory/indexer_stock_default'; - - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('cataloginventory/stock_status', 'product_id'); - } - - /** - * Process stock item save action - * - * @param Mage_Index_Model_Event $event - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock - */ - public function cataloginventoryStockItemSave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['product_id'])) { - return $this; - } - - $productId = $data['product_id']; - $this->reindexProducts($productId); - - if (!empty($data['force_reindex_required'])) { - $massObject = new Varien_Object(); - $massObject->setAttributesData(array( - 'force_reindex_required' => 1 - )); - $massObject->setProductIds(array($productId)); - Mage::getSingleton('index/indexer')->processEntityAction( - $massObject, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION - ); - } - - return $this; - } - - /** - * Refresh stock index for specific product ids - * - * @param array $productIds - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock - */ - public function reindexProducts($productIds) - { - $adapter = $this->_getWriteAdapter(); - if (!is_array($productIds)) { - $productIds = array($productIds); - } - $parentIds = $this->getRelationsByChild($productIds); - if ($parentIds) { - $processIds = array_merge($parentIds, $productIds); - } else { - $processIds = $productIds; - } - - // retrieve product types by processIds - $select = $adapter->select() - ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) - ->where('entity_id IN(?)', $processIds); - $pairs = $adapter->fetchPairs($select); - - $byType = array(); - foreach ($pairs as $productId => $typeId) { - $byType[$typeId][$productId] = $productId; - } - - $adapter->beginTransaction(); - try { - $indexers = $this->_getTypeIndexers(); - foreach ($indexers as $indexer) { - if (isset($byType[$indexer->getTypeId()])) { - $indexer->reindexEntity($byType[$indexer->getTypeId()]); - } - } - } catch (Exception $e) { - $adapter->rollback(); - throw $e; - } - $adapter->commit(); - - return $this; - - } - - /** - * Processing parent products after child product deleted - * - * @param Mage_Index_Model_Event $event - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock - */ - public function catalogProductDelete(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_stock_parent_ids'])) { - return $this; - } - - $adapter = $this->_getWriteAdapter(); - - $parentIds = array(); - foreach ($data['reindex_stock_parent_ids'] as $parentId => $parentType) { - $parentIds[$parentType][$parentId] = $parentId; - } - - $adapter->beginTransaction(); - try { - foreach ($parentIds as $parentType => $entityIds) { - $this->_getIndexer($parentType)->reindexEntity($entityIds); - } - } catch (Exception $e) { - $adapter->rollback(); - throw $e; - } - - $adapter->commit(); - - return $this; - } - - /** - * Process product mass update action - * - * @param Mage_Index_Model_Event $event - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - public function catalogProductMassAction(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['reindex_stock_product_ids'])) { - return $this; - } - - $adapter = $this->_getWriteAdapter(); - $processIds = $data['reindex_stock_product_ids']; - $select = $adapter->select() - ->from($this->getTable('catalog/product'), 'COUNT(*)'); - $pCount = $adapter->fetchOne($select); - - // if affected more 30% of all products - run reindex all products - if ($pCount * 0.3 < count($processIds)) { - return $this->reindexAll(); - } - - // calculate relations - $select = $adapter->select() - ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)') - ->where('child_id IN(?)', $processIds); - $aCount = $adapter->fetchOne($select); - $select = $adapter->select() - ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)') - ->where('parent_id IN(?)', $processIds); - $bCount = $adapter->fetchOne($select); - - // if affected with relations more 30% of all products - run reindex all products - if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) { - return $this->reindexAll(); - } - - - // retrieve affected parent relation products - $parentIds = $this->getRelationsByChild($processIds); - if ($parentIds) { - $processIds = array_merge($processIds, $parentIds); - } - - // retrieve products types - $select = $adapter->select() - ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) - ->where('entity_id IN(?)', $processIds); - $query = $select->query(Zend_Db::FETCH_ASSOC); - $byType = array(); - while ($row = $query->fetch()) { - $byType[$row['type_id']][] = $row['entity_id']; - } - - $adapter->beginTransaction(); - try { - $indexers = $this->_getTypeIndexers(); - foreach ($indexers as $indexer) { - if (!empty($byType[$indexer->getTypeId()])) { - $indexer->reindexEntity($byType[$indexer->getTypeId()]); - } - } - } catch (Exception $e) { - $adapter->rollback(); - throw $e; - } - $adapter->commit(); - - return $this; - } - - /** - * Rebuild all index data - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Eav - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->clearTemporaryIndexTable(); - - foreach ($this->_getTypeIndexers() as $indexer) { - $indexer->reindexAll(); - } - - $this->syncData(); - return $this; - } - - /** - * Retrieve Stock Indexer Models per Product Type - * - * @return array - */ - protected function _getTypeIndexers() - { - if (is_null($this->_indexers)) { - $this->_indexers = array(); - $types = Mage::getSingleton('catalog/product_type')->getTypesByPriority(); - foreach ($types as $typeId => $typeInfo) { - if (isset($typeInfo['stock_indexer'])) { - $modelName = $typeInfo['stock_indexer']; - } else { - $modelName = $this->_defaultIndexer; - } - $isComposite = !empty($typeInfo['composite']); - $indexer = Mage::getResourceModel($modelName) - ->setTypeId($typeId) - ->setIsComposite($isComposite); - - $this->_indexers[$typeId] = $indexer; - } - } - return $this->_indexers; - } - - /** - * Retrieve Stock indexer by Product Type - * - * @param string $productTypeId - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface - */ - protected function _getIndexer($productTypeId) - { - $types = $this->_getTypeIndexers(); - if (!isset($types[$productTypeId])) { - Mage::throwException(Mage::helper('catalog')->__('Unsupported product type "%s".', $productTypeId)); - } - return $types[$productTypeId]; - } - - /** - * Retrieve parent ids and types by child id - * - * Return array with key product_id and value as product type id - * - * @param int $childId - * @return array - */ - public function getProductParentsByChild($childId) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from(array('l' => $this->getTable('catalog/product_relation')), array('parent_id')) - ->join( - array('e' => $this->getTable('catalog/product')), - 'l.parent_id=e.entity_id', - array('e.type_id')) - ->where('l.child_id=?', $childId); - return $write->fetchPairs($select); - } - - /** - * Copy relations product index from primary index to temporary index table by parent entity - * - * @deprecated since 1.4.0 - * @param array|int $parentIds - * @package array|int $excludeIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - protected function _copyRelationIndexData($parentIds, $excludeIds = null) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), array('child_id')) - ->where('parent_id IN(?)', $parentIds); - if (!is_null($excludeIds)) { - $select->where('child_id NOT IN(?)', $excludeIds); - } - - $children = $write->fetchCol($select); - - if ($children) { - $select = $write->select() - ->from($this->getMainTable()) - ->where('product_id IN(?)', $children); - $query = $select->insertFromSelect($this->getIdxTable()); - $write->query($query); - } - - return $this; - } - - /** - * Copy data from temporary index table to main table by defined ids - * - * @deprecated since 1.4.0 - * @param array $processIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price - */ - protected function _copyIndexDataToMainTable($processIds) - { - $write = $this->_getWriteAdapter(); - $write->beginTransaction(); - try { - // remove old index - $where = $write->quoteInto('product_id IN(?)', $processIds); - $write->delete($this->getMainTable(), $where); - - // remove additional data from index - $where = $write->quoteInto('product_id NOT IN(?)', $processIds); - $write->delete($this->getIdxTable(), $where); - - // insert new index - $this->insertFromTable($this->getIdxTable(), $this->getMainTable()); - - $this->commit(); - } catch (Exception $e) { - $this->rollBack(); - throw $e; - } - - return $this; - } - - /** - * Retrieve temporary index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('cataloginventory/stock_status_indexer_idx'); - } - return $this->getTable('cataloginventory/stock_status_indexer_tmp'); - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Configurable.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Configurable.php index 1c0409b27b..e9ce77f720 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Configurable.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,95 +33,6 @@ * @author Magento Core Team */ class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Configurable - extends Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable { - /** - * Reindex all stock status data for configurable products - * - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Configurable - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareIndexTable(); - return $this; - } - - /** - * Reindex stock data for defined configurable product ids - * - * @param int|array $entityIds - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Configurable - */ - public function reindexEntity($entityIds) - { - $this->_updateIndex($entityIds); - return $this; - } - - /** - * Get the select object for get stock status by product ids - * - * @param int|array $entityIds - * @param bool $usePrimaryTable use primary or temporary index table - * @return Varien_Db_Select - */ - protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) - { - $adapter = $this->_getWriteAdapter(); - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); - $select = $adapter->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('cw.website_id') - ->join( - array('cis' => $this->getTable('cataloginventory/stock')), - '', - array('stock_id')) - ->joinLeft( - array('cisi' => $this->getTable('cataloginventory/stock_item')), - 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', - array()) - ->joinLeft( - array('l' => $this->getTable('catalog/product_super_link')), - 'l.parent_id = e.entity_id', - array()) - ->join( - array('le' => $this->getTable('catalog/product')), - 'le.entity_id = l.product_id', - array()) - ->joinLeft( - array('i' => $idxTable), - 'i.product_id = l.product_id AND cw.website_id = i.website_id AND cis.stock_id = i.stock_id', - array()) - ->columns(array('qty' => new Zend_Db_Expr('0'))) - ->where('cw.website_id != 0') - ->where('e.type_id = ?', $this->getTypeId()) - ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); - - $psExpr = $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id'); - $psCond = $adapter->quoteInto($psExpr . '=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - - if ($this->_isManageStock()) { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0,' - . ' 1, cisi.is_in_stock)'); - } else { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1,' - . 'cisi.is_in_stock, 1)'); - } - - $stockStatusExpr = new Zend_Db_Expr("LEAST(MAX(IF({$psCond} AND le.required_options = 0, i.stock_status, 0))" - . ", {$statusExpr})"); - - $select->columns(array( - 'status' => $stockStatusExpr - )); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - return $select; - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Default.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Default.php index cd83b1dd6a..4b52c6f8f2 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Default.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,239 +33,6 @@ * @author Magento Core Team */ class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract - implements Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default { - /** - * Current Product Type Id - * - * @var string - */ - protected $_typeId; - - /** - * Product Type is composite flag - * - * @var bool - */ - protected $_isComposite = false; - - /** - * Initialize connection and define main table name - * - */ - protected function _construct() - { - $this->_init('cataloginventory/stock_status', 'product_id'); - } - - /** - * Reindex all stock status data for default logic product type - * - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareIndexTable(); - return $this; - } - - /** - * Reindex stock data for defined product ids - * - * @param int|array $entityIds - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - public function reindexEntity($entityIds) - { - $this->_updateIndex($entityIds); - return $this; - } - - /** - * Set active Product Type Id - * - * @param string $typeId - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - public function setTypeId($typeId) - { - $this->_typeId = $typeId; - return $this; - } - - /** - * Retrieve active Product Type Id - * - * @throws Mage_Core_Exception - * @return string - */ - public function getTypeId() - { - if (is_null($this->_typeId)) { - Mage::throwException(Mage::helper('cataloginventory')->__('Undefined product type.')); - } - return $this->_typeId; - } - - /** - * Set Product Type Composite flag - * - * @param bool $flag - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default - */ - public function setIsComposite($flag) - { - $this->_isComposite = (bool)$flag; - return $this; - } - - /** - * Check product type is composite - * - * @return bool - */ - public function getIsComposite() - { - return $this->_isComposite; - } - - /** - * Retrieve is Global Manage Stock enabled - * - * @return bool - */ - protected function _isManageStock() - { - return Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); - } - - /** - * Get the select object for get stock status by product ids - * - * @param int|array $entityIds - * @param bool $usePrimaryTable use primary or temporary index table - * @return Varien_Db_Select - */ - protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) - { - $adapter = $this->_getWriteAdapter(); - $select = $adapter->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('cw.website_id') - ->join( - array('cis' => $this->getTable('cataloginventory/stock')), - '', - array('stock_id')) - ->joinLeft( - array('cisi' => $this->getTable('cataloginventory/stock_item')), - 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', - array()) - ->columns(array('qty' => new Zend_Db_Expr('IF(cisi.qty > 0, cisi.qty, 0)'))) - ->where('cw.website_id != 0') - ->where('e.type_id = ?', $this->getTypeId()); - - // add limitation of status - $condition = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition); - - if ($this->_isManageStock()) { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0,' - . ' 1, cisi.is_in_stock)'); - } else { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1,' - . 'cisi.is_in_stock, 1)'); - } - - $select->columns(array('status' => $statusExpr)); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - return $select; - } - - /** - * Prepare stock status data in temporary index table - * - * @param int|array $entityIds the product limitation - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - protected function _prepareIndexTable($entityIds = null) - { - $adapter = $this->_getWriteAdapter(); - $select = $this->_getStockStatusSelect($entityIds); - $query = $select->insertFromSelect($this->getIdxTable()); - $adapter->query($query); - - return $this; - } - - /** - * Update Stock status index by product ids - * - * @param array|int $entityIds - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - protected function _updateIndex($entityIds) - { - $adapter = $this->_getWriteAdapter(); - $select = $this->_getStockStatusSelect($entityIds, true); - $query = $adapter->query($select); - - $i = 0; - $data = array(); - while ($row = $query->fetch(PDO::FETCH_ASSOC)) { - $i ++; - $data[] = array( - 'product_id' => $row['entity_id'], - 'website_id' => $row['website_id'], - 'stock_id' => $row['stock_id'], - 'qty' => $row['qty'], - 'stock_status' => (int)$row['status'], - ); - if (($i % 1000) == 0) { - $this->_updateIndexTable($data); - $data = array(); - } - } - $this->_updateIndexTable($data); - - return $this; - } - - /** - * Update stock status index table (INSERT ... ON DUPLICATE KEY UPDATE ...) - * - * @param array $data - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default - */ - protected function _updateIndexTable($data) - { - if (empty($data)) { - return $this; - } - - $adapter = $this->_getWriteAdapter(); - $adapter->insertOnDuplicate($this->getMainTable(), $data, array('qty', 'stock_status')); - - return $this; - } - - /** - * Retrieve temporary index table name - * - * @return string - */ - public function getIdxTable($table = null) - { - if ($this->useIdxTable()) { - return $this->getTable('cataloginventory/stock_status_indexer_idx'); - } - return $this->getTable('cataloginventory/stock_status_indexer_tmp'); - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Grouped.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Grouped.php index c97996bd62..a65c118618 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Grouped.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,96 +33,6 @@ * @author Magento Core Team */ class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Grouped - extends Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped { - /** - * Reindex all stock status data for configurable products - * - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Grouped - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareIndexTable(); - return $this; - } - - /** - * Reindex stock data for defined configurable product ids - * - * @param int|array $entityIds - * @return Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Grouped - */ - public function reindexEntity($entityIds) - { - $this->_updateIndex($entityIds); - return $this; - } - - /** - * Get the select object for get stock status by product ids - * - * @param int|array $entityIds - * @param bool $usePrimaryTable use primary or temporary index table - * @return Varien_Db_Select - */ - protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) - { - $adapter = $this->_getWriteAdapter(); - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); - $select = $adapter->select() - ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); - $this->_addWebsiteJoinToSelect($select, true); - $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); - $select->columns('cw.website_id') - ->join( - array('cis' => $this->getTable('cataloginventory/stock')), - '', - array('stock_id')) - ->joinLeft( - array('cisi' => $this->getTable('cataloginventory/stock_item')), - 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', - array()) - ->joinLeft( - array('l' => $this->getTable('catalog/product_link')), - 'e.entity_id = l.product_id AND l.link_type_id=' . Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, - array()) - ->joinLeft( - array('le' => $this->getTable('catalog/product')), - 'le.entity_id = l.linked_product_id', - array()) - ->joinLeft( - array('i' => $idxTable), - 'i.product_id = l.linked_product_id AND cw.website_id = i.website_id AND cis.stock_id = i.stock_id', - array()) - ->columns(array('qty' => new Zend_Db_Expr('0'))) - ->where('cw.website_id != 0') - ->where('e.type_id = ?', $this->getTypeId()) - ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); - - // add limitation of status - $psExpr = $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id'); - $psCond = $adapter->quoteInto($psExpr . '=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - - if ($this->_isManageStock()) { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0,' - . ' 1, cisi.is_in_stock)'); - } else { - $statusExpr = new Zend_Db_Expr('IF(cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1,' - . 'cisi.is_in_stock, 1)'); - } - - $stockStatusExpr = new Zend_Db_Expr("LEAST(MAX(IF({$psCond} AND le.required_options = 0, i.stock_status, 0))" - . ", {$statusExpr})"); - - $select->columns(array( - 'status' => $stockStatusExpr - )); - - if (!is_null($entityIds)) { - $select->where('e.entity_id IN(?)', $entityIds); - } - - return $select; - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Interface.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Interface.php index 6e631afa79..cf91ab2b2d 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Interface.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Indexer/Stock/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,36 +32,7 @@ * @package Mage_CatalogInventory * @author Magento Core Team */ -interface Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface +class Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface { - /** - * Reindex all stock status data - * - * @return Mage_CatalogIndex_Model_Mysql4_Indexer_Stock_Interface - */ - public function reindexAll(); - - /** - * Reindex stock status data for defined ids - * - * @param int|array $entityIds - * @return Mage_CatalogIndex_Model_Mysql4_Indexer_Stock_Interface - */ - public function reindexEntity($entityIds); - - /** - * Set Product Type Id for indexer - * - * @param string $typeId - * @return Mage_CatalogIndex_Model_Mysql4_Indexer_Stock_Interface - */ - public function setTypeId($typeId); - - /** - * Retrieve Product Type Id for indexer - * - * @throws Mage_Core_Exception - * @return string - */ - public function getTypeId(); } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock.php index a8a816a3b9..9e6c79ebd5 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock.php @@ -20,209 +20,18 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Stock resource model * - * @category Mage - * @package Mage_CatalogInventory + * @category Mage + * @package Mage_CatalogInventory * @author Magento Core Team */ -class Mage_CatalogInventory_Model_Mysql4_Stock extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogInventory_Model_Mysql4_Stock extends Mage_CatalogInventory_Model_Resource_Stock { - protected $_isConfig; - protected $_isConfigManageStock; - protected $_isConfigBackorders; - protected $_configMinQty; - protected $_configTypeIds; - protected $_configNotifyStockQty; - protected $_stock; - - protected function _construct() - { - $this->_init('cataloginventory/stock', 'stock_id'); - } - - public function lockProductItems($stock, $productIds) - { - $itemTable = $this->getTable('cataloginventory/stock_item'); - $select = $this->_getWriteAdapter()->select() - ->from($itemTable) - ->where('stock_id=?', $stock->getId()) - ->where('product_id IN(?)', $productIds) - ->forUpdate(true); - /** - * We use write adapter for resolving problems with replication - */ - $this->_getWriteAdapter()->query($select); - return $this; - } - - /** - * Get stock items data for requested products - * - * @param Mage_CatalogInventory_Model_Stock $stock - * @param array $productIds - * @param bool $lockRows - */ - public function getProductsStock($stock, $productIds, $lockRows = false) - { - $itemTable = $this->getTable('cataloginventory/stock_item'); - $productTable = $this->getTable('catalog/product'); - $select = $this->_getWriteAdapter()->select() - ->from(array('si' => $itemTable)) - ->join(array('p' => $productTable), 'p.entity_id=si.product_id', array('type_id')) - ->where('stock_id=?', $stock->getId()) - ->where('product_id IN(?)', $productIds) - ->forUpdate($lockRows); - return $this->_getWriteAdapter()->fetchAll($select); - } - - /** - * Correct particular stock products qty based on operator - * - * @param Mage_CatalogInventory_Model_Stock $stock - * @param array $productQtys array($productId => $qty) - * @param string $operator +/- - * @return Mage_CatalogInventory_Model_Mysql4_Stock - */ - public function correctItemsQty($stock, $productQtys, $operator='-') - { - if (empty($productQtys)) { - return $this; - } - $query = 'UPDATE '.$this->getTable('cataloginventory/stock_item').' SET `qty`=CASE `product_id` '; - foreach ($productQtys as $productId => $qty) { - $query.= $this->_getWriteAdapter()->quoteInto(' WHEN ? ', $productId); - $query.= $this->_getWriteAdapter()->quoteInto(' THEN `qty`'.$operator.'? ', $qty); - } - $query.= ' ELSE `qty` END'; - $query.= $this->_getWriteAdapter()->quoteInto(' WHERE `product_id` IN (?)', array_keys($productQtys)); - $query.= $this->_getWriteAdapter()->quoteInto(' AND `stock_id` =?', $stock->getId()); - - $this->_getWriteAdapter()->beginTransaction(); - $this->_getWriteAdapter()->query($query); - $this->_getWriteAdapter()->commit(); - return $this; - } - - /** - * add join to select only in stock products - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection $collection - * @return Mage_CatalogInventory_Model_Mysql4_Stock - */ - public function setInStockFilterToCollection( $collection) - { - $manageStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); - $cond = array( - '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', - '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0', - ); - - if ($manageStock) { - $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1'; - } - else { - $cond[] = '{{table}}.use_config_manage_stock = 1'; - } - - $collection->joinField( - 'inventory_in_stock', - 'cataloginventory/stock_item', - 'is_in_stock', - 'product_id=entity_id', - '('.join(') OR (', $cond) . ')' - ); - return $this; - } - - /** - * Load some inventory configuration settings - * - */ - protected function _initConfig() - { - if (!$this->_isConfig) { - $this->_isConfig = true; - $this->_isConfigManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); - $this->_isConfigBackorders = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_BACKORDERS); - $this->_configMinQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MIN_QTY); - $this->_configNotifyStockQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY); - $this->_configTypeIds = array_keys(Mage::helper('catalogInventory')->getIsQtyTypeIds(true)); - $this->_stock = Mage::getModel('cataloginventory/stock'); - } - } - - /** - * Set items out of stock basing on their quantities and config settings - * - */ - public function updateSetOutOfStock() - { - $this->_initConfig(); - $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), - array('is_in_stock' => 0, 'stock_status_changed_automatically' => 1), - sprintf('stock_id = %d - AND is_in_stock = 1 - AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) - AND (use_config_backorders = 1 AND %d = %d OR use_config_backorders = 0 AND backorders = %d) - AND (use_config_min_qty = 1 AND qty <= %d OR use_config_min_qty = 0 AND qty <= min_qty) - AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', - $this->_stock->getId(), - $this->_isConfigManageStock, - Mage_CatalogInventory_Model_Stock::BACKORDERS_NO, $this->_isConfigBackorders, Mage_CatalogInventory_Model_Stock::BACKORDERS_NO, - $this->_configMinQty, - $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) - )); - } - - /** - * Set items in stock basing on their quantities and config settings - * - */ - public function updateSetInStock() - { - $this->_initConfig(); - $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), - array('is_in_stock' => 1), - sprintf('stock_id = %d - AND is_in_stock = 0 - AND stock_status_changed_automatically = 1 - AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) - AND (use_config_min_qty = 1 AND qty > %d OR use_config_min_qty = 0 AND qty > min_qty) - AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', - $this->_stock->getId(), - $this->_isConfigManageStock, - $this->_configMinQty, - $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) - )); - } - - /** - * Update items low stock date basing on their quantities and config settings - * - */ - public function updateLowStockDate() - { - $nowUTC = Mage::app()->getLocale()->date(null, null, null, false)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); - $this->_initConfig(); - $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), - array('low_stock_date' => new Zend_Db_Expr(sprintf('CASE - WHEN (use_config_notify_stock_qty = 1 AND qty < %d) OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty) - THEN %s ELSE NULL - END - ', $this->_configNotifyStockQty, $this->_getWriteAdapter()->quote($nowUTC) - ))), - sprintf('stock_id = %d - AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) - AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', - $this->_stock->getId(), - $this->_isConfigManageStock, - $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) - )); - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item.php index 9fccc4d36a..e8b529c3c7 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item.php @@ -20,106 +20,18 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Stock item resource model * - * @category Mage - * @package Mage_CatalogInventory + * @category Mage + * @package Mage_CatalogInventory * @author Magento Core Team */ -class Mage_CatalogInventory_Model_Mysql4_Stock_Item extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogInventory_Model_Mysql4_Stock_Item extends Mage_CatalogInventory_Model_Resource_Stock_Item { - protected function _construct() - { - $this->_init('cataloginventory/stock_item', 'item_id'); - } - - /** - * Loading stock item data by product - * - * @param Mage_CatalogInventory_Model_Stock_Item $item - * @param int $productId - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function loadByProductId(Mage_CatalogInventory_Model_Stock_Item $item, $productId) - { - $select = $this->_getLoadSelect('product_id', $productId, $item) - ->where('stock_id=?', $item->getStockId()); - - $item->setData($this->_getReadAdapter()->fetchRow($select)); - $this->_afterLoad($item); - return $this; - } - - /** - * Retrieve select object and join it to product entity table to get type ids - * - * @param string $field - * @param mixed $value - * @param object $object - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - return parent::_getLoadSelect($field, $value, $object) - ->joinInner(array('p' => $this->getTable('catalog/product')), 'product_id=p.entity_id', 'type_id') - ; - } - - /** - * Add join for catalog in stock field to product collection - * - * @param Mage_Catalog_Model_Entity_Product_Collection $productCollection - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Item - */ - public function addCatalogInventoryToProductCollection($productCollection) - { - $isStockManagedInConfig = (int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); - $inventoryTable = $this->getTable('cataloginventory/stock_item'); - $productCollection->joinTable('cataloginventory/stock_item', - 'product_id=entity_id', - array( - 'is_saleable' => new Zend_Db_Expr( - "( - IF( - IF( - $inventoryTable.use_config_manage_stock, - $isStockManagedInConfig, - $inventoryTable.manage_stock - ), - $inventoryTable.is_in_stock, - 1 - ) - )" - ), - 'inventory_in_stock' => 'is_in_stock' - ), - null, 'left'); - return $this; - } - - /** - * Use qty correction for qty column update - * - * @param Varien_Object $object - * @param string $table - * @return array - */ - protected function _prepareDataForTable(Varien_Object $object, $table) - { - $data = parent::_prepareDataForTable($object, $table); - if ($object->getQtyCorrection()) { - if ($object->getQtyCorrection() < 0) { - $data['qty'] = new Zend_Db_Expr('`qty`-'.abs($object->getQtyCorrection())); - } else { - $data['qty'] = new Zend_Db_Expr('`qty`+'.$object->getQtyCorrection()); - } - } - return $data; - } - } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item/Collection.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item/Collection.php index b078082b86..326bfe4ae1 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item/Collection.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Item/Collection.php @@ -20,119 +20,19 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Stock item collection resource model * - * @category Mage - * @package Mage_CatalogInventory + * @category Mage + * @package Mage_CatalogInventory * @author Magento Core Team */ -class Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection + extends Mage_CatalogInventory_Model_Resource_Stock_Item_Collection { - protected function _construct() - { - $this->_init('cataloginventory/stock_item'); - } - - /** - * Add stock filter to collection - * - * @param mixed $stock - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection - */ - public function addStockFilter($stock) - { - if ($stock instanceof Mage_CatalogInventory_Model_Stock) { - $this->addFieldToFilter('main_table.stock_id', $stock->getId()); - } - else { - $this->addFieldToFilter('main_table.stock_id', $stock); - } - return $this; - } - - /** - * Add product filter to collection - * - * @param mixed $products - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection - */ - public function addProductsFilter($products) - { - $productIds = array(); - foreach ($products as $product) { - if ($product instanceof Mage_Catalog_Model_Product) { - $productIds[] = $product->getId(); - } - else { - $productIds[] = $product; - } - } - if (empty($productIds)) { - $productIds[] = false; - $this->_setIsLoaded(true); - } - $this->addFieldToFilter('main_table.product_id', array('in'=>$productIds)); - return $this; - } - - /** - * Join Stock Status to collection - * - * @param int $storeId - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection - */ - public function joinStockStatus($storeId = null) - { - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - $this->getSelect()->joinLeft( - array('status_table' => $this->getTable('cataloginventory/stock_status')), - '`main_table`.`product_id`=`status_table`.`product_id`' - . ' AND `main_table`.`stock_id`=`status_table`.`stock_id`' - . $this->getConnection()->quoteInto(' AND `status_table`.`website_id`=?', $websiteId), - array('stock_status') - ); - - return $this; - } - - public function addManagedFilter($isStockManagedInConfig) - { - if ($isStockManagedInConfig) { - $this->getSelect()->where('(manage_stock = 1 OR use_config_manage_stock = 1)'); - } else { - $this->addFieldToFilter('manage_stock', 1); - } - - return $this; - } - - public function addQtyFilter($comparsionMethod, $qty) - { - $allowedMethods = array('<', '>', '=', '<=', '>=', '<>'); - if (!in_array($comparsionMethod, $allowedMethods)) { - Mage::throwException(Mage::helper('cataloginventory')->__('%s is not a correct comparsion method.', $comparsionMethod)); - } - $this->getSelect()->where("main_table.qty {$comparsionMethod} ?", $qty); - return $this; - } - - /** - * Load data - * - * @return Varien_Data_Collection_Db - */ - public function load($printQuery = false, $logQuery = false) - { - if (!$this->isLoaded()) { - $this->getSelect()->joinInner(array('_products_table' => $this->getTable('catalog/product')), - 'main_table.product_id=_products_table.entity_id', 'type_id' - ); - } - return parent::load($printQuery, $logQuery); - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Status.php b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Status.php index f441380d8b..610c0f5675 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Status.php +++ b/app/code/core/Mage/CatalogInventory/Model/Mysql4/Stock/Status.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CatalogInventory Stock Status per website Resource Model * @@ -31,225 +32,6 @@ * @package Mage_CatalogInventory * @author Magento Core Team */ -class Mage_CatalogInventory_Model_Mysql4_Stock_Status extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogInventory_Model_Mysql4_Stock_Status extends Mage_CatalogInventory_Model_Resource_Stock_Status { - /** - * Resource model initialization - * - */ - protected function _construct() - { - $this->_init('cataloginventory/stock_status', 'product_id'); - } - - /** - * Save Product Status per website - * - * @param Mage_CatalogInventory_Model_Stock_Status $object - * @param int $productId - * @param int $status - * @param float $qty - * @param int $stockId - * @param int|null $websiteId - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Status - */ - public function saveProductStatus(Mage_CatalogInventory_Model_Stock_Status $object, - $productId, $status, $qty = 0, $stockId = 1, $websiteId = null) - { - $websites = array_keys($object->getWebsites($websiteId)); - - foreach ($websites as $websiteId) { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('product_id=?', $productId) - ->where('website_id=?', $websiteId) - ->where('stock_id=?', $stockId); - if ($row = $this->_getWriteAdapter()->fetchRow($select)) { - $bind = array( - 'qty' => $qty, - 'stock_status' => $status - ); - $where = array( - $this->_getWriteAdapter()->quoteInto('product_id=?', $row['product_id']), - $this->_getWriteAdapter()->quoteInto('website_id=?', $row['website_id']), - $this->_getWriteAdapter()->quoteInto('stock_id=?', $row['stock_id']), - ); - $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); - } - else { - $bind = array( - 'product_id' => $productId, - 'website_id' => $websiteId, - 'stock_id' => $stockId, - 'qty' => $qty, - 'stock_status' => $status - ); - $this->_getWriteAdapter()->insert($this->getMainTable(), $bind); - } - } - - return $this; - } - - /** - * Retrieve product status - * Return array as key product id, value - stock status - * - * @param int|array $productIds - * @param int $websiteId - * @param int $stockId - * - * @return array - */ - public function getProductStatus($productIds, $websiteId, $stockId = 1) - { - if (!is_array($productIds)) { - $productIds = array($productIds); - } - - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('product_id', 'stock_status')) - ->where('product_id IN(?)', $productIds) - ->where('stock_id=?', $stockId) - ->where('website_id=?', $websiteId); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Retrieve product(s) data array - * - * @param int|array $productIds - * @param int $websiteId - * @param int $stockId - * - * @return array - */ - public function getProductData($productIds, $websiteId, $stockId = 1) - { - if (!is_array($productIds)) { - $productIds = array($productIds); - } - - $data = array(); - - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('product_id IN(?)', $productIds) - ->where('stock_id=?', $stockId) - ->where('website_id=?', $websiteId); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $data[$row['product_id']] = $row; - } - return $data; - } - - /** - * Retrieve websites and default stores - * Return array as key website_id, value store_id - * - * @return array - */ - public function getWebsiteStores() { - $select = Mage::getModel('core/website')->getDefaultStoresSelect(false); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Retrieve Product Type - * - * @param array|int $productIds - * @return array - */ - public function getProductsType($productIds) - { - if (!is_array($productIds)) { - $productIds = array($productIds); - } - - $select = $this->_getReadAdapter()->select() - ->from( - array('e' => $this->getTable('catalog/product')), - array('entity_id', 'type_id')) - ->where('entity_id IN(?)', $productIds); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Retrieve Product part Collection array - * Return array as key product id, value product type - * - * @param int $lastEntityId - * @param int $limit - * @return array - */ - public function getProductCollection($lastEntityId = 0, $limit = 1000) { - $select = $this->_getReadAdapter()->select() - ->from( - array('e' => $this->getTable('catalog/product')), - array('entity_id', 'type_id')) - ->order('entity_id ASC') - ->where('entity_id>?', $lastEntityId) - ->limit($limit); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Add stock status to prepare index select - * - * @param Varien_Db_Select $select - * @param Mage_Core_Model_Website $website - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Status - */ - public function addStockStatusToSelect(Varien_Db_Select $select, Mage_Core_Model_Website $website) - { - $websiteId = $website->getId(); - $select->joinLeft( - array('stock_status' => $this->getMainTable()), - 'e.entity_id=stock_status.product_id AND stock_status.website_id='.$websiteId, - array('salable' => 'stock_status.stock_status') - ); - - return $this; - } - - /** - * Add stock status limitation to catalog product price index select object - * - * @param Varien_Db_Select $select - * @param string|Zend_Db_Expr $entityField - * @param string|Zend_Db_Expr $websiteField - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Status - */ - public function prepareCatalogProductIndexSelect(Varien_Db_Select $select, $entityField, $websiteField) - { - $select->join( - array('ciss' => $this->getMainTable()), - "ciss.product_id = {$entityField} AND ciss.website_id = {$websiteField}", - array() - ); - $select->where('ciss.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK); - - return $this; - } - - /** - * Add only is in stock products filter to product collection - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection - * @return Mage_CatalogInventory_Model_Stock_Status - */ - public function addIsInStockFilterToCollection($collection) - { - $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId(); - $collection->getSelect() - ->join( - array('stock_status_index' => $this->getMainTable()), - 'e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = ' . $websiteId - . ' AND stock_status_index.stock_id = ' . Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID, - array()) - ->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK); - - return $this; - } } diff --git a/app/code/core/Mage/CatalogInventory/Model/Observer.php b/app/code/core/Mage/CatalogInventory/Model/Observer.php index f0d05cb32e..3df030dff0 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Observer.php +++ b/app/code/core/Mage/CatalogInventory/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -177,7 +177,7 @@ public function copyInventoryData($observer) ); if ($currentStockItem = $currentProduct->getStockItem()) { $stockData += array( - 'use_config_enable_qty_increments' => $currentStockItem->getData('use_config_enable_qty_increments'), + 'use_config_enable_qty_inc' => $currentStockItem->getData('use_config_enable_qty_inc'), 'enable_qty_increments' => $currentStockItem->getData('enable_qty_increments'), 'use_config_qty_increments' => $currentStockItem->getData('use_config_qty_increments'), 'qty_increments' => $currentStockItem->getData('qty_increments'), @@ -226,8 +226,8 @@ protected function _prepareItemForSave($item, $product) $item->setQtyCorrection($item->getQty()-$originalQty); } if (!is_null($product->getData('stock_data/enable_qty_increments')) - && is_null($product->getData('stock_data/use_config_enable_qty_increments'))) { - $item->setData('use_config_enable_qty_increments', false); + && is_null($product->getData('stock_data/use_config_enable_qty_inc'))) { + $item->setData('use_config_enable_qty_inc', false); } if (!is_null($product->getData('stock_data/qty_increments')) && is_null($product->getData('stock_data/use_config_qty_increments'))) { @@ -606,7 +606,10 @@ public function reindexQuoteInventory($observer) } } } - Mage::getResourceSingleton('cataloginventory/indexer_stock')->reindexProducts($productIds); + + if( count($productIds)) { + Mage::getResourceSingleton('cataloginventory/indexer_stock')->reindexProducts($productIds); + } // Reindex previously remembered items $productIds = array(); diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock.php new file mode 100755 index 0000000000..548439ad73 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock.php @@ -0,0 +1,340 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Indexer_Stock extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract +{ + /** + * Stock Indexer models per product type + * Sorted by priority + * + * @var array + */ + protected $_indexers; + + /** + * Default Stock Indexer resource model name + * + * @var string + */ + protected $_defaultIndexer = 'cataloginventory/indexer_stock_default'; + + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock_status', 'product_id'); + } + + /** + * Process stock item save action + * + * @param Mage_Index_Model_Event $event + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock + */ + public function cataloginventoryStockItemSave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['product_id'])) { + return $this; + } + + $productId = $data['product_id']; + $this->reindexProducts($productId); + + if (!empty($data['force_reindex_required'])) { + $massObject = new Varien_Object(); + $massObject->setAttributesData(array( + 'force_reindex_required' => 1 + )); + $massObject->setProductIds(array($productId)); + Mage::getSingleton('index/indexer')->processEntityAction( + $massObject, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION + ); + } + + return $this; + } + + /** + * Refresh stock index for specific product ids + * + * @param array $productIds + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock + */ + public function reindexProducts($productIds) + { + $adapter = $this->_getWriteAdapter(); + if (!is_array($productIds)) { + $productIds = array($productIds); + } + $parentIds = $this->getRelationsByChild($productIds); + if ($parentIds) { + $processIds = array_merge($parentIds, $productIds); + } else { + $processIds = $productIds; + } + + // retrieve product types by processIds + $select = $adapter->select() + ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) + ->where('entity_id IN(?)', $processIds); + $pairs = $adapter->fetchPairs($select); + + $byType = array(); + foreach ($pairs as $productId => $typeId) { + $byType[$typeId][$productId] = $productId; + } + + $adapter->beginTransaction(); + try { + $indexers = $this->_getTypeIndexers(); + foreach ($indexers as $indexer) { + if (isset($byType[$indexer->getTypeId()])) { + $indexer->reindexEntity($byType[$indexer->getTypeId()]); + } + } + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + $adapter->commit(); + + return $this; + } + + /** + * Processing parent products after child product deleted + * + * @param Mage_Index_Model_Event $event + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock + */ + public function catalogProductDelete(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_stock_parent_ids'])) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + + $parentIds = array(); + foreach ($data['reindex_stock_parent_ids'] as $parentId => $parentType) { + $parentIds[$parentType][$parentId] = $parentId; + } + + $adapter->beginTransaction(); + try { + foreach ($parentIds as $parentType => $entityIds) { + $this->_getIndexer($parentType)->reindexEntity($entityIds); + } + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + + $adapter->commit(); + + return $this; + } + + /** + * Process product mass update action + * + * @param Mage_Index_Model_Event $event + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock + */ + public function catalogProductMassAction(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['reindex_stock_product_ids'])) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + $processIds = $data['reindex_stock_product_ids']; + $select = $adapter->select() + ->from($this->getTable('catalog/product'), 'COUNT(*)'); + $pCount = $adapter->fetchOne($select); + + // if affected more 30% of all products - run reindex all products + if ($pCount * 0.3 < count($processIds)) { + return $this->reindexAll(); + } + + // calculate relations + $select = $adapter->select() + ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)') + ->where('child_id IN(?)', $processIds); + $aCount = $adapter->fetchOne($select); + $select = $adapter->select() + ->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)') + ->where('parent_id IN(?)', $processIds); + $bCount = $adapter->fetchOne($select); + + // if affected with relations more 30% of all products - run reindex all products + if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) { + return $this->reindexAll(); + } + + + // retrieve affected parent relation products + $parentIds = $this->getRelationsByChild($processIds); + if ($parentIds) { + $processIds = array_merge($processIds, $parentIds); + } + + // retrieve products types + $select = $adapter->select() + ->from($this->getTable('catalog/product'), array('entity_id', 'type_id')) + ->where('entity_id IN(?)', $processIds); + $query = $select->query(Zend_Db::FETCH_ASSOC); + $byType = array(); + while ($row = $query->fetch()) { + $byType[$row['type_id']][] = $row['entity_id']; + } + + $adapter->beginTransaction(); + try { + $indexers = $this->_getTypeIndexers(); + foreach ($indexers as $indexer) { + if (!empty($byType[$indexer->getTypeId()])) { + $indexer->reindexEntity($byType[$indexer->getTypeId()]); + } + } + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + $adapter->commit(); + + return $this; + } + + /** + * Rebuild all index data + * + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->clearTemporaryIndexTable(); + + foreach ($this->_getTypeIndexers() as $indexer) { + $indexer->reindexAll(); + } + + $this->syncData(); + return $this; + } + + /** + * Retrieve Stock Indexer Models per Product Type + * + * @return array + */ + protected function _getTypeIndexers() + { + if (is_null($this->_indexers)) { + $this->_indexers = array(); + $types = Mage::getSingleton('catalog/product_type')->getTypesByPriority(); + foreach ($types as $typeId => $typeInfo) { + if (isset($typeInfo['stock_indexer'])) { + $modelName = $typeInfo['stock_indexer']; + } else { + $modelName = $this->_defaultIndexer; + } + $isComposite = !empty($typeInfo['composite']); + $indexer = Mage::getResourceModel($modelName) + ->setTypeId($typeId) + ->setIsComposite($isComposite); + + $this->_indexers[$typeId] = $indexer; + } + } + return $this->_indexers; + } + + /** + * Retrieve Stock indexer by Product Type + * + * @param string $productTypeId + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface + */ + protected function _getIndexer($productTypeId) + { + $types = $this->_getTypeIndexers(); + if (!isset($types[$productTypeId])) { + Mage::throwException(Mage::helper('catalog')->__('Unsupported product type "%s".', $productTypeId)); + } + return $types[$productTypeId]; + } + + /** + * Retrieve parent ids and types by child id + * Return array with key product_id and value as product type id + * + * @param int $childId + * @return array + */ + public function getProductParentsByChild($childId) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from(array('l' => $this->getTable('catalog/product_relation')), array('parent_id')) + ->join( + array('e' => $this->getTable('catalog/product')), + 'l.parent_id=e.entity_id', + array('e.type_id') + ) + ->where('l.child_id = :child_id'); + return $write->fetchPairs($select, array(':child_id' => $childId)); + } + + /** + * Retrieve temporary index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('cataloginventory/stock_status_indexer_idx'); + } + return $this->getTable('cataloginventory/stock_status_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Configurable.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Configurable.php new file mode 100755 index 0000000000..b1d282a283 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Configurable.php @@ -0,0 +1,127 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default +{ + /** + * Reindex all stock status data for configurable products + * + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareIndexTable(); + return $this; + } + + /** + * Reindex stock data for defined configurable product ids + * + * @param int|array $entityIds + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable + */ + public function reindexEntity($entityIds) + { + $this->_updateIndex($entityIds); + return $this; + } + + /** + * Get the select object for get stock status by product ids + * + * @param int|array $entityIds + * @param bool $usePrimaryTable use primary or temporary index table + * @return Varien_Db_Select + */ + protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) + { + $adapter = $this->_getWriteAdapter(); + $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); + $select = $adapter->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $select->columns('cw.website_id') + ->join( + array('cis' => $this->getTable('cataloginventory/stock')), + '', + array('stock_id')) + ->joinLeft( + array('cisi' => $this->getTable('cataloginventory/stock_item')), + 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', + array()) + ->joinLeft( + array('l' => $this->getTable('catalog/product_super_link')), + 'l.parent_id = e.entity_id', + array()) + ->join( + array('le' => $this->getTable('catalog/product')), + 'le.entity_id = l.product_id', + array()) + ->joinLeft( + array('i' => $idxTable), + 'i.product_id = l.product_id AND cw.website_id = i.website_id AND cis.stock_id = i.stock_id', + array()) + ->columns(array('qty' => new Zend_Db_Expr('0'))) + ->where('cw.website_id != 0') + ->where('e.type_id = ?', $this->getTypeId()) + ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); + + $psExpr = $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id'); + $psCond = $adapter->quoteInto($psExpr . '=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + + if ($this->_isManageStock()) { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0', + 1, 'cisi.is_in_stock'); + } else { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1', + 'cisi.is_in_stock', 1); + } + + $optExpr = $adapter->getCheckSql("{$psCond} AND le.required_options = 0", 'i.stock_status', 0); + $stockStatusExpr = $adapter->getLeastSql(array("MAX({$optExpr})", "MIN({$statusExpr})")); + + $select->columns(array( + 'status' => $stockStatusExpr + )); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + return $select; + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Default.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Default.php new file mode 100755 index 0000000000..6688e3f5dc --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Default.php @@ -0,0 +1,274 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract + implements Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface +{ + /** + * Current Product Type Id + * + * @var string + */ + protected $_typeId; + + /** + * Product Type is composite flag + * + * @var bool + */ + protected $_isComposite = false; + + /** + * Initialize connection and define main table name + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock_status', 'product_id'); + } + + /** + * Reindex all stock status data for default logic product type + * + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareIndexTable(); + return $this; + } + + /** + * Reindex stock data for defined product ids + * + * @param int|array $entityIds + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + public function reindexEntity($entityIds) + { + $this->_updateIndex($entityIds); + return $this; + } + + /** + * Set active Product Type Id + * + * @param string $typeId + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + public function setTypeId($typeId) + { + $this->_typeId = $typeId; + return $this; + } + + /** + * Retrieve active Product Type Id + * + * @throws Mage_Core_Exception + * + * @return string + */ + public function getTypeId() + { + if (is_null($this->_typeId)) { + Mage::throwException(Mage::helper('cataloginventory')->__('Undefined product type.')); + } + return $this->_typeId; + } + + /** + * Set Product Type Composite flag + * + * @param bool $flag + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + public function setIsComposite($flag) + { + $this->_isComposite = (bool)$flag; + return $this; + } + + /** + * Check product type is composite + * + * @return bool + */ + public function getIsComposite() + { + return $this->_isComposite; + } + + /** + * Retrieve is Global Manage Stock enabled + * + * @return bool + */ + protected function _isManageStock() + { + return Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); + } + + /** + * Get the select object for get stock status by product ids + * + * @param int|array $entityIds + * @param bool $usePrimaryTable use primary or temporary index table + * @return Varien_Db_Select + */ + protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) + { + $adapter = $this->_getWriteAdapter(); + $qtyExpr = $adapter->getCheckSql('cisi.qty > 0', 'cisi.qty', 0); + $select = $adapter->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $select->columns('cw.website_id') + ->join( + array('cis' => $this->getTable('cataloginventory/stock')), + '', + array('stock_id')) + ->joinLeft( + array('cisi' => $this->getTable('cataloginventory/stock_item')), + 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', + array()) + ->columns(array('qty' => $qtyExpr)) + ->where('cw.website_id != 0') + ->where('e.type_id = ?', $this->getTypeId()); + + // add limitation of status + $condition = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition); + + if ($this->_isManageStock()) { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0', + 1, 'cisi.is_in_stock'); + } else { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1', + 'cisi.is_in_stock', 1); + } + + $select->columns(array('status' => $statusExpr)); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + return $select; + } + + /** + * Prepare stock status data in temporary index table + * + * @param int|array $entityIds the product limitation + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + protected function _prepareIndexTable($entityIds = null) + { + $adapter = $this->_getWriteAdapter(); + $select = $this->_getStockStatusSelect($entityIds); + $query = $select->insertFromSelect($this->getIdxTable()); + $adapter->query($query); + + return $this; + } + + /** + * Update Stock status index by product ids + * + * @param array|int $entityIds + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + protected function _updateIndex($entityIds) + { + $adapter = $this->_getWriteAdapter(); + $select = $this->_getStockStatusSelect($entityIds, true); + $query = $adapter->query($select); + + $i = 0; + $data = array(); + while ($row = $query->fetch(PDO::FETCH_ASSOC)) { + $i ++; + $data[] = array( + 'product_id' => (int)$row['entity_id'], + 'website_id' => (int)$row['website_id'], + 'stock_id' => (int)$row['stock_id'], + 'qty' => (float)$row['qty'], + 'stock_status' => (int)$row['status'], + ); + if (($i % 1000) == 0) { + $this->_updateIndexTable($data); + $data = array(); + } + } + $this->_updateIndexTable($data); + + return $this; + } + + /** + * Update stock status index table (INSERT ... ON DUPLICATE KEY UPDATE ...) + * + * @param array $data + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default + */ + protected function _updateIndexTable($data) + { + if (empty($data)) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + $adapter->insertOnDuplicate($this->getMainTable(), $data, array('qty', 'stock_status')); + + return $this; + } + + /** + * Retrieve temporary index table name + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + if ($this->useIdxTable()) { + return $this->getTable('cataloginventory/stock_status_indexer_idx'); + } + return $this->getTable('cataloginventory/stock_status_indexer_tmp'); + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Grouped.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Grouped.php new file mode 100755 index 0000000000..076fd280c3 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Grouped.php @@ -0,0 +1,128 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped + extends Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default +{ + /** + * Reindex all stock status data for configurable products + * + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareIndexTable(); + return $this; + } + + /** + * Reindex stock data for defined configurable product ids + * + * @param int|array $entityIds + * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped + */ + public function reindexEntity($entityIds) + { + $this->_updateIndex($entityIds); + return $this; + } + + /** + * Get the select object for get stock status by product ids + * + * @param int|array $entityIds + * @param bool $usePrimaryTable use primary or temporary index table + * @return Varien_Db_Select + */ + protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) + { + $adapter = $this->_getWriteAdapter(); + $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable(); + $select = $adapter->select() + ->from(array('e' => $this->getTable('catalog/product')), array('entity_id')); + $this->_addWebsiteJoinToSelect($select, true); + $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id'); + $select->columns('cw.website_id') + ->join( + array('cis' => $this->getTable('cataloginventory/stock')), + '', + array('stock_id')) + ->joinLeft( + array('cisi' => $this->getTable('cataloginventory/stock_item')), + 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id', + array()) + ->joinLeft( + array('l' => $this->getTable('catalog/product_link')), + 'e.entity_id = l.product_id AND l.link_type_id=' . Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED, + array()) + ->joinLeft( + array('le' => $this->getTable('catalog/product')), + 'le.entity_id = l.linked_product_id', + array()) + ->joinLeft( + array('i' => $idxTable), + 'i.product_id = l.linked_product_id AND cw.website_id = i.website_id AND cis.stock_id = i.stock_id', + array()) + ->columns(array('qty' => new Zend_Db_Expr('0'))) + ->where('cw.website_id != 0') + ->where('e.type_id = ?', $this->getTypeId()) + ->group(array('e.entity_id', 'cw.website_id', 'cis.stock_id')); + + // add limitation of status + $psExpr = $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id'); + $psCond = $adapter->quoteInto($psExpr . '=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + + if ($this->_isManageStock()) { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0', + 1, 'cisi.is_in_stock'); + } else { + $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1', + 'cisi.is_in_stock', 1); + } + + $optExpr = $adapter->getCheckSql("{$psCond} AND le.required_options = 0", 'i.stock_status', 0); + $stockStatusExpr = $adapter->getLeastSql(array("MAX({$optExpr})", "MIN({$statusExpr})")); + + $select->columns(array( + 'status' => $stockStatusExpr + )); + + if (!is_null($entityIds)) { + $select->where('e.entity_id IN(?)', $entityIds); + } + + return $select; + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Interface.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Interface.php new file mode 100755 index 0000000000..8447e16d0d --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Indexer/Stock/Interface.php @@ -0,0 +1,68 @@ + + */ +interface Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface +{ + /** + * Reindex all stock status data + * + */ + public function reindexAll() +; + + /** + * Reindex stock status data for defined ids + * + * @param int|array $entityIds + */ + public function reindexEntity($entityIds) +; + + /** + * Set Product Type Id for indexer + * + * @param string $typeId + */ + public function setTypeId($typeId) +; + + /** + * Retrieve Product Type Id for indexer + * + * @throws Mage_Core_Exception + * + */ + public function getTypeId() +; +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php new file mode 100755 index 0000000000..f529a38722 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php @@ -0,0 +1,322 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Stock extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Is initialized configuration flag + * + * @var boolean + */ + protected $_isConfig; + + /** + * Manage Stock flag + * + * @var boolean + */ + protected $_isConfigManageStock; + + /** + * Backorders + * + * @var boolean + */ + protected $_isConfigBackorders; + + /** + * Minimum quantity allowed in shopping card + * + * @var int + */ + protected $_configMinQty; + + /** + * Product types that could have quantities + * + * @var array + */ + protected $_configTypeIds; + + /** + * Notify for quantity below _configNotifyStockQty value + * + * @var int + */ + protected $_configNotifyStockQty; + + /** + * Ctalog Inventory Stock instance + * + * @var Mage_CatalogInventory_Model_Stock + */ + protected $_stock; + + /** + * Define main table and initialize connection + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock', 'stock_id'); + } + + /** + * Lock product items + * + * @param Mage_CatalogInventory_Model_Stock $stock + * @param int|array $productIds + * @return Mage_CatalogInventory_Model_Resource_Stock + */ + public function lockProductItems($stock, $productIds) + { + $itemTable = $this->getTable('cataloginventory/stock_item'); + $select = $this->_getWriteAdapter()->select() + ->from($itemTable) + ->where('stock_id=?', $stock->getId()) + ->where('product_id IN(?)', $productIds) + ->forUpdate(true); + /** + * We use write adapter for resolving problems with replication + */ + $this->_getWriteAdapter()->query($select); + return $this; + } + + /** + * Get stock items data for requested products + * + * @param Mage_CatalogInventory_Model_Stock $stock + * @param array $productIds + * @param bool $lockRows + * @return array + */ + public function getProductsStock($stock, $productIds, $lockRows = false) + { + if (empty($productIds)) { + return array(); + } + $itemTable = $this->getTable('cataloginventory/stock_item'); + $productTable = $this->getTable('catalog/product'); + $select = $this->_getWriteAdapter()->select() + ->from(array('si' => $itemTable)) + ->join(array('p' => $productTable), 'p.entity_id=si.product_id', array('type_id')) + ->where('stock_id=?', $stock->getId()) + ->where('product_id IN(?)', $productIds) + ->forUpdate($lockRows); + return $this->_getWriteAdapter()->fetchAll($select); + } + + /** + * Correct particular stock products qty based on operator + * + * @param Mage_CatalogInventory_Model_Stock $stock + * @param array $productQtys + * @param string $operator +/- + * @return Mage_CatalogInventory_Model_Resource_Stock + */ + public function correctItemsQty($stock, $productQtys, $operator = '-') + { + if (empty($productQtys)) { + return $this; + } + + $adapter = $this->_getWriteAdapter(); + $conditions = array(); + foreach ($productQtys as $productId => $qty) { + $case = $adapter->quoteInto('?', $productId); + $result = $adapter->quoteInto("qty{$operator}?", $qty); + $conditions[$case] = $result; + } + + $value = $adapter->getCaseSql('product_id', $conditions, 'qty'); + + $where = array( + 'product_id IN (?)' => array_keys($productQtys), + 'stock_id = ?' => $stock->getId() + ); + + $adapter->beginTransaction(); + $adapter->update($this->getTable('cataloginventory/stock_item'), array('qty' => $value), $where); + $adapter->commit(); + + return $this; + } + + /** + * add join to select only in stock products + * + * @param Mage_Catalog_Model_Resource_Product_Link_Product_Collection $collection + * @return Mage_CatalogInventory_Model_Resource_Stock + */ + public function setInStockFilterToCollection($collection) + { + $manageStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); + $cond = array( + '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', + '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0', + ); + + if ($manageStock) { + $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1'; + } else { + $cond[] = '{{table}}.use_config_manage_stock = 1'; + } + + $collection->joinField( + 'inventory_in_stock', + 'cataloginventory/stock_item', + 'is_in_stock', + 'product_id=entity_id', + '(' . join(') OR (', $cond) . ')' + ); + return $this; + } + + /** + * Load some inventory configuration settings + * + */ + protected function _initConfig() + { + if (!$this->_isConfig) { + $this->_isConfig = true; + $this->_isConfigManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); + $this->_isConfigBackorders = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_BACKORDERS); + $this->_configMinQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MIN_QTY); + $this->_configNotifyStockQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY); + $this->_configTypeIds = array_keys(Mage::helper('catalogInventory')->getIsQtyTypeIds(true)); + $this->_stock = Mage::getModel('cataloginventory/stock'); + } + } + + /** + * Set items out of stock basing on their quantities and config settings + * + */ + public function updateSetOutOfStock() + { + $this->_initConfig(); + $adapter = $this->_getWriteAdapter(); + $values = array( + 'is_in_stock' => 0, + 'stock_status_changed_auto' => 1 + ); + + $select = $adapter->select() + ->from($this->getTable('catalog/product'), 'entity_id') + ->where('type_id IN(?)', $this->_configTypeIds); + + $where = sprintf('stock_id = %1$d' + . ' AND is_in_stock = 1' + . ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' + . ' AND ((use_config_backorders = 1 AND %3$d = %4$d) OR (use_config_backorders = 0 AND backorders = %3$d))' + . ' AND ((use_config_min_qty = 1 AND qty <= %5$d) OR (use_config_min_qty = 0 AND qty <= min_qty))' + . ' AND product_id IN (%6$s)', + $this->_stock->getId(), + $this->_isConfigManageStock, + Mage_CatalogInventory_Model_Stock::BACKORDERS_NO, + $this->_isConfigBackorders, + $this->_configMinQty, + $select->assemble() + ); + + $adapter->update($this->getTable('cataloginventory/stock_item'), $values, $where); + } + + /** + * Set items in stock basing on their quantities and config settings + * + */ + public function updateSetInStock() + { + $this->_initConfig(); + $adapter = $this->_getWriteAdapter(); + $values = array( + 'is_in_stock' => 1, + ); + + $select = $adapter->select() + ->from($this->getTable('catalog/product'), 'entity_id') + ->where('type_id IN(?)', $this->_configTypeIds); + + $where = sprintf('stock_id = %1$d' + . ' AND is_in_stock = 0' + . ' AND stock_status_changed_auto = 1' + . ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' + . ' AND ((use_config_min_qty = 1 AND qty > %3$d) OR (use_config_min_qty = 0 AND qty > min_qty))' + . ' AND product_id IN (%4$s)', + $this->_stock->getId(), + $this->_isConfigManageStock, + $this->_configMinQty, + $select->assemble() + ); + + $adapter->update($this->getTable('cataloginventory/stock_item'), $values, $where); + } + + /** + * Update items low stock date basing on their quantities and config settings + * + */ + public function updateLowStockDate() + { + $this->_initConfig(); + + $adapter = $this->_getWriteAdapter(); + $condition = $adapter->quoteInto('(use_config_notify_stock_qty = 1 AND qty < ?)', + $this->_configNotifyStockQty) . ' OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty)'; + $currentDbTime = $adapter->quoteInto('?', $this->formatDate(true)); + $conditionalDate = $adapter->getCheckSql($condition, $currentDbTime, 'NULL'); + + $value = array( + 'low_stock_date' => new Zend_Db_Expr($conditionalDate), + ); + + $select = $adapter->select() + ->from($this->getTable('catalog/product'), 'entity_id') + ->where('type_id IN(?)', $this->_configTypeIds); + + $where = sprintf('stock_id = %1$d' + . ' AND is_in_stock = 0' + . ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' + . ' AND product_id IN (%3$s)', + $this->_stock->getId(), + $this->_isConfigManageStock, + $select->assemble() + ); + + $adapter->update($this->getTable('cataloginventory/stock_item'), $value, $where); + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item.php new file mode 100755 index 0000000000..cf921a45a4 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item.php @@ -0,0 +1,129 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Stock_Item extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and initialize connection + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock_item', 'item_id'); + } + + /** + * Loading stock item data by product + * + * @param Mage_CatalogInventory_Model_Stock_Item $item + * @param int $productId + * @return Mage_CatalogInventory_Model_Resource_Stock_Item + */ + public function loadByProductId(Mage_CatalogInventory_Model_Stock_Item $item, $productId) + { + $select = $this->_getLoadSelect('product_id', $productId, $item) + ->where('stock_id = :stock_id'); + $data = $this->_getReadAdapter()->fetchRow($select, array(':stock_id' => $item->getStockId())); + if ($data) { + $item->setData($data); + } + $this->_afterLoad($item); + return $this; + } + + /** + * Retrieve select object and join it to product entity table to get type ids + * + * @param string $field + * @param mixed $value + * @param Mage_CatalogInventory_Model_Stock_Item $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object) + ->join(array('p' => $this->getTable('catalog/product')), + 'product_id=p.entity_id', + array('type_id') + ); + return $select; + } + + /** + * Add join for catalog in stock field to product collection + * + * @param Mage_Catalog_Model_Resource_Product_Collection $productCollection + * @return Mage_CatalogInventory_Model_Resource_Stock_Item + */ + public function addCatalogInventoryToProductCollection($productCollection) + { + $adapter = $this->_getReadAdapter(); + $isManageStock = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); + $stockExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 1', $isManageStock, 'cisi.manage_stock'); + $stockExpr = $adapter->getCheckSql("({$stockExpr} = 1)", 'cisi.is_in_stock', '1'); + + $productCollection->joinTable( + array('cisi' => 'cataloginventory/stock_item'), + 'product_id=entity_id', + array( + 'is_saleable' => new Zend_Db_Expr($stockExpr), + 'inventory_in_stock' => 'is_in_stock' + ), + null, + 'left' + ); + return $this; + } + + /** + * Use qty correction for qty column update + * + * @param Mage_Core_Model_Abstract $object + * @param string $table + * @return array + */ + protected function _prepareDataForTable(Varien_Object $object, $table) + { + $data = parent::_prepareDataForTable($object, $table); + if (!$object->isObjectNew() && $object->getQtyCorrection()) { + $qty = abs($object->getQtyCorrection()); + if ($object->getQtyCorrection() < 0) { + $data['qty'] = new Zend_Db_Expr('qty-' . $qty); + } else { + $data['qty'] = new Zend_Db_Expr('qty+' . $object->getQtyCorrection()); + } + } + return $data; + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item/Collection.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item/Collection.php new file mode 100755 index 0000000000..b847904a7f --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Item/Collection.php @@ -0,0 +1,163 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Stock_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock_item'); + } + + /** + * Add stock filter to collection + * + * @param mixed $stock + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + public function addStockFilter($stock) + { + if ($stock instanceof Mage_CatalogInventory_Model_Stock) { + $this->addFieldToFilter('main_table.stock_id', $stock->getId()); + } else { + $this->addFieldToFilter('main_table.stock_id', $stock); + } + return $this; + } + + /** + * Add product filter to collection + * + * @param array $products + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + public function addProductsFilter($products) + { + $productIds = array(); + foreach ($products as $product) { + if ($product instanceof Mage_Catalog_Model_Product) { + $productIds[] = $product->getId(); + } else { + $productIds[] = $product; + } + } + if (empty($productIds)) { + $productIds[] = false; + $this->_setIsLoaded(true); + } + $this->addFieldToFilter('main_table.product_id', array('in' => $productIds)); + return $this; + } + + /** + * Join Stock Status to collection + * + * @param int $storeId + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + public function joinStockStatus($storeId = null) + { + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); + $this->getSelect()->joinLeft( + array('status_table' => $this->getTable('cataloginventory/stock_status')), + 'main_table.product_id=status_table.product_id' + . ' AND main_table.stock_id=status_table.stock_id' + . $this->getConnection()->quoteInto(' AND status_table.website_id=?', $websiteId), + array('stock_status') + ); + + return $this; + } + + /** + * Add Managed Stock products filter to collection + * + * @param boolean $isStockManagedInConfig + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + public function addManagedFilter($isStockManagedInConfig) + { + if ($isStockManagedInConfig) { + $this->getSelect()->where('(manage_stock = 1 OR use_config_manage_stock = 1)'); + } else { + $this->addFieldToFilter('manage_stock', 1); + } + + return $this; + } + + /** + * Add filter by quantity to collection + * + * @param string $comparsionMethod + * @param float $qty + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + public function addQtyFilter($comparsionMethod, $qty) + { + $methods = array( + '<' => 'lt', + '>' => 'gt', + '=' => 'eq', + '<=' => 'lteq', + '>=' => 'gteq', + '<>' => 'neq' + ); + if (!isset($methods[$comparsionMethod])) { + Mage::throwException( + Mage::helper('cataloginventory')->__('%s is not a correct comparsion method.', $comparsionMethod) + ); + } + + return $this->addFieldToFilter('main_table.qty', array($methods[$comparsionMethod] => $qty)); + } + + /** + * Initialize select object + * + * @return Mage_CatalogInventory_Model_Resource_Stock_Item_Collection + */ + protected function _initSelect() + { + return parent::_initSelect()->getSelect() + ->join( + array('cp_table' => $this->getTable('catalog/product')), + 'main_table.product_id = cp_table.entity_id', + array('type_id') + ); + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Status.php b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Status.php new file mode 100755 index 0000000000..a750e0a3fe --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/Model/Resource/Stock/Status.php @@ -0,0 +1,269 @@ + + */ +class Mage_CatalogInventory_Model_Resource_Stock_Status extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource model initialization + * + */ + protected function _construct() + { + $this->_init('cataloginventory/stock_status', 'product_id'); + } + + /** + * Save Product Status per website + * + * @param Mage_CatalogInventory_Model_Stock_Status $object + * @param int $productId + * @param int $status + * @param float $qty + * @param int $stockId + * @param int|null $websiteId + * @return Mage_CatalogInventory_Model_Resource_Stock_Status + */ + public function saveProductStatus(Mage_CatalogInventory_Model_Stock_Status $object, $productId, $status, $qty = 0, + $stockId = 1, $websiteId = null) + { + $websites = array_keys($object->getWebsites($websiteId)); + $adapter = $this->_getWriteAdapter(); + foreach ($websites as $websiteId) { + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('product_id = :product_id') + ->where('website_id = :website_id') + ->where('stock_id = :stock_id'); + $bind = array( + ':product_id' => $productId, + ':website_id' => $websiteId, + ':stock_id' => $stockId + ); + if ($row = $adapter->fetchRow($select, $bind)) { + $bind = array( + 'qty' => $qty, + 'stock_status' => $status + ); + $where = array( + $adapter->quoteInto('product_id=?', (int)$row['product_id']), + $adapter->quoteInto('website_id=?', (int)$row['website_id']), + $adapter->quoteInto('stock_id=?', (int)$row['stock_id']), + ); + $adapter->update($this->getMainTable(), $bind, $where); + } else { + $bind = array( + 'product_id' => $productId, + 'website_id' => $websiteId, + 'stock_id' => $stockId, + 'qty' => $qty, + 'stock_status' => $status + ); + $adapter->insert($this->getMainTable(), $bind); + } + } + + return $this; + } + + /** + * Retrieve product status + * Return array as key product id, value - stock status + * + * @param int|array $productIds + * @param int $websiteId + * @param int $stockId + * @return array + */ + public function getProductStatus($productIds, $websiteId, $stockId = 1) + { + if (!is_array($productIds)) { + $productIds = array($productIds); + } + + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('product_id', 'stock_status')) + ->where('product_id IN(?)', $productIds) + ->where('stock_id=?', (int)$stockId) + ->where('website_id=?', (int)$websiteId); + return $this->_getReadAdapter()->fetchPairs($select); + } + + /** + * Retrieve product(s) data array + * + * @param int|array $productIds + * @param int $websiteId + * @param int $stockId + * @return array + */ + public function getProductData($productIds, $websiteId, $stockId = 1) + { + if (!is_array($productIds)) { + $productIds = array($productIds); + } + + $result = array(); + + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where('product_id IN(?)', $productIds) + ->where('stock_id=?', (int)$stockId) + ->where('website_id=?', (int)$websiteId); + $result = $this->_getReadAdapter()->fetchAssoc($select); + return $result; + } + + /** + * Retrieve websites and default stores + * Return array as key website_id, value store_id + * + * @return array + */ + public function getWebsiteStores() + { + $select = Mage::getModel('core/website')->getDefaultStoresSelect(false); + return $this->_getReadAdapter()->fetchPairs($select); + } + + /** + * Retrieve Product Type + * + * @param array|int $productIds + * @return array + */ + public function getProductsType($productIds) + { + if (!is_array($productIds)) { + $productIds = array($productIds); + } + + $select = $this->_getReadAdapter()->select() + ->from( + array('e' => $this->getTable('catalog/product')), + array('entity_id', 'type_id') + ) + ->where('entity_id IN(?)', $productIds); + return $this->_getReadAdapter()->fetchPairs($select); + } + + /** + * Retrieve Product part Collection array + * Return array as key product id, value product type + * + * @param int $lastEntityId + * @param int $limit + * @return array + */ + public function getProductCollection($lastEntityId = 0, $limit = 1000) + { + $select = $this->_getReadAdapter()->select() + ->from( + array('e' => $this->getTable('catalog/product')), + array('entity_id', 'type_id') + ) + ->order('entity_id ASC') + ->where('entity_id > :entity_id') + ->limit($limit); + return $this->_getReadAdapter()->fetchPairs($select, array(':entity_id' => $lastEntityId)); + } + + /** + * Add stock status to prepare index select + * + * @param Varien_Db_Select $select + * @param Mage_Core_Model_Website $website + * @return Mage_CatalogInventory_Model_Resource_Stock_Status + */ + public function addStockStatusToSelect(Varien_Db_Select $select, Mage_Core_Model_Website $website) + { + $websiteId = $website->getId(); + $select->joinLeft( + array('stock_status' => $this->getMainTable()), + 'e.entity_id = stock_status.product_id AND stock_status.website_id='.$websiteId, + array('salable' => 'stock_status.stock_status') + ); + + return $this; + } + + /** + * Add stock status limitation to catalog product price index select object + * + * @param Varien_Db_Select $select + * @param string|Zend_Db_Expr $entityField + * @param string|Zend_Db_Expr $websiteField + * @return Mage_CatalogInventory_Model_Resource_Stock_Status + */ + public function prepareCatalogProductIndexSelect(Varien_Db_Select $select, $entityField, $websiteField) + { + $select->join( + array('ciss' => $this->getMainTable()), + "ciss.product_id = {$entityField} AND ciss.website_id = {$websiteField}", + array() + ); + $select->where('ciss.stock_status = ?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK); + + return $this; + } + + /** + * Add only is in stock products filter to product collection + * + * @param Mage_Catalog_Model_Resource_Product_Collection $collection + * @return Mage_CatalogInventory_Model_Resource_Stock_Status + */ + public function addIsInStockFilterToCollection($collection) + { + $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId(); + $joinCondition = $this->_getReadAdapter() + ->quoteInto('e.entity_id = stock_status_index.product_id' + . ' AND stock_status_index.website_id = ?', $websiteId + ); + + $joinCondition .= $this->_getReadAdapter()->quoteInto( + ' AND stock_status_index.stock_id = ?', + Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID + ); + + $collection->getSelect() + ->join( + array('stock_status_index' => $this->getMainTable()), + $joinCondition, + array() + ) + ->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK); + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogInventory/Model/Source/Backorders.php b/app/code/core/Mage/CatalogInventory/Model/Source/Backorders.php index b2277d800d..3d346bfbcc 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Source/Backorders.php +++ b/app/code/core/Mage/CatalogInventory/Model/Source/Backorders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/Source/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Source/Stock.php index ab3eb115d2..6390f275dc 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Source/Stock.php +++ b/app/code/core/Mage/CatalogInventory/Model/Source/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock.php b/app/code/core/Mage/CatalogInventory/Model/Stock.php index 2e2d2b4bfa..e4d81599b8 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock.php @@ -20,13 +20,20 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Stock model * + * @method Mage_CatalogInventory_Model_Resource_Stock _getResource() + * @method Mage_CatalogInventory_Model_Resource_Stock getResource() + * @method string getStockName() + * @method Mage_CatalogInventory_Model_Stock setStockName(string $value) + * + * @category Mage + * @package Mage_CatalogInventory * @author Magento Core Team */ class Mage_CatalogInventory_Model_Stock extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php index be5330b331..3e10f88445 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,47 @@ /** * Catalog Inventory Stock Model * - * @category Mage - * @package Mage_CatalogInventory - * @author Magento Core Team + * @method Mage_CatalogInventory_Model_Resource_Stock_Item _getResource() + * @method Mage_CatalogInventory_Model_Resource_Stock_Item getResource() + * @method Mage_CatalogInventory_Model_Stock_Item setProductId(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setStockId(int $value) + * @method float getQty() + * @method Mage_CatalogInventory_Model_Stock_Item setQty(float $value) + * @method Mage_CatalogInventory_Model_Stock_Item setMinQty(float $value) + * @method int getUseConfigMinQty() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigMinQty(int $value) + * @method int getIsQtyDecimal() + * @method Mage_CatalogInventory_Model_Stock_Item setIsQtyDecimal(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setBackorders(int $value) + * @method int getUseConfigBackorders() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigBackorders(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setMinSaleQty(float $value) + * @method int getUseConfigMinSaleQty() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigMinSaleQty(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setMaxSaleQty(float $value) + * @method int getUseConfigMaxSaleQty() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigMaxSaleQty(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setIsInStock(int $value) + * @method string getLowStockDate() + * @method Mage_CatalogInventory_Model_Stock_Item setLowStockDate(string $value) + * @method Mage_CatalogInventory_Model_Stock_Item setNotifyStockQty(float $value) + * @method int getUseConfigNotifyStockQty() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigNotifyStockQty(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setManageStock(int $value) + * @method int getUseConfigManageStock() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigManageStock(int $value) + * @method int getStockStatusChangedAutomatically() + * @method Mage_CatalogInventory_Model_Stock_Item setStockStatusChangedAutomatically(int $value) + * @method int getUseConfigQtyIncrements() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigQtyIncrements(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setQtyIncrements(float $value) + * @method int getUseConfigEnableQtyIncrements() + * @method Mage_CatalogInventory_Model_Stock_Item setUseConfigEnableQtyIncrements(int $value) + * @method Mage_CatalogInventory_Model_Stock_Item setEnableQtyIncrements(int $value) + * + * @category Mage + * @package Mage_CatalogInventory + * @author Magento Core Team */ class Mage_CatalogInventory_Model_Stock_Item extends Mage_Core_Model_Abstract { @@ -99,6 +137,20 @@ protected function _construct() $this->_init('cataloginventory/stock_item'); } + /** + * Init mapping array of short fields to + * its full names + * + * @resturn Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = array( + 'stock_status_changed_automatically' => 'stock_status_changed_auto', + 'use_config_enable_qty_increments' => 'use_config_enable_qty_inc' + ); + } + /** * Retrieve stock identifier * @@ -396,15 +448,6 @@ public function checkQty($qty) case Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY: break; default: - /*if ($this->getProduct()) { - Mage::throwException( - Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProduct()->getName()) - ); - } - else { - Mage::throwException(Mage::helper('cataloginventory')->__('The requested quantity is not available.')); - }*/ - return false; break; } @@ -461,8 +504,11 @@ public function suggestQty($qty) /** * Checking quote item quantity * + * Second parameter of this method specifies quantity of this product in whole shopping cart + * which should be checked for stock availability + * * @param mixed $qty quantity of this item (item qty x parent item qty) - * @param mixed $summaryQty quantity of this product in whole shopping cart which should be checked for stock availability + * @param mixed $summaryQty quantity of this product * @param mixed $origQty original qty of item (not multiplied on parent item qty) * @return Varien_Object */ @@ -471,6 +517,9 @@ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) $result = new Varien_Object(); $result->setHasError(false); + /** @var $_helper Mage_CatalogInventory_Helper_Data */ + $_helper = Mage::helper('cataloginventory'); + if (!is_numeric($qty)) { $qty = Mage::app()->getLocale()->getNumber($qty); } @@ -498,16 +547,20 @@ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) if ($this->getMinSaleQty() && ($qty) < $this->getMinSaleQty()) { $result->setHasError(true) - ->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1)) - ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.')) + ->setMessage( + $_helper->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1) + ) + ->setQuoteMessage($_helper->__('Some of the products cannot be ordered in requested quantity.')) ->setQuoteMessageIndex('qty'); return $result; } if ($this->getMaxSaleQty() && ($qty) > $this->getMaxSaleQty()) { $result->setHasError(true) - ->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1)) - ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.')) + ->setMessage( + $_helper->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1) + ) + ->setQuoteMessage($_helper->__('Some of the products cannot be ordered in requested quantity.')) ->setQuoteMessageIndex('qty'); return $result; } @@ -518,8 +571,8 @@ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) if (!$this->getIsInStock()) { $result->setHasError(true) - ->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.')) - ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock')) + ->setMessage($_helper->__('This product is currently out of stock.')) + ->setQuoteMessage($_helper->__('Some of the products are currently out of stock')) ->setQuoteMessageIndex('stock'); $result->setItemUseOldQty(true); return $result; @@ -532,14 +585,13 @@ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) } if (!$this->checkQty($summaryQty)) { - $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()); + $message = $_helper->__('The requested quantity for "%s" is not available.', $this->getProductName()); $result->setHasError(true) ->setMessage($message) ->setQuoteMessage($message) ->setQuoteMessageIndex('qty'); return $result; - } - else { + } else { if (($this->getQty() - $summaryQty) < 0) { if ($this->getProductName()) { if ($this->getIsChildItem()) { @@ -562,10 +614,18 @@ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) { if (!$this->getIsChildItem()) { - $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', ($backorderQty * 1))); + $result->setMessage( + $_helper->__('This product is not available in the requested quantity. %s of the items will be backordered.', ($backorderQty * 1)) + ); } else { - $result->setMessage(Mage::helper('cataloginventory')->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), ($backorderQty * 1))); + $result->setMessage( + $_helper->__('"%s" is not available in the requested quantity. %s of the items will be backordered.', $this->getProductName(), ($backorderQty * 1)) + ); } + } elseif (Mage::app()->getStore()->isAdmin()) { + $result->setMessage( + $_helper->__('The requested quantity for "%s" is not available.', $this->getProductName()) + ); } } } @@ -591,12 +651,18 @@ public function checkQtyIncrements($qty) $qtyIncrements = $this->getQtyIncrements(); if ($qtyIncrements && ($qty % $qtyIncrements != 0)) { $result->setHasError(true) - ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity.')) + ->setQuoteMessage( + Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity.') + ) ->setQuoteMessageIndex('qty'); if ($this->getIsChildItem()) { - $result->setMessage(Mage::helper('cataloginventory')->__('%s is available for purchase in increments of %s only.', $this->getProductName(), $qtyIncrements * 1)); + $result->setMessage( + Mage::helper('cataloginventory')->__('%s is available for purchase in increments of %s only.',$this->getProductName(), $qtyIncrements * 1) + ); } else { - $result->setMessage(Mage::helper('cataloginventory')->__('This product is available for purchase in increments of %s only.', $qtyIncrements * 1)); + $result->setMessage( + Mage::helper('cataloginventory')->__('This product is available for purchase in increments of %s only.', $qtyIncrements * 1) + ); } } @@ -624,8 +690,9 @@ public function addCatalogInventoryToProductCollection($productCollection) * @param string $errorIndex * @return Mage_CatalogInventory_Model_Stock_Item */ - protected function _addQuoteItemError(Mage_Sales_Model_Quote_Item $item, $itemError, $quoteError, $errorIndex='error') - { + protected function _addQuoteItemError(Mage_Sales_Model_Quote_Item $item, $itemError, + $quoteError, $errorIndex='error' + ) { $item->setHasError(true); $item->setMessage($itemError); $item->setQuoteMessage($quoteError); @@ -781,7 +848,9 @@ public function getStockQty() } } $stockQty = (float) $stockQty; - if ($stockQty < 0 || !$this->getManageStock() || !$this->getIsInStock() || ($product && !$product->isSaleable())) { + if ($stockQty < 0 || !$this->getManageStock() + || !$this->getIsInStock() || ($product && !$product->isSaleable()) + ) { $stockQty = 0; } $this->setStockQty($stockQty); diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api.php index 44f93ce769..40406fee0c 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api/V2.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api/V2.php index 652d5cc5b6..2ad5812547 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api/V2.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Status.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Status.php index ccc3941f16..a73b6ed074 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Status.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Status.php @@ -20,13 +20,26 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * CatalogInventory Stock Status per website Model * + * @method Mage_CatalogInventory_Model_Resource_Stock_Status _getResource() + * @method Mage_CatalogInventory_Model_Resource_Stock_Status getResource() + * @method int getProductId() + * @method Mage_CatalogInventory_Model_Stock_Status setProductId(int $value) + * @method int getWebsiteId() + * @method Mage_CatalogInventory_Model_Stock_Status setWebsiteId(int $value) + * @method int getStockId() + * @method Mage_CatalogInventory_Model_Stock_Status setStockId(int $value) + * @method float getQty() + * @method Mage_CatalogInventory_Model_Stock_Status setQty(float $value) + * @method int getStockStatus() + * @method Mage_CatalogInventory_Model_Stock_Status setStockStatus(int $value) + * * @category Mage * @package Mage_CatalogInventory * @author Magento Core Team @@ -409,16 +422,6 @@ public function getProductData($productIds, $websiteId, $stockId = 1) return $this->getResource()->getProductData($productIds, $websiteId, $stockId); } - /** - * Retrieve resource model wraper - * - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Status - */ - public function getResource() - { - return parent::getResource(); - } - /** * Retrieve Product Type * diff --git a/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Minsaleqty.php b/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Minsaleqty.php index 75b8b05beb..992233be5c 100644 --- a/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Minsaleqty.php +++ b/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Minsaleqty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Qtyincrements.php b/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Qtyincrements.php index d72ab6f307..e4609848a7 100644 --- a/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Qtyincrements.php +++ b/app/code/core/Mage/CatalogInventory/Model/System/Config/Backend/Qtyincrements.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/etc/adminhtml.xml b/app/code/core/Mage/CatalogInventory/etc/adminhtml.xml index 77725519af..7002bd3988 100644 --- a/app/code/core/Mage/CatalogInventory/etc/adminhtml.xml +++ b/app/code/core/Mage/CatalogInventory/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogInventory/etc/api.xml b/app/code/core/Mage/CatalogInventory/etc/api.xml index 527f54b046..5d681ce49a 100644 --- a/app/code/core/Mage/CatalogInventory/etc/api.xml +++ b/app/code/core/Mage/CatalogInventory/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogInventory/etc/config.xml b/app/code/core/Mage/CatalogInventory/etc/config.xml index 0793b58ffa..60cd6ca9cf 100644 --- a/app/code/core/Mage/CatalogInventory/etc/config.xml +++ b/app/code/core/Mage/CatalogInventory/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.8 + 1.6.0.0 Mage_CatalogInventory_Model - cataloginventory_mysql4 + cataloginventory_resource - - Mage_CatalogInventory_Model_Mysql4 + + Mage_CatalogInventory_Model_Resource + cataloginventory_mysql4 cataloginventory_stock
@@ -56,7 +57,7 @@ cataloginventory_stock_status_tmp
-
+
@@ -72,9 +73,10 @@
- Mage_CatalogInventory_Block + + Mage_CatalogInventory_Block + - @@ -116,14 +118,6 @@ - @@ -204,14 +198,6 @@ - @@ -221,7 +207,6 @@ - @@ -240,7 +225,6 @@ - @@ -248,18 +232,17 @@ - + - +
- @@ -278,7 +261,6 @@ - @@ -290,7 +272,6 @@ - diff --git a/app/code/core/Mage/CatalogInventory/etc/system.xml b/app/code/core/Mage/CatalogInventory/etc/system.xml index 959a29d761..04f344f47c 100644 --- a/app/code/core/Mage/CatalogInventory/etc/system.xml +++ b/app/code/core/Mage/CatalogInventory/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/install-1.6.0.0.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..00aafdbc5f --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/install-1.6.0.0.php @@ -0,0 +1,321 @@ +startSetup(); + +/** + * Create table 'cataloginventory_stock' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cataloginventory/stock')) + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Stock Id') + ->addColumn('stock_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Stock Name') + ->setComment('Cataloginventory Stock'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cataloginventory/stock_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cataloginventory/stock_item')) + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Item Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Id') + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Stock Id') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('min_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Min Qty') + ->addColumn('use_config_min_qty', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Min Qty') + ->addColumn('is_qty_decimal', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Qty Decimal') + ->addColumn('backorders', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Backorders') + ->addColumn('use_config_backorders', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Backorders') + ->addColumn('min_sale_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '1.0000', + ), 'Min Sale Qty') + ->addColumn('use_config_min_sale_qty', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Min Sale Qty') + ->addColumn('max_sale_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Max Sale Qty') + ->addColumn('use_config_max_sale_qty', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Max Sale Qty') + ->addColumn('is_in_stock', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is In Stock') + ->addColumn('low_stock_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Low Stock Date') + ->addColumn('notify_stock_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Notify Stock Qty') + ->addColumn('use_config_notify_stock_qty', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Notify Stock Qty') + ->addColumn('manage_stock', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Manage Stock') + ->addColumn('use_config_manage_stock', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Manage Stock') + ->addColumn('stock_status_changed_auto', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Stock Status Changed Automatically') + ->addColumn('use_config_qty_increments', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Qty Increments') + ->addColumn('qty_increments', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty Increments') + ->addColumn('use_config_enable_qty_inc', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Use Config Enable Qty Increments') + ->addColumn('enable_qty_increments', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Enable Qty Increments') + ->addIndex($installer->getIdxName('cataloginventory/stock_item', array('product_id', 'stock_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('product_id', 'stock_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ) + ->addIndex($installer->getIdxName('cataloginventory/stock_item', array('product_id')), + array('product_id') + ) + ->addIndex($installer->getIdxName('cataloginventory/stock_item', array('stock_id')), + array('stock_id') + ) + ->addForeignKey($installer->getFkName('cataloginventory/stock_item', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName( + 'cataloginventory/stock_item', 'stock_id', 'cataloginventory/stock', 'stock_id' + ), + 'stock_id', $installer->getTable('cataloginventory/stock'), 'stock_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Cataloginventory Stock Item'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cataloginventory/stock_status' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cataloginventory/stock_status')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Stock Id') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('stock_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Stock Status') + ->addIndex($installer->getIdxName('cataloginventory/stock_status', array('stock_id')), + array('stock_id') + ) + ->addIndex($installer->getIdxName('cataloginventory/stock_status', array('website_id')), + array('website_id') + ) + ->addForeignKey( + $installer->getFkName( + 'cataloginventory/stock_status', 'stock_id', 'cataloginventory/stock', 'stock_id' + ), + 'stock_id', $installer->getTable('cataloginventory/stock'), 'stock_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey( + $installer->getFkName( + 'cataloginventory/stock_status', 'product_id', 'catalog/product', 'entity_id' + ), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->addForeignKey($installer->getFkName('cataloginventory/stock_status', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Cataloginventory Stock Status'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cataloginventory/stock_status_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cataloginventory/stock_status_indexer_idx')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Stock Id') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('stock_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Stock Status') + ->addIndex($installer->getIdxName('cataloginventory/stock_status_indexer_idx', array('stock_id')), + array('stock_id') + ) + ->addIndex($installer->getIdxName('cataloginventory/stock_status_indexer_idx', array('website_id')), + array('website_id') + ) + ->setComment('Cataloginventory Stock Status Indexer Idx'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cataloginventory/stock_status_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cataloginventory/stock_status_indexer_tmp')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('stock_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Stock Id') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('stock_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Stock Status') + ->addIndex($installer->getIdxName('cataloginventory/stock_status_indexer_tmp', array('stock_id')), + array('stock_id') + ) + ->addIndex($installer->getIdxName('cataloginventory/stock_status_indexer_tmp', array('website_id')), + array('website_id') + ) + ->setComment('Cataloginventory Stock Status Indexer Tmp'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); + +$installer->getConnection()->insertForce($installer->getTable('cataloginventory/stock'), array( + 'stock_id' => 1, + 'stock_name' => 'Default' +)); + diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-install-0.7.0.php index 04f9355259..0e9acabfc8 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.0-0.7.1.php index 06812be102..39b414048c 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.1-0.7.2.php index c5e7c0f501..84d45a486c 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.2-0.7.3.php index da95a5a4a9..1b26ffbe83 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.3-0.7.4.php index 2e9c02da41..9e9d48bc9e 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.4-0.7.5.php index 080be44c52..a798d1063a 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.5-0.7.6.php index b55f8c5426..efc703528b 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.6-0.7.7.php index 2df413ec94..2e265fe3af 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.7-0.7.8.php index 384d554e28..2bdd056c35 100644 --- a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogInventory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..fcfc80d456 --- /dev/null +++ b/app/code/core/Mage/CatalogInventory/sql/cataloginventory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,550 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('cataloginventory/stock_item'), + 'FK_CATALOGINVENTORY_STOCK_ITEM_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cataloginventory/stock_item'), + 'FK_CATALOGINVENTORY_STOCK_ITEM_STOCK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cataloginventory/stock_status'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cataloginventory/stock_status'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_STOCK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cataloginventory/stock_status'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_WEBSITE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_item'), + 'IDX_STOCK_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_item'), + 'FK_CATALOGINVENTORY_STOCK_ITEM_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_item'), + 'FK_CATALOGINVENTORY_STOCK_ITEM_STOCK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_status'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_STOCK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_status'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory_stock_status_idx'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_STOCK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_status_indexer_idx'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory_stock_status_tmp'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_STOCK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cataloginventory/stock_status_indexer_tmp'), + 'FK_CATALOGINVENTORY_STOCK_STATUS_WEBSITE' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('cataloginventory/stock') => array( + 'columns' => array( + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Stock Id' + ), + 'stock_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Stock Name' + ) + ), + 'comment' => 'Cataloginventory Stock' + ), + $installer->getTable('cataloginventory/stock_item') => array( + 'columns' => array( + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Item Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Id' + ), + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Stock Id' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'min_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Min Qty' + ), + 'use_config_min_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Min Qty' + ), + 'is_qty_decimal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Qty Decimal' + ), + 'backorders' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Backorders' + ), + 'use_config_backorders' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Backorders' + ), + 'min_sale_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '1.0000', + 'comment' => 'Min Sale Qty' + ), + 'use_config_min_sale_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Min Sale Qty' + ), + 'max_sale_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Max Sale Qty' + ), + 'use_config_max_sale_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Max Sale Qty' + ), + 'is_in_stock' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is In Stock' + ), + 'low_stock_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Low Stock Date' + ), + 'notify_stock_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Notify Stock Qty' + ), + 'use_config_notify_stock_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Notify Stock Qty' + ), + 'manage_stock' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Manage Stock' + ), + 'use_config_manage_stock' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Manage Stock' + ), + 'use_config_qty_increments' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Qty Increments' + ), + 'qty_increments' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty Increments' + ), + 'enable_qty_increments' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Enable Qty Increments' + ) + ), + 'comment' => 'Cataloginventory Stock Item' + ), + $installer->getTable('cataloginventory/stock_status') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Stock Id' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'stock_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Stock Status' + ) + ), + 'comment' => 'Cataloginventory Stock Status' + ), + $installer->getTable('cataloginventory/stock_status_indexer_idx') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Stock Id' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'stock_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Stock Status' + ) + ), + 'comment' => 'Cataloginventory Stock Status Indexer Idx' + ), + $installer->getTable('cataloginventory/stock_status_indexer_tmp') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Stock Id' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'stock_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Stock Status' + ) + ), + 'comment' => 'Cataloginventory Stock Status Indexer Tmp', + 'engine' => 'InnoDB' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('cataloginventory/stock_item'), + 'stock_status_changed_automatically', + 'stock_status_changed_auto', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Stock Status Changed Automatically' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('cataloginventory/stock_item'), + 'use_config_enable_qty_increments', + 'use_config_enable_qty_inc', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Use Config Enable Qty Increments' + ) +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_item'), + $installer->getIdxName( + 'cataloginventory/stock_item', + array('product_id', 'stock_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'stock_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_item'), + $installer->getIdxName('cataloginventory/stock_item', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_item'), + $installer->getIdxName('cataloginventory/stock_item', array('stock_id')), + array('stock_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status'), + $installer->getIdxName('cataloginventory/stock_status', array('stock_id')), + array('stock_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status'), + $installer->getIdxName('cataloginventory/stock_status', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status_indexer_idx'), + $installer->getIdxName('cataloginventory/stock_status_indexer_idx', array('stock_id')), + array('stock_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status_indexer_idx'), + $installer->getIdxName('cataloginventory/stock_status_indexer_idx', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status_indexer_tmp'), + $installer->getIdxName('cataloginventory/stock_status_indexer_tmp', array('stock_id')), + array('stock_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cataloginventory/stock_status_indexer_tmp'), + $installer->getIdxName('cataloginventory/stock_status_indexer_tmp', array('website_id')), + array('website_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('cataloginventory/stock_item', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('cataloginventory/stock_item'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cataloginventory/stock_item', 'stock_id', 'cataloginventory/stock', 'stock_id'), + $installer->getTable('cataloginventory/stock_item'), + 'stock_id', + $installer->getTable('cataloginventory/stock'), + 'stock_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cataloginventory/stock_status', 'stock_id', 'cataloginventory/stock', 'stock_id'), + $installer->getTable('cataloginventory/stock_status'), + 'stock_id', + $installer->getTable('cataloginventory/stock'), + 'stock_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cataloginventory/stock_status', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('cataloginventory/stock_status'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cataloginventory/stock_status', 'website_id', 'core/website', 'website_id'), + $installer->getTable('cataloginventory/stock_status'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogRule/Helper/Data.php b/app/code/core/Mage/CatalogRule/Helper/Data.php index d429e00429..0df625f894 100644 --- a/app/code/core/Mage/CatalogRule/Helper/Data.php +++ b/app/code/core/Mage/CatalogRule/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -45,7 +45,7 @@ public function calcPriceRule ($actionOperator, $ruleAmount, $price) $priceRule = $ruleAmount; break; case 'to_percent': - $priceRule= $price * $ruleAmount / 100; + $priceRule = $price * $ruleAmount / 100; break; case 'by_fixed': $priceRule = $price - $ruleAmount; diff --git a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule.php b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule.php index 882d301750..98d433ee24 100644 --- a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule.php @@ -20,769 +20,18 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog rules resource model + * + * @category Mage + * @package Mage_CatalogRule + * @author Magento Core Team */ -class Mage_CatalogRule_Model_Mysql4_Rule extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogRule_Model_Mysql4_Rule extends Mage_CatalogRule_Model_Resource_Rule { - const SECONDS_IN_DAY = 86400; - - /** - * Initialize main table and table id field - */ - protected function _construct() - { - $this->_init('catalogrule/rule', 'rule_id'); - } - - /** - * Prepare object data for saving - * - * @param Mage_Core_Model_Abstract $object - */ - public function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getFromDate()) { - $date = Mage::app()->getLocale()->date(); - $date->setHour(0) - ->setMinute(0) - ->setSecond(0); - $object->setFromDate($date); - } - if ($object->getFromDate() instanceof Zend_Date) { - $object->setFromDate($object->getFromDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } - - if (!$object->getToDate()) { - $object->setToDate(new Zend_Db_Expr('NULL')); - } - else { - if ($object->getToDate() instanceof Zend_Date) { - $object->setToDate($object->getToDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } - } - parent::_beforeSave($object); - } - - /** - * Update products which are matched for rule - * - * @param Mage_CatalogRule_Model_Rule $rule - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - public function updateRuleProductData(Mage_CatalogRule_Model_Rule $rule) - { - $ruleId = $rule->getId(); - $write = $this->_getWriteAdapter(); - $write->beginTransaction(); - - $write->delete($this->getTable('catalogrule/rule_product'), $write->quoteInto('rule_id=?', $ruleId)); - - if (!$rule->getIsActive()) { - $write->commit(); - return $this; - } - - $websiteIds = explode(',', $rule->getWebsiteIds()); - if (empty($websiteIds)) { - return $this; - } - Varien_Profiler::start('__MATCH_PRODUCTS__'); - $productIds = $rule->getMatchingProductIds(); - Varien_Profiler::stop('__MATCH_PRODUCTS__'); - $customerGroupIds = $rule->getCustomerGroupIds(); - - $fromTime = strtotime($rule->getFromDate()); - $toTime = strtotime($rule->getToDate()); - $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; - - $sortOrder = (int)$rule->getSortOrder(); - $actionOperator = $rule->getSimpleAction(); - $actionAmount = $rule->getDiscountAmount(); - $actionStop = $rule->getStopRulesProcessing(); - - $rows = array(); - $queryStart = 'INSERT INTO '.$this->getTable('catalogrule/rule_product').' ( - rule_id, from_time, to_time, website_id, customer_group_id, product_id, action_operator, - action_amount, action_stop, sort_order ) values '; - $queryEnd = ' ON DUPLICATE KEY UPDATE action_operator=VALUES(action_operator), - action_amount=VALUES(action_amount), action_stop=VALUES(action_stop)'; - try { - foreach ($productIds as $productId) { - foreach ($websiteIds as $websiteId) { - foreach ($customerGroupIds as $customerGroupId) { - $rows[] = "('" . implode("','", array( - $ruleId, - $fromTime, - $toTime, - $websiteId, - $customerGroupId, - $productId, - $actionOperator, - $actionAmount, - $actionStop, - $sortOrder))."')"; - /** - * Array with 1000 rows contain about 2M data - */ - if (sizeof($rows)==1000) { - $sql = $queryStart.join(',', $rows).$queryEnd; - $write->query($sql); - $rows = array(); - } - } - } - } - if (!empty($rows)) { - $sql = $queryStart.join(',', $rows).$queryEnd; - $write->query($sql); - } - - $write->commit(); - } catch (Exception $e) { - $write->rollback(); - throw $e; - } - - return $this; - } - - /** - * Get all product ids matched for rule - * - * @param int $ruleId - * @return array - */ - public function getRuleProductIds($ruleId) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getTable('catalogrule/rule_product'), 'product_id') - ->where('rule_id=?', $ruleId); - return $read->fetchCol($select); - } - - /** - * Remove catalog rules product prices for specified date range and product - * - * @param int|string $fromDate - * @param int|string $toDate - * @param int|null $productId - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - public function removeCatalogPricesForDateRange($fromDate, $toDate, $productId=null) - { - $write = $this->_getWriteAdapter(); - $conds = array(); - $cond = $write->quoteInto('rule_date between ?', $this->formatDate($fromDate)); - $cond = $write->quoteInto($cond.' and ?', $this->formatDate($toDate)); - $conds[] = $cond; - if (!is_null($productId)) { - $conds[] = $write->quoteInto('product_id=?', $productId); - } - - /** - * Add information about affected products - * It can be used in processes which related with product price (like catalog index) - */ - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable('catalogrule/rule_product_price'), 'product_id') - ->where(implode(' AND ', $conds)); - $insertQuery = 'REPLACE INTO ' . $this->getTable('catalogrule/affected_product') . ' (product_id)' . $select->__toString(); - $this->_getWriteAdapter()->query($insertQuery); - $write->delete($this->getTable('catalogrule/rule_product_price'), $conds); - return $this; - } - - /** - * Delete old price rules data - * - * @param int $maxDate - * @param mixed $productId - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - public function deleteOldData($date, $productId=null) - { - $write = $this->_getWriteAdapter(); - $conds = array(); - $conds[] = $write->quoteInto('rule_dateformatDate($date)); - if (!is_null($productId)) { - $conds[] = $write->quoteInto('product_id=?', $productId); - } - $write->delete($this->getTable('catalogrule/rule_product_price'), $conds); - return $this; - } - - /** - * Get rules data for all products in specified date range - * - * deprecated - * - * @param int|string $fromDate - * @param int|string $toDate - * @param int|null $productId - * @return false|array - */ - public function getRuleProductsForDateRange($fromDate, $toDate, $productId=null) - { - $read = $this->_getReadAdapter(); - - $select = $read->select() - ->from($this->getTable('catalogrule/rule_product')) - ->where($read->quoteInto('from_time=0 or from_time<=?', strtotime($toDate)) - ." or ".$read->quoteInto('to_time=0 or to_time>=?', strtotime($fromDate))) - ->order(array('website_id', 'customer_group_id', 'product_id', 'sort_order')); - // crucial for logic sort order: website_id, customer_group_id, product_id, sort_order - // had 'from_time', 'to_time' in the beginning before - if (!is_null($productId)) { - $select->where('product_id=?', $productId); - } - - if (!$ruleProducts = $read->fetchAll($select)) { - return false; - } - $productIds = array(); - foreach ($ruleProducts as $p) { - $productIds[] = $p['product_id']; - } - - $priceAttr = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'price'); - - $select = $read->select() - ->from($priceAttr->getBackend()->getTable(), array('entity_id', 'store_id', 'value')) - ->where('attribute_id=?', $priceAttr->getAttributeId()) - ->where('entity_id in (?)', $productIds) - ->order('store_id'); - - $prices = $read->fetchAll($select); - - /** - * Prepare price information per website - */ - $productPrices = array(); - foreach ($prices as $index => $priceData) { - $websiteId = Mage::app()->getStore($priceData['store_id'])->getWebsiteId(); - - if (!isset($productPrices[$priceData['entity_id']])) { - $productPrices[$priceData['entity_id']] = array( - 'default' => $priceData['value'], - 'websites' => array($websiteId=>$priceData['value']) - ); - } - else { - $productPrices[$priceData['entity_id']]['websites'][$websiteId] = $priceData['value']; - } - } - - foreach ($ruleProducts as &$p) { - if (isset($productPrices[$p['product_id']]['websites'][$p['website_id']])) { - $p['price'] = $productPrices[$p['product_id']]['websites'][$p['website_id']]; - } - elseif (isset($productPrices[$p['product_id']]['default'])) { - $p['price'] = $productPrices[$p['product_id']]['default']; - } - } - - return $ruleProducts; - } - - /** - * Get DB resource statment for processing query result - * - * @param int $fromDate - * @param int $toDate - * @param int|null $productId - * @param int|null $websiteId - * @return Zend_Db_Statement_Interface - */ - protected function _getRuleProductsStmt($fromDate, $toDate, $productId=null, $websiteId = null) - { - $read = $this->_getReadAdapter(); - /** - * Sort order is important - * It used for check stop price rule condition. - * website_id customer_group_id product_id sort_order - * 1 1 1 0 - * 1 1 1 1 - * 1 1 1 2 - * if row with sort order 1 will have stop flag we should exclude - * all next rows for same product id from price calculation - */ - $select = $read->select() - ->from(array('rp'=>$this->getTable('catalogrule/rule_product'))) - ->where($read->quoteInto('rp.from_time=0 or rp.from_time<=?', $toDate) - ." or ".$read->quoteInto('rp.to_time=0 or rp.to_time>=?', $fromDate)) - ->order(array('rp.website_id', 'rp.customer_group_id', 'rp.product_id', 'rp.sort_order', 'rp.rule_id')); - - if (!is_null($productId)) { - $select->where('rp.product_id=?', $productId); - } - - /** - * Join default price and websites prices to result - */ - $priceAttr = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'price'); - $priceTable = $priceAttr->getBackend()->getTable(); - $attributeId= $priceAttr->getId(); - - $joinCondition = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id='.$attributeId.') and %1$s.store_id=%2$s'; - - $select->join( - array('pp_default'=>$priceTable), - sprintf($joinCondition, 'pp_default', Mage_Core_Model_App::ADMIN_STORE_ID), - array('default_price'=>'pp_default.value') - ); - - if ($websiteId !== null) { - $website = Mage::app()->getWebsite($websiteId); - $defaultGroup = $website->getDefaultGroup(); - if ($defaultGroup instanceof Mage_Core_Model_Store_Group) { - $storeId = $defaultGroup->getDefaultStoreId(); - } else { - $storeId = Mage_Core_Model_App::ADMIN_STORE_ID; - } - - $select->joinInner( - array('product_website'=>$this->getTable('catalog/product_website')), - 'product_website.product_id=rp.product_id AND rp.website_id=product_website.website_id AND product_website.website_id='.$websiteId, - array() - ); - - $tableAlias = 'pp'.$websiteId; - $fieldAlias = 'website_'.$websiteId.'_price'; - $select->joinLeft( - array($tableAlias=>$priceTable), - sprintf($joinCondition, $tableAlias, $storeId), - array($fieldAlias=>$tableAlias.'.value') - ); - } else { - foreach (Mage::app()->getWebsites() as $website) { - $websiteId = $website->getId(); - $defaultGroup = $website->getDefaultGroup(); - if ($defaultGroup instanceof Mage_Core_Model_Store_Group) { - $storeId = $defaultGroup->getDefaultStoreId(); - } else { - $storeId = Mage_Core_Model_App::ADMIN_STORE_ID; - } - - $storeId = $defaultGroup->getDefaultStoreId(); - $tableAlias = 'pp'.$websiteId; - $fieldAlias = 'website_'.$websiteId.'_price'; - $select->joinLeft( - array($tableAlias=>$priceTable), - sprintf($joinCondition, $tableAlias, $storeId), - array($fieldAlias=>$tableAlias.'.value') - ); - } - } - return $read->query($select); - } - - /** - * Generate catalog price rules prices for specified date range - * If from date is not defined - will be used previous day by UTC - * If to date is not defined - will be used next day by UTC - * - * @param int|string|null $fromDate - * @param int|string|null $toDate - * @param int $productId - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - public function applyAllRulesForDateRange($fromDate=null, $toDate=null, $productId=null) - { - $write = $this->_getWriteAdapter(); - $write->beginTransaction(); - - Mage::dispatchEvent('catalogrule_before_apply', array('resource'=>$this)); - - $clearOldData = false; - if ($fromDate === null) { - $fromDate = mktime(0,0,0,date('m'),date('d')-1); - /** - * If fromDate not specified we can delete all data oldest than 1 day - * We have run it for clear table in case when cron was not installed - * and old data exist in table - */ - $clearOldData = true; - } - if (is_string($fromDate)) { - $fromDate = strtotime($fromDate); - } - if ($toDate === null) { - $toDate = mktime(0,0,0,date('m'),date('d')+1); - } - if (is_string($toDate)) { - $toDate = strtotime($toDate); - } - - $product = null; - if ($productId instanceof Mage_Catalog_Model_Product) { - $product = $productId; - $productId = $productId->getId(); - } - - $this->removeCatalogPricesForDateRange($fromDate, $toDate, $productId); - if ($clearOldData) { - $this->deleteOldData($fromDate, $productId); - } - - try { - /** - * Update products rules prices per each website separatly - * because of max join limit in mysql - */ - foreach (Mage::app()->getWebsites(false) as $website) { - $productsStmt = $this->_getRuleProductsStmt( - $fromDate, - $toDate, - $productId, - $website->getId() - ); - - $dayPrices = array(); - $stopFlags = array(); - $prevKey = null; - - while ($ruleData = $productsStmt->fetch()) { - $ruleProductId = $ruleData['product_id']; - $productKey= $ruleProductId . '_' - . $ruleData['website_id'] . '_' - . $ruleData['customer_group_id']; - - if ($prevKey && ($prevKey != $productKey)) { - $stopFlags = array(); - } - - /** - * Build prices for each day - */ - for ($time=$fromDate; $time<=$toDate; $time+=self::SECONDS_IN_DAY) { - if (($ruleData['from_time']==0 || $time >= $ruleData['from_time']) - && ($ruleData['to_time']==0 || $time <=$ruleData['to_time'])) { - - $priceKey = $time . '_' . $productKey; - - if (isset($stopFlags[$priceKey])) { - continue; - } - - if (!isset($dayPrices[$priceKey])) { - $dayPrices[$priceKey] = array( - 'rule_date' => $time, - 'website_id' => $ruleData['website_id'], - 'customer_group_id' => $ruleData['customer_group_id'], - 'product_id' => $ruleProductId, - 'rule_price' => $this->_calcRuleProductPrice($ruleData), - 'latest_start_date' => $ruleData['from_time'], - 'earliest_end_date' => $ruleData['to_time'], - ); - } - else { - $dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice( - $ruleData, - $dayPrices[$priceKey] - ); - $dayPrices[$priceKey]['latest_start_date'] = max( - $dayPrices[$priceKey]['latest_start_date'], - $ruleData['from_time'] - ); - $dayPrices[$priceKey]['earliest_end_date'] = min( - $dayPrices[$priceKey]['earliest_end_date'], - $ruleData['to_time'] - ); - } - - if ($ruleData['action_stop']) { - $stopFlags[$priceKey] = true; - } - } - } - - $prevKey = $productKey; - if (count($dayPrices)>1000) { - $this->_saveRuleProductPrices($dayPrices); - $dayPrices = array(); - } - } - $this->_saveRuleProductPrices($dayPrices); - } - $this->_saveRuleProductPrices($dayPrices); - - $write->delete($this->getTable('catalogrule/rule_group_website'), array()); - - $timestamp = Mage::getModel('core/date')->gmtTimestamp(); - - $select = $write->select() - ->distinct(true) - ->from($this->getTable('catalogrule/rule_product'), array('rule_id', 'customer_group_id', 'website_id')) - ->where("{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)"); - $query = $select->insertFromSelect($this->getTable('catalogrule/rule_group_website')); - $write->query($query); - - $write->commit(); - } catch (Exception $e) { - $write->rollback(); - throw $e; - } - - $productCondition = Mage::getModel('catalog/product_condition') - ->setTable($this->getTable('catalogrule/affected_product')) - ->setPkFieldName('product_id'); - Mage::dispatchEvent('catalogrule_after_apply', array( - 'product'=>$product, - 'product_condition' => $productCondition - )); - $write->delete($this->getTable('catalogrule/affected_product')); - - return $this; - } - - /** - * Calculate product price based on price rule data and previous information - * - * @param array $ruleData - * @param null|array $productData - * @return float - */ - protected function _calcRuleProductPrice($ruleData, $productData=null) - { - if ($productData !== null && isset($productData['rule_price'])) { - $productPrice = $productData['rule_price']; - } - else { - $websiteId = $ruleData['website_id']; - if (isset($ruleData['website_'.$websiteId.'_price'])) { - $productPrice = $ruleData['website_'.$websiteId.'_price']; - } - else { - $productPrice = $ruleData['default_price']; - } - } - - $productPrice = Mage::helper('catalogrule')->calcPriceRule( - $ruleData['action_operator'], - $ruleData['action_amount'], - $productPrice); - - return Mage::app()->getStore()->roundPrice($productPrice); - } - - /** - * Save rule prices for products to DB - * - * @param array $arrData - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - protected function _saveRuleProductPrices($arrData) - { - if (empty($arrData)) { - return $this; - } - $header = 'replace into '.$this->getTable('catalogrule/rule_product_price').' ( - rule_date, website_id, customer_group_id, product_id, rule_price, latest_start_date, earliest_end_date - ) values '; - $rows = array(); - $productIds = array(); - foreach ($arrData as $data) { - $productIds[$data['product_id']] = true; - $data['rule_date'] = $this->formatDate($data['rule_date'], false); - $data['latest_start_date'] = $this->formatDate($data['latest_start_date'], false); - $data['earliest_end_date'] = $this->formatDate($data['earliest_end_date'], false); - $rows[] = '(' . $this->_getWriteAdapter()->quote($data) . ')'; - } - $query = $header.join(',', $rows); - $insertQuery = 'REPLACE INTO ' . $this->getTable('catalogrule/affected_product') . ' (product_id) VALUES ' . - '(' . join('),(', array_keys($productIds)) . ')'; - $this->_getWriteAdapter()->query($insertQuery); - $this->_getWriteAdapter()->query($query); - return $this; - } - - /** - * Get catalog rules product price for specific date, website and - * customer group - * - * @param int|string $date - * @param int $wId - * @param int $gId - * @param int $pId - * @return float | false - */ - public function getRulePrice($date, $wId, $gId, $pId) - { - $data = $this->getRulePrices($date, $wId, $gId, array($pId)); - if (isset($data[$pId])) { - return $data[$pId]; - } - - return false; - } - - /** - * Return product prices by catalog rule for specific date, website and customer group - * Return product - price pairs - * - * @param int|string $date - * @param int $websiteId - * @param int $customerGroupId - * @param array $productIds - * @return array - */ - public function getRulePrices($date, $websiteId, $customerGroupId, $productIds) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from($this->getTable('catalogrule/rule_product_price'), array('product_id', 'rule_price')) - ->where('rule_date = ?', $this->formatDate($date, false)) - ->where('website_id = ?', $websiteId) - ->where('customer_group_id = ?', $customerGroupId) - ->where('product_id IN(?)', $productIds); - return $adapter->fetchPairs($select); - } - - /** - * Get active rule data based on few filters - * - * @param int|string $date - * @param int $websiteId - * @param int $customerGroupId - * @param int $productId - * @return array - */ - public function getRulesFromProduct($date, $websiteId, $customerGroupId, $productId) - { - $adapter = $this->_getReadAdapter(); - $dateQuoted = $adapter->quote($this->formatDate($date, false)); - $joinCondsQuoted[] = 'main_table.rule_id = rp.rule_id'; - $joinCondsQuoted[] = $adapter->quoteInto('rp.website_id = ?', $websiteId); - $joinCondsQuoted[] = $adapter->quoteInto('rp.customer_group_id = ?', $customerGroupId); - $joinCondsQuoted[] = $adapter->quoteInto('rp.product_id = ?', $productId); - $select = $adapter->select() - ->distinct() - ->from(array('main_table' => $this->getTable('catalogrule/rule')), 'main_table.*') - ->joinInner( - array('rp' => $this->getTable('catalogrule/rule_product')), - implode(' AND ', $joinCondsQuoted), - array()) - ->where(new Zend_Db_Expr("{$dateQuoted} BETWEEN IFNULL(main_table.from_date, {$dateQuoted}) AND IFNULL(main_table.to_date, {$dateQuoted})")) - ->where('main_table.is_active = ?', 1) - ->order('main_table.sort_order'); - return $adapter->fetchAll($select); - } - - /** - * Get data about product prices for all customer groups - * - * @param int|string $date - * @param int $wId - * @param int $pId - * @return array - */ - public function getRulesForProduct($date, $wId, $pId) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from($this->getTable('catalogrule/rule_product_price'), '*') - ->where('rule_date=?', $this->formatDate($date, false)) - ->where('website_id=?', $wId) - ->where('product_id=?', $pId); - return $read->fetchAll($select); - } - - /** - * Apply catalog rule to product - * - * @param Mage_CatalogRule_Model_Rule $rule - * @param Mage_Catalog_Model_Product $product - * @param array $websiteIds - * @return Mage_CatalogRule_Model_Mysql4_Rule - */ - public function applyToProduct($rule, $product, $websiteIds) - { - if (!$rule->getIsActive()) { - return $this; - } - - $ruleId = $rule->getId(); - $productId = $product->getId(); - - $write = $this->_getWriteAdapter(); - $write->beginTransaction(); - - $write->delete($this->getTable('catalogrule/rule_product'), array( - $write->quoteInto('rule_id=?', $ruleId), - $write->quoteInto('product_id=?', $productId), - )); - - if (!$rule->getConditions()->validate($product)) { - $write->delete($this->getTable('catalogrule/rule_product_price'), array( - $write->quoteInto('product_id=?', $productId), - )); - $write->commit(); - return $this; - } - - $customerGroupIds = $rule->getCustomerGroupIds(); - - $fromTime = strtotime($rule->getFromDate()); - $toTime = strtotime($rule->getToDate()); - $toTime = $toTime ? $toTime+self::SECONDS_IN_DAY-1 : 0; - - $sortOrder = (int)$rule->getSortOrder(); - $actionOperator = $rule->getSimpleAction(); - $actionAmount = $rule->getDiscountAmount(); - $actionStop = $rule->getStopRulesProcessing(); - - $rows = array(); - $header = 'replace into '.$this->getTable('catalogrule/rule_product').' ( - rule_id, - from_time, - to_time, - website_id, - customer_group_id, - product_id, - action_operator, - action_amount, - action_stop, - sort_order - ) values '; - try { - foreach ($websiteIds as $websiteId) { - foreach ($customerGroupIds as $customerGroupId) { - $rows[] = "( - '$ruleId', - '$fromTime', - '$toTime', - '$websiteId', - '$customerGroupId', - '$productId', - '$actionOperator', - '$actionAmount', - '$actionStop', - '$sortOrder' - )"; - if (sizeof($rows)==100) { - $sql = $header.join(',', $rows); - $write->query($sql); - $rows = array(); - } - } - } - - if (!empty($rows)) { - $sql = $header.join(',', $rows); - $write->query($sql); - } - } catch (Exception $e) { - $write->rollback(); - throw $e; - - } - $this->applyAllRulesForDateRange(null, null, $product); - $write->commit(); - return $this; - } } diff --git a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Collection.php b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Collection.php index 9aed8411f1..2b9a70ab1d 100644 --- a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Collection.php +++ b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Collection.php @@ -20,55 +20,18 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogRule_Model_Mysql4_Rule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogRule + * @author Magento Core Team + */ +class Mage_CatalogRule_Model_Mysql4_Rule_Collection extends Mage_CatalogRule_Model_Resource_Rule_Collection { - protected function _construct() - { - $this->_init('catalogrule/rule'); - } - - protected function _afterLoad() - { - $this->walk('afterLoad'); - } - - /** - * Filter collection by specified website IDs - * - * @param int|array $websiteIds - * @return Mage_CatalogRule_Model_Mysql4_Rule_Collection - */ - public function addWebsiteFilter($websiteIds) - { - if (!is_array($websiteIds)) { - $websiteIds = array($websiteIds); - } - $parts = array(); - foreach ($websiteIds as $websiteId) { - $parts[] = $this->getConnection()->quoteInto('FIND_IN_SET(?, main_table.website_ids)', $websiteId); - } - if ($parts) { - $this->getSelect()->where(new Zend_Db_Expr(implode(' OR ', $parts))); - } - return $this; - } - - /** - * Find product attribute in conditions or actions - * - * @param string $attributeCode - * @return Mage_CatalogRule_Model_Mysql4_Rule_Collection - */ - public function addAttributeInConditionFilter($attributeCode) - { - $match = sprintf('%%%s%%', substr(serialize(array('attribute' => $attributeCode)), 5, -1)); - $this->addFieldToFilter('conditions_serialized', array('like' => $match)); - - return $this; - } } diff --git a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price.php b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price.php index e2ff0d8f9d..26b5dbf202 100644 --- a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price.php +++ b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,66 +32,6 @@ * @package Mage_CatalogRule * @author Magento Core Team */ -class Mage_CatalogRule_Model_Mysql4_Rule_Product_Price extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogRule_Model_Mysql4_Rule_Product_Price extends Mage_CatalogRule_Model_Resource_Rule_Product_Price { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('catalogrule/rule_product_price', 'rule_product_price_id'); - } - - /** - * Apply price rule price to price index table - * - * @param Varien_Db_Select $select - * @param array|string $indexTable - * @param string $entityId - * @param string $customerGroupId - * @param string $websiteId - * @param array $updateFields the array of fields for compare with rule price and update - * @param string $websiteDate - * @return Mage_CatalogRule_Model_Rule_Product_Price - */ - public function applyPriceRuleToIndexTable(Varien_Db_Select $select, $indexTable, $entityId, $customerGroupId, - $websiteId, $updateFields, $websiteDate) - { - if (empty($updateFields)) { - return $this; - } - - if (is_array($indexTable)) { - foreach ($indexTable as $k => $v) { - if (is_string($k)) { - $indexAlias = $k; - } else { - $indexAlias = $v; - } - break; - } - } else { - $indexAlias = $indexTable; - } - - // join rule to select - $select->join( - array('rp' => $this->getMainTable()), - "rp.product_id = {$entityId} AND rp.website_id = {$websiteId}" - . " AND rp.customer_group_id = {$customerGroupId}" - . " AND rp.rule_date = {$websiteDate}", - array()); - - foreach ($updateFields as $priceField) { - $priceCond = $this->_getWriteAdapter()->quoteIdentifier(array($indexAlias, $priceField)); - $priceExpr = new Zend_Db_Expr("IF(rp.rule_price < {$priceCond}, rp.rule_price, {$priceCond})"); - $select->columns(array($priceField => $priceExpr)); - } - - $query = $select->crossUpdateFromSelect($indexTable); - $this->_getWriteAdapter()->query($query); - - return $this; - } } diff --git a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price/Collection.php b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price/Collection.php index 23abb89059..8686d89962 100644 --- a/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price/Collection.php +++ b/app/code/core/Mage/CatalogRule/Model/Mysql4/Rule/Product/Price/Collection.php @@ -20,28 +20,19 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogRule_Model_Mysql4_Rule_Product_Price_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogRule + * @author Magento Core Team + */ +class Mage_CatalogRule_Model_Mysql4_Rule_Product_Price_Collection + extends Mage_CatalogRule_Model_Resource_Rule_Product_Price_Collection { - protected function _construct() - { - parent::_construct(); - $this->_init('catalogrule/rule_product_price'); - } - - public function getProductIds() - { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns('main_table.product_id'); - $idsSelect->distinct(true); - return $this->getConnection()->fetchCol($idsSelect); - } } diff --git a/app/code/core/Mage/CatalogRule/Model/Observer.php b/app/code/core/Mage/CatalogRule/Model/Observer.php index da9ea7d65c..9dd49c6370 100644 --- a/app/code/core/Mage/CatalogRule/Model/Observer.php +++ b/app/code/core/Mage/CatalogRule/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -210,6 +210,7 @@ public function flushPriceCache() public function prepareCatalogProductPriceIndexTable(Varien_Event_Observer $observer) { $select = $observer->getEvent()->getSelect(); + $indexTable = $observer->getEvent()->getIndexTable(); $entityId = $observer->getEvent()->getEntityId(); $customerGroupId = $observer->getEvent()->getCustomerGroupId(); @@ -355,4 +356,27 @@ public function prepareCatalogProductCollectionPrices(Varien_Event_Observer $obs return $this; } + + /** + * Create catalog rule relations for imported products + * + * @param Varien_Event_Observer $observer + */ + public function createCatalogRulesRelations(Varien_Event_Observer $observer) + { + $adapter = $observer->getEvent()->getAdapter(); + $affectedEntityIds = $adapter->getAffectedEntityIds(); + + if (empty($affectedEntityIds)) { + return; + } + + $rules = Mage::getModel('catalogrule/rule')->getCollection() + ->addFieldToFilter('is_active', 1); + + foreach ($rules as $rule) { + $rule->setProductsFilter($affectedEntityIds); + Mage::getResourceSingleton('catalogrule/rule')->updateRuleProductData($rule); + } + } } diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php new file mode 100755 index 0000000000..3c740e63cb --- /dev/null +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php @@ -0,0 +1,708 @@ + + */ +class Mage_CatalogRule_Model_Resource_Rule extends Mage_Core_Model_Resource_Db_Abstract +{ + const SECONDS_IN_DAY = 86400; + + /** + * Initialize main table and table id field + * + */ + protected function _construct() + { + $this->_init('catalogrule/rule', 'rule_id'); + } + + /** + * Prepare object data for saving + * + * @param Mage_Core_Model_Abstract $object + */ + public function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getFromDate()) { + $date = Mage::app()->getLocale()->date(); + $date->setHour(0) + ->setMinute(0) + ->setSecond(0); + $object->setFromDate($date); + } + if ($object->getFromDate() instanceof Zend_Date) { + $object->setFromDate($object->getFromDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + + if (!$object->getToDate()) { + $object->setToDate(new Zend_Db_Expr('NULL')); + } else { + if ($object->getToDate() instanceof Zend_Date) { + $object->setToDate($object->getToDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + } + parent::_beforeSave($object); + } + + /** + * Update products which are matched for rule + * + * @param Mage_CatalogRule_Model_Rule $rule + * @return Mage_CatalogRule_Model_Resource_Rule + */ + public function updateRuleProductData(Mage_CatalogRule_Model_Rule $rule) + { + $ruleId = $rule->getId(); + $write = $this->_getWriteAdapter(); + $write->beginTransaction(); + + $write->delete($this->getTable('catalogrule/rule_product'), $write->quoteInto('rule_id=?', $ruleId)); + + if (!$rule->getIsActive()) { + $write->commit(); + return $this; + } + + $websiteIds = $rule->getWebsiteIds(); + if (!is_array($websiteIds)) { + $websiteIds = explode(',', $websiteIds); + } + if (empty($websiteIds)) { + return $this; + } + + Varien_Profiler::start('__MATCH_PRODUCTS__'); + $productIds = $rule->getMatchingProductIds(); + Varien_Profiler::stop('__MATCH_PRODUCTS__'); + $customerGroupIds = $rule->getCustomerGroupIds(); + + $fromTime = strtotime($rule->getFromDate()); + $toTime = strtotime($rule->getToDate()); + $toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0; + + $sortOrder = (int)$rule->getSortOrder(); + $actionOperator = $rule->getSimpleAction(); + $actionAmount = $rule->getDiscountAmount(); + $actionStop = $rule->getStopRulesProcessing(); + + $rows = array(); + + try { + foreach ($productIds as $productId) { + foreach ($websiteIds as $websiteId) { + foreach ($customerGroupIds as $customerGroupId) { + $rows[] = array( + 'rule_id' => $ruleId, + 'from_time' => $fromTime, + 'to_time' => $toTime, + 'website_id' => $websiteId, + 'customer_group_id' => $customerGroupId, + 'product_id' => $productId, + 'action_operator' => $actionOperator, + 'action_amount' => $actionAmount, + 'action_stop' => $actionStop, + 'sort_order' => $sortOrder, + ); + + if (count($rows) == 1000) { + $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); + $rows = array(); + } + } + } + } + if (!empty($rows)) { + $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); + } + + $write->commit(); + } catch (Exception $e) { + $write->rollback(); + throw $e; + } + + return $this; + } + + /** + * Get all product ids matched for rule + * + * @param int $ruleId + * @return array + */ + public function getRuleProductIds($ruleId) + { + $read = $this->_getReadAdapter(); + $select = $read->select()->from($this->getTable('catalogrule/rule_product'), 'product_id') + ->where('rule_id=?', $ruleId); + return $read->fetchCol($select); + } + + /** + * Remove catalog rules product prices for specified date range and product + * + * @param int|string $fromDate + * @param int|string $toDate + * @param int|null $productId + * @return Mage_CatalogRule_Model_Resource_Rule + */ + public function removeCatalogPricesForDateRange($fromDate, $toDate, $productId = null) + { + $write = $this->_getWriteAdapter(); + $conds = array(); + $cond = $write->quoteInto('rule_date between ?', $this->formatDate($fromDate)); + $cond = $write->quoteInto($cond.' and ?', $this->formatDate($toDate)); + $conds[] = $cond; + if (!is_null($productId)) { + $conds[] = $write->quoteInto('product_id=?', $productId); + } + + /** + * Add information about affected products + * It can be used in processes which related with product price (like catalog index) + */ + $select = $this->_getWriteAdapter()->select() + ->from($this->getTable('catalogrule/rule_product_price'), 'product_id') + ->where(implode(' AND ', $conds)) + ->group('product_id'); + + $replace = $write->insertFromSelect($select, $this->getTable('catalogrule/affected_product'), array('product_id'), true); + $write->query($replace); + $write->delete($this->getTable('catalogrule/rule_product_price'), $conds); + return $this; + } + + /** + * Delete old price rules data + * + * @param unknown_type $date + * @param mixed $productId + * @return Mage_CatalogRule_Model_Resource_Rule + */ + public function deleteOldData($date, $productId = null) + { + $write = $this->_getWriteAdapter(); + $conds = array(); + $conds[] = $write->quoteInto('rule_dateformatDate($date)); + if (!is_null($productId)) { + $conds[] = $write->quoteInto('product_id=?', $productId); + } + $write->delete($this->getTable('catalogrule/rule_product_price'), $conds); + return $this; + } + + /** + * Get DB resource statement for processing query result + * + * @param int $fromDate + * @param int $toDate + * @param int|null $productId + * @param int|null $websiteId + * @return Zend_Db_Statement_Interface + */ + protected function _getRuleProductsStmt($fromDate, $toDate, $productId = null, $websiteId = null) + { + $read = $this->_getReadAdapter(); + /** + * Sort order is important + * It used for check stop price rule condition. + * website_id customer_group_id product_id sort_order + * 1 1 1 0 + * 1 1 1 1 + * 1 1 1 2 + * if row with sort order 1 will have stop flag we should exclude + * all next rows for same product id from price calculation + */ + $select = $read->select() + ->from(array('rp' => $this->getTable('catalogrule/rule_product'))) + ->where($read->quoteInto('rp.from_time=0 or rp.from_time<=?', $toDate) + . ' or ' .$read->quoteInto('rp.to_time=0 or rp.to_time>=?', $fromDate)) + ->order(array('rp.website_id', 'rp.customer_group_id', 'rp.product_id', 'rp.sort_order', 'rp.rule_id')); + + if (!is_null($productId)) { + $select->where('rp.product_id=?', $productId); + } + + /** + * Join default price and websites prices to result + */ + $priceAttr = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'price'); + $priceTable = $priceAttr->getBackend()->getTable(); + $attributeId= $priceAttr->getId(); + + $joinCondition = '%1$s.entity_id=rp.product_id AND (%1$s.attribute_id='.$attributeId.') and %1$s.store_id=%2$s'; + + $select->join( + array('pp_default'=>$priceTable), + sprintf($joinCondition, 'pp_default', Mage_Core_Model_App::ADMIN_STORE_ID), + array('default_price'=>'pp_default.value') + ); + + if ($websiteId !== null) { + $website = Mage::app()->getWebsite($websiteId); + $defaultGroup = $website->getDefaultGroup(); + if ($defaultGroup instanceof Mage_Core_Model_Store_Group) { + $storeId = $defaultGroup->getDefaultStoreId(); + } else { + $storeId = Mage_Core_Model_App::ADMIN_STORE_ID; + } + + $select->joinInner( + array('product_website' => $this->getTable('catalog/product_website')), + 'product_website.product_id=rp.product_id ' . + 'AND rp.website_id=product_website.website_id ' . + 'AND product_website.website_id='.$websiteId, + array() + ); + + $tableAlias = 'pp'.$websiteId; + $fieldAlias = 'website_'.$websiteId.'_price'; + $select->joinLeft( + array($tableAlias=>$priceTable), + sprintf($joinCondition, $tableAlias, $storeId), + array($fieldAlias=>$tableAlias.'.value') + ); + } else { + foreach (Mage::app()->getWebsites() as $website) { + $websiteId = $website->getId(); + $defaultGroup = $website->getDefaultGroup(); + if ($defaultGroup instanceof Mage_Core_Model_Store_Group) { + $storeId = $defaultGroup->getDefaultStoreId(); + } else { + $storeId = Mage_Core_Model_App::ADMIN_STORE_ID; + } + + $tableAlias = 'pp'.$websiteId; + $fieldAlias = 'website_'.$websiteId.'_price'; + $select->joinLeft( + array($tableAlias => $priceTable), + sprintf($joinCondition, $tableAlias, $storeId), + array($fieldAlias => $tableAlias . '.value') + ); + } + } + + return $read->query($select); + } + + /** + * Generate catalog price rules prices for specified date range + * If from date is not defined - will be used previous day by UTC + * If to date is not defined - will be used next day by UTC + * + * @param int|string|null $fromDate + * @param int|string|null $toDate + * @param int $productId + * @return Mage_CatalogRule_Model_Resource_Rule + */ + public function applyAllRulesForDateRange($fromDate = null, $toDate = null, $productId = null) + { + $write = $this->_getWriteAdapter(); + $write->beginTransaction(); + + Mage::dispatchEvent('catalogrule_before_apply', array('resource' => $this)); + + $clearOldData = false; + if ($fromDate === null) { + $fromDate = mktime(0,0,0,date('m'),date('d')-1); + /** + * If fromDate not specified we can delete all data oldest than 1 day + * We have run it for clear table in case when cron was not installed + * and old data exist in table + */ + $clearOldData = true; + } + if (is_string($fromDate)) { + $fromDate = strtotime($fromDate); + } + if ($toDate === null) { + $toDate = mktime(0,0,0,date('m'),date('d')+1); + } + if (is_string($toDate)) { + $toDate = strtotime($toDate); + } + + $product = null; + if ($productId instanceof Mage_Catalog_Model_Product) { + $product = $productId; + $productId = $productId->getId(); + } + + $this->removeCatalogPricesForDateRange($fromDate, $toDate, $productId); + if ($clearOldData) { + $this->deleteOldData($fromDate, $productId); + } + + $dayPrices = array(); + + try { + /** + * Update products rules prices per each website separately + * because of max join limit in mysql + */ + foreach (Mage::app()->getWebsites(false) as $website) { + $productsStmt = $this->_getRuleProductsStmt( + $fromDate, + $toDate, + $productId, + $website->getId() + ); + + $dayPrices = array(); + $stopFlags = array(); + $prevKey = null; + + while ($ruleData = $productsStmt->fetch()) { + $ruleProductId = $ruleData['product_id']; + $productKey = $ruleProductId . '_' + . $ruleData['website_id'] . '_' + . $ruleData['customer_group_id']; + + if ($prevKey && ($prevKey != $productKey)) { + $stopFlags = array(); + } + + /** + * Build prices for each day + */ + for ($time=$fromDate; $time<=$toDate; $time+=self::SECONDS_IN_DAY) { + if (($ruleData['from_time']==0 || $time >= $ruleData['from_time']) + && ($ruleData['to_time']==0 || $time <=$ruleData['to_time']) + ) { + $priceKey = $time . '_' . $productKey; + + if (isset($stopFlags[$priceKey])) { + continue; + } + + if (!isset($dayPrices[$priceKey])) { + $dayPrices[$priceKey] = array( + 'rule_date' => $time, + 'website_id' => $ruleData['website_id'], + 'customer_group_id' => $ruleData['customer_group_id'], + 'product_id' => $ruleProductId, + 'rule_price' => $this->_calcRuleProductPrice($ruleData), + 'latest_start_date' => $ruleData['from_time'], + 'earliest_end_date' => $ruleData['to_time'], + ); + } else { + $dayPrices[$priceKey]['rule_price'] = $this->_calcRuleProductPrice( + $ruleData, + $dayPrices[$priceKey] + ); + $dayPrices[$priceKey]['latest_start_date'] = max( + $dayPrices[$priceKey]['latest_start_date'], + $ruleData['from_time'] + ); + $dayPrices[$priceKey]['earliest_end_date'] = min( + $dayPrices[$priceKey]['earliest_end_date'], + $ruleData['to_time'] + ); + } + + if ($ruleData['action_stop']) { + $stopFlags[$priceKey] = true; + } + } + } + + $prevKey = $productKey; + if (count($dayPrices)>1000) { + $this->_saveRuleProductPrices($dayPrices); + $dayPrices = array(); + } + } + $this->_saveRuleProductPrices($dayPrices); + } + $this->_saveRuleProductPrices($dayPrices); + + $write->delete($this->getTable('catalogrule/rule_group_website'), array()); + + $timestamp = Mage::getModel('core/date')->gmtTimestamp(); + + $select = $write->select() + ->distinct(true) + ->from($this->getTable('catalogrule/rule_product'), array('rule_id', 'customer_group_id', 'website_id')) + ->where("{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)"); + $query = $select->insertFromSelect($this->getTable('catalogrule/rule_group_website')); + $write->query($query); + + $write->commit(); + } catch (Exception $e) { + $write->rollback(); + throw $e; + } + + $productCondition = Mage::getModel('catalog/product_condition') + ->setTable($this->getTable('catalogrule/affected_product')) + ->setPkFieldName('product_id'); + Mage::dispatchEvent('catalogrule_after_apply', array( + 'product' => $product, + 'product_condition' => $productCondition + )); + $write->delete($this->getTable('catalogrule/affected_product')); + + return $this; + } + + /** + * Calculate product price based on price rule data and previous information + * + * @param array $ruleData + * @param null|array $productData + * @return float + */ + protected function _calcRuleProductPrice($ruleData, $productData = null) + { + if ($productData !== null && isset($productData['rule_price'])) { + $productPrice = $productData['rule_price']; + } else { + $websiteId = $ruleData['website_id']; + if (isset($ruleData['website_'.$websiteId.'_price'])) { + $productPrice = $ruleData['website_'.$websiteId.'_price']; + } else { + $productPrice = $ruleData['default_price']; + } + } + + $productPrice = Mage::helper('catalogrule')->calcPriceRule( + $ruleData['action_operator'], + $ruleData['action_amount'], + $productPrice); + + return Mage::app()->getStore()->roundPrice($productPrice); + } + + /** + * Save rule prices for products to DB + * + * @param array $arrData + * @return Mage_CatalogRule_Model_Resource_Rule + */ + protected function _saveRuleProductPrices($arrData) + { + if (empty($arrData)) { + return $this; + } + + foreach ($arrData as $key => $data) { + $productIds[$data['product_id']] = true; // to avoid dupes + $arrData[$key]['rule_date'] = $this->formatDate($data['rule_date'], false); + $arrData[$key]['latest_start_date'] = $this->formatDate($data['latest_start_date'], false); + $arrData[$key]['earliest_end_date'] = $this->formatDate($data['earliest_end_date'], false); + } + + foreach ($productIds as $id => $v) { + $this->_getWriteAdapter()->delete($this->getTable('catalogrule/affected_product'), + array("product_id = $id")); + $this->_getWriteAdapter()->insert($this->getTable('catalogrule/affected_product'), + array('product_id' => $id)); + } + + $this->_getWriteAdapter()->insertOnDuplicate($this->getTable('catalogrule/rule_product_price'), $arrData); + return $this; + } + + /** + * Get catalog rules product price for specific date, website and + * customer group + * + * @param int|string $date + * @param int $wId + * @param int $gId + * @param int $pId + * @return float | false + */ + public function getRulePrice($date, $wId, $gId, $pId) + { + $data = $this->getRulePrices($date, $wId, $gId, array($pId)); + if (isset($data[$pId])) { + return $data[$pId]; + } + + return false; + } + + /** + * Return product prices by catalog rule for specific date, website and customer group + * Return product - price pairs + * + * @param int|string $date + * @param int $websiteId + * @param int $customerGroupId + * @param array $productIds + * @return array + */ + public function getRulePrices($date, $websiteId, $customerGroupId, $productIds) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('catalogrule/rule_product_price'), array('product_id', 'rule_price')) + ->where('rule_date = ?', $this->formatDate($date, false)) + ->where('website_id = ?', $websiteId) + ->where('customer_group_id = ?', $customerGroupId) + ->where('product_id IN(?)', $productIds); + return $adapter->fetchPairs($select); + } + + /** + * Get active rule data based on few filters + * + * @param int|string $date + * @param int $websiteId + * @param int $customerGroupId + * @param int $productId + * @return array + */ + public function getRulesFromProduct($date, $websiteId, $customerGroupId, $productId) + { + $adapter = $this->_getReadAdapter(); + $dateQuoted = $adapter->quote($this->formatDate($date, false)); + $joinCondsQuoted[] = 'main_table.rule_id = rp.rule_id'; + $joinCondsQuoted[] = $adapter->quoteInto('rp.website_id = ?', $websiteId); + $joinCondsQuoted[] = $adapter->quoteInto('rp.customer_group_id = ?', $customerGroupId); + $joinCondsQuoted[] = $adapter->quoteInto('rp.product_id = ?', $productId); + $fromDate = $adapter->getIfNullSql('main_table.from_date', $dateQuoted); + $toDate = $adapter->getIfNullSql('main_table.to_date', $dateQuoted); + $select = $adapter->select() + ->from(array('main_table' => $this->getTable('catalogrule/rule'))) + ->joinInner( + array('rp' => $this->getTable('catalogrule/rule_product')), + implode(' AND ', $joinCondsQuoted), + array()) + ->where(new Zend_Db_Expr("{$dateQuoted} BETWEEN {$fromDate} AND {$toDate}")) + ->where('main_table.is_active = ?', 1) + ->order('main_table.sort_order'); + return $adapter->fetchAll($select); + } + + /** + * Get data about product prices for all customer groups + * + * @param int|string $date + * @param int $wId + * @param int $pId + * @return array + */ + public function getRulesForProduct($date, $wId, $pId) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from($this->getTable('catalogrule/rule_product_price'), '*') + ->where('rule_date=?', $this->formatDate($date, false)) + ->where('website_id=?', $wId) + ->where('product_id=?', $pId); + return $read->fetchAll($select); + } + + /** + * Apply catalog rule to product + * + * @param Mage_CatalogRule_Model_Rule $rule + * @param Mage_Catalog_Model_Product $product + * @param array $websiteIds + * @return Mage_CatalogRule_Model_Resource_Rule + */ + public function applyToProduct($rule, $product, $websiteIds) + { + if (!$rule->getIsActive()) { + return $this; + } + + $ruleId = $rule->getId(); + $productId = $product->getId(); + + $write = $this->_getWriteAdapter(); + $write->beginTransaction(); + + $write->delete($this->getTable('catalogrule/rule_product'), array( + $write->quoteInto('rule_id=?', $ruleId), + $write->quoteInto('product_id=?', $productId), + )); + + if (!$rule->getConditions()->validate($product)) { + $write->delete($this->getTable('catalogrule/rule_product_price'), array( + $write->quoteInto('product_id=?', $productId), + )); + $write->commit(); + return $this; + } + + $customerGroupIds = $rule->getCustomerGroupIds(); + + $fromTime = strtotime($rule->getFromDate()); + $toTime = strtotime($rule->getToDate()); + $toTime = $toTime ? $toTime+self::SECONDS_IN_DAY - 1 : 0; + + $sortOrder = (int)$rule->getSortOrder(); + $actionOperator = $rule->getSimpleAction(); + $actionAmount = $rule->getDiscountAmount(); + $actionStop = $rule->getStopRulesProcessing(); + + $rows = array(); + try { + foreach ($websiteIds as $websiteId) { + foreach ($customerGroupIds as $customerGroupId) { + $rows[] = array( + 'rule_id' => $ruleId, + 'from_time' => $fromTime, + 'to_time' => $toTime, + 'website_id' => $websiteId, + 'customer_group_id' => $customerGroupId, + 'product_id' => $productId, + 'action_operator' => $actionOperator, + 'action_amount' => $actionAmount, + 'action_stop' => $actionStop, + 'sort_order' => $sortOrder, + ); + + if (count($rows) == 1000) { + $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); + $rows = array(); + } + } + } + + if (!empty($rows)) { + $write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows); + } + } catch (Exception $e) { + $write->rollback(); + throw $e; + } + + $this->applyAllRulesForDateRange(null, null, $product); + $write->commit(); + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Collection.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Collection.php new file mode 100755 index 0000000000..420e5fa0b5 --- /dev/null +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Collection.php @@ -0,0 +1,89 @@ + + */ +class Mage_CatalogRule_Model_Resource_Rule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('catalogrule/rule'); + } + + /** + * Enter description here ... + * + */ + protected function _afterLoad() + { + $this->walk('afterLoad'); + } + + /** + * Filter collection by specified website IDs + * + * @param int|array $websiteIds + * @return Mage_CatalogRule_Model_Resource_Rule_Collection + */ + public function addWebsiteFilter($websiteIds) + { + if (!is_array($websiteIds)) { + $websiteIds = array($websiteIds); + } + $parts = array(); + foreach ($websiteIds as $websiteId) { + $parts[] = $this->getConnection()->prepareSqlCondition('main_table.website_ids', array('finset' => $websiteId)); + } + if ($parts) { + $this->getSelect()->where(new Zend_Db_Expr(implode(' OR ', $parts))); + } + return $this; + } + + /** + * Find product attribute in conditions or actions + * + * @param string $attributeCode + * @return Mage_CatalogRule_Model_Resource_Rule_Collection + */ + public function addAttributeInConditionFilter($attributeCode) + { + $match = sprintf('%%%s%%', substr(serialize(array('attribute' => $attributeCode)), 5, -1)); + $this->addFieldToFilter('conditions_serialized', array('like' => $match)); + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price.php new file mode 100755 index 0000000000..07c4655004 --- /dev/null +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price.php @@ -0,0 +1,92 @@ + + */ +class Mage_CatalogRule_Model_Resource_Rule_Product_Price extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('catalogrule/rule_product_price', 'rule_product_price_id'); + } + + /** + * Apply price rule price to price index table + * + * @param Varien_Db_Select $select + * @param array|string $indexTable + * @param string $entityId + * @param string $customerGroupId + * @param string $websiteId + * @param array $updateFields the array of fields for compare with rule price and update + * @param string $websiteDate + * @return Mage_CatalogRule_Model_Resource_Rule_Product_Price + */ + public function applyPriceRuleToIndexTable(Varien_Db_Select $select, $indexTable, $entityId, $customerGroupId, + $websiteId, $updateFields, $websiteDate) + { + if (empty($updateFields)) { + return $this; + } + + if (is_array($indexTable)) { + foreach ($indexTable as $k => $v) { + if (is_string($k)) { + $indexAlias = $k; + } else { + $indexAlias = $v; + } + break; + } + } else { + $indexAlias = $indexTable; + } + + $select->join(array('rp' => $this->getMainTable()), "rp.rule_date = {$websiteDate}", array()) + ->where("rp.product_id = {$entityId} AND rp.website_id = {$websiteId} AND rp.customer_group_id = {$customerGroupId}"); + + foreach ($updateFields as $priceField) { + $priceCond = $this->_getWriteAdapter()->quoteIdentifier(array($indexAlias, $priceField)); + $priceExpr = $this->_getWriteAdapter()->getCheckSql("rp.rule_price < {$priceCond}", 'rp.rule_price', $priceCond); + $select->columns(array($priceField => $priceExpr)); + } + + $query = $select->crossUpdateFromSelect($indexTable); + $this->_getWriteAdapter()->query($query); + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price/Collection.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price/Collection.php new file mode 100755 index 0000000000..22a8423393 --- /dev/null +++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule/Product/Price/Collection.php @@ -0,0 +1,64 @@ + + */ +class Mage_CatalogRule_Model_Resource_Rule_Product_Price_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('catalogrule/rule_product_price'); + } + + /** + * Enter description here ... + * + * @return unknown + */ + public function getProductIds() + { + $idsSelect = clone $this->getSelect(); + $idsSelect->reset(Zend_Db_Select::ORDER); + $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $idsSelect->reset(Zend_Db_Select::COLUMNS); + $idsSelect->columns('main_table.product_id'); + $idsSelect->distinct(true); + return $this->getConnection()->fetchCol($idsSelect); + } +} diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php index cf9a884ba0..390599cd3f 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule.php @@ -20,11 +20,46 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_CatalogRule_Model_Resource_Rule _getResource() + * @method Mage_CatalogRule_Model_Resource_Rule getResource() + * @method string getName() + * @method Mage_CatalogRule_Model_Rule setName(string $value) + * @method string getDescription() + * @method Mage_CatalogRule_Model_Rule setDescription(string $value) + * @method string getFromDate() + * @method Mage_CatalogRule_Model_Rule setFromDate(string $value) + * @method string getToDate() + * @method Mage_CatalogRule_Model_Rule setToDate(string $value) + * @method Mage_CatalogRule_Model_Rule setCustomerGroupIds(string $value) + * @method int getIsActive() + * @method Mage_CatalogRule_Model_Rule setIsActive(int $value) + * @method string getConditionsSerialized() + * @method Mage_CatalogRule_Model_Rule setConditionsSerialized(string $value) + * @method string getActionsSerialized() + * @method Mage_CatalogRule_Model_Rule setActionsSerialized(string $value) + * @method int getStopRulesProcessing() + * @method Mage_CatalogRule_Model_Rule setStopRulesProcessing(int $value) + * @method int getSortOrder() + * @method Mage_CatalogRule_Model_Rule setSortOrder(int $value) + * @method string getSimpleAction() + * @method Mage_CatalogRule_Model_Rule setSimpleAction(string $value) + * @method float getDiscountAmount() + * @method Mage_CatalogRule_Model_Rule setDiscountAmount(float $value) + * @method string getWebsiteIds() + * @method Mage_CatalogRule_Model_Rule setWebsiteIds(string $value) + * + * @category Mage + * @package Mage_CatalogRule + * @author Magento Core Team + */ class Mage_CatalogRule_Model_Rule extends Mage_Rule_Model_Rule { const XML_NODE_RELATED_CACHE = 'global/catalogrule/related_cache_types'; @@ -52,6 +87,13 @@ class Mage_CatalogRule_Model_Rule extends Mage_Rule_Model_Rule */ protected $_productIds; + /** + * Limitation for products collection + * + * @var int|array|null + */ + protected $_productsFilter = null; + protected $_now; /** @@ -71,6 +113,16 @@ protected function _construct() $this->setIdFieldName('rule_id'); } + /** + * Filtering products that must be checked for matching with rule + * + * @param int|array $productIds + */ + public function setProductsFilter($productIds) + { + $this->_productsFilter = $productIds; + } + public function getConditionsInstance() { return Mage::getModel('catalogrule/rule_condition_combine'); @@ -94,7 +146,6 @@ public function setNow($now) $this->_now = $now; } - public function toString($format='') { $str = Mage::helper('catalogrule')->__("Name: %s", $this->getName()) ."\n" @@ -165,12 +216,18 @@ public function getMatchingProductIds() if (is_null($this->_productIds)) { $this->_productIds = array(); $this->setCollectedAttributes(array()); - $websiteIds = explode(',', $this->getWebsiteIds()); + $websiteIds = $this->getWebsiteIds(); + if (!is_array($websiteIds)) { + $websiteIds = explode(',', $websiteIds); + } if ($websiteIds) { - $productCollection = Mage::getResourceModel('catalog/product_collection'); + $productCollection = Mage::getResourceModel('catalog/product_collection') + ->addWebsiteFilter($websiteIds); + if ($this->_productsFilter) { + $productCollection->addIdFilter($this->_productsFilter); + } - $productCollection->addWebsiteFilter($websiteIds); $this->getConditions()->collectValidatedAttributes($productCollection); Mage::getSingleton('core/resource_iterator')->walk( @@ -260,40 +317,45 @@ public function applyAll() /** * Apply all price rules to product * - * @param int|Mage_Catalog_Model_Product $product + * @param int|Mage_Catalog_Model_Product $product * @return Mage_CatalogRule_Model_Rule */ public function applyAllRulesToProduct($product) { $this->_getResource()->applyAllRulesForDateRange(NULL, NULL, $product); $this->_invalidateCache(); - $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price'); - if ($indexProcess) { - $indexProcess->reindexAll(); + + if ($product instanceof Mage_Catalog_Model_Product) { + $productId = $product->getId(); + } else { + $productId = $product; + } + + if ($productId) { + Mage::getResourceSingleton('catalog/product_indexer_price')->reindexProductIds(array($productId)); } } /** * Calculate price using catalog price rule of product * - * @param Mage_Catalog_Model_Product $product - * @param float $price + * @param Mage_Catalog_Model_Product $product + * @param float $price * @return float|null */ public function calcProductPriceRule(Mage_Catalog_Model_Product $product, $price) { - $priceRules = null; - $productId = $product->getId(); - $storeId = $product->getStoreId(); - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - $customerGroupId = null; + $priceRules = null; + $productId = $product->getId(); + $storeId = $product->getStoreId(); + $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); if ($product->hasCustomerGroupId()) { $customerGroupId = $product->getCustomerGroupId(); } else { $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); } - $dateTs = Mage::app()->getLocale()->storeTimeStamp($storeId); - $cacheKey = date('Y-m-d', $dateTs)."|$websiteId|$customerGroupId|$productId|$price"; + $dateTs = Mage::app()->getLocale()->storeTimeStamp($storeId); + $cacheKey = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|$price"; if (!array_key_exists($cacheKey, self::$_priceRulesData)) { $rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId); diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Collection.php b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Collection.php index 8076c21595..fc68d94243 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Collection.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php index 9f4d0b4121..2ac8b299f7 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Action/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Combine.php b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Combine.php index 876e3c224f..a8687b67ce 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Combine.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Combine.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php index d550e5ea20..3d87f6f998 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -61,7 +61,7 @@ public function getAttributeObject() { try { $obj = Mage::getSingleton('eav/config') - ->getAttribute('catalog_product', $this->getAttribute()); + ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $this->getAttribute()); } catch (Exception $e) { $obj = new Varien_Object(); @@ -131,7 +131,7 @@ protected function _prepareValueOptions() $selectOptions = null; if ($this->getAttribute() === 'attribute_set_id') { $entityTypeId = Mage::getSingleton('eav/config') - ->getEntityType('catalog_product')->getId(); + ->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId(); $selectOptions = Mage::getResourceModel('eav/entity_attribute_set_collection') ->setEntityTypeFilter($entityTypeId) ->load() diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Product/Price.php b/app/code/core/Mage/CatalogRule/Model/Rule/Product/Price.php index 4903df7f87..1ce69281f9 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule/Product/Price.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,23 @@ /** * Catalog Rule Product Aggregated Price per date Model * + * @method Mage_CatalogRule_Model_Resource_Rule_Product_Price _getResource() + * @method Mage_CatalogRule_Model_Resource_Rule_Product_Price getResource() + * @method string getRuleDate() + * @method Mage_CatalogRule_Model_Rule_Product_Price setRuleDate(string $value) + * @method int getCustomerGroupId() + * @method Mage_CatalogRule_Model_Rule_Product_Price setCustomerGroupId(int $value) + * @method int getProductId() + * @method Mage_CatalogRule_Model_Rule_Product_Price setProductId(int $value) + * @method float getRulePrice() + * @method Mage_CatalogRule_Model_Rule_Product_Price setRulePrice(float $value) + * @method int getWebsiteId() + * @method Mage_CatalogRule_Model_Rule_Product_Price setWebsiteId(int $value) + * @method string getLatestStartDate() + * @method Mage_CatalogRule_Model_Rule_Product_Price setLatestStartDate(string $value) + * @method string getEarliestEndDate() + * @method Mage_CatalogRule_Model_Rule_Product_Price setEarliestEndDate(string $value) + * * @category Mage * @package Mage_CatalogRule * @author Magento Core Team @@ -58,6 +75,7 @@ protected function _construct() public function applyPriceRuleToIndexTable(Varien_Db_Select $select, $indexTable, $entityId, $customerGroupId, $websiteId, $updateFields, $websiteDate) { + $this->_getResource()->applyPriceRuleToIndexTable($select, $indexTable, $entityId, $customerGroupId, $websiteId, $updateFields, $websiteDate); diff --git a/app/code/core/Mage/CatalogRule/etc/adminhtml.xml b/app/code/core/Mage/CatalogRule/etc/adminhtml.xml index e7b0546a8f..7c5d3c4c47 100644 --- a/app/code/core/Mage/CatalogRule/etc/adminhtml.xml +++ b/app/code/core/Mage/CatalogRule/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogRule/etc/config.xml b/app/code/core/Mage/CatalogRule/etc/config.xml index 40dd9e4319..ddb08bbeee 100644 --- a/app/code/core/Mage/CatalogRule/etc/config.xml +++ b/app/code/core/Mage/CatalogRule/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.10 + 1.6.0.0 @@ -40,18 +40,29 @@ Mage_CatalogRule_Model - catalogrule_mysql4 + catalogrule_resource - - Mage_CatalogRule_Model_Mysql4 + + Mage_CatalogRule_Model_Resource + catalogrule_mysql4 - catalogrule
- catalogrule_product
- catalogrule_product_price
- catalogrule_affected_product
- catalogrule_group_website
+ + catalogrule
+
+ + catalogrule_product
+
+ + catalogrule_product_price
+
+ + catalogrule_affected_product
+
+ + catalogrule_group_website
+
-
+
@@ -113,7 +124,6 @@ - @@ -141,6 +151,16 @@ + + + + + catalogrule/observer + createCatalogRulesRelations + + + + @@ -167,12 +187,15 @@ - - 0 1 * * * - catalogrule/observer::dailyCatalogUpdate + + 0 1 * * * + + + catalogrule/observer::dailyCatalogUpdate + diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/install-1.6.0.0.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..acbac07b2c --- /dev/null +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/install-1.6.0.0.php @@ -0,0 +1,297 @@ +startSetup(); + +/** + * Create table 'catalogrule/rule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogrule/rule')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('from_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'From Date') + ->addColumn('to_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'To Date') + ->addColumn('customer_group_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Customer Group Ids') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Active') + ->addColumn('conditions_serialized', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Conditions Serialized') + ->addColumn('actions_serialized', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Actions Serialized') + ->addColumn('stop_rules_processing', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Stop Rules Processing') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addColumn('simple_action', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Simple Action') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => 0.0000, + ), 'Discount Amount') + ->addColumn('website_ids', Varien_Db_Ddl_Table::TYPE_TEXT, 4000, array( + ), 'Website Ids') + ->addIndex($installer->getIdxName('catalogrule/rule', array('is_active', 'sort_order', 'to_date', 'from_date')), + array('is_active', 'sort_order', 'to_date', 'from_date')) + + ->setComment('CatalogRule'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogrule/rule_product' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogrule/rule_product')) + ->addColumn('rule_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Product Id') + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Rule Id') + ->addColumn('from_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'From Time') + ->addColumn('to_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'To time') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Group Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Id') + ->addColumn('action_operator', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array( + 'default' => 'to_fixed', + ), 'Action Operator') + ->addColumn('action_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Action Amount') + ->addColumn('action_stop', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Action Stop') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Website Id') + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('rule_id', 'from_time', 'to_time', 'website_id', 'customer_group_id', 'product_id', 'sort_order'), true), + array('rule_id', 'from_time', 'to_time', 'website_id', 'customer_group_id', 'product_id', 'sort_order'), array('type' => 'unique')) + + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('rule_id')), + array('rule_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('from_time')), + array('from_time')) + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('to_time')), + array('to_time')) + ->addIndex($installer->getIdxName('catalogrule/rule_product', array('product_id')), + array('product_id')) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product', 'rule_id', 'catalogrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('catalogrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->setComment('CatalogRule Product'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogrule/rule_product_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogrule/rule_product_price')) + ->addColumn('rule_product_price_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Product PriceId') + ->addColumn('rule_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => false, + ), 'Rule Date') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Group Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Id') + ->addColumn('rule_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Rule Price') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Website Id') + ->addColumn('latest_start_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Latest StartDate') + ->addColumn('earliest_end_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Earliest EndDate') + + ->addIndex($installer->getIdxName('catalogrule/rule_product_price', array('rule_date', 'website_id', 'customer_group_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('rule_date', 'website_id', 'customer_group_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalogrule/rule_product_price', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_product_price', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_product_price', array('product_id')), + array('product_id')) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product_price', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product_price', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_product_price', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->setComment('CatalogRule Product Price'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogrule/affected_product' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogrule/affected_product')) + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product Id') + ->setComment('CatalogRule Affected Product'); + +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogrule/rule_group_website' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogrule/rule_group_website')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Rule Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Customer Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Website Id') + ->addIndex($installer->getIdxName('catalogrule/rule_group_website', array('rule_id')), + array('rule_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_group_website', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('catalogrule/rule_group_website', array('website_id')), + array('website_id')) + + ->addForeignKey($installer->getFkName('catalogrule/rule_group_website', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_group_website', 'rule_id', 'catalogrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('catalogrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + + ->addForeignKey($installer->getFkName('catalogrule/rule_group_website', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('CatalogRule Group Website'); + +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-install-0.7.0.php index 0548239fcf..b9fe6bb806 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.0-0.7.1.php index a37c94a4c0..041d52c68d 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.1-0.7.2.php index 6b289ae1a8..fdcc5d73d8 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.2-0.7.3.php index e0739abe9a..b2282e459d 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.3-0.7.4.php index 57fe42d3da..75fed8fa64 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.4-0.7.5.php index 26e80e6cdc..19d5a4682f 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.5-0.7.6.php index f2d29e20bf..40653573f7 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.6-0.7.7.php index 1435da27bf..23aeb6403a 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.7-0.7.8.php index d6f7d0a284..3672439f91 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.8-0.7.9.php index c2778e0600..0d2c5b01c0 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.9-0.7.10.php index edfc0a523c..f88844c54e 100644 --- a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..3bacdbd129 --- /dev/null +++ b/app/code/core/Mage/CatalogRule/sql/catalogrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,620 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_group_website'), + 'FK_CATALOGRULE_GROUP_WEBSITE_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_group_website'), + 'FK_CATALOGRULE_GROUP_WEBSITE_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_group_website'), + 'FK_CATALOGRULE_GROUP_WEBSITE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_CUSTOMERGROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_CUSTOMERGROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_WEBSITE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule'), + 'SORT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_group_website'), + 'RULE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_group_website'), + 'CUSTOMER_GROUP_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_group_website'), + 'WEBSITE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'SORT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_RULE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_CUSTOMERGROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'FK_CATALOGRULE_PRODUCT_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'IDX_FROM_TIME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product'), + 'IDX_TO_TIME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product_price'), + 'RULE_DATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_CUSTOMERGROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogrule/rule_product_price'), + 'FK_CATALOGRULE_PRODUCT_PRICE_PRODUCT' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('catalogrule/rule') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'from_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'From Date' + ), + 'to_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'To Date' + ), + 'customer_group_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Customer Group Ids' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Active' + ), + 'conditions_serialized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Conditions Serialized' + ), + 'actions_serialized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Actions Serialized' + ), + 'stop_rules_processing' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Stop Rules Processing' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ), + 'simple_action' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Simple Action' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'website_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Website Ids' + ) + ), + 'comment' => 'CatalogRule' + ), + $installer->getTable('catalogrule/rule_product') => array( + 'columns' => array( + 'rule_product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Product Id' + ), + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rule Id' + ), + 'from_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'From Time' + ), + 'to_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'To time' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Group Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Id' + ), + 'action_operator' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 10, + 'default' => 'to_fixed', + 'comment' => 'Action Operator' + ), + 'action_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Action Amount' + ), + 'action_stop' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Action Stop' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Website Id' + ) + ), + 'comment' => 'CatalogRule Product' + ), + $installer->getTable('catalogrule/rule_product_price') => array( + 'columns' => array( + 'rule_product_price_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Product PriceId' + ), + 'rule_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'nullable' => false, + 'default' => '0000-00-00', + 'comment' => 'Rule Date' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Group Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Id' + ), + 'rule_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Rule Price' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Website Id' + ), + 'latest_start_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Latest StartDate' + ), + 'earliest_end_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Earliest EndDate' + ) + ), + 'comment' => 'CatalogRule Product Price' + ), + $installer->getTable('catalogrule/affected_product') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product Id' + ) + ), + 'comment' => 'CatalogRule Affected Product' + ), + $installer->getTable('catalogrule/rule_group_website') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Rule Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Customer Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Website Id' + ) + ), + 'comment' => 'CatalogRule Group Website' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule'), + $installer->getIdxName('catalogrule/rule', array('is_active', 'sort_order', 'to_date', 'from_date')), + array('is_active', 'sort_order', 'to_date', 'from_date') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_group_website'), + $installer->getIdxName('catalogrule/rule_group_website', array('rule_id')), + array('rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_group_website'), + $installer->getIdxName('catalogrule/rule_group_website', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_group_website'), + $installer->getIdxName('catalogrule/rule_group_website', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName( + 'catalogrule/rule_product', + array('rule_id', 'from_time', 'to_time', 'website_id', 'customer_group_id', 'product_id', 'sort_order'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('rule_id', 'from_time', 'to_time', 'website_id', 'customer_group_id', 'product_id', 'sort_order'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('rule_id')), + array('rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('from_time')), + array('from_time') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('to_time')), + array('to_time') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product'), + $installer->getIdxName('catalogrule/rule_product', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product_price'), + $installer->getIdxName( + 'catalogrule/rule_product_price', + array('rule_date', 'website_id', 'customer_group_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('rule_date', 'website_id', 'customer_group_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product_price'), + $installer->getIdxName('catalogrule/rule_product_price', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product_price'), + $installer->getIdxName('catalogrule/rule_product_price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogrule/rule_product_price'), + $installer->getIdxName('catalogrule/rule_product_price', array('product_id')), + array('product_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_group_website', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('catalogrule/rule_group_website'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_group_website', 'rule_id', 'catalogrule/rule', 'rule_id'), + $installer->getTable('catalogrule/rule_group_website'), + 'rule_id', + $installer->getTable('catalogrule/rule'), + 'rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_group_website', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalogrule/rule_group_website'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalogrule/rule_product'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('catalogrule/rule_product'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product', 'rule_id', 'catalogrule/rule', 'rule_id'), + $installer->getTable('catalogrule/rule_product'), + 'rule_id', + $installer->getTable('catalogrule/rule'), + 'rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalogrule/rule_product'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product_price', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalogrule/rule_product_price'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product_price', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('catalogrule/rule_product_price'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogrule/rule_product_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('catalogrule/rule_product_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php b/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php index dec0d4954b..8ca85d1930 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php +++ b/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php b/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php index fa86716764..46a2ebc3b6 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php +++ b/app/code/core/Mage/CatalogSearch/Block/Advanced/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Block/Autocomplete.php b/app/code/core/Mage/CatalogSearch/Block/Autocomplete.php index 17f535fb7f..81eeb7efcd 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Autocomplete.php +++ b/app/code/core/Mage/CatalogSearch/Block/Autocomplete.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Block/Layer.php b/app/code/core/Mage/CatalogSearch/Block/Layer.php index 02853c175e..81f5cbe9cd 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Layer.php +++ b/app/code/core/Mage/CatalogSearch/Block/Layer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,15 +30,6 @@ */ class Mage_CatalogSearch_Block_Layer extends Mage_Catalog_Block_Layer_View { - /** - * Internal constructor - */ - protected function _construct() - { - parent::_construct(); - Mage::register('current_layer', $this->getLayer()); - } - /** * Get attribute filter block name * diff --git a/app/code/core/Mage/CatalogSearch/Block/Layer/Filter/Attribute.php b/app/code/core/Mage/CatalogSearch/Block/Layer/Filter/Attribute.php index 9377d035ae..9cc0dea12b 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Layer/Filter/Attribute.php +++ b/app/code/core/Mage/CatalogSearch/Block/Layer/Filter/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Block/Result.php b/app/code/core/Mage/CatalogSearch/Block/Result.php index 2660b1582f..0f9ae577a4 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Result.php +++ b/app/code/core/Mage/CatalogSearch/Block/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,7 +37,7 @@ class Mage_CatalogSearch_Block_Result extends Mage_Core_Block_Template /** * Catalog Product collection * - * @var Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection + * @var Mage_CatalogSearch_Model_Resource_Fulltext_Collection */ protected $_productCollection; @@ -164,7 +164,7 @@ public function getProductListHtml() /** * Retrieve loaded category collection * - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection */ protected function _getProductCollection() { diff --git a/app/code/core/Mage/CatalogSearch/Block/Term.php b/app/code/core/Mage/CatalogSearch/Block/Term.php index 5a33f5c9b8..0b5ff7b65e 100644 --- a/app/code/core/Mage/CatalogSearch/Block/Term.php +++ b/app/code/core/Mage/CatalogSearch/Block/Term.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -53,7 +53,6 @@ protected function _loadTerms() $this->_terms = array(); $terms = Mage::getResourceModel('catalogsearch/query_collection') ->setPopularQueryFilter(Mage::app()->getStore()->getId()) - ->setOrder('popularity', 'DESC') ->setPageSize(100) ->load() ->getItems(); diff --git a/app/code/core/Mage/CatalogSearch/Helper/Data.php b/app/code/core/Mage/CatalogSearch/Helper/Data.php index 1a945be7e4..e4f0584ba6 100644 --- a/app/code/core/Mage/CatalogSearch/Helper/Data.php +++ b/app/code/core/Mage/CatalogSearch/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -65,7 +65,7 @@ class Mage_CatalogSearch_Helper_Data extends Mage_Core_Helper_Abstract /** * Search engine model * - * @var Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine + * @var Mage_CatalogSearch_Model_Resource_Fulltext_Engine */ protected $_engine; @@ -153,7 +153,7 @@ public function getEscapedQueryText() /** * Retrieve suggest collection for query * - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection + * @return Mage_CatalogSearch_Model_Resource_Query_Collection */ public function getSuggestCollection() { diff --git a/app/code/core/Mage/CatalogSearch/Model/Advanced.php b/app/code/core/Mage/CatalogSearch/Model/Advanced.php index 538423002b..b74baef11e 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Advanced.php +++ b/app/code/core/Mage/CatalogSearch/Model/Advanced.php @@ -20,15 +20,34 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog advanced search model * - * @category Mage - * @package Mage_CatalogSearch + * @method Mage_CatalogSearch_Model_Resource_Advanced _getResource() + * @method Mage_CatalogSearch_Model_Resource_Advanced getResource() + * @method int getEntityTypeId() + * @method Mage_CatalogSearch_Model_Advanced setEntityTypeId(int $value) + * @method int getAttributeSetId() + * @method Mage_CatalogSearch_Model_Advanced setAttributeSetId(int $value) + * @method string getTypeId() + * @method Mage_CatalogSearch_Model_Advanced setTypeId(string $value) + * @method string getSku() + * @method Mage_CatalogSearch_Model_Advanced setSku(string $value) + * @method int getHasOptions() + * @method Mage_CatalogSearch_Model_Advanced setHasOptions(int $value) + * @method int getRequiredOptions() + * @method Mage_CatalogSearch_Model_Advanced setRequiredOptions(int $value) + * @method string getCreatedAt() + * @method Mage_CatalogSearch_Model_Advanced setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_CatalogSearch_Model_Advanced setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_CatalogSearch * @author Magento Core Team */ class Mage_CatalogSearch_Model_Advanced extends Mage_Core_Model_Abstract @@ -43,7 +62,7 @@ class Mage_CatalogSearch_Model_Advanced extends Mage_Core_Model_Abstract /** * Current search engine * - * @var object | Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine + * @var object | Mage_CatalogSearch_Model_Resource_Fulltext_Engine */ protected $_engine = null; @@ -69,7 +88,7 @@ protected function _getEngine() /** * Retrieve resource instance wrapper * - * @return Mage_CatalogSearch_Model_Mysql4_Advanced + * @return Mage_CatalogSearch_Model_Resource_Advanced */ protected function _getResource() { @@ -87,7 +106,7 @@ protected function _getResource() */ public function getAttributes() { - /* @var $attributes Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */ + /* @var $attributes Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection */ $attributes = $this->getData('attributes'); if (is_null($attributes)) { $product = Mage::getModel('catalog/product'); @@ -108,7 +127,7 @@ public function getAttributes() /** * Prepare search condition for attribute * - * @deprecated after 1.4.1.0 - use Mage_CatalogSearch_Model_Mysql4_Advanced->_prepareCondition() + * @deprecated after 1.4.1.0 - use Mage_CatalogSearch_Model_Resource_Advanced->_prepareCondition() * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value @@ -143,26 +162,22 @@ public function addFilters($values) (isset($value['to']) && strlen(trim($value['to'])))) { if (isset($value['currency']) && !empty($value['currency'])) { $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']); - } - else { + } else { $rate = 1; } - if ($this->_getResource()->addRatedPriceFilter($this->getProductCollection(), $attribute, $value, $rate)) { $hasConditions = true; $this->_addSearchCriteria($attribute, $value); } } - } - else if ($attribute->isIndexable()) { + } else if ($attribute->isIndexable()) { if (!is_string($value) || strlen($value) != 0) { - if ($this->_getResource()->addIndexableAttributeFilter($this->getProductCollection(), $attribute, $value)) { + if ($this->_getResource()->addIndexableAttributeModifiedFilter($this->getProductCollection(), $attribute, $value)) { $hasConditions = true; $this->_addSearchCriteria($attribute, $value); } } - } - else { + } else { $condition = $this->_prepareCondition($attribute, $value); if ($condition === false) { continue; @@ -179,7 +194,6 @@ public function addFilters($values) $allConditions[$table][$attributeId] = $condition; } } - if ($allConditions) { $this->getProductCollection()->addFieldsToFilter($allConditions); } else if (!$hasConditions) { @@ -263,7 +277,7 @@ public function getSearchCriterias() /** * Retrieve advanced search product collection * - * @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection + * @return Mage_CatalogSearch_Model_Resource_Advanced_Collection */ public function getProductCollection(){ if (is_null($this->_productCollection)) { @@ -281,7 +295,7 @@ public function getProductCollection(){ /** * Prepare product collection * - * @param Mage_CatalogSearch_Model_Mysql4_Advanced_Collection $collection + * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection * @return Mage_Catalog_Model_Layer */ public function prepareProductCollection($collection) diff --git a/app/code/core/Mage/CatalogSearch/Model/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Fulltext.php index fd8b52e030..dd48bfab8a 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Fulltext.php @@ -20,15 +20,24 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog advanced search model * - * @category Mage - * @package Mage_CatalogSearch + * @method Mage_CatalogSearch_Model_Resource_Fulltext _getResource() + * @method Mage_CatalogSearch_Model_Resource_Fulltext getResource() + * @method int getProductId() + * @method Mage_CatalogSearch_Model_Fulltext setProductId(int $value) + * @method int getStoreId() + * @method Mage_CatalogSearch_Model_Fulltext setStoreId(int $value) + * @method string getDataIndex() + * @method Mage_CatalogSearch_Model_Fulltext setDataIndex(string $value) + * + * @category Mage + * @package Mage_CatalogSearch * @author Magento Core Team */ class Mage_CatalogSearch_Model_Fulltext extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php b/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php index c65188a192..fb715227db 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php +++ b/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -87,7 +87,7 @@ public function eavAttributeChange(Varien_Event_Observer $observer) { $attribute = $observer->getEvent()->getAttribute(); /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - $entityType = Mage::getSingleton('eav/config')->getEntityType('catalog_product'); + $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY); /* @var $entityType Mage_Eav_Model_Entity_Type */ if ($attribute->getEntityTypeId() != $entityType->getId()) { diff --git a/app/code/core/Mage/CatalogSearch/Model/Indexer/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Indexer/Fulltext.php index 43507f7a33..dd0232df4a 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Indexer/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Indexer/Fulltext.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,7 +37,7 @@ class Mage_CatalogSearch_Model_Indexer_Fulltext extends Mage_Index_Model_Indexer /** * Retrieve resource instance * - * @return Mage_CatalogSearch_Model_Mysql4_Indexer_Fulltext + * @return Mage_CatalogSearch_Model_Resource_Indexer_Fulltext */ protected function _getResource() { diff --git a/app/code/core/Mage/CatalogSearch/Model/Layer.php b/app/code/core/Mage/CatalogSearch/Model/Layer.php index f8b32c6340..465d987125 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Layer.php +++ b/app/code/core/Mage/CatalogSearch/Model/Layer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ class Mage_CatalogSearch_Model_Layer extends Mage_Catalog_Model_Layer /** * Get current layer product collection * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection + * @return Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection */ public function getProductCollection() { @@ -48,7 +48,7 @@ public function getProductCollection() /** * Prepare product collection * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection + * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection $collection * @return Mage_Catalog_Model_Layer */ public function prepareProductCollection($collection) @@ -99,8 +99,8 @@ public function getStateTags(array $additionalTags = array()) /** * Add filters to attribute collection * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection $collection - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection + * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection $collection + * @return Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection */ protected function _prepareAttributeCollection($collection) { diff --git a/app/code/core/Mage/CatalogSearch/Model/Layer/Filter/Attribute.php b/app/code/core/Mage/CatalogSearch/Model/Layer/Filter/Attribute.php index e749fe95ef..f7ef2f3de1 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Layer/Filter/Attribute.php +++ b/app/code/core/Mage/CatalogSearch/Model/Layer/Filter/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced.php index 3ba3dbe5fc..e526804a89 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,236 +32,6 @@ * @package Mage_CatalogSearch * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Advanced extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogSearch_Model_Mysql4_Advanced extends Mage_CatalogSearch_Model_Resource_Advanced { - /** - * Initialize connection and define catalog product table as main table - * - */ - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - /** - * Prepare response object and dispatch prepare price event - * - * Return response object - * - * @param Varien_Db_Select $select - * @return Varien_Object - */ - protected function _dispatchPreparePriceEvent($select) - { - // prepare response object for event - $response = new Varien_Object(); - $response->setAdditionalCalculations(array()); - - // prepare event arguments - $eventArgs = array( - 'select' => $select, - 'table' => 'price_index', - 'store_id' => Mage::app()->getStore()->getId(), - 'response_object' => $response - ); - - /** - * @deprecated since 1.3.2.2 - */ - Mage::dispatchEvent('catalogindex_prepare_price_select', $eventArgs); - - /** - * @since 1.4 - */ - Mage::dispatchEvent('catalog_prepare_price_select', $eventArgs); - - return $response; - } - - /** - * Prepare search condition for attribute - * - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param string|array $value - * @param Mage_CatalogSearch_Model_Mysql4_Advanced_Collection $collection - * - * @return mixed - */ - public function prepareCondition($attribute, $value, $collection) - { - $condition = false; - - if (is_array($value)) { - if (!empty($value['from']) || !empty($value['to'])) { // range - $condition = $value; - } else if ($attribute->getBackendType() == 'varchar') { // multiselect - $condition = array('in_set' => $value); - } else if (!isset($value['from']) && !isset($value['to'])) { // select - $condition = array('in' => $value); - } - } else { - if (strlen($value) > 0) { - if (in_array($attribute->getBackendType(), array('varchar', 'text', 'static'))) { - $condition = array('like' => '%' . $value . '%'); // text search - } else { - $condition = $value; - } - } - } - - return $condition; - } - - /** - * Add filter by attribute price - * - * @deprecated after 1.4.1.0 - use $this->addRatedPriceFilter() - * - * @param Mage_CatalogSearch_Model_Advanced $object - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param string|array $value - * - * @return bool - */ - public function addPriceFilter($object, $attribute, $value) - { - if (empty($value['from']) && empty($value['to'])) { - return false; - } - - $adapter = $this->_getReadAdapter(); - - $conditions = array(); - if (strlen($value['from']) > 0) { - $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s >= ?', $value['from']); - } - if (strlen($value['to']) > 0) { - $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s <= ?', $value['to']); - } - - if (!$conditions) { - return false; - } - - $object->getProductCollection()->addPriceData(); - $select = $object->getProductCollection()->getSelect(); - $response = $this->_dispatchPreparePriceEvent($select); - $additional = join('', $response->getAdditionalCalculations()); - - $rate = 1; - if (!empty($value['currency'])) { - $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']); - } - - foreach ($conditions as $condition) { - $select->where(sprintf($condition, $additional, $rate)); - } - - return true; - } - - /** - * Add filter by attribute rated price - * - * @param Mage_CatalogSearch_Model_Mysql4_Advanced_Collection $collection - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param string|array $value - * @param int $rate - * - * @return bool - */ - public function addRatedPriceFilter($collection, $attribute, $value, $rate = 1) - { - $adapter = $this->_getReadAdapter(); - - $conditions = array(); - if (strlen($value['from']) > 0) { - $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s >= ?', $value['from']); - } - if (strlen($value['to']) > 0) { - $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s <= ?', $value['to']); - } - - if (!$conditions) { - return false; - } - - $collection->addPriceData(); - $select = $collection->getSelect(); - $response = $this->_dispatchPreparePriceEvent($select); - $additional = join('', $response->getAdditionalCalculations()); - - foreach ($conditions as $condition) { - $select->where(sprintf($condition, $additional, $rate)); - } - - return true; - } - - /** - * Add filter by indexable attribute - * - * @deprecated after 1.4.1.0 - use $this->addIndexableAttributeModifiedFilter() - * - * @param Mage_CatalogSearch_Model_Advanced $object - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param string|array $value - * - * @return bool - */ - public function addIndexableAttributeFilter($object, $attribute, $value) - { - return $this->addIndexableAttributeModifiedFilter($object, $attribute, $value); - } - - /** - * - * @param Mage_CatalogSearch_Model_Mysql4_Advanced_Collection $collection - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute - * @param string|array $value - * - * @return bool - */ - public function addIndexableAttributeModifiedFilter($collection, $attribute, $value) - { - if ($attribute->getIndexType() == 'decimal') { - $table = $this->getTable('catalog/product_index_eav_decimal'); - } else { - $table = $this->getTable('catalog/product_index_eav'); - } - - $tableAlias = 'ast_' . $attribute->getAttributeCode(); - $storeId = Mage::app()->getStore()->getId(); - $select = $collection->getSelect(); - - if (is_array($value)) { - if (isset($value['from']) && isset($value['to'])) { - if (empty($value['from']) && empty($value['to'])) { - return false; - } - } - } - - $select->distinct(true); - $select->join( - array($tableAlias => $table), - "e.entity_id={$tableAlias}.entity_id AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" - . " AND {$tableAlias}.store_id={$storeId}", - array() - ); - - if (is_array($value) && (isset($value['from']) || isset($value['to']))) { - if (isset($value['from']) && !empty($value['from'])) { - $select->where("{$tableAlias}.`value` >= ?", $value['from']); - } - if (isset($value['to']) && !empty($value['to'])) { - $select->where("{$tableAlias}.`value` <= ?", $value['to']); - } - return true; - } - - $select->where("{$tableAlias}.`value` IN(?)", $value); - - return true; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced/Collection.php index 7e003edb9f..203a826405 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced/Collection.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Advanced/Collection.php @@ -20,98 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogSearch_Model_Mysql4_Advanced_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection -{ - /** - * Add not indexable fields to search - * - * @param array $fields - * @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection - */ - public function addFieldsToFilter($fields) - { - if ($fields) { - $previousSelect = null; - foreach ($fields as $table => $conditions) { - foreach ($conditions as $attributeId => $conditionValue) { - $bindVarName = 'attribute_'.$attributeId; - $select = $this->getConnection()->select(); - $select->from(array('t1' => $table), 'entity_id'); - $conditionData = array(); - - if (is_array($conditionValue)) { - if (isset($conditionValue['in'])){ - $conditionData[] = array('IN (?)', $conditionValue['in']); - } - elseif (isset($conditionValue['in_set'])) { - $conditionData[] = array('REGEXP \'(^|,)('.join('|', $conditionValue['in_set']).')(,|$)\'', $conditionValue['in_set']); - } - elseif (isset($conditionValue['like'])) { - $this->addBindParam($bindVarName, $conditionValue['like']); - $conditionData[] = 'LIKE :'.$bindVarName; - } - elseif (isset($conditionValue['from']) && isset($conditionValue['to'])) { - if ($conditionValue['from']) { - if (!is_numeric($conditionValue['from'])){ - $conditionValue['from'] = date("Y-m-d H:i:s", strtotime($conditionValue['from'])); - } - $conditionData[] = array('>= ?', $conditionValue['from']); - } - if ($conditionValue['to']) { - if (!is_numeric($conditionValue['to'])){ - $conditionValue['to'] = date("Y-m-d H:i:s", strtotime($conditionValue['to'])); - } - $conditionData[] = array('<= ?', $conditionValue['to']); - } - } - } else { - $conditionData[] = array('= ?', $conditionValue); - } - - if (!is_numeric($attributeId)) { - foreach ($conditionData as $data) { - if (is_array($data)) { - $select->where('t1.'.$attributeId . ' ' . $data[0], $data[1]); - } - else { - $select->where('t1.'.$attributeId . ' ' . $data); - } - } - } - else { - $storeId = $this->getStoreId(); - $select->joinLeft( - array('t2' => $table), - $this->getConnection()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $storeId), - array() - ); - $select->where('t1.store_id = ?', 0); - $select->where('t1.attribute_id = ?', $attributeId); - - foreach ($conditionData as $data) { - if (is_array($data)) { - $select->where('IF(t2.value_id>0, t2.value, t1.value) ' . $data[0], $data[1]); - } - else { - $select->where('IF(t2.value_id>0, t2.value, t1.value) ' . $data); - } - } - } - - if (!is_null($previousSelect)) { - $select->where('t1.entity_id IN(?)', new Zend_Db_Expr($previousSelect)); - } - $previousSelect = $select; - } - } - - $this->addFieldToFilter('entity_id', array('in' => new Zend_Db_Expr($select))); - } - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogSearch + * @author Magento Core Team + */ +class Mage_CatalogSearch_Model_Mysql4_Advanced_Collection extends Mage_CatalogSearch_Model_Resource_Advanced_Collection +{ } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php index cbae791168..7c1e2970b9 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext.php @@ -20,701 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CatalogSearch Fulltext Index resource model * - * @category Mage - * @package Mage_CatalogSearch - * @author Magento Core Team + * @category Mage + * @package Mage_CatalogSearch + * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Fulltext extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogSearch_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Resource_Fulltext { - /** - * Searchable attributes cache - * - * @var array - */ - protected $_searchableAttributes = null; - - /** - * Index values separator - * - * @var string - */ - protected $_separator = '|'; - - /** - * Array of Zend_Date objects per store - * - * @var array - */ - protected $_dates = array(); - - /** - * Product Type Instances cache - * - * @var array - */ - protected $_productTypes = array(); - - /** - * Store search engine instance - * @var object - */ - protected $_engine = null; - - /** - * Init resource model - */ - protected function _construct() - { - $this->_init('catalogsearch/fulltext', 'product_id'); - $this->_engine = Mage::helper('catalogsearch')->getEngine(); - } - - /** - * Return options separator - * - * @return string - */ - public function getSeparator() - { - return $this->_separator; - } - - /** - * Update category'es products indexes - * - * @param array $productIds - * @param array $categoryIds - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - public function updateCategoryIndex($productIds, $categoryIds) - { - if ($this->_engine && $this->_engine->allowAdvancedIndex()) { - $this->_engine->updateCategoryIndex($productIds, $categoryIds); - } - - return $this; - } - - /** - * Regenerate search index for store(s) - * - * @param int $storeId Store View Id - * @param int|array $productIds Product Entity Id(s) - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - public function rebuildIndex($storeId = null, $productIds = null) - { - if (is_null($storeId)) { - foreach (Mage::app()->getStores(false) as $store) { - $this->_rebuildStoreIndex($store->getId(), $productIds); - } - } else { - $this->_rebuildStoreIndex($storeId, $productIds); - } - return $this; - } - - /** - * Regenerate search index for specific store - * - * @param int $storeId Store View Id - * @param int|array $productIds Product Entity Id - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - protected function _rebuildStoreIndex($storeId, $productIds = null) - { - $this->cleanIndex($storeId, $productIds); - - // prepare searchable attributes - $staticFields = array(); - foreach ($this->_getSearchableAttributes('static') as $attribute) { - $staticFields[] = $attribute->getAttributeCode(); - } - $dynamicFields = array( - 'int' => array_keys($this->_getSearchableAttributes('int')), - 'varchar' => array_keys($this->_getSearchableAttributes('varchar')), - 'text' => array_keys($this->_getSearchableAttributes('text')), - 'decimal' => array_keys($this->_getSearchableAttributes('decimal')), - 'datetime' => array_keys($this->_getSearchableAttributes('datetime')), - ); - - // status and visibility filter - $visibility = $this->_getSearchableAttribute('visibility'); - $status = $this->_getSearchableAttribute('status'); - $visibilityVals = Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds(); - $statusVals = Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(); - - $lastProductId = 0; - while (true) { - $products = $this->_getSearchableProducts($storeId, $staticFields, $productIds, $lastProductId); - if (!$products) { - break; - } - - $productAttributes = array(); - $productRelations = array(); - foreach ($products as $productData) { - $lastProductId = $productData['entity_id']; - $productAttributes[$productData['entity_id']] = $productData['entity_id']; - $productChilds = $this->_getProductChildIds($productData['entity_id'], $productData['type_id']); - $productRelations[$productData['entity_id']] = $productChilds; - if ($productChilds) { - foreach ($productChilds as $productChildId) { - $productAttributes[$productChildId] = $productChildId; - } - } - } - - $productIndexes = array(); - $productAttributes = $this->_getProductAttributes($storeId, $productAttributes, $dynamicFields); - foreach ($products as $productData) { - /* - * If using advanced index and there is no required fields - do not add to index. - * Skipping out of stock products if there are no prices for them in catalog_product_index_price table - */ - if ($this->_engine->allowAdvancedIndex() && - (!isset($productData[$this->_engine->getFieldsPrefix() . 'categories']))) { - continue; - } - if (!isset($productAttributes[$productData['entity_id']])) { - continue; - } - - $protductAttr = $productAttributes[$productData['entity_id']]; - if (!isset($protductAttr[$visibility->getId()]) - || (!in_array($protductAttr[$visibility->getId()], $visibilityVals) - && !$this->_engine->allowAdvancedIndex() - ) - ) { - continue; - } - if (!isset($protductAttr[$status->getId()]) || !in_array($protductAttr[$status->getId()], $statusVals)) { - continue; - } - - $productIndex = array( - $productData['entity_id'] => $protductAttr - ); - if ($productChilds = $productRelations[$productData['entity_id']]) { - foreach ($productChilds as $productChildId) { - if (isset($productAttributes[$productChildId])) { - $productIndex[$productChildId] = $productAttributes[$productChildId]; - } - } - } - - $index = $this->_prepareProductIndex($productIndex, $productData, $storeId); - - $productIndexes[$productData['entity_id']] = $index; - //$this->_saveProductIndex($productData['entity_id'], $storeId, $index); - } - $this->_saveProductIndexes($storeId, $productIndexes); - } - - $this->resetSearchResults(); - - return $this; - } - - /** - * Retrieve searchable products per store - * - * @param int $storeId - * @param array $staticFields - * @param array|int $productIds - * @param int $lastProductId - * @param int $limit - * @return array - */ - protected function _getSearchableProducts($storeId, array $staticFields, $productIds = null, $lastProductId = 0, $limit = 100) - { - $store = Mage::app()->getStore($storeId); - $select = $this->_getWriteAdapter()->select() - ->useStraightJoin(true) - ->from( - array('e' => $this->getTable('catalog/product')), - array_merge(array('entity_id', 'type_id'), $staticFields)) - ->join( - array('website' => $this->getTable('catalog/product_website')), - $this->_getWriteAdapter()->quoteInto('website.product_id=e.entity_id AND website.website_id=?', $store->getWebsiteId()), - array() - ) - ->join( - array('stock_status' => $this->getTable('cataloginventory/stock_status')), - $this->_getWriteAdapter()->quoteInto('stock_status.product_id=e.entity_id AND stock_status.website_id=?', $store->getWebsiteId()), - array('in_stock' => 'stock_status') - ); - - if (!is_null($productIds)) { - $select->where('e.entity_id IN(?)', $productIds); - } - - $select->where('e.entity_id>?', $lastProductId) - ->limit($limit) - ->order('e.entity_id'); - - $result = $this->_getWriteAdapter()->fetchAll($select); - if ($this->_engine && $this->_engine->allowAdvancedIndex() && count($result) > 0) { - return $this->_engine->addAdvancedIndex($result, $storeId, $productIds); - } else { - return $result; - } - } - - /** - * Reset search results - * - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - public function resetSearchResults() - { - $this->beginTransaction(); - try { - $this->_getWriteAdapter()->update($this->getTable('catalogsearch/search_query'), array('is_processed' => 0)); - $this->_getWriteAdapter()->query('TRUNCATE TABLE ' . $this->getTable('catalogsearch/result')); - - $this->commit(); - } - catch (Exception $e) { - $this->rollBack(); - throw $e; - } - - Mage::dispatchEvent('catalogsearch_reset_search_result'); - - return $this; - } - - /** - * Delete search index data for store - * - * @param int $storeId Store View Id - * @param int $productId Product Entity Id - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - public function cleanIndex($storeId = null, $productId = null) - { - if ($this->_engine) { - $this->_engine->cleanIndex($storeId, $productId); - } - return $this; - } - - /** - * Prepare results for query - * - * @param Mage_CatalogSearch_Model_Fulltext $object - * @param string $queryText - * @param Mage_CatalogSearch_Model_Query $query - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - public function prepareResult($object, $queryText, $query) - { - if (!$query->getIsProcessed()) { - $searchType = $object->getSearchType($query->getStoreId()); - - $stringHelper = Mage::helper('core/string'); - /* @var $stringHelper Mage_Core_Helper_String */ - - $bind = array( - ':query' => $queryText - ); - $like = array(); - - $fulltextCond = ''; - $likeCond = ''; - $separateCond = ''; - - if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE - || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) { - $words = $stringHelper->splitWords($queryText, true, $query->getMaxQueryWords()); - $likeI = 0; - foreach ($words as $word) { - $like[] = '`s`.`data_index` LIKE :likew' . $likeI; - $bind[':likew' . $likeI] = '%' . $word . '%'; - $likeI ++; - } - if ($like) { - $likeCond = '(' . join(' OR ', $like) . ')'; - } - } - if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT - || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) { - $fulltextCond = 'MATCH (`s`.`data_index`) AGAINST (:query IN BOOLEAN MODE)'; - } - if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE && $likeCond) { - $separateCond = ' OR '; - } - - $sql = sprintf("INSERT INTO `{$this->getTable('catalogsearch/result')}` " - . "(SELECT STRAIGHT_JOIN '%d', `s`.`product_id`, MATCH (`s`.`data_index`) " - . "AGAINST (:query IN BOOLEAN MODE) FROM `{$this->getMainTable()}` AS `s` " - . "INNER JOIN `{$this->getTable('catalog/product')}` AS `e` " - . "ON `e`.`entity_id`=`s`.`product_id` WHERE (%s%s%s) AND `s`.`store_id`='%d')" - . " ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)", - $query->getId(), - $fulltextCond, - $separateCond, - $likeCond, - $query->getStoreId() - ); - - $this->_getWriteAdapter()->query($sql, $bind); - - $query->setIsProcessed(1); - } - - return $this; - } - - /** - * Retrieve EAV Config Singleton - * - * @return Mage_Eav_Model_Config - */ - public function getEavConfig() - { - return Mage::getSingleton('eav/config'); - } - - /** - * Retrieve Searchable attributes - * - * @return array - */ - protected function _getSearchableAttributes($backendType = null) - { - if (is_null($this->_searchableAttributes)) { - $this->_searchableAttributes = array(); - - $entityType = $this->getEavConfig()->getEntityType('catalog_product'); - $entity = $entityType->getEntity(); - - $productAttributeCollection = Mage::getResourceModel('catalog/product_attribute_collection') - ->setEntityTypeFilter($entityType->getEntityTypeId()); - if ($this->_engine && $this->_engine->allowAdvancedIndex()) { - $productAttributeCollection->addToIndexFilter(true); - } else { - $productAttributeCollection->addSearchableAttributeFilter(); - } - $attributes = $productAttributeCollection->getItems(); - - foreach ($attributes as $attribute) { - $attribute->setEntity($entity); - $this->_searchableAttributes[$attribute->getId()] = $attribute; - } - } - - if (!is_null($backendType)) { - $attributes = array(); - foreach ($this->_searchableAttributes as $attribute) { - if ($attribute->getBackendType() == $backendType) { - $attributes[$attribute->getId()] = $attribute; - } - } - - return $attributes; - } - - return $this->_searchableAttributes; - } - - /** - * Retrieve searchable attribute by Id or code - * - * @param int|string $attribute - * @return Mage_Eav_Model_Entity_Attribute - */ - protected function _getSearchableAttribute($attribute) - { - $attributes = $this->_getSearchableAttributes(); - if (is_numeric($attribute)) { - if (isset($attributes[$attribute])) { - return $attributes[$attribute]; - } - } - elseif (is_string($attribute)) { - foreach ($attributes as $attributeModel) { - if ($attributeModel->getAttributeCode() == $attribute) { - return $attributeModel; - } - } - } - return $this->getEavConfig()->getAttribute('catalog_product', $attribute); - } - - /** - * Load product(s) attributes - * - * @param int $storeId - * @param array $productIds - * @param array $atributeTypes - * - * @return array - */ - protected function _getProductAttributes($storeId, array $productIds, array $atributeTypes) - { - $result = array(); - $selects = array(); - foreach ($atributeTypes as $backendType => $attributeIds) { - if ($attributeIds) { - $tableName = $this->getTable('catalog/product') . '_' . $backendType; - $selects[] = $this->_getWriteAdapter()->select() - ->from( - array('t_default' => $tableName), - array('entity_id', 'attribute_id')) - ->joinLeft( - array('t_store' => $tableName), - $this->_getWriteAdapter()->quoteInto("t_default.entity_id=t_store.entity_id AND t_default.attribute_id=t_store.attribute_id AND t_store.store_id=?", $storeId), - array('value'=>'IF(t_store.value_id > 0, t_store.value, t_default.value)')) - ->where('t_default.store_id=?', 0) - ->where('t_default.attribute_id IN(?)', $attributeIds) - ->where('t_default.entity_id IN(?)', $productIds); - } - } - - if ($selects) { - $select = '('.join(')UNION(', $selects).')'; - $query = $this->_getWriteAdapter()->query($select); - while ($row = $query->fetch()) { - $result[$row['entity_id']][$row['attribute_id']] = $row['value']; - } - } - - return $result; - } - - /** - * Retrieve Product Type Instance - * - * @param string $typeId - * @return Mage_Catalog_Model_Product_Type_Abstract - */ - protected function _getProductTypeInstance($typeId) - { - if (!isset($this->_productTypes[$typeId])) { - $productEmulator = $this->_getProductEmulator(); - $productEmulator->setTypeId($typeId); - - $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type') - ->factory($productEmulator); - } - return $this->_productTypes[$typeId]; - } - - /** - * Return all product children ids - * - * @param int $productId Product Entity Id - * @param string $typeId Super Product Link Type - * @return array - */ - protected function _getProductChildIds($productId, $typeId) - { - $typeInstance = $this->_getProductTypeInstance($typeId); - $relation = $typeInstance->isComposite() - ? $typeInstance->getRelationInfo() - : false; - - if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) { - $select = $this->_getReadAdapter()->select() - ->from( - array('main' => $this->getTable($relation->getTable())), - array($relation->getChildFieldName())) - ->where("{$relation->getParentFieldName()}=?", $productId); - if (!is_null($relation->getWhere())) { - $select->where($relation->getWhere()); - } - return $this->_getReadAdapter()->fetchCol($select); - } - - return null; - } - - /** - * Retrieve Product Emulator (Varien Object) - * - * @return Varien_Object - */ - protected function _getProductEmulator() - { - $productEmulator = new Varien_Object(); - $productEmulator->setIdFieldName('entity_id'); - return $productEmulator; - } - - /** - * Prepare Fulltext index value for product - * - * @param array $indexData - * @param array $productData - * @return string - */ - protected function _prepareProductIndex($indexData, $productData, $storeId) - { - $index = array(); - - foreach ($this->_getSearchableAttributes('static') as $attribute) { - if (isset($productData[$attribute->getAttributeCode()])) { - if ($value = $this->_getAttributeValue($attribute->getId(), $productData[$attribute->getAttributeCode()], $storeId)) { - - //For grouped products - if (isset($index[$attribute->getAttributeCode()])) { - if (!is_array($index[$attribute->getAttributeCode()])) { - $index[$attribute->getAttributeCode()] = array($index[$attribute->getAttributeCode()]); - } - $index[$attribute->getAttributeCode()][] = $value; - } - //For other types of products - else { - $index[$attribute->getAttributeCode()] = $value; - } - } - } - } - - foreach ($indexData as $attributeData) { - foreach ($attributeData as $attributeId => $attributeValue) { - $value = $this->_getAttributeValue($attributeId, $attributeValue, $storeId); - if (!is_null($value) && $value !== false) { - $code = $this->_getSearchableAttribute($attributeId)->getAttributeCode(); - //For grouped products - if (isset($index[$code])) { - if (!is_array($index[$code])) { - $index[$code] = array($index[$code]); - } - $index[$code][] = $value; - } - //For other types of products - else { - $index[$code] = $value; - } - } - } - } - - $product = $this->_getProductEmulator() - ->setId($productData['entity_id']) - ->setTypeId($productData['type_id']) - ->setStoreId($storeId); - $typeInstance = $this->_getProductTypeInstance($productData['type_id']); - if ($data = $typeInstance->getSearchableData($product)) { - $index['options'] = $data; - } - - if (isset($productData['in_stock'])) { - $index['in_stock'] = $productData['in_stock']; - } - - if ($this->_engine) { - if ($this->_engine->allowAdvancedIndex()) { - $index += $this->_engine->addAllowedAdvancedIndexField($productData); - } - - return $this->_engine->prepareEntityIndex($index, $this->_separator); - } - - return Mage::helper('catalogsearch')->prepareIndexdata($index, $this->_separator); - } - - /** - * Retrieve attribute source value for search - * - * @param int $attributeId - * @param mixed $value - * @return mixed - */ - protected function _getAttributeValue($attributeId, $value, $storeId) - { - $attribute = $this->_getSearchableAttribute($attributeId); - if (!($attribute->getIsSearchable() || - $attribute->getIsVisibleInAdvancedSearch() || - $attribute->getIsFilterable() || - $attribute->getIsFilterableInSearch())) { - return null; - } - if ($attribute->usesSource()) { - $attribute->setStoreId($storeId); - $value = $attribute->getSource()->getOptionText($value); - } - if ($attribute->getBackendType() == 'datetime') { - $value = $this->_getStoreDate($storeId, $value); - } - if ($attribute->getFrontend()->getInputType() == 'price') { - $value = Mage::app()->getStore($storeId)->roundPrice($value); - } - - if (is_array($value)) { - $value = implode($this->_separator, $value); - } - - return preg_replace("#\s+#siu", ' ', trim(strip_tags($value))); - } - - /** - * Save Product index - * - * @param int $productId - * @param int $storeId - * @param string $index - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - protected function _saveProductIndex($productId, $storeId, $index) - { - if ($this->_engine) { - $this->_engine->saveEntityIndex($productId, $storeId, $index); - } - return $this; - } - - /** - * Save Multiply Product indexes - * - * @param int $storeId - * @param array $productIndexes - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext - */ - protected function _saveProductIndexes($storeId, $productIndexes) - { - if ($this->_engine) { - $this->_engine->saveEntityIndexes($storeId, $productIndexes); - } - return $this; - } - - /** - * Retrieve Date value for store - * - * @param int $storeId - * @param string $date - * @return string - */ - protected function _getStoreDate($storeId, $date = null) - { - if (!isset($this->_dates[$storeId])) { - $timezone = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $storeId); - $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId); - $locale = new Zend_Locale($locale); - - $dateObj = new Zend_Date(null, null, $locale); - $dateObj->setTimezone($timezone); - $this->_dates[$storeId] = array($dateObj, $locale->getTranslation(null, 'date', $locale)); - } - - if (!is_empty_date($date)) { - list($dateObj, $format) = $this->_dates[$storeId]; - $dateObj->setDate($date, Varien_Date::DATETIME_INTERNAL_FORMAT); - - return $dateObj->toString($format); - } - - return null; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Collection.php index 62becceb7d..a47aa7a1fd 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Collection.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Collection.php @@ -20,71 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogSearch + * @author Magento Core Team + */ +class Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection extends Mage_CatalogSearch_Model_Resource_Fulltext_Collection { - /** - * Retrieve query model object - * - * @return Mage_CatalogSearch_Model_Query - */ - protected function _getQuery() - { - return Mage::helper('catalogsearch')->getQuery(); - } - - /** - * Add search query filter - * - * @param string $query - * @return Mage_CatalogSearch_Model_Mysql4_Search_Collection - */ - public function addSearchFilter($query) - { - Mage::getSingleton('catalogsearch/fulltext')->prepareResult(); - - $this->getSelect()->joinInner( - array('search_result' => $this->getTable('catalogsearch/result')), - $this->getConnection()->quoteInto( - 'search_result.product_id=e.entity_id AND search_result.query_id=?', - $this->_getQuery()->getId() - ), - array('relevance' => 'relevance') - ); - - return $this; - } - - /** - * Set Order field - * - * @param string $attribute - * @param string $dir - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection - */ - public function setOrder($attribute, $dir = 'desc') - { - if ($attribute == 'relevance') { - $this->getSelect()->order("relevance {$dir}"); - } - else { - parent::setOrder($attribute, $dir); - } - return $this; - } - - /** - * Stub method for campatibility with other search engines - * - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection - */ - public function setGeneralDefaultQuery() - { - return $this; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Engine.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Engine.php index ed12edcbdd..189ecaa741 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Engine.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext/Engine.php @@ -20,167 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CatalogSearch Fulltext Index Engine resource model * - * @category Mage - * @package Mage_CatalogSearch - * @author Magento Core Team + * @category Mage + * @package Mage_CatalogSearch + * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine extends Mage_CatalogSearch_Model_Resource_Fulltext_Engine { - /** - * Init resource model - */ - protected function _construct() - { - $this->_init('catalogsearch/fulltext', 'product_id'); - } - - /** - * Add entity data to fulltext search table - * - * @param int $entityId - * @param int $storeId - * @param array $index - * @param string $entity 'product'|'cms' - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine - */ - public function saveEntityIndex($entityId, $storeId, $index, $entity = 'product') - { - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'product_id' => $entityId, - 'store_id' => $storeId, - 'data_index' => $index - )); - return $this; - } - - /** - * Multi add entities data to fulltext search table - * - * @param int $storeId - * @param array $entityIndexes - * @param string $entity 'product'|'cms' - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine - */ - public function saveEntityIndexes($storeId, $entityIndexes, $entity = 'product') - { - $adapter = $this->_getWriteAdapter(); - $data = array(); - $storeId = (int)$storeId; - foreach ($entityIndexes as $entityId => &$index) { - $data[] = array( - 'product_id' => (int)$entityId, - 'store_id' => $storeId, - 'data_index' => $index - ); - } - - if ($data) { - $adapter->insertOnDuplicate($this->getMainTable(), $data, array('data_index')); - } - - return $this; - } - - /** - * Define if current search engine supports advanced index - * - * @return bool - */ - public function allowAdvancedIndex() - { - return false; - } - - /** - * Remove entity data from fulltext search table - * - * @param int $storeId - * @param int $entityId - * @param string $entity 'product'|'cms' - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine - */ - public function cleanIndex($storeId = null, $entityId = null, $entity = 'product') - { - $where = array(); - - if (!is_null($storeId)) { - $where[] = $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId); - } - if (!is_null($entityId)) { - $where[] = $this->_getWriteAdapter()->quoteInto('product_id IN(?)', $entityId); - } - - $this->_getWriteAdapter()->delete($this->getMainTable(), join(' AND ', $where)); - - return $this; - } - - /** - * Prepare index array as a string glued by separator - * - * @param array $index - * @param string $separator - * @return string - */ - public function prepareEntityIndex($index, $separator = ' ') - { - return Mage::helper('catalogsearch')->prepareIndexdata($index, $separator); - } - - /** - * Stub method for compatibility with other search engines - * - * @return null - */ - public function getResourceName() - { - return null; - } - - /** - * Retrieve fulltext search result data collection - * - * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection - */ - public function getResultCollection() - { - return Mage::getResourceModel('catalogsearch/fulltext_collection'); - } - - /** - * Retrieve advanced search result data collection - * - * @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection - */ - public function getAdvancedResultCollection() - { - return Mage::getResourceModel('catalogsearch/advanced_collection'); - } - - /** - * Define if Layered Navigation is allowed - * - * @return bool - */ - public function isLeyeredNavigationAllowed() - { - return true; - } - - /** - * Define if engine is avaliable - * - * @return bool - */ - public function test() - { - return true; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Indexer/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Indexer/Fulltext.php index ac9ae05d17..01ec5e5b57 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Indexer/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Indexer/Fulltext.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,29 +32,7 @@ * @package Mage_CatalogSearch * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Indexer_Fulltext extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogSearch_Model_Mysql4_Indexer_Fulltext extends Mage_CatalogSearch_Model_Resource_Indexer_Fulltext { - /** - * Initialize connection and define catalog product table as main table - */ - protected function _construct() - { - $this->_init('catalogsearch/fulltext', 'product_id'); - } - - /** - * Retrieve product relations by children - * - * @param int|array $childIds - * @return array - */ - public function getRelationsByChild($childIds) - { - $write = $this->_getWriteAdapter(); - $select = $write->select() - ->from($this->getTable('catalog/product_relation'), 'parent_id') - ->where('child_id IN(?)', $childIds); - - return $write->fetchCol($select); - } + } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query.php index c254c9b2c3..2519f125a7 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query.php @@ -20,99 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog search query resource model * + * @category Mage + * @package Mage_CatalogSearch * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Query extends Mage_Core_Model_Mysql4_Abstract +class Mage_CatalogSearch_Model_Mysql4_Query extends Mage_CatalogSearch_Model_Resource_Query { - /** - * Init resource data - * - */ - protected function _construct() - { - $this->_init('catalogsearch/search_query', 'query_id'); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where($this->getMainTable().'.'.$field.'=?', $value); - return $select; - } - - /** - * Custom load model by search query string - * - * @param Mage_Core_Model_Abstract $object - * @param string $value - * @return Mage_CatalogSearch_Model_Mysql4_Query - */ - public function loadByQuery(Mage_Core_Model_Abstract $object, $value) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('synonym_for=? OR query_text=?', $value) - ->where('store_id=?', $object->getStoreId()) - ->order('synonym_for ASC') - ->limit(1); - if ($data = $this->_getReadAdapter()->fetchRow($select)) { - $object->setData($data); - $this->_afterLoad($object); - } - - return $this; - } - - /** - * Custom load model only by query text (skip synonym for) - * - * @param Mage_Core_Model_Abstract $object - * @param string $value - * @return Mage_CatalogSearch_Model_Mysql4_Query - */ - public function loadByQueryText(Mage_Core_Model_Abstract $object, $value) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('query_text = ?', $value) - ->where('store_id = ?', $object->getStoreId()) - ->limit(1); - if ($data = $this->_getReadAdapter()->fetchRow($select)) { - $object->setData($data); - $this->_afterLoad($object); - } - return $this; - } - - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (is_numeric($value)) { - return parent::load($object, $value); - } - else { - $this->loadByQuery($object,$value); - } - return $this; - } - - public function _beforeSave(Mage_Core_Model_Abstract $object) - { - $object->setUpdatedAt($this->formatDate(Mage::getModel('core/date')->gmtTimestamp())); - return $this; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php index 3539033d1a..3429155d0e 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Query/Collection.php @@ -20,130 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Catalog search query collection * + * @category Mage + * @package Mage_CatalogSearch * @author Magento Core Team */ -class Mage_CatalogSearch_Model_Mysql4_Query_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_CatalogSearch_Model_Mysql4_Query_Collection extends Mage_CatalogSearch_Model_Resource_Query_Collection { - /** - * Store for filter - * - * @var int - */ - protected $_storeId; - - /** - * Init model for collection - * - */ - protected function _construct() - { - $this->_init('catalogsearch/query'); - } - - /** - * Set Store ID for filter - * - * @param mixed $store - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection - */ - public function setStoreId($store) - { - if ($store instanceof Mage_Core_Model_Store) { - $store = $store->getId(); - } - $this->_storeId = $store; - return $this; - } - - /** - * Retrieve Store ID Filter - * - * @return int|null - */ - public function getStoreId() - { - return $this->_storeId; - } - - /** - * Set search query text to filter - * - * @param string $query - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection - */ - public function setQueryFilter($query) - { - $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true) - ->from( - array('main_table' => $this->getTable('catalogsearch/search_query')), - array('query' => "IF(IFNULL(synonym_for,'')<>'', synonym_for, query_text)", 'num_results') - ) - ->where('num_results>0 AND display_in_terms=1 AND query_text LIKE ?', $query.'%') - ->order('popularity desc'); - if ($this->getStoreId()) { - $this->getSelect() - ->where('store_id=?', $this->getStoreId()); - } - return $this; - } - - /** - * Set Popular Search Query Filter - * - * @param int|array $storeIds - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection - */ - public function setPopularQueryFilter($storeIds = null) - { - $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true) - ->from( - array('main_table'=>$this->getTable('catalogsearch/search_query')), - array('name'=>"if(ifnull(synonym_for,'')<>'', synonym_for, query_text)", 'num_results') - ); - if ($storeIds) { - $this->addStoreFilter($storeIds); - $this->getSelect()->where('num_results > 0'); - } - elseif (null === $storeIds) { - $this->addStoreFilter(Mage::app()->getStore()->getId()); - $this->getSelect()->where('num_results > 0'); - } - - $this->getSelect()->order(array('popularity desc','name')); - - return $this; - } - - /** - * Set Recent Queries Order - * - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection - */ - public function setRecentQueryFilter() - { - $this->setOrder('updated_at', 'desc'); - return $this; - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection - */ - public function addStoreFilter($storeIds) - { - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); - return $this; - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Search/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Search/Collection.php index 1fcdbd7d76..e05f0870a7 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Mysql4/Search/Collection.php +++ b/app/code/core/Mage/CatalogSearch/Model/Mysql4/Search/Collection.php @@ -20,197 +20,18 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_CatalogSearch_Model_Mysql4_Search_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +/** + * Enter description here ... + * + * @category Mage + * @package Mage_CatalogSearch + * @author Magento Core Team + */ +class Mage_CatalogSearch_Model_Mysql4_Search_Collection extends Mage_CatalogSearch_Model_Resource_Search_Collection { - protected $_attributesCollection; - protected $_searchQuery; - - /** - * Add search query filter - * - * @param string $query - * @return Mage_CatalogSearch_Model_Mysql4_Search_Collection - */ - public function addSearchFilter($query) - { - $this->_searchQuery = '%'.$query.'%'; - $this->addFieldToFilter('entity_id', array('in'=>new Zend_Db_Expr($this->_getSearchEntityIdsSql($query)))); - return $this; - } - - /** - * Retrieve collection of all attributes - * - * @return Varien_Data_Collection_Db - */ - protected function _getAttributesCollection() - { - if (!$this->_attributesCollection) { - $this->_attributesCollection = Mage::getResourceModel('catalog/product_attribute_collection') - ->load(); - - foreach ($this->_attributesCollection as $attribute) { - $attribute->setEntity($this->getEntity()); - } - } - return $this->_attributesCollection; - } - - protected function _isAttributeTextAndSearchable($attribute) - { - if (($attribute->getIsSearchable() && !in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) - && (in_array($attribute->getBackendType(), array('varchar', 'text')) || $attribute->getBackendType() == 'static')) { - return true; - } - return false; - } - - protected function _hasAttributeOptionsAndSearchable($attribute) - { - if ($attribute->getIsSearchable() && in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) { - return true; - } - - return false; - } - - protected function _getSearchEntityIdsSql($query) - { - $tables = array(); - $selects = array(); - /** - * Collect tables and attribute ids of attributes with string values - */ - foreach ($this->_getAttributesCollection() as $attribute) { - if ($this->_isAttributeTextAndSearchable($attribute)) { - $table = $attribute->getBackend()->getTable(); - if (!isset($tables[$table]) && $attribute->getBackendType() != 'static') { - $tables[$table] = array(); - } - - if ($attribute->getBackendType() == 'static') { - $param = $attribute->getAttributeCode().'_search_query'; - $selects[] = $this->getConnection()->select() - ->from($table, 'entity_id') - ->where($attribute->getAttributeCode().' LIKE :'.$param); - $this->addBindParam($param, $this->_searchQuery); - } else { - $tables[$table][] = $attribute->getId(); - } - } - } - - foreach ($tables as $table => $attributeIds) { - $param = $table.'_search_query'; - $selects[] = $this->getConnection()->select() - ->from(array('t1' => $table), 'entity_id') - ->joinLeft( - array('t2' => $table), - $this->getConnection()->quoteInto('t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id=?', $this->getStoreId()), - array() - ) - ->where('t1.attribute_id IN (?)', $attributeIds) - ->where('t1.store_id = ?', 0) - ->where('IF(t2.value_id>0, t2.value, t1.value) LIKE :'.$param); - $this->addBindParam($param, $this->_searchQuery); - } - - if ($sql = $this->_getSearchInOptionSql($query)) { - $selects[] = "SELECT * FROM ({$sql}) AS inoptionsql"; // inheritant unions may be inside - } - $sql = implode(' UNION ', $selects); - return $sql; - } - - /** - * Retrieve SQL for search entities by option - * - * @param unknown_type $query - * @return string - */ - protected function _getSearchInOptionSql($query) - { - $attributeIds = array(); - $attributeTables = array(); - $storeId = (int)$this->getStoreId(); - - /** - * Collect attributes with options - */ - foreach ($this->_getAttributesCollection() as $attribute) { - if ($this->_hasAttributeOptionsAndSearchable($attribute)) { - $attributeTables[$attribute->getFrontendInput()] = $attribute->getBackend()->getTable(); - $attributeIds[] = $attribute->getId(); - } - } - if (empty($attributeIds)) { - return false; - } - - $resource = Mage::getSingleton('core/resource'); - $optionTable = $resource->getTableName('eav/attribute_option'); - $optionValueTable = $resource->getTableName('eav/attribute_option_value'); - $attributesTable = $resource->getTableName('eav/attribute'); - - /** - * Select option Ids - */ - $select = $this->getConnection()->select() - ->from(array('default'=>$optionValueTable), array('option_id','option.attribute_id', 'store_id'=>'IFNULL(store.store_id, default.store_id)', 'a.frontend_input')) - ->joinLeft(array('store'=>$optionValueTable), - $this->getConnection()->quoteInto('store.option_id=default.option_id AND store.store_id=?', $storeId), - array()) - ->join(array('option'=>$optionTable), - 'option.option_id=default.option_id', - array()) - ->join(array('a' => $attributesTable), 'option.attribute_id=a.attribute_id', array()) - ->where('default.store_id=0') - ->where('option.attribute_id IN (?)', $attributeIds) - ->where('IF(store.value_id>0, store.value, default.value) LIKE :search_query'); - $options = $this->getConnection()->fetchAll($select, array('search_query'=>$this->_searchQuery)); - if (empty($options)) { - return false; - } - - // build selects of entity ids for specified options ids by frontend input - $select = array(); - foreach (array( - 'select' => 'value = %d', - 'multiselect' => 'FIND_IN_SET(%d, value)') - as $frontendInput => $condition) { - if (isset($attributeTables[$frontendInput])) { - $where = array(); - foreach ($options as $option) { - if ($frontendInput === $option['frontend_input']) { - $where[] = sprintf("attribute_id=%d AND store_id=%d AND {$condition}", $option['attribute_id'], $option['store_id'], $option['option_id']); - } - } - if ($where) { - $select[$frontendInput] = (string)$this->getConnection()->select() - ->from($attributeTables[$frontendInput], 'entity_id') - ->where(implode(' OR ', $where)); - } - } - } - - // search in catalogindex for products as part of configurable/grouped/bundle products (current store) - $where = array(); - foreach ($options as $option) { - $where[] = sprintf('attribute_id=%d AND value=%d', $option['attribute_id'], $option['option_id']); - } - if ($where) { - $select[] = (string)$this->getConnection()->select() - ->from($resource->getTableName('catalogindex/eav'), 'entity_id') - ->where(implode(' OR ', $where)) - ->where("store_id={$storeId}"); - } - - return implode(' UNION ', $select); - } } diff --git a/app/code/core/Mage/CatalogSearch/Model/Query.php b/app/code/core/Mage/CatalogSearch/Model/Query.php index ffe7b315f5..2832eb13b3 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Query.php +++ b/app/code/core/Mage/CatalogSearch/Model/Query.php @@ -20,13 +20,36 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog search query model * + * @method Mage_CatalogSearch_Model_Resource_Query _getResource() + * @method Mage_CatalogSearch_Model_Resource_Query getResource() + * @method string getQueryText() + * @method Mage_CatalogSearch_Model_Query setQueryText(string $value) + * @method int getNumResults() + * @method Mage_CatalogSearch_Model_Query setNumResults(int $value) + * @method int getPopularity() + * @method Mage_CatalogSearch_Model_Query setPopularity(int $value) + * @method string getRedirect() + * @method Mage_CatalogSearch_Model_Query setRedirect(string $value) + * @method string getSynonymFor() + * @method Mage_CatalogSearch_Model_Query setSynonymFor(string $value) + * @method int getDisplayInTerms() + * @method Mage_CatalogSearch_Model_Query setDisplayInTerms(int $value) + * @method int getIsActive() + * @method Mage_CatalogSearch_Model_Query setIsActive(int $value) + * @method int getIsProcessed() + * @method Mage_CatalogSearch_Model_Query setIsProcessed(int $value) + * @method string getUpdatedAt() + * @method Mage_CatalogSearch_Model_Query setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_CatalogSearch * @author Magento Core Team */ class Mage_CatalogSearch_Model_Query extends Mage_Core_Model_Abstract @@ -62,7 +85,7 @@ protected function _construct() /** * Retrieve search collection * - * @return Mage_CatalogSearch_Model_Mysql4_Search_Collection + * @return Mage_CatalogSearch_Model_Resource_Search_Collection */ public function getSearchCollection() { @@ -97,7 +120,7 @@ public function getResultCollection() /** * Retrieve collection of suggest queries * - * @return Mage_CatalogSearch_Model_Mysql4_Query_Collection + * @return Mage_CatalogSearch_Model_Resource_Query_Collection */ public function getSuggestCollection() { diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php new file mode 100755 index 0000000000..6346123bda --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced.php @@ -0,0 +1,193 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Advanced extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define catalog product table as main table + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Prepare response object and dispatch prepare price event + * Return response object + * + * @param Varien_Db_Select $select + * @return Varien_Object + */ + protected function _dispatchPreparePriceEvent($select) + { + // prepare response object for event + $response = new Varien_Object(); + $response->setAdditionalCalculations(array()); + + // prepare event arguments + $eventArgs = array( + 'select' => $select, + 'table' => 'price_index', + 'store_id' => Mage::app()->getStore()->getId(), + 'response_object' => $response + ); + + Mage::dispatchEvent('catalog_prepare_price_select', $eventArgs); + + return $response; + } + + /** + * Prepare search condition for attribute + * + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @param string|array $value + * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection + * @return mixed + */ + public function prepareCondition($attribute, $value, $collection) + { + $condition = false; + + if (is_array($value)) { + if (!empty($value['from']) || !empty($value['to'])) { // range + $condition = $value; + } else if ($attribute->getBackendType() == 'varchar') { // multiselect + $condition = array('in_set' => $value); + } else if (!isset($value['from']) && !isset($value['to'])) { // select + $condition = array('in' => $value); + } + } else { + if (strlen($value) > 0) { + if (in_array($attribute->getBackendType(), array('varchar', 'text', 'static'))) { + $condition = array('like' => '%' . $value . '%'); // text search + } else { + $condition = $value; + } + } + } + + return $condition; + } + + /** + * Add filter by attribute rated price + * + * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @param string|array $value + * @param int $rate + * @return bool + */ + public function addRatedPriceFilter($collection, $attribute, $value, $rate = 1) + { + $adapter = $this->_getReadAdapter(); + + $conditions = array(); + if (strlen($value['from']) > 0) { + $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s >= ?', $value['from']); + } + if (strlen($value['to']) > 0) { + $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s <= ?', $value['to']); + } + + if (!$conditions) { + return false; + } + + $collection->addPriceData(); + $select = $collection->getSelect(); + $response = $this->_dispatchPreparePriceEvent($select); + $additional = join('', $response->getAdditionalCalculations()); + + foreach ($conditions as $condition) { + $select->where(sprintf($condition, $additional, $rate)); + } + + return true; + } + + /** + * Add filter by indexable attribute + * + * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection + * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @param string|array $value + * @return bool + */ + public function addIndexableAttributeModifiedFilter($collection, $attribute, $value) + { + if ($attribute->getIndexType() == 'decimal') { + $table = $this->getTable('catalog/product_index_eav_decimal'); + } else { + $table = $this->getTable('catalog/product_index_eav'); + } + + $tableAlias = 'a_' . $attribute->getAttributeId(); + $storeId = Mage::app()->getStore()->getId(); + $select = $collection->getSelect(); + + if (is_array($value)) { + if (isset($value['from']) && isset($value['to'])) { + if (empty($value['from']) && empty($value['to'])) { + return false; + } + } + } + + $select->distinct(true); + $select->join( + array($tableAlias => $table), + "e.entity_id={$tableAlias}.entity_id " + . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" + . " AND {$tableAlias}.store_id={$storeId}", + array() + ); + + if (is_array($value) && (isset($value['from']) || isset($value['to']))) { + if (isset($value['from']) && !empty($value['from'])) { + $select->where("{$tableAlias}.value >= ?", $value['from']); + } + if (isset($value['to']) && !empty($value['to'])) { + $select->where("{$tableAlias}.value <= ?", $value['to']); + } + return true; + } + + $select->where("{$tableAlias}.value IN(?)", $value); + + return true; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced/Collection.php new file mode 100755 index 0000000000..ab1cba2a33 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Advanced/Collection.php @@ -0,0 +1,130 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Advanced_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Add not indexable fields to search + * + * @param array $fields + * @return Mage_CatalogSearch_Model_Resource_Advanced_Collection + */ + public function addFieldsToFilter($fields) + { + if ($fields) { + $previousSelect = null; + $conn = $this->getConnection(); + foreach ($fields as $table => $conditions) { + foreach ($conditions as $attributeId => $conditionValue) { + $select = $conn->select(); + $select->from(array('t1' => $table), 'entity_id'); + $conditionData = array(); + + if (!is_numeric($attributeId)) { + $field = 't1.'.$attributeId; + } + else { + $storeId = $this->getStoreId(); + $onCondition = 't1.entity_id = t2.entity_id' + . ' AND t1.attribute_id = t2.attribute_id' + . ' AND t2.store_id=?'; + + $select->joinLeft( + array('t2' => $table), + $conn->quoteInto($onCondition, $storeId), + array() + ); + $select->where('t1.store_id = ?', 0); + $select->where('t1.attribute_id = ?', $attributeId); + + if (array_key_exists('price_index', $this->getSelect()->getPart(Varien_Db_Select::FROM))) { + $select->where('t1.entity_id = price_index.entity_id'); + } + + $field = $this->getConnection()->getCheckSql('t2.value_id>0', 't2.value', 't1.value'); + + } + + if (is_array($conditionValue)) { + if (isset($conditionValue['in'])){ + $conditionData[] = array('in' => $conditionValue['in']); + } + elseif (isset($conditionValue['in_set'])) { + $conditionParts = array(); + foreach ($conditionValue['in_set'] as $value) { + $conditionParts[] = array('finset' => $value); + } + $conditionData[] = $conditionParts; + } + elseif (isset($conditionValue['like'])) { + $conditionData[] = array ('like' => $conditionValue['like']); + } + elseif (isset($conditionValue['from']) && isset($conditionValue['to'])) { + if ($conditionValue['from']) { + if (!is_numeric($conditionValue['from'])){ + $conditionValue['from'] = Mage::getSingleton('core/date') + ->gmtDate(null, $conditionValue['from']); + } + $conditionData[] = array('gteq' => $conditionValue['from']); + } + if ($conditionValue['to']) { + if (!is_numeric($conditionValue['to'])){ + $conditionValue['to'] = Mage::getSingleton('core/date') + ->gmtDate(null, $conditionValue['to']); + } + $conditionData[] = array('lteq' => $conditionValue['to']); + } + + } + } else { + $conditionData[] = array('eq' => $conditionValue); + } + + + foreach ($conditionData as $data) { + $select->where($conn->prepareSqlCondition($field, $data)); + } + + if (!is_null($previousSelect)) { + $select->where('t1.entity_id IN (?)', new Zend_Db_Expr($previousSelect)); + } + $previousSelect = $select; + } + } + $this->addFieldToFilter('entity_id', array('in' => new Zend_Db_Expr($select))); + } + + return $this; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php new file mode 100755 index 0000000000..71995008c3 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php @@ -0,0 +1,743 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Fulltext extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Searchable attributes cache + * + * @var array + */ + protected $_searchableAttributes = null; + + /** + * Index values separator + * + * @var string + */ + protected $_separator = '|'; + + /** + * Array of Zend_Date objects per store + * + * @var array + */ + protected $_dates = array(); + + /** + * Product Type Instances cache + * + * @var array + */ + protected $_productTypes = array(); + + /** + * Store search engine instance + * + * @var object + */ + protected $_engine = null; + + /** + * Init resource model + * + */ + protected function _construct() + { + $this->_init('catalogsearch/fulltext', 'product_id'); + $this->_engine = Mage::helper('catalogsearch')->getEngine(); + } + + /** + * Return options separator + * + * @return string + */ + public function getSeparator() + { + return $this->_separator; + } + + /** + * Update category'es products indexes + * + * @param array $productIds + * @param array $categoryIds + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + public function updateCategoryIndex($productIds, $categoryIds) + { + if ($this->_engine && $this->_engine->allowAdvancedIndex()) { + $this->_engine->updateCategoryIndex($productIds, $categoryIds); + } + + return $this; + } + + /** + * Regenerate search index for store(s) + * + * @param int $storeId Store View Id + * @param int|array $productIds Product Entity Id(s) + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + public function rebuildIndex($storeId = null, $productIds = null) + { + if (is_null($storeId)) { + foreach (Mage::app()->getStores(false) as $store) { + $this->_rebuildStoreIndex($store->getId(), $productIds); + } + } else { + $this->_rebuildStoreIndex($storeId, $productIds); + } + return $this; + } + + /** + * Regenerate search index for specific store + * + * @param int $storeId Store View Id + * @param int|array $productIds Product Entity Id + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + protected function _rebuildStoreIndex($storeId, $productIds = null) + { + $this->cleanIndex($storeId, $productIds); + + // prepare searchable attributes + $staticFields = array(); + foreach ($this->_getSearchableAttributes('static') as $attribute) { + $staticFields[] = $attribute->getAttributeCode(); + } + $dynamicFields = array( + 'int' => array_keys($this->_getSearchableAttributes('int')), + 'varchar' => array_keys($this->_getSearchableAttributes('varchar')), + 'text' => array_keys($this->_getSearchableAttributes('text')), + 'decimal' => array_keys($this->_getSearchableAttributes('decimal')), + 'datetime' => array_keys($this->_getSearchableAttributes('datetime')), + ); + + // status and visibility filter + $visibility = $this->_getSearchableAttribute('visibility'); + $status = $this->_getSearchableAttribute('status'); + $visibilityVals = Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds(); + $statusVals = Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(); + + $lastProductId = 0; + while (true) { + $products = $this->_getSearchableProducts($storeId, $staticFields, $productIds, $lastProductId); + if (!$products) { + break; + } + + $productAttributes = array(); + $productRelations = array(); + foreach ($products as $productData) { + $lastProductId = $productData['entity_id']; + $productAttributes[$productData['entity_id']] = $productData['entity_id']; + $productChilds = $this->_getProductChildIds($productData['entity_id'], $productData['type_id']); + $productRelations[$productData['entity_id']] = $productChilds; + if ($productChilds) { + foreach ($productChilds as $productChildId) { + $productAttributes[$productChildId] = $productChildId; + } + } + } + + $productIndexes = array(); + $productAttributes = $this->_getProductAttributes($storeId, $productAttributes, $dynamicFields); + foreach ($products as $productData) { + /* + * If using advanced index and there is no required fields - do not add to index. + * Skipping out of stock products if there are no prices for them in catalog_product_index_price table + */ + if ($this->_engine->allowAdvancedIndex() && + (!isset($productData[$this->_engine->getFieldsPrefix() . 'categories']))) { + continue; + } + if (!isset($productAttributes[$productData['entity_id']])) { + continue; + } + + $protductAttr = $productAttributes[$productData['entity_id']]; + if (!isset($protductAttr[$visibility->getId()]) + || (!in_array($protductAttr[$visibility->getId()], $visibilityVals) + && !$this->_engine->allowAdvancedIndex() + ) + ) { + continue; + } + if (!isset($protductAttr[$status->getId()]) || !in_array($protductAttr[$status->getId()], $statusVals)) { + continue; + } + + $productIndex = array( + $productData['entity_id'] => $protductAttr + ); + if ($productChilds = $productRelations[$productData['entity_id']]) { + foreach ($productChilds as $productChildId) { + if (isset($productAttributes[$productChildId])) { + $productIndex[$productChildId] = $productAttributes[$productChildId]; + } + } + } + + $index = $this->_prepareProductIndex($productIndex, $productData, $storeId); + + $productIndexes[$productData['entity_id']] = $index; + //$this->_saveProductIndex($productData['entity_id'], $storeId, $index); + } + $this->_saveProductIndexes($storeId, $productIndexes); + } + + $this->resetSearchResults(); + + return $this; + } + + /** + * Retrieve searchable products per store + * + * @param int $storeId + * @param array $staticFields + * @param array|int $productIds + * @param int $lastProductId + * @param int $limit + * @return array + */ + protected function _getSearchableProducts($storeId, array $staticFields, $productIds = null, $lastProductId = 0, + $limit = 100) + { + $store = Mage::app()->getStore($storeId); + $select = $this->_getWriteAdapter()->select() + ->useStraightJoin(true) + ->from( + array('e' => $this->getTable('catalog/product')), + array_merge(array('entity_id', 'type_id'), $staticFields)) + ->join( + array('website' => $this->getTable('catalog/product_website')), + $this->_getWriteAdapter()->quoteInto('website.product_id=e.entity_id AND website.website_id=?', $store->getWebsiteId()), + array() + ) + ->join( + array('stock_status' => $this->getTable('cataloginventory/stock_status')), + $this->_getWriteAdapter()->quoteInto('stock_status.product_id=e.entity_id AND stock_status.website_id=?', $store->getWebsiteId()), + array('in_stock' => 'stock_status') + ); + + if (!is_null($productIds)) { + $select->where('e.entity_id IN(?)', $productIds); + } + + $select->where('e.entity_id>?', $lastProductId) + ->limit($limit) + ->order('e.entity_id'); + + $result = $this->_getWriteAdapter()->fetchAll($select); + if ($this->_engine && $this->_engine->allowAdvancedIndex() && count($result) > 0) { + return $this->_engine->addAdvancedIndex($result, $storeId, $productIds); + } else { + return $result; + } + } + + /** + * Reset search results + * + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + public function resetSearchResults() + { + + $adapter = $this->_getWriteAdapter(); + $adapter->update($this->getTable('catalogsearch/search_query'), array('is_processed' => 0)); + $adapter->truncateTable($this->getTable('catalogsearch/result')); + + Mage::dispatchEvent('catalogsearch_reset_search_result'); + + return $this; + } + + /** + * Delete search index data for store + * + * @param int $storeId Store View Id + * @param int $productId Product Entity Id + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + public function cleanIndex($storeId = null, $productId = null) + { + if ($this->_engine) { + $this->_engine->cleanIndex($storeId, $productId); + } + return $this; + } + + /** + * Prepare results for query + * + * @param Mage_CatalogSearch_Model_Fulltext $object + * @param string $queryText + * @param Mage_CatalogSearch_Model_Query $query + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + public function prepareResult($object, $queryText, $query) + { + $adapter = $this->_getWriteAdapter(); + if (!$query->getIsProcessed()) { + $searchType = $object->getSearchType($query->getStoreId()); + + $preparedTerms = Mage::getResourceHelper('catalogsearch') + ->prepareTerms($queryText, $query->getMaxQueryWords()); + + $bind = array(); + $like = array(); + $likeCond = ''; + if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE + || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) { + $helper = Mage::getResourceHelper('core'); + foreach ($preparedTerms[1] as $term) { + $like[] = $helper->getCILike('s.data_index', $term, array('position' => 'any')); + } + if ($like) { + $likeCond = '(' . join(' OR ', $like) . ')'; + } + } + $mainTableAlias = 's'; + $fields = array( + 'query_id' => new Zend_Db_Expr($query->getId()), + 'product_id', + ); + $select = $adapter->select() + ->from(array($mainTableAlias => $this->getMainTable()), $fields) + ->joinInner(array('e' => $this->getTable('catalog/product')), + 'e.entity_id = s.product_id', + array()) + ->where($mainTableAlias.'.store_id = ?', (int)$query->getStoreId()); + + if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT + || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) { + $bind[':query'] = implode(' ', $preparedTerms[0]); + $where = Mage::getResourceHelper('catalogsearch') + ->chooseFulltext($this->getMainTable(), $mainTableAlias, $select); + } + if ($likeCond!='' + && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) { + $where .= ($where ? ' OR ' : '') . $likeCond; + } + if ($likeCond!='' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) { + $select->columns(array('relevance' => new Zend_Db_Expr(0))); + $where = $likeCond; + } + if ($where != '') { + $select->where($where); + } + + $sql = $adapter->insertFromSelect($select, + $this->getTable('catalogsearch/result'), + array(), + Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE); + $adapter->query($sql, $bind); + + $query->setIsProcessed(1); + } + + return $this; + } + + /** + * Retrieve EAV Config Singleton + * + * @return Mage_Eav_Model_Config + */ + public function getEavConfig() + { + return Mage::getSingleton('eav/config'); + } + + /** + * Retrieve Searchable attributes + * + * @param string $backendType + * @return array + */ + protected function _getSearchableAttributes($backendType = null) + { + if (is_null($this->_searchableAttributes)) { + $this->_searchableAttributes = array(); + + $entityType = $this->getEavConfig()->getEntityType(Mage_Catalog_Model_Product::ENTITY); + $entity = $entityType->getEntity(); + + $productAttributeCollection = Mage::getResourceModel('catalog/product_attribute_collection') + ->setEntityTypeFilter($entityType->getEntityTypeId()); + if ($this->_engine && $this->_engine->allowAdvancedIndex()) { + $productAttributeCollection->addToIndexFilter(true); + } else { + $productAttributeCollection->addSearchableAttributeFilter(); + } + $attributes = $productAttributeCollection->getItems(); + + foreach ($attributes as $attribute) { + $attribute->setEntity($entity); + $this->_searchableAttributes[$attribute->getId()] = $attribute; + } + } + if (!is_null($backendType)) { + $attributes = array(); + foreach ($this->_searchableAttributes as $attribute) { + if ($attribute->getBackendType() == $backendType) { + $attributes[$attribute->getId()] = $attribute; + } + } + + return $attributes; + } + + return $this->_searchableAttributes; + } + + /** + * Retrieve searchable attribute by Id or code + * + * @param int|string $attribute + * @return Mage_Eav_Model_Entity_Attribute + */ + protected function _getSearchableAttribute($attribute) + { + $attributes = $this->_getSearchableAttributes(); + if (is_numeric($attribute)) { + if (isset($attributes[$attribute])) { + return $attributes[$attribute]; + } + } + elseif (is_string($attribute)) { + foreach ($attributes as $attributeModel) { + if ($attributeModel->getAttributeCode() == $attribute) { + return $attributeModel; + } + } + } + return $this->getEavConfig()->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attribute); + } + + /** + * Returns expresion for field unification + * + * @param string $field + * @param string $backendType + * @return Zend_Db_Expr + */ + protected function _unifyField($field, $backendType = 'varchar') + { + if ($backendType == 'datetime') { + $expr = Mage::getResourceHelper('catalogsearch')->castField( + $this->_getReadAdapter()->getDateFormatSql($field, '%Y-%m-%d %H:%i:%s')); + } else { + $expr = Mage::getResourceHelper('catalogsearch')->castField($field); + } + return $expr; + } + + /** + * Load product(s) attributes + * + * @param int $storeId + * @param array $productIds + * @param array $atributeTypes + * @return array + */ + protected function _getProductAttributes($storeId, array $productIds, array $atributeTypes) + { + $result = array(); + $selects = array(); + $adapter = $this->_getReadAdapter(); + $ifStoreValue = $adapter->getCheckSql('t_store.value_id > 0', 't_store.value', 't_default.value'); + foreach ($atributeTypes as $backendType => $attributeIds) { + if ($attributeIds) { + $tableName = $this->getTable(array('catalog/product', $backendType)); + $selects[] = $adapter->select() + ->from( + array('t_default' => $tableName), + array('entity_id', 'attribute_id')) + ->joinLeft( + array('t_store' => $tableName), + $adapter->quoteInto('t_default.entity_id=t_store.entity_id AND t_default.attribute_id=t_store.attribute_id AND t_store.store_id=?', $storeId), + array('value' => $this->_unifyField($ifStoreValue, $backendType))) + ->where('t_default.store_id=?', 0) + ->where('t_default.attribute_id IN (?)', $attributeIds) + ->where('t_default.entity_id IN (?)', $productIds); + } + } + + if ($selects) { + $select = $adapter->select()->union($selects, Zend_Db_Select::SQL_UNION_ALL); + $query = $adapter->query($select); + while ($row = $query->fetch()) { + $result[$row['entity_id']][$row['attribute_id']] = $row['value']; + } + } + + return $result; + } + + /** + * Retrieve Product Type Instance + * + * @param string $typeId + * @return Mage_Catalog_Model_Product_Type_Abstract + */ + protected function _getProductTypeInstance($typeId) + { + if (!isset($this->_productTypes[$typeId])) { + $productEmulator = $this->_getProductEmulator(); + $productEmulator->setTypeId($typeId); + + $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type') + ->factory($productEmulator); + } + return $this->_productTypes[$typeId]; + } + + /** + * Return all product children ids + * + * @param int $productId Product Entity Id + * @param string $typeId Super Product Link Type + * @return array + */ + protected function _getProductChildIds($productId, $typeId) + { + $typeInstance = $this->_getProductTypeInstance($typeId); + $relation = $typeInstance->isComposite() + ? $typeInstance->getRelationInfo() + : false; + + if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) { + $select = $this->_getReadAdapter()->select() + ->from( + array('main' => $this->getTable($relation->getTable())), + array($relation->getChildFieldName())) + ->where("{$relation->getParentFieldName()}=?", $productId); + if (!is_null($relation->getWhere())) { + $select->where($relation->getWhere()); + } + return $this->_getReadAdapter()->fetchCol($select); + } + + return null; + } + + /** + * Retrieve Product Emulator (Varien Object) + * + * @return Varien_Object + */ + protected function _getProductEmulator() + { + $productEmulator = new Varien_Object(); + $productEmulator->setIdFieldName('entity_id'); + return $productEmulator; + } + + /** + * Prepare Fulltext index value for product + * + * @param array $indexData + * @param array $productData + * @param int $storeId + * @return string + */ + protected function _prepareProductIndex($indexData, $productData, $storeId) + { + $index = array(); + + foreach ($this->_getSearchableAttributes('static') as $attribute) { + if (isset($productData[$attribute->getAttributeCode()])) { + if ($value = $this->_getAttributeValue($attribute->getId(), $productData[$attribute->getAttributeCode()], $storeId)) { + + //For grouped products + if (isset($index[$attribute->getAttributeCode()])) { + if (!is_array($index[$attribute->getAttributeCode()])) { + $index[$attribute->getAttributeCode()] = array($index[$attribute->getAttributeCode()]); + } + $index[$attribute->getAttributeCode()][] = $value; + } + //For other types of products + else { + $index[$attribute->getAttributeCode()] = $value; + } + } + } + } + + foreach ($indexData as $attributeData) { + foreach ($attributeData as $attributeId => $attributeValue) { + $value = $this->_getAttributeValue($attributeId, $attributeValue, $storeId); + if (!is_null($value) && $value !== false) { + $code = $this->_getSearchableAttribute($attributeId)->getAttributeCode(); + //For grouped products + if (isset($index[$code])) { + if (!is_array($index[$code])) { + $index[$code] = array($index[$code]); + } + $index[$code][] = $value; + } + //For other types of products + else { + $index[$code] = $value; + } + } + } + } + + $product = $this->_getProductEmulator() + ->setId($productData['entity_id']) + ->setTypeId($productData['type_id']) + ->setStoreId($storeId); + $typeInstance = $this->_getProductTypeInstance($productData['type_id']); + if ($data = $typeInstance->getSearchableData($product)) { + $index['options'] = $data; + } + + if (isset($productData['in_stock'])) { + $index['in_stock'] = $productData['in_stock']; + } + + if ($this->_engine) { + if ($this->_engine->allowAdvancedIndex()) { + $index += $this->_engine->addAllowedAdvancedIndexField($productData); + } + + return $this->_engine->prepareEntityIndex($index, $this->_separator); + } + + return Mage::helper('catalogsearch')->prepareIndexdata($index, $this->_separator); + } + + /** + * Retrieve attribute source value for search + * + * @param int $attributeId + * @param mixed $value + * @param int $storeId + * @return mixed + */ + protected function _getAttributeValue($attributeId, $value, $storeId) + { + $attribute = $this->_getSearchableAttribute($attributeId); + if (!($attribute->getIsSearchable() || + $attribute->getIsVisibleInAdvancedSearch() || + $attribute->getIsFilterable() || + $attribute->getIsFilterableInSearch())) { + return null; + } + if ($attribute->usesSource()) { + $attribute->setStoreId($storeId); + $value = $attribute->getSource()->getOptionText($value); + } + if ($attribute->getBackendType() == 'datetime') { + $value = $this->_getStoreDate($storeId, $value); + } + if ($attribute->getFrontend()->getInputType() == 'price') { + $value = Mage::app()->getStore($storeId)->roundPrice($value); + } + + if (is_array($value)) { + $value = implode($this->_separator, $value); + } + + return preg_replace("#\s+#siu", ' ', trim(strip_tags($value))); + } + + /** + * Save Product index + * + * @param int $productId + * @param int $storeId + * @param string $index + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + protected function _saveProductIndex($productId, $storeId, $index) + { + if ($this->_engine) { + $this->_engine->saveEntityIndex($productId, $storeId, $index); + } + return $this; + } + + /** + * Save Multiply Product indexes + * + * @param int $storeId + * @param array $productIndexes + * @return Mage_CatalogSearch_Model_Resource_Fulltext + */ + protected function _saveProductIndexes($storeId, $productIndexes) + { + if ($this->_engine) { + $this->_engine->saveEntityIndexes($storeId, $productIndexes); + } + return $this; + } + + /** + * Retrieve Date value for store + * + * @param int $storeId + * @param string $date + * @return string + */ + protected function _getStoreDate($storeId, $date = null) + { + if (!isset($this->_dates[$storeId])) { + $timezone = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $storeId); + $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $storeId); + $locale = new Zend_Locale($locale); + + $dateObj = new Zend_Date(null, null, $locale); + $dateObj->setTimezone($timezone); + $this->_dates[$storeId] = array($dateObj, $locale->getTranslation(null, 'date', $locale)); + } + + if (!is_empty_date($date)) { + list($dateObj, $format) = $this->_dates[$storeId]; + $dateObj->setDate($date, Varien_Date::DATETIME_INTERNAL_FORMAT); + + return $dateObj->toString($format); + } + + return null; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php new file mode 100755 index 0000000000..3709cc33f5 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php @@ -0,0 +1,95 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Fulltext_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Retrieve query model object + * + * @return Mage_CatalogSearch_Model_Query + */ + protected function _getQuery() + { + return Mage::helper('catalogsearch')->getQuery(); + } + + /** + * Add search query filter + * + * @param string $query + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection + */ + public function addSearchFilter($query) + { + Mage::getSingleton('catalogsearch/fulltext')->prepareResult(); + + $this->getSelect()->joinInner( + array('search_result' => $this->getTable('catalogsearch/result')), + $this->getConnection()->quoteInto( + 'search_result.product_id=e.entity_id AND search_result.query_id=?', + $this->_getQuery()->getId() + ), + array('relevance' => 'relevance') + ); + + return $this; + } + + /** + * Set Order field + * + * @param string $attribute + * @param string $dir + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection + */ + public function setOrder($attribute, $dir = 'desc') + { + if ($attribute == 'relevance') { + $this->getSelect()->order("relevance {$dir}"); + } else { + parent::setOrder($attribute, $dir); + } + return $this; + } + + /** + * Stub method for campatibility with other search engines + * + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection + */ + public function setGeneralDefaultQuery() + { + return $this; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Engine.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Engine.php new file mode 100755 index 0000000000..1f6dca4f8e --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Engine.php @@ -0,0 +1,189 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Fulltext_Engine extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init resource model + * + */ + protected function _construct() + { + $this->_init('catalogsearch/fulltext', 'product_id'); + } + + /** + * Add entity data to fulltext search table + * + * @param int $entityId + * @param int $storeId + * @param array $index + * @param string $entity 'product'|'cms' + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine + */ + public function saveEntityIndex($entityId, $storeId, $index, $entity = 'product') + { + $this->_getWriteAdapter()->insert($this->getMainTable(), array( + 'product_id' => $entityId, + 'store_id' => $storeId, + 'data_index' => $index + )); + return $this; + } + + /** + * Multi add entities data to fulltext search table + * + * @param int $storeId + * @param array $entityIndexes + * @param string $entity 'product'|'cms' + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine + */ + public function saveEntityIndexes($storeId, $entityIndexes, $entity = 'product') + { + $adapter = $this->_getWriteAdapter(); + $data = array(); + $storeId = (int)$storeId; + foreach ($entityIndexes as $entityId => &$index) { + $data[] = array( + 'product_id' => (int)$entityId, + 'store_id' => $storeId, + 'data_index' => $index + ); + } + + if ($data) { + Mage::getResourceHelper('catalogsearch') + ->insertOnDuplicate($this->getMainTable(), $data, array('data_index')); + } + + return $this; + } + + /** + * Define if current search engine supports advanced index + * + * @return bool + */ + public function allowAdvancedIndex() + { + return false; + } + + /** + * Remove entity data from fulltext search table + * + * @param int $storeId + * @param int $entityId + * @param string $entity 'product'|'cms' + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine + */ + public function cleanIndex($storeId = null, $entityId = null, $entity = 'product') + { + $where = array(); + + if (!is_null($storeId)) { + $where[] = $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId); + } + if (!is_null($entityId)) { + $where[] = $this->_getWriteAdapter()->quoteInto('product_id IN (?)', $entityId); + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + + return $this; + } + + /** + * Prepare index array as a string glued by separator + * + * @param array $index + * @param string $separator + * @return string + */ + public function prepareEntityIndex($index, $separator = ' ') + { + return Mage::helper('catalogsearch')->prepareIndexdata($index, $separator); + } + + /** + * Stub method for compatibility with other search engines + * + * @return null + */ + public function getResourceName() + { + return null; + } + + /** + * Retrieve fulltext search result data collection + * + * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection + */ + public function getResultCollection() + { + return Mage::getResourceModel('catalogsearch/fulltext_collection'); + } + + /** + * Retrieve advanced search result data collection + * + * @return Mage_CatalogSearch_Model_Resource_Advanced_Collection + */ + public function getAdvancedResultCollection() + { + return Mage::getResourceModel('catalogsearch/advanced_collection'); + } + + /** + * Define if Layered Navigation is allowed + * + * @return bool + */ + public function isLeyeredNavigationAllowed() + { + return true; + } + + /** + * Define if engine is avaliable + * + * @return bool + */ + public function test() + { + return true; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..429a276c77 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,121 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Helper_Mysql4 extends Mage_Eav_Model_Resource_Helper_Mysql4 +{ + + /** + * Join information for usin full text search + * + * @param Varien_Db_Select $select + * @return Varien_Db_Select $select + */ + public function chooseFulltext($table, $alias, $select) + { + $field = new Zend_Db_Expr('MATCH ('.$alias.'.data_index) AGAINST (:query IN BOOLEAN MODE)'); + $select->columns(array('relevance' => $field)); + return $field; + } + + /** + * Prepare Terms + * + * @param string $str The source string + * @return array(0=>words, 1=>terms) + */ + function prepareTerms($str, $maxWordLength = 0) + { + $boolWords = array( + '+' => '+', + '-' => '-', + '|' => '|', + '<' => '<', + '>' => '>', + '~' => '~', + '*' => '*', + ); + $brackets = array( + '(' => '(', + ')' => ')' + ); + $words = array(0=>""); + $terms = array(); + preg_match_all('/([\(\)]|[\"\'][^"\']*[\"\']|[^\s\"\(\)]*)/uis', $str, $matches); + $isOpenBracket = 0; + foreach ($matches[1] as $word) { + $word = trim($word); + if (strlen($word)) { + $word = str_replace('"', '', $word); + $isBool = in_array(strtoupper($word), $boolWords); + $isBracket = in_array($word, $brackets); + if (!$isBool && !$isBracket) { + $terms[$word] = $word; + $word = '"'.$word.'"'; + $words[] = $word; + } else if ($isBracket) { + if ($word == '(') { + $isOpenBracket++; + } else { + $isOpenBracket--; + } + $words[] = $word; + } else if ($isBool) { + $words[] = $word; + } + } + } + if ($isOpenBracket > 0) { + $words[] = sprintf("%')".$isOpenBracket."s", ''); + } else if ($isOpenBracket < 0) { + $words[0] = sprintf("%'(".$isOpenBracket."s", ''); + } + if ($maxWordLength && count($terms) > $maxWordLength) { + $terms = array_slice($terms, 0, $maxWordLength); + } + $result = array($words, $terms); + return $result; + } + + /** + * Use sql compatible with Full Text indexes + * + * @param mixed $table The table to insert data into. + * @param array $data Column-value pairs or array of column-value pairs. + * @param arrat $fields update fields pairs or values + * @return int The number of affected rows. + */ + public function insertOnDuplicate($table, array $data, array $fields = array()) { + return $this->_getWriteAdapter()->insertOnDuplicate($table, $data, $fields); + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Indexer/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Indexer/Fulltext.php new file mode 100644 index 0000000000..30c5769376 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Indexer/Fulltext.php @@ -0,0 +1,60 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Indexer_Fulltext extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define catalog product table as main table + */ + protected function _construct() + { + $this->_init('catalogsearch/fulltext', 'product_id'); + } + + /** + * Retrieve product relations by children + * + * @param int|array $childIds + * @return array + */ + public function getRelationsByChild($childIds) + { + $write = $this->_getWriteAdapter(); + $select = $write->select() + ->from($this->getTable('catalog/product_relation'), 'parent_id') + ->where('child_id IN(?)', $childIds); + + return $write->fetchCol($select); + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Query.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Query.php new file mode 100755 index 0000000000..e8908b3cf9 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Query.php @@ -0,0 +1,120 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Query extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init resource data + * + */ + protected function _construct() + { + $this->_init('catalogsearch/search_query', 'query_id'); + } + + /** + * Custom load model by search query string + * + * @param Mage_Core_Model_Abstract $object + * @param string $value + * @return Mage_CatalogSearch_Model_Resource_Query + */ + public function loadByQuery(Mage_Core_Model_Abstract $object, $value) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where('synonym_for=? OR query_text=?', $value) + ->where('store_id=?', $object->getStoreId()) + ->order('synonym_for ASC') + ->limit(1); + if ($data = $this->_getReadAdapter()->fetchRow($select)) { + $object->setData($data); + $this->_afterLoad($object); + } + + return $this; + } + + /** + * Custom load model only by query text (skip synonym for) + * + * @param Mage_Core_Model_Abstract $object + * @param string $value + * @return Mage_CatalogSearch_Model_Resource_Query + */ + public function loadByQueryText(Mage_Core_Model_Abstract $object, $value) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where('query_text = ?', $value) + ->where('store_id = ?', $object->getStoreId()) + ->limit(1); + if ($data = $this->_getReadAdapter()->fetchRow($select)) { + $object->setData($data); + $this->_afterLoad($object); + } + return $this; + } + + /** + * Loading string as a value or regular numeric + * + * @param Mage_Core_Model_Abstract $object + * @param int|string $value + * @param null|string $field + * @return Mage_CatalogSearch_Model_Resource_Query + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (is_numeric($value)) { + return parent::load($object, $value); + } + else { + $this->loadByQuery($object,$value); + } + return $this; + } + + /** + * Enter description here ... + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_CatalogSearch_Model_Resource_Query + */ + public function _beforeSave(Mage_Core_Model_Abstract $object) + { + $object->setUpdatedAt($this->formatDate(Mage::getModel('core/date')->gmtTimestamp())); + return $this; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Query/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Query/Collection.php new file mode 100755 index 0000000000..930ee07529 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Query/Collection.php @@ -0,0 +1,163 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Query_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Store for filter + * + * @var int + */ + protected $_storeId; + + /** + * Init model for collection + * + */ + protected function _construct() + { + $this->_init('catalogsearch/query'); + } + + /** + * Set Store ID for filter + * + * @param mixed $store + * @return Mage_CatalogSearch_Model_Resource_Query_Collection + */ + public function setStoreId($store) + { + if ($store instanceof Mage_Core_Model_Store) { + $store = $store->getId(); + } + $this->_storeId = $store; + return $this; + } + + /** + * Retrieve Store ID Filter + * + * @return int|null + */ + public function getStoreId() + { + return $this->_storeId; + } + + /** + * Set search query text to filter + * + * @param string $query + * @return Mage_CatalogSearch_Model_Resource_Query_Collection + */ + public function setQueryFilter($query) + { + $ifSynonymFor = $this->getConnection() + ->getIfNullSql('synonym_for', 'query_text'); + $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true) + ->from( + array('main_table' => $this->getTable('catalogsearch/search_query')), + array('query' => $ifSynonymFor, 'num_results') + ) + ->where('num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?', + Mage::getResourceHelper('core')->addLikeEscape($query, array('position' => 'start'))) + ->order('popularity ' . Varien_Db_Select::SQL_DESC); + if ($this->getStoreId()) { + $this->getSelect() + ->where('store_id = ?', (int)$this->getStoreId()); + } + return $this; + } + + /** + * Set Popular Search Query Filter + * + * @param int|array $storeIds + * @return Mage_CatalogSearch_Model_Resource_Query_Collection + */ + public function setPopularQueryFilter($storeIds = null) + { + $ifSynonymFor = new Zend_Db_Expr($this->getConnection() + ->getIfNullSql('synonym_for', 'query_text')); + $this->getSelect() + ->reset(Zend_Db_Select::FROM) + ->reset(Zend_Db_Select::COLUMNS) + ->distinct(true) + ->from( + array('main_table'=>$this->getTable('catalogsearch/search_query')), + array('name'=>$ifSynonymFor, + 'num_results', + 'popularity', + ) + ); + if ($storeIds) { + $this->addStoreFilter($storeIds); + $this->getSelect()->where('num_results > 0'); + } + elseif (null === $storeIds) { + $this->addStoreFilter(Mage::app()->getStore()->getId()); + $this->getSelect()->where('num_results > 0'); + } + + $this->getSelect()->order(array('popularity desc','name')); + + return $this; + } + + /** + * Set Recent Queries Order + * + * @return Mage_CatalogSearch_Model_Resource_Query_Collection + */ + public function setRecentQueryFilter() + { + $this->setOrder('updated_at', 'desc'); + return $this; + } + + /** + * Filter collection by specified store ids + * + * @param array|int $storeIds + * @return Mage_CatalogSearch_Model_Resource_Query_Collection + */ + public function addStoreFilter($storeIds) + { + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); + return $this; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Search/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Search/Collection.php new file mode 100755 index 0000000000..e832ede1eb --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Search/Collection.php @@ -0,0 +1,273 @@ + + */ +class Mage_CatalogSearch_Model_Resource_Search_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Attribute collection + * + * @var array + */ + protected $_attributesCollection; + + /** + * Search query + * + * @var string + */ + protected $_searchQuery; + + /** + * Add search query filter + * + * @param string $query + * @return Mage_CatalogSearch_Model_Resource_Search_Collection + */ + public function addSearchFilter($query) + { + $this->_searchQuery = $query; + $this->addFieldToFilter('entity_id', array('in'=>new Zend_Db_Expr($this->_getSearchEntityIdsSql($query)))); + return $this; + } + + /** + * Retrieve collection of all attributes + * + * @return Varien_Data_Collection_Db + */ + protected function _getAttributesCollection() + { + if (!$this->_attributesCollection) { + $this->_attributesCollection = Mage::getResourceModel('catalog/product_attribute_collection') + ->load(); + + foreach ($this->_attributesCollection as $attribute) { + $attribute->setEntity($this->getEntity()); + } + } + return $this->_attributesCollection; + } + + /** + * Check attribute is Text and is Searchable + * + * @param Mage_Catalog_Model_Entity_Attribute $attribute + * @return boolean + */ + protected function _isAttributeTextAndSearchable($attribute) + { + if (($attribute->getIsSearchable() + && !in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) + && (in_array($attribute->getBackendType(), array('varchar', 'text')) + || $attribute->getBackendType() == 'static')) { + return true; + } + return false; + } + + /** + * Check attributes has options and searchable + * + * @param Mage_Catalog_Model_Entity_Attribute $attribute + * @return boolean + */ + protected function _hasAttributeOptionsAndSearchable($attribute) + { + if ($attribute->getIsSearchable() + && in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) { + return true; + } + + return false; + } + + /** + * Retrieve SQL for search entities + * + * @param unknown_type $query + * @return string + */ + protected function _getSearchEntityIdsSql($query) + { + $tables = array(); + $selects = array(); + + /* @var $resHelper Mage_Core_Model_Resource_Helper_Abstract */ + $resHelper = Mage::getResourceHelper('core'); + $likeOptions = array('position' => 'any'); + + /** + * Collect tables and attribute ids of attributes with string values + */ + foreach ($this->_getAttributesCollection() as $attribute) { + /** @var Mage_Catalog_Model_Entity_Attribute $attribute */ + $attributeCode = $attribute->getAttributeCode(); + if ($this->_isAttributeTextAndSearchable($attribute)) { + $table = $attribute->getBackendTable(); + if (!isset($tables[$table]) && $attribute->getBackendType() != 'static') { + $tables[$table] = array(); + } + + if ($attribute->getBackendType() == 'static') { + $selects[] = $this->getConnection()->select() + ->from($table, 'entity_id') + ->where($resHelper->getCILike($attributeCode, $this->_searchQuery, $likeOptions)); + } else { + $tables[$table][] = $attribute->getId(); + } + } + } + + $ifValueId = $this->getConnection()->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + foreach ($tables as $table => $attributeIds) { + $selects[] = $this->getConnection()->select() + ->from(array('t1' => $table), 'entity_id') + ->joinLeft( + array('t2' => $table), + $this->getConnection()->quoteInto( + 't1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id = ?', + $this->getStoreId()), + array() + ) + ->where('t1.attribute_id IN (?)', $attributeIds) + ->where('t1.store_id = ?', 0) + ->where($resHelper->getCILike($ifValueId, $this->_searchQuery, $likeOptions)); + } + + $sql = $this->_getSearchInOptionSql($query); + if ($sql) { + $selects[] = "SELECT * FROM ({$sql}) AS inoptionsql"; // inheritant unions may be inside + } + + $sql = $this->getConnection()->select()->union($selects, Zend_Db_Select::SQL_UNION_ALL); + return $sql; + } + + /** + * Retrieve SQL for search entities by option + * + * @param unknown_type $query + * @return string + */ + protected function _getSearchInOptionSql($query) + { + $attributeIds = array(); + $attributeTables = array(); + $storeId = (int)$this->getStoreId(); + + /** + * Collect attributes with options + */ + foreach ($this->_getAttributesCollection() as $attribute) { + if ($this->_hasAttributeOptionsAndSearchable($attribute)) { + $attributeTables[$attribute->getFrontendInput()] = $attribute->getBackend()->getTable(); + $attributeIds[] = $attribute->getId(); + } + } + if (empty($attributeIds)) { + return false; + } + + $resource = Mage::getSingleton('core/resource'); + $optionTable = $resource->getTableName('eav/attribute_option'); + $optionValueTable = $resource->getTableName('eav/attribute_option_value'); + $attributesTable = $resource->getTableName('eav/attribute'); + + /** + * Select option Ids + */ + $resHelper = Mage::getResourceHelper('core'); + $ifStoreId = $this->getConnection()->getIfNullSql('s.store_id', 'd.store_id'); + $ifValue = $this->getConnection()->getCheckSql('s.value_id > 0', 's.value', 'd.value'); + $select = $this->getConnection()->select() + ->from(array('d'=>$optionValueTable), + array('option_id', + 'o.attribute_id', + 'store_id' => $ifStoreId, + 'a.frontend_input')) + ->joinLeft(array('s'=>$optionValueTable), + $this->getConnection()->quoteInto('s.option_id = d.option_id AND s.store_id=?', $storeId), + array()) + ->join(array('o'=>$optionTable), + 'o.option_id=d.option_id', + array()) + ->join(array('a' => $attributesTable), 'o.attribute_id=a.attribute_id', array()) + ->where('d.store_id=0') + ->where('o.attribute_id IN (?)', $attributeIds) + ->where($resHelper->getCILike($ifValue, $this->_searchQuery, array('position' => 'any'))); + + $options = $this->getConnection()->fetchAll($select); + if (empty($options)) { + return false; + } + + // build selects of entity ids for specified options ids by frontend input + $selects = array(); + foreach (array( + 'select' => 'eq', + 'multiselect' => 'finset') + as $frontendInput => $condition) { + if (isset($attributeTables[$frontendInput])) { + $where = array(); + foreach ($options as $option) { + if ($frontendInput === $option['frontend_input']) { + $findSet = $this->getConnection() + ->prepareSqlCondition('value', array($condition => $option['option_id'])); + $whereCond = "(attribute_id=%d AND store_id=%d AND {$findSet})"; + $where[] = sprintf($whereConf, $option['attribute_id'], $option['store_id']); + } + } + if ($where) { + $selects[$frontendInput] = (string)$this->getConnection()->select() + ->from($attributeTables[$frontendInput], 'entity_id') + ->where(implode(' OR ', $where)); + } + } + } + + // search in catalogindex for products as part of configurable/grouped/bundle products (current store) + $where = array(); + foreach ($options as $option) { + $where[] = sprintf('(attribute_id=%d AND value=%d)', $option['attribute_id'], $option['option_id']); + } + if ($where) { + $selects[] = (string)$this->getConnection()->select() + ->from($resource->getTableName('catalogindex/eav'), 'entity_id') + ->where(implode(' OR ', $where)) + ->where("store_id={$storeId}"); + } + $sql = $this->getConnection()->select()->union($selects, Zend_Db_Select::SQL_UNION_ALL); + return $sql; + } +} diff --git a/app/code/core/Mage/CatalogSearch/Model/Session.php b/app/code/core/Mage/CatalogSearch/Model/Session.php index c5fde29305..618832dae2 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Session.php +++ b/app/code/core/Mage/CatalogSearch/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/Model/System/Config/Backend/Sitemap.php b/app/code/core/Mage/CatalogSearch/Model/System/Config/Backend/Sitemap.php index 69f838580e..6112ae20bc 100644 --- a/app/code/core/Mage/CatalogSearch/Model/System/Config/Backend/Sitemap.php +++ b/app/code/core/Mage/CatalogSearch/Model/System/Config/Backend/Sitemap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php b/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php index cea25bee44..0a37f5128a 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/controllers/AjaxController.php b/app/code/core/Mage/CatalogSearch/controllers/AjaxController.php index 9150100679..9e905357e9 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/AjaxController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/AjaxController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/controllers/ResultController.php b/app/code/core/Mage/CatalogSearch/controllers/ResultController.php index 210664efed..e548a93928 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/ResultController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/ResultController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/controllers/TermController.php b/app/code/core/Mage/CatalogSearch/controllers/TermController.php index 70fb661a73..6fb464f2f4 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/TermController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/TermController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/etc/adminhtml.xml b/app/code/core/Mage/CatalogSearch/etc/adminhtml.xml index 1765d7265c..1606b944e2 100644 --- a/app/code/core/Mage/CatalogSearch/etc/adminhtml.xml +++ b/app/code/core/Mage/CatalogSearch/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogSearch/etc/config.xml b/app/code/core/Mage/CatalogSearch/etc/config.xml index 8961ddce7f..d63bc3f1c8 100644 --- a/app/code/core/Mage/CatalogSearch/etc/config.xml +++ b/app/code/core/Mage/CatalogSearch/etc/config.xml @@ -21,25 +21,25 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.7 + 1.6.0.0 Mage_CatalogSearch_Model - catalogsearch_mysql4 + catalogsearch_resource - - - Mage_CatalogSearch_Model_Mysql4 + + Mage_CatalogSearch_Model_Resource + catalogsearch_mysql4 catalogsearch_query
@@ -51,7 +51,7 @@ catalogsearch_fulltext
-
+
@@ -66,73 +66,12 @@
- + - Mage_CatalogSearch_Block + + Mage_CatalogSearch_Block + @@ -155,27 +94,27 @@ - - Mage_CatalogSearch.csv - + + Mage_CatalogSearch.csv + - - - catalogsearch.xml - - + + + catalogsearch.xml + + - - Mage_CatalogSearch.csv - + + Mage_CatalogSearch.csv + @@ -187,7 +126,6 @@ - diff --git a/app/code/core/Mage/CatalogSearch/etc/system.xml b/app/code/core/Mage/CatalogSearch/etc/system.xml index 1a7516e862..6c8d24fa6e 100644 --- a/app/code/core/Mage/CatalogSearch/etc/system.xml +++ b/app/code/core/Mage/CatalogSearch/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/install-1.6.0.0.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..d41a6cfab6 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/install-1.6.0.0.php @@ -0,0 +1,149 @@ +startSetup(); + +/** + * Create table 'catalogsearch/search_query' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogsearch/search_query')) + ->addColumn('query_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Query ID') + ->addColumn('query_text', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Query text') + ->addColumn('num_results', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Num results') + ->addColumn('popularity', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Popularity') + ->addColumn('redirect', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Redirect') + ->addColumn('synonym_for', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Synonym for') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('display_in_terms', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Display in terms') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'default' => '1', + ), 'Active status') + ->addColumn('is_processed', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'default' => '0', + ), 'Processed status') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated at') + ->addIndex($installer->getIdxName('catalogsearch/search_query', array('query_text','store_id','popularity')), + array('query_text','store_id','popularity')) + ->addIndex($installer->getIdxName('catalogsearch/search_query', 'store_id'), 'store_id') + ->addForeignKey($installer->getFkName('catalogsearch/search_query', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog search query table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogsearch/result' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogsearch/result')) + ->addColumn('query_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Query ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product ID') + ->addColumn('relevance', Varien_Db_Ddl_Table::TYPE_DECIMAL, '20,4', array( + 'nullable' => false, + 'default' => '0.0000' + ), 'Relevance') + ->addIndex($installer->getIdxName('catalogsearch/result', 'query_id'), 'query_id') + ->addForeignKey($installer->getFkName('catalogsearch/result', 'query_id', 'catalogsearch/search_query', 'query_id'), + 'query_id', $installer->getTable('catalogsearch/search_query'), 'query_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('catalogsearch/result', 'product_id'), 'product_id') + ->addForeignKey($installer->getFkName('catalogsearch/result', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Catalog search result table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'catalogsearch/fulltext' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('catalogsearch/fulltext')) + ->addColumn('fulltext_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store ID') + ->addColumn('data_index', Varien_Db_Ddl_Table::TYPE_TEXT, '4g', array( + ), 'Data index') + ->addIndex($installer->getIdxName('catalogsearch/fulltext', array('product_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('product_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('catalogsearch/fulltext', 'data_index', Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT), + 'data_index', + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT)) + ->setOption('type', 'MyISAM') + ->setComment('Catalog search result table'); +$installer->getConnection()->createTable($table); + + +$installer->endSetup(); + diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-install-0.7.0.php index ba1bb34093..a598bb09f7 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.1-0.7.2.php index 2644f44c2c..fe4ac75df6 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.2-0.7.3.php index 0f439760a4..c2320527ec 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.3-0.7.4.php index 0cecbaa184..64187c13eb 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.4-0.7.5.php index 543c083d44..1079464284 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.5-0.7.6.php index 2f3c5bbb3d..802f81adcc 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.6-0.7.7.php index d363b67ffa..89bbf88fd6 100644 --- a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_CatalogSearch - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..91046278f7 --- /dev/null +++ b/app/code/core/Mage/CatalogSearch/sql/catalogsearch_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,309 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogsearch/search_query'), + 'FK_CATALOGSEARCH_QUERY_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogsearch/result'), + 'FK_CATALOGSEARCH_RESULT_CATALOG_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('catalogsearch/result'), + 'FK_CATALOGSEARCH_RESULT_QUERY' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/fulltext'), + 'PRIMARY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/fulltext'), + 'data_index' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/search_query'), + 'FK_CATALOGSEARCH_QUERY_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/search_query'), + 'IDX_SEARCH_QUERY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/result'), + 'IDX_QUERY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/result'), + 'IDX_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('catalogsearch/result'), + 'IDX_RELEVANCE' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('catalogsearch/search_query') => array( + 'columns' => array( + 'query_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Query ID' + ), + 'query_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Query text' + ), + 'num_results' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Num results' + ), + 'popularity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Popularity' + ), + 'redirect' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Redirect' + ), + 'synonym_for' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Synonym for' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'display_in_terms' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Display in terms' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'default' => '1', + 'comment' => 'Active status' + ), + 'is_processed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'default' => '0', + 'comment' => 'Processed status' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated at' + ) + ), + 'comment' => 'Catalog search query table' + ), + $installer->getTable('catalogsearch/result') => array( + 'columns' => array( + 'query_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Query ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product ID' + ), + 'relevance' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 20, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Relevance' + ) + ), + 'comment' => 'Catalog search result table' + ), + $installer->getTable('catalogsearch/fulltext') => array( + 'columns' => array( + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'data_index' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '4g', + 'comment' => 'Data index' + ) + ), + 'comment' => 'Catalog search result table' + ) +); + +$installer->getConnection()->modifyTables($tables); + +/** + * Change columns + */ +$installer->getConnection()->addColumn( + $installer->getTable('catalogsearch/fulltext'), + 'fulltext_id', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity ID' + ) +); + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/fulltext'), + $installer->getIdxName( + 'catalogsearch/fulltext', + array('product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/fulltext'), + $installer->getIdxName( + 'catalogsearch/fulltext', + array('data_index'), + Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT + ), + array('data_index'), + Varien_Db_Adapter_Interface::INDEX_TYPE_FULLTEXT +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/search_query'), + $installer->getIdxName('catalogsearch/search_query', array('query_text', 'store_id', 'popularity')), + array('query_text', 'store_id', 'popularity') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/search_query'), + $installer->getIdxName('catalogsearch/search_query', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/result'), + $installer->getIdxName('catalogsearch/result', array('query_id')), + array('query_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('catalogsearch/result'), + $installer->getIdxName('catalogsearch/result', array('product_id')), + array('product_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogsearch/search_query', 'store_id', 'core/store', 'store_id'), + $installer->getTable('catalogsearch/search_query'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogsearch/result', 'query_id', 'catalogsearch/search_query', 'query_id'), + $installer->getTable('catalogsearch/result'), + 'query_id', + $installer->getTable('catalogsearch/search_query'), + 'query_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('catalogsearch/result', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('catalogsearch/result'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation.php b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation.php index 3fa54fdeb2..cc90f6e083 100644 --- a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation.php +++ b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php index da9c55c57f..a69802a324 100644 --- a/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php +++ b/app/code/core/Mage/Centinel/Block/Adminhtml/Validation/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Block/Authentication.php b/app/code/core/Mage/Centinel/Block/Authentication.php index cb275d1c27..047065dbc4 100644 --- a/app/code/core/Mage/Centinel/Block/Authentication.php +++ b/app/code/core/Mage/Centinel/Block/Authentication.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Block/Authentication/Complete.php b/app/code/core/Mage/Centinel/Block/Authentication/Complete.php index 94c099a8d8..0304134ac4 100644 --- a/app/code/core/Mage/Centinel/Block/Authentication/Complete.php +++ b/app/code/core/Mage/Centinel/Block/Authentication/Complete.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Block/Authentication/Start.php b/app/code/core/Mage/Centinel/Block/Authentication/Start.php index 6c7e833ec5..6d44192db7 100644 --- a/app/code/core/Mage/Centinel/Block/Authentication/Start.php +++ b/app/code/core/Mage/Centinel/Block/Authentication/Start.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Block/Logo.php b/app/code/core/Mage/Centinel/Block/Logo.php index b712eb2d03..1e54ddf188 100644 --- a/app/code/core/Mage/Centinel/Block/Logo.php +++ b/app/code/core/Mage/Centinel/Block/Logo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Helper/Data.php b/app/code/core/Mage/Centinel/Helper/Data.php index a46235345d..aa93eb1c5c 100644 --- a/app/code/core/Mage/Centinel/Helper/Data.php +++ b/app/code/core/Mage/Centinel/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/Api.php b/app/code/core/Mage/Centinel/Model/Api.php index c8ed33c65b..51267012e5 100644 --- a/app/code/core/Mage/Centinel/Model/Api.php +++ b/app/code/core/Mage/Centinel/Model/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/Config.php b/app/code/core/Mage/Centinel/Model/Config.php index 7aab7bfbaa..0bb529cd5d 100644 --- a/app/code/core/Mage/Centinel/Model/Config.php +++ b/app/code/core/Mage/Centinel/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/Observer.php b/app/code/core/Mage/Centinel/Model/Observer.php index b455c7220e..670f066075 100644 --- a/app/code/core/Mage/Centinel/Model/Observer.php +++ b/app/code/core/Mage/Centinel/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/Service.php b/app/code/core/Mage/Centinel/Model/Service.php index 33b496baa9..f42801ad25 100644 --- a/app/code/core/Mage/Centinel/Model/Service.php +++ b/app/code/core/Mage/Centinel/Model/Service.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/Session.php b/app/code/core/Mage/Centinel/Model/Session.php index db55720e3d..59943acfd4 100644 --- a/app/code/core/Mage/Centinel/Model/Session.php +++ b/app/code/core/Mage/Centinel/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/State/Jcb.php b/app/code/core/Mage/Centinel/Model/State/Jcb.php index c07e976544..6f45714bb3 100644 --- a/app/code/core/Mage/Centinel/Model/State/Jcb.php +++ b/app/code/core/Mage/Centinel/Model/State/Jcb.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/State/Mastercard.php b/app/code/core/Mage/Centinel/Model/State/Mastercard.php index 5e3373acce..d9cd1c37f4 100644 --- a/app/code/core/Mage/Centinel/Model/State/Mastercard.php +++ b/app/code/core/Mage/Centinel/Model/State/Mastercard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/State/Visa.php b/app/code/core/Mage/Centinel/Model/State/Visa.php index cfff127aef..6b699ccc09 100644 --- a/app/code/core/Mage/Centinel/Model/State/Visa.php +++ b/app/code/core/Mage/Centinel/Model/State/Visa.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/Model/StateAbstract.php b/app/code/core/Mage/Centinel/Model/StateAbstract.php index b7bceb47ab..b235b128d3 100644 --- a/app/code/core/Mage/Centinel/Model/StateAbstract.php +++ b/app/code/core/Mage/Centinel/Model/StateAbstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/controllers/Adminhtml/Centinel/IndexController.php b/app/code/core/Mage/Centinel/controllers/Adminhtml/Centinel/IndexController.php index 7e75f7a2db..fcc5769d85 100644 --- a/app/code/core/Mage/Centinel/controllers/Adminhtml/Centinel/IndexController.php +++ b/app/code/core/Mage/Centinel/controllers/Adminhtml/Centinel/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/controllers/IndexController.php b/app/code/core/Mage/Centinel/controllers/IndexController.php index 21fa5f92d0..33bf2cb140 100644 --- a/app/code/core/Mage/Centinel/controllers/IndexController.php +++ b/app/code/core/Mage/Centinel/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Centinel/etc/config.xml b/app/code/core/Mage/Centinel/etc/config.xml index 2d527999dd..06f6ceb5ca 100644 --- a/app/code/core/Mage/Centinel/etc/config.xml +++ b/app/code/core/Mage/Centinel/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.0.0 + 1.6.0.0 diff --git a/app/code/core/Mage/Centinel/etc/system.xml b/app/code/core/Mage/Centinel/etc/system.xml index a5b6b833e9..c2489c2c16 100644 --- a/app/code/core/Mage/Centinel/etc/system.xml +++ b/app/code/core/Mage/Centinel/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Checkout/Block/Agreements.php b/app/code/core/Mage/Checkout/Block/Agreements.php index 9aa2da8159..92414da796 100644 --- a/app/code/core/Mage/Checkout/Block/Agreements.php +++ b/app/code/core/Mage/Checkout/Block/Agreements.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Checkout_Block_Agreements extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/Checkout/Block/Cart.php b/app/code/core/Mage/Checkout/Block/Cart.php index 23d76f1463..a30ca88842 100644 --- a/app/code/core/Mage/Checkout/Block/Cart.php +++ b/app/code/core/Mage/Checkout/Block/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Abstract.php b/app/code/core/Mage/Checkout/Block/Cart/Abstract.php index 1bb62a6fd6..34c0a542f4 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Abstract.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Coupon.php b/app/code/core/Mage/Checkout/Block/Cart/Coupon.php index 83608a3abb..917c9c0c70 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Coupon.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Coupon.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php b/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php index 17b8432ad7..94bc9ca1ba 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -67,7 +67,7 @@ public function getItems() } } - if (count($items)<$this->_maxItemCount) { + if (count($items) < $this->_maxItemCount) { $filterProductIds = array_merge($this->_getCartProductIds(), $this->_getCartProductIdsRel()); $collection = $this->_getCollection() ->addProductFilter($filterProductIds) @@ -80,6 +80,7 @@ public function getItems() $items[] = $item; } } + } $this->setData('items', $items); diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Configure.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Configure.php index 2fef2491ab..b796f1be86 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Configure.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Configure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php index 62ae265400..3e0c74e3c7 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Configurable.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Configurable.php index bb0a4c67b5..e202600d63 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Configurable.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Grouped.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Grouped.php index 714a23b57f..225ff0ae80 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Grouped.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Shipping.php b/app/code/core/Mage/Checkout/Block/Cart/Shipping.php index 053431289e..26fac6ccd5 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Shipping.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Sidebar.php b/app/code/core/Mage/Checkout/Block/Cart/Sidebar.php index ef8b315d4e..e97dac7d50 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Sidebar.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Cart/Totals.php b/app/code/core/Mage/Checkout/Block/Cart/Totals.php index 29330ff78f..c91bfdb2ff 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Totals.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Links.php b/app/code/core/Mage/Checkout/Block/Links.php index f6600778b5..a7948c89f2 100644 --- a/app/code/core/Mage/Checkout/Block/Links.php +++ b/app/code/core/Mage/Checkout/Block/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Abstract.php b/app/code/core/Mage/Checkout/Block/Multishipping/Abstract.php index 2574b9994e..8761aecadb 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Abstract.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php b/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php index b4d628efab..50b39723d1 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Address/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php b/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php index 9b90e93cfb..1e1887c281 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Addresses.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php index fbe57e3282..1725974817 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php b/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php index 285d167f31..aef08de1d3 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Link.php b/app/code/core/Mage/Checkout/Block/Multishipping/Link.php index 0f2442cebd..324d57cc1d 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Link.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php b/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php index be34c3bc74..d05b33a41b 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Overview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php b/app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php index 6e5ca9f792..3f212100f6 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php b/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php index c550ca9c0e..1951c9ae3e 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/State.php b/app/code/core/Mage/Checkout/Block/Multishipping/State.php index 112ea547aa..f909e47847 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/State.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/State.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Success.php b/app/code/core/Mage/Checkout/Block/Multishipping/Success.php index c3a4a8913c..d57a5a01d9 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Success.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Success.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage.php b/app/code/core/Mage/Checkout/Block/Onepage.php index b0d533a5e0..7b9abee9ee 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage.php +++ b/app/code/core/Mage/Checkout/Block/Onepage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php b/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php index 2e206f9545..50bd5e871f 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php index 7dbbb3092a..25632a902b 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Failure.php b/app/code/core/Mage/Checkout/Block/Onepage/Failure.php index 8b0ac94b7f..01eac67fb3 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Failure.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Failure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Link.php b/app/code/core/Mage/Checkout/Block/Onepage/Link.php index 35798f4331..9ba9e0d9cd 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Link.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Login.php b/app/code/core/Mage/Checkout/Block/Onepage/Login.php index b0641eb07e..341c739a3b 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Login.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Login.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Payment.php b/app/code/core/Mage/Checkout/Block/Onepage/Payment.php index 2d90f4a018..9015ee6b2a 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Payment.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php index 7f040bfe93..2ee8e013ea 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php index b78dada134..866e80ca36 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Progress.php b/app/code/core/Mage/Checkout/Block/Onepage/Progress.php index 24f34c52f4..ebc9845adb 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Progress.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Progress.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Review.php b/app/code/core/Mage/Checkout/Block/Onepage/Review.php index e9365fa104..4675ce673b 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Review.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Review.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php b/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php index e791ea4662..c76d8e783b 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Shipping.php b/app/code/core/Mage/Checkout/Block/Onepage/Shipping.php index 03f7b00ab4..26fd68be5f 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Shipping.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method.php b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method.php index d299f7a0b5..8298523fc6 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Additional.php b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Additional.php index c71b8aafe3..f72c20bea1 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Additional.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Additional.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php index 00f6ab889e..3d95b7724b 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Success.php b/app/code/core/Mage/Checkout/Block/Onepage/Success.php index 9b3e21899c..85e505eb08 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Success.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Success.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Success.php b/app/code/core/Mage/Checkout/Block/Success.php index 12d8516755..d1066c58e4 100644 --- a/app/code/core/Mage/Checkout/Block/Success.php +++ b/app/code/core/Mage/Checkout/Block/Success.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Total/Default.php b/app/code/core/Mage/Checkout/Block/Total/Default.php index 5a2e7805aa..6df1f11fa8 100644 --- a/app/code/core/Mage/Checkout/Block/Total/Default.php +++ b/app/code/core/Mage/Checkout/Block/Total/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Total/Nominal.php b/app/code/core/Mage/Checkout/Block/Total/Nominal.php index 8ccf6ce114..84edd54870 100644 --- a/app/code/core/Mage/Checkout/Block/Total/Nominal.php +++ b/app/code/core/Mage/Checkout/Block/Total/Nominal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Block/Total/Tax.php b/app/code/core/Mage/Checkout/Block/Total/Tax.php index ee9507805b..82fc5044bb 100644 --- a/app/code/core/Mage/Checkout/Block/Total/Tax.php +++ b/app/code/core/Mage/Checkout/Block/Total/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Controller/Action.php b/app/code/core/Mage/Checkout/Controller/Action.php index d8661c7bea..c8a9e94dd3 100644 --- a/app/code/core/Mage/Checkout/Controller/Action.php +++ b/app/code/core/Mage/Checkout/Controller/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Exception.php b/app/code/core/Mage/Checkout/Exception.php index 598fd1fef4..e0109ff814 100644 --- a/app/code/core/Mage/Checkout/Exception.php +++ b/app/code/core/Mage/Checkout/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Helper/Cart.php b/app/code/core/Mage/Checkout/Helper/Cart.php index d3520adb2d..2331db71a7 100644 --- a/app/code/core/Mage/Checkout/Helper/Cart.php +++ b/app/code/core/Mage/Checkout/Helper/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Helper/Data.php b/app/code/core/Mage/Checkout/Helper/Data.php index 1b3bb229e9..6e037fe297 100644 --- a/app/code/core/Mage/Checkout/Helper/Data.php +++ b/app/code/core/Mage/Checkout/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Helper/Url.php b/app/code/core/Mage/Checkout/Helper/Url.php index a0694e6b64..06dc5e8d22 100644 --- a/app/code/core/Mage/Checkout/Helper/Url.php +++ b/app/code/core/Mage/Checkout/Helper/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Agreement.php b/app/code/core/Mage/Checkout/Model/Agreement.php index a51bd0e488..b575bda50b 100644 --- a/app/code/core/Mage/Checkout/Model/Agreement.php +++ b/app/code/core/Mage/Checkout/Model/Agreement.php @@ -20,10 +20,32 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Checkout_Model_Resource_Agreement _getResource() + * @method Mage_Checkout_Model_Resource_Agreement getResource() + * @method string getName() + * @method Mage_Checkout_Model_Agreement setName(string $value) + * @method string getContent() + * @method Mage_Checkout_Model_Agreement setContent(string $value) + * @method string getContentHeight() + * @method Mage_Checkout_Model_Agreement setContentHeight(string $value) + * @method string getCheckboxText() + * @method Mage_Checkout_Model_Agreement setCheckboxText(string $value) + * @method int getIsActive() + * @method Mage_Checkout_Model_Agreement setIsActive(int $value) + * @method int getIsHtml() + * @method Mage_Checkout_Model_Agreement setIsHtml(int $value) + * + * @category Mage + * @package Mage_Checkout + * @author Magento Core Team + */ class Mage_Checkout_Model_Agreement extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource.php b/app/code/core/Mage/Checkout/Model/Api/Resource.php index b47a5957c9..de11ecde38 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php index ae685915d4..670b188d4d 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php index 543aef23d7..507d3523bb 100644 --- a/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php +++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart.php b/app/code/core/Mage/Checkout/Model/Cart.php index f94b64621a..fb347ebbf7 100644 --- a/app/code/core/Mage/Checkout/Model/Cart.php +++ b/app/code/core/Mage/Checkout/Model/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Api.php index 4cb7245996..203273e315 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Api/V2.php index 59eb34427a..74b3e829eb 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php index 3221863d22..6aad5b9051 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php index f4fc3f3e46..979e521619 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Coupon/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php index a0cdc5abf3..6f4b77d998 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php index 096f0e4dae..d53eccf02f 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php index 188fb6431c..f535514d3f 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php index 1d0b311c6a..b2bc69e6bc 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php index 751fc203d5..914c61abce 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Product/Api.php @@ -1,329 +1,329 @@ - - */ - -class Mage_Checkout_Model_Cart_Product_Api extends Mage_Checkout_Model_Api_Resource_Product -{ - protected function _prepareProductsData($data) - { - if (!is_array($data)) { - return null; - } - - $_data = array(); - if (is_array($data) && is_null($data[0])) { - $_data[] = $data; - } else { - $_data = $data; - } - - return $_data; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function add($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - $errors = array(); - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); - continue; - } - - $productRequest = $this->_getProductRequest($productItem); - try { - $result = $quote->addProduct($productByItem, $productRequest); - if (is_string($result)) { - Mage::throwException($result); - } - } catch (Mage_Core_Exception $e) { - $errors[] = $e->getMessage(); - } - } - - if (!empty($errors)) { - $this->_fault("add_product_fault", implode(PHP_EOL, $errors)); - } - - try { - $quote->collectTotals()->save(); - } catch(Exception $e) { - $this->_fault("add_product_quote_save_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function update($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - $errors = array(); - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); - continue; - } - - /** @var $quoteItem Mage_Sales_Model_Quote_Item */ - $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); - if (is_null($quoteItem->getId())) { - $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); - continue; - } - - if ($productItem['qty'] > 0) { - $quoteItem->setQty($productItem['qty']); - } - } - - if (!empty($errors)) { - $this->_fault("update_product_fault", implode(PHP_EOL, $errors)); - } - - try { - $quote->save(); - } catch(Exception $e) { - $this->_fault("update_product_quote_save_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function remove($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - $errors = array(); - foreach ($productsData as $productItem) { - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); - continue; - } - - try { - /** @var $quoteItem Mage_Sales_Model_Quote_Item */ - $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); - if (is_null($quoteItem->getId())) { - $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); - continue; - } - $quote->removeItem($quoteItem->getId()); - } catch (Mage_Core_Exception $e) { - $errors[] = $e->getMessage(); - } - } - - if (!empty($errors)) { - $this->_fault("remove_product_fault", implode(PHP_EOL, $errors)); - } - - try { - $quote->save(); - } catch(Exception $e) { - $this->_fault("remove_product_quote_save_fault", $e->getMessage()); - } - - return true; - } - - /** - * @param $quoteId - * @param $store - * @return array - */ - public function items($quoteId, $store = null) - { - $quote = $this->_getQuote($quoteId, $store); - if (empty($store)) { - $store = $quote->getStoreId(); - } - - if (!$quote->getItemsCount()) { - return array(); - } - - $productsResult = array(); - foreach ($quote->getAllItems() as $item) { - /** @var $item Mage_Sales_Model_Quote_Item */ - $product = $item->getProduct(); - $productsResult[] = array( // Basic product data - 'product_id' => $product->getId(), - 'sku' => $product->getSku(), - 'set' => $product->getAttributeSetId(), - 'type' => $product->getTypeId(), - 'categories' => $product->getCategoryIds(), - 'websites' => $product->getWebsiteIds() - ); - } - - return $productsResult; - } - - /** - * @param $quoteId - * @param $productsData - * @param $store - * @return bool - */ - public function moveToCustomerQuote($quoteId, $productsData, $store=null) - { - $quote = $this->_getQuote($quoteId, $store); - - if (empty($store)) { - $store = $quote->getStoreId(); - } - - $customer = $quote->getCustomer(); - if (is_null($customer->getId())) { - $this->_fault('customer_not_set_for_quote'); - } - - /** @var $customerQuote Mage_Sales_Model_Quote */ - $customerQuote = Mage::getModel('sales/quote') - ->setStoreId($store) - ->loadByCustomer($customer); - - if (is_null($customerQuote->getId())) { - $this->_fault('customer_quote_not_exist'); - } - - if ($customerQuote->getId() == $quote->getId()) { - $this->_fault('quotes_are_similar'); - } - - $productsData = $this->_prepareProductsData($productsData); - if (empty($productsData)) { - $this->_fault('invalid_product_data'); - } - - $errors = array(); - foreach($productsData as $key => $productItem){ - if (isset($productItem['product_id'])) { - $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); - } else if (isset($productItem['sku'])) { - $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); - } else { - $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); - continue; - } - - try { - /** @var $quoteItem Mage_Sales_Model_Quote_Item */ - $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); - if($quoteItem->getId()){ - $customerQuote->addItem($quoteItem); - $quote->removeItem($quoteItem->getId()); - unset($productsData[$key]); - } else { - $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); - } - } catch (Mage_Core_Exception $e) { - $errors[] = $e->getMessage(); - } - } - - if (count($productsData) || !empty($errors)) { - $this->_fault('unable_to_move_all_products', implode(PHP_EOL, $errors)); - } - - try { - $customerQuote - ->collectTotals() - ->save(); - - $quote - ->collectTotals() - ->save(); - } catch (Exception $e) { - $this->_fault("product_move_quote_save_fault", $e->getMessage()); - } - - return true; - } -} + + */ + +class Mage_Checkout_Model_Cart_Product_Api extends Mage_Checkout_Model_Api_Resource_Product +{ + protected function _prepareProductsData($data) + { + if (!is_array($data)) { + return null; + } + + $_data = array(); + if (is_array($data) && is_null($data[0])) { + $_data[] = $data; + } else { + $_data = $data; + } + + return $_data; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function add($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + $errors = array(); + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); + continue; + } + + $productRequest = $this->_getProductRequest($productItem); + try { + $result = $quote->addProduct($productByItem, $productRequest); + if (is_string($result)) { + Mage::throwException($result); + } + } catch (Mage_Core_Exception $e) { + $errors[] = $e->getMessage(); + } + } + + if (!empty($errors)) { + $this->_fault("add_product_fault", implode(PHP_EOL, $errors)); + } + + try { + $quote->collectTotals()->save(); + } catch(Exception $e) { + $this->_fault("add_product_quote_save_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function update($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + $errors = array(); + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); + continue; + } + + /** @var $quoteItem Mage_Sales_Model_Quote_Item */ + $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); + if (is_null($quoteItem->getId())) { + $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); + continue; + } + + if ($productItem['qty'] > 0) { + $quoteItem->setQty($productItem['qty']); + } + } + + if (!empty($errors)) { + $this->_fault("update_product_fault", implode(PHP_EOL, $errors)); + } + + try { + $quote->save(); + } catch(Exception $e) { + $this->_fault("update_product_quote_save_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function remove($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + $errors = array(); + foreach ($productsData as $productItem) { + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); + continue; + } + + try { + /** @var $quoteItem Mage_Sales_Model_Quote_Item */ + $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); + if (is_null($quoteItem->getId())) { + $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); + continue; + } + $quote->removeItem($quoteItem->getId()); + } catch (Mage_Core_Exception $e) { + $errors[] = $e->getMessage(); + } + } + + if (!empty($errors)) { + $this->_fault("remove_product_fault", implode(PHP_EOL, $errors)); + } + + try { + $quote->save(); + } catch(Exception $e) { + $this->_fault("remove_product_quote_save_fault", $e->getMessage()); + } + + return true; + } + + /** + * @param $quoteId + * @param $store + * @return array + */ + public function items($quoteId, $store = null) + { + $quote = $this->_getQuote($quoteId, $store); + if (empty($store)) { + $store = $quote->getStoreId(); + } + + if (!$quote->getItemsCount()) { + return array(); + } + + $productsResult = array(); + foreach ($quote->getAllItems() as $item) { + /** @var $item Mage_Sales_Model_Quote_Item */ + $product = $item->getProduct(); + $productsResult[] = array( // Basic product data + 'product_id' => $product->getId(), + 'sku' => $product->getSku(), + 'set' => $product->getAttributeSetId(), + 'type' => $product->getTypeId(), + 'categories' => $product->getCategoryIds(), + 'websites' => $product->getWebsiteIds() + ); + } + + return $productsResult; + } + + /** + * @param $quoteId + * @param $productsData + * @param $store + * @return bool + */ + public function moveToCustomerQuote($quoteId, $productsData, $store=null) + { + $quote = $this->_getQuote($quoteId, $store); + + if (empty($store)) { + $store = $quote->getStoreId(); + } + + $customer = $quote->getCustomer(); + if (is_null($customer->getId())) { + $this->_fault('customer_not_set_for_quote'); + } + + /** @var $customerQuote Mage_Sales_Model_Quote */ + $customerQuote = Mage::getModel('sales/quote') + ->setStoreId($store) + ->loadByCustomer($customer); + + if (is_null($customerQuote->getId())) { + $this->_fault('customer_quote_not_exist'); + } + + if ($customerQuote->getId() == $quote->getId()) { + $this->_fault('quotes_are_similar'); + } + + $productsData = $this->_prepareProductsData($productsData); + if (empty($productsData)) { + $this->_fault('invalid_product_data'); + } + + $errors = array(); + foreach($productsData as $key => $productItem){ + if (isset($productItem['product_id'])) { + $productByItem = $this->_getProduct($productItem['product_id'], $store, "id"); + } else if (isset($productItem['sku'])) { + $productByItem = $this->_getProduct($productItem['sku'], $store, "sku"); + } else { + $errors[] = Mage::helper('checkout')->__("One item of products do not have identifier or sku"); + continue; + } + + try { + /** @var $quoteItem Mage_Sales_Model_Quote_Item */ + $quoteItem = $this->_getQuoteItemByProduct($quote, $productByItem, $this->_getProductRequest($productItem)); + if($quoteItem->getId()){ + $customerQuote->addItem($quoteItem); + $quote->removeItem($quoteItem->getId()); + unset($productsData[$key]); + } else { + $errors[] = Mage::helper('checkout')->__("One item of products is not belong any of quote item"); + } + } catch (Mage_Core_Exception $e) { + $errors[] = $e->getMessage(); + } + } + + if (count($productsData) || !empty($errors)) { + $this->_fault('unable_to_move_all_products', implode(PHP_EOL, $errors)); + } + + try { + $customerQuote + ->collectTotals() + ->save(); + + $quote + ->collectTotals() + ->save(); + } catch (Exception $e) { + $this->_fault("product_move_quote_save_fault", $e->getMessage()); + } + + return true; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php index ff0d53da65..f386815018 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php index cfb797cf5b..a9126b458e 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php index 3b9106c558..e3c5a55628 100644 --- a/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php +++ b/app/code/core/Mage/Checkout/Model/Cart/Shipping/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Config/Source/Cart/Summary.php b/app/code/core/Mage/Checkout/Model/Config/Source/Cart/Summary.php index 899d4ca582..af73e517d2 100644 --- a/app/code/core/Mage/Checkout/Model/Config/Source/Cart/Summary.php +++ b/app/code/core/Mage/Checkout/Model/Config/Source/Cart/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Checkout_Model_Config_Source_Cart_Summary diff --git a/app/code/core/Mage/Checkout/Model/Mysql4/Agreement.php b/app/code/core/Mage/Checkout/Model/Mysql4/Agreement.php index 5d8db611cf..379c3a164b 100644 --- a/app/code/core/Mage/Checkout/Model/Mysql4/Agreement.php +++ b/app/code/core/Mage/Checkout/Model/Mysql4/Agreement.php @@ -20,73 +20,18 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Checkout_Model_Mysql4_Agreement extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('checkout/agreement', 'agreement_id'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - // format height - $height = $object->getContentHeight(); - if (!$height) { - $height = ''; - } - if ($height && preg_match('/[0-9]$/', $height)) { - $height .= 'px'; - } - $object->setContentHeight($height); - return parent::_beforeSave($object); - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $condition = $this->_getWriteAdapter()->quoteInto('agreement_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('checkout/agreement_store'), $condition); - - foreach ((array)$object->getData('stores') as $store) { - $storeArray = array(); - $storeArray['agreement_id'] = $object->getId(); - $storeArray['store_id'] = $store; - $this->_getWriteAdapter()->insert($this->getTable('checkout/agreement_store'), $storeArray); - } - - return parent::_afterSave($object); - } - - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('checkout/agreement_store')) - ->where('agreement_id = ?', $object->getId()); - - if ($data = $this->_getReadAdapter()->fetchAll($select)) { - $storesArray = array(); - foreach ($data as $row) { - $storesArray[] = $row['store_id']; - } - $object->setData('store_id', $storesArray); - } - - return parent::_afterLoad($object); - } - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - - if ($object->getStoreId()) { - $select->join(array('cps' => $this->getTable('checkout/agreement_store')), $this->getMainTable().'.agreement_id = `cps`.agreement_id') - ->where('is_active=1 AND `cps`.store_id in (0, ?) ', $object->getStoreId()) - ->order('store_id DESC') - ->limit(1); - } - return $select; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Checkout + * @author Magento Core Team + */ +class Mage_Checkout_Model_Mysql4_Agreement extends Mage_Checkout_Model_Resource_Agreement +{ } diff --git a/app/code/core/Mage/Checkout/Model/Mysql4/Agreement/Collection.php b/app/code/core/Mage/Checkout/Model/Mysql4/Agreement/Collection.php index 8d55dd61e7..635e2412dc 100644 --- a/app/code/core/Mage/Checkout/Model/Mysql4/Agreement/Collection.php +++ b/app/code/core/Mage/Checkout/Model/Mysql4/Agreement/Collection.php @@ -20,69 +20,18 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Checkout_Model_Mysql4_Agreement_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - /** - * @var bool - */ - protected $_isStoreFilterWithAdmin = true; - - /** - * Initialize resource - * - */ - protected function _construct() - { - $this->_init('checkout/agreement'); - } - - /** - * Filter collection by specified store ids - * - * @param int|Mage_Core_Model_Store $store - * @return Mage_Checkout_Model_Mysql4_Agreement_Collection - */ - public function addStoreFilter($store) - { - // check and prepare data - if ($store instanceof Mage_Core_Model_Store) { - $store = array($store->getId()); - }elseif(is_numeric($store)){ - $store = array($store); - } - $alias = 'store_table_' . implode('_', $store); - if ($this->getFlag($alias)) { - return $this; - } - $read = $this->getConnection(); - - // add filter - $this->getSelect()->join( - array($alias => $this->getTable('checkout/agreement_store')), - 'main_table.agreement_id = '.$alias.'.agreement_id', - array() - ) - ->where($alias . '.store_id in (?)', ($this->_isStoreFilterWithAdmin ? array(0, $store) : $store)) - ->group('main_table.agreement_id'); - - $this->setFlag($alias, true); - - return $this; - } - /** - * Make store filter using admin website or not - * - * @param bool $value - * @return Mage_Checkout_Model_Mysql4_Agreement_Collection - */ - public function setIsStoreFilterWithAdmin($value) - { - $this->_isStoreFilterWithAdmin = (bool)$value; - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Checkout + * @author Magento Core Team + */ +class Mage_Checkout_Model_Mysql4_Agreement_Collection extends Mage_Checkout_Model_Resource_Agreement_Collection +{ } diff --git a/app/code/core/Mage/Checkout/Model/Mysql4/Cart.php b/app/code/core/Mage/Checkout/Model/Mysql4/Cart.php index 55bfc1f6dd..e4be9495f7 100644 --- a/app/code/core/Mage/Checkout/Model/Mysql4/Cart.php +++ b/app/code/core/Mage/Checkout/Model/Mysql4/Cart.php @@ -20,71 +20,18 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Checkout_Model_Mysql4_Cart extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Checkout + * @author Magento Core Team + */ +class Mage_Checkout_Model_Mysql4_Cart extends Mage_Checkout_Model_Resource_Cart { - protected function _construct() - { - $this->_init('sales/quote', 'entity_id'); - } - - public function getItemsQty($cart) - { - return $this->fetchItemsSummaryQty($cart->getQuote()->getId()); - } - - public function fetchItemsSummaryQty($quoteId) - { - $entityType = Mage::getSingleton('eav/config')->getEntityType('quote_item'); - $attribute = Mage::getSingleton('eav/config')->getAttribute($entityType->getEntityTypeId(), 'qty'); - - $qtyAttributeTable = $this->getMainTable().'_'.$attribute->getBackendType(); - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('qty'=>$qtyAttributeTable), 'sum(qty.value)') - ->join(array('e'=>$this->getMainTable()), 'e.entity_id=qty.entity_id', array()) - ->where('e.parent_id=?', $quoteId) - ->where('qty.entity_type_id=?', $entityType->getEntityTypeId()) - ->where('qty.attribute_id=?', $attribute->getAttributeId()); - $qty = $read->fetchOne($select); - return $qty; - } - - public function fetchItemsSummary($quoteId) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('q'=>$this->getTable('sales/quote')), array('items_qty', 'items_count')) - ->where('q.entity_id=?', $quoteId); - - $result = $read->fetchRow($select); - return $result ? $result : array('items_qty'=>0, 'items_count'=>0); - } - - public function fetchItems($quoteId) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('qi'=>$this->getTable('sales/quote_item')), array('id'=>'item_id', 'product_id', 'super_product_id', 'qty', 'created_at')) - ->where('qi.quote_id=?', $quoteId); - - return $read->fetchAll($select); - } - - /** - * Make collection not to load products that are in specified quote - * - * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection - * @param int $quoteId - */ - public function addExcludeProductFilter($collection, $quoteId) { - $collection->getSelect()->where(new Zend_Db_Expr(sprintf( - 'e.entity_id NOT IN (SELECT product_id FROM %s WHERE quote_id=%d)', - $this->getTable('sales/quote_item'), $quoteId - ))); - } } diff --git a/app/code/core/Mage/Checkout/Model/Mysql4/Setup.php b/app/code/core/Mage/Checkout/Model/Mysql4/Setup.php index 6f8f98b770..5eade76bc8 100644 --- a/app/code/core/Mage/Checkout/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Checkout/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,6 +32,6 @@ * @package Mage_Checkout * @author Magento Core Team */ -class Mage_Checkout_Model_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup +class Mage_Checkout_Model_Mysql4_Setup extends Mage_Checkout_Model_Resource_Setup { } diff --git a/app/code/core/Mage/Checkout/Model/Observer.php b/app/code/core/Mage/Checkout/Model/Observer.php index 114b604aef..1b6970209c 100644 --- a/app/code/core/Mage/Checkout/Model/Observer.php +++ b/app/code/core/Mage/Checkout/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Resource/Agreement.php b/app/code/core/Mage/Checkout/Model/Resource/Agreement.php new file mode 100755 index 0000000000..4056ff857d --- /dev/null +++ b/app/code/core/Mage/Checkout/Model/Resource/Agreement.php @@ -0,0 +1,129 @@ + + */ +class Mage_Checkout_Model_Resource_Agreement extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('checkout/agreement', 'agreement_id'); + } + + /** + * Method to run before save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + // format height + $height = $object->getContentHeight(); + if (!$height) { + $height = ''; + } + if ($height && preg_match('/[0-9]$/', $height)) { + $height .= 'px'; + } + $object->setContentHeight($height); + return parent::_beforeSave($object); + } + + /** + * Method to run after save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $condition = array('agreement_id = ?' => $object->getId()); + $this->_getWriteAdapter()->delete($this->getTable('checkout/agreement_store'), $condition); + + foreach ((array)$object->getData('stores') as $store) { + $storeArray = array(); + $storeArray['agreement_id'] = $object->getId(); + $storeArray['store_id'] = $store; + $this->_getWriteAdapter()->insert($this->getTable('checkout/agreement_store'), $storeArray); + } + + return parent::_afterSave($object); + } + + /** + * Method to run after load + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('checkout/agreement_store'), array('store_id')) + ->where('agreement_id = :agreement_id'); + + if ($stores = $this->_getReadAdapter()->fetchCol($select, array(':agreement_id' => $object->getId()))) { + $object->setData('store_id', $stores); + } + + return parent::_afterLoad($object); + } + + /** + * Get load select + * + * @param string $field + * @param value $value + * @param Varien_Object $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($object->getStoreId()) { + $select->join( + array('cps' => $this->getTable('checkout/agreement_store')), + $this->getMainTable() . '.agreement_id = cps.agreement_id' + ) + ->where('is_active=1') + ->where('cps.store_id IN (0, ?)', $object->getStoreId()) + ->order('store_id DESC') + ->limit(1); + } + return $select; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Resource/Agreement/Collection.php b/app/code/core/Mage/Checkout/Model/Resource/Agreement/Collection.php new file mode 100755 index 0000000000..fb555b78f8 --- /dev/null +++ b/app/code/core/Mage/Checkout/Model/Resource/Agreement/Collection.php @@ -0,0 +1,109 @@ + + */ +class Mage_Checkout_Model_Resource_Agreement_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Is store filter with admin store + * + * @var bool + */ + protected $_isStoreFilterWithAdmin = true; + + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('checkout/agreement'); + } + + /** + * Filter collection by specified store ids + * + * @param int|Mage_Core_Model_Store $store + * @return Mage_Checkout_Model_Resource_Agreement_Collection + */ + public function addStoreFilter($store) + { + // check and prepare data + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } elseif (is_numeric($store)) { + $store = array($store); + } + + $alias = 'store_table_' . implode('_', $store); + if ($this->getFlag($alias)) { + return $this; + } + + $storeFilter = array($store); + if ($this->_isStoreFilterWithAdmin) { + $storeFilter[] = 0; + } + + // add filter + $this->getSelect()->join( + array($alias => $this->getTable('checkout/agreement_store')), + 'main_table.agreement_id = ' . $alias . '.agreement_id', + array() + ) + ->where($alias . '.store_id IN (?)', $storeFilter) + ->group('main_table.agreement_id'); + + $this->setFlag($alias, true); + + /* + * Allow Analytic functions usage + */ + $this->_useAnalyticFunction = true; + + + return $this; + } + + /** + * Make store filter using admin website or not + * + * @param bool $value + * @return Mage_Checkout_Model_Resource_Agreement_Collection + */ + public function setIsStoreFilterWithAdmin($value) + { + $this->_isStoreFilterWithAdmin = (bool)$value; + return $this; + } +} diff --git a/app/code/core/Mage/Checkout/Model/Resource/Cart.php b/app/code/core/Mage/Checkout/Model/Resource/Cart.php new file mode 100755 index 0000000000..6729faff81 --- /dev/null +++ b/app/code/core/Mage/Checkout/Model/Resource/Cart.php @@ -0,0 +1,97 @@ + + */ +class Mage_Checkout_Model_Resource_Cart extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote', 'entity_id'); + } + + /** + * Fetch items summary + * + * @param int $quoteId + * @return array + */ + public function fetchItemsSummary($quoteId) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('q'=>$this->getTable('sales/quote')), array('items_qty', 'items_count')) + ->where('q.entity_id = :quote_id'); + + $result = $read->fetchRow($select, array(':quote_id' => $quoteId)); + return $result ? $result : array('items_qty'=>0, 'items_count'=>0); + } + + /** + * Fetch items + * + * @param int $quoteId + * @return array + */ + public function fetchItems($quoteId) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('qi'=>$this->getTable('sales/quote_item')), + array('id'=>'item_id', 'product_id', 'super_product_id', 'qty', 'created_at')) + ->where('qi.quote_id = :quote_id'); + + return $read->fetchAll($select, array(':quote_id' => $quoteId)); + } + + /** + * Make collection not to load products that are in specified quote + * + * @param Mage_Catalog_Model_Resource_Product_Collection $collection + * @param int $quoteId + * @return Mage_Checkout_Model_Resource_Cart + */ + public function addExcludeProductFilter($collection, $quoteId) + { + $adapter = $this->_getReadAdapter(); + $exclusionSelect = $adapter->select() + ->from($this->getTable('sales/quote_item'), array('product_id')) + ->where('quote_id = ?', $quoteId); + $condition = $adapter->prepareSqlCondition('e.entity_id', array('nin' => $exclusionSelect)); + $collection->getSelect()->where($condition); + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Customoptions.php b/app/code/core/Mage/Checkout/Model/Resource/Setup.php old mode 100644 new mode 100755 similarity index 73% rename from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Customoptions.php rename to app/code/core/Mage/Checkout/Model/Resource/Setup.php index 5f989689ac..d7f39115bd --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Customoptions.php +++ b/app/code/core/Mage/Checkout/Model/Resource/Setup.php @@ -19,19 +19,19 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Checkout + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Adminhtml block for fieldset of product custom options + * Checkout Resource Setup Model * - * @category Mage - * @package Mage_Adminhtml + * @category Mage + * @package Mage_Checkout * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Composite_Fieldset_Customoptions extends Mage_Adminhtml_Block_Catalog_Product_Composite_Configure +class Mage_Checkout_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup { - } diff --git a/app/code/core/Mage/Checkout/Model/Session.php b/app/code/core/Mage/Checkout/Model/Session.php index f68c5b97f5..423cd82072 100644 --- a/app/code/core/Mage/Checkout/Model/Session.php +++ b/app/code/core/Mage/Checkout/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Type/Abstract.php b/app/code/core/Mage/Checkout/Model/Type/Abstract.php index 6aa8982243..9957e31057 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Abstract.php +++ b/app/code/core/Mage/Checkout/Model/Type/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php index 84463bba45..eabe75b163 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php +++ b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php b/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php index 03ab18f0d3..97fda4df06 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php +++ b/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index f9d145505c..6d3694588d 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/controllers/CartController.php b/app/code/core/Mage/Checkout/controllers/CartController.php index 0689acc93f..12dc0b036e 100644 --- a/app/code/core/Mage/Checkout/controllers/CartController.php +++ b/app/code/core/Mage/Checkout/controllers/CartController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/controllers/IndexController.php b/app/code/core/Mage/Checkout/controllers/IndexController.php index 28d9bbede2..6a5ff01a8d 100644 --- a/app/code/core/Mage/Checkout/controllers/IndexController.php +++ b/app/code/core/Mage/Checkout/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php index 8861cf210b..a764e94bb2 100644 --- a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php +++ b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/controllers/MultishippingController.php b/app/code/core/Mage/Checkout/controllers/MultishippingController.php index cf4895c060..3a13587362 100644 --- a/app/code/core/Mage/Checkout/controllers/MultishippingController.php +++ b/app/code/core/Mage/Checkout/controllers/MultishippingController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -107,6 +107,8 @@ public function preDispatch() } if (!Mage::helper('checkout')->isMultishippingCheckoutAvailable()) { + $error = $this->_getCheckout()->getMinimumAmountError(); + $this->_getCheckoutSession()->addError($this->__($error)); $this->_redirectUrl($this->_getHelper()->getCartUrl()); $this->setFlag('', self::FLAG_NO_DISPATCH, true); return $this; diff --git a/app/code/core/Mage/Checkout/controllers/OnepageController.php b/app/code/core/Mage/Checkout/controllers/OnepageController.php index 8c2b2282bc..c1ea4a56b8 100644 --- a/app/code/core/Mage/Checkout/controllers/OnepageController.php +++ b/app/code/core/Mage/Checkout/controllers/OnepageController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/etc/adminhtml.xml b/app/code/core/Mage/Checkout/etc/adminhtml.xml index f1a72b8b06..a72062df07 100644 --- a/app/code/core/Mage/Checkout/etc/adminhtml.xml +++ b/app/code/core/Mage/Checkout/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Checkout/etc/api.xml b/app/code/core/Mage/Checkout/etc/api.xml index f336ba941d..0c582315a3 100644 --- a/app/code/core/Mage/Checkout/etc/api.xml +++ b/app/code/core/Mage/Checkout/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Checkout/etc/config.xml b/app/code/core/Mage/Checkout/etc/config.xml index 1eb87c0c2c..6f1a381831 100644 --- a/app/code/core/Mage/Checkout/etc/config.xml +++ b/app/code/core/Mage/Checkout/etc/config.xml @@ -21,82 +21,141 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.9.5 + 1.6.0.0 - customer_prefix - customer_firstname - customer_middlename - customer_lastname - customer_suffix - customer_email - customer_group_id - customer_tax_class_id + + customer_prefix + + + customer_firstname + + + customer_middlename + + + customer_lastname + + + customer_suffix + + + customer_email + + + customer_group_id + + + customer_tax_class_id + - * - * - * - * - * - * - dob - taxvat - gender + + * + + + * + + + * + + + * + + + * + + + * + + + dob + + + taxvat + + + gender + - prefix - firstname - middlename - lastname - suffix - email - dob - taxvat - gender + + prefix + + + firstname + + + middlename + + + lastname + + + suffix + + + email + + + dob + + + taxvat + + + gender + - Mage_Checkout_Block + + Mage_Checkout_Block + Mage_Checkout_Model - checkout_mysql4 + checkout_resource - - Mage_Checkout_Model_Mysql4 + + Mage_Checkout_Model_Resource + checkout_mysql4 - checkout_agreement
- checkout_agreement_store
+ + checkout_agreement
+
+ + checkout_agreement_store
+
-
+
Mage_Checkout - Mage_Checkout_Model_Mysql4_Setup + Mage_Checkout_Model_Resource_Setup @@ -152,27 +211,27 @@ - - Mage_Checkout.csv - + + Mage_Checkout.csv + - - - checkout.xml - - + + + checkout.xml + + - - Mage_Checkout.csv - + + Mage_Checkout.csv + diff --git a/app/code/core/Mage/Checkout/etc/system.xml b/app/code/core/Mage/Checkout/etc/system.xml index 73fb00b965..499ddd004a 100644 --- a/app/code/core/Mage/Checkout/etc/system.xml +++ b/app/code/core/Mage/Checkout/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php b/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..ec40ee36a5 --- /dev/null +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php @@ -0,0 +1,783 @@ +startSetup(); +/** + * Create table 'checkout/agreement' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('checkout/agreement')) + ->addColumn('agreement_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Agreement Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Content') + ->addColumn('content_height', Varien_Db_Ddl_Table::TYPE_TEXT, 25, array( + ), 'Content Height') + ->addColumn('checkbox_text', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Checkbox Text') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Active') + ->addColumn('is_html', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Html') + ->setComment('Checkout Agreement'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'checkout/agreement_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('checkout/agreement_store')) + ->addColumn('agreement_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Agreement Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store Id') + ->addForeignKey($installer->getFkName('checkout/agreement_store', 'agreement_id', 'checkout/agreement', 'agreement_id'), + 'agreement_id', $installer->getTable('checkout/agreement'), 'agreement_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('checkout/agreement_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Checkout Agreement Store'); +$installer->getConnection()->createTable($table); + +$setup = $installer->getConnection(); + +$select = $setup->select() + ->from($installer->getTable('core/config_data'), 'COUNT(*)') + ->where('path=?', 'customer/address/prefix_show') + ->where('value NOT LIKE ?', '0'); +$showPrefix = (bool)Mage::helper('customer/address')->getConfig('prefix_show') + || ($setup->fetchOne($select) > 0); + +$select = $setup->select() + ->from($installer->getTable('core/config_data'), 'COUNT(*)') + ->where('path=?', 'customer/address/middlename_show') + ->where('value NOT LIKE ?', '0'); +$showMiddlename = (bool)Mage::helper('customer/address')->getConfig('middlename_show') + || ($setup->fetchOne($select) > 0); + +$select = $setup->select() + ->from($installer->getTable('core/config_data'), 'COUNT(*)') + ->where('path=?', 'customer/address/suffix_show') + ->where('value NOT LIKE ?', '0'); +$showSuffix = (bool)Mage::helper('customer/address')->getConfig('suffix_show') + || ($setup->fetchOne($select) > 0); + +$select = $setup->select() + ->from($installer->getTable('core/config_data'), 'COUNT(*)') + ->where('path=?', 'customer/address/dob_show') + ->where('value NOT LIKE ?', '0'); +$showDob = (bool)Mage::helper('customer/address')->getConfig('dob_show') + || ($setup->fetchOne($select) > 0); + +$select = $setup->select() + ->from($installer->getTable('core/config_data'), 'COUNT(*)') + ->where('path=?', 'customer/address/taxvat_show') + ->where('value NOT LIKE ?', '0'); +$showTaxVat = (bool)Mage::helper('customer/address')->getConfig('taxvat_show') + || ($setup->fetchOne($select) > 0); + +$customerEntityTypeId = $installer->getEntityTypeId('customer'); +$addressEntityTypeId = $installer->getEntityTypeId('customer_address'); + +/** + ***************************************************************************** + * checkout/onepage/register + ***************************************************************************** + */ + +$setup->insert($installer->getTable('eav/form_type'), array( + 'code' => 'checkout_onepage_register', + 'label' => 'checkout_onepage_register', + 'is_system' => 1, + 'theme' => '', + 'store_id' => 0 +)); +$formTypeId = $setup->lastInsertId($installer->getTable('eav/form_type')); + +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $customerEntityTypeId +)); +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $addressEntityTypeId +)); + +$elementSort = 0; +if ($showPrefix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), + 'sort_order' => $elementSort++ +)); +if ($showMiddlename) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), + 'sort_order' => $elementSort++ +)); +if ($showSuffix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'company'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'email'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'street'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'city'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'region'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'postcode'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'country_id'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'telephone'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), + 'sort_order' => $elementSort++ +)); +if ($showDob) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), + 'sort_order' => $elementSort++ + )); +} +if ($showTaxVat) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), + 'sort_order' => $elementSort++ + )); +} + +/** + ***************************************************************************** + * checkout/onepage/register_guest + ***************************************************************************** + */ + +$setup->insert($installer->getTable('eav/form_type'), array( + 'code' => 'checkout_onepage_register_guest', + 'label' => 'checkout_onepage_register_guest', + 'is_system' => 1, + 'theme' => '', + 'store_id' => 0 +)); +$formTypeId = $setup->lastInsertId($installer->getTable('eav/form_type')); + +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $customerEntityTypeId +)); +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $addressEntityTypeId +)); + +$elementSort = 0; +if ($showPrefix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), + 'sort_order' => $elementSort++ +)); +if ($showMiddlename) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), + 'sort_order' => $elementSort++ +)); +if ($showSuffix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'company'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'email'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'street'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'city'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'region'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'postcode'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'country_id'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'telephone'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), + 'sort_order' => $elementSort++ +)); +if ($showDob) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), + 'sort_order' => $elementSort++ + )); +} +if ($showTaxVat) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), + 'sort_order' => $elementSort++ + )); +} + +/** + ***************************************************************************** + * checkout/onepage/billing_address + ***************************************************************************** + */ + +$setup->insert($installer->getTable('eav/form_type'), array( + 'code' => 'checkout_onepage_billing_address', + 'label' => 'checkout_onepage_billing_address', + 'is_system' => 1, + 'theme' => '', + 'store_id' => 0 +)); +$formTypeId = $setup->lastInsertId($installer->getTable('eav/form_type')); + +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $addressEntityTypeId +)); + +$elementSort = 0; +if ($showPrefix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), + 'sort_order' => $elementSort++ +)); +if ($showMiddlename) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), + 'sort_order' => $elementSort++ +)); +if ($showSuffix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'company'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'street'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'city'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'region'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'postcode'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'country_id'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'telephone'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), + 'sort_order' => $elementSort++ +)); + +/** + ***************************************************************************** + * checkout/onepage/shipping_address + ***************************************************************************** + */ + +$setup->insert($installer->getTable('eav/form_type'), array( + 'code' => 'checkout_onepage_shipping_address', + 'label' => 'checkout_onepage_shipping_address', + 'is_system' => 1, + 'theme' => '', + 'store_id' => 0 +)); +$formTypeId = $setup->lastInsertId($installer->getTable('eav/form_type')); + +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $addressEntityTypeId +)); + +$elementSort = 0; +if ($showPrefix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), + 'sort_order' => $elementSort++ +)); +if ($showMiddlename) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), + 'sort_order' => $elementSort++ +)); +if ($showSuffix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'company'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'street'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'city'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'region'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'postcode'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'country_id'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'telephone'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), + 'sort_order' => $elementSort++ +)); + +/** + ***************************************************************************** + * checkout/multishipping/register/ + ***************************************************************************** + */ + +$setup->insert($installer->getTable('eav/form_type'), array( + 'code' => 'checkout_multishipping_register', + 'label' => 'checkout_multishipping_register', + 'is_system' => 1, + 'theme' => '', + 'store_id' => 0 +)); +$formTypeId = $setup->lastInsertId($installer->getTable('eav/form_type')); + +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $customerEntityTypeId +)); +$setup->insert($installer->getTable('eav/form_type_entity'), array( + 'type_id' => $formTypeId, + 'entity_type_id' => $addressEntityTypeId +)); + +$setup->insert($installer->getTable('eav/form_fieldset'), array( + 'type_id' => $formTypeId, + 'code' => 'general', + 'sort_order' => 1 +)); +$fieldsetId = $setup->lastInsertId($installer->getTable('eav/form_fieldset')); + +$setup->insert($installer->getTable('eav/form_fieldset_label'), array( + 'fieldset_id' => $fieldsetId, + 'store_id' => 0, + 'label' => 'Personal Information' +)); + +$elementSort = 0; +if ($showPrefix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'prefix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'firstname'), + 'sort_order' => $elementSort++ +)); +if ($showMiddlename) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'lastname'), + 'sort_order' => $elementSort++ +)); +if ($showSuffix) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'suffix'), + 'sort_order' => $elementSort++ + )); +} +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'email'), + 'sort_order' => $elementSort++ +)); +if ($showDob) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), + 'sort_order' => $elementSort++ + )); +} +if ($showTaxVat) { + $setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), + 'sort_order' => $elementSort++ + )); +} + +$setup->insert($installer->getTable('eav/form_fieldset'), array( + 'type_id' => $formTypeId, + 'code' => 'address', + 'sort_order' => 2 +)); +$fieldsetId = $setup->lastInsertId($installer->getTable('eav/form_fieldset')); + +$setup->insert($installer->getTable('eav/form_fieldset_label'), array( + 'fieldset_id' => $fieldsetId, + 'store_id' => 0, + 'label' => 'Address Information' +)); + +$elementSort = 0; +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'company'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'telephone'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'street'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'city'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'region'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'postcode'), + 'sort_order' => $elementSort++ +)); +$setup->insert($installer->getTable('eav/form_element'), array( + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'country_id'), + 'sort_order' => $elementSort++ +)); + +$table = $installer->getTable('core/config_data'); + +$select = $setup->select() + ->from($table, array('config_id', 'value')) + ->where('path = ?', 'checkout/options/onepage_checkout_disabled'); + +$data = $setup->fetchAll($select); + +if ($data) { + try { + $setup->beginTransaction(); + + foreach ($data as $value) { + $bind = array( + 'path' => 'checkout/options/onepage_checkout_enabled', + 'value' => !((bool)$value['value']) + ); + $where = 'config_id = ' . $value['config_id']; + $setup->update($table, $bind, $where); + } + + $setup->commit(); + } catch (Exception $e) { + $setup->rollback(); + throw $e; + } +} + +$installer->endSetup(); diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-install-0.9.1.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-install-0.9.1.php index 3ca9c85152..7d64ae39a9 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-install-0.9.1.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-install-0.9.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.0-0.9.1.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.0-0.9.1.php index fe2a5e7a53..bbac85d661 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.0-0.9.1.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.0-0.9.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.1-0.9.2.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.1-0.9.2.php index d123db4dce..b7ba6d3137 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.1-0.9.2.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.1-0.9.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.2-0.9.3.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.2-0.9.3.php index f04c310c4e..38b4208551 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.2-0.9.3.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.2-0.9.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php index 6d80231e7d..f77af8a259 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.4-0.9.5.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.4-0.9.5.php index 9c18134092..f016b98904 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.4-0.9.5.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.4-0.9.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Checkout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..577f3c17d1 --- /dev/null +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,162 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('checkout/agreement_store'), + 'FK_CHECKOUT_AGREEMENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('checkout/agreement_store'), + 'FK_CHECKOUT_AGREEMENT_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('checkout/agreement_store'), + 'AGREEMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('checkout/agreement_store'), + 'FK_CHECKOUT_AGREEMENT_STORE' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('checkout/agreement') => array( + 'columns' => array( + 'agreement_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Agreement Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Content' + ), + 'content_height' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 25, + 'comment' => 'Content Height' + ), + 'checkbox_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Checkbox Text' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Active' + ), + 'is_html' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Html' + ) + ), + 'comment' => 'Checkout Agreement' + ), + $installer->getTable('checkout/agreement_store') => array( + 'columns' => array( + 'agreement_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Agreement Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Checkout Agreement Store' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('checkout/agreement_store'), + 'PRIMARY', + array('agreement_id','store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('checkout/agreement_store', 'agreement_id', 'checkout/agreement', 'agreement_id'), + $installer->getTable('checkout/agreement_store'), + 'agreement_id', + $installer->getTable('checkout/agreement'), + 'agreement_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('checkout/agreement_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('checkout/agreement_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Cms/Block/Block.php b/app/code/core/Mage/Cms/Block/Block.php index a7f935defd..520833edc4 100644 --- a/app/code/core/Mage/Cms/Block/Block.php +++ b/app/code/core/Mage/Cms/Block/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Block/Page.php b/app/code/core/Mage/Cms/Block/Page.php index 89ab20599b..5bc0c8bb50 100644 --- a/app/code/core/Mage/Cms/Block/Page.php +++ b/app/code/core/Mage/Cms/Block/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Block/Widget/Block.php b/app/code/core/Mage/Cms/Block/Widget/Block.php index 15b8b623c7..b3dd565397 100644 --- a/app/code/core/Mage/Cms/Block/Widget/Block.php +++ b/app/code/core/Mage/Cms/Block/Widget/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Block/Widget/Page/Link.php b/app/code/core/Mage/Cms/Block/Widget/Page/Link.php index d129ed51b7..a7a299b20c 100644 --- a/app/code/core/Mage/Cms/Block/Widget/Page/Link.php +++ b/app/code/core/Mage/Cms/Block/Widget/Page/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Controller/Router.php b/app/code/core/Mage/Cms/Controller/Router.php index 99c8c16a52..81ec6605dd 100644 --- a/app/code/core/Mage/Cms/Controller/Router.php +++ b/app/code/core/Mage/Cms/Controller/Router.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Helper/Data.php b/app/code/core/Mage/Cms/Helper/Data.php index b134415515..ac81ca9d54 100644 --- a/app/code/core/Mage/Cms/Helper/Data.php +++ b/app/code/core/Mage/Cms/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Helper/Page.php b/app/code/core/Mage/Cms/Helper/Page.php index ed08490766..af9d4ecb5d 100644 --- a/app/code/core/Mage/Cms/Helper/Page.php +++ b/app/code/core/Mage/Cms/Helper/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -62,6 +62,7 @@ public function renderPage(Mage_Core_Controller_Front_Action $action, $pageId = */ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pageId = null, $renderLayout = true) { + $page = Mage::getSingleton('cms/page'); if (!is_null($pageId) && $pageId!==$page->getId()) { $delimeterPosition = strrpos($pageId, '|'); @@ -104,6 +105,7 @@ protected function _renderPage(Mage_Core_Controller_Varien_Action $action, $pag Mage::dispatchEvent('cms_page_render', array('page' => $page, 'controller_action' => $action)); + $action->loadLayoutUpdates(); $layoutUpdate = ($page->getCustomLayoutUpdateXml() && $inRange) ? $page->getCustomLayoutUpdateXml() : $page->getLayoutUpdateXml(); $action->getLayout()->getUpdate()->addUpdate($layoutUpdate); diff --git a/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php b/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php index ad6459d052..059f7b247d 100644 --- a/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Model/Block.php b/app/code/core/Mage/Cms/Model/Block.php index 81ad52f385..8b56395e89 100644 --- a/app/code/core/Mage/Cms/Model/Block.php +++ b/app/code/core/Mage/Cms/Model/Block.php @@ -20,15 +20,30 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * CMS block model * - * @category Mage - * @package Mage_Cms + * @method Mage_Cms_Model_Resource_Block _getResource() + * @method Mage_Cms_Model_Resource_Block getResource() + * @method string getTitle() + * @method Mage_Cms_Model_Block setTitle(string $value) + * @method string getIdentifier() + * @method Mage_Cms_Model_Block setIdentifier(string $value) + * @method string getContent() + * @method Mage_Cms_Model_Block setContent(string $value) + * @method string getCreationTime() + * @method Mage_Cms_Model_Block setCreationTime(string $value) + * @method string getUpdateTime() + * @method Mage_Cms_Model_Block setUpdateTime(string $value) + * @method int getIsActive() + * @method Mage_Cms_Model_Block setIsActive(int $value) + * + * @category Mage + * @package Mage_Cms * @author Magento Core Team */ diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Block.php b/app/code/core/Mage/Cms/Model/Mysql4/Block.php index 7841782aeb..49ad5f0f57 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Block.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Block.php @@ -20,151 +20,18 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CMS block model * - * @category Mage - * @package Mage_Cms + * @category Mage + * @package Mage_Cms * @author Magento Core Team */ - -class Mage_Cms_Model_Mysql4_Block extends Mage_Core_Model_Mysql4_Abstract +class Mage_Cms_Model_Mysql4_Block extends Mage_Cms_Model_Resource_Block { - - protected function _construct() - { - $this->_init('cms/block', 'block_id'); - } - - /** - * - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$this->getIsUniqueBlockToStores($object)) { - Mage::throwException(Mage::helper('cms')->__('A block identifier with the same properties already exists in the selected store.')); - } - - if (! $object->getId()) { - $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate()); - } - $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate()); - return $this; - } - - /** - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $condition = $this->_getWriteAdapter()->quoteInto('block_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('cms/block_store'), $condition); - - foreach ((array)$object->getData('stores') as $store) { - $storeArray = array(); - $storeArray['block_id'] = $object->getId(); - $storeArray['store_id'] = $store; - $this->_getWriteAdapter()->insert($this->getTable('cms/block_store'), $storeArray); - } - - return parent::_afterSave($object); - } - - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - - if (!intval($value) && is_string($value)) { - $field = 'identifier'; - } - return parent::load($object, $value, $field); - } - - /** - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - if ($object->getId()) { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('cms/block_store')) - ->where('block_id = ?', $object->getId()); - - if ($data = $this->_getReadAdapter()->fetchAll($select)) { - $storesArray = array(); - foreach ($data as $row) { - $storesArray[] = $row['store_id']; - } - $object->setData('store_id', $storesArray); - } - } - - return parent::_afterLoad($object); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - - $select = parent::_getLoadSelect($field, $value, $object); - - if ($object->getStoreId()) { - $select->join(array('cbs' => $this->getTable('cms/block_store')), $this->getMainTable().'.block_id = cbs.block_id') - ->where('is_active=1 AND cbs.store_id in (0, ?) ', $object->getStoreId()) - ->order('store_id DESC') - ->limit(1); - } - return $select; - } - - /** - * Check for unique of identifier of block to selected store(s). - * - * @param Mage_Core_Model_Abstract $object - * @return bool - */ - public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->join(array('cbs' => $this->getTable('cms/block_store')), $this->getMainTable().'.block_id = `cbs`.block_id') - ->where($this->getMainTable().'.identifier = ?', $object->getData('identifier')); - if ($object->getId()) { - $select->where($this->getMainTable().'.block_id <> ?',$object->getId()); - } - $select->where('`cbs`.store_id IN (?)', (array)$object->getData('stores')); - - if ($this->_getWriteAdapter()->fetchRow($select)) { - return false; - } - - return true; - } - - /** - * Get store ids to which specified item is assigned - * - * @param int $id - * @return array - */ - public function lookupStoreIds($id) - { - return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select() - ->from($this->getTable('cms/block_store'), 'store_id') - ->where("{$this->getIdFieldName()} = ?", $id) - ); - } } diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Block/Collection.php b/app/code/core/Mage/Cms/Model/Mysql4/Block/Collection.php index 3f5f8e3411..a1eac20916 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Block/Collection.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Block/Collection.php @@ -20,73 +20,18 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CMS block model * - * @category Mage - * @package Mage_Cms + * @category Mage + * @package Mage_Cms * @author Magento Core Team */ - -class Mage_Cms_Model_Mysql4_Block_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Cms_Model_Mysql4_Block_Collection extends Mage_Cms_Model_Resource_Block_Collection { - /** - * Declare base table and mapping of some fields - */ - protected function _construct() - { - $this->_init('cms/block'); - $this->_map['fields']['store'] = 'store_table.store_id'; - } - - public function toOptionArray() - { - return $this->_toOptionArray('block_id', 'title'); - } - - /** - * Add filter by store - * - * @param int|Mage_Core_Model_Store $store - * @return Mage_Cms_Model_Mysql4_Block_Collection - */ - public function addStoreFilter($store, $withAdmin = true) - { - if ($store instanceof Mage_Core_Model_Store) { - $store = array($store->getId()); - } - $this->addFilter('store', array('in' => ($withAdmin ? array(0, $store) : $store)), 'public'); - return $this; - } - - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $countSelect = parent::getSelectCountSql(); - $countSelect->reset(Zend_Db_Select::GROUP); - return $countSelect; - } - - /** - * Join store relation table if there is store filter - */ - protected function _renderFiltersBefore() - { - if ($this->getFilter('store')) { - $this->getSelect()->join( - array('store_table' => $this->getTable('cms/block_store')), - 'main_table.block_id = store_table.block_id', - array() - )->group('main_table.block_id'); - } - return parent::_renderFiltersBefore(); - } } diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Page.php b/app/code/core/Mage/Cms/Model/Mysql4/Page.php index 7b3e9706b1..df01fb2d8d 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Page.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Page.php @@ -20,303 +20,18 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Cms page mysql resource * - * @category Mage - * @package Mage_Cms + * @category Mage + * @package Mage_Cms * @author Magento Core Team */ - -class Mage_Cms_Model_Mysql4_Page extends Mage_Core_Model_Mysql4_Abstract +class Mage_Cms_Model_Mysql4_Page extends Mage_Cms_Model_Resource_Page { - /** - * Store model - * - * @var null|Mage_Core_Model_Store - */ - protected $_store = null; - - /** - * Initialize resource model - */ - protected function _construct() - { - $this->_init('cms/page', 'page_id'); - } - - /** - * Process page data before saving - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - /* - * For two attributes which represent datetime data in DB - * we should make converting such as: - * If they are empty we need to convert them into DB - * type NULL so in DB they will be empty and not some default value. - */ - foreach (array('custom_theme_from', 'custom_theme_to') as $dataKey) { - if (!$object->getData($dataKey)) { - $object->setData($dataKey, new Zend_Db_Expr('NULL')); - } - } - - if (!$this->getIsUniquePageToStores($object)) { - Mage::throwException(Mage::helper('cms')->__('A page URL key for specified store already exists.')); - } - - if (!$this->isValidPageIdentifier($object)) { - Mage::throwException(Mage::helper('cms')->__('The page URL key contains capital letters or disallowed symbols.')); - } - - if ($this->isNumericPageIdentifier($object)) { - Mage::throwException(Mage::helper('cms')->__('The page URL key cannot consist only of numbers.')); - } - - if (! $object->getId()) { - $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate()); - } - - $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate()); - return $this; - } - - /** - * Assign page to store views - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $condition = $this->_getWriteAdapter()->quoteInto('page_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('cms/page_store'), $condition); - - foreach ((array)$object->getData('stores') as $store) { - $storeArray = array(); - $storeArray['page_id'] = $object->getId(); - $storeArray['store_id'] = $store; - $this->_getWriteAdapter()->insert($this->getTable('cms/page_store'), $storeArray); - } - - return parent::_afterSave($object); - } - - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (!is_numeric($value)) { - $field = 'identifier'; - } - return parent::load($object, $value, $field); - } - - /** - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('cms/page_store')) - ->where('page_id = ?', $object->getId()); - - if ($data = $this->_getReadAdapter()->fetchAll($select)) { - $storesArray = array(); - foreach ($data as $row) { - $storesArray[] = $row['store_id']; - } - $object->setData('store_id', $storesArray); - } - - return parent::_afterLoad($object); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - - $storeId = $object->getStoreId(); - if ($storeId) { - $select->join( - array('cps' => $this->getTable('cms/page_store')), - $this->getMainTable().'.page_id = `cps`.page_id' - ) - ->where('is_active=1 AND `cps`.store_id IN (' . Mage_Core_Model_App::ADMIN_STORE_ID . ', ?) ', $storeId) - ->order('store_id DESC') - ->limit(1); - } - return $select; - } - - /** - * Check for unique of identifier of page to selected store(s). - * - * @param Mage_Core_Model_Abstract $object - * @return bool - */ - public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->join(array('cps' => $this->getTable('cms/page_store')), $this->getMainTable().'.page_id = `cps`.page_id') - ->where($this->getMainTable().'.identifier = ?', $object->getData('identifier')); - if ($object->getId()) { - $select->where($this->getMainTable().'.page_id <> ?',$object->getId()); - } - $stores = (array)$object->getData('stores'); - if (Mage::app()->isSingleStoreMode()) { - $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); - } - $select->where('`cps`.store_id IN (?)', $stores); - - if ($this->_getWriteAdapter()->fetchRow($select)) { - return false; - } - - return true; - } - - /** - * Check whether page identifier is numeric - * - * @param Mage_Core_Model_Abstract $object - * @return bool - * @date Wed Mar 26 18:12:28 EET 2008 - */ - protected function isNumericPageIdentifier(Mage_Core_Model_Abstract $object) - { - return preg_match('/^[0-9]+$/', $object->getData('identifier')); - } - - /** - * Check whether page identifier is valid - * - * @param Mage_Core_Model_Abstract $object - * @return bool - */ - protected function isValidPageIdentifier(Mage_Core_Model_Abstract $object) - { - return preg_match('/^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/', $object->getData('identifier')); - } - - /** - * Check if page identifier exist for specific store - * return page id if page exists - * - * @param string $identifier - * @param int $storeId - * @return int - */ - public function checkIdentifier($identifier, $storeId) - { - $select = $this->_getReadAdapter()->select()->from(array('main_table'=>$this->getMainTable()), 'page_id') - ->join( - array('cps' => $this->getTable('cms/page_store')), - 'main_table.page_id = `cps`.page_id' - ) - ->where('main_table.identifier=?', $identifier) - ->where('main_table.is_active=1 AND `cps`.store_id IN (' . Mage_Core_Model_App::ADMIN_STORE_ID . ', ?) ', $storeId) - ->order('store_id DESC'); - - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Retrieves cms page title from DB by passed identifier. - * - * @param string $identifier - * @return string|false - */ - public function getCmsPageTitleByIdentifier($identifier) - { - $select = $this->_getReadAdapter()->select(); - /* @var $select Zend_Db_Select */ - $joinExpr = $this->_getReadAdapter()->quoteInto( - 'main_table.page_id = cps.page_id AND (cps.store_id = ' . Mage_Core_Model_App::ADMIN_STORE_ID . ' OR cps.store_id = ?)', $this->getStore()->getId() - ); - $select->from(array('main_table' => $this->getMainTable()), 'title') - ->joinLeft(array('cps' => $this->getTable('cms/page_store')), $joinExpr ,array()) - ->where('main_table.identifier = ?', $identifier) - ->order('cps.store_id DESC'); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Retrieves cms page title from DB by passed id. - * - * @param string $id - * @return string|false - */ - public function getCmsPageTitleById($id) - { - $select = $this->_getReadAdapter()->select(); - /* @var $select Zend_Db_Select */ - $select->from(array('main_table' => $this->getMainTable()), 'title') - ->where('main_table.page_id = ?', $id); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Retrieves cms page identifier from DB by passed id. - * - * @param string $id - * @return string|false - */ - public function getCmsPageIdentifierById($id) - { - $select = $this->_getReadAdapter()->select(); - /* @var $select Zend_Db_Select */ - $select->from(array('main_table' => $this->getMainTable()), 'identifier') - ->where('main_table.page_id = ?', $id); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Get store ids to which specified item is assigned - * - * @param int $id - * @return array - */ - public function lookupStoreIds($id) - { - return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select() - ->from($this->getTable('cms/page_store'), 'store_id') - ->where("{$this->getIdFieldName()} = ?", $id) - ); - } - - /** - * Set store model - * - * @param Mage_Core_Model_Store $store - * @return Mage_Cms_Model_Mysql4_Page - */ - public function setStore($store) - { - $this->_store = $store; - return $this; - } - - /** - * Retrieve store model - * - * @return Mage_Core_Model_Store - */ - public function getStore() - { - return Mage::app()->getStore($this->_store); - } } diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Page/Collection.php b/app/code/core/Mage/Cms/Model/Mysql4/Page/Collection.php index dc9c6c6fcf..62c515d565 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Page/Collection.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Page/Collection.php @@ -20,149 +20,18 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * CMS page collection * - * @category Mage - * @package Mage_Cms + * @category Mage + * @package Mage_Cms * @author Magento Core Team */ - -class Mage_Cms_Model_Mysql4_Page_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Cms_Model_Mysql4_Page_Collection extends Mage_Cms_Model_Resource_Page_Collection { - protected $_previewFlag; - - /** - * Declare base table and mapping of some fields - */ - protected function _construct() - { - $this->_init('cms/page'); - $this->_map['fields']['page_id'] = 'main_table.page_id'; - $this->_map['fields']['store'] = 'store_table.store_id'; - } - - /** - * deprecated after 1.4.0.1, use toOptionIdArray() - * - * @return array - */ - public function toOptionArray() - { - return $this->_toOptionArray('identifier', 'title'); - } - - /** - * Returns pairs identifier - title for unique identifiers - * and pairs identifier|page_id - title for non-unique after first - * - * @return array - */ - public function toOptionIdArray() - { - $res = array(); - $existingIdentifiers = array(); - foreach ($this as $item) { - $identifier = $item->getData('identifier'); - - $data['value'] = $identifier; - $data['label'] = $item->getData('title'); - if (in_array($identifier, $existingIdentifiers)) { - $data['value'] .= '|' . $item->getData('page_id'); - } - else { - $existingIdentifiers[] = $identifier; - } - - $res[] = $data; - } - - return $res; - } - - public function setFirstStoreFlag($flag = false) - { - $this->_previewFlag = $flag; - return $this; - } - - protected function _afterLoad() - { - if ($this->_previewFlag) { - $items = $this->getColumnValues('page_id'); - if (count($items)) { - $select = $this->getConnection()->select() - ->from($this->getTable('cms/page_store')) - ->where($this->getTable('cms/page_store').'.page_id IN (?)', $items); - if ($result = $this->getConnection()->fetchPairs($select)) { - foreach ($this as $item) { - if (!isset($result[$item->getData('page_id')])) { - continue; - } - if ($result[$item->getData('page_id')] == 0) { - $stores = Mage::app()->getStores(false, true); - $storeId = current($stores)->getId(); - $storeCode = key($stores); - } else { - $storeId = $result[$item->getData('page_id')]; - $storeCode = Mage::app()->getStore($storeId)->getCode(); - } - $item->setData('_first_store_id', $storeId); - $item->setData('store_code', $storeCode); - } - } - } - } - - parent::_afterLoad(); - } - - /** - * Add filter by store - * - * @param int|Mage_Core_Model_Store $store - * @return Mage_Cms_Model_Mysql4_Page_Collection - */ - public function addStoreFilter($store, $withAdmin = true) - { - if ($store instanceof Mage_Core_Model_Store) { - $store = array($store->getId()); - } - $this->addFilter('store', array('in' => ($withAdmin ? array(0, $store) : $store)), 'public'); - return $this; - } - - /** - * Join store relation table if there is store filter - */ - protected function _renderFiltersBefore() - { - if ($this->getFilter('store')) { - $this->getSelect()->join( - array('store_table' => $this->getTable('cms/page_store')), - 'main_table.page_id = store_table.page_id', - array() - )->group('main_table.page_id'); - } - return parent::_renderFiltersBefore(); - } - - /** - * Get SQL for get record count. - * Extra group by strip added. - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $countSelect = parent::getSelectCountSql(); - - $countSelect->reset(Zend_Db_Select::GROUP); - - return $countSelect; - } } diff --git a/app/code/core/Mage/Cms/Model/Mysql4/Page/Service.php b/app/code/core/Mage/Cms/Model/Mysql4/Page/Service.php index 0d69f21c72..96c4c933e7 100644 --- a/app/code/core/Mage/Cms/Model/Mysql4/Page/Service.php +++ b/app/code/core/Mage/Cms/Model/Mysql4/Page/Service.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -29,54 +29,7 @@ * * @author Magento Core Team */ -class Mage_Cms_Model_Mysql4_Page_Service extends Mage_Core_Model_Mysql4_Abstract +class Mage_Cms_Model_Mysql4_Page_Service extends Mage_Cms_Model_Resource_Page_Service { - /** - * Init cms page service model - * - */ - protected function _construct() - { - $this->_init('cms/page', 'page_id'); - } - /** - * Unlinks from $fromStoreId store pages that have same identifiers as pages in $byStoreId - * - * Routine is intented to be used before linking pages of some store ($byStoreId) to other store ($fromStoreId) - * to prevent duplication of url keys - * - * Resolved $byLinkTable can be provided when restoring links from some backup table - * - * @param int $fromStoreId - * @param int $byStoreId - * @param string $byLinkTable - * - * @return Mage_Cms_Model_Mysql4_Page_Service - */ - public function unlinkConflicts($fromStoreId, $byStoreId, $byLinkTable = null) - { - $readAdapter = $this->_getReadAdapter(); - - $linkTable = $this->getTable('cms/page_store'); - $mainTable = $this->getMainTable(); - $byLinkTable = $byLinkTable ? $byLinkTable : $linkTable; - - // Select all page ids of $fromStoreId that have identifiers as some pages in $byStoreId - $select = $readAdapter->select() - ->from(array('from_link' => $linkTable), 'page_id') - ->join(array('from_entity' => $mainTable), $readAdapter->quoteInto('from_entity.page_id = from_link.page_id AND from_link.store_id = ?', $fromStoreId), array()) - ->join(array('by_entity' => $mainTable), 'from_entity.identifier = by_entity.identifier AND from_entity.page_id != by_entity.page_id', array()) - ->join(array('by_link' => $byLinkTable), $readAdapter->quoteInto('by_link.page_id = by_entity.page_id AND by_link.store_id = ?', $byStoreId), array()); - $pageIds = $readAdapter->fetchCol($select); - - // Unlink found pages - if ($pageIds) { - $writeAdapter = $this->_getWriteAdapter(); - $where = $writeAdapter->quoteInto('page_id IN (?)', $pageIds); - $where .= $writeAdapter->quoteInto('AND store_id = ?', $fromStoreId); - $writeAdapter->delete($linkTable, $where); - } - return $this; - } } diff --git a/app/code/core/Mage/Cms/Model/Observer.php b/app/code/core/Mage/Cms/Model/Observer.php index 482802b923..a4e0bcc896 100644 --- a/app/code/core/Mage/Cms/Model/Observer.php +++ b/app/code/core/Mage/Cms/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Model/Page.php b/app/code/core/Mage/Cms/Model/Page.php index 5889ed425b..9b22ff88bf 100644 --- a/app/code/core/Mage/Cms/Model/Page.php +++ b/app/code/core/Mage/Cms/Model/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,43 @@ /** * Cms Page Model * + * @method Mage_Cms_Model_Resource_Page _getResource() + * @method Mage_Cms_Model_Resource_Page getResource() + * @method string getTitle() + * @method Mage_Cms_Model_Page setTitle(string $value) + * @method string getRootTemplate() + * @method Mage_Cms_Model_Page setRootTemplate(string $value) + * @method string getMetaKeywords() + * @method Mage_Cms_Model_Page setMetaKeywords(string $value) + * @method string getMetaDescription() + * @method Mage_Cms_Model_Page setMetaDescription(string $value) + * @method string getIdentifier() + * @method Mage_Cms_Model_Page setIdentifier(string $value) + * @method string getContentHeading() + * @method Mage_Cms_Model_Page setContentHeading(string $value) + * @method string getContent() + * @method Mage_Cms_Model_Page setContent(string $value) + * @method string getCreationTime() + * @method Mage_Cms_Model_Page setCreationTime(string $value) + * @method string getUpdateTime() + * @method Mage_Cms_Model_Page setUpdateTime(string $value) + * @method int getIsActive() + * @method Mage_Cms_Model_Page setIsActive(int $value) + * @method int getSortOrder() + * @method Mage_Cms_Model_Page setSortOrder(int $value) + * @method string getLayoutUpdateXml() + * @method Mage_Cms_Model_Page setLayoutUpdateXml(string $value) + * @method string getCustomTheme() + * @method Mage_Cms_Model_Page setCustomTheme(string $value) + * @method string getCustomRootTemplate() + * @method Mage_Cms_Model_Page setCustomRootTemplate(string $value) + * @method string getCustomLayoutUpdateXml() + * @method Mage_Cms_Model_Page setCustomLayoutUpdateXml(string $value) + * @method string getCustomThemeFrom() + * @method Mage_Cms_Model_Page setCustomThemeFrom(string $value) + * @method string getCustomThemeTo() + * @method Mage_Cms_Model_Page setCustomThemeTo(string $value) + * * @category Mage * @package Mage_Cms * @author Magento Core Team diff --git a/app/code/core/Mage/Cms/Model/Resource/Block.php b/app/code/core/Mage/Cms/Model/Resource/Block.php new file mode 100755 index 0000000000..8bcbccbaa1 --- /dev/null +++ b/app/code/core/Mage/Cms/Model/Resource/Block.php @@ -0,0 +1,241 @@ + + */ +class Mage_Cms_Model_Resource_Block extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('cms/block', 'block_id'); + } + + /** + * Process block data before deleting + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Page + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $object) + { + $condition = array( + 'block_id = ?' => (int) $object->getId(), + ); + + $this->_getWriteAdapter()->delete($this->getTable('cms/block_store'), $condition); + + return parent::_beforeDelete($object); + } + + /** + * Perform operations before object save + * + * @param Mage_Cms_Model_Block $object + * @return Mage_Cms_Model_Resource_Block + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$this->getIsUniqueBlockToStores($object)) { + Mage::throwException(Mage::helper('cms')->__('A block identifier with the same properties already exists in the selected store.')); + } + + if (! $object->getId()) { + $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate()); + } + $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate()); + return $this; + } + + /** + * Perform operations after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Block + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $oldStores = $this->lookupStoreIds($object->getId()); + $newStores = (array)$object->getStores(); + + $table = $this->getTable('cms/block_store'); + $insert = array_diff($newStores, $oldStores); + $delete = array_diff($oldStores, $newStores); + + if ($delete) { + $where = array( + 'block_id = ?' => (int) $object->getId(), + 'store_id IN (?)' => $delete + ); + + $this->_getWriteAdapter()->delete($table, $where); + } + + if ($insert) { + $data = array(); + + foreach ($insert as $storeId) { + $data[] = array( + 'block_id' => (int) $object->getId(), + 'store_id' => (int) $storeId + ); + } + + $this->_getWriteAdapter()->insertMultiple($table, $data); + } + + return parent::_afterSave($object); + + } + + /** + * Load an object using 'identifier' field if there's no field specified and value is not numeric + * + * @param Mage_Core_Model_Abstract $object + * @param mixed $value + * @param string $field + * @return Mage_Cms_Model_Resource_Block + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (!is_numeric($value) && is_null($field)) { + $field = 'identifier'; + } + + return parent::load($object, $value, $field); + } + + /** + * Perform operations after object load + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Block + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + if ($object->getId()) { + $stores = $this->lookupStoreIds($object->getId()); + $object->setData('store_id', $stores); + } + + return parent::_afterLoad($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Cms_Model_Block $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + + if ($object->getStoreId()) { + $stores = array( + (int) $object->getStoreId(), + Mage_Core_Model_App::ADMIN_STORE_ID, + ); + + $select->join( + array('cbs' => $this->getTable('cms/block_store')), + $this->getMainTable().'.block_id = cbs.block_id', + array('store_id') + )->where('is_active = ?', 1) + ->where('cbs.store_id in (?) ', $stores) + ->order('store_id DESC') + ->limit(1); + } + + return $select; + } + + /** + * Check for unique of identifier of block to selected store(s). + * + * @param Mage_Core_Model_Abstract $object + * @return bool + */ + public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object) + { + if (Mage::app()->isSingleStoreMode()) { + $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); + } else { + $stores = (array)$object->getData('stores'); + } + + $select = $this->_getReadAdapter()->select() + ->from(array('cb' => $this->getMainTable())) + ->join( + array('cbs' => $this->getTable('cms/block_store')), + 'cb.block_id = cbs.block_id', + array() + )->where('cb.identifier = ?', $object->getData('identifier')) + ->where('cbs.store_id IN (?)', $stores); + + if ($object->getId()) { + $select->where('cb.block_id <> ?', $object->getId()); + } + + if ($this->_getReadAdapter()->fetchRow($select)) { + return false; + } + + return true; + } + + /** + * Get store ids to which specified item is assigned + * + * @param int $id + * @return array + */ + public function lookupStoreIds($id) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getTable('cms/block_store'), 'store_id') + ->where('block_id = :block_id'); + + $binds = array( + ':block_id' => (int) $id + ); + + return $adapter->fetchCol($select, $binds); + } +} diff --git a/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php b/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php new file mode 100755 index 0000000000..935003eeb6 --- /dev/null +++ b/app/code/core/Mage/Cms/Model/Resource/Block/Collection.php @@ -0,0 +1,118 @@ + + */ +class Mage_Cms_Model_Resource_Block_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('cms/block'); + $this->_map['fields']['store'] = 'store_table.store_id'; + } + + /** + * Returns pairs block_id - title + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('block_id', 'title'); + } + + /** + * Add filter by store + * + * @param int|Mage_Core_Model_Store $store + * @param bool $withAdmin + * @return Mage_Cms_Model_Resource_Block_Collection + */ + public function addStoreFilter($store, $withAdmin = true) + { + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } + + if (!is_array($store)) { + $store = array($store); + } + + if ($withAdmin) { + $store[] = Mage_Core_Model_App::ADMIN_STORE_ID; + } + + $this->addFilter('store', array('in' => $store), 'public'); + + return $this; + } + + /** + * Get SQL for get record count. + * Extra GROUP BY strip added. + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + + $countSelect->reset(Zend_Db_Select::GROUP); + + return $countSelect; + } + + /** + * Join store relation table if there is store filter + */ + protected function _renderFiltersBefore() + { + if ($this->getFilter('store')) { + $this->getSelect()->join( + array('store_table' => $this->getTable('cms/block_store')), + 'main_table.block_id = store_table.block_id', + array() + )->group('main_table.block_id'); + + /* + * Allow analytic functions usage because of one field grouping + */ + $this->_useAnalyticFunction = true; + } + return parent::_renderFiltersBefore(); + } + +} diff --git a/app/code/core/Mage/Cms/Model/Resource/Page.php b/app/code/core/Mage/Cms/Model/Resource/Page.php new file mode 100755 index 0000000000..0018892e02 --- /dev/null +++ b/app/code/core/Mage/Cms/Model/Resource/Page.php @@ -0,0 +1,416 @@ + + */ +class Mage_Cms_Model_Resource_Page extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Store model + * + * @var null|Mage_Core_Model_Store + */ + protected $_store = null; + + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('cms/page', 'page_id'); + } + + /** + * Process page data before deleting + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Page + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $object) + { + $condition = array( + 'page_id = ?' => (int) $object->getId(), + ); + + $this->_getWriteAdapter()->delete($this->getTable('cms/page_store'), $condition); + + return parent::_beforeDelete($object); + } + + /** + * Process page data before saving + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Page + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + /* + * For two attributes which represent timestamp data in DB + * we should make converting such as: + * If they are empty we need to convert them into DB + * type NULL so in DB they will be empty and not some default value + */ + foreach (array('custom_theme_from', 'custom_theme_to') as $field) { + $value = !$object->getData($field) ? null : $object->getData($field); + $object->setData($field, $this->formatDate($value)); + } + + if (!$this->getIsUniquePageToStores($object)) { + Mage::throwException(Mage::helper('cms')->__('A page URL key for specified store already exists.')); + } + + if (!$this->isValidPageIdentifier($object)) { + Mage::throwException(Mage::helper('cms')->__('The page URL key contains capital letters or disallowed symbols.')); + } + + if ($this->isNumericPageIdentifier($object)) { + Mage::throwException(Mage::helper('cms')->__('The page URL key cannot consist only of numbers.')); + } + + // modify create / update dates + if ($object->isObjectNew() && !$object->hasCreationTime()) { + $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate()); + } + + $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate()); + + return parent::_beforeSave($object); + } + + /** + * Assign page to store views + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Page + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $oldStores = $this->lookupStoreIds($object->getId()); + $newStores = (array)$object->getStores(); + if (empty($newStores)) { + $newStores = (array)$object->getStoreId(); + } + $table = $this->getTable('cms/page_store'); + $insert = array_diff($newStores, $oldStores); + $delete = array_diff($oldStores, $newStores); + + if ($delete) { + $where = array( + 'page_id = ?' => (int) $object->getId(), + 'store_id IN (?)' => $delete + ); + + $this->_getWriteAdapter()->delete($table, $where); + } + + if ($insert) { + $data = array(); + + foreach ($insert as $storeId) { + $data[] = array( + 'page_id' => (int) $object->getId(), + 'store_id' => (int) $storeId + ); + } + + $this->_getWriteAdapter()->insertMultiple($table, $data); + } + + return parent::_afterSave($object); + } + + /** + * Load an object using 'identifier' field if there's no field specified and value is not numeric + * + * @param Mage_Core_Model_Abstract $object + * @param mixed $value + * @param string $field + * @return Mage_Cms_Model_Resource_Page + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (!is_numeric($value) && is_null($field)) { + $field = 'identifier'; + } + + return parent::load($object, $value, $field); + } + + /** + * Perform operations after object load + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Cms_Model_Resource_Page + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + if ($object->getId()) { + $stores = $this->lookupStoreIds($object->getId()); + + $object->setData('store_id', $stores); + + } + + return parent::_afterLoad($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Cms_Model_Page $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + + if ($object->getStoreId()) { + $storeIds = array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId()); + $select->join( + array('cms_page_store' => $this->getTable('cms/page_store')), + $this->getMainTable() . '.page_id = cms_page_store.page_id', + array()) + ->where('is_active = ?', 1) + ->where('cms_page_store.store_id IN (?)', $storeIds) + ->order('cms_page_store.store_id DESC') + ->limit(1); + } + + return $select; + } + + /** + * Retrieve load select with filter by identifier, store and activity + * + * @param string $identifier + * @param int|array $store + * @param int $isActive + * @return Varien_Db_Select + */ + protected function _getLoadByIdentifierSelect($identifier, $store, $isActive = null) + { + $select = $this->_getReadAdapter()->select() + ->from(array('cp' => $this->getMainTable())) + ->join( + array('cps' => $this->getTable('cms/page_store')), + 'cp.page_id = cps.page_id', + array()) + ->where('cp.identifier = ?', $identifier) + ->where('cps.store_id IN (?)', $store); + + if (!is_null($isActive)) { + $select->where('cp.is_active = ?', $isActive); + } + + return $select; + } + + /** + * Check for unique of identifier of page to selected store(s). + * + * @param Mage_Core_Model_Abstract $object + * @return bool + */ + public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object) + { + if (Mage::app()->isSingleStoreMode() || !$object->hasStores()) { + $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); + } else { + $stores = (array)$object->getData('stores'); + } + + $select = $this->_getLoadByIdentifierSelect($object->getData('identifier'), $stores); + + if ($object->getId()) { + $select->where('cps.page_id <> ?', $object->getId()); + } + + if ($this->_getWriteAdapter()->fetchRow($select)) { + return false; + } + + return true; + } + + /** + * Check whether page identifier is numeric + * + * @date Wed Mar 26 18:12:28 EET 2008 + * + * @param Mage_Core_Model_Abstract $object + * @return bool + */ + protected function isNumericPageIdentifier(Mage_Core_Model_Abstract $object) + { + return preg_match('/^[0-9]+$/', $object->getData('identifier')); + } + + /** + * Check whether page identifier is valid + * + * @param Mage_Core_Model_Abstract $object + * @return bool + */ + protected function isValidPageIdentifier(Mage_Core_Model_Abstract $object) + { + return preg_match('/^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/', $object->getData('identifier')); + } + + + + /** + * Check if page identifier exist for specific store + * return page id if page exists + * + * @param string $identifier + * @param int $storeId + * @return int + */ + public function checkIdentifier($identifier, $storeId) + { + $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID, $storeId); + $select = $this->_getLoadByIdentifierSelect($identifier, $stores, 1); + $select->reset(Zend_Db_Select::COLUMNS) + ->columns('cp.page_id') + ->order('cps.store_id DESC') + ->limit(1); + + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Retrieves cms page title from DB by passed identifier. + * + * @param string $identifier + * @return string|false + */ + public function getCmsPageTitleByIdentifier($identifier) + { + $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID); + if ($this->_store) { + $stores[] = (int)$this->getStore()->getId(); + } + + $select = $this->_getLoadByIdentifierSelect($identifier, $stores); + $select->reset(Zend_Db_Select::COLUMNS) + ->columns('cp.title') + ->order('cps.store_id DESC') + ->limit(1); + + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Retrieves cms page title from DB by passed id. + * + * @param string $id + * @return string|false + */ + public function getCmsPageTitleById($id) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getMainTable(), 'title') + ->where('page_id = :page_id'); + + $binds = array( + 'page_id' => (int) $id + ); + + return $adapter->fetchOne($select, $binds); + } + + /** + * Retrieves cms page identifier from DB by passed id. + * + * @param string $id + * @return string|false + */ + public function getCmsPageIdentifierById($id) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getMainTable(), 'identifier') + ->where('page_id = :page_id'); + + $binds = array( + 'page_id' => (int) $id + ); + + return $adapter->fetchOne($select, $binds); + } + + /** + * Get store ids to which specified item is assigned + * + * @param int $id + * @return array + */ + public function lookupStoreIds($pageId) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getTable('cms/page_store'), 'store_id') + ->where('page_id = ?',(int)$pageId); + + return $adapter->fetchCol($select); + } + + /** + * Set store model + * + * @param Mage_Core_Model_Store $store + * @return Mage_Cms_Model_Resource_Page + */ + public function setStore($store) + { + $this->_store = $store; + return $this; + } + + /** + * Retrieve store model + * + * @return Mage_Core_Model_Store + */ + public function getStore() + { + return Mage::app()->getStore($this->_store); + } +} diff --git a/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php b/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php new file mode 100755 index 0000000000..df91c980d8 --- /dev/null +++ b/app/code/core/Mage/Cms/Model/Resource/Page/Collection.php @@ -0,0 +1,206 @@ + + */ +class Mage_Cms_Model_Resource_Page_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Load data for preview flag + * + * @var bool + */ + protected $_previewFlag; + + + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('cms/page'); + $this->_map['fields']['page_id'] = 'main_table.page_id'; + $this->_map['fields']['store'] = 'store_table.store_id'; + } + + /** + * deprecated after 1.4.0.1, use toOptionIdArray() + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('identifier', 'title'); + } + + /** + * Returns pairs identifier - title for unique identifiers + * and pairs identifier|page_id - title for non-unique after first + * + * @return array + */ + public function toOptionIdArray() + { + $res = array(); + $existingIdentifiers = array(); + foreach ($this as $item) { + $identifier = $item->getData('identifier'); + + $data['value'] = $identifier; + $data['label'] = $item->getData('title'); + + if (in_array($identifier, $existingIdentifiers)) { + $data['value'] .= '|' . $item->getData('page_id'); + } else { + $existingIdentifiers[] = $identifier; + } + + $res[] = $data; + } + + return $res; + } + + /** + * Set first store flag + * + * @param bool $flag + * @return Mage_Cms_Model_Resource_Page_Collection + */ + public function setFirstStoreFlag($flag = false) + { + $this->_previewFlag = $flag; + return $this; + } + + /** + * Perform operations after collection load + * + * @return Mage_Cms_Model_Resource_Page_Collection + */ + protected function _afterLoad() + { + if ($this->_previewFlag) { + $items = $this->getColumnValues('page_id'); + $connection = $this->getConnection(); + if (count($items)) { + $select = $connection->select() + ->from(array('cps'=>$this->getTable('cms/page_store'))) + ->where('cps.page_id IN (?)', $items); + + if ($result = $connection->fetchPairs($select)) { + foreach ($this as $item) { + if (!isset($result[$item->getData('page_id')])) { + continue; + } + if ($result[$item->getData('page_id')] == 0) { + $stores = Mage::app()->getStores(false, true); + $storeId = current($stores)->getId(); + $storeCode = key($stores); + } else { + $storeId = $result[$item->getData('page_id')]; + $storeCode = Mage::app()->getStore($storeId)->getCode(); + } + $item->setData('_first_store_id', $storeId); + $item->setData('store_code', $storeCode); + } + } + } + } + + return parent::_afterLoad(); + } + + /** + * Add filter by store + * + * @param int|Mage_Core_Model_Store $store + * @param bool $withAdmin + * @return Mage_Cms_Model_Resource_Page_Collection + */ + public function addStoreFilter($store, $withAdmin = true) + { + if (!$this->getFlag('store_filter_added')) { + if ($store instanceof Mage_Core_Model_Store) { + $store = array($store->getId()); + } + + if (!is_array($store)) { + $store = array($store); + } + + if ($withAdmin) { + $store[] = Mage_Core_Model_App::ADMIN_STORE_ID; + } + + $this->addFilter('store', array('in' => $store), 'public'); + } + return $this; + } + + /** + * Join store relation table if there is store filter + */ + protected function _renderFiltersBefore() + { + if ($this->getFilter('store')) { + $this->getSelect()->join( + array('store_table' => $this->getTable('cms/page_store')), + 'main_table.page_id = store_table.page_id', + array() + )->group('main_table.page_id'); + + /* + * Allow analytic functions usage because of one field grouping + */ + $this->_useAnalyticFunction = true; + } + return parent::_renderFiltersBefore(); + } + + + /** + * Get SQL for get record count. + * Extra GROUP BY strip added. + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + + $countSelect->reset(Zend_Db_Select::GROUP); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Cms/Model/Resource/Page/Service.php b/app/code/core/Mage/Cms/Model/Resource/Page/Service.php new file mode 100644 index 0000000000..c98bc9fe3b --- /dev/null +++ b/app/code/core/Mage/Cms/Model/Resource/Page/Service.php @@ -0,0 +1,97 @@ + + */ +class Mage_Cms_Model_Resource_Page_Service extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init cms page service model + * + */ + protected function _construct() + { + $this->_init('cms/page', 'page_id'); + } + + /** + * Unlinks from $fromStoreId store pages that have same identifiers as pages in $byStoreId + * + * Routine is intented to be used before linking pages of some store ($byStoreId) to other store ($fromStoreId) + * to prevent duplication of url keys + * + * Resolved $byLinkTable can be provided when restoring links from some backup table + * + * @param int $fromStoreId + * @param int $byStoreId + * @param string $byLinkTable + * + * @return Mage_Cms_Model_Mysql4_Page_Service + */ + public function unlinkConflicts($fromStoreId, $byStoreId, $byLinkTable = null) + { + $readAdapter = $this->_getReadAdapter(); + + $linkTable = $this->getTable('cms/page_store'); + $mainTable = $this->getMainTable(); + $byLinkTable = $byLinkTable ? $byLinkTable : $linkTable; + + // Select all page ids of $fromStoreId that have identifiers as some pages in $byStoreId + $select = $readAdapter->select() + ->from(array('from_link' => $linkTable), 'page_id') + ->join( + array('from_entity' => $mainTable), + $readAdapter->quoteInto( + 'from_entity.page_id = from_link.page_id AND from_link.store_id = ?', + $fromStoreId + ), + array() + )->join( + array('by_entity' => $mainTable), + 'from_entity.identifier = by_entity.identifier AND from_entity.page_id != by_entity.page_id', + array() + )->join( + array('by_link' => $byLinkTable), + $readAdapter->quoteInto('by_link.page_id = by_entity.page_id AND by_link.store_id = ?', $byStoreId), + array() + ); + $pageIds = $readAdapter->fetchCol($select); + + // Unlink found pages + if ($pageIds) { + $writeAdapter = $this->_getWriteAdapter(); + $where = array( + 'page_id IN (?)' => $pageIds, + 'AND store_id = ?' => $fromStoreId + ); + $writeAdapter->delete($linkTable, $where); + } + return $this; + } +} diff --git a/app/code/core/Mage/Cms/Model/Template/Filter.php b/app/code/core/Mage/Cms/Model/Template/Filter.php index d6611092c6..fd007a6dde 100644 --- a/app/code/core/Mage/Cms/Model/Template/Filter.php +++ b/app/code/core/Mage/Cms/Model/Template/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php index 9bfd2bd3b5..6ec3c19409 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php index ae46446b6f..4fa1250fde 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage/Collection.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage/Collection.php index d8efa81ca8..55dd63109c 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage/Collection.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/controllers/IndexController.php b/app/code/core/Mage/Cms/controllers/IndexController.php index fbd2ef9ccd..d75678b2f0 100644 --- a/app/code/core/Mage/Cms/controllers/IndexController.php +++ b/app/code/core/Mage/Cms/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/controllers/PageController.php b/app/code/core/Mage/Cms/controllers/PageController.php index 4419a373d2..06a2a71d8a 100644 --- a/app/code/core/Mage/Cms/controllers/PageController.php +++ b/app/code/core/Mage/Cms/controllers/PageController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/data/cms_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Cms/data/cms_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..64e62ae649 --- /dev/null +++ b/app/code/core/Mage/Cms/data/cms_setup/data-install-1.6.0.0.php @@ -0,0 +1,99 @@ + 'Footer Links', + 'identifier' => 'footer_links', + 'content' => "", + 'is_active' => 1, + 'stores' => 0 + ) +); + +$cmsPages = array( + array( + 'title' => '404 Not Found 1', + 'root_template' => 'two_columns_right', + 'meta_keywords' => 'Page keywords', + 'meta_description' + => 'Page description', + 'identifier' => 'no-route', + 'content' => "

Whoops, our bad...

\r\n
\r\n
The page you requested was not found, and we have a fine guess why.
\r\n
\r\n
    \r\n
  • If you typed the URL directly, please make sure the spelling is correct.
  • \r\n
  • If you clicked on a link to get here, the link is outdated.
  • \r\n
\r\n
\r\n
\r\n
What can you do?
\r\n
Have no fear, help is near! There are many ways you can get back on track with Magento Store.
\r\n
\r\n
    \r\n
  • Go back to the previous page.
  • \r\n
  • Use the search bar at the top of the page to search for your products.
  • \r\n
  • Follow these links to get you back on track!
    Store Home | My Account
\r\n", + 'is_active' => 1, + 'stores' => array(0), + 'sort_order' => 0 + ), + array( + 'title' => 'Home page', + 'root_template' => 'two_columns_right', + 'identifier' => 'home', + 'content' => "

Home Page

\r\n", + 'is_active' => 1, + 'stores' => array(0), + 'sort_order' => 0 + ), + array( + 'title' => 'About Us', + 'root_template' => 'two_columns_right', + 'identifier' => 'about-magento-demo-store', + 'content' => "
\r\n

About Magento Store

\r\n
\r\n
\r\n

\"Varien\"

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede.

\r\n

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta.

\r\n
\r\n

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit.

\r\n

Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.

\r\n

Maecenas ullamcorper, odio vel tempus egestas, dui orci faucibus orci, sit amet aliquet lectus dolor et quam. Pellentesque consequat luctus purus. Nunc et risus. Etiam a nibh. Phasellus dignissim metus eget nisi. Vestibulum sapien dolor, aliquet nec, porta ac, malesuada a, libero. Praesent feugiat purus eget est. Nulla facilisi. Vestibulum tincidunt sapien eu velit. Mauris purus. Maecenas eget mauris eu orci accumsan feugiat. Pellentesque eget velit. Nunc tincidunt.

\r\n
\r\n

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper

\r\n

Maecenas ullamcorper, odio vel tempus egestas, dui orci faucibus orci, sit amet aliquet lectus dolor et quam. Pellentesque consequat luctus purus.

\r\n

Nunc et risus. Etiam a nibh. Phasellus dignissim metus eget nisi.

\r\n
\r\n

To all of you, from all of us at Magento Store - Thank you and Happy eCommerce!

\r\n

John Doe
Some important guy

\r\n
", + 'is_active' => 1, + 'stores' => array(0), + 'sort_order' => 0 + ), + array( + 'title' => 'Customer Service', + 'root_template' => 'three_columns', + 'identifier' => 'customer-service', + 'content' => "
\r\n

Customer Service

\r\n
\r\n\r\n
\r\n
Shipping & Delivery
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Privacy & Security
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Returns & Replacements
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Ordering
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Payment, Pricing & Promotions
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Viewing Orders
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
Updating Account Information
\r\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi luctus. Duis lobortis. Nulla nec velit. Mauris pulvinar erat non massa. Suspendisse tortor turpis, porta nec, tempus vitae, iaculis semper, pede. Cras vel libero id lectus rhoncus porta. Suspendisse convallis felis ac enim. Vivamus tortor nisl, lobortis in, faucibus et, tempus at, dui. Nunc risus. Proin scelerisque augue. Nam ullamcorper. Phasellus id massa. Pellentesque nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc augue. Aenean sed justo non leo vehicula laoreet. Praesent ipsum libero, auctor ac, tempus nec, tempor nec, justo.
\r\n
", + 'is_active' => 1, + 'stores' => array(0), + 'sort_order' => 0 + ), + array( + 'title' => 'Enable Cookies', + 'root_template' => 'one_column', + 'identifier' => 'enable-cookies', + 'content' => "
\r\n
    \r\n
  • \r\n
      \r\n
    • Please enable cookies in your web browser to continue.
    • \r\n
    \r\n
  • \r\n
\r\n
\r\n

What are Cookies?

\r\n
\r\n

Cookies are short pieces of data that are sent to your computer when you visit a website. On later visits, this data is then returned to that website. Cookies allow us to recognize you automatically whenever you visit our site so that we can personalize your experience and provide you with better service. We also use cookies (and similar browser data, such as Flash cookies) for fraud prevention and other purposes. If your web browser is set to refuse cookies from our website, you will not be able to complete a purchase or take advantage of certain features of our website, such as storing items in your Shopping Cart or receiving personalized recommendations. As a result, we strongly encourage you to configure your web browser to accept cookies from our website.

\r\n

Enabling Cookies

\r\n \r\n

Internet Explorer 7.x

\r\n
    \r\n
  1. \r\n

    Start Internet Explorer

    \r\n
  2. \r\n
  3. \r\n

    Under the Tools menu, click Internet Options

    \r\n

    \"\"

    \r\n
  4. \r\n
  5. \r\n

    Click the Privacy tab

    \r\n

    \"\"

    \r\n
  6. \r\n
  7. \r\n

    Click the Advanced button

    \r\n

    \"\"

    \r\n
  8. \r\n
  9. \r\n

    Put a check mark in the box for Override Automatic Cookie Handling, put another check mark in the Always accept session cookies box

    \r\n

    \"\"

    \r\n
  10. \r\n
  11. \r\n

    Click OK

    \r\n

    \"\"

    \r\n
  12. \r\n
  13. \r\n

    Click OK

    \r\n

    \"\"

    \r\n
  14. \r\n
  15. \r\n

    Restart Internet Explore

    \r\n
  16. \r\n
\r\n

Back to Top

\r\n

Internet Explorer 6.x

\r\n
    \r\n
  1. \r\n

    Select Internet Options from the Tools menu

    \r\n

    \"\"

    \r\n
  2. \r\n
  3. \r\n

    Click on the Privacy tab

    \r\n
  4. \r\n
  5. \r\n

    Click the Default button (or manually slide the bar down to Medium) under Settings. Click OK

    \r\n

    \"\"

    \r\n
  6. \r\n
\r\n

Back to Top

\r\n

Mozilla/Firefox

\r\n
    \r\n
  1. \r\n

    Click on the Tools-menu in Mozilla

    \r\n
  2. \r\n
  3. \r\n

    Click on the Options... item in the menu - a new window open

    \r\n
  4. \r\n
  5. \r\n

    Click on the Privacy selection in the left part of the window. (See image below)

    \r\n

    \"\"

    \r\n
  6. \r\n
  7. \r\n

    Expand the Cookies section

    \r\n
  8. \r\n
  9. \r\n

    Check the Enable cookies and Accept cookies normally checkboxes

    \r\n
  10. \r\n
  11. \r\n

    Save changes by clicking Ok.

    \r\n
  12. \r\n
\r\n

Back to Top

\r\n

Opera 7.x

\r\n
    \r\n
  1. \r\n

    Click on the Tools menu in Opera

    \r\n
  2. \r\n
  3. \r\n

    Click on the Preferences... item in the menu - a new window open

    \r\n
  4. \r\n
  5. \r\n

    Click on the Privacy selection near the bottom left of the window. (See image below)

    \r\n

    \"\"

    \r\n
  6. \r\n
  7. \r\n

    The Enable cookies checkbox must be checked, and Accept all cookies should be selected in the "Normal cookies" drop-down

    \r\n
  8. \r\n
  9. \r\n

    Save changes by clicking Ok

    \r\n
  10. \r\n
\r\n

Back to Top

\r\n
\r\n", + 'is_active' => 1, + 'stores' => array(0) + ) +); + +/** + * Insert default blocks + */ +foreach ($cmsBlocks as $data) { + Mage::getModel('cms/block')->setData($data)->save(); +} + +/** + * Insert default and system pages + */ +foreach ($cmsPages as $data) { + Mage::getModel('cms/page')->setData($data)->save(); +} diff --git a/app/code/core/Mage/Cms/etc/adminhtml.xml b/app/code/core/Mage/Cms/etc/adminhtml.xml index c49e73337a..69ab09b9ef 100644 --- a/app/code/core/Mage/Cms/etc/adminhtml.xml +++ b/app/code/core/Mage/Cms/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Cms/etc/config.xml b/app/code/core/Mage/Cms/etc/config.xml index 6575e54c2b..6e39c5b5a7 100644 --- a/app/code/core/Mage/Cms/etc/config.xml +++ b/app/code/core/Mage/Cms/etc/config.xml @@ -21,25 +21,25 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.13 + 1.6.0.0 - - standard - - Mage_Cms - cms - - + + standard + + Mage_Cms + cms + + @@ -68,13 +68,13 @@ - - - - cms.xml - - - + + + + cms.xml + + + @@ -105,7 +105,7 @@ js css - + @@ -140,10 +140,11 @@ Mage_Cms_Model - cms_mysql4 + cms_resource - - Mage_Cms_Model_Mysql4 + + Mage_Cms_Model_Resource + cms_mysql4 cms_page
@@ -158,7 +159,7 @@ cms_block_store
-
+
@@ -168,7 +169,9 @@ - Mage_Cms_Block + + Mage_Cms_Block + @@ -189,7 +192,6 @@
- diff --git a/app/code/core/Mage/Cms/etc/system.xml b/app/code/core/Mage/Cms/etc/system.xml index f4a78108d7..3676f291e4 100644 --- a/app/code/core/Mage/Cms/etc/system.xml +++ b/app/code/core/Mage/Cms/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Cms/etc/widget.xml b/app/code/core/Mage/Cms/etc/widget.xml index 4d44f1ceda..052257312f 100644 --- a/app/code/core/Mage/Cms/etc/widget.xml +++ b/app/code/core/Mage/Cms/etc/widget.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php b/app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..3f80bfc8d9 --- /dev/null +++ b/app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php @@ -0,0 +1,178 @@ +startSetup(); + +/** + * Create table 'cms/block' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cms/block')) + ->addColumn('block_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Block ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Block Title') + ->addColumn('identifier', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Block String Identifier') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Block Content') + ->addColumn('creation_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Block Creation Time') + ->addColumn('update_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Block Modification Time') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Is Block Active') + ->setComment('CMS Block Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cms/block_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cms/block_store')) + ->addColumn('block_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'primary' => true, + ), 'Block ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addIndex($installer->getIdxName('cms/block_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('cms/block_store', 'block_id', 'cms/block', 'block_id'), + 'block_id', $installer->getTable('cms/block'), 'block_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('cms/block_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('CMS Block To Store Linkage Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cms/page' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cms/page')) + ->addColumn('page_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Page ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true + ), 'Page Title') + ->addColumn('root_template', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true + ), 'Page Template') + ->addColumn('meta_keywords', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => true, + ), 'Page Meta Keywords') + ->addColumn('meta_description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => true, + ), 'Page Meta Description') + ->addColumn('identifier', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + 'nullable' => false, + 'default' => '', + ), 'Page String Identifier') + ->addColumn('content_heading', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Page Content Heading') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Page Content') + ->addColumn('creation_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Page Creation Time') + ->addColumn('update_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Page Modification Time') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Is Page Active') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Page Sort Order') + ->addColumn('layout_update_xml', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => true, + ), 'Page Layout Update Content') + ->addColumn('custom_theme', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + 'nullable' => true, + ), 'Page Custom Theme') + ->addColumn('custom_root_template', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Page Custom Template') + ->addColumn('custom_layout_update_xml', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => true, + ), 'Page Custom Layout Update Content') + ->addColumn('custom_theme_from', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => true, + ), 'Page Custom Theme Active From Date') + ->addColumn('custom_theme_to', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => true, + ), 'Page Custom Theme Active To Date') + ->addIndex($installer->getIdxName('cms/page', array('identifier')), + array('identifier')) + ->setComment('CMS Page Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'cms/page_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cms/page_store')) + ->addColumn('page_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'primary' => true, + ), 'Page ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store ID') + ->addIndex($installer->getIdxName('cms/page_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('cms/page_store', 'page_id', 'cms/page', 'page_id'), + 'page_id', $installer->getTable('cms/page'), 'page_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('cms/page_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('CMS Page To Store Linkage Table'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-install-0.7.0.php index 7a422be772..db09bcc880 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.0-0.7.1.php index bc162d8e79..534109a608 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.1-0.7.2.php index e2ac89a785..a49fb199a4 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.10-0.7.11.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.10-0.7.11.php index b683dd3ab6..b72bd4c576 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.10-0.7.11.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.10-0.7.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php index 465450dd98..0f09c539a4 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.12-0.7.13.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.12-0.7.13.php index da704e7f08..94407ab8e7 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.12-0.7.13.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.12-0.7.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.2-0.7.3.php index 4eaaa0f78c..ad78ec7157 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.4-0.7.5.php index ae2d5dc67c..62c8efab6d 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.5-0.7.6.php index 1746fc7b9f..0c614fdb16 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php index aca7b8ffdf..644fef0403 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.8-0.7.9.php index 9994d00c64..39957cf46b 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.9-0.7.10.php index 0e0a55ee06..486d6a01b8 100644 --- a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cms - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..ad06b5c2ad --- /dev/null +++ b/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,315 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('cms/block_store'), + 'FK_CMS_BLOCK_STORE_BLOCK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cms/block_store'), + 'FK_CMS_BLOCK_STORE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cms/page_store'), + 'FK_CMS_PAGE_STORE_PAGE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('cms/page_store'), + 'FK_CMS_PAGE_STORE_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('cms/block_store'), + 'FK_CMS_BLOCK_STORE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cms/page'), + 'IDENTIFIER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cms/page_store'), + 'FK_CMS_PAGE_STORE_STORE' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('cms/page') => array( + 'columns' => array( + 'page_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Page ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Page Title' + ), + 'root_template' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Page Template' + ), + 'meta_keywords' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Page Meta Keywords' + ), + 'meta_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Page Meta Description' + ), + 'identifier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'nullable' => false, + 'comment' => 'Page String Identifier' + ), + 'content_heading' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Page Content Heading' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Page Content' + ), + 'creation_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Page Creation Time' + ), + 'update_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Page Modification Time' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Page Active' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Page Sort Order' + ), + 'layout_update_xml' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Page Layout Update Content' + ), + 'custom_theme' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'comment' => 'Page Custom Theme' + ), + 'custom_root_template' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Page Custom Template' + ), + 'custom_layout_update_xml' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Page Custom Layout Update Content' + ), + 'custom_theme_from' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Page Custom Theme Active From Date' + ), + 'custom_theme_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Page Custom Theme Active To Date' + ) + ), + 'comment' => 'CMS Page Table' + ), + $installer->getTable('cms/page_store') => array( + 'columns' => array( + 'page_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Page ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Store ID' + ) + ), + 'comment' => 'CMS Page To Store Linkage Table' + ), + $installer->getTable('cms_block') => array( + 'columns' => array( + 'block_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Block ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Block Title' + ), + 'identifier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Block String Identifier' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Block Content' + ), + 'creation_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Block Creation Time' + ), + 'update_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Block Modification Time' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Block Active' + ) + ), + 'comment' => 'CMS Block Table' + ), + $installer->getTable('cms/block_store') => array( + 'columns' => array( + 'block_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Block ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Store ID' + ) + ), + 'comment' => 'CMS Block To Store Linkage Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('cms/page'), + $installer->getIdxName('cms/page', array('identifier')), + array('identifier') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cms/page_store'), + $installer->getIdxName('cms/page_store', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cms/block_store'), + $installer->getIdxName('cms/block_store', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('cms/block_store', 'block_id', 'cms/block', 'block_id'), + $installer->getTable('cms/block_store'), + 'block_id', + $installer->getTable('cms/block'), + 'block_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cms/block_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('cms/block_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cms/page_store', 'page_id', 'cms/page', 'page_id'), + $installer->getTable('cms/page_store'), + 'page_id', + $installer->getTable('cms/page'), + 'page_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('cms/page_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('cms/page_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Compiler/Block/Process.php b/app/code/core/Mage/Compiler/Block/Process.php index 910cdacd2b..faeb627cc5 100644 --- a/app/code/core/Mage/Compiler/Block/Process.php +++ b/app/code/core/Mage/Compiler/Block/Process.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Compiler/Helper/Data.php b/app/code/core/Mage/Compiler/Helper/Data.php index e924dc1328..0a4fc144b2 100644 --- a/app/code/core/Mage/Compiler/Helper/Data.php +++ b/app/code/core/Mage/Compiler/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Compiler/Model/Process.php b/app/code/core/Mage/Compiler/Model/Process.php index 691cd4d786..115b082a9a 100644 --- a/app/code/core/Mage/Compiler/Model/Process.php +++ b/app/code/core/Mage/Compiler/Model/Process.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Compiler/controllers/Adminhtml/Compiler/ProcessController.php b/app/code/core/Mage/Compiler/controllers/Adminhtml/Compiler/ProcessController.php index 687a279898..4e0668522f 100644 --- a/app/code/core/Mage/Compiler/controllers/Adminhtml/Compiler/ProcessController.php +++ b/app/code/core/Mage/Compiler/controllers/Adminhtml/Compiler/ProcessController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Compiler/controllers/ProcessController.php b/app/code/core/Mage/Compiler/controllers/ProcessController.php index 53412f2d55..c2cb487b92 100644 --- a/app/code/core/Mage/Compiler/controllers/ProcessController.php +++ b/app/code/core/Mage/Compiler/controllers/ProcessController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Compiler/etc/adminhtml.xml b/app/code/core/Mage/Compiler/etc/adminhtml.xml index 3a282a11da..53b41a871a 100644 --- a/app/code/core/Mage/Compiler/etc/adminhtml.xml +++ b/app/code/core/Mage/Compiler/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Compiler/etc/compilation.xml b/app/code/core/Mage/Compiler/etc/compilation.xml index d11906a9ba..c827e32db8 100644 --- a/app/code/core/Mage/Compiler/etc/compilation.xml +++ b/app/code/core/Mage/Compiler/etc/compilation.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -71,8 +71,8 @@ - - + + @@ -85,9 +85,9 @@ - - - + + + @@ -101,7 +101,7 @@ - + @@ -118,7 +118,7 @@ - + @@ -160,16 +160,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -216,9 +216,9 @@ - - - + + + @@ -242,29 +242,33 @@ - - - - - - + + + + + + + + + +
- - + + - - - - + + + + - + @@ -287,16 +291,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -316,8 +320,8 @@ - - + + @@ -329,8 +333,8 @@ - - + + @@ -343,8 +347,8 @@ - - + + @@ -353,18 +357,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + @@ -384,7 +388,7 @@ - + diff --git a/app/code/core/Mage/Compiler/etc/config.xml b/app/code/core/Mage/Compiler/etc/config.xml index 000d95ea88..0f373f960a 100644 --- a/app/code/core/Mage/Compiler/etc/config.xml +++ b/app/code/core/Mage/Compiler/etc/config.xml @@ -21,30 +21,31 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.1.0 + 1.6.0.0 Mage_Compiler_Model - compiler_mysql4 + compiler_resource - - Mage_Compiler_Model_Mysql4 + + Mage_Compiler_Model_Resource + compiler_mysql4 compiler_configuration
-
+
diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit.php index 2c445d1b13..76cb1bd0f5 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Form.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Form.php index c5f7ed18cd..0e796385ca 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Form.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Abstract.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Abstract.php index a3173a9150..02c5a84942 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Abstract.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Authors.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Authors.php index b15622421c..295574deac 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Authors.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Authors.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Contents.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Contents.php index a5f7cf4a48..09f17d137e 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Contents.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Contents.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Depends.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Depends.php index a2ef4aacbc..25aaf8a622 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Depends.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Depends.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Grid.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Grid.php index d4738861ff..a04ca442db 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Grid.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Load.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Load.php index d00c522009..3e25084ee1 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Load.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Load.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Local.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Local.php index 4847e46beb..8b55025b8d 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Local.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Local.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php index 0e103ba81b..6dd69dbd94 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Release.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Release.php index 4b0f3c508b..2ca6f32615 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Release.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tab/Release.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tabs.php b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tabs.php index 1929cfdb38..efc8f024af 100644 --- a/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tabs.php +++ b/app/code/core/Mage/Connect/Block/Adminhtml/Extension/Custom/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Helper/Data.php b/app/code/core/Mage/Connect/Helper/Data.php index fa9384c601..b1c87b0a90 100644 --- a/app/code/core/Mage/Connect/Helper/Data.php +++ b/app/code/core/Mage/Connect/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Model/Extension.php b/app/code/core/Mage/Connect/Model/Extension.php index fa403bb1ef..6ffb621e54 100644 --- a/app/code/core/Mage/Connect/Model/Extension.php +++ b/app/code/core/Mage/Connect/Model/Extension.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Model/Extension/Collection.php b/app/code/core/Mage/Connect/Model/Extension/Collection.php index 7b20b8407c..235742cc71 100644 --- a/app/code/core/Mage/Connect/Model/Extension/Collection.php +++ b/app/code/core/Mage/Connect/Model/Extension/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/Model/Session.php b/app/code/core/Mage/Connect/Model/Session.php index 35274485b4..bcad40adf9 100644 --- a/app/code/core/Mage/Connect/Model/Session.php +++ b/app/code/core/Mage/Connect/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php index 22f25d34d8..3c9237cd21 100644 --- a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php +++ b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -85,11 +85,13 @@ public function loadAction() try { $data = Mage::helper('connect')->loadLocalPackage($packageName); if (!$data) { - Mage::throwException(Mage::helper('connect')->__("Failed to load the package data.")); + Mage::throwException(Mage::helper('connect')->__('Failed to load the package data.')); } $data = array_merge($data, array('file_name' => $packageName)); $session->setCustomExtensionPackageFormData($data); - $session->addSuccess(Mage::helper('connect')->__("The package %s data has been loaded.", $packageName)); + $session->addSuccess( + Mage::helper('connect')->__('The package %s data has been loaded.', $packageName) + ); } catch (Exception $e) { $session->addError($e->getMessage()); } @@ -118,7 +120,7 @@ public function saveAction() $session->setCustomExtensionPackageFormData($p); try { $ext = Mage::getModel('connect/extension'); - /* @var $ext Mage_Connect_Model_Extension */ + /** @var $ext Mage_Connect_Model_Extension */ $ext->setData($p); if ($ext->savePackage()) { $session->addSuccess(Mage::helper('connect')->__('The package data has been saved.')); @@ -136,7 +138,7 @@ public function saveAction() $session->addError($e->getMessage()); $this->_redirect('*/*'); } catch (Exception $e){ - $session->addException($e, Mage::helper('connect')->__("Failed to save the package.")); + $session->addException($e, Mage::helper('connect')->__('Failed to save the package.')); $this->_redirect('*/*'); } } @@ -167,7 +169,7 @@ public function createAction() $session->addError($e->getMessage()); $this->_redirect('*/*'); } catch(Exception $e){ - $session->addException($e, Mage::helper('connect')->__("Failed to create the package.")); + $session->addException($e, Mage::helper('connect')->__('Failed to create the package.')); $this->_redirect('*/*'); } } diff --git a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/LocalController.php b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/LocalController.php index e915b61c11..50ae9e8154 100644 --- a/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/LocalController.php +++ b/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/LocalController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Connect/etc/adminhtml.xml b/app/code/core/Mage/Connect/etc/adminhtml.xml index ca801b31f7..682f948889 100644 --- a/app/code/core/Mage/Connect/etc/adminhtml.xml +++ b/app/code/core/Mage/Connect/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Connect/etc/config.xml b/app/code/core/Mage/Connect/etc/config.xml index a9dfa533dd..7f4eb4df5b 100644 --- a/app/code/core/Mage/Connect/etc/config.xml +++ b/app/code/core/Mage/Connect/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0 + 1.6.0.0 diff --git a/app/code/core/Mage/Contacts/Helper/Data.php b/app/code/core/Mage/Contacts/Helper/Data.php index aa5a9b1d1d..a82a16b246 100644 --- a/app/code/core/Mage/Contacts/Helper/Data.php +++ b/app/code/core/Mage/Contacts/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Contacts/Model/System/Config/Backend/Links.php b/app/code/core/Mage/Contacts/Model/System/Config/Backend/Links.php index 5a2029b37c..0cfd7d6885 100644 --- a/app/code/core/Mage/Contacts/Model/System/Config/Backend/Links.php +++ b/app/code/core/Mage/Contacts/Model/System/Config/Backend/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Contacts/controllers/IndexController.php b/app/code/core/Mage/Contacts/controllers/IndexController.php index be65882fff..da8d843eba 100644 --- a/app/code/core/Mage/Contacts/controllers/IndexController.php +++ b/app/code/core/Mage/Contacts/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Contacts/etc/adminhtml.xml b/app/code/core/Mage/Contacts/etc/adminhtml.xml index 69c7472fe4..955faea4cc 100644 --- a/app/code/core/Mage/Contacts/etc/adminhtml.xml +++ b/app/code/core/Mage/Contacts/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Contacts/etc/config.xml b/app/code/core/Mage/Contacts/etc/config.xml index dc22769152..3a50119f91 100644 --- a/app/code/core/Mage/Contacts/etc/config.xml +++ b/app/code/core/Mage/Contacts/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.8.0 + 1.6.0.0 diff --git a/app/code/core/Mage/Contacts/etc/system.xml b/app/code/core/Mage/Contacts/etc/system.xml index 4968449fdf..6141f80624 100644 --- a/app/code/core/Mage/Contacts/etc/system.xml +++ b/app/code/core/Mage/Contacts/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Shipping/Model/Rule/Action/Abstract.php b/app/code/core/Mage/Contacts/sql/contacts_setup/install-1.6.0.0.php similarity index 83% rename from app/code/core/Mage/Shipping/Model/Rule/Action/Abstract.php rename to app/code/core/Mage/Contacts/sql/contacts_setup/install-1.6.0.0.php index 1df82ddf42..2061c93042 100644 --- a/app/code/core/Mage/Shipping/Model/Rule/Action/Abstract.php +++ b/app/code/core/Mage/Contacts/sql/contacts_setup/install-1.6.0.0.php @@ -19,14 +19,13 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Contacts + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -abstract class Mage_Sales_Model_Shipping_Rule_Action_Abstract -{ +/* @var $installer Mage_Core_Model_Resource_Setup */ -} +$installer = $this; diff --git a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.7.1.php b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.7.1.php index 5f3f0a6e15..55a19a37ec 100644 --- a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.7.1.php +++ b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.8.0.php b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.8.0.php index 9fde540812..a205d61317 100644 --- a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.8.0.php +++ b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-install-0.8.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-upgrade-0.7.1-0.7.2.php index 4049843466..8ce115a053 100644 --- a/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Contacts/sql/contacts_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Contacts - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 09e66c8901..99639704d1 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,6 +37,9 @@ */ abstract class Mage_Core_Block_Abstract extends Varien_Object { + /** + * Cache group Tag + */ const CACHE_GROUP = 'block_html'; /** * Block name in layout @@ -60,7 +63,7 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object protected $_parent; /** - * Short alias of this block to be refered from parent + * Short alias of this block that was refered from parent * * @var string */ @@ -78,28 +81,28 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object * * @var array */ - protected $_children = array(); + protected $_children = array(); /** * Sorted children list * * @var array */ - protected $_sortedChildren = array(); + protected $_sortedChildren = array(); /** * Children blocks HTML cache array * * @var array */ - protected $_childrenHtmlCache = array(); + protected $_childrenHtmlCache = array(); /** * Arbitrary groups of child blocks * * @var array */ - protected $_childGroups = array(); + protected $_childGroups = array(); /** * Request object @@ -113,14 +116,14 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object * * @var Mage_Core_Block_Messages */ - protected $_messagesBlock = null; + protected $_messagesBlock = null; /** * Whether this block was not explicitly named * * @var boolean */ - protected $_isAnonymous = false; + protected $_isAnonymous = false; /** * Parent block @@ -141,6 +144,11 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object */ protected $_frameCloseTag; + /** + * Url object + * + * @var Mage_Core_Model_Url + */ protected static $_urlModel; /** @@ -166,6 +174,7 @@ protected function _construct() * Retrieve request object * * @return Mage_Core_Controller_Request_Http + * @throws Exception */ public function getRequest() { @@ -228,7 +237,7 @@ public function setLayout(Mage_Core_Model_Layout $layout) /** * Preparing global layout * - * You can redefine this method in child classes for changin layout + * You can redefine this method in child classes for changing layout * * @return Mage_Core_Block_Abstract */ @@ -256,28 +265,56 @@ public function getIsAnonymous() return $this->_isAnonymous; } + /** + * Set the anonymous flag + * + * @param bool $flag + * @return Mage_Core_Block_Abstract + */ public function setIsAnonymous($flag) { - $this->_isAnonymous = $flag; + $this->_isAnonymous = (bool)$flag; return $this; } + /** + * Returns anonymous block suffix + * + * @return string + */ public function getAnonSuffix() { return $this->_anonSuffix; } + /** + * Set anonymous suffix for current block + * + * @param string $suffix + * @return Mage_Core_Block_Abstract + */ public function setAnonSuffix($suffix) { $this->_anonSuffix = $suffix; return $this; } + /** + * Returns block alias + * + * @return string + */ public function getBlockAlias() { return $this->_alias; } + /** + * Set block alias + * + * @param string $alias + * @return Mage_Core_Block_Abstract + */ public function setBlockAlias($alias) { $this->_alias = $alias; @@ -287,7 +324,7 @@ public function setBlockAlias($alias) /** * Set block's name in layout and unsets previous link if such exists. * - * @param $name + * @param string $name * @return Mage_Core_Block_Abstract */ public function setNameInLayout($name) @@ -314,7 +351,7 @@ public function getSortedChildren() * @param mixed $value * @return Mage_Core_Block_Abstract */ - public function setAttribute($name, $value=null) + public function setAttribute($name, $value = null) { return $this->setData($name, $value); } @@ -338,9 +375,9 @@ public function setChild($alias, $block) if ($block->getIsAnonymous()) { $suffix = $block->getAnonSuffix(); if (empty($suffix)) { - $suffix = 'child'.sizeof($this->_children); + $suffix = 'child' . sizeof($this->_children); } - $blockName = $this->getNameInLayout().'.'.$suffix; + $blockName = $this->getNameInLayout() . '.' . $suffix; if ($this->getLayout()) { $this->getLayout()->unsetBlock($block->getNameInLayout()) @@ -375,7 +412,7 @@ public function unsetChild($alias) if (!empty($this->_sortedChildren)) { $key = array_search($alias, $this->_sortedChildren); - if ($key!==false) { + if ($key !== false) { unset($this->_sortedChildren[$key]); } } @@ -428,7 +465,7 @@ public function unsetCallChild($alias, $callback, $result, $params) */ public function unsetChildren() { - $this->_children = array(); + $this->_children = array(); $this->_sortedChildren = array(); return $this; } @@ -439,9 +476,9 @@ public function unsetChildren() * @param string $name * @return mixed */ - public function getChild($name='') + public function getChild($name = '') { - if (''===$name) { + if ($name === '') { return $this->_children; } elseif (isset($this->_children[$name])) { return $this->_children[$name]; @@ -454,11 +491,12 @@ public function getChild($name='') * * @param string $name * @param boolean $useCache + * @param boolean $sorted * @return string */ - public function getChildHtml($name='', $useCache=true, $sorted=false) + public function getChildHtml($name = '', $useCache = true, $sorted = false) { - if ('' === $name) { + if ($name === '') { if ($sorted) { $children = array(); foreach ($this->getSortedChildren() as $childName) { @@ -477,6 +515,13 @@ public function getChildHtml($name='', $useCache=true, $sorted=false) } } + /** + * @param string $name Parent block name + * @param string $childName OPTIONAL Child block name + * @param bool $useCache OPTIONAL Use cache flag + * @param bool $sorted OPTIONAL @see getChildHtml() + * @return string + */ public function getChildChildHtml($name, $childName = '', $useCache = true, $sorted = false) { if (empty($name)) { @@ -510,7 +555,7 @@ public function getSortedChildBlocks() * @param boolean $useCache * @return string */ - protected function _getChildHtml($name, $useCache=true) + protected function _getChildHtml($name, $useCache = true) { if ($useCache && isset($this->_childrenHtmlCache[$name])) { return $this->_childrenHtmlCache[$name]; @@ -547,7 +592,7 @@ protected function _beforeChildToHtml($name, $child) */ public function getBlockHtml($name) { - if (!($layout = $this->getLayout()) && !($layout = Mage::app()->getFrontController()->getAction()->getLayout())) { + if (!($layout = $this->getLayout()) && !($layout = $this->getAction()->getLayout())) { return ''; } if (!($block = $layout->getBlock($name))) { @@ -565,7 +610,7 @@ public function getBlockHtml($name) * @param string $alias * @return object $this */ - public function insert($block, $siblingName='', $after=false, $alias='') + public function insert($block, $siblingName = '', $after = false, $alias = '') { if (is_string($block)) { $block = $this->getLayout()->getBlock($block); @@ -589,7 +634,7 @@ public function insert($block, $siblingName='', $after=false, $alias='') $this->setChild($name, $block); } - if (''===$siblingName) { + if ($siblingName === '') { if ($after) { array_push($this->_sortedChildren, $name); } else { @@ -597,7 +642,7 @@ public function insert($block, $siblingName='', $after=false, $alias='') } } else { $key = array_search($siblingName, $this->_sortedChildren); - if (false!==$key) { + if (false !== $key) { if ($after) { $key++; } @@ -621,7 +666,7 @@ public function insert($block, $siblingName='', $after=false, $alias='') * @param string $alias * @return Mage_Core_Block_Abstract */ - public function append($block, $alias='') + public function append($block, $alias = '') { $this->insert($block, '', true, $alias); return $this; @@ -722,13 +767,13 @@ protected function _beforeToHtml() * @param $closeTag * @return Mage_Core_Block_Abstract */ - public function setFrameTags($openTag, $closeTag=null) + public function setFrameTags($openTag, $closeTag = null) { $this->_frameOpenTag = $openTag; if ($closeTag) { $this->_frameCloseTag = $closeTag; } else { - $this->_frameCloseTag = '/'.$openTag; + $this->_frameCloseTag = '/' . $openTag; } return $this; } @@ -736,20 +781,20 @@ public function setFrameTags($openTag, $closeTag=null) /** * Produce and return block's html output * - * It is a final method, but you can override _toHmtl() method in descendants if needed + * It is a final method, but you can override _toHtml() method in descendants if needed. * * @return string */ final public function toHtml() { Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this)); - if (Mage::getStoreConfig('advanced/modules_disable_output/'.$this->getModuleName())) { + if (Mage::getStoreConfig('advanced/modules_disable_output/' . $this->getModuleName())) { return ''; } $html = $this->_loadCache(); if ($html === false) { $translate = Mage::getSingleton('core/translate'); - /* @var $translate Mage_Core_Model_Translate */ + /** @var $translate Mage_Core_Model_Translate */ if ($this->hasData('translate_inline')) { $translate->setTranslateInline($this->getData('translate_inline')); } @@ -806,7 +851,7 @@ protected function _toHtml() } /** - * Enter description here... + * Returns url model class name * * @return string */ @@ -816,7 +861,7 @@ protected function _getUrlModelClass() } /** - * Enter description here... + * Create and return url object * * @return Mage_Core_Model_Url */ @@ -832,7 +877,7 @@ protected function _getUrlModel() * @param array $params * @return string */ - public function getUrl($route='', $params=array()) + public function getUrl($route = '', $params = array()) { return $this->_getUrlModel()->getUrl($route, $params); } @@ -844,7 +889,7 @@ public function getUrl($route='', $params=array()) * @param array $params * @return string */ - public function getUrlBase64($route='', $params=array()) + public function getUrlBase64($route = '', $params = array()) { return Mage::helper('core')->urlEncode($this->getUrl($route, $params)); } @@ -868,7 +913,7 @@ public function getUrlEncoded($route = '', $params = array()) * @param array $params * @return string */ - public function getSkinUrl($file=null, array $params=array()) + public function getSkinUrl($file = null, array $params = array()) { return Mage::getDesign()->getSkinUrl($file, $params); } @@ -899,7 +944,7 @@ public function setMessagesBlock(Mage_Core_Block_Messages $block) } /** - * Enter description here... + * Return block helper * * @param string $type * @return Mage_Core_Block_Abstract @@ -907,11 +952,10 @@ public function setMessagesBlock(Mage_Core_Block_Messages $block) public function getHelper($type) { return $this->getLayout()->getBlockSingleton($type); - //return $this->helper($type); } /** - * Enter description here... + * Returns helper object * * @param string $name * @return Mage_Core_Block_Abstract @@ -925,27 +969,27 @@ public function helper($name) } /** - * Retrieve formating date + * Retrieve formatting date * * @param string $date * @param string $format * @param bool $showTime * @return string */ - public function formatDate($date=null, $format='short', $showTime=false) + public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false) { return $this->helper('core')->formatDate($date, $format, $showTime); } /** - * Retrieve formating time + * Retrieve formatting time * * @param string $time * @param string $format * @param bool $showDate * @return string */ - public function formatTime($time=null, $format='short', $showDate=false) + public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showDate = false) { return $this->helper('core')->formatTime($time, $format, $showDate); } @@ -1001,7 +1045,7 @@ public function escapeHtml($data, $allowedTags = null) } /** - * Wrapper for standart strip_tags() function with extra functionality for html entities + * Wrapper for standard strip_tags() function with extra functionality for html entities * * @param string $data * @param string $allowableTags @@ -1088,7 +1132,7 @@ protected function _afterCacheUrl($html) if (Mage::app()->useCache(self::CACHE_GROUP)) { Mage::app()->setUseSessionVar(false); Varien_Profiler::start('CACHE_URL'); - $html = Mage::getSingleton('core/url')->sessionUrlVar($html); + $html = Mage::getSingleton($this->_getUrlModelClass())->sessionUrlVar($html); Varien_Profiler::stop('CACHE_URL'); } return $html; diff --git a/app/code/core/Mage/Core/Block/Flush.php b/app/code/core/Mage/Core/Block/Flush.php index f07505d894..542bda3cf5 100644 --- a/app/code/core/Mage/Core/Block/Flush.php +++ b/app/code/core/Mage/Core/Block/Flush.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Html/Calendar.php b/app/code/core/Mage/Core/Block/Html/Calendar.php index 6c4a8d037c..8f0d6d695d 100644 --- a/app/code/core/Mage/Core/Block/Html/Calendar.php +++ b/app/code/core/Mage/Core/Block/Html/Calendar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Html/Date.php b/app/code/core/Mage/Core/Block/Html/Date.php index 54d2909b79..0cbe48776d 100644 --- a/app/code/core/Mage/Core/Block/Html/Date.php +++ b/app/code/core/Mage/Core/Block/Html/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Html/Link.php b/app/code/core/Mage/Core/Block/Html/Link.php index bf9a25b0c4..d9744f87aa 100644 --- a/app/code/core/Mage/Core/Block/Html/Link.php +++ b/app/code/core/Mage/Core/Block/Html/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Html/Select.php b/app/code/core/Mage/Core/Block/Html/Select.php index d60a0ad0f8..61248dc419 100644 --- a/app/code/core/Mage/Core/Block/Html/Select.php +++ b/app/code/core/Mage/Core/Block/Html/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -107,13 +107,11 @@ protected function _toHtml() $isArrayOption = true; foreach ($this->getOptions() as $key => $option) { - $option['params'] = !empty($option['params']) ? $option['params'] : array(); if ($isArrayOption && is_array($option)) { $value = $option['value']; $label = $option['label']; - $params = $option['params']; - } - else { + $params = (!empty($option['params'])) ? $option['params'] : array(); + } else { $value = $key; $label = $option; $isArrayOption = false; @@ -192,5 +190,4 @@ public function calcOptionHash($optionValue) { return sprintf('%u', crc32($this->getName() . $this->getId() . $optionValue)); } - } diff --git a/app/code/core/Mage/Core/Block/Messages.php b/app/code/core/Mage/Core/Block/Messages.php index a2e7d85956..701aed0cea 100644 --- a/app/code/core/Mage/Core/Block/Messages.php +++ b/app/code/core/Mage/Core/Block/Messages.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Profiler.php b/app/code/core/Mage/Core/Block/Profiler.php index 763f33145a..1238ec8781 100644 --- a/app/code/core/Mage/Core/Block/Profiler.php +++ b/app/code/core/Mage/Core/Block/Profiler.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Store/Switcher.php b/app/code/core/Mage/Core/Block/Store/Switcher.php index 062df91586..1254e18161 100644 --- a/app/code/core/Mage/Core/Block/Store/Switcher.php +++ b/app/code/core/Mage/Core/Block/Store/Switcher.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php index 4167bfcb79..426cdac9ad 100644 --- a/app/code/core/Mage/Core/Block/Template.php +++ b/app/code/core/Mage/Core/Block/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Template/Facade.php b/app/code/core/Mage/Core/Block/Template/Facade.php index 119d7132f5..edb432b211 100644 --- a/app/code/core/Mage/Core/Block/Template/Facade.php +++ b/app/code/core/Mage/Core/Block/Template/Facade.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Template/Smarty.php b/app/code/core/Mage/Core/Block/Template/Smarty.php index 2e68064d89..e79f94abac 100644 --- a/app/code/core/Mage/Core/Block/Template/Smarty.php +++ b/app/code/core/Mage/Core/Block/Template/Smarty.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Template/Zend.php b/app/code/core/Mage/Core/Block/Template/Zend.php index 2a5b62cc28..01caa23d39 100644 --- a/app/code/core/Mage/Core/Block/Template/Zend.php +++ b/app/code/core/Mage/Core/Block/Template/Zend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text.php b/app/code/core/Mage/Core/Block/Text.php index 31542f9500..2d54b827f0 100644 --- a/app/code/core/Mage/Core/Block/Text.php +++ b/app/code/core/Mage/Core/Block/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/List.php b/app/code/core/Mage/Core/Block/Text/List.php index fe30ca2af4..60e33f2d80 100644 --- a/app/code/core/Mage/Core/Block/Text/List.php +++ b/app/code/core/Mage/Core/Block/Text/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/List/Item.php b/app/code/core/Mage/Core/Block/Text/List/Item.php index b10cb52be1..6923b8aee2 100644 --- a/app/code/core/Mage/Core/Block/Text/List/Item.php +++ b/app/code/core/Mage/Core/Block/Text/List/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/List/Link.php b/app/code/core/Mage/Core/Block/Text/List/Link.php index 448558c7c5..e269121883 100644 --- a/app/code/core/Mage/Core/Block/Text/List/Link.php +++ b/app/code/core/Mage/Core/Block/Text/List/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag.php b/app/code/core/Mage/Core/Block/Text/Tag.php index db84f1ec79..ec8708cf10 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag.php +++ b/app/code/core/Mage/Core/Block/Text/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag/Css.php b/app/code/core/Mage/Core/Block/Text/Tag/Css.php index 55057de158..3469836773 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag/Css.php +++ b/app/code/core/Mage/Core/Block/Text/Tag/Css.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag/Css/Admin.php b/app/code/core/Mage/Core/Block/Text/Tag/Css/Admin.php index 05293b197a..bb4bb2b14d 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag/Css/Admin.php +++ b/app/code/core/Mage/Core/Block/Text/Tag/Css/Admin.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag/Debug.php b/app/code/core/Mage/Core/Block/Text/Tag/Debug.php index dc34ad18fa..5fe04cdbdf 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag/Debug.php +++ b/app/code/core/Mage/Core/Block/Text/Tag/Debug.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag/Js.php b/app/code/core/Mage/Core/Block/Text/Tag/Js.php index 79ae8fe215..927f829a55 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag/Js.php +++ b/app/code/core/Mage/Core/Block/Text/Tag/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Block/Text/Tag/Meta.php b/app/code/core/Mage/Core/Block/Text/Tag/Meta.php index 345f9128d0..90b1eb53b1 100644 --- a/app/code/core/Mage/Core/Block/Text/Tag/Meta.php +++ b/app/code/core/Mage/Core/Block/Text/Tag/Meta.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php index 90d182f2cf..6ee57b78e5 100644 --- a/app/code/core/Mage/Core/Controller/Front/Action.php +++ b/app/code/core/Mage/Core/Controller/Front/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Front/Router.php b/app/code/core/Mage/Core/Controller/Front/Router.php index 8c75e2ded4..a47551b1a4 100644 --- a/app/code/core/Mage/Core/Controller/Front/Router.php +++ b/app/code/core/Mage/Core/Controller/Front/Router.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Request/Http.php b/app/code/core/Mage/Core/Controller/Request/Http.php index 2425a13085..0f983c89e8 100644 --- a/app/code/core/Mage/Core/Controller/Request/Http.php +++ b/app/code/core/Mage/Core/Controller/Request/Http.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Response/Http.php b/app/code/core/Mage/Core/Controller/Response/Http.php index e871cf3642..ab2596ebc6 100644 --- a/app/code/core/Mage/Core/Controller/Response/Http.php +++ b/app/code/core/Mage/Core/Controller/Response/Http.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 8333176c7c..14b85de1f9 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Exception.php b/app/code/core/Mage/Core/Controller/Varien/Exception.php index c4de8c0a1b..958e5e7d1b 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Exception.php +++ b/app/code/core/Mage/Core/Controller/Varien/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Front.php b/app/code/core/Mage/Core/Controller/Varien/Front.php index 628f1d966f..1335b67932 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Front.php +++ b/app/code/core/Mage/Core/Controller/Varien/Front.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Abstract.php b/app/code/core/Mage/Core/Controller/Varien/Router/Abstract.php index b5b3e37a33..0a87c469f0 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Abstract.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Admin.php b/app/code/core/Mage/Core/Controller/Varien/Router/Admin.php index 50754eca65..449eff228c 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Admin.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Admin.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Controller/Varien/Router/Default.php b/app/code/core/Mage/Core/Controller/Varien/Router/Default.php index 26a2ee1051..25aa09b8ab 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Default.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 b7a2dcb8d6..9cda877912 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php +++ b/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Exception.php b/app/code/core/Mage/Core/Exception.php index edc593f73d..4d63eb30ed 100644 --- a/app/code/core/Mage/Core/Exception.php +++ b/app/code/core/Mage/Core/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Abstract.php b/app/code/core/Mage/Core/Helper/Abstract.php index 65d645d8f8..06df7894ff 100644 --- a/app/code/core/Mage/Core/Helper/Abstract.php +++ b/app/code/core/Mage/Core/Helper/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 9469909cb5..3a781aa329 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/File/Storage.php b/app/code/core/Mage/Core/Helper/File/Storage.php index 2cd3c10b60..60506d394c 100644 --- a/app/code/core/Mage/Core/Helper/File/Storage.php +++ b/app/code/core/Mage/Core/Helper/File/Storage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/File/Storage/Database.php b/app/code/core/Mage/Core/Helper/File/Storage/Database.php index 49f2c59c7b..1ec17581a5 100644 --- a/app/code/core/Mage/Core/Helper/File/Storage/Database.php +++ b/app/code/core/Mage/Core/Helper/File/Storage/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Http.php b/app/code/core/Mage/Core/Helper/Http.php index cab38c8348..824a81c8fc 100644 --- a/app/code/core/Mage/Core/Helper/Http.php +++ b/app/code/core/Mage/Core/Helper/Http.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Js.php b/app/code/core/Mage/Core/Helper/Js.php index 119f159775..e3e878a4ee 100644 --- a/app/code/core/Mage/Core/Helper/Js.php +++ b/app/code/core/Mage/Core/Helper/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index e3180a2fe3..8d47a31797 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Translate.php b/app/code/core/Mage/Core/Helper/Translate.php index 022d6c733c..9dfa1bd768 100644 --- a/app/code/core/Mage/Core/Helper/Translate.php +++ b/app/code/core/Mage/Core/Helper/Translate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Url.php b/app/code/core/Mage/Core/Helper/Url.php index c0816a6aea..f3151f0b5d 100644 --- a/app/code/core/Mage/Core/Helper/Url.php +++ b/app/code/core/Mage/Core/Helper/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Helper/Url/Rewrite.php b/app/code/core/Mage/Core/Helper/Url/Rewrite.php index 108c6e3b65..aab104c136 100644 --- a/app/code/core/Mage/Core/Helper/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Helper/Url/Rewrite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Abstract.php b/app/code/core/Mage/Core/Model/Abstract.php index 3b567e1970..9799e4e3eb 100644 --- a/app/code/core/Mage/Core/Model/Abstract.php +++ b/app/code/core/Mage/Core/Model/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index 1833dd33c1..35770a9ca2 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/App/Area.php b/app/code/core/Mage/Core/Model/App/Area.php index 2148bb7f9a..3409ab04d7 100644 --- a/app/code/core/Mage/Core/Model/App/Area.php +++ b/app/code/core/Mage/Core/Model/App/Area.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/App/Emulation.php b/app/code/core/Mage/Core/Model/App/Emulation.php index 70ba30f20a..27d68f7e49 100644 --- a/app/code/core/Mage/Core/Model/App/Emulation.php +++ b/app/code/core/Mage/Core/Model/App/Emulation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Cache.php b/app/code/core/Mage/Core/Model/Cache.php index 56775e36d4..71471a394f 100644 --- a/app/code/core/Mage/Core/Model/Cache.php +++ b/app/code/core/Mage/Core/Model/Cache.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index f8c4b60bd1..872a5bdfba 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -197,7 +197,7 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base public function __construct($sourceData=null) { $this->setCacheId('config_global'); - $this->_options = new Mage_Core_Model_Config_Options(); + $this->_options = new Mage_Core_Model_Config_Options($sourceData); $this->_prototype = new Mage_Core_Model_Config_Base(); $this->_cacheChecksum = null; parent::__construct($sourceData); @@ -290,7 +290,7 @@ public function loadBase() */ public function loadModulesCache() { - if (Mage::isInstalled()) { + if (Mage::isInstalled(array('etc_dir' => $this->getOptions()->getEtcDir()))) { if ($this->_canUseCacheForInit()) { Varien_Profiler::start('mage::app::init::config::load_cache'); $loaded = $this->loadCache(); @@ -313,7 +313,9 @@ public function loadModules() { Varien_Profiler::start('config/load-modules'); $this->_loadDeclaredModules(); - $this->loadModulesConfiguration('config.xml', $this); + + $resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core')); + $this->loadModulesConfiguration(array('config.xml',$resourceConfig), $this); /** * Prevent local.xml directives overwriting @@ -488,7 +490,9 @@ protected function _saveSectionCache($idPrefix, $sectionName, $source, $recursio $cacheId = $idPrefix . '_' . $sectionName; if ($recursionLevel > 0) { foreach ($source->$sectionName->children() as $subSectionName => $node) { - $this->_saveSectionCache($cacheId, $subSectionName, $source->$sectionName, $recursionLevel-1, $tags); + $this->_saveSectionCache( + $cacheId, $subSectionName, $source->$sectionName, $recursionLevel-1, $tags + ); } } $this->_cachePartsForSave[$cacheId] = $source->$sectionName->asNiceXml('', false); @@ -642,7 +646,7 @@ public function getNode($path=null, $scope='', $scopeCode=null) } } } - return parent::getNode($path); + return parent::getNode($path); } /** @@ -671,11 +675,9 @@ protected function _getDeclaredModuleFiles() if ($name == 'Mage_All') { $collectModuleFiles['base'][] = $v; - } - elseif (substr($name, 0, 5) == 'Mage_') { + } else if (substr($name, 0, 5) == 'Mage_') { $collectModuleFiles['mage'][] = $v; - } - else { + } else { $collectModuleFiles['custom'][] = $v; } } @@ -801,7 +803,9 @@ protected function _sortModuleDepends($modules) $depends = $moduleProps['depends']; foreach ($moduleProps['depends'] as $depend => $true) { if ($moduleProps['active'] && ((!isset($modules[$depend])) || empty($modules[$depend]['active']))) { - Mage::throwException(Mage::helper('core')->__('Module "%1$s" requires module "%2$s".', $moduleName, $depend)); + Mage::throwException( + Mage::helper('core')->__('Module "%1$s" requires module "%2$s".', $moduleName, $depend) + ); } $depends = array_merge($depends, $modules[$depend]['depends']); } @@ -825,7 +829,9 @@ protected function _sortModuleDepends($modules) foreach ($moduleProp['depends'] as $dependModule => $true) { if (!isset($definedModules[$dependModule])) { Mage::throwException( - Mage::helper('core')->__('Module "%1$s" cannot depend on "%2$s".', $moduleProp['module'], $dependModule) + Mage::helper('core')->__( + 'Module "%1$s" cannot depend on "%2$s".', $moduleProp['module'], $dependModule + ) ); } } @@ -904,9 +910,15 @@ public function loadModulesConfiguration($fileName, $mergeToObject = null, $merg if ($disableLocalModules && ('local' === (string)$module->codePool)) { continue; } - $configFile = $this->getModuleDir('etc', $modName).DS.$fileName; - if ($mergeModel->loadFile($configFile)) { - $mergeToObject->extend($mergeModel, true); + if (!is_array($fileName)) { + $fileName = array($fileName); + } + + foreach ($fileName as $configFile) { + $configFile = $this->getModuleDir('etc', $modName).DS.$configFile; + if ($mergeModel->loadFile($configFile)) { + $mergeToObject->extend($mergeModel, true); + } } } } @@ -938,7 +950,9 @@ public function getDistroServerVars() $hostArr = explode(':', $_SERVER['HTTP_HOST']); $host = $hostArr[0]; - $port = isset($hostArr[1]) && (!$secure && $hostArr[1]!=80 || $secure && $hostArr[1]!=443) ? ':'.$hostArr[1] : ''; + $port = isset( + $hostArr[1]) && (!$secure && $hostArr[1]!=80 || $secure && $hostArr[1]!=443 + ) ? ':'.$hostArr[1] : ''; $path = Mage::app()->getRequest()->getBasePath(); $baseUrl = $scheme.$host.$port.rtrim($path, '/').'/'; @@ -1072,6 +1086,9 @@ public function getModuleDir($type, $moduleName) case 'sql': $dir .= DS.'sql'; break; + case 'data': + $dir .= DS.'data'; + break; case 'locale': $dir .= DS.'locale'; @@ -1093,8 +1110,7 @@ public function loadEventObservers($area) $events = $this->getNode("$area/events"); if ($events) { $events = $events->children(); - } - else { + } else { return false; } @@ -1169,12 +1185,29 @@ public function getGroupedClassName($groupType, $classId, $groupRootNode=null) return $this->_classNameCache[$groupRootNode][$group][$class]; } - //$config = $this->getNode($groupRootNode.'/'.$group); $config = $this->_xml->global->{$groupType.'s'}->{$group}; + // First - check maybe the entity class was rewritten + $className = null; if (isset($config->rewrite->$class)) { $className = (string)$config->rewrite->$class; } else { + /** + * Backwards compatibility for pre-MMDB extensions. + * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So is left + * to keep name of previously used nodes, that still may be used by non-updated extensions. + */ + if ($config->deprecatedNode) { + $deprecatedNode = $config->deprecatedNode; + $configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode; + if (isset($configOld->rewrite->$class)) { + $className = (string) $configOld->rewrite->$class; + } + } + } + + // Second - if entity is not rewritten then use class prefix to form class name + if (empty($className)) { if (!empty($config)) { $className = $config->getClassName(); } @@ -1213,14 +1246,36 @@ public function getBlockClassName($blockType) */ public function getHelperClassName($helperName) { - if (strpos($helperName, '/')===false) { + if (strpos($helperName, '/') === false) { $helperName .= '/data'; } return $this->getGroupedClassName('helper', $helperName); } /** - * Retrieve modele class name + * Retreive resource helper instance + * + * Example: + * $config->getResourceHelper('cms') + * will instantiate Mage_Cms_Model_Resource_Helper_ + * + * @param string $moduleName + * @return Mage_Core_Model_Resource_Helper_Abstract|false + */ + public function getResourceHelper($moduleName) + { + $connectionModel = $this->_getResourceConnectionModel($moduleName); + $helperClass = sprintf('%s/helper_%s', $moduleName, $connectionModel); + $helperClassName = $this->_getResourceModelFactoryClassName($helperClass); + if ($helperClassName) { + return $this->getModelInstance($helperClassName, $moduleName); + } + + return false; + } + + /** + * Retrieve module class name * * @param sting $modelClass * @return string @@ -1255,7 +1310,10 @@ public function getModelInstance($modelClass='', $constructArguments=array()) Varien_Profiler::stop('CORE::create_object_of::'.$className); return $obj; } else { - #throw Mage::exception('Mage_Core', Mage::helper('core')->__('Model class does not exist: %s.', $modelClass)); + /* throw Mage::exception( + 'Mage_Core', + Mage::helper('core')->__('Model class does not exist: %s.', $modelClass) + ); */ return false; } } @@ -1367,8 +1425,7 @@ public function getStoresConfigByPath($path, $allowValues = array(), $useAsKey = if (empty($allowValues)) { $storeValues[$key] = $pathValue; - } - elseif(in_array($pathValue, $allowValues)) { + } else if (in_array($pathValue, $allowValues)) { $storeValues[$key] = $pathValue; } } @@ -1378,8 +1435,8 @@ public function getStoresConfigByPath($path, $allowValues = array(), $useAsKey = /** * Check security requirements for url * - * @param string $url - * @return bool + * @param string $url + * @return bool */ public function shouldUrlBeSecure($url) { @@ -1473,36 +1530,51 @@ public function getFieldset($name, $root = 'global') } /** - * Get factory class name for for a resource + * Retrieve resource connection model name + * + * @param string $moduleName + * @return string + */ + protected function _getResourceConnectionModel($moduleName = null) + { + $config = null; + if (!is_null($moduleName)) { + $setupResource = $moduleName . '_setup'; + $config = $this->getResourceConnectionConfig($setupResource); + } + if (!$config) { + $config = $this->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE); + } + + return (string)$config->model; + } + + /** + * Get factory class name for a resource * * @param string $modelClass * @return string|false */ protected function _getResourceModelFactoryClassName($modelClass) { - $classArr = explode('/', $modelClass); - - $resourceModel = false; - - if (!isset($this->_xml->global->models->{$classArr[0]})) { + $classArray = explode('/', $modelClass); + if (count($classArray) != 2) { return false; } - $module = $this->_xml->global->models->{$classArr[0]}; - - if ((count($classArr)==2) - && isset($module->{$classArr[1]}->resourceModel) - && $resourceInfo = $module->{$classArr[1]}->resourceModel) { - $resourceModel = (string) $resourceInfo; - } - elseif (isset($module->resourceModel) && $resourceInfo = $module->resourceModel) { - $resourceModel = (string) $resourceInfo; + list($module, $model) = $classArray; + if (!isset($this->_xml->global->models->{$module})) { + return false; } - if (!$resourceModel) { + $moduleNode = $this->_xml->global->models->{$module}; + if (!empty($moduleNode->resourceModel)) { + $resourceModel = (string)$moduleNode->resourceModel; + } else { return false; } - return $resourceModel . '/' . $classArr[1]; + + return $resourceModel . '/' . $model; } /** diff --git a/app/code/core/Mage/Core/Model/Config/Base.php b/app/code/core/Mage/Core/Model/Config/Base.php index 77b43dd06d..a7a9c1cd01 100644 --- a/app/code/core/Mage/Core/Model/Config/Base.php +++ b/app/code/core/Mage/Core/Model/Config/Base.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Config/Data.php b/app/code/core/Mage/Core/Model/Config/Data.php index 28273cb3b0..f036ba8852 100644 --- a/app/code/core/Mage/Core/Model/Config/Data.php +++ b/app/code/core/Mage/Core/Model/Config/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,20 @@ /** * Config data model * - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Config_Data _getResource() + * @method Mage_Core_Model_Resource_Config_Data getResource() + * @method string getScope() + * @method Mage_Core_Model_Config_Data setScope(string $value) + * @method int getScopeId() + * @method Mage_Core_Model_Config_Data setScopeId(int $value) + * @method string getPath() + * @method Mage_Core_Model_Config_Data setPath(string $value) + * @method string getValue() + * @method Mage_Core_Model_Config_Data setValue(string $value) + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ class Mage_Core_Model_Config_Data extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Core/Model/Config/Element.php b/app/code/core/Mage/Core/Model/Config/Element.php index 553c67969a..cc94a046fd 100644 --- a/app/code/core/Mage/Core/Model/Config/Element.php +++ b/app/code/core/Mage/Core/Model/Config/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Config/Options.php b/app/code/core/Mage/Core/Model/Config/Options.php index 5687c336bf..0e0ffcb2ad 100644 --- a/app/code/core/Mage/Core/Model/Config/Options.php +++ b/app/code/core/Mage/Core/Model/Config/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -221,9 +221,11 @@ public function createDirIfNotExists($dir) return false; } } else { + $oldUmask = umask(0); if (!@mkdir($dir, 0777, true)) { return false; } + umask($oldUmask); } $this->_dirExists[$dir] = true; return true; diff --git a/app/code/core/Mage/Core/Model/Config/System.php b/app/code/core/Mage/Core/Model/Config/System.php index 9d9a0a723c..de76295e98 100644 --- a/app/code/core/Mage/Core/Model/Config/System.php +++ b/app/code/core/Mage/Core/Model/Config/System.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Convert.php b/app/code/core/Mage/Core/Model/Convert.php index a793b34608..92770f286d 100644 --- a/app/code/core/Mage/Core/Model/Convert.php +++ b/app/code/core/Mage/Core/Model/Convert.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Convert/Profile.php b/app/code/core/Mage/Core/Model/Convert/Profile.php deleted file mode 100644 index 5ea1fe7189..0000000000 --- a/app/code/core/Mage/Core/Model/Convert/Profile.php +++ /dev/null @@ -1,380 +0,0 @@ - - */ -class Mage_Core_Model_Convert_Profile extends Mage_Core_Model_Abstract -{ - protected function _construct() - { - $this->_init('core/convert_profile'); - } - - protected function _afterLoad() - { - if (is_string($this->getGuiData())) { - $guiData = unserialize($this->getGuiData()); - } else { - $guiData = ''; - } - $this->setGuiData($guiData); - - parent::_afterLoad(); - } - - protected function _beforeSave() - { - parent::_beforeSave(); - - if (is_array($this->getGuiData())) { - $this->_parseGuiData(); - $this->setGuiData(serialize($this->getGuiData())); - } - } - - protected function _afterSave() - { - if (is_string($this->getGuiData())) { - $this->setGuiData(unserialize($this->getGuiData())); - } - - Mage::getModel('core/convert_history') - ->setProfileId($this->getId()) - ->setActionCode($this->getOrigData('profile_id') ? 'update' : 'create') - ->save(); - - parent::_afterSave(); - } - - public function run() - { - Mage::getModel('core/convert_history') - ->setProfileId($this->getId()) - ->setActionCode('run') - ->save(); - - $xml = ''.$this->getActionsXml().''; - $profile = Mage::getModel('core/convert')->importXml($xml)->getProfile('default'); - try { - $profile->run(); - } catch (Exception $e) { - - } - $this->setExceptions($profile->getExceptions()); - return $this; - } - - public function _parseGuiData() - { - $nl = "\r\n"; - $import = $this->getDirection()==='import'; - $p = $this->getGuiData(); - - if ($this->getDataTransfer()==='interactive') { -// $p['file']['type'] = 'file'; -// $p['file']['filename'] = $p['interactive']['filename']; -// $p['file']['path'] = 'var/export'; - - $interactiveXml = ''.$nl; - #$interactiveXml .= ' '.$nl; - $interactiveXml .= ''; - - $fileXml = ''; - } else { - $interactiveXml = ''; - - $fileXml = ''.$nl; - $fileXml .= ' '.$p['file']['type'].''.$nl; - $fileXml .= ' '.$p['file']['path'].''.$nl; - $fileXml .= ' '.$nl; - if ($p['file']['type']==='ftp') { - $hostArr = explode(':', $p['file']['host']); - $fileXml .= ' '.$nl; - if (isset($hostArr[1])) { - $fileXml .= ' '.$nl; - } - if (!empty($p['file']['passive'])) { - $fileXml .= ' true'.$nl; - } - if (!empty($p['file']['user'])) { - $fileXml .= ' '.$nl; - } - if (!empty($p['file']['password'])) { - $fileXml .= ' '.$nl; - } - } - $fileXml .= ''.$nl.$nl; - } - - switch ($p['parse']['type']) { - case 'excel_xml': - $parseFileXml = ''.$nl; - $parseFileXml .= ' '.$nl; - break; - - case 'csv': - $parseFileXml = ''.$nl; - $parseFileXml .= ' '.$nl; - $parseFileXml .= ' '.$nl; - break; - } - $parseFileXml .= ' '.$p['parse']['fieldnames'].''.$nl; - $parseFileXml .= ''.$nl.$nl; - - $mapXml = ''; - if (isset($p['map']) && is_array($p['map'])) { - foreach ($p['map'] as $side=>$fields) { - if (!is_array($fields)) { - continue; - } - foreach ($fields['db'] as $i=>$k) { - if ($k=='' || $k=='0') { - unset($p['map'][$side]['db'][$i]); - unset($p['map'][$side]['file'][$i]); - } - } - } - } - $mapXml .= ''.$nl; - $map = $p['map'][$this->getEntityType()]; - if (sizeof($map['db'])>0) { - $from = $map[$import?'file':'db']; - $to = $map[$import?'db':'file']; - foreach ($from as $i=>$f) { - $mapXml .= ' '.$nl; - } - } - if ($p['map']['only_specified']) { - $mapXml .= ' '.$p['map']['only_specified'].''.$nl; - } - $mapXml .= ''.$nl.$nl; - - $parsers = array( - 'product'=>'catalog/convert_parser_product', - 'customer'=>'customer/convert_parser_customer', - ); - - if ($import) { - $parseDataXml = ''.$nl; - $parseDataXml .= ' getStoreId().']]>'.$nl; - $parseDataXml .= ''.$nl.$nl; - } else { - $parseDataXml = ''.$nl; - $parseDataXml .= ' getStoreId().']]>'.$nl; - $parseDataXml .= ''.$nl.$nl; - } - - $adapters = array( - 'product'=>'catalog/convert_adapter_product', - 'customer'=>'customer/convert_adapter_customer', - ); - - if ($import) { - $entityXml = ''.$nl; - $entityXml .= ' getStoreId().']]>'.$nl; - $entityXml .= ''.$nl.$nl; - } else { - $entityXml = ''.$nl; - $entityXml .= ' getStoreId().']]>'.$nl; - foreach ($p[$this->getEntityType()]['filter'] as $f=>$v) { - if (empty($v)) { - continue; - } - if (is_scalar($v)) { - $entityXml .= ' '.$nl; - } elseif (is_array($v)) { - foreach ($v as $a=>$b) { - if (empty($b)) { - continue; - } - $entityXml .= ' '.$nl; - } - } - } - $entityXml .= ''.$nl.$nl; - } - - if ($import) { - $xml = $interactiveXml.$fileXml.$parseFileXml.$mapXml.$parseDataXml.$entityXml; - } else { - $xml = $entityXml.$parseDataXml.$mapXml.$parseFileXml.$fileXml.$interactiveXml; - } - - $this->setGuiData($p); - $this->setActionsXml($xml); -/*echo "
".print_r($p,1)."
"; -echo "".$xml.""; -die;*/ - return $this; - } - - public function _parseGuiDataOrig() - { - $nl = "\r\n"; - $import = $this->getDirection()==='import'; - $p = $this->getGuiData(); - - if ($this->getDataTransfer()==='interactive') { -// $p['file']['type'] = 'file'; -// $p['file']['filename'] = $p['interactive']['filename']; -// $p['file']['path'] = 'var/export'; - - $interactiveXml = ''.$nl; - #$interactiveXml .= ' '.$nl; - $interactiveXml .= ''; - - $fileXml = ''; - } else { - $interactiveXml = ''; - - $fileXml = ''.$nl; - $fileXml .= ' '.$p['file']['type'].''.$nl; - $fileXml .= ' '.$p['file']['path'].''.$nl; - $fileXml .= ' '.$nl; - if ($p['file']['type']==='ftp') { - $hostArr = explode(':', $p['file']['host']); - $fileXml .= ' '.$nl; - if (isset($hostArr[1])) { - $fileXml .= ' '.$nl; - } - if (!empty($p['file']['passive'])) { - $fileXml .= ' true'.$nl; - } - if (!empty($p['file']['user'])) { - $fileXml .= ' '.$nl; - } - if (!empty($p['file']['password'])) { - $fileXml .= ' '.$nl; - } - } - $fileXml .= ''.$nl.$nl; - } - - switch ($p['parse']['type']) { - case 'excel_xml': - $parseFileXml = ''.$nl; - $parseFileXml .= ' '.$nl; - break; - - case 'csv': - $parseFileXml = ''.$nl; - $parseFileXml .= ' '.$nl; - $parseFileXml .= ' '.$nl; - break; - } - $parseFileXml .= ' '.$p['parse']['fieldnames'].''.$nl; - $parseFileXml .= ''.$nl.$nl; - - $mapXml = ''; - if (isset($p['map']) && is_array($p['map'])) { - foreach ($p['map'] as $side=>$fields) { - if (!is_array($fields)) { - continue; - } - foreach ($fields['db'] as $i=>$k) { - if ($k=='' || $k=='0') { - unset($p['map'][$side]['db'][$i]); - unset($p['map'][$side]['file'][$i]); - } - } - } - } - $mapXml .= ''.$nl; - $map = $p['map'][$this->getEntityType()]; - if (sizeof($map['db'])>0) { - $from = $map[$import?'file':'db']; - $to = $map[$import?'db':'file']; - foreach ($from as $i=>$f) { - $mapXml .= ' '.$nl; - } - } - if ($p['map']['only_specified']) { - $mapXml .= ' '.$p['map']['only_specified'].''.$nl; - } - $mapXml .= ''.$nl.$nl; - - $parsers = array( - 'product'=>'catalog/convert_parser_product', - 'customer'=>'customer/convert_parser_customer', - ); - - if ($import) { - $parseDataXml = ''.$nl; - $parseDataXml .= ' getStoreId().']]>'.$nl; - $parseDataXml .= ''.$nl.$nl; - } else { - $parseDataXml = ''.$nl; - $parseDataXml .= ' getStoreId().']]>'.$nl; - $parseDataXml .= ''.$nl.$nl; - } - - $adapters = array( - 'product'=>'catalog/convert_adapter_product', - 'customer'=>'customer/convert_adapter_customer', - ); - - if ($import) { - $entityXml = ''.$nl; - $entityXml .= ' getStoreId().']]>'.$nl; - $entityXml .= ''.$nl.$nl; - } else { - $entityXml = ''.$nl; - $entityXml .= ' getStoreId().']]>'.$nl; - foreach ($p[$this->getEntityType()]['filter'] as $f=>$v) { - if (empty($v)) { - continue; - } - if (is_scalar($v)) { - $entityXml .= ' '.$nl; - } elseif (is_array($v)) { - foreach ($v as $a=>$b) { - if (empty($b)) { - continue; - } - $entityXml .= ' '.$nl; - } - } - } - $entityXml .= ''.$nl.$nl; - } - - if ($import) { - $xml = $interactiveXml.$fileXml.$parseFileXml.$mapXml.$parseDataXml.$entityXml; - } else { - $xml = $entityXml.$parseDataXml.$mapXml.$parseFileXml.$fileXml.$interactiveXml; - } - - $this->setGuiData($p); - $this->setActionsXml($xml); -/*echo "
".print_r($p,1)."
"; -echo "".$xml.""; -die;*/ - return $this; - } -} diff --git a/app/code/core/Mage/Core/Model/Cookie.php b/app/code/core/Mage/Core/Model/Cookie.php index 83c8e90e6c..e949ef9267 100644 --- a/app/code/core/Mage/Core/Model/Cookie.php +++ b/app/code/core/Mage/Core/Model/Cookie.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Date.php b/app/code/core/Mage/Core/Model/Date.php index fa5cb19578..974c2259bf 100644 --- a/app/code/core/Mage/Core/Model/Date.php +++ b/app/code/core/Mage/Core/Model/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Design.php b/app/code/core/Mage/Core/Model/Design.php index 37957d5a30..456ae7201b 100644 --- a/app/code/core/Mage/Core/Model/Design.php +++ b/app/code/core/Mage/Core/Model/Design.php @@ -20,11 +20,29 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Core_Model_Resource_Design _getResource() + * @method Mage_Core_Model_Resource_Design getResource() + * @method int getStoreId() + * @method Mage_Core_Model_Design setStoreId(int $value) + * @method string getDesign() + * @method Mage_Core_Model_Design setDesign(string $value) + * @method string getDateFrom() + * @method Mage_Core_Model_Design setDateFrom(string $value) + * @method string getDateTo() + * @method Mage_Core_Model_Design setDateTo(string $value) + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ class Mage_Core_Model_Design extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Core/Model/Design/Package.php b/app/code/core/Mage/Core/Model/Design/Package.php index a60d437209..d0b06a31eb 100644 --- a/app/code/core/Mage/Core/Model/Design/Package.php +++ b/app/code/core/Mage/Core/Model/Design/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Design/Source/Apply.php b/app/code/core/Mage/Core/Model/Design/Source/Apply.php index 2a97495286..fe392e99f4 100644 --- a/app/code/core/Mage/Core/Model/Design/Source/Apply.php +++ b/app/code/core/Mage/Core/Model/Design/Source/Apply.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Design/Source/Design.php b/app/code/core/Mage/Core/Model/Design/Source/Design.php index 61bf0fddc0..8f0d25e1f2 100644 --- a/app/code/core/Mage/Core/Model/Design/Source/Design.php +++ b/app/code/core/Mage/Core/Model/Design/Source/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Email.php b/app/code/core/Mage/Core/Model/Email.php index 32040d8c0e..d2833cffa7 100644 --- a/app/code/core/Mage/Core/Model/Email.php +++ b/app/code/core/Mage/Core/Model/Email.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Email/Info.php b/app/code/core/Mage/Core/Model/Email/Info.php index 28cb25472e..6f05ee4e47 100644 --- a/app/code/core/Mage/Core/Model/Email/Info.php +++ b/app/code/core/Mage/Core/Model/Email/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Email/Template.php b/app/code/core/Mage/Core/Model/Email/Template.php index f58115a3b2..51a6f9be4c 100644 --- a/app/code/core/Mage/Core/Model/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Email/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -38,8 +38,33 @@ * ); * $emailTemplate->send('some@domain.com', 'Name Of User', $variables); * - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Email_Template _getResource() + * @method Mage_Core_Model_Resource_Email_Template getResource() + * @method string getTemplateCode() + * @method Mage_Core_Model_Email_Template setTemplateCode(string $value) + * @method string getTemplateText() + * @method Mage_Core_Model_Email_Template setTemplateText(string $value) + * @method string getTemplateStyles() + * @method Mage_Core_Model_Email_Template setTemplateStyles(string $value) + * @method int getTemplateType() + * @method Mage_Core_Model_Email_Template setTemplateType(int $value) + * @method string getTemplateSubject() + * @method Mage_Core_Model_Email_Template setTemplateSubject(string $value) + * @method string getTemplateSenderName() + * @method Mage_Core_Model_Email_Template setTemplateSenderName(string $value) + * @method string getTemplateSenderEmail() + * @method Mage_Core_Model_Email_Template setTemplateSenderEmail(string $value) + * @method string getAddedAt() + * @method Mage_Core_Model_Email_Template setAddedAt(string $value) + * @method string getModifiedAt() + * @method Mage_Core_Model_Email_Template setModifiedAt(string $value) + * @method string getOrigTemplateCode() + * @method Mage_Core_Model_Email_Template setOrigTemplateCode(string $value) + * @method string getOrigTemplateVariables() + * @method Mage_Core_Model_Email_Template setOrigTemplateVariables(string $value) + * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ class Mage_Core_Model_Email_Template extends Mage_Core_Model_Template @@ -139,17 +164,17 @@ public function loadDefault($templateId, $locale=null) $data['file'], 'email', $locale ); - if (preg_match('//', $templateText, $matches)) { + if (preg_match('//u', $templateText, $matches)) { $this->setTemplateSubject($matches[1]); $templateText = str_replace($matches[0], '', $templateText); } - if (preg_match('//us', $templateText, $matches)) { + if (preg_match('//us', $templateText, $matches)) { $this->setData('orig_template_variables', str_replace("\n", '', $matches[1])); $templateText = str_replace($matches[0], '', $templateText); } - if (preg_match('//sm', $templateText, $matches)) { + if (preg_match('//s', $templateText, $matches)) { $this->setTemplateStyles($matches[1]); $templateText = str_replace($matches[0], '', $templateText); } diff --git a/app/code/core/Mage/Core/Model/Email/Template/Filter.php b/app/code/core/Mage/Core/Model/Email/Template/Filter.php index 214d5eb6d3..a1236a48f1 100644 --- a/app/code/core/Mage/Core/Model/Email/Template/Filter.php +++ b/app/code/core/Mage/Core/Model/Email/Template/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Email/Template/Mailer.php b/app/code/core/Mage/Core/Model/Email/Template/Mailer.php index d68b518222..06f15d3ba5 100644 --- a/app/code/core/Mage/Core/Model/Email/Template/Mailer.php +++ b/app/code/core/Mage/Core/Model/Email/Template/Mailer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Email/Transport.php b/app/code/core/Mage/Core/Model/Email/Transport.php index a491eab9d6..02b6ea5eaa 100644 --- a/app/code/core/Mage/Core/Model/Email/Transport.php +++ b/app/code/core/Mage/Core/Model/Email/Transport.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Encryption.php b/app/code/core/Mage/Core/Model/Encryption.php index 17b0ca1171..9fffd830d8 100644 --- a/app/code/core/Mage/Core/Model/Encryption.php +++ b/app/code/core/Mage/Core/Model/Encryption.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage.php b/app/code/core/Mage/Core/Model/File/Storage.php index 8d1d9654a5..dab4ded38b 100644 --- a/app/code/core/Mage/Core/Model/File/Storage.php +++ b/app/code/core/Mage/Core/Model/File/Storage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/Abstract.php b/app/code/core/Mage/Core/Model/File/Storage/Abstract.php index 54fdd5182c..0f0f83b32c 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Abstract.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/Database.php b/app/code/core/Mage/Core/Model/File/Storage/Database.php index 16301f5762..32adc3aba6 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Database.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/Database/Abstract.php b/app/code/core/Mage/Core/Model/File/Storage/Database/Abstract.php index 3440a612d5..81b25f5abe 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Database/Abstract.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Database/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/Directory/Database.php b/app/code/core/Mage/Core/Model/File/Storage/Directory/Database.php index c430d853f7..7289a1609e 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Directory/Database.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Directory/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/File.php b/app/code/core/Mage/Core/Model/File/Storage/File.php index 65e83e8dee..4b7798ec8d 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/File.php +++ b/app/code/core/Mage/Core/Model/File/Storage/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Storage/Flag.php b/app/code/core/Mage/Core/Model/File/Storage/Flag.php index e19373d517..8dbbca1cd5 100644 --- a/app/code/core/Mage/Core/Model/File/Storage/Flag.php +++ b/app/code/core/Mage/Core/Model/File/Storage/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Uploader.php b/app/code/core/Mage/Core/Model/File/Uploader.php index f92b3d4752..af91108cb7 100644 --- a/app/code/core/Mage/Core/Model/File/Uploader.php +++ b/app/code/core/Mage/Core/Model/File/Uploader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php b/app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php index a21b739b15..0eb5b4d143 100644 --- a/app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php +++ b/app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/File/Validator/NotProtectedExtension.php b/app/code/core/Mage/Core/Model/File/Validator/NotProtectedExtension.php index 9de0a149c7..fef7b2f252 100644 --- a/app/code/core/Mage/Core/Model/File/Validator/NotProtectedExtension.php +++ b/app/code/core/Mage/Core/Model/File/Validator/NotProtectedExtension.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Flag.php b/app/code/core/Mage/Core/Model/Flag.php index b095976a80..d49a79aafe 100644 --- a/app/code/core/Mage/Core/Model/Flag.php +++ b/app/code/core/Mage/Core/Model/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Core Flag model * - * @category Mage - * @package Mage_Core - * @author Magento Core Team + * @method Mage_Core_Model_Resource_Flag _getResource() + * @method Mage_Core_Model_Resource_Flag getResource() + * @method string getFlagCode() + * @method Mage_Core_Model_Flag setFlagCode(string $value) + * @method int getState() + * @method Mage_Core_Model_Flag setState(int $value) + * @method string getLastUpdate() + * @method Mage_Core_Model_Flag setLastUpdate(string $value) + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ class Mage_Core_Model_Flag extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Core/Model/Input/Filter/MaliciousCode.php b/app/code/core/Mage/Core/Model/Input/Filter/MaliciousCode.php index 0eec59d9d9..d170299d87 100644 --- a/app/code/core/Mage/Core/Model/Input/Filter/MaliciousCode.php +++ b/app/code/core/Mage/Core/Model/Input/Filter/MaliciousCode.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Language.php b/app/code/core/Mage/Core/Model/Language.php index 0275cf8b02..aa9e597737 100644 --- a/app/code/core/Mage/Core/Model/Language.php +++ b/app/code/core/Mage/Core/Model/Language.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index b093209c62..6394b37279 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Layout/Data.php b/app/code/core/Mage/Core/Model/Layout/Data.php index 1b20c2b32d..442c01d554 100644 --- a/app/code/core/Mage/Core/Model/Layout/Data.php +++ b/app/code/core/Mage/Core/Model/Layout/Data.php @@ -20,11 +20,27 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Core_Model_Resource_Layout _getResource() + * @method Mage_Core_Model_Resource_Layout getResource() + * @method string getHandle() + * @method Mage_Core_Model_Layout_Data setHandle(string $value) + * @method string getXml() + * @method Mage_Core_Model_Layout_Data setXml(string $value) + * @method int getSortOrder() + * @method Mage_Core_Model_Layout_Data setSortOrder(int $value) + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ class Mage_Core_Model_Layout_Data extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Core/Model/Layout/Element.php b/app/code/core/Mage/Core/Model/Layout/Element.php index ae6095a551..cb8de940e8 100644 --- a/app/code/core/Mage/Core/Model/Layout/Element.php +++ b/app/code/core/Mage/Core/Model/Layout/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Layout/Update.php b/app/code/core/Mage/Core/Model/Layout/Update.php index 034b270b69..7e66e02eb2 100644 --- a/app/code/core/Mage/Core/Model/Layout/Update.php +++ b/app/code/core/Mage/Core/Model/Layout/Update.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index b303b1516a..eead5758a3 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Locale/Config.php b/app/code/core/Mage/Core/Model/Locale/Config.php index d48b238e96..195303562f 100644 --- a/app/code/core/Mage/Core/Model/Locale/Config.php +++ b/app/code/core/Mage/Core/Model/Locale/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Core_Model_Locale_Config @@ -108,7 +108,8 @@ class Mage_Core_Model_Locale_Config 'UYU' /*Uruguay Peso Uruguayo*/,'UZS' /*Uzbekistan Sum*/,'VUV' /*Vanuatu Vatu*/, 'VEB' /*Venezuelan Bolivar*/, 'VEF' /*Venezuelan bolívar fuerte*/,'VND' /*Vietnamese Dong*/, 'CHE' /*WIR Euro*/, 'CHW' /*WIR Franc*/, 'XOF' /*West African CFA franc*/,'WST' /*Western Samoa Tala*/,'YER' /*Yemeni Rial*/, 'ZMK' /*Zambian Kwacha*/, - 'ZWD' /*Zimbabwe Dollar*/, + 'ZWD' /*Zimbabwe Dollar*/,'TRY' /*Turkish Lira*/,'AZM' /*Azerbaijani Manat (1993-2006)*/, 'ROL' /*Old Romanian Leu*/, + 'TRL' /*Old Turkish Lira*/,'XPF' /*CFP Franc*/ ); /** diff --git a/app/code/core/Mage/Core/Model/Log/Adapter.php b/app/code/core/Mage/Core/Model/Log/Adapter.php index 77916e9ca7..cb562d04b7 100644 --- a/app/code/core/Mage/Core/Model/Log/Adapter.php +++ b/app/code/core/Mage/Core/Model/Log/Adapter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message.php b/app/code/core/Mage/Core/Model/Message.php index 88bd810fb8..67bc773d0f 100644 --- a/app/code/core/Mage/Core/Model/Message.php +++ b/app/code/core/Mage/Core/Model/Message.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Abstract.php b/app/code/core/Mage/Core/Model/Message/Abstract.php index 1347bbfa28..ff4d3d5f0d 100644 --- a/app/code/core/Mage/Core/Model/Message/Abstract.php +++ b/app/code/core/Mage/Core/Model/Message/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Collection.php b/app/code/core/Mage/Core/Model/Message/Collection.php index a830014ce1..93dcd7975c 100644 --- a/app/code/core/Mage/Core/Model/Message/Collection.php +++ b/app/code/core/Mage/Core/Model/Message/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Error.php b/app/code/core/Mage/Core/Model/Message/Error.php index bd6525a264..f339a5bdd6 100644 --- a/app/code/core/Mage/Core/Model/Message/Error.php +++ b/app/code/core/Mage/Core/Model/Message/Error.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Notice.php b/app/code/core/Mage/Core/Model/Message/Notice.php index 544609392e..e0c4333b2e 100644 --- a/app/code/core/Mage/Core/Model/Message/Notice.php +++ b/app/code/core/Mage/Core/Model/Message/Notice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Success.php b/app/code/core/Mage/Core/Model/Message/Success.php index 2e8722b9d9..bf51fdf5b1 100644 --- a/app/code/core/Mage/Core/Model/Message/Success.php +++ b/app/code/core/Mage/Core/Model/Message/Success.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Message/Warning.php b/app/code/core/Mage/Core/Model/Message/Warning.php index 234fd68fcd..ad44e90528 100644 --- a/app/code/core/Mage/Core/Model/Message/Warning.php +++ b/app/code/core/Mage/Core/Model/Message/Warning.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Mysql4/Abstract.php b/app/code/core/Mage/Core/Model/Mysql4/Abstract.php index 2f3bc90bcb..4269cfbe2b 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Abstract.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,734 +28,10 @@ /** * Abstract resource model class * - * * @category Mage * @package Mage_Core * @author Magento Core Team */ -abstract class Mage_Core_Model_Mysql4_Abstract extends Mage_Core_Model_Resource_Abstract +abstract class Mage_Core_Model_Mysql4_Abstract extends Mage_Core_Model_Resource_Db_Abstract { - const CHECKSUM_KEY_NAME = 'Checksum'; - - /** - * Cached resources singleton - * - * @var Mage_Core_Model_Resource - */ - protected $_resources; - - /** - * Prefix for resources that will be used in this resource model - * - * @var string - */ - protected $_resourcePrefix; - - /** - * Connections cache for this resource model - * - * @var array - */ - protected $_connections = array(); - - /** - * Resource model name that contains entities (names of tables) - * - * @var string - */ - protected $_resourceModel; - - /** - * Tables used in this resource model - * - * @var array - */ - protected $_tables = array(); - - /** - * Main table name - * - * @var string - */ - protected $_mainTable; - - /** - * Main table primary key field name - * - * @var string - */ - protected $_idFieldName; - - /** - * Primery key auto increment flag - * - * @var bool - */ - protected $_isPkAutoIncrement = true; - - /** - * Use is object new method for save of object - * - * @var boolean - */ - protected $_useIsObjectNew = false; - - /** - * Fields List for update in forsedSave - * - * @var array - */ - protected $_fieldsForUpdate = array(); - - protected $_mainTableFields; - - /** - * Main table unique keys field names - * - * could array( - * array('field' => 'db_field_name1', 'title' => 'Field 1 should be unique') - * array('field' => 'db_field_name2', 'title' => 'Field 2 should be unique') - * array( - * 'field' => array('db_field_name3', 'db_field_name3'), - * 'title' => 'Field 3 and Field 4 combination should be unique' - * ) - * ) - * - * or string 'my_field_name' - will be autoconverted to - * array( array( 'field' => 'my_field_name', 'title' => 'my_field_name' ) ) - * - * @var array - */ - protected $_uniqueFields = null; - - /** - * Serializable fields declaration - * - * Structure: array( - * => array( - * , - * , - * // optional parameter - * ), - * ) - * - * @var array - */ - protected $_serializableFields = array(); - - /** - * Standard resource model initialization - * - * @param string $mainTable - * @param string $idFieldName - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _init($mainTable, $idFieldName) - { - $this->_setMainTable($mainTable, $idFieldName); - } - - /** - * Initialize connections and tables for this resource model - * - * If one or both arguments are string, will be used as prefix - * If $tables is null and $connections is string, $tables will be the same - * - * @param string|array $connections - * @param string|array|null $tables - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _setResource($connections, $tables=null) - { - $this->_resources = Mage::getSingleton('core/resource'); - - if (is_array($connections)) { - foreach ($connections as $k=>$v) { - $this->_connections[$k] = $this->_resources->getConnection($v); - } - } - elseif (is_string($connections)) { - $this->_resourcePrefix = $connections; - } - - if (is_null($tables) && is_string($connections)) { - $this->_resourceModel = $this->_resourcePrefix; - } - elseif (is_array($tables)) { - foreach ($tables as $k=>$v) { - $this->_tables[$k] = $this->_resources->getTableName($v); - } - } - elseif (is_string($tables)) { - $this->_resourceModel = $tables; - } - return $this; - } - - /** - * Set main entity table name and primary key field name - * - * If field name is ommited {table_name}_id will be used - * - * @param string $mainTable - * @param string|null $idFieldName - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _setMainTable($mainTable, $idFieldName=null) - { - $mainTableArr = explode('/', $mainTable); - - if (!empty($mainTableArr[1])) { - if (empty($this->_resourceModel)) { - $this->_setResource($mainTableArr[0]); - } - $this->_setMainTable($mainTableArr[1], $idFieldName); - } else { - $this->_mainTable = $mainTable; - if (is_null($idFieldName)) { - $idFieldName = $mainTable.'_id'; - } - $this->_idFieldName = $idFieldName; - } - - return $this; - } - - /** - * Get primary key field name - * - * @return string - */ - public function getIdFieldName() - { - if (empty($this->_idFieldName)) { - Mage::throwException(Mage::helper('core')->__('Empty identifier field name')); - } - return $this->_idFieldName; - } - - /** - * Get main table name - * - * @return string - */ - public function getMainTable() - { - if (empty($this->_mainTable)) { - Mage::throwException(Mage::helper('core')->__('Empty main table name')); - } - return $this->getTable($this->_mainTable); - } - - /** - * Get table name for the entity - * - * @param string $entityName - * @return string - */ - public function getTable($entityName) - { - if (isset($this->_tables[$entityName])) { - return $this->_tables[$entityName]; - } - if (strpos($entityName, '/')) { - $this->_tables[$entityName] = $this->_resources->getTableName($entityName); - } elseif (!empty($this->_resourceModel)) { - $this->_tables[$entityName] = $this->_resources->getTableName( - $this->_resourceModel.'/'.$entityName); - } else { - $this->_tables[$entityName] = $entityName; - } - return $this->_tables[$entityName]; - } - - /** - * Retrieve table name for the entity separated value - * - * @param string $entityName - * @param string $valueType - * @return string - */ - public function getValueTable($entityName, $valueType) - { - return $this->getTable($entityName) . '_' . $valueType; - } - - /** - * Get connection by name or type - * - * @param string $connectionName - * @return Zend_Db_Adapter_Abstract - */ - protected function _getConnection($connectionName) - { - if (isset($this->_connections[$connectionName])) { - return $this->_connections[$connectionName]; - } - if (!empty($this->_resourcePrefix)) { - $this->_connections[$connectionName] = $this->_resources->getConnection( - $this->_resourcePrefix.'_'.$connectionName); - } else { - $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName); - } - - return $this->_connections[$connectionName]; - } - - /** - * Retrieve connection for read data - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - protected function _getReadAdapter() - { - return $this->_getConnection('read'); - } - - /** - * Retrieve connection for write data - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - protected function _getWriteAdapter() - { - return $this->_getConnection('write'); - } - - /** - * Temporary resolving collection compatibility - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - public function getReadConnection() - { - return $this->_getReadAdapter(); - } - - /** - * Load an object - * - * @param Mage_Core_Model_Abstract $object - * @param mixed $value - * @param string $field field to load by (defaults to model id) - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (is_null($field)) { - $field = $this->getIdFieldName(); - } - - $read = $this->_getReadAdapter(); - if ($read && !is_null($value)) { - $select = $this->_getLoadSelect($field, $value, $object); - $data = $read->fetchRow($select); - - if ($data) { - $object->setData($data); - } - } - - $this->unserializeFields($object); - $this->_afterLoad($object); - - return $this; - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where($this->getMainTable().'.'.$field.'=?', $value); - return $select; - } - - /** - * Save object object data - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function save(Mage_Core_Model_Abstract $object) - { - if ($object->isDeleted()) { - return $this->delete($object); - } - - $this->_serializeFields($object); - $this->_beforeSave($object); - $this->_checkUnique($object); - - if (!is_null($object->getId()) && (!$this->_useIsObjectNew || !$object->isObjectNew())) { - $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()); - /** - * Not auto increment primary key support - */ - if ($this->_isPkAutoIncrement) { - $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); - } else { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), array($this->getIdFieldName())) - ->where($condition); - if ($this->_getWriteAdapter()->fetchOne($select) !== false) { - $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); - } else { - $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object)); - } - } - } else { - $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object)); - $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable())); - if ($this->_useIsObjectNew) { - $object->isObjectNew(false); - } - } - - $this->unserializeFields($object); - $this->_afterSave($object); - - return $this; - } - - /** - * Forsed save object data - * forsed update If duplicate unique key data - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function forsedSave(Mage_Core_Model_Abstract $object) - { - $this->_beforeSave($object); - - // update - if (!is_null($object->getId()) && $this->_isPkAutoIncrement) { - $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()); - $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); - } - else { - $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), $this->_prepareDataForSave($object), $this->_fieldsForUpdate); - $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable())); - } - - $this->_afterSave($object); - - return $this; - } - - /** - * Delete the object - * - * @param Varien_Object $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function delete(Mage_Core_Model_Abstract $object) - { - $this->_beforeDelete($object); - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()) - ); - $this->_afterDelete($object); - return $this; - } - - /** - * Add unique field restriction - * - * @param array|string $field - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function addUniqueField($field) - { - if (is_null($this->_uniqueFields)) { - $this->_initUniqueFields(); - } - if(is_array($this->_uniqueFields) ) { - $this->_uniqueFields[] = $field; - } - return $this; - } - - /** - * Reset unique fields restrictions - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function resetUniqueField() - { - $this->_uniqueFields = array(); - return $this; - } - - /** - * Unserialize serializeable object fields - * - * @param Mage_Core_Model_Abstract $object - */ - public function unserializeFields(Mage_Core_Model_Abstract $object) - { - foreach ($this->_serializableFields as $field => $parameters) { - list($serializeDefault, $unserializeDefault) = $parameters; - $this->_unserializeField($object, $field, $unserializeDefault); - } - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(); - return $this; - } - - /** - * Get configuration of all unique fields - * - * @return array - */ - public function getUniqueFields() - { - if (is_null($this->_uniqueFields)) { - $this->_initUniqueFields(); - } - return $this->_uniqueFields; - } - - /** - * Prepare data for save - * - * @param Mage_Core_Model_Abstract $object - * @return array - */ - protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) - { - return $this->_prepareDataForTable($object, $this->getMainTable()); - } - - /** - * Prepare data for passed table - * - * @param Varien_Object $object - * @param string $table - * @return array - */ - protected function _prepareDataForTable(Varien_Object $object, $table) - { - $data = array(); - $fields = $this->_getWriteAdapter()->describeTable($table); - foreach (array_keys($fields) as $field) { - if ($object->hasData($field)) { - $fieldValue = $object->getData($field); - if ($fieldValue instanceof Zend_Db_Expr) { - $data[$field] = $fieldValue; - } else { - if (null !== $fieldValue) { - $data[$field] = $this->_prepareValueForSave($fieldValue, $fields[$field]['DATA_TYPE']); - } elseif (!empty($fields[$field]['NULLABLE'])) { - $data[$field] = null; - } - } - } - } - return $data; - } - - /** - * Check that model data fields that can be saved - * has really changed comparing with origData - * - * @param Mage_Core_Model_Abstract $object - * @return boolean - */ - public function hasDataChanged($object) - { - if (!$object->getOrigData()) { - return true; - } - - $fields = $this->_getWriteAdapter()->describeTable($this->getMainTable()); - foreach (array_keys($fields) as $field) { - if ($object->getOrigData($field) != $object->getData($field)) { - return true; - } - } - - return false; - } - - /** - * Prepare value for save - * - * @param mixed $value - * @param string $type - * @return mixed - */ - protected function _prepareValueForSave($value, $type) - { - if ($type == 'decimal') { - $value = Mage::app()->getLocale()->getNumber($value); - } - return $value; - } - - /** - * Check for unique values existence - * - * @param Varien_Object $object - * @return Mage_Core_Model_Mysql4_Abstract - * @throws Mage_Core_Exception - */ - protected function _checkUnique(Mage_Core_Model_Abstract $object) - { - $existent = array(); - $fields = $this->getUniqueFields(); - if (!empty($fields)) { - if (!is_array($fields)) { - $this->_uniqueFields = array( - array( - 'field' => $fields, - 'title' => $fields - )); - } - - $data = new Varien_Object($this->_prepareDataForSave($object)); - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()); - - foreach ($fields as $unique) { - $select->reset(Zend_Db_Select::WHERE); - - if (is_array($unique['field'])) { - foreach ($unique['field'] as $field) { - $select->where($field.'=?', $data->getData($field)); - } - } - else { - $select->where( $unique['field'] . ' = ?', $data->getData($unique['field']) ); - } - - if ($object->getId()) { - $select->where($this->getIdFieldName().' != ?', $object->getId()); - } - - if ( $test = $this->_getWriteAdapter()->fetchRow($select) ) { - $existent[] = $unique['title']; - } - } - } - - if (!empty($existent)) { - if (count($existent) == 1 ) { - $error = Mage::helper('core')->__('%s already exists.', $existent[0]); - } - else { - $error = Mage::helper('core')->__('%s already exist.', implode(', ', $existent)); - } - Mage::throwException($error); - } - return $this; - } - - public function afterLoad(Mage_Core_Model_Abstract $object) - { - $this->_afterLoad($object); - } - - /** - * Perform actions after object load - * - * @param Varien_Object $object - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - return $this; - } - - /** - * Perform actions before object save - * - * @param Varien_Object $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - return $this; - } - - /** - * Perform actions after object save - * - * @param Varien_Object $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - return $this; - } - - /** - * Perform actions before object delete - * - * @param Varien_Object $object - */ - protected function _beforeDelete(Mage_Core_Model_Abstract $object) - { - return $this; - } - - /** - * Perform actions after object delete - * - * @param Varien_Object $object - */ - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - return $this; - } - - /** - * Serialize serializeable fields of the object - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _serializeFields(Mage_Core_Model_Abstract $object) - { - foreach ($this->_serializableFields as $field => $parameters) { - list($serializeDefault, $unserializeDefault) = $parameters; - $this->_serializeField($object, $field, $serializeDefault, isset($parameters[2])); - } - } - - /** - * Retrieve table checksum - * - * @param string $table - * @return int - */ - public function getChecksum($table) - { - if (!$this->_getConnection('read')) { - return false; - } - - if (is_array($table)) { - $table = implode(',', $table); - } - - $data = $this->_getConnection('read')->fetchAll('checksum table '.$table); - $checksum = 0; - foreach ($data as $row) { - $checksum+= $row[self::CHECKSUM_KEY_NAME]; - } - return $checksum; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Cache.php b/app/code/core/Mage/Core/Model/Mysql4/Cache.php index 1137d9e98e..a0a863a333 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Cache.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Cache.php @@ -20,56 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Cache extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Cache extends Mage_Core_Model_Resource_Cache { - protected function _construct() - { - $this->_init('core/cache_option', 'code'); - } - - /** - * Get all cache options - * @return array | false - */ - public function getAllOptions() - { - $adapter = $this->_getReadAdapter(); - if ($adapter) { - /** - * Check if table exist (it protect upgrades. cache settings checked before upgrades) - */ - if ($adapter->fetchOne('SHOW TABLES LIKE ?', $this->getMainTable())) { - $select = $adapter->select() - ->from($this->getMainTable(), array('code', 'value')); - return $adapter->fetchPairs($select); - } - } - return false; - } - - /** - * Save all options to option table - * - * @param array $options - * @return Mage_Core_Model_Mysql4_Cache - */ - public function saveAllOptions($options) - { - if (!$this->_getWriteAdapter()) { - return $this; - } - $this->_getWriteAdapter()->delete($this->getMainTable()); - foreach ($options as $code => $value) { - $this->_getWriteAdapter()->insert($this->getMainTable(), array( - 'code' => $code, - 'value' => $value - )); - } - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php b/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php index a85e6ac289..95a9ed0fce 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php @@ -20,593 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -abstract class Mage_Core_Model_Mysql4_Collection_Abstract extends Varien_Data_Collection_Db +/** + * Abstract Core Resource Collection + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract { - const CACHE_TAG = 'COLLECTION_DATA'; - /** - * Model name - * - * @var string - */ - protected $_model; - - /** - * Resource model name - * - * @var string - */ - protected $_resourceModel; - - /** - * Resource instance - * - * @var Mage_Core_Model_Mysql4_Abstract - */ - protected $_resource; - - /** - * Fields to select in query - * - * @var array|null - */ - protected $_fieldsToSelect = null; - - /** - * Fields initial fields to select like id_field - * - * @var array|null - */ - protected $_initialFieldsToSelect = null; - - /** - * Fields to select changed flag - * - * @var booleam - */ - protected $_fieldsToSelectChanged = false; - - /** - * Store joined tables here - * - * @var array - */ - protected $_joinedTables = array(); - - /** - * Collection main table - * - * @var string - */ - protected $_mainTable = null; - - /** - * Reset items data changed flag - * - * @var boolean - */ - protected $_resetItemsDataChanged = false; - - /** - * Name prefix of events that are dispatched by model - * - * @var string - */ - protected $_eventPrefix = ''; - - /** - * Name of event parameter - * - * @var string - */ - protected $_eventObject = ''; - - /** - * Collection constructor - * - * @param Mage_Core_Model_Mysql4_Abstract $resource - */ - public function __construct($resource=null) - { - parent::__construct(); - $this->_construct(); - $this->_resource = $resource; - $this->setConnection($this->getResource()->getReadConnection()); - $this->_initSelect(); - } - - /** - * Initialization here - * - */ - protected function _construct() - { - - } - - /** - * Retrieve main table - * - * @return string - */ - public function getMainTable() - { - if ($this->_mainTable === null) { - $this->setMainTable($this->getResource()->getMainTable()); - } - - return $this->_mainTable; - } - - /** - * Set main collection table - * - * @param string $table - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function setMainTable($table) - { - if (strpos($table, '/') !== false) { - $table = $this->getTable($table); - } - - if ($this->_mainTable !== null && $table !== $this->_mainTable && $this->getSelect() !== null) { - $from = $this->getSelect()->getPart(Zend_Db_Select::FROM); - if (isset($from['main_table'])) { - $from['main_table']['tableName'] = $table; - } - $this->getSelect()->setPart(Zend_Db_Select::FROM, $from); - } - - $this->_mainTable = $table; - return $this; - } - - /** - * Init collection select - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _initSelect() - { - $this->getSelect()->from(array('main_table' => $this->getMainTable())); - return $this; - } - - /** - * Get Zend_Db_Select instance and applies fields to select if needed - * - * @return Varien_Db_Select - */ - public function getSelect() - { - if ($this->_select && $this->_fieldsToSelectChanged) { - $this->_fieldsToSelectChanged = false; - $this->_initSelectFields(); - } - return parent::getSelect(); - } - - /** - * Init fields for select - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _initSelectFields() - { - $columns = $this->_select->getPart(Zend_Db_Select::COLUMNS); - $columnsToSelect = array(); - foreach ($columns as $columnEntry) { - list($correlationName, $column, $alias) = $columnEntry; - if ($correlationName !== 'main_table') { // Add joined fields to select - if ($column instanceof Zend_Db_Expr) { - $column = $column->__toString(); - } - $key = ($alias !== null ? $alias : $column); - $columnsToSelect[$key] = $columnEntry; - } - } - - $columns = $columnsToSelect; - - $columnsToSelect = array_keys($columnsToSelect); - - if ($this->_fieldsToSelect !== null) { - $insertIndex = 0; - foreach ($this->_fieldsToSelect as $alias => $field) { - if (!is_string($alias)) { - $alias = null; - } - - if ($field instanceof Zend_Db_Expr) { - $column = $field->__toString(); - } else { - $column = $field; - } - - if (($alias !== null && in_array($alias, $columnsToSelect)) || // If field already joined fron another table - ($alias === null && isset($alias, $columnsToSelect))) { - continue; - } - - $columnEntry = array('main_table', $field, $alias); - array_splice($columns, $insertIndex, 0, array($columnEntry)); // Insert column - $insertIndex ++; - - } - } else { - array_unshift($columns, array('main_table', '*', null)); - } - - $this->_select->setPart(Zend_Db_Select::COLUMNS, $columns); - - return $this; - } - - /** - * Retrieve initial fields to select like id field - * - * @return array - */ - protected function _getInitialFieldsToSelect() - { - if ($this->_initialFieldsToSelect === null) { - $this->_initialFieldsToSelect = array(); - $this->_initInitialFieldsToSelect(); - } - - return $this->_initialFieldsToSelect; - } - - /** - * Initialize initial fields to select like id field - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _initInitialFieldsToSelect() - { - $idFieldName = $this->getResource()->getIdFieldName(); - if ($idFieldName) { - $this->_initialFieldsToSelect[] = $idFieldName; - } - return $this; - } - - /** - * Add field to select - * - * @param string|array $field - * @param string|null $alias - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function addFieldToSelect($field, $alias = null) - { - if ($field === '*') { // If we will select all fields - $this->_fieldsToSelect = null; - $this->_fieldsToSelectChanged = true; - return $this; - } - - if (is_array($field)) { - if ($this->_fieldsToSelect === null) { - $this->_fieldsToSelect = $this->_getInitialFieldsToSelect(); - } - - foreach ($field as $key => $value) { - $this->addFieldToSelect( - $value, - (is_string($key) ? $key : null), - false - ); - } - - $this->_fieldsToSelectChanged = true; - return $this; - } - - if ($alias === null) { - $this->_fieldsToSelect[] = $field; - } else { - $this->_fieldsToSelect[$alias] = $field; - } - - $this->_fieldsToSelectChanged = true; - return $this; - } - - /** - * Add attribute expression (SUM, COUNT, etc) - * - * Example: ('sub_total', 'SUM({{attribute}})', 'revenue') - * Example: ('sub_total', 'SUM({{revenue}})', 'revenue') - * - * For some functions like SUM use groupByAttribute. - * - * @param string $alias - * @param string $expression - * @param array $fields - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addExpressionFieldToSelect($alias, $expression, $fields) - { - // validate alias - if(!is_array($fields)) { - $fields = array($fields=>$fields); - } - - $fullExpression = $expression; - foreach($fields as $fieldKey=>$fieldItem) { - $fullExpression = str_replace('{{' . $fieldKey . '}}', $fieldItem, $fullExpression); - } - - $this->getSelect()->columns(array($alias=>$fullExpression)); - - return $this; - } - - /** - * Removes field from select - * - * @param string|null $field - * @param boolean $isAlias Alias identifier - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function removeFieldFromSelect($field, $isAlias = false) - { - if ($isAlias) { - if (isset($this->_fieldsToSelect[$field])) { - unset($this->_fieldsToSelect[$field]); - } - } else { - foreach ($this->_fieldsToSelect as $key => $value) { - if ($value === $field) { - unset($this->_fieldsToSelect[$key]); - break; - } - } - } - - $this->_fieldsToSelectChanged = true; - return $this; - } - - /** - * Removes all fields from select - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function removeAllFieldsFromSelect() - { - $this->_fieldsToSelect = $this->_getInitialFieldsToSelect(); - $this->_fieldsToSelectChanged = true; - return $this; - } - - /** - * Standard resource collection initalization - * - * @param string $model - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _init($model, $resourceModel=null) - { - $this->setModel($model); - if (is_null($resourceModel)) { - $resourceModel = $model; - } - $this->setResourceModel($resourceModel); - return $this; - } - - /** - * Set model name for collection items - * - * @param string $model - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function setModel($model) - { - if (is_string($model)) { - $this->_model = $model; - $this->setItemObjectClass(Mage::getConfig()->getModelClassName($model)); - } - return $this; - } - - /** - * Get model instance - * - * @param array $args - * @return Varien_Object - */ - public function getModelName($args=array()) - { - return $this->_model; - } - - public function setResourceModel($model) - { - $this->_resourceModel = $model; - } - - public function getResourceModelName() - { - return $this->_resourceModel; - } - - /** - * Get resource instance - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function getResource() - { - if (empty($this->_resource)) { - $this->_resource = Mage::getResourceModel($this->getResourceModelName()); - } - return $this->_resource; - } - - public function getTable($table) - { - return $this->getResource()->getTable($table); - } - - /** - * Retrive all ids for collection - * - * @return array - */ - public function getAllIds() - { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns( - 'main_table.' . $this->getResource()->getIdFieldName() - ); - return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams); - } - - public function join($table, $cond, $cols='*') - { - if (!isset($this->_joinedTables[$table])) { - $this->getSelect()->join(array($table=>$this->getTable($table)), $cond, $cols); - $this->_joinedTables[$table] = true; - } - return $this; - } - - /** - * Redeclare before load method for adding event - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _beforeLoad() - { - parent::_beforeLoad(); - Mage::dispatchEvent('core_collection_abstract_load_before', array('collection' => $this)); - if ($this->_eventPrefix && $this->_eventObject) { - Mage::dispatchEvent($this->_eventPrefix.'_load_before', array( - $this->_eventObject => $this - )); - } - return $this; - } - - /** - * Set reset items data changed flag - * - * @param boolean $flag - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function setResetItemsDataChanged($flag) - { - $this->_resetItemsDataChanged = (bool)$flag; - return $this; - } - - /** - * Set flag data has changed to all collection items - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function resetItemsDataChanged() - { - foreach ($this->_items as $item) { - $item->setDataChanges(false); - } - - return $this; - } - - /** - * Redeclare after load method for specifying collection items original data - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _afterLoad() - { - parent::_afterLoad(); - foreach ($this->_items as $item) { - $item->setOrigData(); - if ($this->_resetItemsDataChanged) { - $item->setDataChanges(false); - } - } - Mage::dispatchEvent('core_collection_abstract_load_after', array('collection' => $this)); - if ($this->_eventPrefix && $this->_eventObject) { - Mage::dispatchEvent($this->_eventPrefix.'_load_after', array( - $this->_eventObject => $this - )); - } - return $this; - } - - /** - * Save all the entities in the collection - * - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function save() - { - foreach ($this->getItems() as $item) { - $item->save(); - } - return $this; - } - - /** - * Check if cache can be used for collection - * - * @return bool - */ - protected function _canUseCache() - { - return Mage::app()->useCache('collections') && !empty($this->_cacheConf); - } - - /** - * Load cached data for select - * - * @param Zend_Db_Select $select - * @return string | false - */ - protected function _loadCache($select) - { - $data = Mage::app()->loadCache($this->_getSelectCacheId($select)); - return $data; - } - - /** - * Save collection data to cache - * - * @param array $data - * @param Zend_Db_Select $select - * @return unknown_type - */ - protected function _saveCache($data, $select) - { - Mage::app()->saveCache(serialize($data), $this->_getSelectCacheId($select), $this->_getCacheTags()); - return $this; - } - - /** - * Redeclared for processing cache tags throw application object - * - * @return array - */ - protected function _getCacheTags() - { - $tags = parent::_getCacheTags(); - $tags[] = Mage_Core_Model_App::CACHE_TAG; - $tags[] = self::CACHE_TAG; - return $tags; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Config.php b/app/code/core/Mage/Core/Model/Mysql4/Config.php index 89eaa617b7..eacc1baece 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Config.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Config.php @@ -20,217 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Config extends Mage_Core_Model_Resource_Config { - protected function _construct() - { - $this->_init('core/config_data', 'config_id'); - } - - /** - * Get checksum for one or more tables - * - * @param string|array $tables string is separated by comma - * @return integer|boolean - */ - public function getChecksum($tables) - { - if (is_string($tables)) { - $tablesArr = explode(',', $tables); - $tables = array(); - foreach ($tablesArr as $table) { - $table = $this->getTable(trim($table)); - if (!empty($table)) { - $tables[] = $table; - } - } - } - if (empty($tables) || !$this->_getReadAdapter()) { - return false; - } - $checksumArr = $this->_getReadAdapter()->fetchAll('checksum table '.join(',', $tables)); - $checksum = 0; - foreach ($checksumArr as $r) { - $checksum += $r['Checksum']; - } - return $checksum; - } - - /** - * Load configuration values into xml config object - * - * @param Mage_Core_Model_Config $xmlConfig - * @param string $cond - * @return Mage_Core_Model_Mysql4_Config_Collection - */ - public function loadToXml(Mage_Core_Model_Config $xmlConfig, $cond=null) - { - $read = $this->_getReadAdapter(); - if (!$read) { - return $this; - } - - $websites = array(); - $rows = $read->fetchAssoc("select website_id, code, name from ".$this->getTable('website')); - foreach ($rows as $w) { - $xmlConfig->setNode('websites/'.$w['code'].'/system/website/id', $w['website_id']); - $xmlConfig->setNode('websites/'.$w['code'].'/system/website/name', $w['name']); - $websites[$w['website_id']] = array('code'=>$w['code']); - } - - $stores = array(); - $rows = $read->fetchAssoc("select store_id, code, name, website_id from ".$this->getTable('store')." order by sort_order asc"); - foreach ($rows as $s) { - if (!isset($websites[$s['website_id']])) { - continue; - } - $xmlConfig->setNode('stores/'.$s['code'].'/system/store/id', $s['store_id']); - $xmlConfig->setNode('stores/'.$s['code'].'/system/store/name', $s['name']); - $xmlConfig->setNode('stores/'.$s['code'].'/system/website/id', $s['website_id']); - $xmlConfig->setNode('websites/'.$websites[$s['website_id']]['code'].'/system/stores/'.$s['code'], $s['store_id']); - $stores[$s['store_id']] = array('code'=>$s['code']); - $websites[$s['website_id']]['stores'][$s['store_id']] = $s['code']; - } - - $subst_from = array(); - $subst_to = array(); - - // load all configuration records from database, which are not inherited - $rows = $read->fetchAll("select scope, scope_id, path, value from ".$this->getMainTable().($cond ? ' where '.$cond : '')); - - // set default config values from database - foreach ($rows as $r) { - if ($r['scope']!=='default') { - continue; - } - $value = str_replace($subst_from, $subst_to, $r['value']); - $xmlConfig->setNode('default/'.$r['path'], $value); - } - // inherit default config values to all websites - $extendSource = $xmlConfig->getNode('default'); - foreach ($websites as $id=>$w) { - $websiteNode = $xmlConfig->getNode('websites/'.$w['code']); - $websiteNode->extend($extendSource); - } - - $deleteWebsites = array(); - // set websites config values from database - foreach ($rows as $r) { - if ($r['scope']!=='websites') { - continue; - } - $value = str_replace($subst_from, $subst_to, $r['value']); - if (isset($websites[$r['scope_id']])) { - $xmlConfig->setNode('websites/'.$websites[$r['scope_id']]['code'].'/'.$r['path'], $value); - } - else { - $deleteWebsites[$r['scope_id']] = $r['scope_id']; - } - } - - // extend website config values to all associated stores - foreach ($websites as $website) { - $extendSource = $xmlConfig->getNode('websites/'.$website['code']); - if (isset($website['stores'])) { - foreach ($website['stores'] as $sCode) { - $storeNode = $xmlConfig->getNode('stores/'.$sCode); - /** - * $extendSource DO NOT need overwrite source - */ - $storeNode->extend($extendSource, false); - } - } - } - - $deleteStores = array(); - // set stores config values from database - foreach ($rows as $r) { - if ($r['scope']!=='stores') { - continue; - } - $value = str_replace($subst_from, $subst_to, $r['value']); - if (isset($stores[$r['scope_id']])) { - $xmlConfig->setNode('stores/'.$stores[$r['scope_id']]['code'].'/'.$r['path'], $value); - } - else { - $deleteStores[$r['scope_id']] = $r['scope_id']; - } - } - - if ($deleteWebsites) { - $this->_getWriteAdapter()->delete($this->getMainTable(), array( - $this->_getWriteAdapter()->quoteInto('scope=?', 'websites'), - $this->_getWriteAdapter()->quoteInto('scope_id IN(?)', $deleteWebsites), - )); - } - - if ($deleteStores) { - $this->_getWriteAdapter()->delete($this->getMainTable(), array( - $this->_getWriteAdapter()->quoteInto('scope=?', 'stores'), - $this->_getWriteAdapter()->quoteInto('scope_id IN(?)', $deleteStores), - )); - } - - return $this; - } - - /** - * Save config value - * - * @param string $path - * @param string $value - * @param string $scope - * @param int $scopeId - * @return Mage_Core_Store_Mysql4_Config - */ - public function saveConfig($path, $value, $scope, $scopeId) - { - $writeAdapter = $this->_getWriteAdapter(); - $select = $writeAdapter->select() - ->from($this->getMainTable()) - ->where('path=?', $path) - ->where('scope=?', $scope) - ->where('scope_id=?', $scopeId); - $row = $writeAdapter->fetchRow($select); - - $newData = array( - 'scope' => $scope, - 'scope_id' => $scopeId, - 'path' => $path, - 'value' => $value - ); - - if ($row) { - $whereCondition = $writeAdapter->quoteInto($this->getIdFieldName() . '=?', $row[$this->getIdFieldName()]); - $writeAdapter->update($this->getMainTable(), $newData, $whereCondition); - } - else { - $writeAdapter->insert($this->getMainTable(), $newData); - } - return $this; - } - - /** - * Delete config value - * - * @param string $path - * @param string $scope - * @param int $scopeId - * @return Mage_Core_Store_Mysql4_Config - */ - public function deleteConfig($path, $scope, $scopeId) - { - $writeAdapter = $this->_getWriteAdapter(); - $writeAdapter->delete($this->getMainTable(), array( - $writeAdapter->quoteInto('path=?', $path), - $writeAdapter->quoteInto('scope=?', $scope), - $writeAdapter->quoteInto('scope_id=?', $scopeId) - )); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Config/Data.php b/app/code/core/Mage/Core/Model/Mysql4/Config/Data.php index fef262eb8f..bccdc13817 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Config/Data.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Config/Data.php @@ -20,22 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Config_Data extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Config_Data extends Mage_Core_Model_Resource_Config_Data { - protected function _construct() - { - $this->_init('core/config_data', 'config_id'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (is_array($object->getValue())) { - $object->setValue(join(',', $object->getValue())); - } - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Config/Data/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Config/Data/Collection.php index 0c8db8714e..69c7175820 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Config/Data/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Config/Data/Collection.php @@ -20,43 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Config data collection * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Config_Data_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Config_Data_Collection extends Mage_Core_Model_Resource_Config_Data_Collection { - protected function _construct() - { - $this->_init('core/config_data'); - } - - public function addScopeFilter($scope, $scopeId, $section) - { - $this->_select - ->where('scope=?', $scope) - ->where('scope_id=?', $scopeId) - ->where('path like ?', $section . '/%'); - return $this; - } - - public function addPathFilter($section) - { - $this->_select - ->where('path like ?', $section . '/%'); - return $this; - } - - public function addValueFilter($value) - { - $this->getSelect()->where('value=?', $value); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Design.php b/app/code/core/Mage/Core/Model/Mysql4/Design.php index 51642cf279..96a5b1d628 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Design.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Design.php @@ -20,146 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Design extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Design extends Mage_Core_Model_Resource_Design { - protected function _construct() - { - $this->_init('core/design_change', 'design_change_id'); - } - - public function _beforeSave(Mage_Core_Model_Abstract $object) - { - $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); - if ($date = $object->getDateFrom()) { - $date = Mage::app()->getLocale()->date($date, $format, null, false); - $object->setDateFrom($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } else { - $object->setDateFrom(null); - } - - if ($date = $object->getDateTo()) { - $date = Mage::app()->getLocale()->date($date, $format, null, false); - $object->setDateTo($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } else { - $object->setDateTo(null); - } - - if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && strtotime($object->getDateFrom()) > strtotime($object->getDateTo())){ - Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); - } - - $check = $this->_checkIntersection( - $object->getStoreId(), - $object->getDateFrom(), - $object->getDateTo(), - $object->getId() - ); - - if ($check){ - Mage::throwException(Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.')); - } - - if (is_null($object->getDateFrom())) - $object->setDateFrom(new Zend_Db_Expr('null')); - if (is_null($object->getDateTo())) - $object->setDateTo(new Zend_Db_Expr('null')); - - parent::_beforeSave($object); - } - - private function _checkIntersection($storeId, $dateFrom, $dateTo, $currentId) - { - $condition = '(date_to is null AND date_from is null)'; - if (!is_null($dateFrom)) { - $condition .= ' - OR - (? between date_from and date_to) - OR - (? >= date_from and date_to is null) - OR - (? <= date_to and date_from is null) - '; - } else { - $condition .= ' - OR - (date_from is null) - '; - } - - if (!is_null($dateTo)) { - $condition .= ' - OR - (# between date_from and date_to) - OR - (# >= date_from and date_to is null) - OR - (# <= date_to and date_from is null) - '; - } else { - $condition .= ' - OR - (date_to is null) - '; - } - - if (is_null($dateFrom) && !is_null($dateTo)) { - $condition .= ' - OR - (date_to <= # or date_from <= #) - '; - } - if (!is_null($dateFrom) && is_null($dateTo)) { - $condition .= ' - OR - (date_to >= ? or date_from >= ?) - '; - } - - if (!is_null($dateFrom) && !is_null($dateTo)) { - $condition .= ' - OR - (date_from between ? and #) - OR - (date_to between ? and #) - '; - } else if (is_null($dateFrom) && is_null($dateTo)) { - $condition = false; - } - - $select = $this->_getReadAdapter()->select() - ->from(array('main_table'=>$this->getTable('design_change'))) - ->where('main_table.store_id = ?', $storeId) - ->where('main_table.design_change_id <> ?', $currentId); - - if ($condition) { - $condition = $this->_getReadAdapter()->quoteInto($condition, $dateFrom); - $condition = str_replace('#', '?', $condition); - $condition = $this->_getReadAdapter()->quoteInto($condition, $dateTo); - - $select->where($condition); - } - - return $this->_getReadAdapter()->fetchOne($select); - } - - public function loadChange($storeId, $date = null) - { - if (is_null($date)) { - //$date = new Zend_Db_Expr('NOW()'); - $date = now(); - } - - $select = $this->_getReadAdapter()->select() - ->from(array('main_table'=>$this->getTable('design_change'))) - ->where('store_id = ?', $storeId) - ->where('(date_from <= ? or date_from is null)', $date) - ->where('(date_to >= ? or date_to is null)', $date); - - return $this->_getReadAdapter()->fetchRow($select); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Design/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Design/Collection.php index 4544435687..9a895245a0 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Design/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Design/Collection.php @@ -20,42 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Design_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Design_Collection extends Mage_Core_Model_Resource_Design_Collection { - protected function _construct() - { - $this->_init('core/design'); - } - - public function joinStore(){ - $this->getSelect() - ->join(array('s'=>$this->getTable('core/store')), 's.store_id = main_table.store_id', array('s.name')); - - return $this; - } - - public function addDateFilter($date = null) - { - if (is_null($date)) - $date = date("Y-m-d"); - - $this->getSelect() - ->where('main_table.date_from <= ?', $date) - ->where('main_table.date_to >= ?', $date); - - return $this; - } - - public function addStoreFilter($storeId) - { - $this->getSelect() - ->where('main_table.store_id IN(?)', $storeId); - - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Design/Package/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Design/Package/Collection.php index 1ea417c357..2adbbe83fd 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Design/Package/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Design/Package/Collection.php @@ -20,33 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Design_Package_Collection extends Varien_Object +/** + * Design package collection + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Design_Package_Collection extends Mage_Core_Model_Resource_Design_Package_Collection { - public function load() - { - $packages = $this->getData('packages'); - if (is_null($packages)) { - $packages = Mage::getModel('core/design_package')->getPackageList(); - $this->setData('packages', $packages); - } - - return $this; - } - - public function toOptionArray() - { - $options = array(); - $packages = $this->getData('packages'); - foreach ($packages as $package) { - $options[] = array('value'=>$package, 'label'=>$package); - } - array_unshift($options, array('value'=>'', 'label'=>'')); - - return $options; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php index d06a82afef..cd78c568ef 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php b/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php index 5c2ccc764d..19633c4260 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Email/Template.php @@ -20,132 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Template db resource * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Email_Template extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Email_Template extends Mage_Core_Model_Resource_Email_Template { - - /** - * Templates table name - * @var string - */ - protected $_templateTable; - - /** - * DB write connection - */ - protected $_write; - - /** - * DB read connection - */ - protected $_read; - - /** - * Initialize email template resource model - * - */ - protected function _construct() - { - $this->_init('core/email_template', 'template_id'); - $this->_templateTable = $this->getTable('core/email_template'); - $this->_read = $this->_getReadAdapter(); - $this->_write = $this->_getWriteAdapter(); - } - - /** - * Load by template code from DB. - * - * @param string $templateCode - * @return array - */ - public function loadByCode($templateCode) - { - $select = $this->_read->select() - ->from($this->_templateTable) - ->where('template_code=?', $templateCode); - - - $result = $this->_read->fetchRow($select); - - if (!$result) { - return array(); - } - - return $result; - } - - - /** - * Check usage of template code in other templates - * - * @param Mage_Core_Model_Email_Template $template - * @return boolean - */ - public function checkCodeUsage(Mage_Core_Model_Email_Template $template) - { - if($template->getTemplateActual()!=0 || is_null($template->getTemplateActual())) { - - $select = $this->_read->select() - ->from($this->_templateTable, new Zend_Db_Expr('COUNT(template_id)')) - ->where('template_id!=?',$template->getId()) - ->where('template_code=?',$template->getTemplateCode()); - - $countOfCodes = $this->_read->fetchOne($select); - - return $countOfCodes > 0; - } else { - return false; - } - } - - /** - * Set template type, added at and modified at time - * - * @param Varien_Object $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if(!$object->getAddedAt()) { - $object->setAddedAt(Mage::getSingleton('core/date')->gmtDate()); - $object->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); - } - $object->setTemplateType((int)$object->getTemplateType()); - return parent::_beforeSave($object); - } - - /** - * Retrieve config scope and scope id of specified email template by email pathes - * - * @param array $paths - * @param int|string $templateId - * @return array - */ - public function getSystemConfigByPathsAndTemplateId($paths, $templateId) - { - $adapter = $this->_getReadAdapter(); - $orWhere = array(); - foreach ($paths as $path) { - $orWhere[] = $adapter->quoteInto('path = ?', $path); - } - $select = $this->_read->select() - ->from($this->getTable('core/config_data'), array('scope', 'scope_id', 'path')) - ->where('value=?', $templateId) - ->where(join(' OR ', $orWhere)); - - $result = $this->_read->fetchAll($select); - if (!$result) { - return array(); - } - return $result; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Email/Template/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Email/Template/Collection.php index 161f820f5f..5e18dd4b1f 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Email/Template/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Email/Template/Collection.php @@ -20,42 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Templates collection - * - * @category Mage - * @package Mage_Core + * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Email_Template_Collection extends Varien_Data_Collection_Db +class Mage_Core_Model_Mysql4_Email_Template_Collection extends Mage_Core_Model_Resource_Email_Template_Collection { - /** - * Template table name - * - * @var string - */ - protected $_templateTable; - - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('core_read')); - $this->_templateTable = Mage::getSingleton('core/resource')->getTableName('core/email_template'); - $this->_select->from($this->_templateTable, array('template_id','template_code', - 'template_type', - 'template_subject','template_sender_name', - 'template_sender_email', - 'added_at', - 'modified_at')); - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('core/email_template')); - } - - public function toOptionArray() - { - return $this->_toOptionArray('template_id', 'template_code'); - } - } diff --git a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Abstract.php b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Abstract.php index e72826184d..d70d36f80f 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Abstract.php +++ b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,56 +32,6 @@ * @package Mage_Core * @author Magento Core Team */ -abstract class Mage_Core_Model_Mysql4_File_Storage_Abstract extends Mage_Core_Model_Mysql4_Abstract +abstract class Mage_Core_Model_Mysql4_File_Storage_Abstract extends Mage_Core_Model_Resource_File_Storage_Abstract { - /** - * File storage connection name - * - * @var string - */ - protected $_connectionName = null; - - - public function setConnectionName($name) - { - $this->_connectionName = $name; - return $this; - } - - /** - * Retrieve connection for read data - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - protected function _getReadAdapter() - { - return $this->_getConnection($this->_connectionName); - } - - /** - * Retrieve connection for write data - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - protected function _getWriteAdapter() - { - return $this->_getConnection($this->_connectionName); - } - - /** - * Get connection by name or type - * - * @param string $connectionName - * @return Zend_Db_Adapter_Abstract - */ - protected function _getConnection($connectionName) - { - if (isset($this->_connections[$connectionName])) { - return $this->_connections[$connectionName]; - } - - $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName); - - return $this->_connections[$connectionName]; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Database.php b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Database.php index eb8d30bdc9..439b710508 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Database.php +++ b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Database.php @@ -20,260 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * File storage database resource resource model class + * File storage database resource model class * * @category Mage * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_File_Storage_Database extends Mage_Core_Model_Mysql4_File_Storage_Abstract +class Mage_Core_Model_Mysql4_File_Storage_Database extends Mage_Core_Model_Resource_File_Storage_Database { - /** - * Define table name and id field for resource - */ - protected function _construct() - { - $this->_init('core/file_storage', 'file_id'); - } - - /** - * Create database scheme for storing files - * - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function createDatabaseScheme() - { - $this->_getWriteAdapter()->multi_query("CREATE TABLE IF NOT EXISTS {$this->getMainTable()} ( - `file_id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `content` LONGBLOB NOT NULL, - `upload_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `filename` varchar(255) NOT NULL DEFAULT '', - `directory_id` int(10) unsigned DEFAULT NULL, - `directory` varchar(255) DEFAULT NULL, - PRIMARY KEY (`file_id`), - UNIQUE KEY `IDX_FILENAME` (`filename`, `directory`), - KEY (`directory_id`), - CONSTRAINT `FK_FILE_DIRECTORY` FOREIGN KEY (`directory_id`) - REFERENCES {$this->getTable('core/directory_storage')} (`directory_id`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='File storage'"); - - return $this; - } - - /** - * Load entity by filename - * - * @param Mage_Core_Model_File_Storage_Database $object - * @param string $filename - * @param string $path - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function loadByFilename(Mage_Core_Model_File_Storage_Database $object, $filename, $path) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from(array('e' => $this->getMainTable())) - ->where('filename = ?', $filename) - ->where('directory = ?', $path); - - if ($data = $adapter->fetchRow($select)) { - $object->setData($data); - $this->_afterLoad($object); - } - - return $this; - } - - /** - * Clear files in storage - * - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function clearFiles() - { - $adapter = $this->_getWriteAdapter(); - $adapter->delete($this->getMainTable()); - - return $this; - } - - /** - * Get files from storage at defined range - * - * @param int $offset - * @param int $count - * @return array - */ - public function getFiles($offset = 0, $count = 100) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from( - array('e' => $this->getMainTable()), - array('filename', 'content', 'directory') - ) - ->order('file_id') - ->limit($count, $offset); - - return $adapter->fetchAll($select); - } - - /** - * Save matched product Ids - * - * @param Mage_Core_Model_File_Storage_Database|array $object - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function saveFile($file) - { - $adapter = $this->_getWriteAdapter(); - $data = array( - 'content' => $file['content'], - 'upload_time' => $file['update_time'], - 'filename' => $file['filename'], - 'directory_id' => $file['directory_id'], - 'directory' => $file['directory'] - ); - - $adapter->insertOnDuplicate($this->getMainTable(), $data, array('content', 'upload_time')); - - return $this; - } - - /** - * Rename files in database - * - * @param string $oldFilename - * @param string $oldPath - * @param string $newFilename - * @param string $newPath - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function renameFile($oldFilename, $oldPath, $newFilename, $newPath) - { - $adapter = $this->_getWriteAdapter(); - $dataUpdate = array('filename' => $newFilename, 'directory' => $newPath); - $dataWhere = array('filename = ?' => $oldFilename, 'directory = ?' => $oldPath); - - $adapter->update($this->getMainTable(), $dataUpdate, $dataWhere); - - return $this; - } - - /** - * Copy files in database - * - * @param string $oldFilename - * @param string $oldPath - * @param string $newFilename - * @param string $newPath - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function copyFile($oldFilename, $oldPath, $newFilename, $newPath) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from(array('e' => $this->getMainTable())) - ->where('filename = ?', $oldFilename) - ->where('directory = ?', $oldPath); - - $data = $adapter->fetchRow($select); - if (!$data) { - return $this; - } - - if (isset($data['file_id']) && isset($data['filename'])) { - unset($data['file_id']); - $data['filename'] = $newFilename; - $data['directory'] = $newPath; - - $writeAdapter = $this->_getWriteAdapter(); - $writeAdapter->insertOnDuplicate($this->getMainTable(), $data, array('content', 'upload_time')); - } - - return $this; - } - - /** - * Check whether file exists in DB - * - * @param string $filename - * @param string $path - * @return bool - */ - public function fileExists($filename, $path) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from(array('e' => $this->getMainTable())) - ->where('filename = ?', $filename) - ->where('directory = ?', $path) - ->limit(1); - - $data = $adapter->fetchRow($select); - return (bool)$data; - } - - /** - * Delete files that starts with given $folderName - * - * @param string $folderName - */ - public function deleteFolder($folderName = '') - { - if ($folderName && ($folderName !== '/')) { - $folderName = str_replace(array('%','_'), array('\%','\_'), $folderName); - $folderName = rtrim($folderName, '/'); - - $adapter = $this->_getWriteAdapter(); - $adapter->delete($this->getMainTable(), new Zend_Db_Expr('filename LIKE "' . $folderName . '/%"')); - } - } - - /** - * Delete file - * - * @param string $filename - * @param string $directory - */ - public function deleteFile($filename, $directory) - { - $this->_getWriteAdapter() - ->delete($this->getMainTable(), array('filename = ?' => $filename, 'directory = ?' => $directory)); - } - - /** - * Return directory file listing - * - * @param string $directory - * @return mixed - */ - public function getDirectoryFiles($directory) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from( - array('e' => $this->getMainTable()), - array( - 'filename', - 'directory', - 'content' - ) - ) - ->where('directory = ?', trim($directory, '/')) - ->order('file_id'); - - return $adapter->fetchAll($select); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Directory/Database.php b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Directory/Database.php index fb5bac26f7..75d51bda9e 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Directory/Database.php +++ b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Directory/Database.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,161 +32,6 @@ * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_File_Storage_Directory_Database extends Mage_Core_Model_Mysql4_File_Storage_Abstract +class Mage_Core_Model_Mysql4_File_Storage_Directory_Database extends Mage_Core_Model_Resource_File_Storage_Directory_Database { - /** - * Define table name and id field for resource - */ - protected function _construct() - { - $this->_init('core/directory_storage', 'directory_id'); - } - - /** - * Create database scheme for storing files - * - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function createDatabaseScheme() - { - $this->_getWriteAdapter()->multi_query("CREATE TABLE IF NOT EXISTS {$this->getMainTable()} ( - `directory_id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL DEFAULT '', - `path` varchar(255) NOT NULL DEFAULT '', - `upload_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `parent_id` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`directory_id`), - UNIQUE KEY `IDX_DIRECTORY_PATH` (`name`, `path`), - KEY `parent_id` (`parent_id`), - CONSTRAINT `FK_DIRECTORY_PARENT_ID` FOREIGN KEY (`parent_id`) - REFERENCES {$this->getMainTable()} (`directory_id`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Directory storage'"); - - return $this; - } - - /** - * Load entity by path - * - * @param Mage_Core_Model_File_Storage_Directory_Database $object - * @param string $path - * @return Mage_Core_Model_Mysql4_File_Storage_Directory_Database - */ - public function loadByPath(Mage_Core_Model_File_Storage_Directory_Database $object, $path) - { - $adapter = $this->_getReadAdapter(); - - $name = basename($path); - $path = dirname($path); - if ($path == '.') { - $path = ''; - } - - $select = $adapter->select() - ->from(array('e' => $this->getMainTable())) - ->where('name = ?', $name) - ->where('path = ?', $path); - - if ($data = $adapter->fetchRow($select)) { - $object->setData($data); - $this->_afterLoad($object); - } - - return $this; - } - - /** - * Return parent id - * - * @param string $path - * @return int - */ - public function getParentId($path) - { - $adapter = $this->_getReadAdapter(); - - $name = basename($path); - $path = dirname($path); - if ($path == '.') { - $path = ''; - } - - $select = $adapter->select() - ->from( - array('e' => $this->getMainTable()), - array('directory_id') - ) - ->where('name = ?', $name) - ->where('path = ?', $path); - - return $adapter->fetchOne($select); - } - - /** - * Delete all directories from storage - * - * @return Mage_Core_Model_Mysql4_File_Storage_Database - */ - public function clearDirectories() - { - $adapter = $this->_getWriteAdapter(); - $adapter->delete($this->getMainTable()); - - return $this; - } - - /** - * Export directories from database - * - * @param int $offset - * @param int $count - * @return mixed - */ - public function exportDirectories($offset, $count = 100) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from( - array('e' => $this->getMainTable()), - array('name', 'path') - ) - ->order('directory_id') - ->limit($count, $offset); - - return $adapter->fetchAll($select); - } - - /** - * Return directory file listing - * - * @param string $directory - * @return mixed - */ - public function getSubdirectories($directory) - { - $adapter = $this->_getReadAdapter(); - - $select = $adapter->select() - ->from( - array('e' => $this->getMainTable()), - array('name', 'path') - ) - ->where('path = ?', trim($directory, '/')) - ->order('directory_id'); - - return $adapter->fetchAll($select); - } - - /** - * Delete directory - * - * @param string $name - * @param string $path - */ - public function deleteDirectory($name, $path) - { - $this->_getWriteAdapter() - ->delete($this->getMainTable(), array('name = ?' => $name, 'path = ?' => $path)); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/File.php b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/File.php index fd190bf4a2..a1a03cbc0b 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/File/Storage/File.php +++ b/app/code/core/Mage/Core/Model/Mysql4/File/Storage/File.php @@ -20,179 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Abstract resource model class - * + * Model for synchronization from DB to filesystem * * @category Mage * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_File_Storage_File +class Mage_Core_Model_Mysql4_File_Storage_File extends Mage_Core_Model_Resource_File_Storage_File { - /** - * Prefix of model events names - * - * @var string - */ - protected $_mediaBaseDirectory = null; - - /** - * Files at storage - * - * @var array - */ - public function getMediaBaseDirectory() - { - if (is_null($this->_mediaBaseDirectory)) { - $this->_mediaBaseDirectory = Mage::helper('core/file_storage_database')->getMediaBaseDir(); - } - - return $this->_mediaBaseDirectory; - } - - /** - * Collect files and directories recursively - * - * @param string$dir - * @return array - */ - public function getStorageData($dir = '') - { - $files = array(); - $directories = array(); - $currentDir = $this->getMediaBaseDirectory() . $dir; - - if (is_dir($currentDir)) { - $dh = opendir($currentDir); - if ($dh) { - while (($file = readdir($dh)) !== false) { - if ($file == '.' || $file == '..' || $file == '.svn' || $file == '.htaccess') { - continue; - } - - $fullPath = $currentDir . DS . $file; - $relativePath = $dir . DS . $file; - if (is_dir($fullPath)) { - $directories[] = array( - 'name' => $file, - 'path' => str_replace(DS, '/', ltrim($dir, DS)) - ); - - $data = $this->getStorageData($relativePath); - $directories = array_merge($directories, $data['directories']); - $files = array_merge($files, $data['files']); - } else { - $files[] = $relativePath; - } - } - closedir($dh); - } - } - - return array('files' => $files, 'directories' => $directories); - } - - /** - * Clear files and directories in storage - * - * @param string $dir - * @return Mage_Core_Model_Mysql4_File_Storage_File - */ - public function clear($dir = '') - { - $currentDir = $this->getMediaBaseDirectory() . $dir; - - if (is_dir($currentDir)) { - $dh = opendir($currentDir); - if ($dh) { - while (($file = readdir($dh)) !== false) { - if ($file == '.' || $file == '..') { - continue; - } - - $fullPath = $currentDir . DS . $file; - if (is_dir($fullPath)) { - $this->clear($dir . DS . $file); - } else { - @unlink($fullPath); - } - } - closedir($dh); - @rmdir($currentDir); - } - } - - return $this; - } - - /** - * Save directory to storage - * - * @param array $dir - * @return bool - */ - public function saveDir($dir) - { - if (!isset($dir['name']) || !strlen($dir['name']) - || !isset($dir['path']) - ) { - return false; - } - - $path = (strlen($dir['path'])) - ? $dir['path'] . DS . $dir['name'] - : $dir['name']; - $path = Mage::helper('core/file_storage_database')->getMediaBaseDir() . DS . str_replace('/', DS, $path); - - if (!file_exists($path) || !is_dir($path)) { - if (!@mkdir($path, 0777, true)) { - Mage::throwException(Mage::helper('core')->__('Unable to create directory: %s', $path)); - } - } - - return true; - } - - /** - * Save file to storage - * - * @param string $filePath - * @param string $content - * @param bool $overwrite - * @return bool - */ - public function saveFile($filePath, $content, $overwrite = false) - { - $filename = basename($filePath); - $path = $this->getMediaBaseDirectory() . DS . str_replace('/', DS ,dirname($filePath)); - - if (!file_exists($path) || !is_dir($path)) { - @mkdir($path, 0777, true); - } - - $ioFile = new Varien_Io_File(); - $ioFile->cd($path); - - if (!$ioFile->fileExists($filename) || ($overwrite && $ioFile->rm($filename))) { - $ioFile->streamOpen($filename); - $ioFile->streamLock(true); - $result = $ioFile->streamWrite($content); - $ioFile->streamUnlock(); - $ioFile->streamClose(); - - if ($result) { - return true; - } - - Mage::throwException(Mage::helper('core')->__('Unable to save file: %s', $filePath)); - } - - return false; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Flag.php b/app/code/core/Mage/Core/Model/Mysql4/Flag.php index 87cceef00e..5fef62fda1 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Flag.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Flag.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Flag extends Mage_Core_Model_Mysql4_Abstract + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Flag extends Mage_Core_Model_Resource_Flag { - protected function _construct() - { - $this->_init('core/flag', 'flag_id'); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Language.php b/app/code/core/Mage/Core/Model/Mysql4/Language.php index ea0bbc7675..f98965901b 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Language.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Language.php @@ -20,15 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Language extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Language extends Mage_Core_Model_Resource_Language { - protected function _construct() - { - $this->_init('core/language', 'language_code'); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Language/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Language/Collection.php index ff892aa2ee..eb16838caf 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Language/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Language/Collection.php @@ -20,25 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Language_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Language_Collection extends Mage_Core_Model_Resource_Language_Collection { - protected function _construct() - { - $this->_init('core/language'); - } - - public function toOptionArray() - { - return $this->_toOptionArray('language_code', 'language_title', array('title'=>'language_title')); - } - - public function toOptionHash() - { - return $this->_toOptionHash('language_code', 'language_title'); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Layout.php b/app/code/core/Mage/Core/Model/Mysql4/Layout.php index 6ca9903219..2a583e6b4e 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Layout.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Layout.php @@ -20,49 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Layout extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Layout extends Mage_Core_Model_Resource_Layout { - protected function _construct() - { - $this->_init('core/layout_update', 'layout_update_id'); - } - - /** - * Retrieve layout updates by handle - * - * @param string $handle - * @param array $params - */ - public function fetchUpdatesByHandle($handle, $params = array()) - { - $storeId = isset($params['store_id']) ? $params['store_id'] : Mage::app()->getStore()->getId(); - $area = isset($params['area']) ? $params['area'] : Mage::getSingleton('core/design_package')->getArea(); - $package = isset($params['package']) ? $params['package'] : Mage::getSingleton('core/design_package')->getPackageName(); - $theme = isset($params['theme']) ? $params['theme'] : Mage::getSingleton('core/design_package')->getTheme('layout'); - - $updateStr = ''; - - $readAdapter = $this->_getReadAdapter(); - if ($readAdapter) { - $select = $readAdapter->select() - ->from(array('update'=>$this->getMainTable()), array('xml')) - ->join(array('link'=>$this->getTable('core/layout_link')), 'link.layout_update_id=update.layout_update_id', '') - ->where('link.store_id IN (0, ?)', $storeId) - ->where('link.area=?', $area) - ->where('link.package=?', $package) - ->where('link.theme=?', $theme) - ->where('update.handle = ?', $handle) - ->order('update.sort_order ASC'); - - foreach ($readAdapter->fetchAll($select) as $update) { - $updateStr .= $update['xml']; - } - } - return $updateStr; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Resource.php b/app/code/core/Mage/Core/Model/Mysql4/Resource.php index 2874583043..11e1bcd131 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Resource.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Resource.php @@ -20,120 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -#require_once 'Mage/Core/Model/Mysql4.php'; /** * Mysql Model for module + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Resource +class Mage_Core_Model_Mysql4_Resource extends Mage_Core_Model_Resource_Resource { - protected $_read = null; - protected $_write = null; - protected $_resTable = null; - protected static $_versions = null; - protected static $_dataVersions = null; - - /** - * Class constructor - */ - public function __construct() - { - $this->_resTable = Mage::getSingleton('core/resource')->getTableName('core/resource'); - $this->_read = Mage::getSingleton('core/resource')->getConnection('core_read'); - $this->_write = Mage::getSingleton('core/resource')->getConnection('core_write'); - } - - /** - * Get Module version from DB - * - * @param string $moduleName - * @return string - */ - function getDbVersion($resName) - { - if (!$this->_read) { - return false; - } - - if (is_null(self::$_versions)) { - // if Core module not instaled - try { - $select = $this->_read->select()->from($this->_resTable, array('code', 'version')); - self::$_versions = $this->_read->fetchPairs($select); - } - catch (Exception $e){ - self::$_versions = array(); - } - } - return isset(self::$_versions[$resName]) ? self::$_versions[$resName] : false; - } - - /** - * Set module wersion into DB - * - * @param string $moduleName - * @param string $version - * @return int - */ - function setDbVersion($resName, $version) - { - $dbModuleInfo = array( - 'code' => $resName, - 'version' => $version, - ); - - if ($this->getDbVersion($resName)) { - self::$_versions[$resName] = $version; - $condition = $this->_write->quoteInto('code=?', $resName); - return $this->_write->update($this->_resTable, $dbModuleInfo, $condition); - } - else { - self::$_versions[$resName] = $version; - return $this->_write->insert($this->_resTable, $dbModuleInfo); - } - } - - /** - * Get resource data version - * - * @param string $resName - * @return string | false - */ - public function getDataVersion($resName) - { - if (!$this->_read) { - return false; - } - if (is_null(self::$_dataVersions)) { - $select = $this->_read->select()->from($this->_resTable, array('code', 'data_version')); - self::$_dataVersions = $this->_read->fetchPairs($select); - } - return isset(self::$_dataVersions[$resName]) ? self::$_dataVersions[$resName] : false; - } - - /** - * Specify resource data version - * - * @param string $resName - * @param string $version - * @return Mage_Core_Model_Mysql4_Resource - */ - public function setDataVersion($resName, $version) - { - $data = array('code' => $resName, 'data_version' => $version); - - if ($this->getDbVersion($resName) || $this->getDataVersion($resName)) { - self::$_dataVersions[$resName] = $version; - $this->_write->update($this->_resTable, $data, array('code=?' => $resName)); - } - else { - self::$_dataVersions[$resName] = $version; - $this->_write->insert($this->_resTable, $data); - } - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Session.php b/app/code/core/Mage/Core/Model/Mysql4/Session.php index 18e174a9a2..7b42ababc6 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Session.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,209 +28,10 @@ /** * Mysql4 session save handler * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Session implements Zend_Session_SaveHandler_Interface +class Mage_Core_Model_Mysql4_Session extends Mage_Core_Model_Resource_Session { - /** - * Session lifetime - * - * @var integer - */ - protected $_lifeTime; - - /** - * Session data table name - * - * @var string - */ - protected $_sessionTable; - - /** - * Database read connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_read; - - /** - * Database write connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_write; - - /** - * Automatic cleaning factor of expired sessions - * - * value zero means no automatic cleaning, one means automatic cleaning each time a session is closed, and x>1 means - * cleaning once in x calls - */ - protected $_automaticCleaningFactor = 50; - - public function __construct() - { - $this->_sessionTable = Mage::getSingleton('core/resource')->getTableName('core/session'); - $this->_read = Mage::getSingleton('core/resource')->getConnection('core_read'); - $this->_write = Mage::getSingleton('core/resource')->getConnection('core_write'); - } - - public function __destruct() - { - session_write_close(); - } - - public function getLifeTime() - { - if (is_null($this->_lifeTime)) { - $configNode = Mage::app()->getStore()->isAdmin() ? 'admin/security/session_cookie_lifetime' : 'web/cookie/cookie_lifetime'; - $this->_lifeTime = (int) Mage::getStoreConfig($configNode); - - if ($this->_lifeTime < 60) { - $this->_lifeTime = ini_get('session.gc_maxlifetime'); - } - - if ($this->_lifeTime < 60) { - $this->_lifeTime = 3600; - } - } - return $this->_lifeTime; - } - - /** - * Check DB connection - * - * @return bool - */ - public function hasConnection() - { - if (!$this->_read) { - return false; - } - $tables = $this->_read->fetchAssoc('show tables'); - if (!isset($tables[$this->_sessionTable])) { - return false; - } - - return true; - } - - public function setSaveHandler() - { - if ($this->hasConnection()) { - session_set_save_handler( - array($this, 'open'), - array($this, 'close'), - array($this, 'read'), - array($this, 'write'), - array($this, 'destroy'), - array($this, 'gc') - ); - } else { - session_save_path(Mage::getBaseDir('session')); - } - return $this; - } - - /** - * Open session - * - * @param string $savePath ignored - * @param string $sessName ignored - * @return boolean - */ - public function open($savePath, $sessName) - { - return true; - } - - /** - * Close session - * - * @return boolean - */ - public function close() - { - $this->gc($this->getLifeTime()); - - return true; - } - - /** - * Fetch session data - * - * @param string $sessId - * @return string - */ - public function read($sessId) - { - $data = $this->_read->fetchOne( - "SELECT session_data FROM $this->_sessionTable - WHERE session_id = ? AND session_expires > ?", - array($sessId, time()) - ); - - return $data; - } - - /** - * Update session - * - * @param string $sessId - * @param string $sessData - * @return boolean - */ - public function write($sessId, $sessData) - { - $bind = array( - 'session_expires'=>time() + $this->getLifeTime(), - 'session_data'=>$sessData - ); - - $exists = $this->_write->fetchOne( - "SELECT session_id FROM `{$this->_sessionTable}` - WHERE session_id = ?", array($sessId) - ); - - if ($exists) { - $where = $this->_write->quoteInto('session_id=?', $sessId); - $this->_write->update($this->_sessionTable, $bind, $where); - } else { - $bind['session_id'] = $sessId; - $this->_write->insert($this->_sessionTable, $bind); - } - - return true; - } - - /** - * Destroy session - * - * @param string $sessId - * @return boolean - */ - public function destroy($sessId) - { - $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_id` = ?", array($sessId)); - return true; - } - - /** - * Garbage collection - * - * @param int $sessMaxLifeTime ignored - * @return boolean - */ - public function gc($sessMaxLifeTime) - { - if ($this->_automaticCleaningFactor > 0) { - if ($this->_automaticCleaningFactor == 1 || - rand(1, $this->_automaticCleaningFactor)==1) { - $this->_write->query("DELETE FROM `{$this->_sessionTable}` WHERE `session_expires` < ?", array(time())); - } - } - return true; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Store.php b/app/code/core/Mage/Core/Model/Mysql4/Store.php index 37c76a6fd0..83975ad973 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Store.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Store.php @@ -20,100 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Store extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Store extends Mage_Core_Model_Resource_Store { - protected function _construct() - { - $this->_init('core/store', 'store_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'code', - 'title' => Mage::helper('core')->__('Store with the same code') - )); - return $this; - } - - protected function _beforeSave(Mage_Core_Model_Abstract $model) - { - if(!preg_match('/^[a-z]+[a-z0-9_]*$/',$model->getCode())) { - Mage::throwException( - Mage::helper('core')->__('The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter')); - } - - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - parent::_afterSave($object); - $this->_updateGroupDefaultStore($object->getGroupId(), $object->getId()); - $this->_changeGroup($object); - - return $this; - } - - protected function _afterDelete(Mage_Core_Model_Abstract $model) - { - $this->_getWriteAdapter()->delete( - $this->getTable('core/config_data'), - $this->_getWriteAdapter()->quoteInto("scope = 'stores' AND scope_id = ?", $model->getStoreId()) - ); - return $this; - } - - protected function _updateGroupDefaultStore($groupId, $store_id) - { - $write = $this->_getWriteAdapter(); - $cnt = $write->fetchOne($write->select() - ->from($this->getTable('core/store'), array('count'=>'COUNT(*)')) - ->where($write->quoteInto('group_id=?', $groupId)), - 'count'); - if ($cnt == 1) { - $write->update($this->getTable('core/store_group'), - array('default_store_id' => $store_id), - $write->quoteInto('group_id=?', $groupId) - ); - } - return $this; - } - - protected function _changeGroup(Mage_Core_Model_Abstract $model) { - if ($model->getOriginalGroupId() && $model->getGroupId() != $model->getOriginalGroupId()) { - $write = $this->_getWriteAdapter(); - $storeId = $write->fetchOne($write->select() - ->from($this->getTable('core/store_group'), 'default_store_id') - ->where($write->quoteInto('group_id=?', $model->getOriginalGroupId())), - 'default_store_id' - ); - if ($storeId == $model->getId()) { - $write->update($this->getTable('core/store_group'), - array('default_store_id'=>0), - $write->quoteInto('group_id=?', $model->getOriginalGroupId())); - } - } - return $this; - } - - protected function _getLoadSelect($field, $value, $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where($field.'=?', $value) - ->order('sort_order ASC'); - - return $select; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php index 36cd2c1aa9..03cbc6eb9c 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php @@ -20,150 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Stores collection * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Store_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Store_Collection extends Mage_Core_Model_Resource_Store_Collection { - protected $_loadDefault = false; - - protected function _construct() - { - $this->_init('core/store'); - } - - public function setLoadDefault($loadDefault) - { - $this->_loadDefault = $loadDefault; - return $this; - } - - public function getLoadDefault() - { - return $this->_loadDefault; - } - - public function setWithoutDefaultFilter() - { - $this->getSelect()->where($this->getConnection()->quoteInto('main_table.store_id>?', 0)); - return $this; - } - - /** - * Add filter by group id. - * Group id can be passed as one single value or array of values. - * - * @param int|array $groupId - * @return Mage_Core_Model_Mysql4_Store_Collection - */ - public function addGroupFilter($groupId) - { - if (is_array($groupId)) { - $condition = $this->getConnection()->quoteInto("main_table.group_id IN (?)", $groupId); - } else { - $condition = $this->getConnection()->quoteInto("main_table.group_id = ?",$groupId); - } - - $this->addFilter('group_id', $condition, 'string'); - return $this; - } - - public function addIdFilter($store) - { - if (is_array($store)) { - $condition = $this->getConnection()->quoteInto("main_table.store_id IN (?)", $store); - } - else { - $condition = $this->getConnection()->quoteInto("main_table.store_id=?",$store); - } - - $this->addFilter('store_id', $condition, 'string'); - return $this; - } - - public function addWebsiteFilter($website) - { - if (is_array($website)) { - $condition = $this->getConnection()->quoteInto("main_table.website_id IN (?)", $website); - } - else { - $condition = $this->getConnection()->quoteInto("main_table.website_id=?",$website); - } - - $this->addFilter('website_id', $condition, 'string'); - return $this; - } - - /** - * Add root category id filter to store collection - * - * @param int|array $category - * @return Mage_Core_Model_Mysql4_Store_Collection - */ - public function addCategoryFilter($category) - { - if (!is_array($category)) { - $category = array($category); - } - return $this->loadByCategoryIds($category); - } - - public function toOptionArray() - { - return $this->_toOptionArray('store_id', 'name'); - } - - public function toOptionHash() - { - return $this->_toOptionHash('store_id', 'name'); - } - - public function load($printQuery = false, $logQuery = false) - { - if (!$this->getLoadDefault()) { - $this->getSelect()->where($this->getConnection()->quoteInto('main_table.store_id>?', 0)); - } - $this->addOrder('CASE WHEN main_table.store_id = 0 THEN 0 ELSE 1 END', 'ASC') - ->addOrder('main_table.sort_order', 'ASC') - ->addOrder('main_table.name', 'ASC'); - parent::load($printQuery, $logQuery); - return $this; - } - - /** - * Add root category id filter to store collection - * - * @param array $categories - * @return Mage_Core_Model_Mysql4_Store_Collection - */ - public function loadByCategoryIds(array $categories) - { - $this->setLoadDefault(true); - $condition = $this->getConnection()->quoteInto('group_table.root_category_id IN(?)', $categories); - $this->_select->joinLeft( - array('group_table' => $this->getTable('core/store_group')), - 'main_table.group_id=group_table.group_id', - array('root_category_id') - )->where($condition); - - return $this; - } - - public function addRootCategoryIdAttribute() - { - $this->_select->joinLeft( - array('group_table' => $this->getTable('core/store_group')), - 'main_table.group_id=group_table.group_id', - array('root_category_id') - ); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Store/Group.php b/app/code/core/Mage/Core/Model/Mysql4/Store/Group.php index 5a524c2791..785c539fd9 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Store/Group.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Store/Group.php @@ -20,82 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Store group resource model * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ - -class Mage_Core_Model_Mysql4_Store_Group extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Store_Group extends Mage_Core_Model_Resource_Store_Group { - protected function _construct() - { - $this->_init('core/store_group', 'group_id'); - } - - protected function _afterSave(Mage_Core_Model_Abstract $model) - { - $this->_updateStoreWebsite($model->getId(), $model->getWebsiteId()); - $this->_updateWebsiteDefaultGroup($model->getWebsiteId(), $model->getId()); - $this->_changeWebsite($model); - - return $this; - } - - protected function _updateWebsiteDefaultGroup($websiteId, $groupId) - { - $write = $this->_getWriteAdapter(); - $cnt = $write->fetchOne($write->select() - ->from($this->getTable('core/store_group'), array('count'=>'COUNT(*)')) - ->where($write->quoteInto('website_id=?', $websiteId)), - 'count'); - if ($cnt == 1) { - $write->update($this->getTable('core/website'), - array('default_group_id' => $groupId), - $write->quoteInto('website_id=?', $websiteId) - ); - } - return $this; - } - - protected function _changeWebsite(Mage_Core_Model_Abstract $model) { - if ($model->getOriginalWebsiteId() && $model->getWebsiteId() != $model->getOriginalWebsiteId()) { - $write = $this->_getWriteAdapter(); - $groupId = $write->fetchOne($write->select() - ->from($this->getTable('core/website'), 'default_group_id') - ->where($write->quoteInto('website_id=?', $model->getOriginalWebsiteId())), - 'default_group_id' - ); - if ($groupId == $model->getId()) { - $write->update($this->getTable('core/website'), - array('default_group_id'=>0), - $write->quoteInto('website_id=?', $model->getOriginalWebsiteId())); - } - } - return $this; - } - - protected function _updateStoreWebsite($groupId, $websiteId) - { - $write = $this->_getWriteAdapter(); - $bind = array('website_id'=>$websiteId); - $condition = $write->quoteInto('group_id=?', $groupId); - $this->_getWriteAdapter()->update($this->getTable('core/store'), $bind, $condition); - return $this; - } - - protected function _saveDefaultStore($groupId, $storeId) - { - $write = $this->_getWriteAdapter(); - $bind = array('default_store_id'=>$storeId); - $condition = $write->quoteInto('group_id=?', $groupId); - $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $condition); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Store/Group/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Store/Group/Collection.php index b8f77fa67d..b13d878f03 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Store/Group/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Store/Group/Collection.php @@ -20,66 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Store group collection * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ - -class Mage_Core_Model_Mysql4_Store_Group_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Store_Group_Collection extends Mage_Core_Model_Resource_Store_Group_Collection { - protected $_loadDefault = false; - - protected function _construct() - { - $this->_init('core/store_group'); - } - - public function load($printQuery = false, $logQuery = false) - { - if (!$this->_loadDefault) { - $this->setWithoutDefaultFilter(); - } - $this->addOrder('main_table.name', 'ASC'); - return parent::load($printQuery, $logQuery); - } - - public function setLoadDefault($loadDefault) - { - $this->_loadDefault = (bool)$loadDefault; - return $this; - } - - public function getLoadDefault() - { - return $this->_loadDefault; - } - - public function setWithoutDefaultFilter() - { - $this->getSelect()->where($this->getConnection()->quoteInto('main_table.group_id>?', 0)); - return $this; - } - - public function toOptionArray() - { - return $this->_toOptionArray('group_id', 'name'); - } - - public function addWebsiteFilter($website) - { - if (is_array($website)) { - $condition = $this->getConnection()->quoteInto('main_table.website_id IN(?)', $website); - } - else { - $condition = $this->getConnection()->quoteInto('main_table.website_id=?', $website); - } - return $this->addFilter('website_id', $condition, 'string'); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Translate.php b/app/code/core/Mage/Core/Model/Mysql4/Translate.php index a2cd5c6674..2e1373326f 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Translate.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Translate.php @@ -20,98 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Translation resource model * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Translate extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Translate extends Mage_Core_Model_Resource_Translate { - protected function _construct() - { - $this->_init('core/translate', 'key_id'); - } - - public function getTranslationArray($storeId=null, $locale=null) - { - if(!Mage::isInstalled()) { - return array(); - } - - if (is_null($storeId)) { - $storeId = Mage::app()->getStore()->getId(); - } - - $read = $this->_getReadAdapter(); - if (!$read) { - return array(); - } - -// $select = $read->select() -// ->from(array('main'=>$this->getMainTable()), array( -// 'string', -// new Zend_Db_Expr('IFNULL(store.translate, main.translate)') -// )) -// ->joinLeft(array('store'=>$this->getMainTable()), -// $read->quoteInto('store.string=main.string AND store.store_id=?', $storeId), -// 'string') -// ->where('main.store_id=0'); -// -// $result = $read->fetchPairs($select); -// - $select = $read->select() - ->from($this->getMainTable()) - ->where('store_id in (?)', array(0, $storeId)) - ->where('locale=?', $locale) - ->order('store_id'); - - $result = array(); - foreach ($read->fetchAll($select) as $row) { - $result[$row['string']] = $row['translate']; - } - - return $result; - } - - public function getTranslationArrayByStrings(array $strings, $storeId=null) - { - if(!Mage::isInstalled()) { - return array(); - } - - if (is_null($storeId)) { - $storeId = Mage::app()->getStore()->getId(); - } - - $read = $this->_getReadAdapter(); - if (!$read) { - return array(); - } - - if (empty($strings)) { - return array(); - } - - $select = $read->select() - ->from($this->getMainTable()) - ->where('string in (:tr_strings)') - ->where('store_id = ?', $storeId); - $result = array(); - foreach ($read->fetchAll($select, array('tr_strings'=>$read->quote($strings))) as $row) { - $result[$row['string']] = $row['translate']; - } - - return $result; - } - - public function getMainChecksum() - { - return parent::getChecksum($this->getMainTable()); - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Translate/String.php b/app/code/core/Mage/Core/Model/Mysql4/Translate/String.php index 2ef0f47e68..c9e977b152 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Translate/String.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Translate/String.php @@ -20,181 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * String translate resource model * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Translate_String extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Translate_String extends Mage_Core_Model_Resource_Translate_String { - protected function _construct() - { - $this->_init('core/translate', 'key_id'); - } - - public function load(Mage_Core_Model_Abstract $object, $value, $field=null) - { - if (is_string($value)) { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where($this->getMainTable().'.string=:tr_string'); - $result = $this->_getReadAdapter()->fetchRow($select, array('tr_string'=>$value)); - $object->setData($result); - $this->_afterLoad($object); - return $result; - } - else { - return parent::load($object, $value, $field); - } - } - - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $select->where('store_id', 0); - return $select; - } - - - public function _afterLoad(Mage_Core_Model_Abstract $object) - { - $connection = $this->_getReadAdapter(); - $select = $connection->select() - ->from($this->getMainTable(), array('store_id', 'translate')) - ->where('string=:translate_string'); - $translations = $connection->fetchPairs($select, array('translate_string' => $object->getString())); - $object->setStoreTranslations($translations); - return parent::_afterLoad($object); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $connection = $this->_getWriteAdapter(); - $select = $connection->select() - ->from($this->getMainTable(), 'key_id') - ->where('string=?', $object->getString()) - ->where('store_id=?', 0); - - $object->setId($connection->fetchOne($select)); - return parent::_beforeSave($object); - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $connection = $this->_getWriteAdapter(); - $select = $connection->select() - ->from($this->getMainTable(), array('store_id', 'key_id')) - ->where('string=?', $object->getString()); - $stors = $connection->fetchPairs($select); - - $translations = $object->getStoreTranslations(); - - if (is_array($translations)) { - foreach ($translations as $storeId => $translate) { - $condition = $connection->quoteInto('store_id=? AND ', $storeId) . - $connection->quoteInto('string=?', $object->getString()); - - if (is_null($translate) || $translate=='') { - $connection->delete($this->getMainTable(), $condition); - } - else { - $data = array( - 'store_id' => $storeId, - 'string' => $object->getString(), - 'translate' =>$translate, - ); - - if (isset($stors[$storeId])) { - $connection->update( - $this->getMainTable(), - $data, - $connection->quoteInto('key_id=?', $stors[$storeId])); - } - else { - $connection->insert($this->getMainTable(), $data); - } - } - } - } - return parent::_afterSave($object); - } - - /** - * Delete translates - * - * @param string $string - * @param string $locale - * @param int|null $storeId - * - * @return Mage_Core_Model_Mysql4_Translate_String - */ - public function deleteTranslate($string, $locale = null, $storeId = null) - { - if (is_null($locale)) { - $locale = Mage::app()->getLocale()->getLocaleCode(); - } - - $where = array( - $this->_getWriteAdapter()->quoteInto('locale=?', $locale), - $this->_getWriteAdapter()->quoteInto('string=?', $string), - ); - - if ($storeId === false) { - $where[] = $this->_getWriteAdapter()->quoteInto('store_id>?', 0); - } - elseif (!is_null($storeId)) { - $where[] = $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId); - } - - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - - return $this; - } - - public function saveTranslate($string, $translate, $locale=null, $storeId=null) - { - $write = $this->_getWriteAdapter(); - $table = $this->getMainTable(); - - if (is_null($locale)) { - $locale = Mage::app()->getLocale()->getLocaleCode(); - } - - if (is_null($storeId)) { - $storeId = Mage::app()->getStore()->getId(); - } - - $select = $write->select() - ->from($table, array('key_id', 'translate')) - ->where('store_id=?', $storeId) - ->where('locale=?', $locale) - ->where('string=?', $string) - ; - if ($row = $write->fetchRow($select)) { - $original = $string; - if (strpos($original, '::')!==false) { - list($scope, $original) = explode('::', $original); - } - if ($original == $translate) { - $write->delete($table, 'key_id='.(int)$row['key_id']); - } elseif ($row['translate']!=$translate) { - $write->update($table, array('translate'=>$translate), 'key_id='.(int)$row['key_id']); - } - } else { - $write->insert($table, array( - 'store_id'=>$storeId, - 'locale'=>$locale, - 'string'=>$string, - 'translate'=>$translate, - )); - } - - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php index 1deb50e985..fa5962405d 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,139 +28,10 @@ /** * Url rewrite resource model class * - * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Url_Rewrite extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Url_Rewrite extends Mage_Core_Model_Resource_Url_Rewrite { - protected $_tagTable; - - protected function _construct() - { - $this->_init('core/url_rewrite', 'url_rewrite_id'); - $this->_tagTable = $this->getTable('url_rewrite_tag'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array( - array( - 'field' => array('id_path','store_id','is_system'), - 'title' => Mage::helper('core')->__('ID Path for Specified Store') - ), - array( - 'field' => array('request_path','store_id'), - 'title' => Mage::helper('core')->__('Request Path for Specified Store'), - ) - ); - return $this; - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - /* @var $select Varien_Db_Select */ - $select = parent::_getLoadSelect($field, $value, $object); - - if (!is_null($object->getStoreId())) { - $select->where('store_id IN(?)', array(0, $object->getStoreId())); - $select->order('store_id desc'); - $select->limit(1); - } - - return $select; - } - - /** - * Retrieve request_path using id_path and current store's id. - * - * @param string $idPath - * @param int|Mage_Core_Model_Store $store - * @return string|false - */ - public function getRequestPathByIdPath($idPath, $store) - { - if ($store instanceof Mage_Core_Model_Store) { - $storeId = (int)$store->getId(); - } else { - $storeId = (int)$store; - } - - $select = $this->_getReadAdapter()->select(); - /* @var $select Zend_Db_Select */ - $select->from(array('main_table' => $this->getMainTable()), 'request_path') - ->where('main_table.store_id = ?', $storeId) - ->where('main_table.id_path = ?', $idPath) - ->limit(1); - - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Load rewrite information for request - * If $path is array - we must load all possible records and choose one matching earlier record in array - * - * @param Mage_Core_Model_Url_Rewrite $object - * @param array|string $path - * @return Mage_Core_Model_Mysql4_Url_Rewrite - */ - public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path) - { - if (!is_array($path)) { - $path = array($path); - } - - $pathBind = array(); - foreach ($path as $key => $url) { - $pathBind['path'.$key] = $url; - } - // Form select - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from($this->getMainTable()) - ->where($this->getMainTable() . '.request_path IN (:' . implode(', :', array_flip($pathBind)) . ')') - ->where('store_id IN(?)', array(0, (int)$object->getStoreId())); - - $items = $read->fetchAll($select, $pathBind); - - // Go through all found records and choose one with lowest penalty - earlier path in array, concrete store - $mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better - $currentPenalty = null; - $foundItem = null; - foreach ($items as $item) { - $penalty = $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1); - if (!$foundItem || $currentPenalty > $penalty) { - $foundItem = $item; - $currentPenalty = $penalty; - if (!$currentPenalty) { - break; // Found best matching item with zero penalty, no reason to continue - } - } - } - - // Set data and finish loading - if ($foundItem) { - $object->setData($foundItem); - } - - // Finish - $this->unserializeFields($object); - $this->_afterLoad($object); - - return $this; - } - } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite/Collection.php index e864d649b8..edb917e105 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,74 +28,10 @@ /** * Url rewrite resource collection model class * - * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Url_Rewrite_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Url_Rewrite_Collection extends Mage_Core_Model_Resource_Url_Rewrite_Collection { - protected function _construct() - { - $this->_init('core/url_rewrite'); - } - - /** - * Add filter for tags (combined by OR) - */ - public function addTagsFilter($tags) - { - $tagsArr = is_array($tags) ? $tags : explode(',', $tags); - - $sqlArr = array(); - foreach ($tagsArr as $t) { - $sqlArr[] = $this->getConnection()->quoteInto("find_in_set(?, `tags`)", $t); - } - - $cond = $this->getConnection()->quoteInto('`url_rewrite_id`=main_table.`url_rewrite_id` and `tag` in (?)', $tagsArr); - $this->getSelect()->join($this->getTable('url_rewrite_tag'), $cond, array()); - return $this; - } - - /** - * Filter collections by stores - * - * @param mixed $store - * @param bool $withAdmin - * @return Mage_Core_Model_Mysql4_Url_Rewrite_Collection - */ - public function addStoreFilter($store, $withAdmin = true) - { - if (is_array($store) || is_numeric($store)) { - if (!is_array($store)) { - $store = array($store); - } - } - else { - $store = Mage::helper('core')->getStoreId($store); - } - if ($withAdmin) { - $this->getSelect()->where('store_id = 0 OR store_id IN (?)', $store); - } - else { - $this->getSelect()->where('store_id IN (?)', $store); - } - return $this; - } - - public function filterAllByProductId($productId) - { - $this->getSelect() - ->where('id_path = ?', "product/{$productId}") - ->orWhere('id_path like ?', "product/{$productId}/%"); - - return $this; - } - - public function filterAllByCategory() - { - $this->getSelect() - ->where('id_path like ?', "category%"); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Variable.php b/app/code/core/Mage/Core/Model/Mysql4/Variable.php index 063e40104d..a660f0c733 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Variable.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Variable.php @@ -20,126 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Custom variable resource model * - * @category Mage - * @package Mage_Core - * @author Magento Core Team + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Variable extends Mage_Core_Model_Mysql4_Abstract +class Mage_Core_Model_Mysql4_Variable extends Mage_Core_Model_Resource_Variable { - /** - * Constructor - */ - protected function _construct() - { - $this->_init('core/variable', 'variable_id'); - } - - /** - * Load variable by code - * - * @param Mage_Core_Model_Variable $object - * @param string $code - * @return Mage_Core_Model_Mysql4_Variable - */ - public function loadByCode(Mage_Core_Model_Variable $object, $code) - { - if ($result = $this->getVariableByCode($code, true, $object->getStoreId())) { - $object->setData($result); - } - return $this; - } - - /** - * Retrieve variable data by code - * - * @param string $code - * @param boolean $withValue - * @param integer $storeId - * @return array - */ - public function getVariableByCode($code, $withValue = false, $storeId = 0) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where($this->getMainTable().'.code = ?', $code); - if ($withValue) { - $this->_addValueToSelect($select, $storeId); - } - return $this->_getReadAdapter()->fetchRow($select); - } - - /** - * Perform actions after object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Variable - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - parent::_afterSave($object); - if ($object->getUseDefaultValue()) { - /* - * remove store value - */ - $this->_getWriteAdapter()->delete( - $this->getTable('core/variable_value'), array( - 'variable_id = ?' => $object->getId(), - 'store_id = ?' => $object->getStoreId() - )); - } else { - $this->_getWriteAdapter()->insertOnDuplicate( - $this->getTable('core/variable_value'), array( - 'variable_id' => $object->getId(), - 'store_id' => $object->getStoreId(), - 'plain_value' => $object->getPlainValue(), - 'html_value' => $object->getHtmlValue() - ), array('plain_value', 'html_value')); - } - return $this; - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @param Mage_Core_Model_Abstract $object - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $this->_addValueToSelect($select, $object->getStoreId()); - return $select; - } - - /** - * Add variable store and default value to select - * - * @param Zend_Db_Select $select - * @param integer $storeId - * @return Mage_Core_Model_Mysql4_Variable - */ - protected function _addValueToSelect(Zend_Db_Select $select, $storeId = 0) - { - $select->joinLeft( - array('default' => $this->getTable('core/variable_value')), - 'default.variable_id = '.$this->getMainTable().'.variable_id AND default.store_id = 0', - array()) - ->joinLeft( - array('store' => $this->getTable('core/variable_value')), - 'store.variable_id = default.variable_id AND store.store_id = ' . $storeId, - array()) - ->columns(array('plain_value' => new Zend_Db_Expr('IFNULL(store.plain_value, default.plain_value)'), - 'html_value' => new Zend_Db_Expr('IFNULL(store.html_value, default.html_value)'), - 'store_plain_value' => 'store.plain_value', 'store_html_value' => 'store.html_value')); - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Variable/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Variable/Collection.php index a2accb4856..fa23931078 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Variable/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Variable/Collection.php @@ -20,76 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Custom variabel collection * - * @category Mage - * @package Mage_Core - * @author Magento Core Team + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Variable_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Variable_Collection extends Mage_Core_Model_Resource_Variable_Collection { - protected $_storeId = 0; - - /** - * Constructor - */ - protected function _construct() - { - parent::_construct(); - $this->_init('core/variable'); - } - - /** - * Setter - * - * @param integer $storeId - * @return Mage_Core_Model_Mysql4_Variable_Collection - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Getter - * - * @return integer - */ - public function getStoreId() - { - return $this->_storeId; - } - - /** - * Add store values to result - * - * @return Mage_Core_Model_Mysql4_Variable_Collection - */ - public function addValuesToResult() - { - $this->getSelect() - ->join( - array('value_table' => $this->getTable('core/variable_value')), - $this->getConnection()->quoteInto('value_table.variable_id = main_table.variable_id AND store_id = ?', $this->getStoreId()), - array()) - ->columns(array('value' => 'value_table.value')); - return $this; - } - - /** - * Retrieve option array - * - * @return array - */ - public function toOptionArray() - { - return $this->_toOptionArray('code', 'name'); - } - } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Website.php b/app/code/core/Mage/Core/Model/Mysql4/Website.php index c4508592a4..af3819ee97 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Website.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Website.php @@ -20,99 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Core_Model_Mysql4_Website extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team + */ +class Mage_Core_Model_Mysql4_Website extends Mage_Core_Model_Resource_Website { - protected function _construct() - { - $this->_init('core/website', 'website_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'code', - 'title' => Mage::helper('core')->__('Website with the same code') - )); - return $this; - } - - /** - * Perform actions before object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Website - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if(!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) { - Mage::throwException(Mage::helper('core')->__('Website code may only contain letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter')); - } - - return parent::_beforeSave($object); - } - - /** - * Perform actions after object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Website - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->getIsDefault()) { - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('is_default' => 0), - 1 - ); - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('is_default' => 1), - $this->_getWriteAdapter()->quoteInto('website_id=?', $object->getId()) - ); - } - return parent::_afterSave($object); - } - - protected function _afterDelete(Mage_Core_Model_Abstract $model) - { - $this->_getWriteAdapter()->delete( - $this->getTable('core/config_data'), - $this->_getWriteAdapter()->quoteInto("scope = 'websites' AND scope_id = ?", $model->getWebsiteId()) - ); - return $this; - } - - /** - * Retrieve default stores select object - * Select fields website_id, store_id - * - * @param $withDefault include/exclude default admin website - * @return Varien_Db_Select - */ - public function getDefaultStoresSelect($withDefault = false) { - $select = $this->_getReadAdapter()->select() - ->from(array('website_table' => $this->getTable('core/website')), array('website_id')) - ->joinLeft( - array('store_group_table' => $this->getTable('core/store_group')), - '`website_table`.`website_id`=`store_group_table`.`website_id`' - . ' AND `website_table`.`default_group_id`=`store_group_table`.`group_id`', - array('store_id' => 'IFNULL(`store_group_table`.`default_store_id`, 0)') - ); - if (!$withDefault) { - $select->where('`website_table`.`website_id` <> ?', 0); - } - return $select; - } - } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php b/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php index f8d717ec1a..4080007d7f 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php +++ b/app/code/core/Mage/Core/Model/Mysql4/Website/Collection.php @@ -20,121 +20,18 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Websites collection * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Website_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Mysql4_Website_Collection extends Mage_Core_Model_Resource_Website_Collection { - protected $_loadDefault = false; - - protected $_map = array('fields' => array('website_id' => 'main_table.website_id')); - - protected function _construct() - { - $this->_init('core/website'); - } - - public function addIdFilter($ids) - { - if (is_array($ids)) { - if (empty($ids)) { - $this->addFieldToFilter('website_id', null); - } - else { - $this->addFieldToFilter('website_id', array('in'=>$ids)); - } - } - else { - $this->addFieldToFilter('website_id', $ids); - } - return $this; - } - - public function setLoadDefault($loadDefault) - { - $this->_loadDefault = $loadDefault; - return $this; - } - - public function getLoadDefault() - { - return $this->_loadDefault; - } - - public function toOptionArray() - { - return $this->_toOptionArray('website_id', 'name'); - } - - public function toOptionHash() - { - return $this->_toOptionHash('website_id', 'name'); - } - - public function load($printQuery = false, $logQuery = false) - { - if (!$this->getLoadDefault()) { - $this->getSelect()->where($this->getConnection()->quoteInto('main_table.website_id>?', 0)); - } - $this->unshiftOrder('main_table.name', 'ASC') // website name SECOND - ->unshiftOrder('main_table.sort_order', 'ASC') // website sort order FIRST - ; - parent::load($printQuery, $logQuery); - return $this; - } - - /** - * Join group and store info from appropriate tables. - * Defines new _idFiledName as 'website_group_store' bc for - * one website can be more then one row in collection. - * Sets extra combined ordering by group's name, defined - * sort ordering and store's name. - * - * @return Mage_Core_Model_Mysql4_Website_Collection - */ - public function joinGroupAndStore() - { - if (!$this->getFlag('groups_and_stores_joined')) { - $this->_idFieldName = 'website_group_store'; - $this->getSelect()->joinLeft( - array('group_table' => $this->getTable('core/store_group')), - 'main_table.website_id=group_table.website_id', - array('group_id'=>'group_id', 'group_title'=>'name') - )->joinLeft( - array('store_table' => $this->getTable('core/store')), - 'group_table.group_id=store_table.group_id', - array('store_id'=>'store_id', 'store_title'=>'name') - ); - $this->addOrder('group_table.name', 'ASC') // store name - ->addOrder('CASE WHEN store_table.store_id = 0 THEN 0 ELSE 1 END', 'ASC') // view is admin - ->addOrder('store_table.sort_order', 'ASC') // view sort order - ->addOrder('store_table.name', 'ASC') // view name - ; - $this->setFlag('groups_and_stores_joined', true); - } - return $this; - } - - /** - * Adding filter by group id or array of ids but only if - * tables with appropriate information were joined before. - * - * @param int|array $groupIds - * @return Mage_Core_Model_Mysql4_Website_Collection - */ - public function addFilterByGroupIds($groupIds) - { - if ($this->getFlag('groups_and_stores_joined')) { - $this->addFieldToFilter('group_table.group_id', $groupIds); - } - return $this; - } } diff --git a/app/code/core/Mage/Core/Model/Observer.php b/app/code/core/Mage/Core/Model/Observer.php index a35deb5bcc..aaad029c07 100644 --- a/app/code/core/Mage/Core/Model/Observer.php +++ b/app/code/core/Mage/Core/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Resource.php b/app/code/core/Mage/Core/Model/Resource.php index 1bcddf1ca2..06bd75861e 100644 --- a/app/code/core/Mage/Core/Model/Resource.php +++ b/app/code/core/Mage/Core/Model/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,43 +31,48 @@ */ class Mage_Core_Model_Resource { + const AUTO_UPDATE_CACHE_KEY = 'DB_AUTOUPDATE'; + const AUTO_UPDATE_ONCE = 0; + const AUTO_UPDATE_NEVER = -1; + const AUTO_UPDATE_ALWAYS = 1; - const AUTO_UPDATE_CACHE_KEY = 'DB_AUTOUPDATE'; - const AUTO_UPDATE_ONCE = 0; - const AUTO_UPDATE_NEVER = -1; - const AUTO_UPDATE_ALWAYS = 1; - - const DEFAULT_READ_RESOURCE = 'core_read'; - const DEFAULT_WRITE_RESOURCE= 'core_write'; + const DEFAULT_READ_RESOURCE = 'core_read'; + const DEFAULT_WRITE_RESOURCE = 'core_write'; + const DEFAULT_SETUP_RESOURCE = 'core_setup'; /** * Instances of classes for connection types * * @var array */ - protected $_connectionTypes = array(); + protected $_connectionTypes = array(); /** * Instances of actual connections * * @var array */ - protected $_connections = array(); + protected $_connections = array(); /** * Registry of resource entities * * @var array */ - protected $_entities = array(); + protected $_entities = array(); + /** + * Mapped tables cache array + * + * @var array + */ protected $_mappedTableNames; /** * Creates a connection to resource whenever needed * * @param string $name - * @return mixed + * @return Varien_Db_Adapter_Interface */ public function getConnection($name) { @@ -75,6 +80,7 @@ public function getConnection($name) return $this->_connections[$name]; } $connConfig = Mage::getConfig()->getResourceConnectionConfig($name); + if (!$connConfig) { $this->_connections[$name] = $this->_getDefaultConnection($name); return $this->_connections[$name]; @@ -82,26 +88,92 @@ public function getConnection($name) if (!$connConfig->is('active', 1)) { return false; } - $origName = $connConfig->getParent()->getName(); + $origName = $connConfig->getParent()->getName(); if (isset($this->_connections[$origName])) { $this->_connections[$name] = $this->_connections[$origName]; return $this->_connections[$origName]; } - $typeInstance = $this->getConnectionTypeInstance((string)$connConfig->type); - $conn = $typeInstance->getConnection($connConfig); - if (method_exists($conn, 'setCacheAdapter')) { - $conn->setCacheAdapter(Mage::app()->getCache()); + $connection = $this->_newConnection((string)$connConfig->type, $connConfig); + if ($connection) { + $connection->setCacheAdapter(Mage::app()->getCache()); + } + + $this->_connections[$name] = $connection; + if ($origName !== $name) { + $this->_connections[$origName] = $connection; + } + return $connection; + } + /** + * Retrieve connection adapter class name by connection type + * + * @param string $type the connection type + * @return string|false + */ + protected function _getConnectionAdapterClassName($type) + { + $config = Mage::getConfig()->getResourceTypeConfig($type); + if (!empty($config->adapter)) { + return (string)$config->adapter; + } + return false; + } + + /** + * Create new connection adapter instance by connection type and config + * + * @param string $type the connection type + * @param Mage_Core_Model_Config_Element|array $config the connection configuration + * @return Varien_Db_Adapter_Interface|false + */ + protected function _newConnection($type, $config) + { + if ($config instanceof Mage_Core_Model_Config_Element) { + $config = $config->asArray(); + } + if (!is_array($config)) { + return false; } - $this->_connections[$name] = $conn; - if ($origName!==$name) { - $this->_connections[$origName] = $conn; + $connection = false; + // try to get adapter and create connection + $className = $this->_getConnectionAdapterClassName($type); + if ($className) { + // define profiler settings + $config['profiler'] = isset($config['profiler']) && $config['profiler'] != 'false'; + + $connection = new $className($config); + if ($connection instanceof Varien_Db_Adapter_Interface) { + // run after initialization statements + if (!empty($config['initStatements'])) { + $connection->query($config['initStatements']); + } + } else { + $connection = false; + } + } + + // try to get connection from type + if (!$connection) { + $typeInstance = $this->getConnectionTypeInstance($type); + $connection = $typeInstance->getConnection($config); + if (!$connection instanceof Varien_Db_Adapter_Interface) { + $connection = false; + } } - return $conn; + + return $connection; + } + /** + * Retrieve default connection name by required connection name + * + * @param string $requiredConnectionName + * @return string + */ protected function _getDefaultConnection($requiredConnectionName) { if (strpos($requiredConnectionName, 'read') !== false) { @@ -131,40 +203,70 @@ public function getConnectionTypeInstance($type) /** * Get resource entity * - * @param string $resource + * @param string $model * @param string $entity * @return Varien_Simplexml_Config */ public function getEntity($model, $entity) { - //return Mage::getConfig()->getNode("global/models/$model/entities/$entity"); - return Mage::getConfig()->getNode()->global->models->{$model}->entities->{$entity}; + $modelsNode = Mage::getConfig()->getNode()->global->models; + $entityConfig = $modelsNode->$model->entities->{$entity}; + + /** + * Backwards compatibility for pre-MMDB extensions. + * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So is left + * to keep name of previously used nodes, that still may be used by non-updated extensions. + */ + if (isset($modelsNode->$model->deprecatedNode)) { + $deprecatedNode = $modelsNode->$model->deprecatedNode; + if (isset($modelsNode->$deprecatedNode->entities->$entity)) { + $entityConfig = $modelsNode->$deprecatedNode->entities->$entity; + } + } + + return $entityConfig; } /** - * Get resource table name + * Get resource table name, validated by db adapter * - * @param string $modelEntity + * @param string|array $modelEntity * @return string */ public function getTableName($modelEntity) { - $arr = explode('/', $modelEntity); - if (isset($arr[1])) { - list($model, $entity) = $arr; - //$resourceModel = (string)Mage::getConfig()->getNode('global/models/'.$model.'/resourceModel'); - $resourceModel = (string) Mage::getConfig()->getNode()->global->models->{$model}->resourceModel; - $entityConfig = $this->getEntity($resourceModel, $entity); - if ($entityConfig) { + $tableSuffix = null; + if (is_array($modelEntity)) { + list($modelEntity, $tableSuffix) = $modelEntity; + } + + $parts = explode('/', $modelEntity); + if (isset($parts[1])) { + list($model, $entity) = $parts; + $entityConfig = false; + if (!empty(Mage::getConfig()->getNode()->global->models->{$model}->resourceModel)) { + $resourceModel = (string)Mage::getConfig()->getNode()->global->models->{$model}->resourceModel; + $entityConfig = $this->getEntity($resourceModel, $entity); + } + + if ($entityConfig && !empty($entityConfig->table)) { + $tableName = (string)$entityConfig->table; } else { - Mage::throwException(Mage::helper('core')->__('Cannot retrieve entity config: %s', $modelEntity)); + Mage::throwException(Mage::helper('core')->__('Can\'t retrieve entity config: %s', $modelEntity)); } } else { $tableName = $modelEntity; } - Mage::dispatchEvent('resource_get_tablename', array('resource' => $this, 'model_entity' => $modelEntity, 'table_name' => $tableName)); + Mage::dispatchEvent('resource_get_tablename', array( + 'resource' => $this, + 'model_entity' => $modelEntity, + 'table_name' => $tableName, + 'table_suffix' => $tableSuffix + )); + + $mappedTableName = $this->getMappedTableName($tableName); if ($mappedTableName) { $tableName = $mappedTableName; @@ -173,7 +275,12 @@ public function getTableName($modelEntity) $tableName = $tablePrefix . $tableName; } - return $tableName; + if (!is_null($tableSuffix)) { + $tableName .= '_' . $tableSuffix; + } + + return $this->getConnection(self::DEFAULT_READ_RESOURCE)->getTableName($tableName); + } public function setMappedTableName($tableName, $mappedName) @@ -203,11 +310,20 @@ public function cleanDbRow(&$row) return $this; } + /** + * Create new connection with custom config + * + * @param string $name + * @param string $type + * @param array $config + * @return unknown + */ public function createConnection($name, $type, $config) { if (!isset($this->_connections[$name])) { - $typeObj = $this->getConnectionTypeInstance($type); - $this->_connections[$name] = $typeObj->getConnection($config); + $connection = $this->_newConnection($type, $config); + + $this->_connections[$name] = $connection; } return $this->_connections[$name]; } @@ -230,5 +346,33 @@ public function setAutoUpdate($value) #Mage::app()->saveCache($value, self::AUTO_UPDATE_CACHE_KEY); return $this; } + /** + * Retrieve 32bit UNIQUE HASH for a Table index + * + * @param string $tableName + * @param array|string $fields + * @param string $indexType + * @return string + */ + public function getIdxName($tableName, $fields, $indexType = Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX) + { + return $this->getConnection(self::DEFAULT_READ_RESOURCE) + ->getIndexName($this->getTableName($tableName), $fields, $indexType); + } + /** + * Retrieve 32bit UNIQUE HASH for a Table foreign key + * + * @param string $priTableName the target table name + * @param string $priColumnName the target table column name + * @param string $refTableName the reference table name + * @param string $refColumnName the reference table column name + * @return string + */ + public function getFkName($priTableName, $priColumnName, $refTableName, $refColumnName) + { + return $this->getConnection(self::DEFAULT_READ_RESOURCE) + ->getForeignKeyName($this->getTableName($priTableName), $priColumnName, + $this->getTableName($refTableName), $refColumnName); + } } diff --git a/app/code/core/Mage/Core/Model/Resource/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Abstract.php index 4a152f118c..3ca2de8c29 100644 --- a/app/code/core/Mage/Core/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,8 +33,14 @@ */ abstract class Mage_Core_Model_Resource_Abstract { + /** + * Main constructor + */ public function __construct() { + /** + * Please override this one instead of overriding real __construct constructor + */ $this->_construct(); } @@ -122,39 +128,24 @@ public function rollBack() /** * Format date to internal format * - * @param string | Zend_Date $date - * @param bool $includeTime - * @return string + * @param string|Zend_Date $date + * @param bool $includeTime + * @return string */ public function formatDate($date, $includeTime=true) { - if ($date instanceof Zend_Date) { - if ($includeTime) { - return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); - } - else { - return $date->toString(Varien_Date::DATE_INTERNAL_FORMAT); - } - } - - if (empty($date)) { - return new Zend_Db_Expr('NULL'); - } - - if (!is_numeric($date)) { - $date = strtotime($date); - } - if ($includeTime) { - return date('Y-m-d H:i:s', $date); - } - else { - return date('Y-m-d', $date); - } + return Varien_Date::formatDate($date, $includeTime); } + /** + * Convert internal date to UNIX timestamp + * + * @param string $str + * @return int + */ public function mktime($str) { - return strtotime($str); + return Varien_Date::formatDate($str); } /** @@ -164,6 +155,7 @@ public function mktime($str) * @param string $field * @param mixed $defaultValue * @param bool $unsetEmpty + * @return Mage_Core_Model_Resource_Abstract */ protected function _serializeField(Varien_Object $object, $field, $defaultValue = null, $unsetEmpty = false) { @@ -180,6 +172,8 @@ protected function _serializeField(Varien_Object $object, $field, $defaultValue } elseif (is_array($value) || is_object($value)) { $object->setData($field, serialize($value)); } + + return $this; } /** @@ -198,4 +192,49 @@ protected function _unserializeField(Varien_Object $object, $field, $defaultValu $object->setData($field, unserialize($value)); } } + + /** + * Prepare data for passed table + * + * @param Varien_Object $object + * @param string $table + * @return array + */ + protected function _prepareDataForTable(Varien_Object $object, $table) + { + $data = array(); + $fields = $this->_getWriteAdapter()->describeTable($table); + foreach (array_keys($fields) as $field) { + if ($object->hasData($field)) { + $fieldValue = $object->getData($field); + if ($fieldValue instanceof Zend_Db_Expr) { + $data[$field] = $fieldValue; + } else { + if (null !== $fieldValue) { + $fieldValue = $this->_prepareTableValueForSave($fieldValue, $fields[$field]['DATA_TYPE']); + $data[$field] = $this->_getWriteAdapter()->prepareColumnValue($fields[$field], $fieldValue); + } else if (!empty($fields[$field]['NULLABLE'])) { + $data[$field] = null; + } + } + } + } + return $data; + } + + /** + * Prepare value for save + * + * @param mixed $value + * @param string $type + * @return mixed + */ + protected function _prepareTableValueForSave($value, $type) + { + $type = strtolower($type); + if ($type == 'decimal' || $type == 'numeric' || $type == 'float') { + $value = Mage::app()->getLocale()->getNumber($value); + } + return $value; + } } diff --git a/app/code/core/Mage/Core/Model/Resource/Cache.php b/app/code/core/Mage/Core/Model/Resource/Cache.php new file mode 100644 index 0000000000..0ac3e8c4a9 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Cache.php @@ -0,0 +1,100 @@ + + */ +class Mage_Core_Model_Resource_Cache extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/cache_option', 'code'); + } + + /** + * Get all cache options + * + * @return array | false + */ + public function getAllOptions() + { + $adapter = $this->_getReadAdapter(); + if ($adapter) { + /** + * Check if table exist (it protect upgrades. cache settings checked before upgrades) + */ + if ($adapter->isTableExists($this->getMainTable())) { + $select = $adapter->select() + ->from($this->getMainTable(), array('code', 'value')); + return $adapter->fetchPairs($select); + } + } + return false; + } + + /** + * Save all options to option table + * + * @param array $options + * @return Mage_Core_Model_Resource_Cache + * @throws Exception + */ + public function saveAllOptions($options) + { + $adapter = $this->_getWriteAdapter(); + if (!$adapter) { + return $this; + } + + $data = array(); + foreach ($options as $code => $value) { + $data[] = array($code, $value); + } + + $adapter->beginTransaction(); + try { + $this->_getWriteAdapter()->delete($this->getMainTable()); + if ($data) { + $this->_getWriteAdapter()->insertArray($this->getMainTable(), array('code', 'value'), $data); + } + } catch (Exception $e) { + $adapter->rollback(); + throw $e; + } + $adapter->commit(); + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Config.php b/app/code/core/Mage/Core/Model/Resource/Config.php new file mode 100644 index 0000000000..60fb918b63 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Config.php @@ -0,0 +1,228 @@ + + */ +class Mage_Core_Model_Resource_Config extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/config_data', 'config_id'); + } + + /** + * Load configuration values into xml config object + * + * @param Mage_Core_Model_Config $xmlConfig + * @param string $condition + * @return Mage_Core_Model_Resource_Config + */ + public function loadToXml(Mage_Core_Model_Config $xmlConfig, $condition = null) + { + $read = $this->_getReadAdapter(); + if (!$read) { + return $this; + } + + $websites = array(); + $select = $read->select() + ->from($this->getTable('core/website'), array('website_id', 'code', 'name')); + $rowset = $read->fetchAssoc($select); + foreach ($rowset as $w) { + $xmlConfig->setNode('websites/'.$w['code'].'/system/website/id', $w['website_id']); + $xmlConfig->setNode('websites/'.$w['code'].'/system/website/name', $w['name']); + $websites[$w['website_id']] = array('code' => $w['code']); + } + + $stores = array(); + $select = $read->select() + ->from($this->getTable('core/store'), array('store_id', 'code', 'name', 'website_id')) + ->order('sort_order ' . Varien_Db_Select::SQL_ASC); + $rowset = $read->fetchAssoc($select); + foreach ($rowset as $s) { + if (!isset($websites[$s['website_id']])) { + continue; + } + $xmlConfig->setNode('stores/'.$s['code'].'/system/store/id', $s['store_id']); + $xmlConfig->setNode('stores/'.$s['code'].'/system/store/name', $s['name']); + $xmlConfig->setNode('stores/'.$s['code'].'/system/website/id', $s['website_id']); + $xmlConfig->setNode('websites/'.$websites[$s['website_id']]['code'].'/system/stores/'.$s['code'], $s['store_id']); + $stores[$s['store_id']] = array('code'=>$s['code']); + $websites[$s['website_id']]['stores'][$s['store_id']] = $s['code']; + } + + $substFrom = array(); + $substTo = array(); + + // load all configuration records from database, which are not inherited + $select = $read->select() + ->from($this->getMainTable(), array('scope', 'scope_id', 'path', 'value')); + if (!is_null($condition)) { + $select->where($condition); + } + $rowset = $read->fetchAll($select); + + + // set default config values from database + foreach ($rowset as $r) { + if ($r['scope'] !== 'default') { + continue; + } + $value = str_replace($substFrom, $substTo, $r['value']); + $xmlConfig->setNode('default/' . $r['path'], $value); + } + + // inherit default config values to all websites + $extendSource = $xmlConfig->getNode('default'); + foreach ($websites as $id=>$w) { + $websiteNode = $xmlConfig->getNode('websites/' . $w['code']); + $websiteNode->extend($extendSource); + } + + $deleteWebsites = array(); + // set websites config values from database + foreach ($rowset as $r) { + if ($r['scope'] !== 'websites') { + continue; + } + $value = str_replace($substFrom, $substTo, $r['value']); + if (isset($websites[$r['scope_id']])) { + $nodePath = sprintf('websites/%s/%s', $websites[$r['scope_id']]['code'], $r['path']); + $xmlConfig->setNode($nodePath, $value); + } else { + $deleteWebsites[$r['scope_id']] = $r['scope_id']; + } + } + + // extend website config values to all associated stores + foreach ($websites as $website) { + $extendSource = $xmlConfig->getNode('websites/' . $website['code']); + if (isset($website['stores'])) { + foreach ($website['stores'] as $sCode) { + $storeNode = $xmlConfig->getNode('stores/'.$sCode); + /** + * $extendSource DO NOT need overwrite source + */ + $storeNode->extend($extendSource, false); + } + } + } + + $deleteStores = array(); + // set stores config values from database + foreach ($rowset as $r) { + if ($r['scope'] !== 'stores') { + continue; + } + $value = str_replace($substFrom, $substTo, $r['value']); + if (isset($stores[$r['scope_id']])) { + $nodePath = sprintf('stores/%s/%s', $stores[$r['scope_id']]['code'], $r['path']); + $xmlConfig->setNode($nodePath, $value); + } else { + $deleteStores[$r['scope_id']] = $r['scope_id']; + } + } + + if ($deleteWebsites) { + $this->_getWriteAdapter()->delete($this->getMainTable(), array( + 'scope = ?' => 'websites', + 'scope_id IN(?)' => $deleteWebsites, + )); + } + + if ($deleteStores) { + $this->_getWriteAdapter()->delete($this->getMainTable(), array( + 'scope=?' => 'stores', + 'scope_id IN(?)' => $deleteStores, + )); + } + return $this; + } + + /** + * Save config value + * + * @param string $path + * @param string $value + * @param string $scope + * @param int $scopeId + * @return Mage_Core_Model_Resource_Config + */ + public function saveConfig($path, $value, $scope, $scopeId) + { + $writeAdapter = $this->_getWriteAdapter(); + $select = $writeAdapter->select() + ->from($this->getMainTable()) + ->where('path = ?', $path) + ->where('scope = ?', $scope) + ->where('scope_id = ?', $scopeId); + $row = $writeAdapter->fetchRow($select); + + $newData = array( + 'scope' => $scope, + 'scope_id' => $scopeId, + 'path' => $path, + 'value' => $value + ); + + if ($row) { + $whereCondition = array($this->getIdFieldName() . '=?' => $row[$this->getIdFieldName()]); + $writeAdapter->update($this->getMainTable(), $newData, $whereCondition); + } else { + $writeAdapter->insert($this->getMainTable(), $newData); + } + return $this; + } + + /** + * Delete config value + * + * @param string $path + * @param string $scope + * @param int $scopeId + * @return Mage_Core_Model_Resource_Config + */ + public function deleteConfig($path, $scope, $scopeId) + { + $adapter = $this->_getWriteAdapter(); + $adapter->delete($this->getMainTable(), array( + $adapter->quoteInto('path = ?', $path), + $adapter->quoteInto('scope = ?', $scope), + $adapter->quoteInto('scope_id = ?', $scopeId) + )); + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Config/Data.php b/app/code/core/Mage/Core/Model/Resource/Config/Data.php new file mode 100644 index 0000000000..93bb3b5ac7 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Config/Data.php @@ -0,0 +1,91 @@ + + */ +class Mage_Core_Model_Resource_Config_Data extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/config_data', 'config_id'); + } + + /** + * Convert array to comma separated value + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Config_Data + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getId()) { + $this->_checkUnique($object); + } + + if (is_array($object->getValue())) { + $object->setValue(join(',', $object->getValue())); + } + return parent::_beforeSave($object); + } + + /** + * Validate unique configuration data before save + * Set id to object if exists configuration instead of throw exception + * + * @param Mage_Core_Model_Config_Data $object + * @return Mage_Core_Model_Resource_Config_Data + */ + protected function _checkUnique(Mage_Core_Model_Abstract $object) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array($this->getIdFieldName())) + ->where('scope = :scope') + ->where('scope_id = :scope_id') + ->where('path = :path'); + $bind = array( + 'scope' => $object->getScope(), + 'scope_id' => $object->getScopeId(), + 'path' => $object->getPath() + ); + + $configId = $this->_getReadAdapter()->fetchOne($select, $bind); + if ($configId) { + $object->setId($configId); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Config/Data/Collection.php b/app/code/core/Mage/Core/Model/Resource/Config/Data/Collection.php new file mode 100644 index 0000000000..83c2136308 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Config/Data/Collection.php @@ -0,0 +1,85 @@ + + */ +class Mage_Core_Model_Resource_Config_Data_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('core/config_data'); + } + + /** + * Add scope filter to collection + * + * @param string $scope + * @param int $scopeId + * @param string $section + * @return Mage_Core_Model_Resource_Config_Data_Collection + */ + public function addScopeFilter($scope, $scopeId, $section) + { + $this->addFieldToFilter('scope', $scope); + $this->addFieldToFilter('scope_id', $scopeId); + $this->addFieldToFilter('path', array('like' => $section . '/%')); + return $this; + } + + /** + * Add path filter + * + * @param string $section + * @return Mage_Core_Model_Resource_Config_Data_Collection + */ + public function addPathFilter($section) + { + $this->addFieldToFilter('path', array('like' => $section . '/%')); + return $this; + } + + /** + * Add value filter + * + * @param int|string $value + * @return Mage_Core_Model_Resource_Config_Data_Collection + */ + public function addValueFilter($value) + { + $this->addFieldToFilter('value', array('like' => $value)); + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php new file mode 100644 index 0000000000..fd76ed8b04 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php @@ -0,0 +1,770 @@ + + */ +abstract class Mage_Core_Model_Resource_Db_Abstract extends Mage_Core_Model_Resource_Abstract +{ + /** + * @deprecated since 1.5.0.0 + */ + const CHECKSUM_KEY_NAME= 'Checksum'; + + /** + * Cached resources singleton + * + * @var Mage_Core_Model_Resource + */ + protected $_resources; + + /** + * Prefix for resources that will be used in this resource model + * + * @var string + */ + protected $_resourcePrefix; + + /** + * Connections cache for this resource model + * + * @var array + */ + protected $_connections = array(); + + /** + * Resource model name that contains entities (names of tables) + * + * @var string + */ + protected $_resourceModel; + + /** + * Tables used in this resource model + * + * @var array + */ + protected $_tables = array(); + + /** + * Main table name + * + * @var string + */ + protected $_mainTable; + + /** + * Main table primary key field name + * + * @var string + */ + protected $_idFieldName; + + /** + * Primery key auto increment flag + * + * @var bool + */ + protected $_isPkAutoIncrement = true; + + /** + * Use is object new method for save of object + * + * @var boolean + */ + protected $_useIsObjectNew = false; + + /** + * Fields List for update in forsedSave + * + * @var array + */ + protected $_fieldsForUpdate = array(); + + /** + * Fields of main table + * + * @var array + */ + protected $_mainTableFields; + + /** + * Main table unique keys field names + * could array( + * array('field' => 'db_field_name1', 'title' => 'Field 1 should be unique') + * array('field' => 'db_field_name2', 'title' => 'Field 2 should be unique') + * array( + * 'field' => array('db_field_name3', 'db_field_name3'), + * 'title' => 'Field 3 and Field 4 combination should be unique' + * ) + * ) + * or string 'my_field_name' - will be autoconverted to + * array( array( 'field' => 'my_field_name', 'title' => 'my_field_name' ) ) + * + * @var array + */ + protected $_uniqueFields = null; + + /** + * Serializable fields declaration + * Structure: array( + * => array( + * , + * , + * // optional parameter + * ), + * ) + * + * @var array + */ + protected $_serializableFields = array(); + + /** + * Standard resource model initialization + * + * @param string $mainTable + * @param string $idFieldName + * @return Mage_Core_Model_Resource_Abstract + */ + protected function _init($mainTable, $idFieldName) + { + $this->_setMainTable($mainTable, $idFieldName); + } + + /** + * Initialize connections and tables for this resource model + * If one or both arguments are string, will be used as prefix + * If $tables is null and $connections is string, $tables will be the same + * + * @param string|array $connections + * @param string|array|null $tables + * @return Mage_Core_Model_Resource_Abstract + */ + protected function _setResource($connections, $tables = null) + { + $this->_resources = Mage::getSingleton('core/resource'); + + if (is_array($connections)) { + foreach ($connections as $k=>$v) { + $this->_connections[$k] = $this->_resources->getConnection($v); + } + } else if (is_string($connections)) { + $this->_resourcePrefix = $connections; + } + + if (is_null($tables) && is_string($connections)) { + $this->_resourceModel = $this->_resourcePrefix; + } else if (is_array($tables)) { + foreach ($tables as $k => $v) { + $this->_tables[$k] = $this->_resources->getTableName($v); + } + } else if (is_string($tables)) { + $this->_resourceModel = $tables; + } + return $this; + } + + /** + * Set main entity table name and primary key field name + * If field name is ommited {table_name}_id will be used + * + * @param string $mainTable + * @param string|null $idFieldName + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _setMainTable($mainTable, $idFieldName = null) + { + $mainTableArr = explode('/', $mainTable); + + if (!empty($mainTableArr[1])) { + if (empty($this->_resourceModel)) { + $this->_setResource($mainTableArr[0]); + } + $this->_setMainTable($mainTableArr[1], $idFieldName); + } else { + $this->_mainTable = $mainTable; + if (is_null($idFieldName)) { + $idFieldName = $mainTable . '_id'; + } + $this->_idFieldName = $idFieldName; + } + + return $this; + } + + /** + * Get primary key field name + * + * @return string + */ + public function getIdFieldName() + { + if (empty($this->_idFieldName)) { + Mage::throwException(Mage::helper('core')->__('Empty identifier field name')); + } + return $this->_idFieldName; + } + + /** + * Returns main table name - extracted from "module/table" style and + * validated by db adapter + * + * @return string + */ + public function getMainTable() + { + if (empty($this->_mainTable)) { + Mage::throwException(Mage::helper('core')->__('Empty main table name')); + } + return $this->getTable($this->_mainTable); + } + + /** + * Get table name for the entity, validated by db adapter + * + * @param string $entityName + * @return string + */ + public function getTable($entityName) + { + if (is_array($entityName)) { + $cacheName = join('@', $entityName); + list($entityName, $entitySuffix) = $entityName; + } else { + $cacheName = $entityName; + $entitySuffix = null; + } + + if (isset($this->_tables[$cacheName])) { + return $this->_tables[$cacheName]; + } + + if (strpos($entityName, '/')) { + if (!is_null($entitySuffix)) { + $modelEntity = array($entityName, $entitySuffix); + } else { + $modelEntity = $entityName; + } + $this->_tables[$cacheName] = $this->_resources->getTableName($modelEntity); + } else if (!empty($this->_resourceModel)) { + $entityName = sprintf('%s/%s', $this->_resourceModel, $entityName); + if (!is_null($entitySuffix)) { + $modelEntity = array($entityName, $entitySuffix); + } else { + $modelEntity = $entityName; + } + $this->_tables[$cacheName] = $this->_resources->getTableName($modelEntity); + } else { + if (!is_null($entitySuffix)) { + $entityName .= '_' . $entitySuffix; + } + $this->_tables[$cacheName] = $entityName; + } + return $this->_tables[$cacheName]; + } + + + /** + * Retrieve table name for the entity separated value + * + * @param string $entityName + * @param string $valueType + * @return string + */ + public function getValueTable($entityName, $valueType) + { + return $this->getTable(array($entityName, $valueType)); + } + + /** + * Get connection by name or type + * + * @param string $connectionName + * @return Zend_Db_Adapter_Abstract + */ + protected function _getConnection($connectionName) + { + if (isset($this->_connections[$connectionName])) { + return $this->_connections[$connectionName]; + } + if (!empty($this->_resourcePrefix)) { + $this->_connections[$connectionName] = $this->_resources->getConnection( + $this->_resourcePrefix . '_' . $connectionName); + } else { + $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName); + } + + return $this->_connections[$connectionName]; + } + + /** + * Retrieve connection for read data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getReadAdapter() + { + return $this->_getConnection('read'); + } + + /** + * Retrieve connection for write data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getWriteAdapter() + { + return $this->_getConnection('write'); + } + + /** + * Temporary resolving collection compatibility + * + * @return Varien_Db_Adapter_Interface + */ + public function getReadConnection() + { + return $this->_getReadAdapter(); + } + + /** + * Load an object + * + * @param Mage_Core_Model_Abstract $object + * @param mixed $value + * @param string $field field to load by (defaults to model id) + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (is_null($field)) { + $field = $this->getIdFieldName(); + } + + $read = $this->_getReadAdapter(); + if ($read && !is_null($value)) { + $select = $this->_getLoadSelect($field, $value, $object); + $data = $read->fetchRow($select); + + if ($data) { + $object->setData($data); + } + } + + $this->unserializeFields($object); + $this->_afterLoad($object); + + return $this; + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $field = $this->_getReadAdapter()->quoteIdentifier(sprintf('%s.%s', $this->getMainTable(), $field)); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where($field . '=?', $value); + return $select; + } + + /** + * Save object object data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function save(Mage_Core_Model_Abstract $object) + { + if ($object->isDeleted()) { + return $this->delete($object); + } + + $this->_serializeFields($object); + $this->_beforeSave($object); + $this->_checkUnique($object); + if (!is_null($object->getId()) && (!$this->_useIsObjectNew || !$object->isObjectNew())) { + $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()); + /** + * Not auto increment primary key support + */ + if ($this->_isPkAutoIncrement) { + $data = $this->_prepareDataForSave($object); + unset($data[$this->getIdFieldName()]); + $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); + } else { + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable(), array($this->getIdFieldName())) + ->where($condition); + if ($this->_getWriteAdapter()->fetchOne($select) !== false) { + $data = $this->_prepareDataForSave($object); + unset($data[$this->getIdFieldName()]); + if (!empty($data)) { + $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); + } + } else { + $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object)); + } + } + } else { + $bind = $this->_prepareDataForSave($object); + if ($this->_isPkAutoIncrement) { + unset($bind[$this->getIdFieldName()]); + } + $this->_getWriteAdapter()->insert($this->getMainTable(), $bind); + + $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable())); + + if ($this->_useIsObjectNew) { + $object->isObjectNew(false); + } + } + + $this->unserializeFields($object); + $this->_afterSave($object); + + return $this; + } + + /** + * Forsed save object data + * forsed update If duplicate unique key data + * + * @deprecated + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function forsedSave(Mage_Core_Model_Abstract $object) + { + $this->_beforeSave($object); + $bind = $this->_prepareDataForSave($object); + $adapter = $this->_getWriteAdapter(); + // update + if (!is_null($object->getId()) && $this->_isPkAutoIncrement) { + unset($bind[$this->getIdFieldName()]); + $condition = $adapter->quoteInto($this->getIdFieldName().'=?', $object->getId()); + $adapter->update($this->getMainTable(), $bind, $condition); + } else { + $adapter->insertOnDuplicate($this->getMainTable(), $bind, $this->_fieldsForUpdate); + $object->setId($adapter->lastInsertId($this->getMainTable())); + } + + $this->_afterSave($object); + + return $this; + } + + /** + * Delete the object + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function delete(Mage_Core_Model_Abstract $object) + { + $this->_beforeDelete($object); + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId()) + ); + $this->_afterDelete($object); + return $this; + } + + /** + * Add unique field restriction + * + * @param array|string $field + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function addUniqueField($field) + { + if (is_null($this->_uniqueFields)) { + $this->_initUniqueFields(); + } + if (is_array($this->_uniqueFields) ) { + $this->_uniqueFields[] = $field; + } + return $this; + } + + /** + * Reset unique fields restrictions + * + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function resetUniqueField() + { + $this->_uniqueFields = array(); + return $this; + } + + /** + * Unserialize serializeable object fields + * + * @param Mage_Core_Model_Abstract $object + */ + public function unserializeFields(Mage_Core_Model_Abstract $object) + { + foreach ($this->_serializableFields as $field => $parameters) { + list($serializeDefault, $unserializeDefault) = $parameters; + $this->_unserializeField($object, $field, $unserializeDefault); + } + } + + /** + * Initialize unique fields + * + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(); + return $this; + } + + /** + * Get configuration of all unique fields + * + * @return array + */ + public function getUniqueFields() + { + if (is_null($this->_uniqueFields)) { + $this->_initUniqueFields(); + } + return $this->_uniqueFields; + } + + /** + * Prepare data for save + * + * @param Mage_Core_Model_Abstract $object + * @return array + */ + protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) + { + return $this->_prepareDataForTable($object, $this->getMainTable()); + } + + /** + * Check that model data fields that can be saved + * has really changed comparing with origData + * + * @param Mage_Core_Model_Abstract $object + * @return boolean + */ + public function hasDataChanged($object) + { + if (!$object->getOrigData()) { + return true; + } + + $fields = $this->_getWriteAdapter()->describeTable($this->getMainTable()); + foreach (array_keys($fields) as $field) { + if ($object->getOrigData($field) != $object->getData($field)) { + return true; + } + } + + return false; + } + + /** + * Prepare value for save + * + * @param mixed $value + * @param string $type + * @return mixed + */ + protected function _prepareValueForSave($value, $type) + { + return $this->_prepareTableValueForSave($value, $type); + } + + /** + * Check for unique values existence + + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + * @throws Mage_Core_Exception + */ + protected function _checkUnique(Mage_Core_Model_Abstract $object) + { + $existent = array(); + $fields = $this->getUniqueFields(); + if (!empty($fields)) { + if (!is_array($fields)) { + $this->_uniqueFields = array( + array( + 'field' => $fields, + 'title' => $fields + )); + } + + $data = new Varien_Object($this->_prepareDataForSave($object)); + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable()); + + foreach ($fields as $unique) { + $select->reset(Zend_Db_Select::WHERE); + + if (is_array($unique['field'])) { + foreach ($unique['field'] as $field) { + $select->where($field.'=?', $data->getData($field)); + } + } else { + $select->where( $unique['field'] . ' = ?', $data->getData($unique['field']) ); + } + + if ($object->getId()) { + $select->where($this->getIdFieldName().' != ?', $object->getId()); + } + + if ( $test = $this->_getWriteAdapter()->fetchRow($select) ) { + $existent[] = $unique['title']; + } + } + } + + if (!empty($existent)) { + if (count($existent) == 1 ) { + $error = Mage::helper('core')->__('%s already exists.', $existent[0]); + } else { + $error = Mage::helper('core')->__('%s already exist.', implode(', ', $existent)); + } + Mage::throwException($error); + } + return $this; + } + + /** + * After load + * + * @param Mage_Core_Model_Abstract $object + */ + public function afterLoad(Mage_Core_Model_Abstract $object) + { + $this->_afterLoad($object); + } + + /** + * Perform actions after object load + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + return $this; + } + + /** + * Perform actions before object save + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + return $this; + } + + /** + * Perform actions after object save + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + return $this; + } + + /** + * Perform actions before object delete + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $object) + { + return $this; + } + + /** + * Perform actions after object delete + * + * @param Varien_Object $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterDelete(Mage_Core_Model_Abstract $object) + { + return $this; + } + + /** + * Serialize serializeable fields of the object + * + * @param Mage_Core_Model_Abstract $object + */ + protected function _serializeFields(Mage_Core_Model_Abstract $object) + { + foreach ($this->_serializableFields as $field => $parameters) { + list($serializeDefault, $unserializeDefault) = $parameters; + $this->_serializeField($object, $field, $serializeDefault, isset($parameters[2])); + } + } + + /** + * Retrieve table checksum + * + * @param string|array $table + * @return int|array + */ + public function getChecksum($table) + { + if (!$this->_getReadAdapter()) { + return false; + } + $checksum = $this->_getReadAdapter()->getTablesChecksum($table); + if (count($checksum) == 1) { + return $checksum[$table]; + } + return $checksum; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php new file mode 100644 index 0000000000..8db14c1277 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php @@ -0,0 +1,718 @@ + + */ +abstract class Mage_Core_Model_Resource_Db_Collection_Abstract extends Varien_Data_Collection_Db +{ + const CACHE_TAG = 'COLLECTION_DATA'; + + /** + * Model name + * + * @var string + */ + protected $_model; + + /** + * Resource model name + * + * @var string + */ + protected $_resourceModel; + + /** + * Resource instance + * + * @var Mage_Core_Model_Resource_Db_Abstract + */ + protected $_resource; + + /** + * Fields to select in query + * + * @var array|null + */ + protected $_fieldsToSelect = null; + + /** + * Fields initial fields to select like id_field + * + * @var array|null + */ + protected $_initialFieldsToSelect = null; + + /** + * Fields to select changed flag + * + * @var booleam + */ + protected $_fieldsToSelectChanged = false; + + /** + * Store joined tables here + * + * @var array + */ + protected $_joinedTables = array(); + + /** + * Collection main table + * + * @var string + */ + protected $_mainTable = null; + + /** + * Reset items data changed flag + * + * @var boolean + */ + protected $_resetItemsDataChanged = false; + + /** + * Name prefix of events that are dispatched by model + * + * @var string + */ + protected $_eventPrefix = ''; + + /** + * Name of event parameter + * + * @var string + */ + protected $_eventObject = ''; + + /** + * Use analytic function flag + * If true - allows to prepare final select with analytic function + * + * @var bool + */ + protected $_useAnalyticFunction = false; + + /** + * Collection constructor + * + * @param Mage_Core_Model_Resource_Db_Abstract $resource + */ + public function __construct($resource = null) + { + parent::__construct(); + $this->_construct(); + $this->_resource = $resource; + $this->setConnection($this->getResource()->getReadConnection()); + $this->_initSelect(); + } + + /** + * Initialization here + * + */ + protected function _construct() + { + + } + + /** + * Retrieve main table + * + * @return string + */ + public function getMainTable() + { + if ($this->_mainTable === null) { + $this->setMainTable($this->getResource()->getMainTable()); + } + + return $this->_mainTable; + } + + /** + * Set main collection table + * + * @param string $table + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function setMainTable($table) + { + if (strpos($table, '/') !== false) { + $table = $this->getTable($table); + } + + if ($this->_mainTable !== null && $table !== $this->_mainTable && $this->getSelect() !== null) { + $from = $this->getSelect()->getPart(Zend_Db_Select::FROM); + if (isset($from['main_table'])) { + $from['main_table']['tableName'] = $table; + } + $this->getSelect()->setPart(Zend_Db_Select::FROM, $from); + } + + $this->_mainTable = $table; + return $this; + } + + /** + * Init collection select + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _initSelect() + { + $this->getSelect()->from(array('main_table' => $this->getMainTable())); + return $this; + } + + /** + * Get Zend_Db_Select instance and applies fields to select if needed + * + * @return Varien_Db_Select + */ + public function getSelect() + { + if ($this->_select && $this->_fieldsToSelectChanged) { + $this->_fieldsToSelectChanged = false; + $this->_initSelectFields(); + } + return parent::getSelect(); + } + + /** + * Init fields for select + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _initSelectFields() + { + $columns = $this->_select->getPart(Zend_Db_Select::COLUMNS); + $columnsToSelect = array(); + foreach ($columns as $columnEntry) { + list($correlationName, $column, $alias) = $columnEntry; + if ($correlationName !== 'main_table') { // Add joined fields to select + if ($column instanceof Zend_Db_Expr) { + $column = $column->__toString(); + } + $key = ($alias !== null ? $alias : $column); + $columnsToSelect[$key] = $columnEntry; + } + } + + $columns = $columnsToSelect; + + $columnsToSelect = array_keys($columnsToSelect); + + if ($this->_fieldsToSelect !== null) { + $insertIndex = 0; + foreach ($this->_fieldsToSelect as $alias => $field) { + if (!is_string($alias)) { + $alias = null; + } + + if ($field instanceof Zend_Db_Expr) { + $column = $field->__toString(); + } else { + $column = $field; + } + + if (($alias !== null && in_array($alias, $columnsToSelect)) || // If field already joined from another table + ($alias === null && isset($alias, $columnsToSelect))) { + continue; + } + + $columnEntry = array('main_table', $field, $alias); + array_splice($columns, $insertIndex, 0, array($columnEntry)); // Insert column + $insertIndex ++; + + } + } else { + array_unshift($columns, array('main_table', '*', null)); + } + + $this->_select->setPart(Zend_Db_Select::COLUMNS, $columns); + + return $this; + } + + /** + * Retrieve initial fields to select like id field + * + * @return array + */ + protected function _getInitialFieldsToSelect() + { + if ($this->_initialFieldsToSelect === null) { + $this->_initialFieldsToSelect = array(); + $this->_initInitialFieldsToSelect(); + } + + return $this->_initialFieldsToSelect; + } + + /** + * Initialize initial fields to select like id field + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _initInitialFieldsToSelect() + { + $idFieldName = $this->getResource()->getIdFieldName(); + if ($idFieldName) { + $this->_initialFieldsToSelect[] = $idFieldName; + } + return $this; + } + + /** + * Add field to select + * + * @param string|array $field + * @param string|null $alias + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function addFieldToSelect($field, $alias = null) + { + if ($field === '*') { // If we will select all fields + $this->_fieldsToSelect = null; + $this->_fieldsToSelectChanged = true; + return $this; + } + + if (is_array($field)) { + if ($this->_fieldsToSelect === null) { + $this->_fieldsToSelect = $this->_getInitialFieldsToSelect(); + } + + foreach ($field as $key => $value) { + $this->addFieldToSelect( + $value, + (is_string($key) ? $key : null), + false + ); + } + + $this->_fieldsToSelectChanged = true; + return $this; + } + + if ($alias === null) { + $this->_fieldsToSelect[] = $field; + } else { + $this->_fieldsToSelect[$alias] = $field; + } + + $this->_fieldsToSelectChanged = true; + return $this; + } + + /** + * Add attribute expression (SUM, COUNT, etc) + * Example: ('sub_total', 'SUM({{attribute}})', 'revenue') + * Example: ('sub_total', 'SUM({{revenue}})', 'revenue') + * For some functions like SUM use groupByAttribute. + * + * @param string $alias + * @param string $expression + * @param array $fields + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function addExpressionFieldToSelect($alias, $expression, $fields) + { + // validate alias + if (!is_array($fields)) { + $fields = array($fields=>$fields); + } + + $fullExpression = $expression; + foreach ($fields as $fieldKey=>$fieldItem) { + $fullExpression = str_replace('{{' . $fieldKey . '}}', $fieldItem, $fullExpression); + } + + $this->getSelect()->columns(array($alias=>$fullExpression)); + + return $this; + } + + /** + * Removes field from select + * + * @param string|null $field + * @param boolean $isAlias Alias identifier + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function removeFieldFromSelect($field, $isAlias = false) + { + if ($isAlias) { + if (isset($this->_fieldsToSelect[$field])) { + unset($this->_fieldsToSelect[$field]); + } + } else { + foreach ($this->_fieldsToSelect as $key => $value) { + if ($value === $field) { + unset($this->_fieldsToSelect[$key]); + break; + } + } + } + + $this->_fieldsToSelectChanged = true; + return $this; + } + + /** + * Removes all fields from select + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function removeAllFieldsFromSelect() + { + $this->_fieldsToSelect = $this->_getInitialFieldsToSelect(); + $this->_fieldsToSelectChanged = true; + return $this; + } + + /** + * Standard resource collection initialization + * + * @param string $model + * @param Mage_Core_Model_Resource_Db_Abstract $resourceModel + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _init($model, $resourceModel = null) + { + $this->setModel($model); + if (is_null($resourceModel)) { + $resourceModel = $model; + } + $this->setResourceModel($resourceModel); + return $this; + } + + /** + * Set model name for collection items + * + * @param string $model + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function setModel($model) + { + if (is_string($model)) { + $this->_model = $model; + $this->setItemObjectClass(Mage::getConfig()->getModelClassName($model)); + } + return $this; + } + + /** + * Get model instance + * + * @param array $args + * @return Varien_Object + */ + public function getModelName($args = array()) + { + return $this->_model; + } + + /** + * Set resource model name for collection items + * + * @param string $model + */ + public function setResourceModel($model) + { + $this->_resourceModel = $model; + } + + /** + * Retrieve resource model name + * + * @return string + */ + public function getResourceModelName() + { + return $this->_resourceModel; + } + + /** + * Get resource instance + * + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function getResource() + { + if (empty($this->_resource)) { + $this->_resource = Mage::getResourceModel($this->getResourceModelName()); + } + return $this->_resource; + } + + /** + * Retrieve table name + * + * @param string $table + * @return string + */ + public function getTable($table) + { + return $this->getResource()->getTable($table); + } + + /** + * Retrieve all ids for collection + * + * @return array + */ + public function getAllIds() + { + $idsSelect = clone $this->getSelect(); + $idsSelect->reset(Zend_Db_Select::ORDER); + $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $idsSelect->reset(Zend_Db_Select::COLUMNS); + + $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table'); + return $this->getConnection()->fetchCol($idsSelect); + } + + public function getData() + { + if ($this->_data === null) { + + + $this->_renderFilters() + ->_renderOrders() + ->_renderLimit(); + /** + * Prepare select for execute + * @var string $query + */ + $query = $this->_prepareSelect($this->getSelect()); + $this->_data = $this->_fetchAll($query, $this->_bindParams); + $this->_afterLoadData(); + } + return $this->_data; + } + + /** + * Prepare select for load + * + * @return string + */ + protected function _prepareSelect(Varien_Db_Select $select) + { + $helper = Mage::getResourceHelper('core'); + + $unionParts = $select->getPart(Zend_Db_Select::UNION); + if (!empty($unionParts)) { + $select = $helper->limitUnion($select); + } + + if ($this->_useAnalyticFunction) { + return $helper->getQueryUsingAnalyticFunction($select); + } + + return (string)$select; + } + /** + * Join table to collection select + * + * @param string $table + * @param string $cond + * @param string $cols + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function join($table, $cond, $cols = '*') + { + if (is_array($table)) { + foreach ($table as $k => $v) { + $alias = $k; + $table = $v; + break; + } + } else { + $alias = $table; + } + + if (!isset($this->_joinedTables[$alias])) { + $this->getSelect()->join( + array($alias => $this->getTable($table)), + $cond, + $cols + ); + $this->_joinedTables[$table] = true; + } + return $this; + } + + /** + * Redeclare before load method for adding event + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _beforeLoad() + { + parent::_beforeLoad(); + Mage::dispatchEvent('core_collection_abstract_load_before', array('collection' => $this)); + if ($this->_eventPrefix && $this->_eventObject) { + Mage::dispatchEvent($this->_eventPrefix.'_load_before', array( + $this->_eventObject => $this + )); + } + return $this; + } + + /** + * Set reset items data changed flag + * + * @param boolean $flag + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function setResetItemsDataChanged($flag) + { + $this->_resetItemsDataChanged = (bool)$flag; + return $this; + } + + /** + * Set flag data has changed to all collection items + * + * @return Mage_Core_Model_Mysql4_Collection_Abstract + */ + public function resetItemsDataChanged() + { + foreach ($this->_items as $item) { + $item->setDataChanges(false); + } + + return $this; + } + + /** + * Redeclare after load method for specifying collection items original data + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _afterLoad() + { + parent::_afterLoad(); + foreach ($this->_items as $item) { + $item->setOrigData(); + if ($this->_resetItemsDataChanged) { + $item->setDataChanges(false); + } + } + Mage::dispatchEvent('core_collection_abstract_load_after', array('collection' => $this)); + if ($this->_eventPrefix && $this->_eventObject) { + Mage::dispatchEvent($this->_eventPrefix.'_load_after', array( + $this->_eventObject => $this + )); + } + return $this; + } + + /** + * Save all the entities in the collection + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function save() + { + foreach ($this->getItems() as $item) { + $item->save(); + } + return $this; + } + + /** + * Check if cache can be used for collection + * + * @return bool + */ + protected function _canUseCache() + { + return Mage::app()->useCache('collections') && !empty($this->_cacheConf); + } + + /** + * Load cached data for select + * + * @param Zend_Db_Select $select + * @return string | false + */ + protected function _loadCache($select) + { + $data = Mage::app()->loadCache($this->_getSelectCacheId($select)); + return $data; + } + + /** + * Save collection data to cache + * + * @param array $data + * @param Zend_Db_Select $select + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _saveCache($data, $select) + { + Mage::app()->saveCache(serialize($data), $this->_getSelectCacheId($select), $this->_getCacheTags()); + return $this; + } + + /** + * Redeclared for processing cache tags throw application object + * + * @return array + */ + protected function _getCacheTags() + { + $tags = parent::_getCacheTags(); + $tags[] = Mage_Core_Model_App::CACHE_TAG; + $tags[] = self::CACHE_TAG; + return $tags; + } + + /** + * Format Date to internal database date format + * + * @param int|string|Zend_Date $date + * @param boolean $includeTime + * @return string + */ + public function formatDate($date, $includeTime = true) + { + return Varien_Date::formatDate($date, $includeTime); + } + + + +} diff --git a/app/code/core/Mage/Core/Model/Resource/Design.php b/app/code/core/Mage/Core/Model/Resource/Design.php new file mode 100644 index 0000000000..5ca9a33452 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Design.php @@ -0,0 +1,191 @@ + + */ +class Mage_Core_Model_Resource_Design extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and primary key + * + */ + protected function _construct() + { + $this->_init('core/design_change', 'design_change_id'); + } + + /** + * Perform actions before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + * @throws Mage_Core_Exception + */ + public function _beforeSave(Mage_Core_Model_Abstract $object) + { + if ($date = $object->getDateFrom()) { + $object->setDateFrom($this->formatDate($date)); + } else { + $object->setDateFrom(null); + } + + if ($date = $object->getDateTo()) { + $object->setDateTo($this->formatDate($date)); + } else { + $object->setDateTo(null); + } + + if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) + && Varien_Date::toTimestamp($object->getDateFrom()) > Varien_Date::toTimestamp($object->getDateTo())) { + Mage::throwException(Mage::helper('core')->__('Start date cannot be greater than end date.')); + } + + $check = $this->_checkIntersection( + $object->getStoreId(), + $object->getDateFrom(), + $object->getDateTo(), + $object->getId() + ); + + if ($check) { + Mage::throwException( + Mage::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range.')); + } + + if ($object->getDateFrom() === null) + $object->setDateFrom(new Zend_Db_Expr('null')); + if ($object->getDateTo() === null) + $object->setDateTo(new Zend_Db_Expr('null')); + + parent::_beforeSave($object); + } + + + /** + * Check intersections + * + * @param int $storeId + * @param date $dateFrom + * @param date $dateTo + * @param int $currentId + * @return Array + */ + protected function _checkIntersection($storeId, $dateFrom, $dateTo, $currentId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from(array('main_table'=>$this->getTable('design_change'))) + ->where('main_table.store_id = :store_id') + ->where('main_table.design_change_id <> :current_id'); + + $dateConditions = array('date_to IS NULL AND date_from IS NULL'); + + if (!is_null($dateFrom)) { + $dateConditions[] = ':date_from BETWEEN date_from AND date_to'; + $dateConditions[] = ':date_from >= date_from and date_to IS NULL'; + $dateConditions[] = ':date_from <= date_to and date_from IS NULL'; + } else { + $dateConditions[] = 'date_from IS NULL'; + } + + if (!is_null($dateTo)) { + $dateConditions[] = ':date_to BETWEEN date_from AND date_to'; + $dateConditions[] = ':date_to >= date_from AND date_to IS NULL'; + $dateConditions[] = ':date_to <= date_to AND date_from IS NULL'; + } else { + $dateConditions[] = 'date_to IS NULL'; + } + + if (is_null($dateFrom) && !is_null($dateTo)) { + $dateConditions[] = 'date_to <= :date_to OR date_from <= :date_to'; + } + + if (!is_null($dateFrom) && is_null($dateTo)) { + $dateConditions[] = 'date_to >= :date_from OR date_from >= :date_from'; + } + + if (!is_null($dateFrom) && !is_null($dateTo)) { + $dateConditions[] = 'date_from BETWEEN :date_from AND :date_to'; + $dateConditions[] = 'date_to BETWEEN :date_from AND :date_to'; + } elseif (is_null($dateFrom) && is_null($dateTo)) { + $dateConditions = array(); + } + + $condition = ''; + if (!empty($dateConditions)) { + $condition = '(' . implode(') OR (', $dateConditions) . ')'; + $select->where($condition); + } + + $bind = array( + 'store_id' => (int)$storeId, + 'current_id' => (int)$currentId, + ); + + if (!is_null($dateTo)) { + $bind['date_to'] = $dateTo; + } + if (!is_null($dateFrom)) { + $bind['date_from'] = $dateFrom; + } + + $result = $adapter->fetchOne($select, $bind); + return $result; + } + + /** + * Load changes for specific store and date + * + * @param int $storeId + * @param string $date + * @return array + */ + public function loadChange($storeId, $date = null) + { + if (is_null($date)) { + $date = Varien_Date::now(); + } + + $select = $this->_getReadAdapter()->select() + ->from(array('main_table' => $this->getTable('design_change'))) + ->where('store_id = :store_id') + ->where('date_from <= :required_date or date_from IS NULL') + ->where('date_to >= :required_date or date_to IS NULL'); + + $bind = array( + 'store_id' => (int)$storeId, + 'required_date' => $date + ); + + return $this->_getReadAdapter()->fetchRow($select, $bind); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Design/Collection.php b/app/code/core/Mage/Core/Model/Resource/Design/Collection.php new file mode 100644 index 0000000000..e97cb40a7a --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Design/Collection.php @@ -0,0 +1,88 @@ + + */ +class Mage_Core_Model_Resource_Design_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Core Design resource collection + * + */ + protected function _construct() + { + $this->_init('core/design'); + } + + /** + * Join store data to collection + * + * @return Mage_Core_Model_Resource_Design_Collection + */ + public function joinStore() + { + return $this->join( + array('cs' => $this->getTable('core/store')), + 'cs.store_id = main_table.store_id', + array('cs.name')); + } + + /** + * Add date filter to collection + * + * @param null|int|string|Zend_Date $date + * @return Mage_Core_Model_Resource_Design_Collection + */ + public function addDateFilter($date = null) + { + if (is_null($date)) { + $date = $this->formatDate(true); + } else { + $date = $this->formatDate($date); + } + + $this->addFieldToFilter('date_from', array('lteq' => $date)); + $this->addFieldToFilter('date_to', array('gteq' => $date)); + return $this; + } + + /** + * Add store filter to collection + * + * @param int|array $storeId + * @return Mage_Core_Model_Resource_Design_Collection + */ + public function addStoreFilter($storeId) + { + return $this->addFieldToFilter('store_id', array('in' => $storeId)); + } +} diff --git a/app/code/core/Mage/Core/Model/Convert/Adapter/Interactive.php b/app/code/core/Mage/Core/Model/Resource/Design/Package/Collection.php old mode 100644 new mode 100755 similarity index 55% rename from app/code/core/Mage/Core/Model/Convert/Adapter/Interactive.php rename to app/code/core/Mage/Core/Model/Resource/Design/Package/Collection.php index 29c79e36ff..e36b15f9e4 --- a/app/code/core/Mage/Core/Model/Convert/Adapter/Interactive.php +++ b/app/code/core/Mage/Core/Model/Resource/Design/Package/Collection.php @@ -20,48 +20,50 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Convert HTTP adapter + * Design package collection * * @category Mage * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Convert_Adapter_Interactive extends Varien_Convert_Adapter_Abstract +class Mage_Core_Model_Resource_Design_Package_Collection extends Varien_Object { - + /** + * Load design package collection + * + * @return Mage_Core_Model_Resource_Design_Package_Collection + */ public function load() { - if (!$_FILES) { -?> -
-File to upload: -
-setData(file_get_contents($_FILES['io_file']['tmp_name'])); + $packages = $this->getData('packages'); + if (is_null($packages)) { + $packages = Mage::getModel('core/design_package')->getPackageList(); + $this->setData('packages', $packages); } return $this; } - public function save() + /** + * Convert to option array + * + * @return array + */ + public function toOptionArray() { - if ($this->getVars()) { - foreach ($this->getVars() as $key=>$value) { - header($key.': '.$value); - } - } - echo $this->getData(); - return $this; - } + $options = array(); + $packages = $this->getData('packages'); + foreach ($packages as $package) { + $options[] = array('value' => $package, 'label' => $package); + } + array_unshift($options, array('value' => '', 'label' => '')); + return $options; + } } diff --git a/app/code/core/Mage/Core/Model/Resource/Email/Template.php b/app/code/core/Mage/Core/Model/Resource/Email/Template.php new file mode 100644 index 0000000000..a431a53aac --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Email/Template.php @@ -0,0 +1,134 @@ + + */ +class Mage_Core_Model_Resource_Email_Template extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize email template resource model + * + */ + protected function _construct() + { + $this->_init('core/email_template', 'template_id'); + } + + /** + * Load by template code from DB. + * + * @param string $templateCode + * @return array + */ + public function loadByCode($templateCode) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where('template_code = :template_code'); + $result = $this->_getReadAdapter()->fetchRow($select, array('template_code' => $templateCode)); + + if (!$result) { + return array(); + } + return $result; + } + + /** + * Check usage of template code in other templates + * + * @param Mage_Core_Model_Email_Template $template + * @return boolean + */ + public function checkCodeUsage(Mage_Core_Model_Email_Template $template) + { + if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'COUNT(*)') + ->where('template_id != :template_id') + ->where('template_code = :template_code'); + + $bind = array( + 'template_id' => $template->getId(), + 'template_code' => $template->getTemplateCode() + ); + $result = $this->_getReadAdapter()->fetchOne($select, $bind); + if ($result) { + return true; + } + } + return false; + } + + /** + * Set template type, added at and modified at time + * + * @param Mage_Core_Model_Email_Template $object + * @return Mage_Core_Model_Resource_Email_Template + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if ($object->isObjectNew()) { + $object->setCreatedAt($this->formatDate(true)); + } + $object->setModifiedAt($this->formatDate(true)); + $object->setTemplateType((int)$object->getTemplateType()); + + return parent::_beforeSave($object); + } + + /** + * Retrieve config scope and scope id of specified email template by email pathes + * + * @param array $paths + * @param int|string $templateId + * @return array + */ + public function getSystemConfigByPathsAndTemplateId($paths, $templateId) + { + $orWhere = array(); + $pathesCounter = 1; + $bind = array(); + foreach ($paths as $path) { + $pathAlias = 'path_' . $pathesCounter; + $orWhere[] = 'path = :' . $pathAlias; + $bind[$pathAlias] = $path; + $pathesCounter++; + } + $bind['template_id'] = $templateId; + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('core/config_data'), array('scope', 'scope_id', 'path')) + ->where('value LIKE :template_id') + ->where(join(' OR ', $orWhere)); + + return $this->_getReadAdapter()->fetchAll($select, $bind); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Email/Template/Collection.php b/app/code/core/Mage/Core/Model/Resource/Email/Template/Collection.php new file mode 100644 index 0000000000..1dabbcd39b --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Email/Template/Collection.php @@ -0,0 +1,63 @@ + + */ +class Mage_Core_Model_Resource_Email_Template_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Template table name + * + * @var string + */ + protected $_templateTable; + + /** + * Define resource table + * + */ + public function _construct() + { + $this->_init('core/email_template'); + $this->_templateTable = $this->getMainTable(); + } + + /** + * Convert collection items to select options array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('template_id', 'template_code'); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Entity/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Entity/Abstract.php index f793a2be3f..2d582e2b95 100644 --- a/app/code/core/Mage/Core/Model/Resource/Entity/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Entity/Abstract.php @@ -20,22 +20,37 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - abstract class Mage_Core_Model_Resource_Entity_Abstract { protected $_name = null; + /** + * Configuration object + * + * @var Varien_Simplexml_Config + */ protected $_config = array(); + /** + * Set config + * + * @param Varien_Simplexml_Config $config + */ public function __construct($config) { $this->_config = $config; } - public function getConfig($key='') + /** + * Get config by key + * + * @param string $key + * @return string|boolean + */ + public function getConfig($key = '') { if (''===$key) { return $this->_config; diff --git a/app/code/core/Mage/Core/Model/Resource/Entity/Table.php b/app/code/core/Mage/Core/Model/Resource/Entity/Table.php index d63f456cb2..68380e149e 100644 --- a/app/code/core/Mage/Core/Model/Resource/Entity/Table.php +++ b/app/code/core/Mage/Core/Model/Resource/Entity/Table.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,6 +31,11 @@ */ class Mage_Core_Model_Resource_Entity_Table extends Mage_Core_Model_Resource_Entity_Abstract { + /** + * Get table + * + * @return String + */ function getTable() { return $this->getConfig('table'); diff --git a/app/code/core/Mage/Core/Model/Resource/File/Storage/Abstract.php b/app/code/core/Mage/Core/Model/Resource/File/Storage/Abstract.php new file mode 100644 index 0000000000..6d0079a666 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/File/Storage/Abstract.php @@ -0,0 +1,92 @@ + + */ +abstract class Mage_Core_Model_Resource_File_Storage_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * File storage connection name + * + * @var string + */ + protected $_connectionName = null; + + /** + * Sets name of connection the resource will use + * + * @param string $name + * @return Mage_Core_Model_Resource_File_Storage_Abstract + */ + public function setConnectionName($name) + { + $this->_connectionName = $name; + return $this; + } + + /** + * Retrieve connection for read data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getReadAdapter() + { + return $this->_getConnection($this->_connectionName); + } + + /** + * Retrieve connection for write data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getWriteAdapter() + { + return $this->_getConnection($this->_connectionName); + } + + /** + * Get connection by name or type + * + * @param string $connectionName + * @return Varien_Db_Adapter_Interface + */ + protected function _getConnection($connectionName) + { + if (isset($this->_connections[$connectionName])) { + return $this->_connections[$connectionName]; + } + + $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName); + + return $this->_connections[$connectionName]; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/File/Storage/Database.php b/app/code/core/Mage/Core/Model/Resource/File/Storage/Database.php new file mode 100644 index 0000000000..a1e7984d38 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/File/Storage/Database.php @@ -0,0 +1,318 @@ + + */ +class Mage_Core_Model_Resource_File_Storage_Database extends Mage_Core_Model_Resource_File_Storage_Abstract +{ + /** + * Define table name and id field for resource + */ + protected function _construct() + { + $this->_init('core/file_storage', 'file_id'); + } + + /** + * Create database scheme for storing files + * + * @return Mage_Core_Model_Resource_File_Storage_Database + */ + public function createDatabaseScheme() + { + $adapter = $this->_getWriteAdapter(); + $table = $this->getMainTable(); + if ($adapter->isTableExists($table)) { + return $this; + } + + $dirStorageTable = $this->getTable('core/directory_storage'); // For foreign key + + $ddlTable = $adapter->newTable($table) + ->addColumn('file_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true + ), 'File Id') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_BLOB, Varien_Db_Ddl_Table::MAX_TEXT_SIZE, array( + 'nullable' => false + ), 'File Content') + ->addColumn('upload_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT + ), 'Upload Timestamp') + ->addColumn('filename', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false + ), 'Filename') + ->addColumn('directory_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => null + ), 'Identifier of Directory where File is Located') + ->addColumn('directory', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'default' => null + ), 'Directory Path') + ->addIndex($adapter->getIndexName($table, array('filename', 'directory'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('filename', 'directory'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($adapter->getIndexName($table, array('directory_id')), array('directory_id')) + ->addForeignKey($adapter->getForeignKeyName($table, 'directory_id', $dirStorageTable, 'directory_id'), + 'directory_id', $dirStorageTable, 'directory_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('File Storage'); + + $adapter->createTable($ddlTable); + return $this; + } + + /** + * Load entity by filename + * + * @param Mage_Core_Model_File_Storage_Database $object + * @param string $filename + * @param string $path + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function loadByFilename(Mage_Core_Model_File_Storage_Database $object, $filename, $path) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from(array('e' => $this->getMainTable())) + ->where('filename = ?', $filename) + ->where($adapter->prepareSqlCondition('directory', array('seq' => $path))); + + $row = $adapter->fetchRow($select); + if ($row) { + $object->setData($row); + $this->_afterLoad($object); + } + + return $this; + } + + /** + * Clear files in storage + * + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function clearFiles() + { + $adapter = $this->_getWriteAdapter(); + $adapter->delete($this->getMainTable()); + + return $this; + } + + /** + * Get files from storage at defined range + * + * @param int $offset + * @param int $count + * @return array + */ + public function getFiles($offset = 0, $count = 100) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from( + array('e' => $this->getMainTable()), + array('filename', 'content', 'directory') + ) + ->order('file_id') + ->limit($count, $offset); + + return $adapter->fetchAll($select); + } + + /** + * Save matched product Ids + * + * @param Mage_Core_Model_File_Storage_Database|array $object + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function saveFile($file) + { + $adapter = $this->_getWriteAdapter(); + $data = array( + 'content' => $file['content'], + 'upload_time' => $file['update_time'], + 'filename' => $file['filename'], + 'directory_id' => $file['directory_id'], + 'directory' => $file['directory'] + ); + + $adapter->insertOnDuplicate($this->getMainTable(), $data, array('content', 'upload_time')); + + return $this; + } + + /** + * Rename files in database + * + * @param string $oldFilename + * @param string $oldPath + * @param string $newFilename + * @param string $newPath + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function renameFile($oldFilename, $oldPath, $newFilename, $newPath) + { + $adapter = $this->_getWriteAdapter(); + $dataUpdate = array('filename' => $newFilename, 'directory' => $newPath); + + $dataWhere = array('filename = ?' => $oldFilename); + $dataWhere[] = new Zend_Db_Expr($adapter->prepareSqlCondition('directory', array('seq' => $oldPath))); + + $adapter->update($this->getMainTable(), $dataUpdate, $dataWhere); + + return $this; + } + + /** + * Copy files in database + * + * @param string $oldFilename + * @param string $oldPath + * @param string $newFilename + * @param string $newPath + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function copyFile($oldFilename, $oldPath, $newFilename, $newPath) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from(array('e' => $this->getMainTable())) + ->where('filename = ?', $oldFilename) + ->where($adapter->prepareSqlCondition('directory', array('seq' => $oldPath))); + + $data = $adapter->fetchRow($select); + if (!$data) { + return $this; + } + + if (isset($data['file_id']) && isset($data['filename'])) { + unset($data['file_id']); + $data['filename'] = $newFilename; + $data['directory'] = $newPath; + + $writeAdapter = $this->_getWriteAdapter(); + $writeAdapter->insertOnDuplicate($this->getMainTable(), $data, array('content', 'upload_time')); + } + + return $this; + } + + /** + * Check whether file exists in DB + * + * @param string $filename + * @param string $path + * @return bool + */ + public function fileExists($filename, $path) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from(array('e' => $this->getMainTable())) + ->where('filename = ?', $filename) + ->where($adapter->prepareSqlCondition('directory', array('seq' => $path))) + ->limit(1); + + $data = $adapter->fetchRow($select); + return (bool)$data; + } + + /** + * Delete files that starts with given $folderName + * + * @param string $folderName + */ + public function deleteFolder($folderName = '') + { + $folderName = rtrim($folderName, '/'); + if (!strlen($folderName)) { + return; + } + + /* @var $resHelper Mage_Core_Model_Resource_Helper_Abstract */ + $resHelper = Mage::getResourceHelper('core'); + $likeExpression = $resHelper->addLikeEscape($folderName . '/', array('position' => 'start')); + $this->_getWriteAdapter() + ->delete($this->getMainTable(), new Zend_Db_Expr('filename LIKE ' . $likeExpression)); + } + + /** + * Delete file + * + * @param string $filename + * @param string $directory + */ + public function deleteFile($filename, $directory) + { + $adapter = $this->_getWriteAdapter(); + + $where = array('filename = ?' => $filename); + $where[] = new Zend_Db_Expr($adapter->prepareSqlCondition('directory', array('seq' => $directory))); + + $adapter->delete($this->getMainTable(), $where); + } + + /** + * Return directory file listing + * + * @param string $directory + * @return mixed + */ + public function getDirectoryFiles($directory) + { + $directory = trim($directory, '/'); + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from( + array('e' => $this->getMainTable()), + array( + 'filename', + 'directory', + 'content' + ) + ) + ->where($adapter->prepareSqlCondition('directory', array('seq' => $directory))) + ->order('file_id'); + + return $adapter->fetchAll($select); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/File/Storage/Directory/Database.php b/app/code/core/Mage/Core/Model/Resource/File/Storage/Directory/Database.php new file mode 100644 index 0000000000..d0893e0d84 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/File/Storage/Directory/Database.php @@ -0,0 +1,222 @@ + + */ +class Mage_Core_Model_Resource_File_Storage_Directory_Database extends Mage_Core_Model_Resource_File_Storage_Abstract +{ + /** + * Define table name and id field for resource + */ + protected function _construct() + { + $this->_init('core/directory_storage', 'directory_id'); + } + + /** + * Create database scheme for storing files + * + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function createDatabaseScheme() + { + $adapter = $this->_getWriteAdapter(); + $table = $this->getMainTable(); + if ($adapter->isTableExists($table)) { + return $this; + } + + $ddlTable = $adapter->newTable($table) + ->addColumn('directory_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true + ), 'Directory Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false + ), 'Directory Name') + ->addColumn('path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'default' => null), 'Path to the Directory') + ->addColumn('upload_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT + ), 'Upload Timestamp') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => true, + 'default' => null, + 'unsigned' => true + ), 'Parent Directory Id') + ->addIndex($adapter->getIndexName($table, array('name', 'path'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('name', 'path'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($adapter->getIndexName($table, array('parent_id')), array('parent_id')) + ->addForeignKey($adapter->getForeignKeyName($table, 'parent_id', $table, 'directory_id'), + 'parent_id', $table, 'directory_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Directory Storage'); + + $adapter->createTable($ddlTable); + return $this; + } + + /** + * Load entity by path + * + * @param Mage_Core_Model_File_Storage_Directory_Database $object + * @param string $path + * @return Mage_Core_Model_Mysql4_File_Storage_Directory_Database + */ + public function loadByPath(Mage_Core_Model_File_Storage_Directory_Database $object, $path) + { + $adapter = $this->_getReadAdapter(); + + $name = basename($path); + $path = dirname($path); + if ($path == '.') { + $path = ''; + } + + $select = $adapter->select() + ->from(array('e' => $this->getMainTable())) + ->where('name = ?', $name) + ->where($adapter->prepareSqlCondition('path', array('seq' => $path))); + + $data = $adapter->fetchRow($select); + if ($data) { + $object->setData($data); + $this->_afterLoad($object); + } + + return $this; + } + + /** + * Return parent id + * + * @param string $path + * @return int + */ + public function getParentId($path) + { + $adapter = $this->_getReadAdapter(); + + $name = basename($path); + $path = dirname($path); + if ($path == '.') { + $path = ''; + } + + $select = $adapter->select() + ->from( + array('e' => $this->getMainTable()), + array('directory_id') + ) + ->where('name = ?', $name) + ->where($adapter->prepareSqlCondition('path', array('seq' => $path))); + + return $adapter->fetchOne($select); + } + + /** + * Delete all directories from storage + * + * @return Mage_Core_Model_Mysql4_File_Storage_Database + */ + public function clearDirectories() + { + $adapter = $this->_getWriteAdapter(); + $adapter->delete($this->getMainTable()); + + return $this; + } + + /** + * Export directories from database + * + * @param int $offset + * @param int $count + * @return mixed + */ + public function exportDirectories($offset, $count = 100) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from( + array('e' => $this->getMainTable()), + array('name', 'path') + ) + ->order('directory_id') + ->limit($count, $offset); + + return $adapter->fetchAll($select); + } + + /** + * Return directory file listing + * + * @param string $directory + * @return mixed + */ + public function getSubdirectories($directory) + { + $directory = trim($directory, '/'); + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from( + array('e' => $this->getMainTable()), + array('name', 'path') + ) + ->where($adapter->prepareSqlCondition('path', array('seq' => $directory))) + ->order('directory_id'); + + return $adapter->fetchAll($select); + } + + /** + * Delete directory + * + * @param string $name + * @param string $path + */ + public function deleteDirectory($name, $path) + { + $adapter = $this->_getWriteAdapter(); + + $where = array('name = ?' => $name); + $where[] = new Zend_Db_Expr($adapter->prepareSqlCondition('path', array('seq' => $path))); + + $adapter->delete($this->getMainTable(), $where); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php b/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php new file mode 100644 index 0000000000..f0bee37e04 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/File/Storage/File.php @@ -0,0 +1,197 @@ + + */ +class Mage_Core_Model_Resource_File_Storage_File +{ + /** + * Prefix of model events names + * + * @var string + */ + protected $_mediaBaseDirectory = null; + + /** + * Files at storage + * + * @var array + */ + public function getMediaBaseDirectory() + { + if (is_null($this->_mediaBaseDirectory)) { + $this->_mediaBaseDirectory = Mage::helper('core/file_storage_database')->getMediaBaseDir(); + } + + return $this->_mediaBaseDirectory; + } + + /** + * Collect files and directories recursively + * + * @param string$dir + * @return array + */ + public function getStorageData($dir = '') + { + $files = array(); + $directories = array(); + $currentDir = $this->getMediaBaseDirectory() . $dir; + + if (is_dir($currentDir)) { + $dh = opendir($currentDir); + if ($dh) { + while (($file = readdir($dh)) !== false) { + if ($file == '.' || $file == '..' || $file == '.svn' || $file == '.htaccess') { + continue; + } + + $fullPath = $currentDir . DS . $file; + $relativePath = $dir . DS . $file; + if (is_dir($fullPath)) { + $directories[] = array( + 'name' => $file, + 'path' => str_replace(DS, '/', ltrim($dir, DS)) + ); + + $data = $this->getStorageData($relativePath); + $directories = array_merge($directories, $data['directories']); + $files = array_merge($files, $data['files']); + } else { + $files[] = $relativePath; + } + } + closedir($dh); + } + } + + return array('files' => $files, 'directories' => $directories); + } + + /** + * Clear files and directories in storage + * + * @param string $dir + * @return Mage_Core_Model_Mysql4_File_Storage_File + */ + public function clear($dir = '') + { + $currentDir = $this->getMediaBaseDirectory() . $dir; + + if (is_dir($currentDir)) { + $dh = opendir($currentDir); + if ($dh) { + while (($file = readdir($dh)) !== false) { + if ($file == '.' || $file == '..') { + continue; + } + + $fullPath = $currentDir . DS . $file; + if (is_dir($fullPath)) { + $this->clear($dir . DS . $file); + } else { + @unlink($fullPath); + } + } + closedir($dh); + @rmdir($currentDir); + } + } + + return $this; + } + + /** + * Save directory to storage + * + * @param array $dir + * @return bool + */ + public function saveDir($dir) + { + if (!isset($dir['name']) || !strlen($dir['name']) + || !isset($dir['path']) + ) { + return false; + } + + $path = (strlen($dir['path'])) + ? $dir['path'] . DS . $dir['name'] + : $dir['name']; + $path = Mage::helper('core/file_storage_database')->getMediaBaseDir() . DS . str_replace('/', DS, $path); + + if (!file_exists($path) || !is_dir($path)) { + if (!@mkdir($path, 0777, true)) { + Mage::throwException(Mage::helper('core')->__('Unable to create directory: %s', $path)); + } + } + + return true; + } + + /** + * Save file to storage + * + * @param string $filePath + * @param string $content + * @param bool $overwrite + * @return bool + */ + public function saveFile($filePath, $content, $overwrite = false) + { + $filename = basename($filePath); + $path = $this->getMediaBaseDirectory() . DS . str_replace('/', DS ,dirname($filePath)); + + if (!file_exists($path) || !is_dir($path)) { + @mkdir($path, 0777, true); + } + + $ioFile = new Varien_Io_File(); + $ioFile->cd($path); + + if (!$ioFile->fileExists($filename) || ($overwrite && $ioFile->rm($filename))) { + $ioFile->streamOpen($filename); + $ioFile->streamLock(true); + $result = $ioFile->streamWrite($content); + $ioFile->streamUnlock(); + $ioFile->streamClose(); + + if ($result) { + return true; + } + + Mage::throwException(Mage::helper('core')->__('Unable to save file: %s', $filePath)); + } + + return false; + } +} diff --git a/app/code/core/Mage/Core/Model/Mysql4/Convert/Profile/Collection.php b/app/code/core/Mage/Core/Model/Resource/Flag.php similarity index 77% rename from app/code/core/Mage/Core/Model/Mysql4/Convert/Profile/Collection.php rename to app/code/core/Mage/Core/Model/Resource/Flag.php index bceb1bcf41..e895176e42 100644 --- a/app/code/core/Mage/Core/Model/Mysql4/Convert/Profile/Collection.php +++ b/app/code/core/Mage/Core/Model/Resource/Flag.php @@ -20,21 +20,26 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Convert profile collection + * Flag model * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Convert_Profile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Resource_Flag extends Mage_Core_Model_Resource_Db_Abstract { + /** + * Define main table + * + */ protected function _construct() { - $this->_init('core/convert_profile'); + $this->_init('core/flag', 'flag_id'); } } diff --git a/app/code/core/Mage/Core/Model/Resource/Helper/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Helper/Abstract.php new file mode 100644 index 0000000000..7ab662229b --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Helper/Abstract.php @@ -0,0 +1,306 @@ + + */ +abstract class Mage_Core_Model_Resource_Helper_Abstract +{ + /** + * Read adapter instance + * + * @var Varien_Db_Adapter_Interface + */ + protected $_readAdapter; + + /** + * Write adapter instance + * + * @var Varien_Db_Adapter_Interface + */ + protected $_writeAdapter; + + /** + * Resource helper module prefix + * + * @var string + */ + protected $_modulePrefix; + + /** + * Initialize resource helper instance + * + * @param string $module + */ + public function __construct($module) + { + $this->_modulePrefix = (string)$module; + } + + /** + * Retrieve connection for read data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getReadAdapter() + { + if ($this->_readAdapter === null) { + $this->_readAdapter = $this->_getConnection('read'); + } + + return $this->_readAdapter; + } + + /** + * Retrieve connection for write data + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getWriteAdapter() + { + if ($this->_writeAdapter === null) { + $this->_writeAdapter = $this->_getConnection('write'); + } + + return $this->_writeAdapter; + } + + /** + * Retrieves connection to the resource + * + * @param string $name + * @return Varien_Db_Adapter_Interface + */ + protected function _getConnection($name) + { + $connection = sprintf('%s_%s', $this->_modulePrefix, $name); + /** @var $resource Mage_Core_Model_Resource */ + $resource = Mage::getSingleton('core/resource'); + + return $resource->getConnection($connection); + } + + /** + * Escapes value, that participates in LIKE, with '\' symbol. + * Note: this func cannot be used on its own, because different RDMBS may use different default escape symbols, + * so you should either use addLikeEscape() to produce LIKE construction, or add escape symbol on your own. + * + * By default escapes '_', '%' and '\' symbols. If some masking symbols must not be escaped, then you can set + * appropriate options in $options. + * + * $options can contain following flags: + * - 'allow_symbol_mask' - the '_' symbol will not be escaped + * - 'allow_string_mask' - the '%' symbol will not be escaped + * - 'position' ('any', 'start', 'end') - expression will be formed so that $value will be found at position within string, + * by default when nothing set - string must be fully matched with $value + * + * @param string $value + * @param array $options + * @return string + */ + public function escapeLikeValue($value, $options = array()) + { + $value = str_replace('\\', '\\\\', $value); + + $from = array(); + $to = array(); + if (empty($options['allow_symbol_mask'])) { + $from[] = '_'; + $to[] = '\_'; + } + if (empty($options['allow_string_mask'])) { + $from[] = '%'; + $to[] = '\%'; + } + if ($from) { + $value = str_replace($from, $to, $value); + } + + if (isset($options['position'])) { + switch ($options['position']) { + case 'any': + $value = '%' . $value . '%'; + break; + case 'start': + $value = $value . '%'; + break; + case 'end': + $value = '%' . $value; + break; + } + } + + return $value; + } + + /** + * Escapes, quotes and adds escape symbol to LIKE expression. + * For options and escaping see escapeLikeValue(). + * + * @param string $value + * @param array $options + * @return Zend_Db_Expr + * + * @see escapeLikeValue() + */ + abstract public function addLikeEscape($value, $options = array()); + + /** + * Returns case insensitive LIKE construction. + * For options and escaping see escapeLikeValue(). + * + * @param string $field + * @param string $value + * @param array $options + * @return Zend_Db_Expr + * + * @see escapeLikeValue() + */ + public function getCILike($field, $value, $options = array()) + { + $quotedField = $this->_getReadAdapter()->quoteIdentifier($field); + return new Zend_Db_Expr($quotedField . ' LIKE ' . $this->addLikeEscape($value, $options)); + } + + /** + * Converts old pre-MMDB column type made for MySQL to new cross-db column DDL definition. + * Used to convert data from 3rd party extensions that hasn't been updated to MMDB style yet. + * + * E.g. Converts 'varchar(255)' to array('type' => Varien_Db_Ddl_Table::TYPE_TEXT, 'length' => 255) + * + * @param string $definition + * @return array + */ + public function convertOldColumnType2Ddl($definition) + { + // Match type and size - e.g. varchar(100) or decimal(12,4) or int + $matches = array(); + $definition = trim($definition); + if (!preg_match('/([^(]*)(\\((.*)\\))?/', $definition, $matches)) { + throw Mage::exception('Mage_Core', Mage::helper('core')->__("Wrong old style column type definition: {$definition}.")); + } + + $length = null; + $proposedLength = (isset($matches[3]) && strlen($matches[3])) ? $matches[3] : null; + switch (strtolower($matches[1])) { + case 'bool': + $length = null; + $type = Varien_Db_Ddl_Table::TYPE_BOOLEAN; + break; + case 'char': + case 'varchar': + case 'tinytext': + $length = $proposedLength; + if (!$length) { + $length = 255; + } + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + break; + case 'text': + $length = $proposedLength; + if (!$length) { + $length = 65535; + } + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + break; + case 'mediumtext': + $length = $proposedLength; + if (!$length) { + $length = 16777215; + } + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + break; + case 'longtext': + $length = $proposedLength; + if (!$length) { + $length = 4294967295; + } + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + break; + case 'blob': + $length = $proposedLength; + if (!$length) { + $length = 65535; + } + $type = Varien_Db_Ddl_Table::TYPE_BLOB; + break; + case 'mediumblob': + $length = $proposedLength; + if (!$length) { + $length = 16777215; + } + $type = Varien_Db_Ddl_Table::TYPE_BLOB; + break; + case 'longblob': + $length = $proposedLength; + if (!$length) { + $length = 4294967295; + } + $type = Varien_Db_Ddl_Table::TYPE_BLOB; + break; + case 'tinyint': + case 'smallint': + $type = Varien_Db_Ddl_Table::TYPE_SMALLINT; + break; + case 'mediumint': + case 'int': + $type = Varien_Db_Ddl_Table::TYPE_INTEGER; + break; + case 'bigint': + $type = Varien_Db_Ddl_Table::TYPE_BIGINT; + break; + case 'float': + $type = Varien_Db_Ddl_Table::TYPE_FLOAT; + break; + case 'decimal': + case 'numeric': + $length = $proposedLength; + $type = Varien_Db_Ddl_Table::TYPE_DECIMAL; + break; + case 'datetime': + case 'timestamp': + case 'time': + $type = Varien_Db_Ddl_Table::TYPE_TIMESTAMP; + break; + case 'date': + $type = Varien_Db_Ddl_Table::TYPE_DATE; + break; + default: + throw Mage::exception('Mage_Core', Mage::helper('core')->__("Unknown old style column type definition: {$definition}.")); + } + + return array( + 'type' => $type, + 'length' => $length + ); + + return $result; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Core/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..3c97725b6d --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,371 @@ + + */ +class Mage_Core_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Abstract +{ + /** + * Returns expresion for field unification + * + * @param string $field + * @return Zend_Db_Expr + */ + public function castField($field) + { + return $field; + } + /** + * Returns analytic expression for database column + * + * @param string $column + * @param string $groupAliasName OPTIONAL + * @param string $orderBy OPTIONAL + * @return Zend_Db_Expr + */ + public function prepareColumn($column, $groupAliasName = null, $orderBy = null) + { + return new Zend_Db_Expr((string)$column); + } + + /** + * Returns select query with analytic functions + * + * @param Varien_Db_Select $select + * @return string + */ + public function getQueryUsingAnalyticFunction(Varien_Db_Select $select) + { + return $select->assemble(); + } + + /** + * + * Returns Insert From Select On Duplicate query with analytic functions + * + * @param Varien_Db_Select $select + * @param string $table + * @param array $table + * @return string + */ + public function getInsertFromSelectUsingAnalytic(Varien_Db_Select $select, $table, $fields) + { + return $select->insertFromSelect($table, $fields); + } + + /** + * Correct limitation of queries with UNION + * No need to do additional actions on MySQL + * + * @param Varien_Db_Select $select + * @return Varien_Db_Select + */ + public function limitUnion($select) + { + return $select; + } + + /** + * Returns array of quoted orders with direction + * + * @param Varien_Db_Select $select + * @param bool $autoReset + * @return array + */ + protected function _prepareOrder(Varien_Db_Select $select, $autoReset = false) + { + $selectOrders = $select->getPart(Zend_Db_Select::ORDER); + if (!$selectOrders) { + return array(); + } + + $orders = array(); + foreach ($selectOrders as $term) { + if (is_array($term)) { + if (!is_numeric($term[0])) { + $orders[] = sprintf('%s %s', $this->_getReadAdapter()->quoteIdentifier($term[0], true), $term[1]); + } + } else { + if (!is_numeric($term)) { + $orders[] = $this->_getReadAdapter()->quoteIdentifier($term, true); + } + } + } + + if ($autoReset) { + $select->reset(Zend_Db_Select::ORDER); + } + + return $orders; + } + + /** + * Truncate alias name from field. + * + * Result string depends from second optional argument $reverse + * which can be true if you need the first part of the field. + * Field can be with 'dot' delimiter. + * + * @param string $field + * @param bool $reverse OPTIONAL + * @return string + */ + protected function _truncateAliasName($field, $reverse = false) + { + $string = $field; + if (!is_numeric($field) && (strpos($field, '.') !== false)) { + $size = strpos($field, '.'); + if ($reverse) { + $string = substr($field, 0, $size); + } else { + $string = substr($field, $size + 1); + } + } + + return $string; + } + + /** + * Returns quoted group by fields + * + * @param Varien_Db_Select $select + * @param bool $autoReset + * @return array + */ + protected function _prepareGroup(Varien_Db_Select $select, $autoReset = false) + { + $selectGroups = $select->getPart(Zend_Db_Select::GROUP); + if (!$selectGroups) { + return array(); + } + + $groups = array(); + foreach ($selectGroups as $term) { + $groups[] = $this->_getReadAdapter()->quoteIdentifier($term, true); + } + + if ($autoReset) { + $select->reset(Zend_Db_Select::GROUP); + } + + return $groups; + } + + /** + * Prepare and returns having array + * + * @param Varien_Db_Select $select + * @param bool $autoReset + * @return array + * @throws Zend_Db_Exception + */ + protected function _prepareHaving(Varien_Db_Select $select, $autoReset = false) + { + $selectHavings = $select->getPart(Zend_Db_Select::HAVING); + if (!$selectHavings) { + return array(); + } + + $havings = array(); + $columns = $select->getPart(Zend_Db_Select::COLUMNS); + foreach ($columns as $columnEntry) { + $correlationName = (string)$columnEntry[1]; + $column = $columnEntry[2]; + foreach ($selectHavings as $having) { + /** + * Looking for column expression in the having clause + */ + if (strpos($having, $correlationName) !== false) { + if (is_string($column)) { + /** + * Replace column expression to column alias in having clause + */ + $havings[] = str_replace($correlationName, $column, $having); + } else { + throw new Zend_Db_Exception(sprintf("Can't prepare expression without column alias: '%s'", $correlationName)); + } + } + } + } + + if ($autoReset) { + $select->reset(Zend_Db_Select::HAVING); + } + + return $havings; + } + + /** + * + * @param string $query + * @param int $limitCount + * @param int $limitOffset + * @param array $columnList + * @return string + */ + protected function _assembleLimit($query, $limitCount, $limitOffset, $columnList = array()) + { + if ($limitCount !== null) { + $limitCount = intval($limitCount); + if ($limitCount <= 0) { +// throw new Exception("LIMIT argument count={$limitCount} is not valid"); + } + + $limitOffset = intval($limitOffset); + if ($limitOffset < 0) { +// throw new Exception("LIMIT argument offset={$limitOffset} is not valid"); + } + + if ($limitOffset + $limitCount != $limitOffset + 1) { + $columns = array(); + foreach ($columnList as $columnEntry) { + $columns[] = $columnEntry[2] ? $columnEntry[2] : $columnEntry[1]; + } + + $query = sprintf('%s LIMIT %s, %s', $query, $limitCount, $limitOffset); + } + } + + return $query; + } + + /** + * Prepare select column list + * + * @param Varien_Db_Select $select + * @param $groupByCondition OPTIONAL + * @return array + * @throws Zend_Db_Exception + */ + public function prepareColumnsList(Varien_Db_Select $select, $groupByCondition = null) + { + if (!count($select->getPart(Zend_Db_Select::FROM))) { + return $select->getPart(Zend_Db_Select::COLUMNS); + } + + $columns = $select->getPart(Zend_Db_Select::COLUMNS); + $tables = $select->getPart(Zend_Db_Select::FROM); + $preparedColumns = array(); + + foreach ($columns as $columnEntry) { + list($correlationName, $column, $alias) = $columnEntry; + if ($column instanceof Zend_Db_Expr) { + if ($alias !== null) { + if (preg_match('/(^|[^a-zA-Z_])^(SELECT)?(SUM|MIN|MAX|AVG|COUNT)\s*\(/i', $column, $matches)) { + $column = $this->prepareColumn($column, $groupByCondition); + } + $preparedColumns[strtoupper($alias)] = array(null, $column, $alias); + } else { + throw new Zend_Db_Exception("Can't prepare expression without alias"); + } + } else { + if ($column == Zend_Db_Select::SQL_WILDCARD) { + if ($tables[$correlationName]['tableName'] instanceof Zend_Db_Expr) { + throw new Zend_Db_Exception("Can't prepare expression when tableName is instance of Zend_Db_Expr"); + } + $tableColumns = $this->_getReadAdapter()->describeTable($tables[$correlationName]['tableName']); + foreach(array_keys($tableColumns) as $col) { + $preparedColumns[strtoupper($col)] = array($correlationName, $col, null); + } + } else { + $columnKey = is_null($alias) ? $column : $alias; + $preparedColumns[strtoupper($columnKey)] = array($correlationName, $column, $alias); + } + } + } + +// $select->reset(Zend_Db_Select::COLUMNS); +// $select->setPart(Zend_Db_Select::COLUMNS, array_values($preparedColumns)); + + return $preparedColumns; + } + + /** + * Add prepared column group_concat expression + * + * @param Varien_Db_Select $select + * @param string $fieldAlias Field alias which will be added with column group_concat expression + * @param string $fields + * @param string $groupConcatDelimiter + * @param string $fieldsDelimiter + * @param string $additionalWhere + * @return Varien_Db_Select + */ + public function addGroupConcatColumn($select, $fieldAlias, $fields, $groupConcatDelimiter = ',', $fieldsDelimiter = '', $additionalWhere = '') + { + if (is_array($fields)) { + $fieldExpr = $this->_getReadAdapter()->getConcatSql($fields, $fieldsDelimiter); + } else { + $fieldExpr = $fields; + } + if ($additionalWhere) { + $fieldExpr = $this->_getReadAdapter()->getCheckSql($additionalWhere, $fieldExpr, "''"); + } + $separator = ''; + if ($groupConcatDelimiter) { + $separator = sprintf(" SEPARATOR '%s'", $groupConcatDelimiter); + } + + $select->columns(array($fieldAlias => new Zend_Db_Expr(sprintf('GROUP_CONCAT(%s%s)', $fieldExpr, $separator)))); + + return $select; + } + + /** + * Returns expression of days passed from $startDate to $endDate + * + * @param string|Zend_Db_Expr $startDate + * @param string|Zend_Db_Expr $endDate + * @return Zend_Db_Expr + */ + public function getDateDiff($startDate, $endDate) + { + $dateDiff = '(TO_DAYS(' . $endDate . ') - TO_DAYS(' . $startDate . '))'; + return new Zend_Db_Expr($dateDiff); + } + + /** + * Escapes and quotes LIKE value. + * Stating escape symbol in expression is not required, because we use standard MySQL escape symbol. + * For options and escaping see escapeLikeValue(). + * + * @param string $value + * @param array $options + * @return Zend_Db_Expr + * + * @see escapeLikeValue() + */ + public function addLikeEscape($value, $options = array()) + { + $value = $this->escapeLikeValue($value, $options); + return new Zend_Db_Expr($this->_getReadAdapter()->quote($value)); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Iterator.php b/app/code/core/Mage/Core/Model/Resource/Iterator.php index 113428cf4a..1b7d5e1d33 100644 --- a/app/code/core/Mage/Core/Model/Resource/Iterator.php +++ b/app/code/core/Mage/Core/Model/Resource/Iterator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -35,14 +35,14 @@ class Mage_Core_Model_Resource_Iterator extends Varien_Object * Walk over records fetched from query one by one using callback function * * @param Zend_Db_Statement_Interface|Zend_Db_Select|string $query - * @param array|string $callback + * @param array|string $callbacks * @param array $args - * @return Mage_Core_Model_Resource_Activerecord + * @param Varien_Db_Adapter_interface $adapter + * @return Mage_Core_Model_Resource_Iterator */ - public function walk($query, array $callbacks, array $args=array()) + public function walk($query, array $callbacks, array $args=array(), $adapter = null) { - $stmt = $this->_getStatement($query); - + $stmt = $this->_getStatement($query, $adapter); $args['idx'] = 0; while ($row = $stmt->fetch()) { $args['row'] = $row; @@ -64,8 +64,9 @@ public function walk($query, array $callbacks, array $args=array()) * @param Zend_Db_Statement_Interface|Zend_Db_Select|string $query * @param Zend_Db_Adapter_Abstract $conn * @return Zend_Db_Statement_Interface + * @throws Mage_Core_Exception */ - protected function _getStatement($query, $conn=null) + protected function _getStatement($query, $conn = null) { if ($query instanceof Zend_Db_Statement_Interface) { return $query; @@ -75,15 +76,13 @@ protected function _getStatement($query, $conn=null) return $query->query(); } - $hlp = Mage::helper('core'); - if (is_string($query)) { if (!$conn instanceof Zend_Db_Adapter_Abstract) { - Mage::throwException($hlp->__('Invalid connection')); + Mage::throwException(Mage::helper('core')->__('Invalid connection')); } return $conn->query($query); } - Mage::throwException($hlp->__('Invalid query')); + Mage::throwException(Mage::helper('core')->__('Invalid query')); } } diff --git a/app/code/core/Mage/Core/Model/Mysql4/Convert/History/Collection.php b/app/code/core/Mage/Core/Model/Resource/Language.php old mode 100644 new mode 100755 similarity index 75% rename from app/code/core/Mage/Core/Model/Mysql4/Convert/History/Collection.php rename to app/code/core/Mage/Core/Model/Resource/Language.php index 99efbfc193..2e390d0226 --- a/app/code/core/Mage/Core/Model/Mysql4/Convert/History/Collection.php +++ b/app/code/core/Mage/Core/Model/Resource/Language.php @@ -20,22 +20,26 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Convert history collection + * Language resource model * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_Convert_History_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Core_Model_Resource_Language extends Mage_Core_Model_Resource_Db_Abstract { + /** + * Define main table + * + */ protected function _construct() { - $this->_init('core/convert_history'); - parent::_construct(); + $this->_init('core/language', 'language_code'); } } diff --git a/app/code/core/Mage/Core/Model/Resource/Language/Collection.php b/app/code/core/Mage/Core/Model/Resource/Language/Collection.php new file mode 100644 index 0000000000..f025c13b85 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Language/Collection.php @@ -0,0 +1,65 @@ + + */ +class Mage_Core_Model_Resource_Language_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('core/language'); + } + + /** + * Convert collection items to array of select options + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('language_code', 'language_title', array('title'=>'language_title')); + } + + /** + * Convert items array to hash for select options + * + * @return array + */ + public function toOptionHash() + { + return $this->_toOptionHash('language_code', 'language_title'); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Layout.php b/app/code/core/Mage/Core/Model/Resource/Layout.php new file mode 100644 index 0000000000..f13a5a1c8d --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Layout.php @@ -0,0 +1,88 @@ + + */ +class Mage_Core_Model_Resource_Layout extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/layout_update', 'layout_update_id'); + } + + /** + * Retrieve layout updates by handle + * + * @param string $handle + * @param array $params + * @return string + */ + public function fetchUpdatesByHandle($handle, $params = array()) + { + $bind = array( + 'store_id' => Mage::app()->getStore()->getId(), + 'area' => Mage::getSingleton('core/design_package')->getArea(), + 'package' => Mage::getSingleton('core/design_package')->getPackageName(), + 'theme' => Mage::getSingleton('core/design_package')->getTheme('layout') + ); + + foreach ($params as $key => $value) { + if (isset($bind[$key])) { + $bind[$key] = $value; + } + } + $bind['layout_update_handle'] = $handle; + $result = ''; + + $readAdapter = $this->_getReadAdapter(); + if ($readAdapter) { + $select = $readAdapter->select() + ->from(array('layout_update' => $this->getMainTable()), array('xml')) + ->join(array('link'=>$this->getTable('core/layout_link')), + 'link.layout_update_id=layout_update.layout_update_id', + '') + ->where('link.store_id IN (0, :store_id)') + ->where('link.area = :area') + ->where('link.package = :package') + ->where('link.theme = :theme') + ->where('layout_update.handle = :layout_update_handle') + ->order('layout_update.sort_order ' . Varien_Db_Select::SQL_ASC); + + $result = join('', $readAdapter->fetchCol($select, $bind)); + } + return $result; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Resource.php b/app/code/core/Mage/Core/Model/Resource/Resource.php new file mode 100644 index 0000000000..7290509666 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Resource.php @@ -0,0 +1,177 @@ + + */ +class Mage_Core_Model_Resource_Resource extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Database versions + * + * @var array + */ + protected static $_versions = null; + + /** + * Resource data versions cache array + * + * @var array + */ + protected static $_dataVersions = null; + + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/resource', 'store_id'); + } + + /** + * Fill static versions arrays. + * This routine fetches Db and Data versions of at once to optimize sql requests. However, when upgrading, it's + * possible that 'data' column will be created only after all Db installs are passed. So $neededType contains + * information on main purpose of calling this routine, and even when 'data' column is absent - it won't require + * reissuing new sql just to get 'db' version of module. + * + * @param string $needType Can be 'db' or 'data' + * @return Mage_Core_Model_Resource_Resource + */ + protected function _loadVersionData($needType) + { + if ((($needType == 'db') && is_null(self::$_versions)) + || (($needType == 'data') && is_null(self::$_dataVersions))) { + self::$_versions = array(); // Db version column always exists + self::$_dataVersions = null; // Data version array will be filled only if Data column exist + + if ($this->_getReadAdapter()->isTableExists($this->getMainTable())) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), '*'); + $rowset = $this->_getReadAdapter()->fetchAll($select); + foreach ($rowset as $row) { + self::$_versions[$row['code']] = $row['version']; + if (array_key_exists('data_version', $row)) { + if (is_null(self::$_dataVersions)) { + self::$_dataVersions = array(); + } + self::$_dataVersions[$row['code']] = $row['data_version']; + } + } + } + } + + return $this; + } + + + /** + * Get Module version from DB + * + * @param string $resName + * @return bool|string + */ + public function getDbVersion($resName) + { + if (!$this->_getReadAdapter()) { + return false; + } + $this->_loadVersionData('db'); + return isset(self::$_versions[$resName]) ? self::$_versions[$resName] : false; + } + + /** + * Set module version into DB + * + * @param string $resName + * @param string $version + * @return int + */ + public function setDbVersion($resName, $version) + { + $dbModuleInfo = array( + 'code' => $resName, + 'version' => $version, + ); + + if ($this->getDbVersion($resName)) { + self::$_versions[$resName] = $version; + return $this->_getWriteAdapter()->update($this->getMainTable(), + $dbModuleInfo, + array('code = ?' => $resName)); + } else { + self::$_versions[$resName] = $version; + return $this->_getWriteAdapter()->insert($this->getMainTable(), $dbModuleInfo); + } + } + + /** + * Get resource data version + * + * @param string $resName + * @return string|false + */ + public function getDataVersion($resName) + { + if (!$this->_getReadAdapter()) { + return false; + } + + $this->_loadVersionData('data'); + + return isset(self::$_dataVersions[$resName]) ? self::$_dataVersions[$resName] : false; + } + + /** + * Specify resource data version + * + * @param string $resName + * @param string $version + * @return Mage_Core_Model_Resource_Resource + */ + public function setDataVersion($resName, $version) + { + $data = array( + 'code' => $resName, + 'data_version' => $version + ); + + if ($this->getDbVersion($resName) || $this->getDataVersion($resName)) { + self::$_dataVersions[$resName] = $version; + $this->_getWriteAdapter()->update($this->getMainTable(), $data, array('code = ?' => $resName)); + } else { + self::$_dataVersions[$resName] = $version; + $this->_getWriteAdapter()->insert($this->getMainTable(), $data); + } + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php new file mode 100644 index 0000000000..c29f0f3f5b --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -0,0 +1,266 @@ + + */ +class Mage_Core_Model_Resource_Session implements Zend_Session_SaveHandler_Interface +{ + /** + * Session lifetime + * + * @var integer + */ + protected $_lifeTime; + + /** + * Session data table name + * + * @var string + */ + protected $_sessionTable; + + /** + * Database read connection + * + * @var Varien_Db_Adapter_Interface + */ + protected $_read; + + /** + * Database write connection + * + * @var Varien_Db_Adapter_Interface + */ + protected $_write; + + /** + * Automatic cleaning factor of expired sessions + * value zero means no automatic cleaning, one means automatic cleaning each time a session is closed, and x>1 means + * cleaning once in x calls + * + * @var int + */ + protected $_automaticCleaningFactor = 50; + + /** + * Constructor + * + */ + public function __construct() + { + $resource = Mage::getSingleton('core/resource'); + $this->_sessionTable = $resource->getTableName('core/session'); + $this->_read = $resource->getConnection('core_read'); + $this->_write = $resource->getConnection('core_write'); + } + + /** + * Destrucor + * + */ + public function __destruct() + { + session_write_close(); + } + + /** + * Retrieve session life time + * + * @return int + */ + public function getLifeTime() + { + if (is_null($this->_lifeTime)) { + $configNode = Mage::app()->getStore()->isAdmin() ? 'admin/security/session_cookie_lifetime' : 'web/cookie/cookie_lifetime'; + $this->_lifeTime = (int) Mage::getStoreConfig($configNode); + + if ($this->_lifeTime < 60) { + $this->_lifeTime = ini_get('session.gc_maxlifetime'); + } + + if ($this->_lifeTime < 60) { + $this->_lifeTime = 3600; //one hour + } + } + return $this->_lifeTime; + } + + /** + * Check DB connection + * + * @return bool + */ + public function hasConnection() + { + if (!$this->_read) { + return false; + } + if (!$this->_read->isTableExists($this->_sessionTable)) { + return false; + } + + return true; + } + + /** + * Setup save handler + * + * @return Mage_Core_Model_Resource_Session + */ + public function setSaveHandler() + { + if ($this->hasConnection()) { + session_set_save_handler( + array($this, 'open'), + array($this, 'close'), + array($this, 'read'), + array($this, 'write'), + array($this, 'destroy'), + array($this, 'gc') + ); + } else { + session_save_path(Mage::getBaseDir('session')); + } + return $this; + } + + /** + * Open session + * + * @param string $savePath ignored + * @param string $sessName ignored + * @return boolean + */ + public function open($savePath, $sessName) + { + return true; + } + + /** + * Close session + * + * @return boolean + */ + public function close() + { + $this->gc($this->getLifeTime()); + + return true; + } + + /** + * Fetch session data + * + * @param string $sessId + * @return string + */ + public function read($sessId) + { + $select = $this->_read->select() + ->from($this->_sessionTable) + ->where('session_id = :session_id') + ->where('session_expires > :session_expires'); + $bind = array( + 'session_id' => $sessId, + 'session_expires' => Varien_Date::toTimestamp(true) + ); + + $data = $this->_read->fetchOne($select, $bind); + + return $data; + } + + /** + * Update session + * + * @param string $sessId + * @param string $sessData + * @return boolean + */ + public function write($sessId, $sessData) + { + $bindValues = array( + 'session_id' => $sessId + ); + $select = $this->_write->select() + ->from($this->_sessionTable) + ->where('session_id = :session_id'); + $exists = $this->_read->fetchOne($select, $bindValues); + + $bind = array( + 'session_expires' => Varien_Date::toTimestamp(true) + $this->getLifeTime(), + 'session_data' => $sessData + ); + if ($exists) { + $where = array( + 'session_id=?' => $sessId + ); + $this->_write->update($this->_sessionTable, $bind, $where); + } else { + $bind['session_id'] = $sessId; + $this->_write->insert($this->_sessionTable, $bind); + } + + return true; + } + + /** + * Destroy session + * + * @param string $sessId + * @return boolean + */ + public function destroy($sessId) + { + $where = array('session_id = ?' => $sessId); + $this->_write->delete($this->_sessionTable, $where); + return true; + } + + /** + * Garbage collection + * + * @param int $sessMaxLifeTime ignored + * @return boolean + */ + public function gc($sessMaxLifeTime) + { + if ($this->_automaticCleaningFactor > 0) { + if ($this->_automaticCleaningFactor == 1 || + rand(1, $this->_automaticCleaningFactor) == 1) { + $where = array('session_expires < ?' => Varien_Date::toTimestamp(true)); + $this->_write->delete($this->_sessionTable, $where); + } + } + return true; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Setup.php b/app/code/core/Mage/Core/Model/Resource/Setup.php index 3f56603e6a..f6be68fa50 100644 --- a/app/code/core/Mage/Core/Model/Resource/Setup.php +++ b/app/code/core/Mage/Core/Model/Resource/Setup.php @@ -20,25 +20,56 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Resource setup model + * Resource Setup Model * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ class Mage_Core_Model_Resource_Setup { - const DEFAULT_SETUP_CONNECTION = 'core_setup'; - const VERSION_COMPARE_EQUAL = 0; - const VERSION_COMPARE_LOWER = -1; - const VERSION_COMPARE_GREATER = 1; + const DEFAULT_SETUP_CONNECTION = 'core_setup'; + const VERSION_COMPARE_EQUAL = 0; + const VERSION_COMPARE_LOWER = -1; + const VERSION_COMPARE_GREATER = 1; + + const TYPE_DB_INSTALL = 'install'; + const TYPE_DB_UPGRADE = 'upgrade'; + const TYPE_DB_ROLLBACK = 'rollback'; + const TYPE_DB_UNINSTALL = 'uninstall'; + const TYPE_DATA_INSTALL = 'data-install'; + const TYPE_DATA_UPGRADE = 'data-upgrade'; + /** + * Setup resource name + * @var string + */ protected $_resourceName; + + /** + * Setup resource configuration object + * + * @var Varien_Simplexml_Object + */ protected $_resourceConfig; + + /** + * Connection configuration object + * + * @var Varien_Simplexml_Object + */ protected $_connectionConfig; + + /** + * Setup module configuration object + * + * @var Varien_Simplexml_Object + */ protected $_moduleConfig; /** @@ -54,18 +85,38 @@ class Mage_Core_Model_Resource_Setup * @var Varien_Db_Adapter_Pdo_Mysql */ protected $_conn; + /** + * Tables cache array + * + * @var array + */ protected $_tables = array(); + /** + * Tables data cache array + * + * @var array + */ protected $_setupCache = array(); /** - * Flag wich allow to detect that some schema update was applied dueting request + * Flag which allow to detect that some schema update was applied dueting request * * @var bool */ protected static $_hadUpdates; + /** + * Flag which allow run data install or upgrade + * + * @var bool + */ protected static $_schemaUpdatesChecked; + /** + * Initialize resource configurations, setup connection, etc + * + * @param string $resourceName the setup resource name + */ public function __construct($resourceName) { $config = Mage::getConfig(); @@ -85,7 +136,7 @@ public function __construct($resourceName) * If module setup configuration wasn't loaded */ if (!$connection) { - $connection = Mage::getSingleton('core/resource')->getConnection('core_setup'); + $connection = Mage::getSingleton('core/resource')->getConnection($this->_resourceName); } $this->_conn = $connection; } @@ -93,7 +144,7 @@ public function __construct($resourceName) /** * Get connection object * - * @return Varien_Db_Adapter_Pdo_Mysql + * @return Varien_Db_Adapter_Interface */ public function getConnection() { @@ -114,23 +165,39 @@ public function setTable($tableName, $realTableName) } /** - * Get table name by table placeholder + * Get table name (validated by db adapter) by table placeholder * - * @param string $tableName - * @return string + * @param string|array $tableName + * @return string */ public function getTable($tableName) { - if (!isset($this->_tables[$tableName])) { - $this->_tables[$tableName] = Mage::getSingleton('core/resource')->getTableName($tableName); + $cacheKey = $this->_getTableCacheName($tableName); + if (!isset($this->_tables[$cacheKey])) { + $this->_tables[$cacheKey] = Mage::getSingleton('core/resource')->getTableName($tableName); } - return $this->_tables[$tableName]; + return $this->_tables[$cacheKey]; + } + + /** + * Retrieve table name for cache + * + * @param string|array $tableName + * @return string + */ + protected function _getTableCacheName($tableName) + { + if (is_array($tableName)) { + return join('_', $tableName); + + } + return $tableName; } /** * Get core resource resource model * - * @return Mage_Core_Model_Mysql4_Resource + * @return Mage_Core_Model_Resource_Resource */ protected function _getResource() { @@ -140,7 +207,7 @@ protected function _getResource() /** * Apply database updates whenever needed * - * @return boolean + * @return boolean */ static public function applyAllUpdates() { @@ -149,7 +216,7 @@ static public function applyAllUpdates() $resources = Mage::getConfig()->getNode('global/resources')->children(); $afterApplyUpdates = array(); - foreach ($resources as $resName=>$resource) { + foreach ($resources as $resName => $resource) { if (!$resource->setup) { continue; } @@ -175,6 +242,7 @@ static public function applyAllUpdates() /** * Apply database data updates whenever needed + * */ static public function applyAllDataUpdates() { @@ -182,7 +250,7 @@ static public function applyAllDataUpdates() return; } $resources = Mage::getConfig()->getNode('global/resources')->children(); - foreach ($resources as $resName=>$resource) { + foreach ($resources as $resName => $resource) { if (!$resource->setup) { continue; } @@ -213,17 +281,20 @@ public function applyDataUpdates() } elseif ($configVer) { $this->_installData($configVer); } + return $this; } /** * Apply module resource install, upgrade and data scripts + * + * @return Mage_Core_Model_Resource_Setup */ public function applyUpdates() { $dbVer = $this->_getResource()->getDbVersion($this->_resourceName); $configVer = (string)$this->_moduleConfig->version; // Module is installed - if ($dbVer!==false) { + if ($dbVer !== false) { $status = version_compare($configVer, $dbVer); switch ($status) { case self::VERSION_COMPARE_LOWER: @@ -239,18 +310,22 @@ public function applyUpdates() } elseif ($configVer) { $this->_installResourceDb($configVer); } + return $this; } /** * Run data install scripts * * @param string $newVersion + * @return Mage_Core_Model_Resource_Setup */ protected function _installData($newVersion) { - $oldVersion = $this->_modifyResourceDb('data-install', '', $newVersion); - $this->_modifyResourceDb('data-upgrade', $oldVersion, $newVersion); + $oldVersion = $this->_modifyResourceDb(self::TYPE_DATA_INSTALL, '', $newVersion); + $this->_modifyResourceDb(self::TYPE_DATA_UPGRADE, $oldVersion, $newVersion); $this->_getResource()->setDataVersion($this->_resourceName, $newVersion); + + return $this; } /** @@ -258,24 +333,29 @@ protected function _installData($newVersion) * * @param string $oldVersion * @param string $newVersion + * @return Mage_Core_Model_Resource_Setup */ protected function _upgradeData($oldVersion, $newVersion) { - $appliedVersion = $this->_modifyResourceDb('data-upgrade', $oldVersion, $newVersion); + $this->_modifyResourceDb('data-upgrade', $oldVersion, $newVersion); $this->_getResource()->setDataVersion($this->_resourceName, $newVersion); + + return $this; } /** * Run resource installation file * - * @param string $version - * @return boolean + * @param string $newVersion + * @return Mage_Core_Model_Resource_Setup */ protected function _installResourceDb($newVersion) { - $oldVersion = $this->_modifyResourceDb('install', '', $newVersion); - $this->_modifyResourceDb('upgrade', $oldVersion, $newVersion); + $oldVersion = $this->_modifyResourceDb(self::TYPE_DB_INSTALL, '', $newVersion); + $this->_modifyResourceDb(self::TYPE_DB_UPGRADE, $oldVersion, $newVersion); $this->_getResource()->setDbVersion($this->_resourceName, $newVersion); + + return $this; } /** @@ -283,166 +363,279 @@ protected function _installResourceDb($newVersion) * * @param string $oldVersion * @param string $newVersion + * @return Mage_Core_Model_Resource_Setup */ protected function _upgradeResourceDb($oldVersion, $newVersion) { - $this->_modifyResourceDb('upgrade', $oldVersion, $newVersion); + $this->_modifyResourceDb(self::TYPE_DB_UPGRADE, $oldVersion, $newVersion); $this->_getResource()->setDbVersion($this->_resourceName, $newVersion); + + return $this; } /** * Roll back resource * - * @param string $newVersion - * @return bool + * @param string $newVersion + * @param string $oldVersion + * @return Mage_Core_Model_Resource_Setup */ - protected function _rollbackResourceDb($newVersion, $oldVersion) { - $this->_modifyResourceDb('rollback', $newVersion, $oldVersion); + $this->_modifyResourceDb(self::TYPE_DB_ROLLBACK, $newVersion, $oldVersion); + return $this; } /** * Uninstall resource * - * @param $version existing resource version - * @return bool + * @param string $version existing resource version + * @return Mage_Core_Model_Resource_Setup */ - protected function _uninstallResourceDb($version) { - $this->_modifyResourceDb('uninstall', $version, ''); + $this->_modifyResourceDb(self::TYPE_DB_UNINSTALL, $version, ''); + return $this; } /** - * Run module modification files. Return version of last applied upgrade (false if no upgrades applied) + * Retrieve available Database install/upgrade files for current module * - * @param string $actionType install|upgrade|uninstall - * @param string $fromVersion - * @param string $toVersion - * @return string | false + * @param string $actionType + * @param string $fromVersion + * @param string $toVersion + * @return array */ - - protected function _modifyResourceDb($actionType, $fromVersion, $toVersion) + protected function _getAvailableDbFiles($actionType, $fromVersion, $toVersion) { - $resModel = (string)$this->_connectionConfig->model; - $modName = (string)$this->_moduleConfig[0]->getName(); + $resModel = (string)$this->_connectionConfig->model; + $modName = (string)$this->_moduleConfig[0]->getName(); - $sqlFilesDir = Mage::getModuleDir('sql', $modName).DS.$this->_resourceName; - if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) { - return false; + $filesDir = Mage::getModuleDir('sql', $modName) . DS . $this->_resourceName; + if (!is_dir($filesDir) || !is_readable($filesDir)) { + return array(); } - // Read resource files - $arrAvailableFiles = array(); - $sqlDir = dir($sqlFilesDir); - while (false !== ($sqlFile = $sqlDir->read())) { + + $dbFiles = array(); + $typeFiles = array(); + $regExpDb = sprintf('#^%s-(.*)\.(php|sql)$#i', $actionType); + $regExpType = sprintf('#^%s-%s-(.*)\.(php|sql)$#i', $resModel, $actionType); + $handlerDir = dir($filesDir); + while (false !== ($file = $handlerDir->read())) { $matches = array(); - if (preg_match('#^'.$resModel.'-'.$actionType.'-(.*)\.(sql|php)$#i', $sqlFile, $matches)) { - $arrAvailableFiles[$matches[1]] = $sqlFile; + if (preg_match($regExpDb, $file, $matches)) { + $dbFiles[$matches[1]] = $filesDir . DS . $file; + } else if (preg_match($regExpType, $file, $matches)) { + $typeFiles[$matches[1]] = $filesDir . DS . $file; } } - $sqlDir->close(); - if (empty($arrAvailableFiles)) { - return false; + $handlerDir->close(); + + if (empty($typeFiles) && empty($dbFiles)) { + return array(); } - // Get SQL files name - $arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles); - if (empty($arrModifyFiles)) { - return false; + foreach ($typeFiles as $version => $file) { + $dbFiles[$version] = $file; } - $modifyVersion = false; - foreach ($arrModifyFiles as $resourceFile) { - $sqlFile = $sqlFilesDir.DS.$resourceFile['fileName']; - $fileType = pathinfo($resourceFile['fileName'], PATHINFO_EXTENSION); - // Execute SQL - if ($this->_conn) { - if (method_exists($this->_conn, 'disallowDdlCache')) { - $this->_conn->disallowDdlCache(); + return $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $dbFiles); + } + + /** + * Retrieve available Data install/upgrade files for current module + * + * @param string $actionType + * @param string $fromVersion + * @param string $toVersion + * @return array + */ + protected function _getAvailableDataFiles($actionType, $fromVersion, $toVersion) + { + $modName = (string)$this->_moduleConfig[0]->getName(); + $files = array(); + + $filesDir = Mage::getModuleDir('data', $modName) . DS . $this->_resourceName; + if (is_dir($filesDir) && is_readable($filesDir)) { + $regExp = sprintf('#^%s-(.*)\.php$#i', $actionType); + $handlerDir = dir($filesDir); + while (false !== ($file = $handlerDir->read())) { + $matches = array(); + if (preg_match($regExp, $file, $matches)) { + $files[$matches[1]] = $filesDir . DS . $file; } - try { - switch ($fileType) { - case 'sql': - $sql = file_get_contents($sqlFile); - if ($sql!='') { - $result = $this->run($sql); - } else { - $result = true; - } - break; - case 'php': - $conn = $this->_conn; - $result = include($sqlFile); - break; - default: - $result = false; - } - if ($result) { - if (strpos($actionType, 'data-') !== false) { - $this->_getResource()->setDataVersion($this->_resourceName, $resourceFile['toVersion']); + + } + $handlerDir->close(); + } + + // search data files in old location + $filesDir = Mage::getModuleDir('sql', $modName) . DS . $this->_resourceName; + if (is_dir($filesDir) && is_readable($filesDir)) { + $regExp = sprintf('#^%s-%s-(.*)\.php$#i', $this->_connectionConfig->model, $actionType); + $handlerDir = dir($filesDir); + + while (false !== ($file = $handlerDir->read())) { + $matches = array(); + if (preg_match($regExp, $file, $matches)) { + $files[$matches[1]] = $filesDir . DS . $file; + } + } + $handlerDir->close(); + } + + if (empty($files)) { + return array(); + } + + return $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $files); + } + + /** + * Save resource version + * + * @param string $actionType + * @param string $version + * @return Mage_Core_Model_Resource_Setup + */ + protected function _setResourceVersion($actionType, $version) + { + switch ($actionType) { + case self::TYPE_DB_INSTALL: + case self::TYPE_DB_UPGRADE: + $this->_getResource()->setDbVersion($this->_resourceName, $version); + break; + case self::TYPE_DATA_INSTALL: + case self::TYPE_DATA_UPGRADE: + $this->_getResource()->setDataVersion($this->_resourceName, $version); + break; + + } + + return $this; + } + + /** + * Run module modification files. Return version of last applied upgrade (false if no upgrades applied) + * + * @param string $actionType self::TYPE_* + * @param string $fromVersion + * @param string $toVersion + * @return string|false + * @throws Mage_Core_Exception + */ + + protected function _modifyResourceDb($actionType, $fromVersion, $toVersion) + { + switch ($actionType) { + case self::TYPE_DB_INSTALL: + case self::TYPE_DB_UPGRADE: + $files = $this->_getAvailableDbFiles($actionType, $fromVersion, $toVersion); + break; + case self::TYPE_DATA_INSTALL: + case self::TYPE_DATA_UPGRADE: + $files = $this->_getAvailableDataFiles($actionType, $fromVersion, $toVersion); + break; + default: + $files = array(); + break; + } + if (empty($files) || !$this->getConnection()) { + return false; + } + + $version = false; + + foreach ($files as $file) { + $fileName = $file['fileName']; + $fileType = pathinfo($fileName, PATHINFO_EXTENSION); + $this->getConnection()->disallowDdlCache(); + try { + switch ($fileType) { + case 'php': + $conn = $this->getConnection(); + $result = include $fileName; + break; + case 'sql': + $sql = file_get_contents($fileName); + if (!empty($sql)) { + + $result = $this->run($sql); } else { - $this->_getResource()->setDbVersion($this->_resourceName, $resourceFile['toVersion']); + $result = true; } - } - } catch (Exception $e){ - echo "
".print_r($e,1)."
"; - throw Mage::exception('Mage_Core', Mage::helper('core')->__('Error in file: "%s" - %s', $sqlFile, $e->getMessage())); + break; + default: + $result = false; + break; } - if (method_exists($this->_conn, 'allowDdlCache')) { - $this->_conn->allowDdlCache(); + + if ($result) { + $this->_setResourceVersion($actionType, $file['toVersion']); } + } catch (Exception $e) { + printf('
%s
', print_r($e, true)); + throw Mage::exception('Mage_Core', Mage::helper('core')->__('Error in file: "%s" - %s', $fileName, $e->getMessage())); } - $modifyVersion = $resourceFile['toVersion']; + $version = $file['toVersion']; + $this->getConnection()->allowDdlCache(); } self::$_hadUpdates = true; - return $modifyVersion; + return $version; } /** - * Get sql files for modifications + * Get data files for modifications * - * @param $actionType - * @return array + * @param string $actionType + * @param string $fromVersion + * @param string $toVersion + * @param array $arrFiles + * @return array */ protected function _getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrFiles) { $arrRes = array(); - switch ($actionType) { - case 'install': - case 'data-install': + case self::TYPE_DB_INSTALL: + case self::TYPE_DATA_INSTALL: uksort($arrFiles, 'version_compare'); foreach ($arrFiles as $version => $file) { - if (version_compare($version, $toVersion)!==self::VERSION_COMPARE_GREATER) { - $arrRes[0] = array('toVersion'=>$version, 'fileName'=>$file); + if (version_compare($version, $toVersion) !== self::VERSION_COMPARE_GREATER) { + $arrRes[0] = array( + 'toVersion' => $version, + 'fileName' => $file + ); } } break; - case 'upgrade': - case 'data-upgrade': + case self::TYPE_DB_UPGRADE: + case self::TYPE_DATA_UPGRADE: uksort($arrFiles, 'version_compare'); foreach ($arrFiles as $version => $file) { - $version_info = explode('-', $version); + $versionInfo = explode('-', $version); // In array must be 2 elements: 0 => version from, 1 => version to - if (count($version_info)!=2) { + if (count($versionInfo)!=2) { break; } - $infoFrom = $version_info[0]; - $infoTo = $version_info[1]; - if (version_compare($infoFrom, $fromVersion)!==self::VERSION_COMPARE_LOWER - && version_compare($infoTo, $toVersion)!==self::VERSION_COMPARE_GREATER) { - $arrRes[] = array('toVersion'=>$infoTo, 'fileName'=>$file); + $infoFrom = $versionInfo[0]; + $infoTo = $versionInfo[1]; + if (version_compare($infoFrom, $fromVersion) !== self::VERSION_COMPARE_LOWER + && version_compare($infoTo, $toVersion) !== self::VERSION_COMPARE_GREATER) { + $arrRes[] = array( + 'toVersion' => $infoTo, + 'fileName' => $file + ); } } break; - case 'rollback': + case self::TYPE_DB_ROLLBACK: break; - case 'uninstall': + case self::TYPE_DB_UNINSTALL: break; } return $arrRes; @@ -464,48 +657,60 @@ protected function _getModifySqlFiles($actionType, $fromVersion, $toVersion, $ar */ public function getTableRow($table, $idField, $id, $field=null, $parentField=null, $parentId=0) { - if (strpos($table, '/')!==false) { + if (strpos($table, '/') !== false) { $table = $this->getTable($table); } if (empty($this->_setupCache[$table][$parentId][$id])) { - $sql = "select * from $table where $idField=?"; + $adapter = $this->getConnection(); + $bind = array('id_field' => $id); + $select = $adapter->select() + ->from($table) + ->where($adapter->quoteIdentifier($idField) . '= :id_field'); if (!is_null($parentField)) { - $sql .= $this->_conn->quoteInto(" and $parentField=?", $parentId); + $select->where($adapter->quoteIdentifier($parentField) . '= :parent_id'); + $bind['parent_id'] = $parentId; } - $this->_setupCache[$table][$parentId][$id] = $this->_conn->fetchRow($sql, $id); + $this->_setupCache[$table][$parentId][$id] = $adapter->fetchRow($select, $bind); } + if (is_null($field)) { return $this->_setupCache[$table][$parentId][$id]; } - return isset($this->_setupCache[$table][$parentId][$id][$field]) ? $this->_setupCache[$table][$parentId][$id][$field] : false; + return isset($this->_setupCache[$table][$parentId][$id][$field]) + ? $this->_setupCache[$table][$parentId][$id][$field] + : false; } - /** + + /** * Delete table row * - * @param string $table - * @param string $idField - * @param string|int $id - * @param null|string $parentField - * @param int|string $parentId - * @return Mage_Core_Model_Resource_Setup + * @param string $table + * @param string $idField + * @param string|int $id + * @param null|string $parentField + * @param int|string $parentId + * @return Mage_Core_Model_Resource_Setup */ - public function deleteTableRow($table, $idField, $id, $parentField=null, $parentId=0) + public function deleteTableRow($table, $idField, $id, $parentField = null, $parentId = 0) { - if (strpos($table, '/')!==false) { + if (strpos($table, '/') !== false) { $table = $this->getTable($table); } - $condition = $this->_conn->quoteInto("$idField=?", $id); - if ($parentField !== null) { - $condition.= $this->_conn->quoteInto(" AND $parentField=?", $parentId); + $adapter = $this->getConnection(); + $where = array($adapter->quoteIdentifier($idField) . '=?' => $id); + if (!is_null($parentField)) { + $where[$adapter->quoteIdentifier($parentField) . '=?'] = $parentId; } - $this->_conn->delete($table, $condition); + + $adapter->delete($table, $where); if (isset($this->_setupCache[$table][$parentId][$id])) { unset($this->_setupCache[$table][$parentId][$id]); } + return $this; } @@ -521,25 +726,21 @@ public function deleteTableRow($table, $idField, $id, $parentField=null, $parent * @param string|integer $parentId * @return Mage_Eav_Model_Entity_Setup */ - public function updateTableRow($table, $idField, $id, $field, $value=null, $parentField=null, $parentId=0) + public function updateTableRow($table, $idField, $id, $field, $value = null, $parentField = null, $parentId = 0) { - if (is_array($field)) { - $updateArr = array(); - foreach ($field as $f=>$v) { - $updateArr[] = $this->_conn->quoteInto("$f=?", $v); - } - $updateStr = join(', ', $updateArr); - } else { - $updateStr = $this->_conn->quoteInto("$field=?", $value); - } - if (strpos($table, '/')!==false) { + if (strpos($table, '/') !== false) { $table = $this->getTable($table); } - $sql = "update $table set $updateStr where ".$this->_conn->quoteInto("$idField=?", $id); - if (!is_null($parentField)) { - $sql .= $this->_conn->quoteInto(" and $parentField=?", $parentId); + + if (is_array($field)) { + $data = $field; + } else { + $data = array($field => $value); } - $this->_conn->query($sql); + + $adapter = $this->getConnection(); + $where = array($adapter->quoteIdentifier($idField) . '=?' => $id); + $adapter->update($table, $data, $where); if (isset($this->_setupCache[$table][$parentId][$id])) { if (is_array($field)) { @@ -552,110 +753,169 @@ public function updateTableRow($table, $idField, $id, $field, $value=null, $pare return $this; } + /** + * Update table data + * + * @param string $table + * @param Zend_Db_Expr $conditionExpr + * @param Zend_Db_Expr $valueExpr + * @return Mage_Core_Model_Resource_Setup + * + * @deprecated since 1.4.0.1 + */ public function updateTable($table, $conditionExpr, $valueExpr) { - if (strpos($table, '/')!==false) { + if (strpos($table, '/') !== false) { $table = $this->getTable($table); } - $sql = 'update ' . $table . ' set ' . $valueExpr . ' where ' . $conditionExpr; - $this->_conn->query($sql); + $query = sprintf('UPDATE %s SET %s WHERE %s', + $this->getConnection()->quoteIdentifier($table), + $conditionExpr, + $valueExpr); + + $this->getConnection()->query($query); + return $this; } + /** + * Check is table exists + * + * @param string $table + * @return bool + */ public function tableExists($table) { - $select = $this->getConnection()->quoteInto('SHOW TABLES LIKE ?', $table); - $result = $this->getConnection()->fetchOne($select); - return !empty($result); + if (strpos($table, '/') !== false) { + $table = $this->getTable($table); + } + + return $this->getConnection()->isTableExists($table); + } /******************* CONFIG *****************/ + /** + * Undefined + * + * @param string $path + * @param string $label + * @param array $data + * @param string $default + * @return Mage_Core_Model_Resource_Setup + * @deprecated since 1.4.0.1 + */ public function addConfigField($path, $label, array $data=array(), $default=null) { - $data['level'] = sizeof(explode('/', $path)); - $data['path'] = $path; - $data['frontend_label'] = $label; - if ($id = $this->getTableRow('core/config_field', 'path', $path, 'field_id')) { - $this->updateTableRow('core/config_field', 'field_id', $id, $data); - } else { - if (empty($data['sort_order'])) { - $sql = "select max(sort_order) cnt from ".$this->getTable('core/config_field')." where level=".($data['level']+1); - if ($data['level']>1) { - $sql.= $this->_conn->quoteInto(" and path like ?", dirname($path).'/%'); - } - - $result = $this->_conn->raw_fetchRow($sql); - $this->_conn->fetchAll($sql); -#print_r($result); die; - $data['sort_order'] = $result['cnt']+1; -/* -// Triggers "Command out of sync" mysql error for next statement!?!? - $data['sort_order'] = $this->_conn->fetchOne("select max(sort_order) - from ".$this->getTable('core/config_field')." - where level=?".$parentWhere, $data['level'])+1; -*/ - } - - #$this->_conn->raw_query("insert into ".$this->getTable('core/config_field')." (".join(',', array_keys($data)).") values ('".join("','", array_values($data))."')"); - $this->_conn->insert($this->getTable('core/config_field'), $data); - } - - if (!is_null($default)) { - $this->setConfigData($path, $default); - } return $this; } - public function setConfigData($path, $value, $scope='default', $scopeId=0, $inherit=0) + /** + * Save configuration data + * + * @param string $path + * @param string $value + * @param int|string $scope + * @param int $scopeId + * @param int $inherit + * @return Mage_Core_Model_Resource_Setup + */ + public function setConfigData($path, $value, $scope = 'default', $scopeId = 0, $inherit=0) { - $this->_conn->showTableStatus($this->getTable('core/config_data')); // this is a fix for mysql 4.1 - $this->_conn->raw_query("replace into ".$this->getTable('core/config_data')." (scope, scope_id, path, value) values ('$scope', $scopeId, '$path', '$value')"); + $table = $this->getTable('core/config_data'); + // this is a fix for mysql 4.1 + $this->getConnection()->showTableStatus($table); + + $data = array( + 'scope' => $scope, + 'scope_id' => $scopeId, + 'path' => $path, + 'value' => $value + ); + $this->getConnection()->insertOnDuplicate($table, $data, array('value')); return $this; } /** * Delete config field values * - * @param string $path - * @param string $scope (default|stores|websites|config) - * @return Mage_Core_Model_Resource_Setup + * @param string $path + * @param string $scope (default|stores|websites|config) + * @return Mage_Core_Model_Resource_Setup */ - public function deleteConfigData($path, $scope=null) + public function deleteConfigData($path, $scope = null) { - $sql = "delete from ".$this->getTable('core/config_data')." where path='".$path."'"; - if ($scope) { - $sql.= " and scope='".$scope."'"; + $where = array('path = ?' => $path); + if (!is_null($scope)) { + $where['scope = ?'] = $scope; } - $this->_conn->raw_query($sql); + $this->getConnection()->delete($this->getTable('core/config_data'), $where); return $this; } + /** + * Run plain SQL query(ies) + * + * @param string $sql + * @return Mage_Core_Model_Resource_Setup + */ public function run($sql) { - $this->_conn->multi_query($sql); + $this->getConnection()->multiQuery($sql); return $this; } + /** + * Prepare database before install/upgrade + * + * @return Mage_Core_Model_Resource_Setup + */ public function startSetup() { - $this->_conn->multi_query("SET SQL_MODE=''; -SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; -SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'; -"); - + $this->getConnection()->startSetup(); return $this; } + /** + * Prepare database after install/upgrade + * + * @return Mage_Core_Model_Resource_Setup + */ public function endSetup() { - $this->_conn->multi_query(" -SET SQL_MODE=IFNULL(@OLD_SQL_MODE,''); -SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS=0, 0, 1); -"); + $this->getConnection()->endSetup(); return $this; } + /** + * Retrieve 32bit UNIQUE HASH for a Table index + * + * @param string $tableName + * @param array|string $fields + * @param string $indexType + * @return string + */ + public function getIdxName($tableName, $fields, $indexType = '') + { + return Mage::getSingleton('core/resource')->getIdxName($tableName, $fields, $indexType); + } + + /** + * Retrieve 32bit UNIQUE HASH for a Table foreign key + * + * @param string $priTableName the target table name + * @param string $priColumnName the target table column name + * @param string $refTableName the reference table name + * @param string $refColumnName the reference table column name + * @return string + */ + public function getFkName($priTableName, $priColumnName, $refTableName, $refColumnName) + { + return Mage::getSingleton('core/resource') + ->getFkName($priTableName, $priColumnName, $refTableName, $refColumnName); + } + /** * Check call afterApplyAllUpdates method for setup class * diff --git a/app/code/core/Mage/Core/Model/Resource/Store.php b/app/code/core/Mage/Core/Model/Resource/Store.php new file mode 100644 index 0000000000..59422745bf --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Store.php @@ -0,0 +1,175 @@ + + */ +class Mage_Core_Model_Resource_Store extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and primary key + * + */ + protected function _construct() + { + $this->_init('core/store', 'store_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Core_Model_Resource_Store + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => 'code', + 'title' => Mage::helper('core')->__('Store with the same code') + )); + return $this; + } + + /** + * Check store code before save + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Store + */ + protected function _beforeSave(Mage_Core_Model_Abstract $model) + { + if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $model->getCode())) { + Mage::throwException( + Mage::helper('core')->__('The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter')); + } + + return $this; + } + + /** + * Update Store Group data after save store + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Store + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + parent::_afterSave($object); + $this->_updateGroupDefaultStore($object->getGroupId(), $object->getId()); + $this->_changeGroup($object); + + return $this; + } + + /** + * Remove core configuration data after delete store + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Store + */ + protected function _afterDelete(Mage_Core_Model_Abstract $model) + { + $where = array( + 'scope = ?' => 'stores', + 'scope_id = ?' => $model->getStoreId() + ); + + $this->_getWriteAdapter()->delete( + $this->getTable('core/config_data'), + $where + ); + return $this; + } + + /** + * Update Default store for Store Group + * + * @param int $groupId + * @param int $storeId + * @return Mage_Core_Model_Resource_Store + */ + protected function _updateGroupDefaultStore($groupId, $storeId) + { + $adapter = $this->_getWriteAdapter(); + + $bindValues = array('group_id' => (int)$groupId); + $select = $adapter->select() + ->from($this->getMainTable(), array('count' => 'COUNT(*)')) + ->where('group_id = :group_id'); + $count = $adapter->fetchOne($select, $bindValues); + + if ($count == 1) { + $bind = array('default_store_id' => (int)$storeId); + $where = array('group_id = ?' => (int)$groupId); + $adapter->update($this->getTable('core/store_group'), $bind, $where); + } + + return $this; + } + + /** + * Change store group for store + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Store + */ + protected function _changeGroup(Mage_Core_Model_Abstract $model) + { + if ($model->getOriginalGroupId() && $model->getGroupId() != $model->getOriginalGroupId()) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('core/store_group'), 'default_store_id') + ->where($adapter->quoteInto('group_id=?', $model->getOriginalGroupId())); + $storeId = $adapter->fetchOne($select, 'default_store_id'); + + if ($storeId == $model->getId()) { + $bind = array('default_store_id' => Mage_Core_Model_App::ADMIN_STORE_ID); + $where = array('group_id = ?' => $model->getOriginalGroupId()); + $this->_getWriteAdapter()->update($this->getTable('core/store_group'), $bind, $where); + } + } + return $this; + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $select->order('sort_order'); + return $select; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Store/Collection.php b/app/code/core/Mage/Core/Model/Resource/Store/Collection.php new file mode 100644 index 0000000000..9cf66732e8 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Store/Collection.php @@ -0,0 +1,209 @@ + + */ +class Mage_Core_Model_Resource_Store_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Load default flag + * + * @deprecated since 1.5.0.0 + * @var boolean + */ + protected $_loadDefault = false; + + /** + * Define resource model + * + */ + protected function _construct() + { + $this->setFlag('load_default_store', false); + $this->_init('core/store'); + } + + /** + * Set flag for load default (admin) store + * + * @param boolean $loadDefault + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function setLoadDefault($loadDefault) + { + $this->setFlag('load_default_store', (bool)$loadDefault); + return $this; + } + + /** + * Is load default (admin) store + * + * @return boolean + */ + public function getLoadDefault() + { + return $this->getFlag('load_default_store'); + } + + /** + * Add disable default store filter to collection + * + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function setWithoutDefaultFilter() + { + $this->addFieldToFilter('main_table.store_id', array('gt' => 0)); + return $this; + } + + /** + * Add filter by group id. + * Group id can be passed as one single value or array of values. + * + * @param int|array $groupId + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addGroupFilter($groupId) + { + return $this->addFieldToFilter('main_table.group_id', array('in' => $groupId)); + } + + /** + * Add store id(s) filter to collection + * + * @param int|array $store + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addIdFilter($store) + { + return $this->addFieldToFilter('main_table.store_id', array('in' => $store)); + } + + /** + * Add filter by website to collection + * + * @param int|array $website + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addWebsiteFilter($website) + { + return $this->addFieldToFilter('main_table.website_id', array('in' => $website)); + } + + /** + * Add root category id filter to store collection + * + * @param int|array $category + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addCategoryFilter($category) + { + if (!is_array($category)) { + $category = array($category); + } + return $this->loadByCategoryIds($category); + } + + /** + * Convert items array to array for select options + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('store_id', 'name'); + } + + /** + * Convert items array to hash for select options + * + * @return array + */ + public function toOptionHash() + { + return $this->_toOptionHash('store_id', 'name'); + } + + /** + * Load collection data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if (!$this->getLoadDefault()) { + $this->setWithoutDefaultFilter(); + } + + if (!$this->isLoaded()) { + $this->addOrder('CASE WHEN main_table.store_id = 0 THEN 0 ELSE 1 END', Varien_Db_Select::SQL_ASC) + ->addOrder('main_table.sort_order', Varien_Db_Select::SQL_ASC) + ->addOrder('main_table.name', Varien_Db_Select::SQL_ASC); + } + return parent::load($printQuery, $logQuery); + } + + /** + * Add root category id filter to store collection + * + * @param array $categories + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function loadByCategoryIds(array $categories) + { + $this->addRootCategoryIdAttribute(); + $this->addFieldToFilter('group_table.root_category_id', array('in' => $categories)); + + return $this; + } + + /** + * Add store root category data to collection + * + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addRootCategoryIdAttribute() + { + if (!$this->getFlag('core_store_group_table_joined')) { + $this->getSelect()->join( + array('group_table' => $this->getTable('core/store_group')), + 'main_table.group_id = group_table.group_id', + array('root_category_id') + ); + $this->setFlag('core_store_group_table_joined', true); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Store/Group.php b/app/code/core/Mage/Core/Model/Resource/Store/Group.php new file mode 100644 index 0000000000..1c06a28318 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Store/Group.php @@ -0,0 +1,136 @@ + + */ +class Mage_Core_Model_Resource_Store_Group extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/store_group', 'group_id'); + } + + /** + * Update default store group for website + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Store_Group + */ + protected function _afterSave(Mage_Core_Model_Abstract $model) + { + $this->_updateStoreWebsite($model->getId(), $model->getWebsiteId()); + $this->_updateWebsiteDefaultGroup($model->getWebsiteId(), $model->getId()); + $this->_changeWebsite($model); + + return $this; + } + + /** + * Update default store group for website + * + * @param int $websiteId + * @param int $groupId + * @return Mage_Core_Model_Resource_Store_Group + */ + protected function _updateWebsiteDefaultGroup($websiteId, $groupId) + { + $select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable(), 'COUNT(*)') + ->where('website_id = :website'); + $count = $this->_getWriteAdapter()->fetchOne($select, array('website' => $websiteId)); + + if ($count == 1) { + $bind = array('default_group_id' => $groupId); + $where = array('website_id = ?' => $websiteId); + $this->_getWriteAdapter()->update($this->getTable('core/website'), $bind, $where); + } + return $this; + } + + /** + * Change store group website + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Store_Group + */ + protected function _changeWebsite(Mage_Core_Model_Abstract $model) + { + if ($model->getOriginalWebsiteId() && $model->getWebsiteId() != $model->getOriginalWebsiteId()) { + $select = $this->_getWriteAdapter()->select() + ->from($this->getTable('core/website'), 'default_group_id') + ->where('website_id = :website_id'); + $groupId = $this->_getWriteAdapter()->fetchOne($select, array('website_id' => $model->getOriginalWebsiteId())); + + if ($groupId == $model->getId()) { + $bind = array('default_group_id' => 0); + $where = array('website_id = ?' => $model->getOriginalWebsiteId()); + $this->_getWriteAdapter()->update($this->getTable('core/website'), $bind, $where); + } + } + return $this; + } + + /** + * Update website for stores that assigned to store group + * + * @param int $groupId + * @param int $websiteId + * @return Mage_Core_Model_Resource_Store_Group + */ + protected function _updateStoreWebsite($groupId, $websiteId) + { + $bind = array('website_id' => $websiteId); + $where = array('group_id = ?' => $groupId); + $this->_getWriteAdapter()->update($this->getTable('core/store'), $bind, $where); + return $this; + } + + /** + * Save default store for store group + * + * @param int $groupId + * @param int $storeId + * @return Mage_Core_Model_Resource_Store_Group + */ + protected function _saveDefaultStore($groupId, $storeId) + { + $bind = array('default_store_id' => $storeId); + $where = array('group_id = ?' => $groupId); + $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Store/Group/Collection.php b/app/code/core/Mage/Core/Model/Resource/Store/Group/Collection.php new file mode 100644 index 0000000000..8d76c4672d --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Store/Group/Collection.php @@ -0,0 +1,125 @@ + + */ +class Mage_Core_Model_Resource_Store_Group_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Load default flag + * + * @deprecated since 1.5.0.0 + * @var boolean + */ + protected $_loadDefault = false; + + /** + * Define resource model + * + */ + protected function _construct() + { + $this->setFlag('load_default_store_group', false); + $this->_init('core/store_group'); + } + + /** + * Set flag for load default (admin) store + * + * @param boolean $loadDefault + * @return Mage_Core_Model_Resource_Store_Group_Collection + */ + public function setLoadDefault($loadDefault) + { + $this->setFlag('load_default_store_group', (bool)$loadDefault); + return $this; + } + + /** + * Is load default (admin) store + * + * @return boolean + */ + public function getLoadDefault() + { + return $this->getFlag('load_default_store_group'); + } + + /** + * Add disable default store group filter to collection + * + * @return Mage_Core_Model_Resource_Store_Group_Collection + */ + public function setWithoutDefaultFilter() + { + $this->addFieldToFilter('main_table.group_id', array('gt' => 0)); + return $this; + } + + /** + * Load collection data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Core_Model_Resource_Store_Group_Collection + */ + public function _beforeLoad() + { + if (!$this->getLoadDefault()) { + $this->setWithoutDefaultFilter(); + } + $this->addOrder('main_table.name', self::SORT_ORDER_ASC); + return $this; + } + + /** + * Convert collection items to array for select options + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('group_id', 'name'); + } + + /** + * Add filter by website to collection + * + * @param int|array $website + * @return Mage_Core_Model_Resource_Store_Collection + */ + public function addWebsiteFilter($website) + { + return $this->addFieldToFilter('main_table.website_id', array('in' => $website)); + } + +} diff --git a/app/code/core/Mage/Core/Model/Resource/Transaction.php b/app/code/core/Mage/Core/Model/Resource/Transaction.php index 3d13ffbcba..5fed71dc03 100644 --- a/app/code/core/Mage/Core/Model/Resource/Transaction.php +++ b/app/code/core/Mage/Core/Model/Resource/Transaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -110,9 +110,9 @@ protected function _runCallbacks() /** * Adding object for using in transaction * - * @param Mage_Core_Model_Abstract $object - * @param string $alias - * @return Mage_Core_Model_Resource_Transaction + * @param Mage_Core_Model_Abstract $object + * @param string $alias + * @return Mage_Core_Model_Resource_Transaction */ public function addObject(Mage_Core_Model_Abstract $object, $alias='') { @@ -124,10 +124,10 @@ public function addObject(Mage_Core_Model_Abstract $object, $alias='') } /** - * Add callback funtion which will be called befor commit transactions + * Add callback function which will be called before commit transactions * - * @param callback $callback - * @return Mage_Core_Model_Resource_Transaction + * @param callback $callback + * @return Mage_Core_Model_Resource_Transaction */ public function addCommitCallback($callback) { @@ -139,6 +139,7 @@ public function addCommitCallback($callback) * Initialize objects save transaction * * @return Mage_Core_Model_Resource_Transaction + * @throws Exception */ public function save() { @@ -175,11 +176,12 @@ public function save() * Initialize objects delete transaction * * @return Mage_Core_Model_Resource_Transaction + * @throws Exception */ public function delete() { $this->_startTransaction(); - $error = false; + $error = false; try { foreach ($this->_objects as $object) { diff --git a/app/code/core/Mage/Core/Model/Resource/Translate.php b/app/code/core/Mage/Core/Model/Resource/Translate.php new file mode 100644 index 0000000000..fc1e8d0a70 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Translate.php @@ -0,0 +1,129 @@ + + */ +class Mage_Core_Model_Resource_Translate extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/translate', 'key_id'); + } + + /** + * Retrieve translation array for store / locale code + * + * @param int $storeId + * @param string|Zend_Locale $locale + * @return array + */ + public function getTranslationArray($storeId = null, $locale = null) + { + if (!Mage::isInstalled()) { + return array(); + } + + if (is_null($storeId)) { + $storeId = Mage::app()->getStore()->getId(); + } + + $adapter = $this->_getReadAdapter(); + if (!$adapter) { + return array(); + } + + $select = $adapter->select() + ->from($this->getMainTable(), array('string', 'translate')) + ->where('store_id IN (0 , :store_id)') + ->where('locale = :locale') + ->order('store_id'); + + $bind = array( + ':locale' => (string)$locale, + ':store_id' => $storeId + ); + + return $adapter->fetchPairs($select, $bind); + + } + + /** + * Retrieve translations array by strings + * + * @param array $strings + * @param int_type $storeId + * @return array + */ + public function getTranslationArrayByStrings(array $strings, $storeId = null) + { + if (!Mage::isInstalled()) { + return array(); + } + + if (is_null($storeId)) { + $storeId = Mage::app()->getStore()->getId(); + } + + $adapter = $this->_getReadAdapter(); + if (!$adapter) { + return array(); + } + + if (empty($strings)) { + return array(); + } + + $bind = array( + ':store_id' => $storeId + ); + $select = $adapter->select() + ->from($this->getMainTable(), array('string', 'translate')) + ->where('string IN (?)', $strings) + ->where('store_id = :store_id'); + + return $adapter->fetchPairs($select, $bind); + } + + /** + * Retrieve table checksum + * + * @return int + */ + public function getMainChecksum() + { + return $this->getChecksum($this->getMainTable()); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Translate/String.php b/app/code/core/Mage/Core/Model/Resource/Translate/String.php new file mode 100644 index 0000000000..44268009e1 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Translate/String.php @@ -0,0 +1,254 @@ + + */ +class Mage_Core_Model_Resource_Translate_String extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/translate', 'key_id'); + } + + /** + * Load + * + * @param Mage_Core_Model_Abstract $object + * @param String $value + * @param String $field + * @return array + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (is_string($value)) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where($this->getMainTable().'.string=:tr_string'); + $result = $this->_getReadAdapter()->fetchRow($select, array('tr_string'=>$value)); + $object->setData($result); + $this->_afterLoad($object); + return $result; + } else { + return parent::load($object, $value, $field); + } + } + + /** + * Retrieve select for load + * + * @param String $field + * @param String $value + * @param Mage_Core_Model_Abstract $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $select->where('store_id = ?', Mage_Core_Model_App::ADMIN_STORE_ID); + return $select; + } + + /** + * After translation loading + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + public function _afterLoad(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('store_id', 'translate')) + ->where('string = :translate_string'); + $translations = $adapter->fetchPairs($select, array('translate_string' => $object->getString())); + $object->setStoreTranslations($translations); + return parent::_afterLoad($object); + } + + /** + * Before save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Translate_String + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), 'key_id') + ->where('string = :string') + ->where('store_id = :store_id'); + + $bind = array( + 'string' => $object->getString(), + 'store_id' => Mage_Core_Model_App::ADMIN_STORE_ID + ); + + $object->setId($adapter->fetchOne($select, $bind)); + return parent::_beforeSave($object); + } + + /** + * After save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Translate_String + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('store_id', 'key_id')) + ->where('string = :string'); + $stores = $adapter->fetchPairs($select, array('string' => $object->getString())); + + $translations = $object->getStoreTranslations(); + + if (is_array($translations)) { + foreach ($translations as $storeId => $translate) { + if (is_null($translate) || $translate=='') { + $where = array( + 'store_id = ?' => $storeId, + 'string = ?' => $object->getString() + ); + $adapter->delete($this->getMainTable(), $where); + } else { + $data = array( + 'store_id' => $storeId, + 'string' => $object->getString(), + 'translate' => $translate, + ); + + if (isset($stores[$storeId])) { + $adapter->update( + $this->getMainTable(), + $data, + array('key_id = ?' => $stores[$storeId])); + } else { + $adapter->insert($this->getMainTable(), $data); + } + } + } + } + return parent::_afterSave($object); + } + + /** + * Delete translates + * + * @param string $string + * @param string $locale + * @param int|null $storeId + * @return Mage_Core_Model_Resource_Translate_String + */ + public function deleteTranslate($string, $locale = null, $storeId = null) + { + if (is_null($locale)) { + $locale = Mage::app()->getLocale()->getLocaleCode(); + } + + $where = array( + 'locale = ?' => $locale, + 'string = ?' => $string + ); + + if ($storeId === false) { + $where['store_id > ?'] = Mage_Core_Model_App::ADMIN_STORE_ID; + } elseif ($storeId !== null) { + $where['store_id > ?'] = $storeId; + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), $where); + + return $this; + } + + /** + * Save translation + * + * @param String $string + * @param String $translate + * @param String $locale + * @param int|null $storeId + * @return Mage_Core_Model_Resource_Translate_String + */ + public function saveTranslate($string, $translate, $locale = null, $storeId = null) + { + $write = $this->_getWriteAdapter(); + $table = $this->getMainTable(); + + if (is_null($locale)) { + $locale = Mage::app()->getLocale()->getLocaleCode(); + } + + if (is_null($storeId)) { + $storeId = Mage::app()->getStore()->getId(); + } + + $select = $write->select() + ->from($table, array('key_id', 'translate')) + ->where('store_id = :store_id') + ->where('locale = :locale') + ->where('string = :string') + ; + $bind = array( + 'store_id' => $storeId, + 'locale' => $locale, + 'string' => $string + ); + + if ($row = $write->fetchRow($select, $bind)) { + $original = $string; + if (strpos($original, '::') !== false) { + list($scope, $original) = explode('::', $original); + } + if ($original == $translate) { + $write->delete($table, array('key_id=?' => $row['key_id'])); + } elseif ($row['translate'] != $translate) { + $write->update($table, array('translate' => $translate), array('key_id=?' => $row['key_id'])); + } + } else { + $write->insert($table, array( + 'store_id' => $storeId, + 'locale' => $locale, + 'string' => $string, + 'translate' => $translate, + )); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Type/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Type/Abstract.php index 71dbca047b..fbf1a9142b 100644 --- a/app/code/core/Mage/Core/Model/Resource/Type/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Type/Abstract.php @@ -20,26 +20,52 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ abstract class Mage_Core_Model_Resource_Type_Abstract { + /** + * Name + * + * @var String + */ protected $_name = ''; + + /** + * Entity class + * + * @var String + */ protected $_entityClass = 'Mage_Core_Model_Resource_Entity_Abstract'; + /** + * Retrieve entity type + * + * @return String + */ public function getEntityClass() { return $this->_entityClass; } + /** + * Set name + * + * @param String $name + */ public function setName($name) { $this->_name = $name; } + /** + * Retrieve name + * + * @return String + */ public function getName() { return $this->_name; diff --git a/app/code/core/Mage/Core/Model/Resource/Type/Db.php b/app/code/core/Mage/Core/Model/Resource/Type/Db.php index 0ba41fe922..67f3430c87 100644 --- a/app/code/core/Mage/Core/Model/Resource/Type/Db.php +++ b/app/code/core/Mage/Core/Model/Resource/Type/Db.php @@ -20,13 +20,15 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - abstract class Mage_Core_Model_Resource_Type_Db extends Mage_Core_Model_Resource_Type_Abstract { + /** + * Constructor + */ public function __construct() { $this->_entityClass = 'Mage_Core_Model_Resource_Entity_Table'; diff --git a/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli.php b/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli.php index bbd316e4a3..7f8f28625c 100644 --- a/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli.php +++ b/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,6 +34,12 @@ */ class Mage_Core_Model_Resource_Type_Db_Mysqli extends Mage_Core_Model_Resource_Type_Db { + /** + * Get Connection + * + * @param Array $config + * @return Varien_Db_Adapter_Mysqli + */ public function getConnection($config) { $configArr = (array)$config; diff --git a/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli/Setup.php b/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli/Setup.php index 8021f3535a..ea0444c3fe 100644 --- a/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli/Setup.php +++ b/app/code/core/Mage/Core/Model/Resource/Type/Db/Mysqli/Setup.php @@ -20,13 +20,19 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Core_Model_Resource_Type_Db_Mysqli_Setup extends Mage_Core_Model_Resource_Type_Db { + /** + * Get connection + * + * @param Array $config + * @return Varien_Db_Adapter_Mysqli + */ public function getConnection($config) { $conn = new Varien_Db_Adapter_Mysqli((array)$config); diff --git a/app/code/core/Mage/Core/Model/Resource/Type/Db/Pdo/Mysql.php b/app/code/core/Mage/Core/Model/Resource/Type/Db/Pdo/Mysql.php index bbbc74f94c..3b905f2ec5 100644 --- a/app/code/core/Mage/Core/Model/Resource/Type/Db/Pdo/Mysql.php +++ b/app/code/core/Mage/Core/Model/Resource/Type/Db/Pdo/Mysql.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -29,7 +29,7 @@ class Mage_Core_Model_Resource_Type_Db_Pdo_Mysql extends Mage_Core_Model_Resourc { /** - * Enter description here... + * Get connection * * @param array $config Connection config * @return Varien_Db_Adapter_Pdo_Mysql diff --git a/app/code/core/Mage/Core/Model/Resource/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Resource/Url/Rewrite.php new file mode 100644 index 0000000000..e6e22d8b3f --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Url/Rewrite.php @@ -0,0 +1,179 @@ + + */ +class Mage_Core_Model_Resource_Url_Rewrite extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Tag table + * + * @var string + */ + protected $_tagTable; + + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/url_rewrite', 'url_rewrite_id'); + $this->_tagTable = $this->getTable('url_rewrite_tag'); + } + + /** + * Initialize array fields + * + * @return Mage_Core_Model_Resource_Url_Rewrite + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array( + array( + 'field' => array('id_path','store_id','is_system'), + 'title' => Mage::helper('core')->__('ID Path for Specified Store') + ), + array( + 'field' => array('request_path','store_id'), + 'title' => Mage::helper('core')->__('Request Path for Specified Store'), + ) + ); + return $this; + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Url_Rewrite $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + /** @var $select Varien_Db_Select */ + $select = parent::_getLoadSelect($field, $value, $object); + + if (!is_null($object->getStoreId())) { + $select->where('store_id IN(?)', array(Mage_Core_Model_App::ADMIN_STORE_ID, $object->getStoreId())); + $select->order('store_id ' . Varien_Db_Select::SQL_DESC); + $select->limit(1); + } + + return $select; + } + + /** + * Retrieve request_path using id_path and current store's id. + * + * @param string $idPath + * @param int|Mage_Core_Model_Store $store + * @return string|false + */ + public function getRequestPathByIdPath($idPath, $store) + { + if ($store instanceof Mage_Core_Model_Store) { + $storeId = (int)$store->getId(); + } else { + $storeId = (int)$store; + } + + $select = $this->_getReadAdapter()->select(); + /** @var $select Varien_Db_Select */ + $select->from(array('main_table' => $this->getMainTable()), 'request_path') + ->where('main_table.store_id = :store_id') + ->where('main_table.id_path = :id_path') + ->limit(1); + + $bind = array( + 'store_id' => $storeId, + 'id_path' => $idPath + ); + + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Load rewrite information for request + * If $path is array - we must load all possible records and choose one matching earlier record in array + * + * @param Mage_Core_Model_Url_Rewrite $object + * @param array|string $path + * @return Mage_Core_Model_Resource_Url_Rewrite + */ + public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path) + { + if (!is_array($path)) { + $path = array($path); + } + + $pathBind = array(); + foreach ($path as $key => $url) { + $pathBind['path' . $key] = $url; + } + // Form select + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('request_path IN (:' . implode(', :', array_flip($pathBind)) . ')') + ->where('store_id IN(?)', array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId())); + + $items = $adapter->fetchAll($select, $pathBind); + + // Go through all found records and choose one with lowest penalty - earlier path in array, concrete store + $mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better + $currentPenalty = null; + $foundItem = null; + foreach ($items as $item) { + $penalty = $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1); + if (!$foundItem || $currentPenalty > $penalty) { + $foundItem = $item; + $currentPenalty = $penalty; + if (!$currentPenalty) { + break; // Found best matching item with zero penalty, no reason to continue + } + } + } + + // Set data and finish loading + if ($foundItem) { + $object->setData($foundItem); + } + + // Finish + $this->unserializeFields($object); + $this->_afterLoad($object); + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Url/Rewrite/Collection.php b/app/code/core/Mage/Core/Model/Resource/Url/Rewrite/Collection.php new file mode 100644 index 0000000000..7a46f2c8d1 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Url/Rewrite/Collection.php @@ -0,0 +1,115 @@ + + */ +class Mage_Core_Model_Resource_Url_Rewrite_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model + * + */ + protected function _construct() + { + $this->_init('core/url_rewrite'); + } + + /** + * Add filter for tags (combined by OR) + * + * @param string|array $tags + * @return Mage_Core_Model_Resource_Url_Rewrite_Collection + */ + public function addTagsFilter($tags) + { + $tags = is_array($tags) ? $tags : explode(',', $tags); + + if (!$this->getFlag('tag_table_joined')) { + $this->join( + array('curt' => $this->getTable('core/url_rewrite_tag')), + 'main_table.url_rewrite_id = curt.url_rewrite_id', + array()); + $this->setFlag('tag_table_joined', true); + } + + $this->addFieldToFilter('curt.tag', array('in' => $tags)); + return $this; + } + + /** + * Filter collections by stores + * + * @param mixed $store + * @param bool $withAdmin + * @return Mage_Core_Model_Resource_Url_Rewrite_Collection + */ + public function addStoreFilter($store, $withAdmin = true) + { + if (!is_array($store)) { + $store = array(Mage::app()->getStore($store)->getId()); + } + if ($withAdmin) { + $store[] = 0; + } + + $this->addFieldToFilter('store_id', array('in' => $store)); + + return $this; + } + + /** + * Add filter by catalog product Id + * + * @param int $productId + * @return Mage_Core_Model_Resource_Url_Rewrite_Collection + */ + public function filterAllByProductId($productId) + { + $this->getSelect() + ->where('id_path = ?', "product/{$productId}") + ->orWhere('id_path LIKE ?', "product/{$productId}/%"); + + return $this; + } + + /** + * Add filter by all catalog category + * + * @return Mage_Core_Model_Resource_Url_Rewrite_Collection + */ + public function filterAllByCategory() + { + $this->getSelect() + ->where('id_path LIKE ?', "category/%"); + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Variable.php b/app/code/core/Mage/Core/Model/Resource/Variable.php new file mode 100644 index 0000000000..845d987e51 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Variable.php @@ -0,0 +1,161 @@ + + */ +class Mage_Core_Model_Resource_Variable extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + $this->_init('core/variable', 'variable_id'); + } + + /** + * Load variable by code + * + * @param Mage_Core_Model_Variable $object + * @param string $code + * @return Mage_Core_Model_Resource_Variable + */ + public function loadByCode(Mage_Core_Model_Variable $object, $code) + { + if ($result = $this->getVariableByCode($code, true, $object->getStoreId())) { + $object->setData($result); + } + return $this; + } + + /** + * Retrieve variable data by code + * + * @param string $code + * @param boolean $withValue + * @param integer $storeId + * @return array + */ + public function getVariableByCode($code, $withValue = false, $storeId = 0) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where($this->getMainTable() . '.code = ?', $code); + if ($withValue) { + $this->_addValueToSelect($select, $storeId); + } + return $this->_getReadAdapter()->fetchRow($select); + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Variable + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + parent::_afterSave($object); + if ($object->getUseDefaultValue()) { + /* + * remove store value + */ + $this->_getWriteAdapter()->delete( + $this->getTable('core/variable_value'), array( + 'variable_id = ?' => $object->getId(), + 'store_id = ?' => $object->getStoreId() + )); + } else { + $data = array( + 'variable_id' => $object->getId(), + 'store_id' => $object->getStoreId(), + 'plain_value' => $object->getPlainValue(), + 'html_value' => $object->getHtmlValue() + ); + $data = $this->_prepareDataForTable(new Varien_Object($data), $this->getTable('core/variable_value')); + $this->_getWriteAdapter()->insertOnDuplicate( + $this->getTable('core/variable_value'), + $data, + array('plain_value', 'html_value') + ); + } + return $this; + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $this->_addValueToSelect($select, $object->getStoreId()); + return $select; + } + + /** + * Add variable store and default value to select + * + * @param Zend_Db_Select $select + * @param integer $storeId + * @return Mage_Core_Model_Resource_Variable + */ + protected function _addValueToSelect(Zend_Db_Select $select, $storeId = Mage_Core_Model_App::ADMIN_STORE_ID) + { + $ifNullPlainValue = $this->_getReadAdapter() + ->getCheckSql('store.plain_value IS NULL', 'def.plain_value', 'store.plain_value'); + $ifNullHtmlValue = $this->_getReadAdapter() + ->getCheckSql('store.html_value IS NULL', 'def.html_value', 'store.html_value'); + + $select->joinLeft( + array('def' => $this->getTable('core/variable_value')), + 'def.variable_id = '.$this->getMainTable().'.variable_id AND def.store_id = 0', + array()) + ->joinLeft( + array('store' => $this->getTable('core/variable_value')), + 'store.variable_id = def.variable_id AND store.store_id = ' . $storeId, + array()) + ->columns(array( + 'plain_value' => $ifNullPlainValue, + 'html_value' => $ifNullHtmlValue, + 'store_plain_value' => 'store.plain_value', + 'store_html_value' => 'store.html_value' + )); + + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Variable/Collection.php b/app/code/core/Mage/Core/Model/Resource/Variable/Collection.php new file mode 100644 index 0000000000..640cef2d56 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Variable/Collection.php @@ -0,0 +1,101 @@ + + */ +class Mage_Core_Model_Resource_Variable_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Store Id + * + * @var int + */ + protected $_storeId = 0; + + /** + * Define resource model + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('core/variable'); + } + + /** + * Setter + * + * @param integer $storeId + * @return Mage_Core_Model_Resource_Variable_Collection + */ + public function setStoreId($storeId) + { + $this->_storeId = $storeId; + return $this; + } + + /** + * Getter + * + * @return integer + */ + public function getStoreId() + { + return $this->_storeId; + } + + /** + * Add store values to result + * + * @return Mage_Core_Model_Resource_Variable_Collection + */ + public function addValuesToResult() + { + $this->getSelect() + ->join( + array('value_table' => $this->getTable('core/variable_value')), + 'value_table.variable_id = main_table.variable_id', + array('value_table.value')); + $this->addFieldToFilter('value_table.store_id', array('eq' => $this->getStoreId())); + return $this; + } + + /** + * Retrieve option array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('code', 'name'); + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Website.php b/app/code/core/Mage/Core/Model/Resource/Website.php new file mode 100644 index 0000000000..4d75ae7765 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Website.php @@ -0,0 +1,136 @@ + + */ +class Mage_Core_Model_Resource_Website extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('core/website', 'website_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Core_Model_Resource_Website + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => 'code', + 'title' => Mage::helper('core')->__('Website with the same code') + )); + return $this; + } + + /** + * Validate website code before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Website + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) { + Mage::throwException(Mage::helper('core')->__('Website code may only contain letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter')); + } + + return parent::_beforeSave($object); + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Website + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->getIsDefault()) { + $this->_getWriteAdapter()->update($this->getMainTable(), array('is_default' => 0)); + $where = array('website_id = ?' => $object->getId()); + $this->_getWriteAdapter()->update($this->getMainTable(), array('is_default' => 1), $where); + } + return parent::_afterSave($object); + } + + /** + * Remove core configuration data after delete website + * + * @param Mage_Core_Model_Abstract $model + * @return Mage_Core_Model_Resource_Website + */ + protected function _afterDelete(Mage_Core_Model_Abstract $model) + { + $where = array( + 'scope = ?' => 'websites', + 'scope_id = ?' => $model->getWebsiteId() + ); + + $this->_getWriteAdapter()->delete($this->getTable('core/config_data'), $where); + + return $this; + + } + + /** + * Retrieve default stores select object + * Select fields website_id, store_id + * + * @param boolean $withDefault include/exclude default admin website + * @return Varien_Db_Select + */ + public function getDefaultStoresSelect($withDefault = false) + { + $ifNull = $this->_getReadAdapter() + ->getCheckSql('store_group_table.default_store_id IS NULL', '0', 'store_group_table.default_store_id'); + $select = $this->_getReadAdapter()->select() + ->from( + array('website_table' => $this->getTable('core/website')), + array('website_id')) + ->joinLeft( + array('store_group_table' => $this->getTable('core/store_group')), + 'website_table.website_id=store_group_table.website_id' + . ' AND website_table.default_group_id = store_group_table.group_id', + array('store_id' => $ifNull) + ); + if (!$withDefault) { + $select->where('website_table.website_id <> ?', 0); + } + return $select; + } +} diff --git a/app/code/core/Mage/Core/Model/Resource/Website/Collection.php b/app/code/core/Mage/Core/Model/Resource/Website/Collection.php new file mode 100644 index 0000000000..0837edbbb1 --- /dev/null +++ b/app/code/core/Mage/Core/Model/Resource/Website/Collection.php @@ -0,0 +1,187 @@ + + */ +class Mage_Core_Model_Resource_Website_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * @deprecated since 1.5.0.0 + */ + protected $_loadDefault = false; + + /** + * Map field to alias + * + * @var array + */ + protected $_map = array('fields' => array('website_id' => 'main_table.website_id')); + + /** + * Define resource model + * + */ + protected function _construct() + { + $this->setFlag('load_default_website', false); + $this->_init('core/website'); + } + + /** + * Set flag for load default (admin) website + * + * @param boolean $loadDefault + * @return Mage_Core_Model_Resource_Website_Collection + */ + public function setLoadDefault($loadDefault) + { + $this->setFlag('load_default_website', (bool)$loadDefault); + return $this; + } + + /** + * Is load default (admin) website + * + * @return boolean + */ + public function getLoadDefault() + { + return $this->getFlag('load_default_website'); + } + + /** + * Convert items array to array for select options + * + * @return Array + */ + public function toOptionArray() + { + return $this->_toOptionArray('website_id', 'name'); + } + + /** + * Convert items array to hash for select options + * + * @return Array + */ + public function toOptionHash() + { + return $this->_toOptionHash('website_id', 'name'); + } + + + /** + * Add website filter to collection + * + * @param int $ids|array + * @return Mage_Core_Model_Resource_Website_Collection + */ + public function addIdFilter($ids) + { + if (is_array($ids)) { + if (empty($ids)) { + $this->addFieldToFilter('website_id', null); + } else { + $this->addFieldToFilter('website_id', array('in' => $ids)); + } + } else { + $this->addFieldToFilter('website_id', $ids); + } + return $this; + } + + /** + * Load collection data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Core_Model_Resource_Website_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if (!$this->getLoadDefault()) { + $this->getSelect()->where('main_table.website_id > ?', 0); + } + $this->unshiftOrder('main_table.name', Varien_Db_Select::SQL_ASC) // website name SECOND + ->unshiftOrder('main_table.sort_order', Varien_Db_Select::SQL_ASC); // website sort order FIRST + + return parent::load($printQuery, $logQuery); + + } + + /** + * Join group and store info from appropriate tables. + * Defines new _idFiledName as 'website_group_store' bc for + * one website can be more then one row in collection. + * Sets extra combined ordering by group's name, defined + * sort ordering and store's name. + * + * @return Mage_Core_Model_Resource_Website_Collection + */ + public function joinGroupAndStore() + { + if (!$this->getFlag('groups_and_stores_joined')) { + $this->_idFieldName = 'website_group_store'; + $this->getSelect()->joinLeft( + array('group_table' => $this->getTable('core/store_group')), + 'main_table.website_id = group_table.website_id', + array('group_id' => 'group_id', 'group_title' => 'name') + )->joinLeft( + array('store_table' => $this->getTable('core/store')), + 'group_table.group_id = store_table.group_id', + array('store_id' => 'store_id', 'store_title' => 'name') + ); + $this->addOrder('group_table.name', Varien_Db_Select::SQL_ASC) // store name + ->addOrder('CASE WHEN store_table.store_id = 0 THEN 0 ELSE 1 END', Varien_Db_Select::SQL_ASC) // view is admin + ->addOrder('store_table.sort_order', Varien_Db_Select::SQL_ASC) // view sort order + ->addOrder('store_table.name', Varien_Db_Select::SQL_ASC) // view name + ; + $this->setFlag('groups_and_stores_joined', true); + } + return $this; + } + + /** + * Adding filter by group id or array of ids but only if + * tables with appropriate information were joined before. + * + * @param int|array $groupIds + * @return Mage_Core_Model_Resource_Website_Collection + */ + public function addFilterByGroupIds($groupIds) + { + if ($this->getFlag('groups_and_stores_joined')) { + $this->addFieldToFilter('group_table.group_id', $groupIds); + } + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Session.php b/app/code/core/Mage/Core/Model/Session.php index 3f708da3b1..a188c5fa21 100644 --- a/app/code/core/Mage/Core/Model/Session.php +++ b/app/code/core/Mage/Core/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Session/Abstract.php b/app/code/core/Mage/Core/Model/Session/Abstract.php index f7f09c068c..a98449c8d1 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php index 18220d9107..30b971b966 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Zend.php b/app/code/core/Mage/Core/Model/Session/Abstract/Zend.php index 80adc728c5..8e083f5deb 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Zend.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Zend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Session/Exception.php b/app/code/core/Mage/Core/Model/Session/Exception.php index be6e52ff2c..f21bee10d6 100644 --- a/app/code/core/Mage/Core/Model/Session/Exception.php +++ b/app/code/core/Mage/Core/Model/Session/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Source/Email/Variables.php b/app/code/core/Mage/Core/Model/Source/Email/Variables.php index f4bbf7834d..64d81777d2 100644 --- a/app/code/core/Mage/Core/Model/Source/Email/Variables.php +++ b/app/code/core/Mage/Core/Model/Source/Email/Variables.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Store.php b/app/code/core/Mage/Core/Model/Store.php index cbf61086b0..7359e45f4a 100644 --- a/app/code/core/Mage/Core/Model/Store.php +++ b/app/code/core/Mage/Core/Model/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,19 @@ /** * Store model * - * @author Magento Core Team - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Store _getResource() + * @method Mage_Core_Model_Resource_Store getResource() + * @method Mage_Core_Model_Store setCode(string $value) + * @method Mage_Core_Model_Store setWebsiteId(int $value) + * @method Mage_Core_Model_Store setGroupId(int $value) + * @method Mage_Core_Model_Store setName(string $value) + * @method int getSortOrder() + * @method Mage_Core_Model_Store setSortOrder(int $value) + * @method Mage_Core_Model_Store setIsActive(int $value) + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team */ class Mage_Core_Model_Store extends Mage_Core_Model_Abstract { @@ -205,7 +215,6 @@ public function getCode() * Retrieve store configuration data * * @param string $path - * @param string $scope * @return string|null */ public function getConfig($path) @@ -216,7 +225,7 @@ public function getConfig($path) $config = Mage::getConfig(); - $fullPath = 'stores/'.$this->getCode().'/'.$path; + $fullPath = 'stores/' . $this->getCode() . '/' . $path; $data = $config->getNode($fullPath); if (!$data && !Mage::isInstalled()) { $data = $config->getNode('default/' . $path); @@ -566,7 +575,10 @@ public function isFrontUrlSecure() public function isCurrentlySecure() { - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $standardRule = !empty($_SERVER['HTTPS']) && 'off' != $_SERVER['HTTPS']; + $offloaderHeader = trim(Mage::getStoreConfig('web/secure/offloader_header')); + + if ((!empty($offloaderHeader) && !empty($_SERVER[$offloaderHeader])) || $standardRule) { return true; } diff --git a/app/code/core/Mage/Core/Model/Store/Exception.php b/app/code/core/Mage/Core/Model/Store/Exception.php index ce5ce66c0c..215e31f253 100644 --- a/app/code/core/Mage/Core/Model/Store/Exception.php +++ b/app/code/core/Mage/Core/Model/Store/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Store/Group.php b/app/code/core/Mage/Core/Model/Store/Group.php index 1ab547a694..60a7cf17b4 100644 --- a/app/code/core/Mage/Core/Model/Store/Group.php +++ b/app/code/core/Mage/Core/Model/Store/Group.php @@ -20,15 +20,23 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Store group model * - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Store_Group _getResource() + * @method Mage_Core_Model_Resource_Store_Group getResource() + * @method Mage_Core_Model_Store_Group setWebsiteId(int $value) + * @method string getName() + * @method Mage_Core_Model_Store_Group setName(string $value) + * @method Mage_Core_Model_Store_Group setRootCategoryId(int $value) + * @method Mage_Core_Model_Store_Group setDefaultStoreId(int $value) + * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ diff --git a/app/code/core/Mage/Core/Model/Template.php b/app/code/core/Mage/Core/Model/Template.php index a4db50448c..dae8af5dca 100644 --- a/app/code/core/Mage/Core/Model/Template.php +++ b/app/code/core/Mage/Core/Model/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Translate.php b/app/code/core/Mage/Core/Model/Translate.php index 352fd91b01..87444f3cad 100644 --- a/app/code/core/Mage/Core/Model/Translate.php +++ b/app/code/core/Mage/Core/Model/Translate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Translate/Expr.php b/app/code/core/Mage/Core/Model/Translate/Expr.php index 06c9c1a3fb..9de35666c6 100644 --- a/app/code/core/Mage/Core/Model/Translate/Expr.php +++ b/app/code/core/Mage/Core/Model/Translate/Expr.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Translate/Inline.php b/app/code/core/Mage/Core/Model/Translate/Inline.php index 68efa5bf8c..b3869df656 100644 --- a/app/code/core/Mage/Core/Model/Translate/Inline.php +++ b/app/code/core/Mage/Core/Model/Translate/Inline.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Translate/String.php b/app/code/core/Mage/Core/Model/Translate/String.php index 2d8a957841..2bd7a3e469 100644 --- a/app/code/core/Mage/Core/Model/Translate/String.php +++ b/app/code/core/Mage/Core/Model/Translate/String.php @@ -20,15 +20,24 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * String translation model * - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Translate_String _getResource() + * @method Mage_Core_Model_Resource_Translate_String getResource() + * @method int getStoreId() + * @method Mage_Core_Model_Translate_String setStoreId(int $value) + * @method string getTranslate() + * @method Mage_Core_Model_Translate_String setTranslate(string $value) + * @method string getLocale() + * @method Mage_Core_Model_Translate_String setLocale(string $value) + * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ class Mage_Core_Model_Translate_String extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index 032d44382a..d1f0c016d9 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Url/Rewrite.php index 9a9a6dfb2d..cfa03c4173 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,28 @@ /** * Url rewrite model class * + * @method Mage_Core_Model_Resource_Url_Rewrite _getResource() + * @method Mage_Core_Model_Resource_Url_Rewrite getResource() + * @method Mage_Core_Model_Url_Rewrite setStoreId(int $value) + * @method int getCategoryId() + * @method Mage_Core_Model_Url_Rewrite setCategoryId(int $value) + * @method int getProductId() + * @method Mage_Core_Model_Url_Rewrite setProductId(int $value) + * @method string getIdPath() + * @method Mage_Core_Model_Url_Rewrite setIdPath(string $value) + * @method string getRequestPath() + * @method Mage_Core_Model_Url_Rewrite setRequestPath(string $value) + * @method string getTargetPath() + * @method Mage_Core_Model_Url_Rewrite setTargetPath(string $value) + * @method int getIsSystem() + * @method Mage_Core_Model_Url_Rewrite setIsSystem(int $value) + * @method string getOptions() + * @method Mage_Core_Model_Url_Rewrite setOptions(string $value) + * @method string getDescription() + * @method Mage_Core_Model_Url_Rewrite setDescription(string $value) * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Core * @author Magento Core Team */ class Mage_Core_Model_Url_Rewrite extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Core/Model/Variable.php b/app/code/core/Mage/Core/Model/Variable.php index 1c9587bfb8..0b075aee4c 100644 --- a/app/code/core/Mage/Core/Model/Variable.php +++ b/app/code/core/Mage/Core/Model/Variable.php @@ -20,13 +20,20 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Custom variable model * + * @method Mage_Core_Model_Resource_Variable _getResource() + * @method Mage_Core_Model_Resource_Variable getResource() + * @method string getCode() + * @method Mage_Core_Model_Variable setCode(string $value) + * @method string getName() + * @method Mage_Core_Model_Variable setName(string $value) + * * @category Mage * @package Mage_Core * @author Magento Core Team diff --git a/app/code/core/Mage/Core/Model/Variable/Config.php b/app/code/core/Mage/Core/Model/Variable/Config.php index 7b358bb0d4..7637478c76 100644 --- a/app/code/core/Mage/Core/Model/Variable/Config.php +++ b/app/code/core/Mage/Core/Model/Variable/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Variable/Observer.php b/app/code/core/Mage/Core/Model/Variable/Observer.php index 8e5d663f4e..e4244a795e 100644 --- a/app/code/core/Mage/Core/Model/Variable/Observer.php +++ b/app/code/core/Mage/Core/Model/Variable/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/Model/Website.php b/app/code/core/Mage/Core/Model/Website.php index de08592bf9..71862910e5 100644 --- a/app/code/core/Mage/Core/Model/Website.php +++ b/app/code/core/Mage/Core/Model/Website.php @@ -20,15 +20,26 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Core Website model * - * @category Mage - * @package Mage_Core + * @method Mage_Core_Model_Resource_Website _getResource() + * @method Mage_Core_Model_Resource_Website getResource() + * @method Mage_Core_Model_Website setCode(string $value) + * @method string getName() + * @method Mage_Core_Model_Website setName(string $value) + * @method int getSortOrder() + * @method Mage_Core_Model_Website setSortOrder(int $value) + * @method Mage_Core_Model_Website setDefaultGroupId(int $value) + * @method int getIsDefault() + * @method Mage_Core_Model_Website setIsDefault(int $value) + * + * @category Mage + * @package Mage_Core * @author Magento Core Team */ diff --git a/app/code/core/Mage/Core/controllers/AjaxController.php b/app/code/core/Mage/Core/controllers/AjaxController.php index b8b9c11be2..8d3bce5afa 100644 --- a/app/code/core/Mage/Core/controllers/AjaxController.php +++ b/app/code/core/Mage/Core/controllers/AjaxController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/controllers/IndexController.php b/app/code/core/Mage/Core/controllers/IndexController.php index f5abafff33..13f2111037 100644 --- a/app/code/core/Mage/Core/controllers/IndexController.php +++ b/app/code/core/Mage/Core/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/etc/config.xml b/app/code/core/Mage/Core/etc/config.xml index a44436985a..a5be05dc98 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -21,45 +21,73 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.8.28 + 1.6.0.0 - - + - core_website
- core_store_group
- core_store
- core_config_field
- core_config_data
- core_email_template
- core_variable
- core_variable_value
- core_translate
- core_session
- core_layout_update
- core_layout_link
- core_url_rewrite
- core_url_rewrite_tag
- core_convert_profile
- core_convert_history
- design_change
- core_flag
+ + core_website
+
+ + core_store_group
+
+ + core_store
+
+ + core_config_field
+
+ + core_config_data
+
+ + core_email_template
+
+ + core_variable
+
+ + core_variable_value
+
+ + core_translate
+
+ + core_session
+
+ + core_layout_update
+
+ + core_layout_link
+
+ + core_url_rewrite
+
+ + core_url_rewrite_tag
+
+ + design_change
+
+ + core_flag
+
core_file_storage
core_directory_storage
-
+
- Mage_Core_Block @@ -71,7 +99,7 @@ @@ -139,13 +167,13 @@ - - - - core.xml - - - + + + + core.xml + + +
@@ -195,7 +223,6 @@ - @@ -210,10 +237,9 @@ 5 - - + 0 @@ -235,7 +261,6 @@ 0 - 0 @@ -253,38 +278,38 @@ - custom1@example.com Custom 1 - custom2@example.com Custom 2 - owner@example.com Owner - sales@example.com Sales - support@example.com CustomerSupport - - - adminMage_Core_Controller_Varien_Router_Admin - frontendMage_Core_Controller_Varien_Router_Standard + + + admin + Mage_Core_Controller_Varien_Router_Admin + + + frontend + Mage_Core_Controller_Varien_Router_Standard + 0 @@ -293,7 +318,6 @@ 0 - {{base_url}} {{unsecure_base_url}} @@ -302,7 +326,6 @@ {{unsecure_base_url}}skin/ {{unsecure_base_url}}media/ - {{base_url}} {{secure_base_url}} @@ -312,13 +335,12 @@ {{secure_base_url}}media/ 0 0 + SSL_OFFLOADED - 3600 1 - 0 0 @@ -326,26 +348,23 @@ 0 1 - 1 1 - dashboard 0 - + 1 - 0 @@ -386,12 +405,18 @@ - + - adminMage_Core_Controller_Varien_Router_Admin - frontendMage_Core_Controller_Varien_Router_Standard + + admin + Mage_Core_Controller_Varien_Router_Admin + + + frontend + Mage_Core_Controller_Varien_Router_Standard + diff --git a/app/code/core/Mage/Core/etc/system.xml b/app/code/core/Mage/Core/etc/system.xml index 2e4a936edc..13da94d153 100644 --- a/app/code/core/Mage/Core/etc/system.xml +++ b/app/code/core/Mage/Core/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -1237,6 +1237,14 @@ 0 0 + + + text + 75 + 1 + 0 + 0 + diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php index cd8ef85e1f..06894aeb3e 100644 --- a/app/code/core/Mage/Core/functions.php +++ b/app/code/core/Mage/Core/functions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/install-1.6.0.0.php b/app/code/core/Mage/Core/sql/core_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..6673649717 --- /dev/null +++ b/app/code/core/Mage/Core/sql/core_setup/install-1.6.0.0.php @@ -0,0 +1,660 @@ +startSetup(); + +/** + * Create table 'core/resource' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/resource')) + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'primary' => true, + ), 'Resource Code') + ->addColumn('version', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Resource Version') + ->addColumn('data_version', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Data Version') + ->setComment('Resources'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/website' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/website')) + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Code') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'Website Name') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addColumn('default_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Default Group Id') + ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Defines Is Website Default') + ->addIndex($installer->getIdxName('core/website', array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/website', array('sort_order')), + array('sort_order')) + ->addIndex($installer->getIdxName('core/website', array('default_group_id')), + array('default_group_id')) + ->setComment('Websites'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/store_group' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/store_group')) + ->addColumn('group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Group Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Store Group Name') + ->addColumn('root_category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Root Category Id') + ->addColumn('default_store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Default Store Id') + ->addIndex($installer->getIdxName('core/store_group', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('core/store_group', array('default_store_id')), + array('default_store_id')) + ->addForeignKey($installer->getFkName('core/store_group', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Store Groups'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/store')) + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Code') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website Id') + ->addColumn('group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Group Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Store Name') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Sort Order') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Activity') + ->addIndex($installer->getIdxName('core/store', array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/store', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('core/store', array('is_active', 'sort_order')), + array('is_active', 'sort_order')) + ->addIndex($installer->getIdxName('core/store', array('group_id')), + array('group_id')) + ->addForeignKey($installer->getFkName('core/store', 'group_id', 'core/store_group', 'group_id'), + 'group_id', $installer->getTable('core/store_group'), 'group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('core/store', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Stores'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/config_data' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/config_data')) + ->addColumn('config_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Config Id') + ->addColumn('scope', Varien_Db_Ddl_Table::TYPE_TEXT, 8, array( + 'nullable' => false, + 'default' => 'default', + ), 'Config Scope') + ->addColumn('scope_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Config Scope Id') + ->addColumn('path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => 'general', + ), 'Config Path') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Config Value') + ->addIndex($installer->getIdxName('core/config_data', array('scope', 'scope_id', 'path'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('scope', 'scope_id', 'path'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Config Data'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/email_template' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/email_template')) + ->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Template Id') + ->addColumn('template_code', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array( + 'nullable' => false + ), 'Template Name') + ->addColumn('template_text', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false + ), 'Template Content') + ->addColumn('template_styles', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Templste Styles') + ->addColumn('template_type', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Template Type') + ->addColumn('template_subject', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + 'nullable' => false, + ), 'Template Subject') + ->addColumn('template_sender_name', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Template Sender Name') + ->addColumn('template_sender_email', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Template Sender Email') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Date of Template Creation') + ->addColumn('modified_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Date of Template Modification') + ->addColumn('orig_template_code', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Original Template Code') + ->addColumn('orig_template_variables', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Original Template Variables') + ->addIndex($installer->getIdxName('core/email_template', array('template_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('template_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/email_template', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('core/email_template', array('modified_at')), + array('modified_at')) + ->setComment('Email Templates'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/layout_update' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/layout_update')) + ->addColumn('layout_update_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Layout Update Id') + ->addColumn('handle', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Handle') + ->addColumn('xml', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Xml') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex($installer->getIdxName('core/layout_update', array('handle')), + array('handle')) + ->setComment('Layout Updates'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/layout_link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/layout_link')) + ->addColumn('layout_link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('area', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'Area') + ->addColumn('package', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'Package') + ->addColumn('theme', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'Theme') + ->addColumn('layout_update_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Layout Update Id') + ->addIndex($installer->getIdxName('core/layout_link', array('store_id', 'package', 'theme', 'layout_update_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('store_id', 'package', 'theme', 'layout_update_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/layout_link', array('layout_update_id')), + array('layout_update_id')) + ->addForeignKey($installer->getFkName('core/layout_link', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('core/layout_link', 'layout_update_id', 'core/layout_update', 'layout_update_id'), + 'layout_update_id', $installer->getTable('core/layout_update'), 'layout_update_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Layout Link'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/session' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/session')) + ->addColumn('session_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'primary' => true, + ), 'Session Id') + ->addColumn('session_expires', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Date of Session Expiration') + ->addColumn('session_data', Varien_Db_Ddl_Table::TYPE_BLOB, '2M', array( + 'nullable' => false, + ), 'Session Data') + ->setComment('Database Sessions Storage'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/translate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/translate')) + ->addColumn('key_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Key Id of Translation') + ->addColumn('string', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => 'Translate String', + ), 'Translation String') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('translate', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Translate') + ->addColumn('locale', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + 'default' => 'en_US', + ), 'Locale') + ->addIndex($installer->getIdxName('core/translate', array('store_id', 'locale', 'string'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('store_id', 'locale', 'string'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/translate', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('core/translate', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Translations'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/url_rewrite' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/url_rewrite')) + ->addColumn('url_rewrite_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rewrite Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('id_path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Id Path') + ->addColumn('request_path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Request Path') + ->addColumn('target_path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Target Path') + ->addColumn('is_system', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '1', + ), 'Defines is Rewrite System') + ->addColumn('options', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Options') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Deascription') + ->addIndex($installer->getIdxName('core/url_rewrite', array('request_path', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('request_path', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/url_rewrite', array('id_path', 'is_system', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('id_path', 'is_system', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/url_rewrite', array('target_path', 'store_id')), + array('target_path', 'store_id')) + ->addIndex($installer->getIdxName('core/url_rewrite', array('id_path')), + array('id_path')) + ->addIndex($installer->getIdxName('core/url_rewrite', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('core/url_rewrite', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Url Rewrites'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/design_change' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/design_change')) + ->addColumn('design_change_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Design Change Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('design', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Design') + ->addColumn('date_from', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'First Date of Design Activity') + ->addColumn('date_to', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Last Date of Design Activity') + ->addIndex($installer->getIdxName('core/design_change', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('core/design_change', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Design Changes'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/variable' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/variable')) + ->addColumn('variable_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Variable Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Variable Code') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Variable Name') + ->addIndex($installer->getIdxName('core/variable', array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Variables'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/variable_value' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/variable_value')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Variable Value Id') + ->addColumn('variable_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Variable Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('plain_value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Plain Text Value') + ->addColumn('html_value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Html Value') + ->addIndex($installer->getIdxName('core/variable_value', array('variable_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('variable_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('core/variable_value', array('variable_id')), + array('variable_id')) + ->addIndex($installer->getIdxName('core/variable_value', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('core/variable_value', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('core/variable_value', 'variable_id', 'core/variable', 'variable_id'), + 'variable_id', $installer->getTable('core/variable'), 'variable_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Variable Value'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/cache' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/cache')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + 'nullable' => false, + 'primary' => true, + ), 'Cache Id') + ->addColumn('data', Varien_Db_Ddl_Table::TYPE_BLOB, '2M', array( + ), 'Cache Data') + ->addColumn('create_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Cache Creation Time') + ->addColumn('update_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Time of Cache Updating') + ->addColumn('expire_time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Cache Expiration Time') + ->addIndex($installer->getIdxName('core/cache', array('expire_time')), + array('expire_time')) + ->setComment('Caches'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/cache_tag' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/cache_tag')) + ->addColumn('tag', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + 'nullable' => false, + 'primary' => true, + ), 'Tag') + ->addColumn('cache_id', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + 'nullable' => false, + 'primary' => true, + ), 'Cache Id') + ->addIndex($installer->getIdxName('core/cache_tag', array('cache_id')), + array('cache_id')) + ->addForeignKey($installer->getFkName('core/cache_tag', 'cache_id', 'core/cache', 'id'), + 'cache_id', $installer->getTable('core/cache'), 'id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tag Caches'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/cache_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/cache_option')) + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'primary' => true, + ), 'Code') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + ), 'Value') + ->setComment('Cache Options'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'core/flag' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('core/flag')) + ->addColumn('flag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Flag Id') + ->addColumn('flag_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Flag Code') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Flag State') + ->addColumn('flag_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Flag Data') + ->addColumn('last_update', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT_UPDATE, + ), 'Date of Last Flag Update') + ->addIndex($installer->getIdxName('core/flag', array('last_update')), + array('last_update')) + ->setComment('Flag'); +$installer->getConnection()->createTable($table); + + +/** + * Insert core websites + */ +$installer->getConnection()->insertForce($installer->getTable('core/website'), array( + 'website_id' => 0, + 'code' => 'admin', + 'name' => 'Admin', + 'sort_order' => 0, + 'default_group_id' => 0, + 'is_default' => 0, +)); +$installer->getConnection()->insertForce($installer->getTable('core/website'), array( + 'website_id' => 1, + 'code' => 'base', + 'name' => 'Main Website', + 'sort_order' => 0, + 'default_group_id' => 1, + 'is_default' => 1, +)); + +/** + * Insert core store groups + */ +$installer->getConnection()->insertForce($installer->getTable('core/store_group'), array( + 'group_id' => 0, + 'website_id' => 0, + 'name' => 'Default', + 'root_category_id' => 0, + 'default_store_id' => 0 +)); +$installer->getConnection()->insertForce($installer->getTable('core/store_group'), array( + 'group_id' => 1, + 'website_id' => 1, + 'name' => 'Main Website Store', + 'root_category_id' => 2, + 'default_store_id' => 1 +)); + +/** + * Insert core stores + */ +$installer->getConnection()->insertForce($installer->getTable('core/store'), array( + 'store_id' => 0, + 'code' => 'admin', + 'website_id' => 0, + 'group_id' => 0, + 'name' => 'Admin', + 'sort_order' => 0, + 'is_active' => 1, +)); +$installer->getConnection()->insertForce($installer->getTable('core/store'), array( + 'store_id' => 1, + 'code' => 'default', + 'website_id' => 1, + 'group_id' => 1, + 'name' => 'Default Store View', + 'sort_order' => 0, + 'is_active' => 1, +)); + +$installer->endSetup(); + diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.7.0.php index 81de8a3283..4d49bfe1bc 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.8.0.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.8.0.php index 522a5a2534..7c98fd0b32 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.8.0.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-install-0.8.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.6.26-0.7.0.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.6.26-0.7.0.php index 8439c0fe9f..8f83ac3ddc 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.6.26-0.7.0.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.6.26-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.1-0.7.2.php index 8802162f5d..6de0fd79e3 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.2-0.7.3.php index 6c616145ca..6170608a79 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.3-0.7.4.php index 3deb8320f5..9e1715e02c 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.4-0.7.5.php index b2d1c13d78..ad7f7c23bd 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.5-0.7.6.php index 90877f13c2..3666f32d39 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.6-0.7.7.php index 271ef07665..e2a9dbf73b 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.7-0.7.8.php index 9133387396..1ab752d59f 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.8-0.7.9.php index 395d23519f..9c1ac21736 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.0-0.8.1.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.0-0.8.1.php index 86a27e7bab..6f45c3d11b 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.0-0.8.1.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.0-0.8.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.1-0.8.2.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.1-0.8.2.php index 366345f2ea..b01876d309 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.1-0.8.2.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.1-0.8.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.10-0.8.11.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.10-0.8.11.php index baea4dea3c..5bd452f77f 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.10-0.8.11.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.10-0.8.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.11-0.8.12.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.11-0.8.12.php index 6b643c6790..a27a29df09 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.11-0.8.12.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.11-0.8.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.12-0.8.13.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.12-0.8.13.php index 731d607bec..272155a2c2 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.12-0.8.13.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.12-0.8.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.13-0.8.14.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.13-0.8.14.php index 9a8604281d..e6e7f2777f 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.13-0.8.14.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.13-0.8.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.14-0.8.15.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.14-0.8.15.php index 58a4d1d989..d5ca99dff5 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.14-0.8.15.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.14-0.8.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.15-0.8.16.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.15-0.8.16.php index a5958bbd74..77c7c4022f 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.15-0.8.16.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.15-0.8.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.16-0.8.17.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.16-0.8.17.php index 50de906fb4..f58989f887 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.16-0.8.17.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.16-0.8.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.17-0.8.18.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.17-0.8.18.php index 339eb64d69..91d5b0338a 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.17-0.8.18.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.17-0.8.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php index 32f0f552d7..9a49909bea 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php index f2abccb5ce..01a67aa2c1 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.2-0.8.3.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.2-0.8.3.php index 7dfafaf4a7..c64cae90a5 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.2-0.8.3.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.2-0.8.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.20-0.8.21.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.20-0.8.21.php index c060233312..b1a465c6b5 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.20-0.8.21.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.20-0.8.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,4 +28,11 @@ $installer = $this; $installer->getConnection()->addColumn($installer->getTable('core/resource'), 'data_version', 'varchar(50)'); - +/* + * Update core_resource table to prevent running data upgrade install scripts, + * New 'data_version' column will contain value from 'version' column + */ +$installer->getConnection()->update( + $this->getTable('core/resource'), + array('data_version' => new Zend_Db_Expr('version')) +); diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.21-0.8.22.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.21-0.8.22.php index 972fb443c7..406e632ed1 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.21-0.8.22.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.21-0.8.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.22-0.8.23.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.22-0.8.23.php index b995c6b806..e22668fb14 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.22-0.8.23.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.22-0.8.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.23-0.8.24.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.23-0.8.24.php index 22ef4719f8..470d1e174d 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.23-0.8.24.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.23-0.8.24.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.24-0.8.25.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.24-0.8.25.php index 275692b286..fcf0340a79 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.24-0.8.25.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.24-0.8.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ $installer->startSetup(); $installer->getConnection()->modifyColumn( - $this->getTable('core_flag'), 'flag_id', 'INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT' + $this->getTable('core/flag'), 'flag_id', 'INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT' ); $installer->endSetup(); diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.25-0.8.26.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.25-0.8.26.php index bb29dd9975..6a814bfba0 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.25-0.8.26.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.25-0.8.26.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.26-0.8.27.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.26-0.8.27.php index 9e8d381c8e..e4ad568df8 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.26-0.8.27.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.26-0.8.27.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php index e1b2a67c34..e5b57464b5 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.27-0.8.28.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.3-0.8.4.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.3-0.8.4.php index 87feb23770..0f311c79e2 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.3-0.8.4.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.3-0.8.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.4-0.8.5.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.4-0.8.5.php index 24a5b2952e..7694357e81 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.4-0.8.5.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.4-0.8.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.5-0.8.6.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.5-0.8.6.php index 4bd94035e0..e47b701c46 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.5-0.8.6.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.5-0.8.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.6-0.8.7.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.6-0.8.7.php index b1fa747be7..59ff8f9d7d 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.6-0.8.7.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.6-0.8.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.7-0.8.8.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.7-0.8.8.php index 43296cc9e6..e151259862 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.7-0.8.8.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.7-0.8.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.8-0.8.9.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.8-0.8.9.php index 263c2cb2b3..3269a04912 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.8-0.8.9.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.8-0.8.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.9-0.8.10.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.9-0.8.10.php index b242be6549..ceaebcf6aa 100644 --- a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.9-0.8.10.php +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.9-0.8.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..a81ae88d7d --- /dev/null +++ b/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,1288 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/layout_link'), + 'FK_CORE_LAYOUT_LINK_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/layout_link'), + 'FK_CORE_LAYOUT_LINK_UPDATE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/store'), + 'FK_STORE_GROUP_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/store'), + 'FK_STORE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/session'), + 'FK_SESSION_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/store_group'), + 'FK_STORE_GROUP_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/translate'), + 'FK_CORE_TRANSLATE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/url_rewrite'), + 'CORE_URL_REWRITE_IBFK_1' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_CATEGORY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/variable_value'), + 'FK_CORE_VARIABLE_VALUE_STORE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/variable_value'), + 'FK_CORE_VARIABLE_VALUE_VARIABLE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('core/design_change'), + 'FK_DESIGN_CHANGE_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('core/cache'), + 'IDX_EXPIRE_TIME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/cache_tag'), + 'IDX_CACHE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/config_data'), + 'CONFIG_SCOPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/email_template'), + 'TEMPLATE_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/email_template'), + 'ADDED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/email_template'), + 'MODIFIED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/flag'), + 'LAST_UPDATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/layout_link'), + 'STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/layout_link'), + 'FK_CORE_LAYOUT_LINK_UPDATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/layout_update'), + 'HANDLE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store'), + 'CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store'), + 'FK_STORE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store'), + 'IS_ACTIVE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store'), + 'FK_STORE_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store_group'), + 'FK_STORE_GROUP_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/store_group'), + 'DEFAULT_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/translate'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/translate'), + 'FK_CORE_TRANSLATE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/session'), + 'FK_SESSION_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'UNQ_REQUEST_PATH' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'UNQ_PATH' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_CATEGORY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'FK_CORE_URL_REWRITE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'IDX_ID_PATH' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'IDX_CATEGORY_REWRITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/url_rewrite'), + 'IDX_TARGET_PATH' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/variable'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/variable_value'), + 'IDX_VARIABLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/variable_value'), + 'IDX_VARIABLE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/variable_value'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/website'), + 'CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/website'), + 'SORT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/website'), + 'DEFAULT_GROUP_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('core/design_change'), + 'FK_DESIGN_CHANGE_STORE' +); + + +/* + * Change columns + */ +$tables = array( + $installer->getTable('core/config_data') => array( + 'columns' => array( + 'config_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Config Id' + ), + 'scope' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 8, + 'nullable' => false, + 'default' => 'default', + 'comment' => 'Config Scope' + ), + 'scope_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Config Scope Id' + ), + 'path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => 'general', + 'comment' => 'Config Path' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Config Value' + ) + ), + 'comment' => 'Config Data' + ), + $installer->getTable('core/website') => array( + 'columns' => array( + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Code' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Website Name' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ), + 'default_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Default Group Id' + ), + 'is_default' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Defines Is Website Default' + ) + ), + 'comment' => 'Websites' + ), + $installer->getTable('core/store') => array( + 'columns' => array( + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Store Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Code' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Group Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Store Name' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Sort Order' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Activity' + ) + ), + 'comment' => 'Stores' + ), + $installer->getTable('core/resource') => array( + 'columns' => array( + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Resource Code' + ), + 'version' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Resource Version' + ), + 'data_version' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Data Version' + ) + ), + 'comment' => 'Resources' + ), + $installer->getTable('core/cache') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Cache Id' + ), + 'data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BLOB, + 'length' => '2M', + 'comment' => 'Cache Data' + ), + 'create_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Cache Creation Time' + ), + 'update_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Time of Cache Updating' + ), + 'expire_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Cache Expiration Time' + ) + ), + 'comment' => 'Caches' + ), + $installer->getTable('core/cache_tag') => array( + 'columns' => array( + 'tag' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tag' + ), + 'cache_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Cache Id' + ) + ), + 'comment' => 'Tag Caches' + ), + $installer->getTable('core/cache_option') => array( + 'columns' => array( + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Code' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'comment' => 'Value' + ) + ), + 'comment' => 'Cache Options' + ), + $installer->getTable('core/store_group') => array( + 'columns' => array( + 'group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Group Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Store Group Name' + ), + 'root_category_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Root Category Id' + ), + 'default_store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Default Store Id' + ) + ), + 'comment' => 'Store Groups' + ), + $installer->getTable('core/email_template') => array( + 'columns' => array( + 'template_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Template Id' + ), + 'template_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 150, + 'nullable' => false, + 'comment' => 'Template Name' + ), + 'template_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Template Content' + ), + 'template_styles' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Templste Styles' + ), + 'template_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Template Type' + ), + 'template_subject' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'nullable' => false, + 'comment' => 'Template Subject' + ), + 'template_sender_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Template Sender Name' + ), + 'template_sender_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Template Sender Email' + ), + 'added_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Date of Template Creation' + ), + 'modified_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Date of Template Modification' + ), + 'orig_template_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Original Template Code' + ), + 'orig_template_variables' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Original Template Variables' + ) + ), + 'comment' => 'Email Templates' + ), + $installer->getTable('core/variable') => array( + 'columns' => array( + 'variable_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Variable Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Variable Code' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Variable Name' + ) + ), + 'comment' => 'Variables' + ), + $installer->getTable('core/variable_value') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Variable Value Id' + ), + 'variable_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Variable Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'plain_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Plain Text Value' + ), + 'html_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Html Value' + ) + ), + 'comment' => 'Variable Value' + ), + $installer->getTable('core/translate') => array( + 'columns' => array( + 'key_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Key Id of Translation' + ), + 'string' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => 'Translate String', + 'comment' => 'Translation String' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'translate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Translate' + ), + 'locale' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'default' => 'en_US', + 'comment' => 'Locale' + ) + ), + 'comment' => 'Translations' + ), + $installer->getTable('core/session') => array( + 'columns' => array( + 'session_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Session Id' + ), + 'session_expires' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Date of Session Expiration' + ), + 'session_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BLOB, + 'length' => '2M', + 'nullable' => false, + 'comment' => 'Session Data' + ) + ), + 'comment' => 'Database Sessions Storage' + ), + $installer->getTable('core/layout_update') => array( + 'columns' => array( + 'layout_update_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Layout Update Id' + ), + 'handle' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Handle' + ), + 'xml' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Xml' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Layout Updates' + ), + $installer->getTable('core/layout_link') => array( + 'columns' => array( + 'layout_link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'area' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Area' + ), + 'package' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Package' + ), + 'theme' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Theme' + ), + 'layout_update_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Layout Update Id' + ) + ), + 'comment' => 'Layout Link' + ), + $installer->getTable('core/url_rewrite') => array( + 'columns' => array( + 'url_rewrite_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rewrite Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'id_path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Id Path' + ), + 'request_path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Request Path' + ), + 'target_path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Target Path' + ), + 'is_system' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '1', + 'comment' => 'Defines is Rewrite System' + ), + 'options' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Options' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Deascription' + ) + ), + 'comment' => 'Url Rewrites' + ), + $installer->getTable('core/design_change') => array( + 'columns' => array( + 'design_change_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Design Change Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'design' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Design' + ), + 'date_from' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'First Date of Design Activity' + ), + 'date_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Last Date of Design Activity' + ) + ), + 'comment' => 'Design Changes' + ), + $installer->getTable('core/flag') => array( + 'columns' => array( + 'flag_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Flag Id' + ), + 'flag_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Flag Code' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Flag State' + ), + 'flag_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Flag Data' + ), + 'last_update' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT_UPDATE, + 'comment' => 'Date of Last Flag Update' + ) + ), + 'comment' => 'Flag' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->dropColumn( + $installer->getTable('core/session'), + 'website_id' +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('core/variable'), + $installer->getIdxName( + 'core/variable', + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/variable_value'), + $installer->getIdxName( + 'core/variable_value', + array('variable_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('variable_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/variable_value'), + $installer->getIdxName('core/variable_value', array('variable_id')), + array('variable_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/variable_value'), + $installer->getIdxName('core/variable_value', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/cache'), + $installer->getIdxName('core/cache', array('expire_time')), + array('expire_time') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/cache_tag'), + $installer->getIdxName('core/cache_tag', array('cache_id')), + array('cache_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/config_data'), + $installer->getIdxName( + 'core/config_data', + array('scope', 'scope_id', 'path'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('scope', 'scope_id', 'path'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/email_template'), + $installer->getIdxName( + 'core/email_template', + array('template_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('template_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/email_template'), + $installer->getIdxName('core/email_template', array('added_at')), + array('added_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/email_template'), + $installer->getIdxName('core/email_template', array('modified_at')), + array('modified_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/flag'), + $installer->getIdxName('core/flag', array('last_update')), + array('last_update') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/layout_link'), + $installer->getIdxName( + 'core/layout_link', + array('store_id', 'package', 'theme', 'layout_update_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('store_id', 'package', 'theme', 'layout_update_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/layout_link'), + $installer->getIdxName('core/layout_link', array('layout_update_id')), + array('layout_update_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/layout_update'), + $installer->getIdxName('core/layout_update', array('handle')), + array('handle') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store'), + $installer->getIdxName( + 'core/store', + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store'), + $installer->getIdxName('core/store', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store'), + $installer->getIdxName('core/store', array('is_active', 'sort_order')), + array('is_active', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store'), + $installer->getIdxName('core/store', array('group_id')), + array('group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store_group'), + $installer->getIdxName('core/store_group', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/store_group'), + $installer->getIdxName('core/store_group', array('default_store_id')), + array('default_store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/translate'), + $installer->getIdxName( + 'core/translate', + array('store_id', 'locale', 'string'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('store_id', 'locale', 'string'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/translate'), + $installer->getIdxName('core/translate', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/url_rewrite'), + $installer->getIdxName( + 'core/url_rewrite', + array('request_path', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('request_path', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/url_rewrite'), + $installer->getIdxName( + 'core/url_rewrite', + array('id_path', 'is_system', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('id_path', 'is_system', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/url_rewrite'), + $installer->getIdxName('core/url_rewrite', array('target_path', 'store_id')), + array('target_path', 'store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/url_rewrite'), + $installer->getIdxName('core/url_rewrite', array('id_path')), + array('id_path') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/url_rewrite'), + $installer->getIdxName('core/url_rewrite', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/website'), + $installer->getIdxName( + 'core/website', + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/website'), + $installer->getIdxName('core/website', array('sort_order')), + array('sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/website'), + $installer->getIdxName('core/website', array('default_group_id')), + array('default_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('core/design_change'), + $installer->getIdxName('core/design_change', array('store_id')), + array('store_id') +); + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/cache_tag', 'cache_id', 'core/cache', 'id'), + $installer->getTable('core/cache_tag'), + 'cache_id', + $installer->getTable('core/cache'), + 'id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/layout_link', 'store_id', 'core/store', 'store_id'), + $installer->getTable('core/layout_link'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/layout_link', 'layout_update_id', 'core/layout_update', 'layout_update_id'), + $installer->getTable('core/layout_link'), + 'layout_update_id', + $installer->getTable('core/layout_update'), + 'layout_update_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/store', 'group_id', 'core/store_group', 'group_id'), + $installer->getTable('core/store'), + 'group_id', + $installer->getTable('core/store_group'), + 'group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/store', 'website_id', 'core/website', 'website_id'), + $installer->getTable('core/store'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/store_group', 'website_id', 'core/website', 'website_id'), + $installer->getTable('core/store_group'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/translate', 'store_id', 'core/store', 'store_id'), + $installer->getTable('core/translate'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/url_rewrite', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('core/url_rewrite'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/url_rewrite', 'category_id', 'catalog/category', 'entity_id'), + $installer->getTable('core/url_rewrite'), + 'category_id', + $installer->getTable('catalog/category'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/url_rewrite', 'store_id', 'core/store', 'store_id'), + $installer->getTable('core/url_rewrite'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/variable_value', 'store_id', 'core/store', 'store_id'), + $installer->getTable('core/variable_value'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/variable_value', 'variable_id', 'core/variable', 'variable_id'), + $installer->getTable('core/variable_value'), + 'variable_id', + $installer->getTable('core/variable'), + 'variable_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('core/design_change', 'store_id', 'core/store', 'store_id'), + $installer->getTable('core/design_change'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Cron/Exception.php b/app/code/core/Mage/Cron/Exception.php index 0fd10a129c..4e4ed73371 100644 --- a/app/code/core/Mage/Cron/Exception.php +++ b/app/code/core/Mage/Cron/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cron/Helper/Data.php b/app/code/core/Mage/Cron/Helper/Data.php index 65dab58c85..d5649c2de6 100644 --- a/app/code/core/Mage/Cron/Helper/Data.php +++ b/app/code/core/Mage/Cron/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cron/Model/Mysql4/Schedule.php b/app/code/core/Mage/Cron/Model/Mysql4/Schedule.php index 6f47faaca7..c80b6f4f04 100644 --- a/app/code/core/Mage/Cron/Model/Mysql4/Schedule.php +++ b/app/code/core/Mage/Cron/Model/Mysql4/Schedule.php @@ -20,44 +20,18 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Schedule mysql4 resource * - * @category Mage - * @package Mage_Cron + * @category Mage + * @package Mage_Cron * @author Magento Core Team */ -class Mage_Cron_Model_Mysql4_Schedule extends Mage_Core_Model_Mysql4_Abstract +class Mage_Cron_Model_Mysql4_Schedule extends Mage_Cron_Model_Resource_Schedule { - public function _construct() - { - $this->_init('cron/schedule', 'schedule_id'); - } - - /** - * If job is currently in $currentStatus, set it to $newStatus - * and return true. Otherwise, return false and do not change the job. - * - * This method is used to implement locking for cron jobs. - * - * @param String $newStatus - * @param String $currentStatus - */ - public function trySetJobStatusAtomic($scheduleId, $newStatus, $currentStatus) - { - $write = $this->_getWriteAdapter(); - $result = $write->update( - $this->getTable('cron/schedule'), - array('status' => $newStatus), - array('schedule_id = ?' => $scheduleId, 'status = ?' => $currentStatus) - ); - if ($result == 1) { - return true; - } - return false; - } } diff --git a/app/code/core/Mage/Cron/Model/Mysql4/Schedule/Collection.php b/app/code/core/Mage/Cron/Model/Mysql4/Schedule/Collection.php index 258a7dd016..7932ba0910 100644 --- a/app/code/core/Mage/Cron/Model/Mysql4/Schedule/Collection.php +++ b/app/code/core/Mage/Cron/Model/Mysql4/Schedule/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Schedules Collection * - * @category Mage - * @package Mage_Cron + * @category Mage + * @package Mage_Cron * @author Magento Core Team */ -class Mage_Cron_Model_Mysql4_Schedule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Cron_Model_Mysql4_Schedule_Collection extends Mage_Cron_Model_Resource_Schedule_Collection { - public function _construct() - { - $this->_init('cron/schedule'); - } } diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php index 21748e98e8..1614271826 100644 --- a/app/code/core/Mage/Cron/Model/Observer.php +++ b/app/code/core/Mage/Cron/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -60,11 +60,15 @@ public function dispatch($observer) $scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60; $now = time(); $jobsRoot = Mage::getConfig()->getNode('crontab/jobs'); + $defaultJobsRoot = Mage::getConfig()->getNode('default/crontab/jobs'); foreach ($schedules->getIterator() as $schedule) { $jobConfig = $jobsRoot->{$schedule->getJobCode()}; if (!$jobConfig || !$jobConfig->run) { - continue; + $jobConfig = $defaultJobsRoot->{$schedule->getJobCode()}; + if (!$jobConfig || !$jobConfig->run) { + continue; + } } $runConfig = $jobConfig->run; diff --git a/app/code/core/Mage/Cron/Model/Resource/Schedule.php b/app/code/core/Mage/Cron/Model/Resource/Schedule.php new file mode 100755 index 0000000000..d36dcd71f3 --- /dev/null +++ b/app/code/core/Mage/Cron/Model/Resource/Schedule.php @@ -0,0 +1,69 @@ + + */ +class Mage_Cron_Model_Resource_Schedule extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource + * + */ + public function _construct() + { + $this->_init('cron/schedule', 'schedule_id'); + } + + /** + * If job is currently in $currentStatus, set it to $newStatus + * and return true. Otherwise, return false and do not change the job. + * This method is used to implement locking for cron jobs. + * + * @param unknown_type $scheduleId + * @param String $newStatus + * @param String $currentStatus + * @return unknown + */ + public function trySetJobStatusAtomic($scheduleId, $newStatus, $currentStatus) + { + $write = $this->_getWriteAdapter(); + $result = $write->update( + $this->getTable('cron/schedule'), + array('status' => $newStatus), + array('schedule_id = ?' => $scheduleId, 'status = ?' => $currentStatus) + ); + if ($result == 1) { + return true; + } + return false; + } +} diff --git a/app/code/core/Mage/Cron/Model/Resource/Schedule/Collection.php b/app/code/core/Mage/Cron/Model/Resource/Schedule/Collection.php new file mode 100755 index 0000000000..1ee6188033 --- /dev/null +++ b/app/code/core/Mage/Cron/Model/Resource/Schedule/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Cron_Model_Resource_Schedule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource collection + * + */ + public function _construct() + { + $this->_init('cron/schedule'); + } +} diff --git a/app/code/core/Mage/Cron/Model/Schedule.php b/app/code/core/Mage/Cron/Model/Schedule.php index 01ea37a44c..cd136077df 100644 --- a/app/code/core/Mage/Cron/Model/Schedule.php +++ b/app/code/core/Mage/Cron/Model/Schedule.php @@ -20,15 +20,32 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Crontab schedule model * - * @category Mage - * @package Mage_Cron + * @method Mage_Cron_Model_Resource_Schedule _getResource() + * @method Mage_Cron_Model_Resource_Schedule getResource() + * @method string getJobCode() + * @method Mage_Cron_Model_Schedule setJobCode(string $value) + * @method string getStatus() + * @method Mage_Cron_Model_Schedule setStatus(string $value) + * @method string getMessages() + * @method Mage_Cron_Model_Schedule setMessages(string $value) + * @method string getCreatedAt() + * @method Mage_Cron_Model_Schedule setCreatedAt(string $value) + * @method string getScheduledAt() + * @method Mage_Cron_Model_Schedule setScheduledAt(string $value) + * @method string getExecutedAt() + * @method Mage_Cron_Model_Schedule setExecutedAt(string $value) + * @method string getFinishedAt() + * @method Mage_Cron_Model_Schedule setFinishedAt(string $value) + * + * @category Mage + * @package Mage_Cron * @author Magento Core Team */ class Mage_Cron_Model_Schedule extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Cron/etc/config.xml b/app/code/core/Mage/Cron/etc/config.xml index ad328d8870..93e4bd6f1f 100644 --- a/app/code/core/Mage/Cron/etc/config.xml +++ b/app/code/core/Mage/Cron/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.1 + 1.6.0.0 @@ -42,19 +42,19 @@ Mage_Cron_Model - cron_mysql4 + cron_resource - - Mage_Cron_Model_Mysql4 + + Mage_Cron_Model_Resource + cron_mysql4 cron_schedule
-
+
- @@ -66,20 +66,7 @@ - - @@ -92,16 +79,15 @@ - - - - - - Mage_Cron.csv - - - - + + + + + Mage_Cron.csv + + + +
diff --git a/app/code/core/Mage/Cron/etc/system.xml b/app/code/core/Mage/Cron/etc/system.xml index dbbe608d6e..c947686ee1 100644 --- a/app/code/core/Mage/Cron/etc/system.xml +++ b/app/code/core/Mage/Cron/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Cron/sql/cron_setup/install-1.6.0.0.php b/app/code/core/Mage/Cron/sql/cron_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..cc9d323db2 --- /dev/null +++ b/app/code/core/Mage/Cron/sql/cron_setup/install-1.6.0.0.php @@ -0,0 +1,74 @@ +startSetup(); + +/** + * Create table 'cron/schedule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('cron/schedule')) + ->addColumn('schedule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Schedule Id') + ->addColumn('job_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '0', + ), 'Job Code') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 7, array( + 'nullable' => false, + 'default' => 'pending', + ), 'Status') + ->addColumn('messages', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Messages') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('scheduled_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Scheduled At') + ->addColumn('executed_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Executed At') + ->addColumn('finished_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Finished At') + ->addIndex($installer->getIdxName('cron/schedule', array('job_code')), + array('job_code')) + ->addIndex($installer->getIdxName('cron/schedule', array('scheduled_at', 'status')), + array('scheduled_at', 'status')) + ->setComment('Cron Schedule'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Cron/sql/cron_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-install-0.7.0.php index 484ebb151e..26801fb71e 100644 --- a/app/code/core/Mage/Cron/sql/cron_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-0.7.0-0.7.1.php index 7d5401cf4d..dd965d2569 100644 --- a/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Cron - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..8148b69297 --- /dev/null +++ b/app/code/core/Mage/Cron/sql/cron_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,118 @@ +startSetup(); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('cron/schedule'), + 'TASK_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('cron/schedule'), + 'SCHEDULED_AT' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('cron/schedule') => array( + 'columns' => array( + 'schedule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Schedule Id' + ), + 'job_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Job Code' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 7, + 'nullable' => false, + 'default' => 'pending', + 'comment' => 'Status' + ), + 'messages' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Messages' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'scheduled_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Scheduled At' + ), + 'executed_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Executed At' + ), + 'finished_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Finished At' + ) + ), + 'comment' => 'Cron Schedule' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('cron/schedule'), + $installer->getIdxName('cron/schedule', array('job_code')), + array('job_code') +); + +$installer->getConnection()->addIndex( + $installer->getTable('cron/schedule'), + $installer->getIdxName('cron/schedule', array('scheduled_at', 'status')), + array('scheduled_at', 'status') +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Customer/Block/Account.php b/app/code/core/Mage/Customer/Block/Account.php index e4efd2b9c8..5ef4db3ad4 100644 --- a/app/code/core/Mage/Customer/Block/Account.php +++ b/app/code/core/Mage/Customer/Block/Account.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard.php b/app/code/core/Mage/Customer/Block/Account/Dashboard.php index f0c621b515..097715abb2 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php index 63e4e26320..8c2235ad3d 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Block.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Block.php index 8c4fbbebea..f518a2ddb5 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Block.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php index 443e784b9d..650d0760cf 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php index 8089580750..01c5da5154 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php index d0970dbda7..4392a492a2 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php index cef5dd0ff0..95db64260b 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Forgotpassword.php b/app/code/core/Mage/Customer/Block/Account/Forgotpassword.php index 6197992b6e..d1e18c6d0d 100644 --- a/app/code/core/Mage/Customer/Block/Account/Forgotpassword.php +++ b/app/code/core/Mage/Customer/Block/Account/Forgotpassword.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Account/Navigation.php b/app/code/core/Mage/Customer/Block/Account/Navigation.php index 29f370382e..14b514dc89 100644 --- a/app/code/core/Mage/Customer/Block/Account/Navigation.php +++ b/app/code/core/Mage/Customer/Block/Account/Navigation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Address/Book.php b/app/code/core/Mage/Customer/Block/Address/Book.php index 4d9030ce5a..8957f6b1e2 100644 --- a/app/code/core/Mage/Customer/Block/Address/Book.php +++ b/app/code/core/Mage/Customer/Block/Address/Book.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index 8d3b5fdb69..d00f8b5766 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php b/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php index 2e57743f87..1e5e4dd17c 100644 --- a/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php +++ b/app/code/core/Mage/Customer/Block/Address/Renderer/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Address/Renderer/Interface.php b/app/code/core/Mage/Customer/Block/Address/Renderer/Interface.php index 9842122b04..826c103970 100644 --- a/app/code/core/Mage/Customer/Block/Address/Renderer/Interface.php +++ b/app/code/core/Mage/Customer/Block/Address/Renderer/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index 9eadb2f1a6..f09e6ad023 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Form/Login.php b/app/code/core/Mage/Customer/Block/Form/Login.php index fd678eb12b..c939a925fd 100644 --- a/app/code/core/Mage/Customer/Block/Form/Login.php +++ b/app/code/core/Mage/Customer/Block/Form/Login.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index f6948b08ed..c2a4c78b90 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -125,7 +125,7 @@ public function getRegion() */ public function isNewsletterEnabled() { - return !Mage::getStoreConfigFlag('advanced/modules_disable_output/Mage_Newsletter'); + return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter'); } /** diff --git a/app/code/core/Mage/Customer/Block/Newsletter.php b/app/code/core/Mage/Customer/Block/Newsletter.php index 91cca9583f..5dbe1e099d 100644 --- a/app/code/core/Mage/Customer/Block/Newsletter.php +++ b/app/code/core/Mage/Customer/Block/Newsletter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Widget/Abstract.php b/app/code/core/Mage/Customer/Block/Widget/Abstract.php index 44f95cd2d3..0d7fe0ecd4 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Abstract.php +++ b/app/code/core/Mage/Customer/Block/Widget/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Widget/Dob.php b/app/code/core/Mage/Customer/Block/Widget/Dob.php index 0f2d90919c..5c5b4eed66 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Dob.php +++ b/app/code/core/Mage/Customer/Block/Widget/Dob.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Widget/Gender.php b/app/code/core/Mage/Customer/Block/Widget/Gender.php index 16c5967ba7..cadcdbf3c6 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Gender.php +++ b/app/code/core/Mage/Customer/Block/Widget/Gender.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Block/Widget/Name.php b/app/code/core/Mage/Customer/Block/Widget/Name.php index 27a5cd784e..83422320cc 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Name.php +++ b/app/code/core/Mage/Customer/Block/Widget/Name.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -77,6 +77,7 @@ public function isPrefixRequired() public function getPrefixOptions() { $prefixOptions = $this->helper('customer')->getNamePrefixOptions(); + if ($this->getObject() && !empty($prefixOptions)) { $oldPrefix = $this->escapeHtml(trim($this->getObject()->getPrefix())); $prefixOptions[$oldPrefix] = $oldPrefix; @@ -157,16 +158,17 @@ public function getContainerClassName() } /** - * Retrieve customer attribute instance + * Retrieve customer or customer address attribute instance * * @param string $attributeCode - * @return Mage_Customer_Model_Attribute + * @return Mage_Eav_Model_Entity_Attribute_Abstract */ protected function _getAttribute($attributeCode) { - if (!($this->getObject() instanceof Mage_Customer_Model_Customer)) { - return Mage::getSingleton('eav/config')->getAttribute('customer_address', $attributeCode); + if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof Mage_Customer_Model_Customer) { + return parent::_getAttribute($attributeCode); } - return parent::_getAttribute($attributeCode); + + return Mage::getSingleton('eav/config')->getAttribute('customer_address', $attributeCode); } } diff --git a/app/code/core/Mage/Customer/Block/Widget/Taxvat.php b/app/code/core/Mage/Customer/Block/Widget/Taxvat.php index caef4fdb96..1fe6f4ebcb 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Taxvat.php +++ b/app/code/core/Mage/Customer/Block/Widget/Taxvat.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Exception.php b/app/code/core/Mage/Customer/Exception.php index dca4d72d5c..60763500c2 100644 --- a/app/code/core/Mage/Customer/Exception.php +++ b/app/code/core/Mage/Customer/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Helper/Address.php b/app/code/core/Mage/Customer/Helper/Address.php index 09f75a6611..54c4be2f26 100644 --- a/app/code/core/Mage/Customer/Helper/Address.php +++ b/app/code/core/Mage/Customer/Helper/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index a0dc9242d1..73254ce378 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index b8ecb283b3..f6ffc58cd4 100644 --- a/app/code/core/Mage/Customer/Model/Address.php +++ b/app/code/core/Mage/Customer/Model/Address.php @@ -20,16 +20,16 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Customer address + * Customer address model * * @category Mage * @package Mage_Customer - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Customer_Model_Address extends Mage_Customer_Model_Address_Abstract { diff --git a/app/code/core/Mage/Customer/Model/Address/Abstract.php b/app/code/core/Mage/Customer/Model/Address/Abstract.php index 2cb39a9f77..4c85d49281 100644 --- a/app/code/core/Mage/Customer/Model/Address/Abstract.php +++ b/app/code/core/Mage/Customer/Model/Address/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Address/Api.php b/app/code/core/Mage/Customer/Model/Address/Api.php index b34bb644ce..c292bc38b9 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api.php +++ b/app/code/core/Mage/Customer/Model/Address/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Address/Api/V2.php b/app/code/core/Mage/Customer/Model/Address/Api/V2.php index 6a71fb4a15..29cef1aa98 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api/V2.php +++ b/app/code/core/Mage/Customer/Model/Address/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Address/Config.php b/app/code/core/Mage/Customer/Model/Address/Config.php index 5d4db7c993..0b3553d3c2 100644 --- a/app/code/core/Mage/Customer/Model/Address/Config.php +++ b/app/code/core/Mage/Customer/Model/Address/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Api/Resource.php b/app/code/core/Mage/Customer/Model/Api/Resource.php index 3abec7751f..b6a52df146 100644 --- a/app/code/core/Mage/Customer/Model/Api/Resource.php +++ b/app/code/core/Mage/Customer/Model/Api/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute.php b/app/code/core/Mage/Customer/Model/Attribute.php index e7f63a8880..5b155bf360 100644 --- a/app/code/core/Mage/Customer/Model/Attribute.php +++ b/app/code/core/Mage/Customer/Model/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data.php b/app/code/core/Mage/Customer/Model/Attribute/Data.php index b4909a9599..df32706eb3 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Abstract.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Abstract.php index 9bfd5fba52..7652c499fe 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Abstract.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Boolean.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Boolean.php index 9a7c5a4307..f0eaae352b 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Boolean.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Date.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Date.php index b904b6453b..ff4d931b9e 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Date.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Date.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/File.php b/app/code/core/Mage/Customer/Model/Attribute/Data/File.php index 25686d28f2..f3a10186d3 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/File.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Hidden.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Hidden.php index cded7d222b..3481f340a4 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Hidden.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Hidden.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Image.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Image.php index e06c2dbe04..e296f9f78a 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Image.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Multiline.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Multiline.php index 78c0915c47..dd266ae6b3 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Multiline.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Multiline.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Multiselect.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Multiselect.php index d1d784aaab..232266392a 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Multiselect.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Multiselect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Postcode.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Postcode.php index f51667133e..57f131b454 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Postcode.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Postcode.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Select.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Select.php index d65d5bc4ca..1081d9d4b1 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Select.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Select.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Text.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Text.php index de23cba6c9..d146a1b6a0 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Text.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Text.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Attribute/Data/Textarea.php b/app/code/core/Mage/Customer/Model/Attribute/Data/Textarea.php index c8df4f38e6..224ed3744c 100644 --- a/app/code/core/Mage/Customer/Model/Attribute/Data/Textarea.php +++ b/app/code/core/Mage/Customer/Model/Attribute/Data/Textarea.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Config/Share.php b/app/code/core/Mage/Customer/Model/Config/Share.php index ccea3f3347..d91ae036c5 100644 --- a/app/code/core/Mage/Customer/Model/Config/Share.php +++ b/app/code/core/Mage/Customer/Model/Config/Share.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php index a60494fecc..aa8cbff738 100644 --- a/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php +++ b/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php b/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php index 07b687d432..f6e578c6d6 100644 --- a/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php +++ b/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 44989477d3..f1ca797b60 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -104,8 +104,9 @@ public function getSharingConfig() * * @param string $login * @param string $password + * @throws Mage_Core_Exception * @return true - * @throws Exception + * */ public function authenticate($login, $password) { @@ -124,6 +125,7 @@ public function authenticate($login, $password) 'model' => $this, 'password' => $password, )); + return true; } @@ -143,14 +145,14 @@ public function loadByEmail($customerEmail) /** * Processing object before save data * - * @return Mage_Core_Model_Abstract + * @return Mage_Customer_Model_Customer */ protected function _beforeSave() { parent::_beforeSave(); $storeId = $this->getStoreId(); - if (is_null($storeId)) { + if ($storeId === null) { $this->setStoreId(Mage::app()->getStore()->getId()); } @@ -162,7 +164,7 @@ protected function _beforeSave() * Change customer password * * @param string $newPassword - * @return this + * @return Mage_Customer_Model_Customer */ public function changePassword($newPassword) { @@ -247,7 +249,7 @@ public function getAddressCollection() */ public function getAddressesCollection() { - if (is_null($this->_addressesCollection)) { + if ($this->_addressesCollection === null) { $this->_addressesCollection = $this->getAddressCollection() ->setCustomerFilter($this) ->addAttributeToSelect('*'); @@ -277,7 +279,7 @@ public function getAddresses() */ public function getAttributes() { - if (null === $this->_attributes) { + if ($this->_attributes === null) { $this->_attributes = $this->_getResource() ->loadAllAttributes($this) ->getSortedAttributes(); @@ -289,7 +291,7 @@ public function getAttributes() * Get customer attribute model object * * @param string $attributeCode - * @return Mage_Customer_Model_Entity_Attribute || null + * @return Mage_Customer_Model_Entity_Attribute | null */ public function getAttribute($attributeCode) { @@ -317,9 +319,10 @@ public function setPassword($password) * Hash customer password * * @param string $password + * @param int $salt * @return string */ - public function hashPassword($password, $salt=null) + public function hashPassword($password, $salt = null) { return Mage::helper('core')->getHash($password, !is_null($salt) ? $salt : 2); } @@ -330,7 +333,7 @@ public function hashPassword($password, $salt=null) * @param int $length * @return string */ - public function generatePassword($length=6) + public function generatePassword($length = 6) { return Mage::helper('core')->getRandomString($length); } @@ -343,7 +346,8 @@ public function generatePassword($length=6) */ public function validatePassword($password) { - if (!($hash = $this->getPasswordHash())) { + $hash = $this->getPasswordHash(); + if (!$hash) { return false; } return Mage::helper('core')->validateHash($password, $hash); @@ -428,7 +432,7 @@ public function getDefaultShippingAddress() /** * Retrieve ids of default addresses * - * @return unknown + * @return array */ public function getPrimaryAddressIds() { @@ -460,8 +464,7 @@ public function getPrimaryAddresses() if ($primaryShipping) { if ($primaryBilling->getId() == $primaryShipping->getId()) { $primaryBilling->setIsPrimaryShipping(true); - } - else { + } else { $primaryShipping->setIsPrimaryShipping(true); $addresses[] = $primaryShipping; } @@ -497,6 +500,7 @@ public function isAddressPrimary(Mage_Customer_Model_Address $address) /** * Send email with new account specific information * + * @throws Mage_Core_Exception * @return Mage_Customer_Model_Customer */ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0') @@ -507,7 +511,7 @@ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeI 'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE, // email with confirmation link ); if (!isset($types[$type])) { - throw new Exception(Mage::helper('customer')->__('Wrong transactional account email type.')); + Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type')); } $translate = Mage::getSingleton('core/translate'); @@ -519,7 +523,7 @@ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeI } Mage::getModel('core/email_template') - ->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId)) + ->setDesignConfig(array('area' => 'frontend', 'store' => $storeId)) ->sendTransactional( Mage::getStoreConfig($types[$type], $storeId), Mage::getStoreConfig(self::XML_PATH_REGISTER_EMAIL_IDENTITY, $storeId), @@ -542,10 +546,11 @@ public function isConfirmationRequired() if ($this->canSkipConfirmation()) { return false; } - if (null === self::$_isConfirmationRequired) { + if (self::$_isConfirmationRequired === null) { $storeId = $this->getStoreId() ? $this->getStoreId() : null; - self::$_isConfirmationRequired = 1 == Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId); + self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId); } + return self::$_isConfirmationRequired; } @@ -571,13 +576,13 @@ public function sendPasswordReminderEmail() } Mage::getModel('core/email_template') - ->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId)) + ->setDesignConfig(array('area' => 'frontend', 'store' => $storeId)) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_TEMPLATE, $storeId), Mage::getStoreConfig(self::XML_PATH_FORGOT_EMAIL_IDENTITY, $storeId), $this->getEmail(), $this->getName(), - array('customer'=>$this) + array('customer' => $this) ); $translate->setTranslateInline(true); @@ -594,7 +599,8 @@ public function getGroupId() { if (!$this->hasData('group_id')) { $storeId = $this->getStoreId() ? $this->getStoreId() : Mage::app()->getStore()->getId(); - $this->setData('group_id', Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $storeId)); + $groupId = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $storeId); + $this->setData('group_id', $groupId); } return $this->getData('group_id'); } @@ -615,15 +621,14 @@ public function getTaxClassId() /** * Check store availability for customer * - * @param mixed $store + * @param Mage_Core_Model_Store | int $store * @return bool */ public function isInStore($store) { if ($store instanceof Mage_Core_Model_Store) { $storeId = $store->getId(); - } - else { + } else { $storeId = $store; } @@ -649,18 +654,18 @@ public function getStore() public function getSharedStoreIds() { $ids = $this->_getData('shared_store_ids'); - if (is_null($ids)) { + if ($ids === null) { $ids = array(); if ((bool)$this->getSharingConfig()->isWebsiteScope()) { $ids = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds(); - } - else { + } else { foreach (Mage::app()->getStores() as $store) { $ids[] = $store->getId(); } } $this->setData('shared_store_ids', $ids); } + return $ids; } @@ -672,12 +677,11 @@ public function getSharedStoreIds() public function getSharedWebsiteIds() { $ids = $this->_getData('shared_website_ids'); - if (is_null($ids)) { + if ($ids === null) { $ids = array(); if ((bool)$this->getSharingConfig()->isWebsiteScope()) { $ids[] = $this->getWebsiteId(); - } - else { + } else { foreach (Mage::app()->getWebsites() as $website) { $ids[] = $website->getId(); } @@ -688,7 +692,7 @@ public function getSharedWebsiteIds() } /** - * Enter description here... + * Set store to customer * * @param Mage_Core_Model_Store $store * @return Mage_Customer_Model_Customer @@ -768,12 +772,11 @@ public function importFromTextArray(array $row) $row = $row['row']; $regions = Mage::getResourceModel('directory/region_collection'); -// $config = Mage::getSingleton('eav/config')->getEntityType('customer'); $website = Mage::getModel('core/website')->load($row['website_code'], 'code'); if (!$website->getId()) { - $this->addError($hlp->__('Invalid website, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('Invalid website, skipping the record, line: %s', $line)); } else { $row['website_id'] = $website->getWebsiteId(); @@ -782,18 +785,18 @@ public function importFromTextArray(array $row) // Validate Email if (empty($row['email'])) { - $this->addError($hlp->__('Missing email, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('Missing email, skipping the record, line: %s', $line)); } else { $this->loadByEmail($row['email']); } if (empty($row['entity_id'])) { if ($this->getData('entity_id')) { - $this->addError($hlp->__('The customer email (%s) already exists, skipping the record, line: %s.', $row['email'], $line)); + $this->addError($hlp->__('The customer email (%s) already exists, skipping the record, line: %s', $row['email'], $line)); } } else { if ($row['entity_id'] != $this->getData('entity_id')) { - $this->addError($hlp->__('The customer ID and email did not match, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('The customer ID and email did not match, skipping the record, line: %s', $line)); } else { $this->unsetData(); $this->load($row['entity_id']); @@ -805,7 +808,7 @@ public function importFromTextArray(array $row) } if (empty($row['website_code'])) { - $this->addError($hlp->__('Missing website, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('Missing website, skipping the record, line: %s', $line)); } if (empty($row['group'])) { @@ -813,10 +816,10 @@ public function importFromTextArray(array $row) } if (empty($row['firstname'])) { - $this->addError($hlp->__('Missing first name, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('Missing first name, skipping the record, line: %s', $line)); } if (empty($row['lastname'])) { - $this->addError($hlp->__('Missing last name, skipping the record, line: %s.', $line)); + $this->addError($hlp->__('Missing last name, skipping the record, line: %s', $line)); } if (!empty($row['password_new'])) { @@ -827,31 +830,16 @@ public function importFromTextArray(array $row) if ($errors = $this->getErrors()) { $this->unsetData(); - $this->printError(join("
",$errors)); + $this->printError(implode('
', $errors)); return; } -// $entity = $this->getResource(); - foreach ($row as $field=>$value) { - -// $attribute = $entity->getAttribute($field); -// if (!$attribute) { -// echo $field; -// continue; -// } -// if ($attribute->usesSource()) { -// $source = $attribute->getSource(); -// $optionId = $config->getSourceOptionId($source, $value); -// if (is_null($optionId)) { -// $this->printError($hlp->__("Invalid attribute option specified for attribute attribute %s (%s).", $field, $value), $line); -// } -// $value = $optionId; -// } + foreach ($row as $field => $value) { $this->setData($field, $value); } if (!$this->validateAddress($row, 'billing')) { - $this->printError($hlp->__('Invalid billing address for (%s).', $row['email']), $line); + $this->printError($hlp->__('Invalid billing address for (%s)', $row['email']), $line); } else { // Handling billing address $billingAddress = $this->getPrimaryBillingAddress(); @@ -868,11 +856,13 @@ public function importFromTextArray(array $row) $billingAddress->setLastname($row['lastname']); $billingAddress->setCity($row['billing_city']); $billingAddress->setRegion($row['billing_region']); - if (isset($regionId)) $billingAddress->setRegionId($regionId); + if (isset($regionId)) { + $billingAddress->setRegionId($regionId); + } $billingAddress->setCountryId($row['billing_country']); $billingAddress->setPostcode($row['billing_postcode']); if (isset($row['billing_street2'])) { - $billingAddress->setStreet(array($row['billing_street1'],$row['billing_street2'])); + $billingAddress->setStreet(array($row['billing_street1'], $row['billing_street2'])); } else { $billingAddress->setStreet(array($row['billing_street1'])); } @@ -890,7 +880,7 @@ public function importFromTextArray(array $row) } if (!$this->validateAddress($row, 'shipping')) { - $this->printError($hlp->__('Invalid shipping address for (%s).', $row['email']), $line); + $this->printError($hlp->__('Invalid shipping address for (%s)', $row['email']), $line); } else { // Handling shipping address $shippingAddress = $this->getPrimaryShippingAddress(); @@ -908,7 +898,9 @@ public function importFromTextArray(array $row) $shippingAddress->setLastname($row['lastname']); $shippingAddress->setCity($row['shipping_city']); $shippingAddress->setRegion($row['shipping_region']); - if (isset($regionId)) $shippingAddress->setRegionId($regionId); + if (isset($regionId)) { + $shippingAddress->setRegionId($regionId); + } $shippingAddress->setCountryId($row['shipping_country']); $shippingAddress->setPostcode($row['shipping_postcode']); if (isset($row['shipping_street2'])) { @@ -927,43 +919,80 @@ public function importFromTextArray(array $row) // End handling shipping address } if (!empty($row['is_subscribed'])) { - $this->setIsSubscribed(strtolower($row['is_subscribed'])==self::SUBSCRIBED_YES ? 1 : 0); + $isSubscribed = (bool)strtolower($row['is_subscribed']) == self::SUBSCRIBED_YES; + $this->setIsSubscribed($isSubscribed); } unset($row); return $this; } + /** + * Unset subscription + * + * @return Mage_Customer_Model_Customer + */ function unsetSubscription() { if (isset($this->_isSubscribed)) { unset($this->_isSubscribed); } + return $this; } + /** + * Clean all addresses + * + * @return Mage_Customer_Model_Customer + */ function cleanAllAddresses() { $this->_addressesCollection = null; $this->_addresses = null; } + /** + * Add error + * + * @return Mage_Customer_Model_Customer + */ function addError($error) { $this->_errors[] = $error; + return $this; } + /** + * Retreive errors + * + * @return array + */ function getErrors() { return $this->_errors; } + /** + * Reset errors array + * + * @return Mage_Customer_Model_Customer + */ function resetErrors() { $this->_errors = array(); + return $this; } + /** + * Print error + * + * @param $error + * @param $line + */ function printError($error, $line = null) { - if ($error == null) return false; - $img = 'error_msg_icon.gif'; + if ($error == null) { + return false; + } + $img = 'error_msg_icon.gif'; $liStyle = 'background-color:#FDD; '; echo '
  • '; echo ''; @@ -974,28 +1003,33 @@ function printError($error, $line = null) echo "
  • "; } + /** + * Validate address + * + * @param array $data + * @param string $type + * @return bool + */ function validateAddress(array $data, $type = 'billing') { - $fields = array('city', - 'country', 'postcode', - 'telephone', 'street1'); - $usca = array('US', 'CA'); - $prefix = $type ? $type.'_':''; + $fields = array('city', 'country', 'postcode', 'telephone', 'street1'); + $usca = array('US', 'CA'); + $prefix = $type ? $type . '_' : ''; if ($data) { foreach($fields as $field) { - if (!isset($data[$prefix.$field])) { + if (!isset($data[$prefix . $field])) { return false; } if ($field == 'country' - && in_array(strtolower($data[$prefix.$field]), array('US', 'CA'))) { + && in_array(strtolower($data[$prefix . $field]), array('US', 'CA'))) { - if (!isset($data[$prefix.'region'])) { + if (!isset($data[$prefix . 'region'])) { return false; } $region = Mage::getModel('directory/region') - ->loadByName($data[$prefix.'region']); + ->loadByName($data[$prefix . 'region']); if (!$region->getId()) { return false; } @@ -1008,6 +1042,9 @@ function validateAddress(array $data, $type = 'billing') return false; } + /** + * Prepare customer for delete + */ protected function _beforeDelete() { $this->_protectFromNonAdmin(); @@ -1017,12 +1054,12 @@ protected function _beforeDelete() /** * Get customer created at date timestamp * - * @return int + * @return int|null */ public function getCreatedAtTimestamp() { if ($date = $this->getCreatedAt()) { - return $this->_getResource()->mktime($date); + return Varien_Date::toTimestamp($date); } return null; } @@ -1059,7 +1096,7 @@ public function isDeleteable() */ public function setIsDeleteable($value) { - $this->_isDeleteable = (boolean) $value; + $this->_isDeleteable = (bool)$value; return $this; } @@ -1081,7 +1118,7 @@ public function isReadonly() */ public function setIsReadonly($value) { - $this->_isReadonly = (boolean) $value; + $this->_isReadonly = (bool)$value; return $this; } @@ -1131,7 +1168,7 @@ public function getEntityTypeId() } return $entityTypeId; } - + /** * Get either first store ID from a set website or the provided as default * diff --git a/app/code/core/Mage/Customer/Model/Customer/Api.php b/app/code/core/Mage/Customer/Model/Customer/Api.php index 849fca6be6..8eec34b85e 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Api.php +++ b/app/code/core/Mage/Customer/Model/Customer/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Api/V2.php b/app/code/core/Mage/Customer/Model/Customer/Api/V2.php index 511ef759da..23fa81b79f 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Api/V2.php +++ b/app/code/core/Mage/Customer/Model/Customer/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Billing.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Billing.php index f07b7eb01f..d509f11d31 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Billing.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Billing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php index ff7ecf2eb7..37444a8773 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Password.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Shipping.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Shipping.php index d795ff6205..3a0197102d 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Shipping.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Store.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Store.php index 2ff3447038..057ca7567b 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Store.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Website.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Website.php index 784f0658d5..0f190f6f05 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Website.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Backend/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Group.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Group.php index 31975f002b..00abb66067 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Group.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Group.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Store.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Store.php index 5558210004..c6c0cc0e4f 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Store.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Website.php b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Website.php index dc35a984a3..29f8aa1d45 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Website.php +++ b/app/code/core/Mage/Customer/Model/Customer/Attribute/Source/Website.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Entity/Address.php b/app/code/core/Mage/Customer/Model/Entity/Address.php index 2c33a8da5c..350aaaa844 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address.php @@ -20,72 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer address entity resource model * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address extends Mage_Eav_Model_Entity_Abstract +class Mage_Customer_Model_Entity_Address extends Mage_Customer_Model_Resource_Address { - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - $this->setType('customer_address')->setConnection( - $resource->getConnection('customer_read'), - $resource->getConnection('customer_write') - ); - } - - protected function _afterSave(Varien_Object $address) - { - if ($address->getIsCustomerSaveTransaction()) { - return $this; - } - if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) { - $customer = Mage::getModel('customer/customer') - ->load($address->getCustomerId()); - - if ($address->getIsDefaultBilling()) { - $customer->setDefaultBilling($address->getId()); - } - if ($address->getIsDefaultShipping()) { - $customer->setDefaultShipping($address->getId()); - } - $customer->save(); - } - return $this; - } - - /** - * Return customer id - * - * @deprecated - * @param Mage_Customer_Model_Address $object - * @return integer - */ - public function getCustomerId($object) - { - return $object->getData('customer_id') ? $object->getData('customer_id') :$object->getParentId(); - } - - /** - * Set customer id - * - * @deprecated - * @param Mage_Customer_Model_Address $object - * @param integer $id - * @return Mage_Customer_Model_Address - */ - public function setCustomerId($object, $id) - { - $object->setParentId($id); - $object->setData('customer_id', $id); - return $object; - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Region.php b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Region.php index 7293658d05..433ee5f0ca 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Region.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Region.php @@ -20,29 +20,19 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Address region attribute backend * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Attribute_Backend_Region extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +class Mage_Customer_Model_Entity_Address_Attribute_Backend_Region + extends Mage_Customer_Model_Resource_Address_Attribute_Backend_Region { - public function beforeSave($object) - { - $region = $object->getData('region'); - if (is_numeric($region)) { - $regionModel = Mage::getModel('directory/region')->load($region); - if ($regionModel->getId() && $object->getCountryId() == $regionModel->getCountryId()) { - $object->setRegionId($regionModel->getId()) - ->setRegion($regionModel->getName()); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Street.php b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Street.php index e89c573489..74bd16b89b 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Street.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Backend/Street.php @@ -20,23 +20,19 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer password attribute backend * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Attribute_Backend_Street extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +class Mage_Customer_Model_Entity_Address_Attribute_Backend_Street + extends Mage_Customer_Model_Resource_Address_Attribute_Backend_Street { - public function beforeSave($object) - { - if ($street = $object->getStreet(-1)) { - $object->implodeStreetAddress(); - } - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Collection.php index 4e4957ab4e..9a20d0d629 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,11 @@ /** * Customer Address EAV additional attribute resource collection * - * @category Mage - * @package Mage_Customer - * @author Magento Core Team + * @category Mage + * @package Mage_Customer + * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Attribute_Collection extends Mage_Customer_Model_Entity_Attribute_Collection +class Mage_Customer_Model_Entity_Address_Attribute_Collection + extends Mage_Customer_Model_Resource_Address_Attribute_Collection { - /** - * Default attribute entity type code - * - * @var string - */ - protected $_entityTypeCode = 'customer_address'; } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Country.php b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Country.php index 9b960a41bb..3f143be02a 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Country.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Country.php @@ -20,28 +20,19 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer country attribute source * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Attribute_Source_Country extends Mage_Eav_Model_Entity_Attribute_Source_Table +class Mage_Customer_Model_Entity_Address_Attribute_Source_Country + extends Mage_Customer_Model_Resource_Address_Attribute_Source_Country { - public function getAllOptions() - { - if (!$this->_options) { - $this->_options = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray(); - /*$baseUrl = Mage::getBaseUrl(); - foreach ($this->_options as $index=>$option) { - $this->_options[$index]['style'] = 'background-image:url('.$baseUrl.'skins/default/images/icons/flags/'.strtolower($option['title']).'.gif)'; - }*/ - } - return $this->_options; - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Region.php b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Region.php index 229bc42fa4..be18d3135c 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Region.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Attribute/Source/Region.php @@ -20,24 +20,19 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer region attribute source * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Attribute_Source_Region extends Mage_Eav_Model_Entity_Attribute_Source_Table +class Mage_Customer_Model_Entity_Address_Attribute_Source_Region + extends Mage_Customer_Model_Resource_Address_Attribute_Source_Region { - public function getAllOptions() - { - if (!$this->_options) { - $this->_options = Mage::getResourceModel('directory/region_collection')->load()->toOptionArray(); - } - return $this->_options; - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Address/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Address/Collection.php index b97c09027d..cf93619c64 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Address/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Address/Collection.php @@ -20,32 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers collection * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Address_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +class Mage_Customer_Model_Entity_Address_Collection extends Mage_Customer_Model_Resource_Address_Collection { - protected function _construct() - { - $this->_init('customer/address'); - } - - public function setCustomerFilter($customer) - { - if ($customer->getId()) { - $this->addAttributeToFilter('parent_id', $customer->getId()); - } - else { - $this->addAttributeToFilter('parent_id', '-1'); - } - return $this; - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Attribute.php b/app/code/core/Mage/Customer/Model/Entity/Attribute.php index 2c96112475..e6dc2a94b2 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Customer/Model/Entity/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,154 +28,10 @@ /** * Customer attribute resource model * - * @category Mage - * @package Mage_Customer - * @author Magento Core Team + * @category Mage + * @package Mage_Customer + * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Attribute extends Mage_Eav_Model_Mysql4_Entity_Attribute +class Mage_Customer_Model_Entity_Attribute extends Mage_Customer_Model_Resource_Attribute { - /** - * Perform actions before object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Customer_Model_Entity_Attribute - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $validateRules = $object->getData('validate_rules'); - if (is_array($validateRules)) { - $object->setData('validate_rules', serialize($validateRules)); - } - return parent::_beforeSave($object); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - if ($object->getWebsite()->getId()) { - $columns = array(); - $describe = $this->_getReadAdapter()->describeTable($this->getTable('customer/eav_attribute_website')); - unset($describe['attribute_id']); - foreach (array_keys($describe) as $columnName) { - if ($columnName == 'attribute_id') { - continue; - } - $columns['scope_' . $columnName] = $columnName; - } - - $select->joinLeft( - array('scope_table' => $this->getTable('customer/eav_attribute_website')), - $this->getMainTable() . '.attribute_id = scope_table.attribute_id AND scope_table.website_id = ' - . (int)$object->getWebsite()->getId(), - $columns - ); - } - - return $select; - } - - /** - * Save attribute/form relations after attribute save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Customer_Model_Entity_Attribute - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $forms = $object->getData('used_in_forms'); - if (is_array($forms)) { - $where = array('attribute_id=?' => $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('customer/form_attribute'), $where); - - $data = array(); - foreach ($forms as $formCode) { - $data[] = array( - 'form_code' => $formCode, - 'attribute_id' => intval($object->getId()) - ); - } - - if ($data) { - $this->_getWriteAdapter()->insertMultiple($this->getTable('customer/form_attribute'), $data); - } - } - - // update sort order - if (!$object->isObjectNew() && $object->dataHasChangedFor('sort_order')) { - $bind = array( - 'sort_order' => $object->getSortOrder() - ); - $where = $this->_getWriteAdapter()->quoteInto('attribute_id=?', $object->getId()); - $this->_getWriteAdapter()->update($this->getTable('eav/entity_attribute'), $bind, $where); - } - - // save scope attributes - $websiteId = $object->getWebsite()->getId(); - if ($websiteId) { - $table = $this->getTable('customer/eav_attribute_website'); - $describe = $this->_getReadAdapter()->describeTable($table); - $data = array(); - if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) { - $data = $this->getScopeValues($object); - } - - $data['attribute_id'] = $object->getId(); - $data['website_id'] = $websiteId; - - $updateColumns = array(); - foreach (array_keys($describe) as $columnName) { - if ($columnName != 'attribute_id' && $columnName != 'website_id') { - $data[$columnName] = $object->getData('scope_' . $columnName); - $updateColumns[] = $columnName; - } - } - - $this->_getWriteAdapter()->insertOnDuplicate($table, $data, $updateColumns); - } - - return parent::_afterSave($object); - } - - /** - * Return scope values for attribute and website - * - * @param Mage_Customer_Model_Attribute $object - * @return array - */ - public function getScopeValues(Mage_Customer_Model_Attribute $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('customer/eav_attribute_website')) - ->where('attribute_id = ?', $object->getId()) - ->where('website_id = ?', $object->getWebsite()->getId()) - ->limit(1); - $result = $this->_getReadAdapter()->fetchRow($select); - - if (!$result) { - $result = array(); - } - - return $result; - } - - /** - * Return forms in which the attribute - * - * @param Mage_Core_Model_Abstract $object - * @return array - */ - public function getUsedInForms(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('customer/form_attribute'), 'form_code') - ->where('attribute_id = ?', (int)$object->getId()); - return $this->_getReadAdapter()->fetchCol($select); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Attribute/Collection.php index 3ddef3625b..189b5ac348 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,202 +28,10 @@ /** * Customer EAV additional attribute resource collection * - * @category Mage - * @package Mage_Customer - * @author Magento Core Team + * @category Mage + * @package Mage_Customer + * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Attribute_Collection extends Mage_Eav_Model_Mysql4_Entity_Attribute_Collection +class Mage_Customer_Model_Entity_Attribute_Collection extends Mage_Customer_Model_Resource_Attribute_Collection { - /** - * code of password hash in customer's EAV tables - */ - const EAV_CODE_PASSWORD_HASH = 'password_hash'; - - /** - * Current website scope instance - * - * @var Mage_Core_Model_Website - */ - protected $_website; - - /** - * Attribute Entity Type Filter - * - * @var Mage_Eav_Model_Entity_Type - */ - protected $_entityType; - - /** - * Default attribute entity type code - * - * @var string - */ - protected $_entityTypeCode = 'customer'; - - /** - * Return customer entity type instance - * - * @return Mage_Eav_Model_Entity_Type - */ - public function getEntityType() - { - if (is_null($this->_entityType)) { - $this->_entityType = Mage::getSingleton('eav/config')->getEntityType($this->_entityTypeCode); - } - return $this->_entityType; - } - - /** - * Set Website scope - * - * @param Mage_Core_Model_Website|int $website - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function setWebsite($website) - { - $this->_website = Mage::app()->getWebsite($website); - $this->addBindParam(':scope_website_id', $this->_website->getId()); - return $this; - } - - /** - * Return current website scope instance - * - * @return Mage_Core_Model_Website - */ - public function getWebsite() - { - if (is_null($this->_website)) { - $this->_website = Mage::app()->getStore()->getWebsite(); - } - return $this->_website; - } - - /** - * Initialize collection select - * - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - protected function _initSelect() - { - $entityType = $this->getEntityType(); - $extraTable = $entityType->getAdditionalAttributeTable(); - $mainDescribe = $this->getConnection()->describeTable($this->getResource()->getMainTable()); - $mainColumns = array(); - - foreach (array_keys($mainDescribe) as $columnName) { - $mainColumns[$columnName] = $columnName; - } - - $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable()), $mainColumns); - - // additional attribute data table - $extraDescribe = $this->getConnection()->describeTable($this->getTable($extraTable)); - $extraColumns = array(); - foreach (array_keys($extraDescribe) as $columnName) { - if (isset($mainColumns[$columnName])) { - continue; - } - $extraColumns[$columnName] = $columnName; - } - - $this->getSelect()->join( - array('additional_table' => $this->getTable($extraTable)), - 'additional_table.attribute_id = main_table.attribute_id', - $extraColumns) - ->where('main_table.entity_type_id = ?', $entityType->getId()); - - // scope values - - $scopeDescribe = $this->getConnection()->describeTable($this->getTable('customer/eav_attribute_website')); - $scopeColumns = array(); - foreach (array_keys($scopeDescribe) as $columnName) { - if ($columnName == 'attribute_id') { - continue; - } else if ($columnName == 'website_id') { - $scopeColumns['scope_website_id'] = $columnName; - } else { - if (isset($mainColumns[$columnName])) { - $alias = sprintf('scope_%s', $columnName); - $expression = new Zend_Db_Expr(sprintf('IFNULL(main_table.%s, scope_table.%s)', - $columnName, $columnName)); - $this->addFilterToMap($columnName, $expression); - $scopeColumns[$alias] = $columnName; - } else if (isset($extraColumns[$columnName])) { - $alias = sprintf('scope_%s', $columnName); - $expression = new Zend_Db_Expr(sprintf('IFNULL(additional_table.%s, scope_table.%s)', - $columnName, $columnName)); - $this->addFilterToMap($columnName, $expression); - $scopeColumns[$alias] = $columnName; - } - } - } - - $this->getSelect()->joinLeft( - array('scope_table' => $this->getTable('customer/eav_attribute_website')), - 'scope_table.attribute_id = main_table.attribute_id AND scope_table.website_id = :scope_website_id', - $scopeColumns - ); - $this->addBindParam(':scope_website_id', $this->getWebsite()->getId()); - - return $this; - } - - /** - * Specify attribute entity type filter - * Entity type is defined - * - * @param int $typeId - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function setEntityTypeFilter($type) - { - return $this; - } - - /** - * Specify filter by "is_visible" field - * - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function addVisibleFilter() - { - $this->addFieldToFilter('is_visible', 1); - return $this; - } - - /** - * Exclude system hidden attributes - * - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function addSystemHiddenFilter() - { - $field = '(CASE WHEN additional_table.is_system = 1 AND additional_table.is_visible = 0 THEN 1 ELSE 0 END)'; - $this->addFieldToFilter($field, 0); - return $this; - } - - /** - * Exclude system hidden attributes but include password hash - * - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function addSystemHiddenFilterWithPasswordHash() - { - $field = '(CASE WHEN additional_table.is_system = 1 AND additional_table.is_visible = 0 - AND main_table.attribute_code != "' . self::EAV_CODE_PASSWORD_HASH . '" THEN 1 ELSE 0 END)'; - $this->addFieldToFilter($field, 0); - return $this; - } - - /** - * Add exclude hidden frontend input attribute filter to collection - * - * @return Mage_Customer_Model_Entity_Attribute_Collection - */ - public function addExcludeHiddenFrontendFilter() - { - return $this->addFieldToFilter('main_table.frontend_input', array('neq' => 'hidden')); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Customer.php b/app/code/core/Mage/Customer/Model/Entity/Customer.php index 66269c7e31..3dbe8708ed 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Customer.php +++ b/app/code/core/Mage/Customer/Model/Entity/Customer.php @@ -20,271 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer entity resource model * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Customer extends Mage_Eav_Model_Entity_Abstract +class Mage_Customer_Model_Entity_Customer extends Mage_Customer_Model_Resource_Customer { - /** - * Initiate resources - * - */ - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - $this->setType('customer'); - $this->setConnection('customer_read', 'customer_write'); - } - - /** - * Retrieve customer entity default attributes - * - * @return array - */ - protected function _getDefaultAttributes() - { - return array( - 'entity_type_id', - 'attribute_set_id', - 'created_at', - 'updated_at', - 'increment_id', - 'store_id', - 'website_id' - ); - } - - /** - * Check customer scope, email and confirmation key before saving - * - * @param Varien_Object $customer - * @return Mage_Customer_Model_Entity_Customer - * @throws Mage_Core_Exception - */ - protected function _beforeSave(Varien_Object $customer) - { - parent::_beforeSave($customer); - - if (!$customer->getEmail()) { - Mage::throwException(Mage::helper('customer')->__('Customer email is required.')); - } - - $select = $this->_getWriteAdapter()->select() - ->from($this->getEntityTable(), array($this->getEntityIdField())) - ->where('email=?', $customer->getEmail()); - if ($customer->getSharingConfig()->isWebsiteScope()) { - $select->where('website_id=?', (int) $customer->getWebsiteId()); - } - if ($customer->getId()) { - $select->where('entity_id !=?', $customer->getId()); - } - - if ($this->_getWriteAdapter()->fetchOne($select)) { - throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This customer email already exists.'), - Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS - ); - } - - // set confirmation key logic - if ($customer->getForceConfirmed()) { - $customer->setConfirmation(null); - } - elseif ((!$customer->getId()) && ($customer->isConfirmationRequired())) { - $customer->setConfirmation($customer->getRandomConfirmationKey()); - } - // remove customer confirmation key from database, if empty - if (!$customer->getConfirmation()) { - $customer->setConfirmation(null); - } - - return $this; - } - - /** - * Save customer addresses and set default addresses in attributes backend - * - * @param Varien_Object $customer - * @return Mage_Eav_Model_Entity_Abstract - */ - protected function _afterSave(Varien_Object $customer) - { - $this->_saveAddresses($customer); - return parent::_afterSave($customer); - } - - /** - * Save/delete customer address - * - * @param Mage_Customer_Model_Customer $customer - * @return Mage_Customer_Model_Entity_Customer - */ - protected function _saveAddresses(Mage_Customer_Model_Customer $customer) - { - $defaultBillingId = $customer->getData('default_billing'); - $defaultShippingId = $customer->getData('default_shipping'); - foreach ($customer->getAddresses() as $address) { - if ($address->getData('_deleted')) { - if ($address->getId() == $defaultBillingId) { - $customer->setData('default_billing', null); - } - if ($address->getId() == $defaultShippingId) { - $customer->setData('default_shipping', null); - } - $address->delete(); - } else { - $address->setParentId($customer->getId()) - ->setStoreId($customer->getStoreId()) - ->setIsCustomerSaveTransaction(true) - ->save(); - if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) - && $address->getId() != $defaultBillingId) { - $customer->setData('default_billing', $address->getId()); - } - if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) - && $address->getId() != $defaultShippingId) { - $customer->setData('default_shipping', $address->getId()); - } - } - } - if ($customer->dataHasChangedFor('default_billing')) { - $this->saveAttribute($customer, 'default_billing'); - } - if ($customer->dataHasChangedFor('default_shipping')) { - $this->saveAttribute($customer, 'default_shipping'); - } - return $this; - } - - /** - * Retrieve select object for loading base entity row - * - * @param Varien_Object $object - * @param mixed $rowId - * @return Zend_Db_Select - */ - protected function _getLoadRowSelect($object, $rowId) - { - $select = parent::_getLoadRowSelect($object, $rowId); - if ($object->getWebsiteId() && $object->getSharingConfig()->isWebsiteScope()) { - $select->where('website_id=?', (int) $object->getWebsiteId()); - } - return $select; - } - - /** - * Load customer by email - * - * @param Mage_Customer_Model_Customer $customer - * @param string $email - * @param bool $testOnly - * @return Mage_Customer_Model_Entity_Customer - * @throws Mage_Core_Exception - */ - public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getEntityTable(), array($this->getEntityIdField())) - //->where('email=?', $email); - ->where('email=:customer_email'); - if ($customer->getSharingConfig()->isWebsiteScope()) { - if (!$customer->hasData('website_id')) { - Mage::throwException(Mage::helper('customer')->__('Customer website ID must be specified when using the website scope.')); - } - $select->where('website_id=?', (int)$customer->getWebsiteId()); - } - - if ($id = $this->_getReadAdapter()->fetchOne($select, array('customer_email' => $email))) { - $this->load($customer, $id); - } - else { - $customer->setData(array()); - } - return $this; - } - - /** - * Change customer password - * - * @param Mage_Customer_Model_Customer - * @param string $newPassword - * @return this - */ - public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword) - { - $customer->setPassword($newPassword); - $this->saveAttribute($customer, 'password_hash'); - return $this; - } - - /** - * Check whether there are email duplicates of customers in global scope - * - * @return bool - */ - public function findEmailDuplicates() - { - $lookup = $this->_getReadAdapter()->fetchRow("SELECT email, COUNT(*) AS `qty` - FROM `{$this->getTable('customer/entity')}` - GROUP BY 1 ORDER BY 2 DESC LIMIT 1 - "); - if (empty($lookup)) { - return false; - } - return $lookup['qty'] > 1; - } - - /** - * Check customer by id - * - * @param int $customerId - * @return bool - */ - public function checkCustomerId($customerId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('customer/entity'), 'entity_id') - ->where('entity_id=?', $customerId) - ->limit(1); - if ($this->_getReadAdapter()->fetchOne($select)) { - return true; - } - return false; - } - - /** - * Get customer website id - * - * @param int $customerId - * @return int - */ - public function getWebsiteId($customerId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('customer/entity'), 'website_id') - ->where('entity_id=?', $customerId); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Custom setter of increment ID if its needed - * - * @param Varien_Object $object - * @return Mage_Customer_Model_Entity_Customer - */ - public function setNewIncrementId(Varien_Object $object) - { - if (Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_GENERATE_HUMAN_FRIENDLY_ID)) { - parent::setNewIncrementId($object); - } - return $this; - } } - diff --git a/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php index 224f1fc562..7a1006e236 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Customer/Collection.php @@ -20,86 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers collection * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Customer_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +class Mage_Customer_Model_Entity_Customer_Collection extends Mage_Customer_Model_Resource_Customer_Collection { - protected function _construct() - { - $this->_init('customer/customer'); - } - - public function groupByEmail() - { - $this->getSelect() - ->from(array('email'=>$this->getEntity()->getEntityTable()), - array('email_count'=>new Zend_Db_Expr('COUNT(email.entity_id)')) - ) - ->where('email.entity_id=e.entity_id') - ->group('email.email'); - return $this; - } - - public function addNameToSelect() - { - $fields = array(); - foreach (Mage::getConfig()->getFieldset('customer_account') as $code=>$node) { - if ($node->is('name')) { - //$this->addAttributeToSelect($code); - $fields[$code] = $code; - } - } - - $expr = 'CONCAT(' - .(isset($fields['prefix']) ? 'IF({{prefix}} IS NOT NULL AND {{prefix}} != "", CONCAT(TRIM({{prefix}})," "), ""),' : '') - .'TRIM({{firstname}})'.(isset($fields['middlename']) ? ',IF({{middlename}} IS NOT NULL AND {{middlename}} != "", CONCAT(" ",TRIM({{middlename}})), "")' : '').'," ",TRIM({{lastname}})' - .(isset($fields['suffix']) ? ',IF({{suffix}} IS NOT NULL AND {{suffix}} != "", CONCAT(" ",TRIM({{suffix}})), "")' : '') - .')'; - - $this->addExpressionAttributeToSelect('name', $expr, $fields); - return $this; - } - - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - - $countSelect->columns('COUNT(*)'); - $countSelect->resetJoinLeft(); - - return $countSelect; - } - - /** - * Reset left join - * - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - protected function _getAllIdsSelect($limit=null, $offset=null) - { - $idsSelect = parent::_getAllIdsSelect($limit, $offset); - $idsSelect->resetJoinLeft(); - return $idsSelect; - } - } diff --git a/app/code/core/Mage/Customer/Model/Entity/Form/Attribute.php b/app/code/core/Mage/Customer/Model/Entity/Form/Attribute.php index fb1e8b8465..29cd339ce4 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Form/Attribute.php +++ b/app/code/core/Mage/Customer/Model/Entity/Form/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,28 +32,6 @@ * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Form_Attribute extends Mage_Core_Model_Mysql4_Abstract +class Mage_Customer_Model_Entity_Form_Attribute extends Mage_Customer_Model_Resource_Form_Attribute { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('customer/form_attribute', 'attribute_id'); - } - - /** - * Return form attribute IDs by form code - * - * @param string $formCode - * @return array - */ - public function getFormAttributeIds($formCode) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'attribute_id') - ->where('form_code=?', $formCode); - return $this->_getReadAdapter()->fetchCol($select); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Form/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Form/Attribute/Collection.php index 5ba96dff12..9b83af265a 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Form/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Form/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,194 +32,7 @@ * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Form_Attribute_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Customer_Model_Entity_Form_Attribute_Collection + extends Mage_Customer_Model_Resource_Form_Attribute_Collection { - /** - * Current store instance - * - * @var Mage_Core_Model_Store - */ - protected $_store; - - /** - * Eav Entity Type instance - * - * @var Mage_Eav_Model_Entity_Type - */ - protected $_entityType; - - /** - * Define resource model - * - */ - protected function _construct() - { - $this->_init('eav/attribute', 'customer/form_attribute'); - } - - /** - * Set current store to collection - * - * @param Mage_Core_Model_Store|string|int $store - * @return Mage_Customer_Model_Entity_Form_Attribute_Collection - */ - public function setStore($store) - { - $this->_store = Mage::app()->getStore($store); - return $this; - } - - /** - * Return current store instance - * - * @return Mage_Core_Model_Store - */ - public function getStore() - { - if (is_null($this->_store)) { - $this->_store = Mage::app()->getStore(); - } - return $this->_store; - } - - /** - * Set entity type instance to collection - * - * @param Mage_Eav_Model_Entity_Type|string|int $entityType - * @return Mage_Customer_Model_Entity_Form_Attribute_Collection - */ - public function setEntityType($entityType) - { - $this->_entityType = Mage::getSingleton('eav/config')->getEntityType($entityType); - return $this; - } - - /** - * Return current entity type instance - * - * @return Mage_Eav_Model_Entity_Type - */ - public function getEntityType() - { - if (is_null($this->_entityType)) { - $this->setEntityType('customer'); - } - return $this->_entityType; - } - - /** - * Add Form Code filter to collection - * - * @param string $code - * @return Mage_Customer_Model_Entity_Form_Attribute_Collection - */ - public function addFormCodeFilter($code) - { - return $this->addFieldToFilter('main_table.form_code', $code); - } - - /** - * Set order by attribute sort order - * - * @param string $direction - * @return Mage_Customer_Model_Entity_Form_Attribute_Collection - */ - public function setSortOrder($direction = self::SORT_ORDER_ASC) - { - $this->setOrder('ea.is_user_defined', self::SORT_ORDER_ASC); - return $this->setOrder('ca.sort_order', $direction); - } - - /** - * Add joins to select - * - * @return Mage_Customer_Model_Entity_Form_Attribute_Collection - */ - protected function _beforeLoad() - { - $entityType = $this->getEntityType(); - $this->setItemObjectClass($entityType->getAttributeModel()); - - $eaColumns = array(); - $caColumns = array(); - $saColumns = array(); - - $eaDescribe = $this->getConnection()->describeTable($this->getTable('eav/attribute')); - foreach (array_keys($eaDescribe) as $columnName) { - if ($columnName == 'attribute_id') { - continue; - } - $eaColumns[$columnName] = $columnName; - } - - $this->_select->join( - array('ea' => $this->getTable('eav/attribute')), - 'main_table.attribute_id = ea.attribute_id', - $eaColumns - ); - - // join additional attribute data table - $additionalTable = $entityType->getAdditionalAttributeTable(); - if ($additionalTable) { - $caDescribe = $this->getConnection()->describeTable($this->getTable($additionalTable)); - foreach (array_keys($caDescribe) as $columnName) { - if ($columnName == 'attribute_id') { - continue; - } - $caColumns[$columnName] = $columnName; - } - - $this->_select->join( - array('ca' => $this->getTable($additionalTable)), - 'main_table.attribute_id = ca.attribute_id', - $caColumns - ); - } - - // add scope values - $saDescribe = $this->getConnection()->describeTable($this->getTable('customer/eav_attribute_website')); - foreach (array_keys($saDescribe) as $columnName) { - if ($columnName == 'attribute_id') { - continue; - } else if ($columnName == 'website_id') { - $saColumns['scope_website_id'] = $columnName; - } else { - if (isset($eaColumns[$columnName])) { - $code = sprintf('scope_%s', $columnName); - $saColumns[$code] = new Zend_Db_Expr(sprintf('IFNULL(sa.%s, ea.%s)', - $columnName, $columnName)); - } else if (isset($caColumns[$columnName])) { - $code = sprintf('scope_%s', $columnName); - $saColumns[$code] = new Zend_Db_Expr(sprintf('IFNULL(sa.%s, ca.%s)', - $columnName, $columnName)); - } - } - } - - $store = $this->getStore(); - - $this->_select->joinLeft( - array('sa' => $this->getTable('customer/eav_attribute_website')), - 'main_table.attribute_id = sa.attribute_id AND sa.website_id = :scope_website_id', - $saColumns - ); - $this->addBindParam(':scope_website_id', $store->getWebsiteId()); - - // add store attribute label - if ($store->isAdmin()) { - $this->_select->columns(array('store_label' => 'ea.frontend_label')); - } else { - $this->_select->joinLeft( - array('al' => $this->getTable('eav/attribute_label')), - 'al.attribute_id = main_table.attribute_id AND al.store_id = :label_store_id', - array('store_label' => new Zend_Db_Expr('IFNULL(al.value, ea.frontend_label)')) - ); - $this->addBindParam(':label_store_id', $store->getId()); - } - - // add entity type filter - $this->_select->where('ea.entity_type_id = ?', (int)$entityType->getId()); - - return parent::_beforeLoad(); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Group.php b/app/code/core/Mage/Customer/Model/Entity/Group.php index ea93564507..8fa0835c18 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Group.php +++ b/app/code/core/Mage/Customer/Model/Entity/Group.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer group resource model * + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Group extends Mage_Core_Model_Mysql4_Abstract +class Mage_Customer_Model_Entity_Group extends Mage_Customer_Model_Resource_Group { - protected function _construct() - { - $this->_init('customer/customer_group', 'customer_group_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'customer_group_code', - 'title' => Mage::helper('customer')->__('Customer Group') - )); - return $this; - } - - protected function _beforeDelete(Mage_Core_Model_Abstract $group) - { - if ($group->usesAsDefault()) { - Mage::throwException(Mage::helper('customer')->__('The group "%s" cannot be deleted.', $group->getCode())); - } - return parent::_beforeDelete($group); - } - - protected function _afterDelete(Mage_Core_Model_Abstract $group) - { - $customerCollection = Mage::getResourceModel('customer/customer_collection') - ->addAttributeToFilter('group_id', $group->getId()) - ->load(); - foreach ($customerCollection as $customer) { - $defaultGroupId = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $customer->getStoreId()); - $customer->setGroupId($defaultGroupId); - $customer->save(); - } - return parent::_afterDelete($group); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Group/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Group/Collection.php index 66c707c704..a4a631ee0a 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Group/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Group/Collection.php @@ -20,59 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer group collection * + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Group_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Customer_Model_Entity_Group_Collection extends Mage_Customer_Model_Resource_Group_Collection { - protected function _construct() - { - $this->_init('customer/group'); - } - - public function setTaxGroupFilter($classId) - { - $taxClassGroupTable = Mage::getSingleton('core/resource')->getTableName('tax/tax_class_group'); - $this->_select->joinLeft($taxClassGroupTable, "{$taxClassGroupTable}.class_group_id=main_table.customer_group_id"); - $this->_select->where("{$taxClassGroupTable}.class_parent_id = ?", $classId); - return $this; - } - - public function setIgnoreIdFilter($indexes) - { - if( !count($indexes) > 0 ) { - return $this; - } - $this->_select->where('main_table.customer_group_id NOT IN(?)', $indexes); - return $this; - } - - public function setRealGroupsFilter() - { - $this->addFieldToFilter('customer_group_id', array('gt'=>0)); - return $this; - } - - public function addTaxClass() - { - $taxClassTable = Mage::getSingleton('core/resource')->getTableName('tax/tax_class'); - $this->_select->joinLeft($taxClassTable, "main_table.tax_class_id = {$taxClassTable}.class_id"); - - return $this; - } - - public function toOptionArray() - { - return parent::_toOptionArray('customer_group_id', 'customer_group_code'); - } - public function toOptionHash() - { - return parent::_toOptionHash('customer_group_id', 'customer_group_code'); - } } diff --git a/app/code/core/Mage/Customer/Model/Entity/Setup.php b/app/code/core/Mage/Customer/Model/Entity/Setup.php index 5c7defee63..780848e082 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Setup.php +++ b/app/code/core/Mage/Customer/Model/Entity/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,246 +28,10 @@ /** * Customer resource setup model * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer + * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup +class Mage_Customer_Model_Entity_Setup extends Mage_Customer_Model_Resource_Setup { - - /** - * Prepare customer attribute values to save - * - * @param array $attr - * @return array - */ - protected function _prepareValues($attr) - { - $data = parent::_prepareValues($attr); - $data = array_merge($data, array( - 'is_visible' => $this->_getValue($attr, 'visible', 1), - 'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0), - 'input_filter' => $this->_getValue($attr, 'input_filter', ''), - 'lines_to_divide_multiline' => $this->_getValue($attr, 'lines_to_divide', 0), - 'min_text_length' => $this->_getValue($attr, 'min_text_length', 0), - 'max_text_length' => $this->_getValue($attr, 'max_text_length', 0) - )); - return $data; - } - - public function getDefaultEntities() - { - return array( - 'customer' => array( - 'entity_model' =>'customer/customer', - 'table' => 'customer/entity', - 'increment_model' => 'eav/entity_increment_numeric', - 'increment_per_store' => false, - 'additional_attribute_table' => 'customer/eav_attribute', - 'entity_attribute_collection' => 'customer/attribute_collection', - 'attributes' => array( -// 'entity_id' => array('type'=>'static'), -// 'entity_type_id' => array('type'=>'static'), -// 'attribute_set_id' => array('type'=>'static'), -// 'increment_id' => array('type'=>'static'), -// 'created_at' => array('type'=>'static'), -// 'updated_at' => array('type'=>'static'), -// 'is_active' => array('type'=>'static'), - - 'website_id' => array( - 'type' => 'static', - 'label' => 'Associate to Website', - 'input' => 'select', - 'source' => 'customer/customer_attribute_source_website', - 'backend' => 'customer/customer_attribute_backend_website', - 'sort_order' => 10, - ), - 'store_id' => array( - 'type' => 'static', - 'label' => 'Create In', - 'input' => 'select', - 'source' => 'customer/customer_attribute_source_store', - 'backend' => 'customer/customer_attribute_backend_store', - 'visible' => false, - 'sort_order' => 20, - ), - 'created_in' => array( - 'type' => 'varchar', - 'label' => 'Created From', - 'sort_order' => 30, - ), - 'prefix' => array( - 'label' => 'Prefix', - 'required' => false, - 'sort_order' => 37, - ), - 'firstname' => array( - 'label' => 'First Name', - 'sort_order' => 40, - ), - 'middlename' => array( - 'label' => 'Middle Name/Initial', - 'required' => false, - 'sort_order' => 43, - ), - 'lastname' => array( - 'label' => 'Last Name', - 'sort_order' => 50, - ), - 'suffix' => array( - 'label' => 'Suffix', - 'required' => false, - 'sort_order' => 53, - ), - 'email' => array( - 'type' => 'static', - 'label' => 'Email', - 'class' => 'validate-email', - 'sort_order' => 60, - ), - 'group_id' => array( - 'type' => 'static', - 'input' => 'select', - 'label' => 'Group', - 'source' => 'customer/customer_attribute_source_group', - 'sort_order' => 70, - ), - 'dob' => array( - 'type' => 'datetime', - 'input' => 'date', - 'backend' => 'eav/entity_attribute_backend_datetime', - 'required' => false, - 'label' => 'Date Of Birth', - 'sort_order' => 80, - ), - 'password_hash' => array( - 'input' => 'hidden', - 'backend' => 'customer/customer_attribute_backend_password', - 'required' => false, - ), - 'default_billing' => array( - 'type' => 'int', - 'visible' => false, - 'required' => false, - 'backend' => 'customer/customer_attribute_backend_billing', - ), - 'default_shipping' => array( - 'type' => 'int', - 'visible' => false, - 'required' => false, - 'backend' => 'customer/customer_attribute_backend_shipping', - ), - 'taxvat' => array( - 'label' => 'Tax/VAT Number', - 'visible' => true, - 'required' => false, - ), - 'confirmation' => array( - 'label' => 'Is Confirmed', - 'visible' => false, - 'required' => false, - ), - 'created_at' => array( - 'type' => 'static', - 'label' => 'Created At', - 'visible' => false, - 'required' => false, - 'input' => 'date', - ), - ), - ), - - 'customer_address'=>array( - 'entity_model' =>'customer/customer_address', - 'table' => 'customer/address_entity', - 'additional_attribute_table' => 'customer/eav_attribute', - 'entity_attribute_collection' => 'customer/address_attribute_collection', - 'attributes' => array( -// 'entity_id' => array('type'=>'static'), -// 'entity_type_id' => array('type'=>'static'), -// 'attribute_set_id' => array('type'=>'static'), -// 'increment_id' => array('type'=>'static'), -// 'parent_id' => array('type'=>'static'), -// 'created_at' => array('type'=>'static'), -// 'updated_at' => array('type'=>'static'), -// 'is_active' => array('type'=>'static'), - - 'prefix' => array( - 'label' => 'Prefix', - 'required' => false, - 'sort_order' => 7, - ), - 'firstname' => array( - 'label' => 'First Name', - 'sort_order' => 10, - ), - 'middlename' => array( - 'label' => 'Middle Name/Initial', - 'required' => false, - 'sort_order' => 13, - ), - 'lastname' => array( - 'label' => 'Last Name', - 'sort_order' => 20, - ), - 'suffix' => array( - 'label' => 'Suffix', - 'required' => false, - 'sort_order' => 23, - ), - 'company' => array( - 'label' => 'Company', - 'required' => false, - 'sort_order' => 30, - ), - 'street' => array( - 'type' => 'text', - 'backend' => 'customer_entity/address_attribute_backend_street', - 'input' => 'multiline', - 'label' => 'Street Address', - 'sort_order' => 40, - ), - 'city' => array( - 'label' => 'City', - 'sort_order' => 50, - ), - 'country_id' => array( - 'type' => 'varchar', - 'input' => 'select', - 'label' => 'Country', - 'class' => 'countries', - 'source' => 'customer_entity/address_attribute_source_country', - 'sort_order' => 60, - ), - 'region' => array( - 'backend' => 'customer_entity/address_attribute_backend_region', - 'label' => 'State/Province', - 'class' => 'regions', - 'sort_order' => 70, - ), - 'region_id' => array( - 'type' => 'int', - 'input' => 'hidden', - 'source' => 'customer_entity/address_attribute_source_region', - 'required' => 'false', - 'sort_order' => 80, - 'label' => 'State/Province' - ), - 'postcode' => array( - 'label' => 'Zip/Postal Code', - 'sort_order' => 90, - ), - 'telephone' => array( - 'label' => 'Telephone', - 'sort_order' => 100, - ), - 'fax' => array( - 'label' => 'Fax', - 'required' => false, - 'sort_order' => 110, - ), - ), - ), - ); - } - } diff --git a/app/code/core/Mage/Customer/Model/Entity/Wishlist/Collection.php b/app/code/core/Mage/Customer/Model/Entity/Wishlist/Collection.php index 3fd71ddc9c..47f9b9c815 100644 --- a/app/code/core/Mage/Customer/Model/Entity/Wishlist/Collection.php +++ b/app/code/core/Mage/Customer/Model/Entity/Wishlist/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers collection * - * @category Mage - * @package Mage_Customer + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ -class Mage_Customer_Model_Entity_Wishlist_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +class Mage_Customer_Model_Entity_Wishlist_Collection extends Mage_Customer_Model_Resource_Wishlist_Collection { - protected function _construct() - { - $this->setEntity(Mage::getResourceSingleton('customer/wishlist')); - } } diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index 7bbe0fcc26..4f5f20dda5 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Group.php b/app/code/core/Mage/Customer/Model/Group.php index eb88871f35..b8e33b0263 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -20,13 +20,21 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer group model * + * @method Mage_Customer_Model_Resource_Group _getResource() + * @method Mage_Customer_Model_Resource_Group getResource() + * @method string getCustomerGroupCode() + * @method Mage_Customer_Model_Group setCustomerGroupCode(string $value) + * @method Mage_Customer_Model_Group setTaxClassId(int $value) + * + * @category Mage + * @package Mage_Customer * @author Magento Core Team */ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract @@ -84,7 +92,7 @@ public function getCode() return $this->getCustomerGroupCode(); } - public function getTaxClassId($groupId=null) + public function getTaxClassId($groupId = null) { if (!is_null($groupId)) { if (empty(self::$_taxClassIds[$groupId])) { diff --git a/app/code/core/Mage/Customer/Model/Group/Api.php b/app/code/core/Mage/Customer/Model/Group/Api.php index eef004446a..9dfd0e646f 100644 --- a/app/code/core/Mage/Customer/Model/Group/Api.php +++ b/app/code/core/Mage/Customer/Model/Group/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -50,4 +50,4 @@ public function items() return $result; } -} // Class Mage_Customer_Model_Group_Api End +} diff --git a/app/code/core/Mage/Customer/Model/Group/Api/V2.php b/app/code/core/Mage/Customer/Model/Group/Api/V2.php index 267ea9f5c4..7aec13a972 100644 --- a/app/code/core/Mage/Customer/Model/Group/Api/V2.php +++ b/app/code/core/Mage/Customer/Model/Group/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Observer.php b/app/code/core/Mage/Customer/Model/Observer.php index 2f0932e6cb..65cadcab54 100644 --- a/app/code/core/Mage/Customer/Model/Observer.php +++ b/app/code/core/Mage/Customer/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/Model/Resource/Address.php b/app/code/core/Mage/Customer/Model/Resource/Address.php new file mode 100755 index 0000000000..ed3414f668 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address.php @@ -0,0 +1,99 @@ + + */ +class Mage_Customer_Model_Resource_Address extends Mage_Eav_Model_Entity_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $resource = Mage::getSingleton('core/resource'); + $this->setType('customer_address')->setConnection( + $resource->getConnection('customer_read'), + $resource->getConnection('customer_write') + ); + } + + /** + * Set default shipping to address + * + * @param Varien_Object $address + * @return Mage_Customer_Model_Resource_Address + */ + protected function _afterSave(Varien_Object $address) + { + if ($address->getIsCustomerSaveTransaction()) { + return $this; + } + if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) { + $customer = Mage::getModel('customer/customer') + ->load($address->getCustomerId()); + + if ($address->getIsDefaultBilling()) { + $customer->setDefaultBilling($address->getId()); + } + if ($address->getIsDefaultShipping()) { + $customer->setDefaultShipping($address->getId()); + } + $customer->save(); + } + return $this; + } + + /** + * Return customer id + * @deprecated + * + * @param Mage_Customer_Model_Address $object + * @return int + */ + public function getCustomerId($object) + { + return $object->getData('customer_id') ? $object->getData('customer_id') : $object->getParentId(); + } + + /** + * Set customer id + * @deprecated + * + * @param Mage_Customer_Model_Address $object + * @param int $id + * @return Mage_Customer_Model_Address + */ + public function setCustomerId($object, $id) + { + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Region.php b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Region.php new file mode 100755 index 0000000000..a8bdebd0cb --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Region.php @@ -0,0 +1,56 @@ + + */ +class Mage_Customer_Model_Resource_Address_Attribute_Backend_Region + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Prepare object for save + * + * @param Varien_Object $object + * @return Mage_Customer_Model_Resource_Address_Attribute_Backend_Region + */ + public function beforeSave($object) + { + $region = $object->getData('region'); + if (is_numeric($region)) { + $regionModel = Mage::getModel('directory/region')->load($region); + if ($regionModel->getId() && $object->getCountryId() == $regionModel->getCountryId()) { + $object->setRegionId($regionModel->getId()) + ->setRegion($regionModel->getName()); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Street.php b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Street.php new file mode 100755 index 0000000000..7ba4dab0e7 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Backend/Street.php @@ -0,0 +1,52 @@ + + */ +class Mage_Customer_Model_Resource_Address_Attribute_Backend_Street + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Prepare object for save + * + * @param Varien_Object $object + * @return Mage_Customer_Model_Resource_Address_Attribute_Backend_Street + */ + public function beforeSave($object) + { + $street = $object->getStreet(-1); + if ($street) { + $object->implodeStreetAddress(); + } + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Collection.php new file mode 100755 index 0000000000..006de12587 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Collection.php @@ -0,0 +1,44 @@ + + */ +class Mage_Customer_Model_Resource_Address_Attribute_Collection + extends Mage_Customer_Model_Resource_Attribute_Collection +{ + /** + * Default attribute entity type code + * + * @var string + */ + protected $_entityTypeCode = 'customer_address'; +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Country.php b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Country.php new file mode 100755 index 0000000000..b5467f4757 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Country.php @@ -0,0 +1,49 @@ + + */ +class Mage_Customer_Model_Resource_Address_Attribute_Source_Country extends Mage_Eav_Model_Entity_Attribute_Source_Table +{ + /** + * Retreive all options + * + * @return array + */ + public function getAllOptions() + { + if (!$this->_options) { + $this->_options = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray(); + } + return $this->_options; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Region.php b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Region.php new file mode 100755 index 0000000000..8b113ff7a3 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Attribute/Source/Region.php @@ -0,0 +1,49 @@ + + */ +class Mage_Customer_Model_Resource_Address_Attribute_Source_Region extends Mage_Eav_Model_Entity_Attribute_Source_Table +{ + /** + * Retreive all region options + * + * @return array + */ + public function getAllOptions() + { + if (!$this->_options) { + $this->_options = Mage::getResourceModel('directory/region_collection')->load()->toOptionArray(); + } + return $this->_options; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Address/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Address/Collection.php new file mode 100755 index 0000000000..cd908f1678 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Address/Collection.php @@ -0,0 +1,60 @@ + + */ +class Mage_Customer_Model_Resource_Address_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('customer/address'); + } + + /** + * Set customer filter + * + * @param Mage_Customer_Model_Customer $customer + * @return Mage_Customer_Model_Resource_Address_Collection + */ + public function setCustomerFilter($customer) + { + if ($customer->getId()) { + $this->addAttributeToFilter('parent_id', $customer->getId()); + } else { + $this->addAttributeToFilter('parent_id', '-1'); + } + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Attribute.php b/app/code/core/Mage/Customer/Model/Resource/Attribute.php new file mode 100755 index 0000000000..f07ae3f9ec --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Attribute.php @@ -0,0 +1,190 @@ + + */ +class Mage_Customer_Model_Resource_Attribute extends Mage_Eav_Model_Resource_Entity_Attribute +{ + /** + * Perform actions before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Customer_Model_Resource_Attribute + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $validateRules = $object->getData('validate_rules'); + if (is_array($validateRules)) { + $object->setData('validate_rules', serialize($validateRules)); + } + return parent::_beforeSave($object); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $websiteId = (int)$object->getWebsite()->getId(); + if ($websiteId) { + $adapter = $this->_getReadAdapter(); + $columns = array(); + $scopeTable = $this->getTable('customer/eav_attribute_website'); + $describe = $adapter->describeTable($scopeTable); + unset($describe['attribute_id']); + foreach (array_keys($describe) as $columnName) { + $columns['scope_' . $columnName] = $columnName; + } + $conditionSql = $adapter->quoteInto( + $this->getMainTable() . '.attribute_id = scope_table.attribute_id AND scope_table.website_id =?', + $websiteId); + $select->joinLeft( + array('scope_table' => $scopeTable), + $conditionSql, + $columns + ); + } + + return $select; + } + + /** + * Save attribute/form relations after attribute save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Customer_Model_Resource_Attribute + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $forms = $object->getData('used_in_forms'); + $adapter = $this->_getWriteAdapter(); + if (is_array($forms)) { + $where = array('attribute_id=?' => $object->getId()); + $adapter->delete($this->getTable('customer/form_attribute'), $where); + + $data = array(); + foreach ($forms as $formCode) { + $data[] = array( + 'form_code' => $formCode, + 'attribute_id' => (int)$object->getId() + ); + } + + if ($data) { + $adapter->insertMultiple($this->getTable('customer/form_attribute'), $data); + } + } + + // update sort order + if (!$object->isObjectNew() && $object->dataHasChangedFor('sort_order')) { + $data = array('sort_order' => $object->getSortOrder()); + $where = array('attribute_id=?' => (int)$object->getId()); + $adapter->update($this->getTable('eav/entity_attribute'), $data, $where); + } + + // save scope attributes + $websiteId = (int)$object->getWebsite()->getId(); + if ($websiteId) { + $table = $this->getTable('customer/eav_attribute_website'); + $describe = $this->_getReadAdapter()->describeTable($table); + $data = array(); + if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) { + $data = $this->getScopeValues($object); + } + + $data['attribute_id'] = (int)$object->getId(); + $data['website_id'] = (int)$websiteId; + unset($describe['attribute_id']); + unset($describe['website_id']); + + $updateColumns = array(); + foreach (array_keys($describe) as $columnName) { + $data[$columnName] = $object->getData('scope_' . $columnName); + $updateColumns[] = $columnName; + } + + $adapter->insertOnDuplicate($table, $data, $updateColumns); + } + + return parent::_afterSave($object); + } + + /** + * Return scope values for attribute and website + * + * @param Mage_Customer_Model_Attribute $object + * @return array + */ + public function getScopeValues(Mage_Customer_Model_Attribute $object) + { + $adapter = $this->_getReadAdapter(); + $bind = array( + 'attribute_id' => (int)$object->getId(), + 'website_id' => (int)$object->getWebsite()->getId() + ); + $select = $adapter->select() + ->from($this->getTable('customer/eav_attribute_website')) + ->where('attribute_id = :attribute_id') + ->where('website_id = :website_id') + ->limit(1); + $result = $adapter->fetchRow($select, $bind); + + if (!$result) { + $result = array(); + } + + return $result; + } + + /** + * Return forms in which the attribute + * + * @param Mage_Core_Model_Abstract $object + * @return array + */ + public function getUsedInForms(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getReadAdapter(); + $bind = array('attribute_id' => (int)$object->getId()); + $select = $adapter->select() + ->from($this->getTable('customer/form_attribute'), 'form_code') + ->where('attribute_id = :attribute_id'); + + return $adapter->fetchCol($select, $bind); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Attribute/Collection.php new file mode 100755 index 0000000000..d95ce32ba3 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Attribute/Collection.php @@ -0,0 +1,232 @@ + + */ +class Mage_Customer_Model_Resource_Attribute_Collection extends Mage_Eav_Model_Resource_Entity_Attribute_Collection +{ + /** + * code of password hash in customer's EAV tables + */ + const EAV_CODE_PASSWORD_HASH = 'password_hash'; + + /** + * Current website scope instance + * + * @var Mage_Core_Model_Website + */ + protected $_website; + + /** + * Attribute Entity Type Filter + * + * @var Mage_Eav_Model_Entity_Type + */ + protected $_entityType; + + /** + * Default attribute entity type code + * + * @var string + */ + protected $_entityTypeCode = 'customer'; + + /** + * Return customer entity type instance + * + * @return Mage_Eav_Model_Entity_Type + */ + public function getEntityType() + { + if ($this->_entityType === null) { + $this->_entityType = Mage::getSingleton('eav/config')->getEntityType($this->_entityTypeCode); + } + return $this->_entityType; + } + + /** + * Set Website scope + * + * @param Mage_Core_Model_Website|int $website + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + public function setWebsite($website) + { + $this->_website = Mage::app()->getWebsite($website); + $this->addBindParam('scope_website_id', $this->_website->getId()); + return $this; + } + + /** + * Return current website scope instance + * + * @return Mage_Core_Model_Website + */ + public function getWebsite() + { + if ($this->_website === null) { + $this->_website = Mage::app()->getStore()->getWebsite(); + } + return $this->_website; + } + + /** + * Initialize collection select + * + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + protected function _initSelect() + { + $select = $this->getSelect(); + $connection = $this->getConnection(); + $entityType = $this->getEntityType(); + $extraTable = $entityType->getAdditionalAttributeTable(); + $mainDescribe = $this->getConnection()->describeTable($this->getResource()->getMainTable()); + $mainColumns = array(); + + foreach (array_keys($mainDescribe) as $columnName) { + $mainColumns[$columnName] = $columnName; + } + + $select->from(array('main_table' => $this->getResource()->getMainTable()), $mainColumns); + + // additional attribute data table + $extraDescribe = $connection->describeTable($this->getTable($extraTable)); + $extraColumns = array(); + foreach (array_keys($extraDescribe) as $columnName) { + if (isset($mainColumns[$columnName])) { + continue; + } + $extraColumns[$columnName] = $columnName; + } + + $this->addBindParam('mt_entity_type_id', (int)$entityType->getId()); + $select + ->join( + array('additional_table' => $this->getTable($extraTable)), + 'additional_table.attribute_id = main_table.attribute_id', + $extraColumns) + ->where('main_table.entity_type_id = :mt_entity_type_id'); + + // scope values + + $scopeDescribe = $connection->describeTable($this->getTable('customer/eav_attribute_website')); + unset($scopeDescribe['attribute_id']); + $scopeColumns = array(); + foreach (array_keys($scopeDescribe) as $columnName) { + if ($columnName == 'website_id') { + $scopeColumns['scope_website_id'] = $columnName; + } else { + if (isset($mainColumns[$columnName])) { + $alias = sprintf('scope_%s', $columnName); + $expression = $connection->getCheckSql('main_table.%s IS NULL', + 'scope_table.%s', 'main_table.%s'); + $expression = sprintf($expression, $columnName, $columnName, $columnName); + $this->addFilterToMap($columnName, $expression); + $scopeColumns[$alias] = $columnName; + } elseif (isset($extraColumns[$columnName])) { + $alias = sprintf('scope_%s', $columnName); + $expression = $connection->getCheckSql('additional_table.%s IS NULL', + 'scope_table.%s', 'additional_table.%s'); + $expression = sprintf($expression, $columnName, $columnName, $columnName); + $this->addFilterToMap($columnName, $expression); + $scopeColumns[$alias] = $columnName; + } + } + } + + $select->joinLeft( + array('scope_table' => $this->getTable('customer/eav_attribute_website')), + 'scope_table.attribute_id = main_table.attribute_id AND scope_table.website_id = :scope_website_id', + $scopeColumns + ); + $this->addBindParam('scope_website_id', (int)$this->getWebsite()->getId()); + + return $this; + } + + /** + * Specify attribute entity type filter + * Entity type is defined + * + * @param mixed $type + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + public function setEntityTypeFilter($type) + { + return $this; + } + + /** + * Specify filter by "is_visible" field + * + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + public function addVisibleFilter() + { + return $this->addFieldToFilter('is_visible', 1); + } + + /** + * Exclude system hidden attributes + * + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + public function addSystemHiddenFilter() + { + $field = '(CASE WHEN additional_table.is_system = 1 AND additional_table.is_visible = 0 THEN 1 ELSE 0 END)'; + return $this->addFieldToFilter($field, 0); + } + + /** + * Exclude system hidden attributes but include password hash + * + * @return Mage_Customer_Model_Entity_Attribute_Collection + */ + public function addSystemHiddenFilterWithPasswordHash() + { + $field = '(CASE WHEN additional_table.is_system = 1 AND additional_table.is_visible = 0 + AND main_table.attribute_code != "' . self::EAV_CODE_PASSWORD_HASH . '" THEN 1 ELSE 0 END)'; + $this->addFieldToFilter($field, 0); + return $this; + } + + /** + * Add exclude hidden frontend input attribute filter to collection + * + * @return Mage_Customer_Model_Resource_Attribute_Collection + */ + public function addExcludeHiddenFrontendFilter() + { + return $this->addFieldToFilter('main_table.frontend_input', array('neq' => 'hidden')); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Customer.php b/app/code/core/Mage/Customer/Model/Resource/Customer.php new file mode 100755 index 0000000000..4f7d4e6c49 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Customer.php @@ -0,0 +1,315 @@ + + */ +class Mage_Customer_Model_Resource_Customer extends Mage_Eav_Model_Entity_Abstract +{ + /** + * Resource initialization + */ + public function __construct() + { + $this->setType('customer'); + $this->setConnection('customer_read', 'customer_write'); + } + + /** + * Retrieve customer entity default attributes + * + * @return array + */ + protected function _getDefaultAttributes() + { + return array( + 'entity_type_id', + 'attribute_set_id', + 'created_at', + 'updated_at', + 'increment_id', + 'store_id', + 'website_id' + ); + } + + /** + * Check customer scope, email and confirmation key before saving + * + * @param Mage_Customer_Model_Customer $customer + * @throws Mage_Customer_Exception + * @return Mage_Customer_Model_Resource_Customer + */ + protected function _beforeSave(Varien_Object $customer) + { + parent::_beforeSave($customer); + + if (!$customer->getEmail()) { + throw Mage::exception('Mage_Customer', Mage::helper('customer')->__('Customer email is required')); + } + + $adapter = $this->_getWriteAdapter(); + $bind = array('email' => $customer->getEmail()); + + $select = $adapter->select() + ->from($this->getEntityTable(), array($this->getEntityIdField())) + ->where('email = :email'); + if ($customer->getSharingConfig()->isWebsiteScope()) { + $bind['website_id'] = (int)$customer->getWebsiteId(); + $select->where('website_id = :website_id'); + } + if ($customer->getId()) { + $bind['entity_id'] = (int)$customer->getId(); + $select->where('entity_id != :entity_id'); + } + + $result = $adapter->fetchOne($select, $bind); + if ($result) { + throw Mage::exception( + 'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'), + Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS + ); + } + + // set confirmation key logic + if ($customer->getForceConfirmed()) { + $customer->setConfirmation(null); + } elseif (!$customer->getId() && $customer->isConfirmationRequired()) { + $customer->setConfirmation($customer->getRandomConfirmationKey()); + } + // remove customer confirmation key from database, if empty + if (!$customer->getConfirmation()) { + $customer->setConfirmation(null); + } + + return $this; + } + + /** + * Save customer addresses and set default addresses in attributes backend + * + * @param Varien_Object $customer + * @return Mage_Eav_Model_Entity_Abstract + */ + protected function _afterSave(Varien_Object $customer) + { + $this->_saveAddresses($customer); + return parent::_afterSave($customer); + } + + /** + * Save/delete customer address + * + * @param Mage_Customer_Model_Customer $customer + * @return Mage_Customer_Model_Resource_Customer + */ + protected function _saveAddresses(Mage_Customer_Model_Customer $customer) + { + $defaultBillingId = $customer->getData('default_billing'); + $defaultShippingId = $customer->getData('default_shipping'); + foreach ($customer->getAddresses() as $address) { + if ($address->getData('_deleted')) { + if ($address->getId() == $defaultBillingId) { + $customer->setData('default_billing', null); + } + if ($address->getId() == $defaultShippingId) { + $customer->setData('default_shipping', null); + } + $address->delete(); + } else { + $address->setParentId($customer->getId()) + ->setStoreId($customer->getStoreId()) + ->setIsCustomerSaveTransaction(true) + ->save(); + if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) + && $address->getId() != $defaultBillingId + ) { + $customer->setData('default_billing', $address->getId()); + } + if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) + && $address->getId() != $defaultShippingId + ) { + $customer->setData('default_shipping', $address->getId()); + } + } + } + if ($customer->dataHasChangedFor('default_billing')) { + $this->saveAttribute($customer, 'default_billing'); + } + if ($customer->dataHasChangedFor('default_shipping')) { + $this->saveAttribute($customer, 'default_shipping'); + } + + return $this; + } + + /** + * Retrieve select object for loading base entity row + * + * @param Varien_Object $object + * @param mixed $rowId + * @return Varien_Db_Select + */ + protected function _getLoadRowSelect($object, $rowId) + { + $select = parent::_getLoadRowSelect($object, $rowId); + if ($object->getWebsiteId() && $object->getSharingConfig()->isWebsiteScope()) { + $select->where('website_id =?', (int)$object->getWebsiteId()); + } + + return $select; + } + + /** + * Load customer by email + * + * @throws Mage_Core_Exception + * + * @param Mage_Customer_Model_Customer $customer + * @param string $email + * @param bool $testOnly + * @return Mage_Customer_Model_Resource_Customer + */ + public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false) + { + $adapter = $this->_getReadAdapter(); + $bind = array('customer_email' => $email); + $select = $adapter->select() + ->from($this->getEntityTable(), array($this->getEntityIdField())) + ->where('email = :customer_email'); + + if ($customer->getSharingConfig()->isWebsiteScope()) { + if (!$customer->hasData('website_id')) { + Mage::throwException( + Mage::helper('customer')->__('Customer website ID must be specified when using the website scope') + ); + } + $bind['website_id'] = (int)$customer->getWebsiteId(); + $select->where('website_id = :website_id'); + } + + $customerId = $adapter->fetchOne($select, $bind); + if ($customerId) { + $this->load($customer, $customerId); + } else { + $customer->setData(array()); + } + + return $this; + } + + /** + * Change customer password + * + * @param Mage_Customer_Model_Customer $customer + * @param string $newPassword + * @return Mage_Customer_Model_Resource_Customer + */ + public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword) + { + $customer->setPassword($newPassword); + $this->saveAttribute($customer, 'password_hash'); + return $this; + } + + /** + * Check whether there are email duplicates of customers in global scope + * + * @return bool + */ + public function findEmailDuplicates() + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('customer/entity'), array('email', 'cnt' => 'COUNT(*)')) + ->group('email') + ->order('cnt DESC') + ->limit(1); + $lookup = $adapter->fetchRow($select); + if (empty($lookup)) { + return false; + } + return $lookup['cnt'] > 1; + } + + /** + * Check customer by id + * + * @param int $customerId + * @return bool + */ + public function checkCustomerId($customerId) + { + $adapter = $this->_getReadAdapter(); + $bind = array('entity_id' => (int)$customerId); + $select = $adapter->select() + ->from($this->getTable('customer/entity'), 'entity_id') + ->where('entity_id = :entity_id') + ->limit(1); + + $result = $adapter->fetchOne($select, $bind); + if ($result) { + return true; + } + return false; + } + + /** + * Get customer website id + * + * @param int $customerId + * @return int + */ + public function getWebsiteId($customerId) + { + $adapter = $this->_getReadAdapter(); + $bind = array('entity_id' => (int)$customerId); + $select = $adapter->select() + ->from($this->getTable('customer/entity'), 'website_id') + ->where('entity_id = :entity_id'); + + return $adapter->fetchOne($select, $bind); + } + + /** + * Custom setter of increment ID if its needed + * + * @param Varien_Object $object + * @return Mage_Customer_Model_Resource_Customer + */ + public function setNewIncrementId(Varien_Object $object) + { + if (Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_GENERATE_HUMAN_FRIENDLY_ID)) { + parent::setNewIncrementId($object); + } + return $this; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Customer/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Customer/Collection.php new file mode 100755 index 0000000000..ae35c9481f --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Customer/Collection.php @@ -0,0 +1,132 @@ + + */ +class Mage_Customer_Model_Resource_Customer_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('customer/customer'); + } + + /** + * Group result by customer email + * + * @return Mage_Customer_Model_Resource_Customer_Collection + */ + public function groupByEmail() + { + $this->getSelect() + ->from( + array('email' => $this->getEntity()->getEntityTable()), + array('email_count' => new Zend_Db_Expr('COUNT(email.entity_id)')) + ) + ->where('email.entity_id = e.entity_id') + ->group('email.email'); + + return $this; + } + + /** + * Add Name to select + * + * @return Mage_Customer_Model_Resource_Customer_Collection + */ + public function addNameToSelect() + { + $fields = array(); + $customerAccount = Mage::getConfig()->getFieldset('customer_account'); + foreach ($customerAccount as $code => $node) { + if ($node->is('name')) { + $fields[$code] = $code; + } + } + + $adapter = $this->getConnection(); + $concatenate = array(); + if (isset($fields['prefix'])) { + $concatenate[] = $adapter->getCheckSql( + '{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', + 'LTRIM(RTRIM({{prefix}}))', + '\'\''); + } + $concatenate[] = 'LTRIM(RTRIM({{firstname}}))'; + if (isset($fields['middlename'])) { + $concatenate[] = $adapter->getCheckSql( + '{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', + 'LTRIM(RTRIM({{middlename}}))', + '\'\''); + } + $concatenate[] = 'LTRIM(RTRIM({{lastname}}))'; + if (isset($fields['suffix'])) { + $concatenate[] = $adapter + ->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', "LTRIM(RTRIM({{suffix}}))", "''"); + } + + $nameExpr = $adapter->getConcatSql($concatenate, ' '); + + $this->addExpressionAttributeToSelect('name', $nameExpr, $fields); + + return $this; + } + + /** + * Get SQL for get record count + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $select = parent::getSelectCountSql(); + $select->resetJoinLeft(); + + return $select; + } + + /** + * Reset left join + * + * @param int $limit + * @param int $offset + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + protected function _getAllIdsSelect($limit = null, $offset = null) + { + $idsSelect = parent::_getAllIdsSelect($limit, $offset); + $idsSelect->resetJoinLeft(); + return $idsSelect; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute.php b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute.php new file mode 100755 index 0000000000..f744e54717 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute.php @@ -0,0 +1,61 @@ + + */ +class Mage_Customer_Model_Resource_Form_Attribute extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('customer/form_attribute', 'attribute_id'); + } + + /** + * Return form attribute IDs by form code + * + * @param string $formCode + * @return array + */ + public function getFormAttributeIds($formCode) + { + $bind = array('form_code' => $formCode); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'attribute_id') + ->where('form_code = :form_code'); + + return $this->_getReadAdapter()->fetchCol($select, $bind); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php new file mode 100755 index 0000000000..dd180ac0a3 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php @@ -0,0 +1,225 @@ + + */ +class Mage_Customer_Model_Resource_Form_Attribute_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Current store instance + * + * @var Mage_Core_Model_Store + */ + protected $_store; + + /** + * Eav Entity Type instance + * + * @var Mage_Eav_Model_Entity_Type + */ + protected $_entityType; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/attribute', 'customer/form_attribute'); + } + + /** + * Set current store to collection + * + * @param Mage_Core_Model_Store|string|int $store + * @return Mage_Customer_Model_Resource_Form_Attribute_Collection + */ + public function setStore($store) + { + $this->_store = Mage::app()->getStore($store); + return $this; + } + + /** + * Return current store instance + * + * @return Mage_Core_Model_Store + */ + public function getStore() + { + if ($this->_store === null) { + $this->_store = Mage::app()->getStore(); + } + return $this->_store; + } + + /** + * Set entity type instance to collection + * + * @param Mage_Eav_Model_Entity_Type|string|int $entityType + * @return Mage_Customer_Model_Resource_Form_Attribute_Collection + */ + public function setEntityType($entityType) + { + $this->_entityType = Mage::getSingleton('eav/config')->getEntityType($entityType); + return $this; + } + + /** + * Return current entity type instance + * + * @return Mage_Eav_Model_Entity_Type + */ + public function getEntityType() + { + if ($this->_entityType === null) { + $this->setEntityType('customer'); + } + return $this->_entityType; + } + + /** + * Add Form Code filter to collection + * + * @param string $code + * @return Mage_Customer_Model_Resource_Form_Attribute_Collection + */ + public function addFormCodeFilter($code) + { + return $this->addFieldToFilter('main_table.form_code', $code); + } + + /** + * Set order by attribute sort order + * + * @param string $direction + * @return Mage_Customer_Model_Resource_Form_Attribute_Collection + */ + public function setSortOrder($direction = self::SORT_ORDER_ASC) + { + $this->setOrder('ea.is_user_defined', self::SORT_ORDER_ASC); + return $this->setOrder('ca.sort_order', $direction); + } + + /** + * Add joins to select + * + * @return Mage_Customer_Model_Resource_Form_Attribute_Collection + */ + protected function _beforeLoad() + { + $select = $this->getSelect(); + $connection = $this->getConnection(); + $entityType = $this->getEntityType(); + $this->setItemObjectClass($entityType->getAttributeModel()); + + $eaColumns = array(); + $caColumns = array(); + $saColumns = array(); + + $eaDescribe = $connection->describeTable($this->getTable('eav/attribute')); + unset($eaDescribe['attribute_id']); + foreach (array_keys($eaDescribe) as $columnName) { + $eaColumns[$columnName] = $columnName; + } + + $select->join( + array('ea' => $this->getTable('eav/attribute')), + 'main_table.attribute_id = ea.attribute_id', + $eaColumns + ); + + // join additional attribute data table + $additionalTable = $entityType->getAdditionalAttributeTable(); + if ($additionalTable) { + $caDescribe = $connection->describeTable($this->getTable($additionalTable)); + unset($caDescribe['attribute_id']); + foreach (array_keys($caDescribe) as $columnName) { + $caColumns[$columnName] = $columnName; + } + + $select->join( + array('ca' => $this->getTable($additionalTable)), + 'main_table.attribute_id = ca.attribute_id', + $caColumns + ); + } + + // add scope values + $saDescribe = $connection->describeTable($this->getTable('customer/eav_attribute_website')); + unset($saDescribe['attribute_id']); + foreach (array_keys($saDescribe) as $columnName) { + if ($columnName == 'website_id') { + $saColumns['scope_website_id'] = $columnName; + } else { + if (isset($eaColumns[$columnName])) { + $code = sprintf('scope_%s', $columnName); + $expression = $connection->getCheckSql('sa.%s IS NULL', 'ea.%s', 'sa.%s'); + $saColumns[$code] = new Zend_Db_Expr(sprintf($expression, + $columnName, $columnName, $columnName)); + } elseif (isset($caColumns[$columnName])) { + $code = sprintf('scope_%s', $columnName); + $expression = $connection->getCheckSql('sa.%s IS NULL', 'ca.%s', 'sa.%s'); + $saColumns[$code] = new Zend_Db_Expr(sprintf($expression, + $columnName, $columnName, $columnName)); + } + } + } + + $store = $this->getStore(); + $joinWebsiteExpression = $connection + ->quoteInto('sa.attribute_id = main_table.attribute_id AND sa.website_id = ?', (int)$store->getWebsiteId()); + $select->joinLeft( + array('sa' => $this->getTable('customer/eav_attribute_website')), + $joinWebsiteExpression, + $saColumns + ); + + // add store attribute label + if ($store->isAdmin()) { + $select->columns(array('store_label' => 'ea.frontend_label')); + } else { + $storeLabelExpr = $connection->getCheckSql('al.value IS NULL', 'ea.frontend_label', 'al.value'); + $joinExpression = $connection + ->quoteInto('al.attribute_id = main_table.attribute_id AND al.store_id = ?', (int)$store->getId()); + $select->joinLeft( + array('al' => $this->getTable('eav/attribute_label')), + $joinExpression, + array('store_label' => $storeLabelExpr) + ); + } + + // add entity type filter + $select->where('ea.entity_type_id = ?', (int)$entityType->getId()); + + return parent::_beforeLoad(); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Group.php b/app/code/core/Mage/Customer/Model/Resource/Group.php new file mode 100755 index 0000000000..1c624157fd --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Group.php @@ -0,0 +1,95 @@ + + */ +class Mage_Customer_Model_Resource_Group extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('customer/customer_group', 'customer_group_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Customer_Model_Resource_Group + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array( + array( + 'field' => 'customer_group_code', + 'title' => Mage::helper('customer')->__('Customer Group') + )); + + return $this; + } + + /** + * Check if group uses as default + * + * @param Mage_Core_Model_Abstract $group + * @throws Mage_Core_Exception + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $group) + { + if ($group->usesAsDefault()) { + Mage::throwException(Mage::helper('customer')->__('The group "%s" cannot be deleted', $group->getCode())); + } + return parent::_beforeDelete($group); + } + + /** + * Method set default group id to the customers collection + * + * @param Mage_Core_Model_Abstract $group + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterDelete(Mage_Core_Model_Abstract $group) + { + $customerCollection = Mage::getResourceModel('customer/customer_collection') + ->addAttributeToFilter('group_id', $group->getId()) + ->load(); + foreach ($customerCollection as $customer) { + $defaultGroupId = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, + $customer->getStoreId()); + $customer->setGroupId($defaultGroupId); + $customer->save(); + } + return parent::_afterDelete($group); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Group/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Group/Collection.php new file mode 100755 index 0000000000..ecbb83a93d --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Group/Collection.php @@ -0,0 +1,117 @@ + + */ +class Mage_Customer_Model_Resource_Group_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('customer/group'); + } + + /** + * Set tax group filter + * + * @param mixed $classId + * @return Mage_Customer_Model_Resource_Group_Collection + */ + public function setTaxGroupFilter($classId) + { + $this->getSelect()->joinLeft( + array('tax_class_group' => $this->getTable('tax/tax_class_group')), + 'tax_class_group.class_group_id = main_table.customer_group_id' + ); + $this->addFieldToFilter('tax_class_group.class_parent_id', $classId); + return $this; + } + + /** + * Set ignore ID filter + * + * @param array $indexes + * @return Mage_Customer_Model_Resource_Group_Collection + */ + public function setIgnoreIdFilter($indexes) + { + if (count($indexes)) { + $this->addFieldToFilter('main_table.customer_group_id', array('nin' => $indexes)); + } + return $this; + } + + /** + * Set real groups filter + * + * @return Mage_Customer_Model_Resource_Group_Collection + */ + public function setRealGroupsFilter() + { + return $this->addFieldToFilter('customer_group_id', array('gt' => 0)); + } + + /** + * Add tax class + * + * @return Mage_Customer_Model_Resource_Group_Collection + */ + public function addTaxClass() + { + $this->getSelect()->joinLeft( + array('tax_class_table' => $this->getTable('tax/tax_class')), + "main_table.tax_class_id = tax_class_table.class_id"); + return $this; + } + + /** + * Retreive option array + * + * @return array + */ + public function toOptionArray() + { + return parent::_toOptionArray('customer_group_id', 'customer_group_code'); + } + + /** + * Retreive option hash + * + * @return array + */ + public function toOptionHash() + { + return parent::_toOptionHash('customer_group_id', 'customer_group_code'); + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Setup.php b/app/code/core/Mage/Customer/Model/Resource/Setup.php new file mode 100755 index 0000000000..71aacd9cb2 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Setup.php @@ -0,0 +1,468 @@ + + */ +class Mage_Customer_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup +{ + /** + * Prepare customer attribute values to save in additional table + * + * @param array $attr + * @return array + */ + protected function _prepareValues($attr) + { + $data = parent::_prepareValues($attr); + $data = array_merge($data, array( + 'is_visible' => $this->_getValue($attr, 'visible', 1), + 'is_system' => $this->_getValue($attr, 'system', 1), + 'input_filter' => $this->_getValue($attr, 'input_filter', null), + 'multiline_count' => $this->_getValue($attr, 'multiline_count', 0), + 'validate_rules' => $this->_getValue($attr, 'validate_rules', null), + 'data_model' => $this->_getValue($attr, 'data', null), + 'sort_order' => $this->_getValue($attr, 'position', 0) + )); + + return $data; + } + + /** + * Add customer attributes to customer forms + * + * @return void + */ + public function installCustomerForms() + { + $customer = (int)$this->getEntityTypeId('customer'); + $customerAddress = (int)$this->getEntityTypeId('customer_address'); + + $attributeIds = array(); + $select = $this->getConnection()->select() + ->from( + array('ea' => $this->getTable('eav/attribute')), + array('entity_type_id', 'attribute_code', 'attribute_id')) + ->where('ea.entity_type_id IN(?)', array($customer, $customerAddress)); + foreach ($this->getConnection()->fetchAll($select) as $row) { + $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id']; + } + + $data = array(); + $entities = $this->getDefaultEntities(); + $attributes = $entities['customer']['attributes']; + foreach ($attributes as $attributeCode => $attribute) { + $attributeId = $attributeIds[$customer][$attributeCode]; + $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true; + $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true; + if ($attribute['system'] != true || $attribute['visible'] != false) { + $usedInForms = array( + 'customer_account_create', + 'customer_account_edit', + 'checkout_register', + ); + if (!empty($attribute['adminhtml_only'])) { + $usedInForms = array('adminhtml_customer'); + } else { + $usedInForms[] = 'adminhtml_customer'; + } + if (!empty($attribute['admin_checkout'])) { + $usedInForms[] = 'adminhtml_checkout'; + } + foreach ($usedInForms as $formCode) { + $data[] = array( + 'form_code' => $formCode, + 'attribute_id' => $attributeId + ); + } + } + } + + $attributes = $entities['customer_address']['attributes']; + foreach ($attributes as $attributeCode => $attribute) { + $attributeId = $attributeIds[$customerAddress][$attributeCode]; + $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true; + $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true; + if (false === ($attribute['system'] == true && $attribute['visible'] == false)) { + $usedInForms = array( + 'adminhtml_customer_address', + 'customer_address_edit', + 'customer_register_address' + ); + foreach ($usedInForms as $formCode) { + $data[] = array( + 'form_code' => $formCode, + 'attribute_id' => $attributeId + ); + } + } + } + + if ($data) { + $this->getConnection()->insertMultiple($this->getTable('customer/form_attribute'), $data); + } + } + + /** + * Retreive default entities: customer, customer_address + * + * @return array + */ + public function getDefaultEntities() + { + $entities = array( + 'customer' => array( + 'entity_model' => 'customer/customer', + 'attribute_model' => 'customer/attribute', + 'table' => 'customer/entity', + 'increment_model' => 'eav/entity_increment_numeric', + 'additional_attribute_table' => 'customer/eav_attribute', + 'entity_attribute_collection' => 'customer/attribute_collection', + 'attributes' => array( + 'website_id' => array( + 'type' => 'static', + 'label' => 'Associate to Website', + 'input' => 'select', + 'source' => 'customer/customer_attribute_source_website', + 'backend' => 'customer/customer_attribute_backend_website', + 'sort_order' => 10, + 'position' => 10, + 'adminhtml_only' => 1, + ), + 'store_id' => array( + 'type' => 'static', + 'label' => 'Create In', + 'input' => 'select', + 'source' => 'customer/customer_attribute_source_store', + 'backend' => 'customer/customer_attribute_backend_store', + 'sort_order' => 20, + 'visible' => false, + 'adminhtml_only' => 1, + ), + 'created_in' => array( + 'type' => 'varchar', + 'label' => 'Created From', + 'input' => 'text', + 'required' => false, + 'sort_order' => 20, + 'position' => 20, + 'adminhtml_only' => 1, + ), + 'prefix' => array( + 'type' => 'varchar', + 'label' => 'Prefix', + 'input' => 'text', + 'required' => false, + 'sort_order' => 30, + 'visible' => false, + 'system' => false, + 'position' => 30, + ), + 'firstname' => array( + 'type' => 'varchar', + 'label' => 'First Name', + 'input' => 'text', + 'sort_order' => 40, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 40, + ), + 'middlename' => array( + 'type' => 'varchar', + 'label' => 'Middle Name/Initial', + 'input' => 'text', + 'required' => false, + 'sort_order' => 50, + 'visible' => false, + 'system' => false, + 'position' => 50, + ), + 'lastname' => array( + 'type' => 'varchar', + 'label' => 'Last Name', + 'input' => 'text', + 'sort_order' => 60, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 60, + ), + 'suffix' => array( + 'type' => 'varchar', + 'label' => 'Suffix', + 'input' => 'text', + 'required' => false, + 'sort_order' => 70, + 'visible' => false, + 'system' => false, + 'position' => 70, + ), + 'email' => array( + 'type' => 'static', + 'label' => 'Email', + 'input' => 'text', + 'sort_order' => 80, + 'validate_rules' => 'a:1:{s:16:"input_validation";s:5:"email";}', + 'position' => 80, + 'admin_checkout' => 1 + ), + 'group_id' => array( + 'type' => 'static', + 'label' => 'Group', + 'input' => 'select', + 'source' => 'customer/customer_attribute_source_group', + 'sort_order' => 25, + 'position' => 25, + 'adminhtml_only' => 1, + 'admin_checkout' => 1, + ), + 'dob' => array( + 'type' => 'datetime', + 'label' => 'Date Of Birth', + 'input' => 'date', + 'frontend' => 'eav/entity_attribute_frontend_datetime', + 'backend' => 'eav/entity_attribute_backend_datetime', + 'required' => false, + 'sort_order' => 90, + 'visible' => false, + 'system' => false, + 'input_filter' => 'date', + 'validate_rules' => 'a:1:{s:16:"input_validation";s:4:"date";}', + 'position' => 90, + 'admin_checkout' => 1, + ), + 'password_hash' => array( + 'type' => 'varchar', + 'input' => 'hidden', + 'backend' => 'customer/customer_attribute_backend_password', + 'required' => false, + 'sort_order' => 81, + 'visible' => false, + ), + 'default_billing' => array( + 'type' => 'int', + 'label' => 'Default Billing Address', + 'input' => 'text', + 'backend' => 'customer/customer_attribute_backend_billing', + 'required' => false, + 'sort_order' => 82, + 'visible' => false, + ), + 'default_shipping' => array( + 'type' => 'int', + 'label' => 'Default Shipping Address', + 'input' => 'text', + 'backend' => 'customer/customer_attribute_backend_shipping', + 'required' => false, + 'sort_order' => 83, + 'visible' => false, + ), + 'taxvat' => array( + 'type' => 'varchar', + 'label' => 'Tax/VAT Number', + 'input' => 'text', + 'required' => false, + 'sort_order' => 100, + 'visible' => false, + 'system' => false, + 'validate_rules' => 'a:1:{s:15:"max_text_length";i:255;}', + 'position' => 100, + 'admin_checkout' => 1, + ), + 'confirmation' => array( + 'type' => 'varchar', + 'label' => 'Is Confirmed', + 'input' => 'text', + 'required' => false, + 'sort_order' => 85, + 'visible' => false, + ), + 'created_at' => array( + 'type' => 'static', + 'label' => 'Created At', + 'input' => 'date', + 'required' => false, + 'sort_order' => 86, + 'visible' => false, + 'system' => false, + ), + 'gender' => array( + 'type' => 'int', + 'label' => 'Gender', + 'input' => 'select', + 'source' => 'eav/entity_attribute_source_table', + 'required' => false, + 'sort_order' => 110, + 'visible' => false, + 'system' => false, + 'validate_rules' => 'a:0:{}', + 'position' => 110, + 'admin_checkout' => 1, + 'option' => array('values' => array('Male', 'Female')) + ), + ) + ), + + 'customer_address' => array( + 'entity_model' => 'customer/address', + 'attribute_model' => 'customer/attribute', + 'table' => 'customer/address_entity', + 'additional_attribute_table' => 'customer/eav_attribute', + 'entity_attribute_collection' => 'customer/address_attribute_collection', + 'attributes' => array( + 'prefix' => array( + 'type' => 'varchar', + 'label' => 'Prefix', + 'input' => 'text', + 'required' => false, + 'sort_order' => 10, + 'visible' => false, + 'system' => false, + 'position' => 10, + ), + 'firstname' => array( + 'type' => 'varchar', + 'label' => 'First Name', + 'input' => 'text', + 'sort_order' => 20, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 20, + ), + 'middlename' => array( + 'type' => 'varchar', + 'label' => 'Middle Name/Initial', + 'input' => 'text', + 'required' => false, + 'sort_order' => 30, + 'visible' => false, + 'system' => false, + 'position' => 30, + ), + 'lastname' => array( + 'type' => 'varchar', + 'label' => 'Last Name', + 'input' => 'text', + 'sort_order' => 40, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 40, + ), + 'suffix' => array( + 'type' => 'varchar', + 'label' => 'Suffix', + 'input' => 'text', + 'required' => false, + 'sort_order' => 50, + 'visible' => false, + 'system' => false, + 'position' => 50, + ), + 'company' => array( + 'type' => 'varchar', + 'label' => 'Company', + 'input' => 'text', + 'required' => false, + 'sort_order' => 60, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 60, + ), + 'street' => array( + 'type' => 'text', + 'label' => 'Street Address', + 'input' => 'multiline', + 'backend' => 'customer/entity_address_attribute_backend_street', + 'sort_order' => 70, + 'multiline_count' => 2, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 70, + ), + 'city' => array( + 'type' => 'varchar', + 'label' => 'City', + 'input' => 'text', + 'sort_order' => 80, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 80, + ), + 'country_id' => array( + 'type' => 'varchar', + 'label' => 'Country', + 'input' => 'select', + 'source' => 'customer/entity_address_attribute_source_country', + 'sort_order' => 90, + 'position' => 90, + ), + 'region' => array( + 'type' => 'varchar', + 'label' => 'State/Province', + 'input' => 'text', + 'backend' => 'customer/entity_address_attribute_backend_region', + 'required' => false, + 'sort_order' => 100, + 'position' => 100, + ), + 'region_id' => array( + 'type' => 'int', + 'label' => 'State/Province', + 'input' => 'hidden', + 'source' => 'customer/entity_address_attribute_source_region', + 'required' => false, + 'sort_order' => 100, + 'position' => 100, + ), + 'postcode' => array( + 'type' => 'varchar', + 'label' => 'Zip/Postal Code', + 'input' => 'text', + 'sort_order' => 110, + 'validate_rules' => 'a:0:{}', + 'data' => 'customer/attribute_data_postcode', + 'position' => 110, + ), + 'telephone' => array( + 'type' => 'varchar', + 'label' => 'Telephone', + 'input' => 'text', + 'sort_order' => 120, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 120, + ), + 'fax' => array( + 'type' => 'varchar', + 'label' => 'Fax', + 'input' => 'text', + 'required' => false, + 'sort_order' => 130, + 'validate_rules' => 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}', + 'position' => 130, + ), + ) + ) + ); + return $entities; + } +} diff --git a/app/code/core/Mage/Customer/Model/Resource/Wishlist/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Wishlist/Collection.php new file mode 100755 index 0000000000..e9d39351c1 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Resource/Wishlist/Collection.php @@ -0,0 +1,44 @@ + + */ +class Mage_Customer_Model_Resource_Wishlist_Collection extends Mage_Eav_Model_Entity_Collection_Abstract +{ + /** + * Set entity + */ + protected function _construct() + { + $this->setEntity(Mage::getResourceSingleton('customer/wishlist')); + } +} diff --git a/app/code/core/Mage/Customer/Model/Session.php b/app/code/core/Mage/Customer/Model/Session.php index d71c7a3762..acf7de9a7c 100644 --- a/app/code/core/Mage/Customer/Model/Session.php +++ b/app/code/core/Mage/Customer/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index e48fc411ae..976241b529 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/controllers/AddressController.php b/app/code/core/Mage/Customer/controllers/AddressController.php index c416601f22..a410ff8fc2 100644 --- a/app/code/core/Mage/Customer/controllers/AddressController.php +++ b/app/code/core/Mage/Customer/controllers/AddressController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/controllers/ReviewController.php b/app/code/core/Mage/Customer/controllers/ReviewController.php index 0f288e1034..5f3880bd9b 100644 --- a/app/code/core/Mage/Customer/controllers/ReviewController.php +++ b/app/code/core/Mage/Customer/controllers/ReviewController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Customer/etc/adminhtml.xml b/app/code/core/Mage/Customer/etc/adminhtml.xml index c2c0327e1f..bbd0bcc866 100644 --- a/app/code/core/Mage/Customer/etc/adminhtml.xml +++ b/app/code/core/Mage/Customer/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Customer/etc/api.xml b/app/code/core/Mage/Customer/etc/api.xml index 649de6497a..2cef5bf12d 100644 --- a/app/code/core/Mage/Customer/etc/api.xml +++ b/app/code/core/Mage/Customer/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index fd80b7d8c8..e77ad8ec6b 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -21,77 +21,215 @@ * * @category Mage * @package Mage_Customer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.0.14 + 1.6.0.0 - - 1 - 1 - 11 - 11 - 1 - 1 - 11 - 1 - 1 - 1 - 1 - 11 - 1 - 11 - 1 - 1 - 1 - - 111 - 1111 - 111 - 1111 - 111 - 11 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 11 - 11 - 1111 - 1111 - 11 - 11 - 11 + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + 1 + + + 1 + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + 1 + 1 + + + 1 + 1 + 1 + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + - - 111 - 111 - 111 - 111 - 111 - 11 - 1 - 1 - 11 - 11 - 11 + + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + 1 + + + 1 + 1 + + + 1 + + + 1 + + + 1 + 1 + + + 1 + 1 + + + 1 + 1 + @@ -117,15 +255,18 @@ - Mage_Customer_Block + + Mage_Customer_Block + Mage_Customer_Model - customer_entity + customer_resource - - Mage_Customer_Model_Entity + + Mage_Customer_Model_Resource + customer_mysql4 customer_entity
    @@ -149,17 +290,16 @@ customer_form_attribute
    -
    +
    Mage_Customer - Mage_Customer_Model_Entity_Setup + Mage_Customer_Model_Resource_Setup -
    - @@ -116,7 +118,6 @@ - @@ -128,14 +129,12 @@ - AZN,AZM,AFN,ALL,DZD,AOA,ARS,AMD,AWG,AUD,BSD,BHD,BDT,BBD,BYR,BZD,BMD,BTN,BOB,BAM,BWP,BRL,GBP,BND,BGN,BUK,BIF,KHR,CAD,CVE,CZK,KYD,CLP,CNY,COP,KMF,CDF,CRC,HRK,CUP,DKK,DJF,DOP,XCD,EGP,SVC,GQE,ERN,EEK,ETB,EUR,FKP,FJD,GMD,GEK,GEL,GHS,GIP,GTQ,GNF,GYD,HTG,HNL,HKD,HUF,ISK,INR,IDR,IRR,IQD,ILS,JMD,JPY,JOD,KZT,KES,KWD,KGS,LAK,LVL,LBP,LSL,LRD,LYD,LTL,MOP,MKD,MGA,MWK,MYR,MVR,LSM,MRO,MUR,MXN,MDL,MNT,MAD,MZN,MMK,NAD,NPR,ANG,TRL,TRY,NZD,NIC,NGN,KPW,NOK,OMR,PKR,PAB,PGK,PYG,PEN,PHP,PLN,QAR,RHD,RON,ROL,RUB,RWF,SHP,STD,SAR,RSD,SCR,SLL,SGD,SKK,SBD,SOS,ZAR,KRW,LKR,SDG,SRD,SZL,SEK,CHF,SYP,TWD,TJS,TZS,THB,TOP,TTD,TND,TMM,USD,UGX,UAH,AED,UYU,UZS,VUV,VEB,VEF,VND,CHE,CHW,XOF,XPF,WST,YER,ZMK,ZWD - USD,EUR @@ -147,18 +146,16 @@ 0 - + general currency_import_error_email_template - AF,AL,DZ,AS,AD,AO,AI,AQ,AG,AR,AM,AW,AU,AT,AX,AZ,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BL,BT,BO,BA,BW,BV,BR,IO,VG,BN,BG,BF,BI,KH,CM,CA,CD,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,CG,CK,CR,HR,CU,CY,CZ,DK,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,GF,PF,TF,GA,GM,GE,DE,GG,GH,GI,GR,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,HN,HK,HU,IS,IM,IN,ID,IR,IQ,IE,IL,IT,CI,JE,JM,JP,JO,KZ,KE,KI,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,ME,MF,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,FX,MX,FM,MD,MC,MN,MS,MA,MZ,MM,NA,NR,NP,NL,AN,NC,NZ,NI,NE,NG,NU,NF,KP,MP,NO,OM,PK,PW,PA,PG,PY,PE,PH,PN,PL,PS,PT,PR,QA,RE,RO,RS,RU,RW,SH,KN,LC,PM,VC,WS,SM,ST,SA,SN,SC,SL,SG,SK,SI,SB,SO,ZA,GS,KR,ES,LK,SD,SR,SJ,SZ,SE,CH,SY,TL,TW,TJ,TZ,TH,TG,TK,TO,TT,TN,TR,TM,TC,TV,VI,UG,UA,AE,GB,US,UM,UY,UZ,VU,VA,VE,VN,WF,EH,YE,ZM,ZW US - %A, %B %e %Y [%I:%M %p] %a, %b %e %Y [%I:%M %p] diff --git a/app/code/core/Mage/Directory/etc/system.xml b/app/code/core/Mage/Directory/etc/system.xml index dbc7d41529..34d00a173f 100644 --- a/app/code/core/Mage/Directory/etc/system.xml +++ b/app/code/core/Mage/Directory/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Directory/sql/directory_setup/install-1.6.0.0.php b/app/code/core/Mage/Directory/sql/directory_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..8c0730a9c6 --- /dev/null +++ b/app/code/core/Mage/Directory/sql/directory_setup/install-1.6.0.0.php @@ -0,0 +1,158 @@ +startSetup(); + +/** + * Create table 'directory/country' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('directory/country')) + ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + 'primary' => true, + 'default' => '', + ), 'Country Id in ISO-2') + ->addColumn('iso2_code', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + 'default' => '', + ), 'Country ISO-2 format') + ->addColumn('iso3_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + 'nullable' => false, + 'default' => '', + ), 'Country ISO-3') + ->setComment('Directory Country'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'directory/country_format' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('directory/country_format')) + ->addColumn('country_format_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Country Format Id') + ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + 'default' => '', + ), 'Country Id in ISO-2') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 30, array( + 'nullable' => false, + 'default' => '', + ), 'Country Format Type') + ->addColumn('format', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Country Format') + ->addIndex($installer->getIdxName('directory/country_format', array('country_id', 'type'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('country_id', 'type'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Directory Country Format'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'directory/country_region' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('directory/country_region')) + ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Region Id') + ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 4, array( + 'nullable' => false, + 'default' => '0', + ), 'Country Id in ISO-2') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'default' => '', + ), 'Region code') + ->addColumn('default_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Region Name') + ->addIndex($installer->getIdxName('directory/country_region', array('country_id')), + array('country_id')) + ->setComment('Directory Country Region'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'directory/country_region_name' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('directory/country_region_name')) + ->addColumn('locale', Varien_Db_Ddl_Table::TYPE_TEXT, 8, array( + 'nullable' => false, + 'primary' => true, + 'default' => '', + ), 'Locale') + ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Region Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Region Name') + ->addIndex($installer->getIdxName('directory/country_region_name', array('region_id')), + array('region_id')) + ->addForeignKey($installer->getFkName('directory/country_region_name', 'region_id', 'directory/country_region', 'region_id'), + 'region_id', $installer->getTable('directory/country_region'), 'region_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Directory Country Region Name'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'directory/currency_rate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('directory/currency_rate')) + ->addColumn('currency_from', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + 'nullable' => false, + 'primary' => true, + 'default' => '', + ), 'Currency Code Convert From') + ->addColumn('currency_to', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + 'nullable' => false, + 'primary' => true, + 'default' => '', + ), 'Currency Code Convert To') + ->addColumn('rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '24,12', array( + 'nullable' => false, + 'default' => '0.000000000000', + ), 'Currency Conversion Rate') + ->addIndex($installer->getIdxName('directory/currency_rate', array('currency_to')), + array('currency_to')) + ->setComment('Directory Currency Rate'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.7.0.php index 045ecaf3cb..10553e4c26 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.8.0.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.8.0.php index f3f799084d..629058f1c9 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.8.0.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-install-0.8.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.0-0.7.1.php index d910b8ce9c..a229cc5d10 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.1-0.7.2.php index 620915519e..939364c067 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.0-0.8.1.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.0-0.8.1.php index 0a17f1d886..73f2297412 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.0-0.8.1.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.0-0.8.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.1-0.8.2.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.1-0.8.2.php index bb22cf4bb8..b4bfdd69a0 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.1-0.8.2.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.1-0.8.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.10-0.8.11.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.10-0.8.11.php index c281a6af60..0197dbcc32 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.10-0.8.11.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.10-0.8.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.2-0.8.3.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.2-0.8.3.php index 5581605e7a..ecde70556b 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.2-0.8.3.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.2-0.8.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.3-0.8.4.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.3-0.8.4.php index 9336461239..ab8381a84a 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.3-0.8.4.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.3-0.8.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.4-0.8.5.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.4-0.8.5.php index b2b14d4cc1..f88aded50e 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.4-0.8.5.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.4-0.8.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.5-0.8.6.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.5-0.8.6.php index 0fe67ecb0e..bb2631eb09 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.5-0.8.6.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.5-0.8.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.6-0.8.7.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.6-0.8.7.php index bd1f2bc1dd..a5c6e84fd1 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.6-0.8.7.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.6-0.8.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.7-0.8.8.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.7-0.8.8.php index e20b21381d..cd2f5565dd 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.7-0.8.8.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.7-0.8.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.8-0.8.9.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.8-0.8.9.php index 8c9fa0f98e..a32acd036a 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.8-0.8.9.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.8-0.8.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.9-0.8.10.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.9-0.8.10.php index 755bb3a197..3becb5c3ae 100644 --- a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.9-0.8.10.php +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-0.8.9-0.8.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Directory - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..305ef1ae4c --- /dev/null +++ b/app/code/core/Mage/Directory/sql/directory_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,256 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('directory/country_region_name'), + 'FK_DIRECTORY_REGION_NAME_REGION' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('directory/country_format'), + 'COUNTRY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('directory/country_region'), + 'FK_REGION_COUNTRY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('directory/country_region_name'), + 'FK_DIRECTORY_REGION_NAME_REGION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('directory/currency_rate'), + 'FK_CURRENCY_RATE_TO' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('directory/country') => array( + 'columns' => array( + 'country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Country Id in ISO-2' + ), + 'iso2_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'comment' => 'Country ISO-2 format' + ), + 'iso3_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'nullable' => false, + 'comment' => 'Country ISO-3' + ) + ), + 'comment' => 'Directory Country' + ), + $installer->getTable('directory/country_format') => array( + 'columns' => array( + 'country_format_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Country Format Id' + ), + 'country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'comment' => 'Country Id in ISO-2' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 30, + 'nullable' => false, + 'comment' => 'Country Format Type' + ), + 'format' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Country Format' + ) + ), + 'comment' => 'Directory Country Format' + ), + $installer->getTable('directory/country_region') => array( + 'columns' => array( + 'region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Region Id' + ), + 'country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 4, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Country Id in ISO-2' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Region code' + ), + 'default_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Region Name' + ) + ), + 'comment' => 'Directory Country Region' + ), + $installer->getTable('directory/country_region_name') => array( + 'columns' => array( + 'locale' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 8, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Locale' + ), + 'region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Region Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Region Name' + ) + ), + 'comment' => 'Directory Country Region Name' + ), + $installer->getTable('directory/currency_rate') => array( + 'columns' => array( + 'currency_from' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Currency Code Convert From' + ), + 'currency_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Currency Code Convert To' + ), + 'rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 12, + 'precision' => 24, + 'nullable' => false, + 'default' => '0.000000000000', + 'comment' => 'Currency Conversion Rate' + ) + ), + 'comment' => 'Directory Currency Rate' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('directory/country_format'), + $installer->getIdxName( + 'directory/country_format', + array('country_id', 'type'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('country_id', 'type'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('directory/country_region'), + $installer->getIdxName('directory/country_region', array('country_id')), + array('country_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('directory/country_region_name'), + $installer->getIdxName('directory/country_region_name', array('region_id')), + array('region_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('directory/currency_rate'), + $installer->getIdxName('directory/currency_rate', array('currency_to')), + array('currency_to') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('directory/country_region_name', 'region_id', 'directory/country_region', 'region_id'), + $installer->getTable('directory/country_region_name'), + 'region_id', + $installer->getTable('directory/country_region'), + 'region_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php index cca3268e7b..c3e17e6ba6 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php index af4459219a..3bbb844138 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php index 84cc80343f..4c98ec1c36 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -71,7 +71,7 @@ public function getPurchasedSeparatelyAttribute() $_attributeCode = 'links_purchased_separately'; $this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute') - ->loadByCode('catalog_product', $_attributeCode); + ->loadByCode(Mage_Catalog_Model_Product::ENTITY, $_attributeCode); } return $this->_purchasedSeparatelyAttribute; diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php index 74073b4c3f..5c50d21979 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Adminhtml/Sales/Items/Column/Downloadable/Name.php b/app/code/core/Mage/Downloadable/Block/Adminhtml/Sales/Items/Column/Downloadable/Name.php index 1bb9f5aa50..c5b975116b 100644 --- a/app/code/core/Mage/Downloadable/Block/Adminhtml/Sales/Items/Column/Downloadable/Name.php +++ b/app/code/core/Mage/Downloadable/Block/Adminhtml/Sales/Items/Column/Downloadable/Name.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Catalog/Product/Links.php b/app/code/core/Mage/Downloadable/Block/Catalog/Product/Links.php index 4ed592576e..1f6d9b1cc4 100644 --- a/app/code/core/Mage/Downloadable/Block/Catalog/Product/Links.php +++ b/app/code/core/Mage/Downloadable/Block/Catalog/Product/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Catalog/Product/Samples.php b/app/code/core/Mage/Downloadable/Block/Catalog/Product/Samples.php index 7fc32362a4..8b10805cda 100644 --- a/app/code/core/Mage/Downloadable/Block/Catalog/Product/Samples.php +++ b/app/code/core/Mage/Downloadable/Block/Catalog/Product/Samples.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Catalog/Product/View/Type.php b/app/code/core/Mage/Downloadable/Block/Catalog/Product/View/Type.php index 6ab31b97f0..3573fb01c9 100644 --- a/app/code/core/Mage/Downloadable/Block/Catalog/Product/View/Type.php +++ b/app/code/core/Mage/Downloadable/Block/Catalog/Product/View/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Checkout/Cart/Item/Renderer.php b/app/code/core/Mage/Downloadable/Block/Checkout/Cart/Item/Renderer.php index 5cde4a385f..bb99f505c9 100644 --- a/app/code/core/Mage/Downloadable/Block/Checkout/Cart/Item/Renderer.php +++ b/app/code/core/Mage/Downloadable/Block/Checkout/Cart/Item/Renderer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Checkout/Success.php b/app/code/core/Mage/Downloadable/Block/Checkout/Success.php index 86c609662c..6cd6a543cb 100644 --- a/app/code/core/Mage/Downloadable/Block/Checkout/Success.php +++ b/app/code/core/Mage/Downloadable/Block/Checkout/Success.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php b/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php index 69cacabec2..d42f9b1285 100644 --- a/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php +++ b/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -49,6 +49,9 @@ public function __construct() foreach ($purchased as $_item) { $purchasedIds[] = $_item->getId(); } + if (empty($purchasedIds)) { + $purchasedIds = array(null); + } $purchasedItems = Mage::getResourceModel('downloadable/link_purchased_item_collection') ->addFieldToFilter('purchased_id', array('in' => $purchasedIds)) ->addFieldToFilter('status', diff --git a/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Downloadable.php index 0ca0b7a60b..3ca4c527b8 100644 --- a/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Order/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Order/Downloadable.php index 496ced9355..801c79fae1 100644 --- a/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Order/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Sales/Order/Email/Items/Order/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Block/Sales/Order/Item/Renderer/Downloadable.php b/app/code/core/Mage/Downloadable/Block/Sales/Order/Item/Renderer/Downloadable.php index c88f253271..c82c9ad734 100644 --- a/app/code/core/Mage/Downloadable/Block/Sales/Order/Item/Renderer/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Block/Sales/Order/Item/Renderer/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Helper/Catalog/Product/Configuration.php b/app/code/core/Mage/Downloadable/Helper/Catalog/Product/Configuration.php index a0c4eaa3d8..069a784e93 100644 --- a/app/code/core/Mage/Downloadable/Helper/Catalog/Product/Configuration.php +++ b/app/code/core/Mage/Downloadable/Helper/Catalog/Product/Configuration.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Helper/Data.php b/app/code/core/Mage/Downloadable/Helper/Data.php index d14c08ceff..39070908d7 100644 --- a/app/code/core/Mage/Downloadable/Helper/Data.php +++ b/app/code/core/Mage/Downloadable/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Helper/Download.php b/app/code/core/Mage/Downloadable/Helper/Download.php index 77c1ecd344..fedfc381bf 100644 --- a/app/code/core/Mage/Downloadable/Helper/Download.php +++ b/app/code/core/Mage/Downloadable/Helper/Download.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Helper/File.php b/app/code/core/Mage/Downloadable/Helper/File.php index 1dbcdd968d..4e09b03533 100644 --- a/app/code/core/Mage/Downloadable/Helper/File.php +++ b/app/code/core/Mage/Downloadable/Helper/File.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/CatalogIndex/Data/Downloadable.php b/app/code/core/Mage/Downloadable/Model/CatalogIndex/Data/Downloadable.php index b46d6665d6..135a5ba542 100644 --- a/app/code/core/Mage/Downloadable/Model/CatalogIndex/Data/Downloadable.php +++ b/app/code/core/Mage/Downloadable/Model/CatalogIndex/Data/Downloadable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Link.php b/app/code/core/Mage/Downloadable/Model/Link.php index 715db82168..c3a4e51657 100644 --- a/app/code/core/Mage/Downloadable/Model/Link.php +++ b/app/code/core/Mage/Downloadable/Model/Link.php @@ -20,13 +20,36 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Downloadable link model * + * @method Mage_Downloadable_Model_Resource_Link _getResource() + * @method Mage_Downloadable_Model_Resource_Link getResource() + * @method int getProductId() + * @method Mage_Downloadable_Model_Link setProductId(int $value) + * @method int getSortOrder() + * @method Mage_Downloadable_Model_Link setSortOrder(int $value) + * @method int getNumberOfDownloads() + * @method Mage_Downloadable_Model_Link setNumberOfDownloads(int $value) + * @method int getIsShareable() + * @method Mage_Downloadable_Model_Link setIsShareable(int $value) + * @method string getLinkUrl() + * @method Mage_Downloadable_Model_Link setLinkUrl(string $value) + * @method string getLinkFile() + * @method Mage_Downloadable_Model_Link setLinkFile(string $value) + * @method string getLinkType() + * @method Mage_Downloadable_Model_Link setLinkType(string $value) + * @method string getSampleUrl() + * @method Mage_Downloadable_Model_Link setSampleUrl(string $value) + * @method string getSampleFile() + * @method Mage_Downloadable_Model_Link setSampleFile(string $value) + * @method string getSampleType() + * @method Mage_Downloadable_Model_Link setSampleType(string $value) + * * @category Mage * @package Mage_Downloadable * @author Magento Core Team diff --git a/app/code/core/Mage/Downloadable/Model/Link/Purchased.php b/app/code/core/Mage/Downloadable/Model/Link/Purchased.php index c37d89d683..b016dd00ef 100644 --- a/app/code/core/Mage/Downloadable/Model/Link/Purchased.php +++ b/app/code/core/Mage/Downloadable/Model/Link/Purchased.php @@ -20,13 +20,34 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Downloadable links purchased model * + * @method Mage_Downloadable_Model_Resource_Link_Purchased _getResource() + * @method Mage_Downloadable_Model_Resource_Link_Purchased getResource() + * @method int getOrderId() + * @method Mage_Downloadable_Model_Link_Purchased setOrderId(int $value) + * @method string getOrderIncrementId() + * @method Mage_Downloadable_Model_Link_Purchased setOrderIncrementId(string $value) + * @method int getOrderItemId() + * @method Mage_Downloadable_Model_Link_Purchased setOrderItemId(int $value) + * @method string getCreatedAt() + * @method Mage_Downloadable_Model_Link_Purchased setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Downloadable_Model_Link_Purchased setUpdatedAt(string $value) + * @method int getCustomerId() + * @method Mage_Downloadable_Model_Link_Purchased setCustomerId(int $value) + * @method string getProductName() + * @method Mage_Downloadable_Model_Link_Purchased setProductName(string $value) + * @method string getProductSku() + * @method Mage_Downloadable_Model_Link_Purchased setProductSku(string $value) + * @method string getLinkSectionTitle() + * @method Mage_Downloadable_Model_Link_Purchased setLinkSectionTitle(string $value) + * * @category Mage * @package Mage_Downloadable * @author Magento Core Team diff --git a/app/code/core/Mage/Downloadable/Model/Link/Purchased/Item.php b/app/code/core/Mage/Downloadable/Model/Link/Purchased/Item.php index 79325273db..48f4aa6c20 100644 --- a/app/code/core/Mage/Downloadable/Model/Link/Purchased/Item.php +++ b/app/code/core/Mage/Downloadable/Model/Link/Purchased/Item.php @@ -20,13 +20,46 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Downloadable links purchased item model * + * @method Mage_Downloadable_Model_Resource_Link_Purchased_Item _getResource() + * @method Mage_Downloadable_Model_Resource_Link_Purchased_Item getResource() + * @method int getPurchasedId() + * @method Mage_Downloadable_Model_Link_Purchased_Item setPurchasedId(int $value) + * @method int getOrderItemId() + * @method Mage_Downloadable_Model_Link_Purchased_Item setOrderItemId(int $value) + * @method int getProductId() + * @method Mage_Downloadable_Model_Link_Purchased_Item setProductId(int $value) + * @method string getLinkHash() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkHash(string $value) + * @method int getNumberOfDownloadsBought() + * @method Mage_Downloadable_Model_Link_Purchased_Item setNumberOfDownloadsBought(int $value) + * @method int getNumberOfDownloadsUsed() + * @method Mage_Downloadable_Model_Link_Purchased_Item setNumberOfDownloadsUsed(int $value) + * @method int getLinkId() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkId(int $value) + * @method string getLinkTitle() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkTitle(string $value) + * @method int getIsShareable() + * @method Mage_Downloadable_Model_Link_Purchased_Item setIsShareable(int $value) + * @method string getLinkUrl() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkUrl(string $value) + * @method string getLinkFile() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkFile(string $value) + * @method string getLinkType() + * @method Mage_Downloadable_Model_Link_Purchased_Item setLinkType(string $value) + * @method string getStatus() + * @method Mage_Downloadable_Model_Link_Purchased_Item setStatus(string $value) + * @method string getCreatedAt() + * @method Mage_Downloadable_Model_Link_Purchased_Item setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Downloadable_Model_Link_Purchased_Item setUpdatedAt(string $value) + * * @category Mage * @package Mage_Downloadable * @author Magento Core Team diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Indexer/Price.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Indexer/Price.php index e472b75519..dd47549f87 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Indexer/Price.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Indexer/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,133 +32,6 @@ * @package Mage_Downloadable * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Indexer_Price - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Default +class Mage_Downloadable_Model_Mysql4_Indexer_Price extends Mage_Downloadable_Model_Resource_Indexer_Price { - /** - * Reindex temporary (price result data) for all products - * - * @return Mage_Downloadable_Model_Mysql4_Indexer_Price - */ - public function reindexAll() - { - $this->useIdxTable(true); - $this->_prepareFinalPriceData(); - $this->_applyCustomOption(); - $this->_applyDownloadableLink(); - $this->_movePriceDataToIndexTable(); - - return $this; - } - - /** - * Reindex temporary (price result data) for defined product(s) - * - * @param int|array $entityIds - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price_Interface - */ - public function reindexEntity($entityIds) - { - $this->_prepareFinalPriceData($entityIds); - $this->_applyCustomOption(); - $this->_applyDownloadableLink(); - $this->_movePriceDataToIndexTable(); - - return $this; - } - - /** - * Retrieve downloadable links price temporary index table name - * - * @see _prepareDefaultFinalPriceTable() - * @return string - */ - protected function _getDownloadableLinkPriceTable() - { - if ($this->useIdxTable()) { - return $this->getTable('downloadable/product_price_indexer_idx'); - } - return $this->getTable('downloadable/product_price_indexer_tmp'); - } - - /** - * Prepare downloadable links price temporary index table - * - * @return Mage_Downloadable_Model_Mysql4_Indexer_Price - */ - protected function _prepareDownloadableLinkPriceTable() - { - $this->_getWriteAdapter()->delete($this->_getDownloadableLinkPriceTable()); - return $this; - } - - /** - * Calculate and apply Downloadable links price to index - * - * @return Mage_Downloadable_Model_Mysql4_Indexer_Price - */ - protected function _applyDownloadableLink() - { - $write = $this->_getWriteAdapter(); - $table = $this->_getDownloadableLinkPriceTable(); - - $this->_prepareDownloadableLinkPriceTable(); - - $dlType = $this->_getAttribute('links_purchased_separately'); - - $select = $write->select() - ->from( - array('i' => $this->_getDefaultFinalPriceTable()), - array('entity_id', 'customer_group_id', 'website_id')) - ->join( - array('dl' => $dlType->getBackend()->getTable()), - "dl.entity_id = i.entity_id AND dl.attribute_id = {$dlType->getAttributeId()}" - . " AND dl.store_id = 0", - array()) - ->join( - array('dll' => $this->getTable('downloadable/link')), - 'dll.product_id = i.entity_id', - array()) - ->join( - array('dlpd' => $this->getTable('downloadable/link_price')), - 'dll.link_id = dlpd.link_id AND dlpd.website_id = 0', - array()) - ->joinLeft( - array('dlpw' => $this->getTable('downloadable/link_price')), - 'dlpd.link_id = dlpw.link_id AND dlpw.website_id = i.website_id', - array()) - ->where('dl.value = ?', 1) - ->group(array('i.entity_id', 'i.customer_group_id', 'i.website_id')) - ->columns(array( - 'min_price' => new Zend_Db_Expr('MIN(IF(dlpw.price_id, dlpw.price, dlpd.price))'), - 'max_price' => new Zend_Db_Expr('SUM(IF(dlpw.price_id, dlpw.price, dlpd.price))') - )); - - $query = $select->insertFromSelect($table); - $write->query($query); - - $select = $write->select() - ->join( - array('id' => $table), - 'i.entity_id = id.entity_id AND i.customer_group_id = id.customer_group_id' - .' AND i.website_id = id.website_id', - array()) - ->columns(array( - 'min_price' => new Zend_Db_Expr('i.min_price + id.min_price'), - 'max_price' => new Zend_Db_Expr('i.max_price + id.max_price'), - 'tier_price' => new Zend_Db_Expr('IF(i.tier_price IS NOT NULL, i.tier_price + id.min_price, NULL)') - )); - - $query = $select->crossUpdateFromSelect(array('i' => $this->_getDefaultFinalPriceTable())); - $write->query($query); - - if ($this->useIdxTable()) { - $write->truncate($table); - } - else { - $write->delete($table); - } - - return $this; - } } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link.php index 3d06da1bf7..5387d864a0 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link.php @@ -20,166 +20,18 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable Product Samples resource model * - * @category Mage - * @package Mage_Downloadable - * @author Magento Core Team + * @category Mage + * @package Mage_Downloadable + * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link extends Mage_Core_Model_Mysql4_Abstract +class Mage_Downloadable_Model_Mysql4_Link extends Mage_Downloadable_Model_Resource_Link { - /** - * Initialize connection and define resource - * - */ - protected function _construct() - { - $this->_init('downloadable/link', 'link_id'); - } - - /** - * Save title and price of link item - * - * @param Mage_Downloadable_Model_Link $linkObject - * @return Mage_Downloadable_Model_Mysql4_link - */ - public function saveItemTitleAndPrice($linkObject) - { - $stmt = $this->_getReadAdapter()->select() - ->from($this->getTable('downloadable/link_title')) - ->where('link_id = ?', $linkObject->getId()) - ->where('store_id = ?', $linkObject->getStoreId()); - if ($this->_getReadAdapter()->fetchOne($stmt)) { - $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . - ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId()); - if ($linkObject->getUseDefaultTitle()) { - $this->_getWriteAdapter()->delete( - $this->getTable('downloadable/link_title'), $where); - } else { - $this->_getWriteAdapter()->update( - $this->getTable('downloadable/link_title'), - array('title' => $linkObject->getTitle()), $where); - } - } else { - if (!$linkObject->getUseDefaultTitle()) { - $this->_getWriteAdapter()->insert( - $this->getTable('downloadable/link_title'), - array( - 'link_id' => $linkObject->getId(), - 'store_id' => $linkObject->getStoreId(), - 'title' => $linkObject->getTitle(), - )); - } - } - $stmt = null; - $stmt = $this->_getReadAdapter()->select() - ->from($this->getTable('downloadable/link_price')) - ->where('link_id = ?', $linkObject->getId()) - ->where('website_id = ?', $linkObject->getWebsiteId()); - if ($this->_getReadAdapter()->fetchOne($stmt)) { - $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) . - ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId()); - if ($linkObject->getUseDefaultPrice()) { - $this->_getReadAdapter()->delete( - $this->getTable('downloadable/link_price'), $where); - } else { - $this->_getWriteAdapter()->update( - $this->getTable('downloadable/link_price'), - array('price' => $linkObject->getPrice()), $where); - } - } else { - if (!$linkObject->getUseDefaultPrice()) { - $dataToInsert[] = array( - 'link_id' => $linkObject->getId(), - 'website_id' => $linkObject->getWebsiteId(), - 'price' => $linkObject->getPrice() - ); - $_isNew = $linkObject->getOrigData('link_id') != $linkObject->getLinkId(); - if ($linkObject->getWebsiteId() == 0 && $_isNew && !Mage::helper('catalog')->isPriceGlobal()) { - $websiteIds = $linkObject->getProductWebsiteIds(); - foreach ($websiteIds as $websiteId) { - $baseCurrency = Mage::app()->getBaseCurrencyCode(); - $websiteCurrency = Mage::app()->getWebsite($websiteId)->getBaseCurrencyCode(); - if ($websiteCurrency == $baseCurrency) { - continue; - } - $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($websiteCurrency); - if (!$rate) { - $rate = 1; - } - $newPrice = $linkObject->getPrice() * $rate; - $dataToInsert[] = array( - 'link_id' => $linkObject->getId(), - 'website_id' => $websiteId, - 'price' => $newPrice - ); - } - } - foreach ($dataToInsert as $_data) { - $this->_getWriteAdapter()->insert($this->getTable('downloadable/link_price'), $_data); - } - } - } - return $this; - } - - /** - * Delete data by item(s) - * - * @param Mage_Downloadable_Model_Link|array|int $items - * @return Mage_Downloadable_Model_Mysql4_Link - */ - public function deleteItems($items) - { - $where = ''; - if ($items instanceof Mage_Downloadable_Model_Link) { - $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $items->getId()); - } - elseif (is_array($items)) { - $where = $this->_getReadAdapter()->quoteInto('link_id in (?)', $items); - } - else { - $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items); - } - if ($where) { - $this->_getWriteAdapter()->delete( - $this->getTable('downloadable/link'), $where); - $this->_getWriteAdapter()->delete( - $this->getTable('downloadable/link_title'), $where); - $this->_getWriteAdapter()->delete( - $this->getTable('downloadable/link_price'), $where); - } - return $this; - } - - /** - * Retrieve links searchable data - * - * @param int $productId - * @param int $storeId - * @return array - */ - public function getSearchableData($productId, $storeId) - { - $select = $this->_getReadAdapter()->select() - ->from(array('link' => $this->getMainTable()), null) - ->join( - array('link_title_default' => $this->getTable('downloadable/link_title')), - 'link_title_default.link_id=link.link_id AND link_title_default.store_id=0', - array()) - ->joinLeft( - array('link_title_store' => $this->getTable('downloadable/link_title')), - 'link_title_store.link_id=link.link_id AND link_title_store.store_id=' . intval($storeId), - array('title' => 'IFNULL(link_title_store.title, link_title_default.title)')) - ->where('link.product_id=?', $productId); - if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) { - $searchData = array(); - } - return $searchData; - } } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Collection.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Collection.php index 2f62807570..d6ea52dec8 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Collection.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable links resource collection * @@ -31,76 +32,6 @@ * @package Mage_Downloadable * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Downloadable_Model_Mysql4_Link_Collection extends Mage_Downloadable_Model_Resource_Link_Collection { - - /** - * Enter description here... - * - */ - protected function _construct() - { - $this->_init('downloadable/link'); - } - - /** - * Enter description here... - * - * @param Mage_Catalog_Model_Product|array|integer|null $product - * @return Mage_Downloadable_Model_Mysql4_Link_Collection - */ - public function addProductToFilter($product) - { - if (empty($product)) { - $this->addFieldToFilter('product_id', ''); - } elseif (is_array($product)) { - $this->addFieldToFilter('product_id', array('in' => $product)); - } elseif ($product instanceof Mage_Catalog_Model_Product) { - $this->addFieldToFilter('product_id', $product->getId()); - } else { - $this->addFieldToFilter('product_id', $product); - } - - return $this; - } - - /** - * Enter description here... - * - * @param integer $storeId - * @return Mage_Downloadable_Model_Mysql4_Link_Collection - */ - public function addTitleToResult($storeId=0) - { - $this->getSelect() - ->joinLeft(array('default_title_table' => $this->getTable('downloadable/link_title')), - '`default_title_table`.link_id=`main_table`.link_id AND `default_title_table`.store_id = 0', - array('default_title'=>'title')) - ->joinLeft(array('store_title_table' => $this->getTable('downloadable/link_title')), - '`store_title_table`.link_id=`main_table`.link_id AND `store_title_table`.store_id = ' . intval($storeId), - array('store_title' => 'title','title' => new Zend_Db_Expr('IFNULL(`store_title_table`.title, `default_title_table`.title)'))) - ->order('main_table.sort_order ASC') - ->order('title ASC'); - - return $this; - } - - /** - * Enter description here... - * - * @param integer $websiteId - * @return Mage_Downloadable_Model_Mysql4_Link_Collection - */ - public function addPriceToResult($websiteId) - { - $this->getSelect() - ->joinLeft(array('default_price_table' => $this->getTable('downloadable/link_price')), - '`default_price_table`.link_id=`main_table`.link_id AND `default_price_table`.website_id = 0', - array('default_price' => 'price')) - ->joinLeft(array('website_price_table' => $this->getTable('downloadable/link_price')), - '`website_price_table`.link_id=`main_table`.link_id AND `website_price_table`.website_id = ' . intval($websiteId), - array('website_price' => 'price','price' => new Zend_Db_Expr('IFNULL(`website_price_table`.price, `default_price_table`.price)'))); - return $this; - } - } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased.php index 33f27f9064..86f5fd8e75 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable Product link purchased resource model * - * @category Mage - * @package Mage_Downloadable - * @author Magento Core Team + * @category Mage + * @package Mage_Downloadable + * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link_Purchased extends Mage_Core_Model_Mysql4_Abstract +class Mage_Downloadable_Model_Mysql4_Link_Purchased extends Mage_Downloadable_Model_Resource_Link_Purchased { - - /** - * Varien class constructor - * - */ - protected function _construct() - { - $this->_init('downloadable/link_purchased', 'purchased_id'); - } - } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Collection.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Collection.php index f5757fbbc2..4e4cc36920 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Collection.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable links purchased resource collection * @@ -31,23 +32,7 @@ * @package Mage_Downloadable * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link_Purchased_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Downloadable_Model_Mysql4_Link_Purchased_Collection + extends Mage_Downloadable_Model_Resource_Link_Purchased_Collection { - - /** - * Enter description here... - * - */ - protected function _construct() - { - $this->_init('downloadable/link_purchased'); - } - - public function addPurchasedItemsToResult() - { - $this->getSelect() - ->join(array('purchased_items'=>$this->getTable('downloadable/link_purchased_item')), - '`purchased_items`.purchased_id=`main_table`.purchased_id'); - return $this; - } } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item.php index e3c1f529a7..6d5c2f6b03 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable Product link purchased items resource model * - * @category Mage - * @package Mage_Downloadable - * @author Magento Core Team + * @category Mage + * @package Mage_Downloadable + * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link_Purchased_Item extends Mage_Core_Model_Mysql4_Abstract +class Mage_Downloadable_Model_Mysql4_Link_Purchased_Item extends Mage_Downloadable_Model_Resource_Link_Purchased_Item { - - /** - * Varien class constructor - * - */ - protected function _construct() - { - $this->_init('downloadable/link_purchased_item', 'item_id'); - } - } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item/Collection.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item/Collection.php index 514478942d..a2dff972c5 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item/Collection.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Link/Purchased/Item/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable links purchased items resource collection * @@ -31,16 +32,7 @@ * @package Mage_Downloadable * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Link_Purchased_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Downloadable_Model_Mysql4_Link_Purchased_Item_Collection + extends Mage_Downloadable_Model_Resource_Link_Purchased_Item_Collection { - - /** - * Enter description here... - * - */ - protected function _construct() - { - $this->_init('downloadable/link_purchased_item'); - } - } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Sample.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Sample.php index f0348f3fe1..1edb0651f6 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Sample.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Sample.php @@ -20,116 +20,18 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable Product Samples resource model * - * @category Mage - * @package Mage_Downloadable - * @author Magento Core Team + * @category Mage + * @package Mage_Downloadable + * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Sample extends Mage_Core_Model_Mysql4_Abstract +class Mage_Downloadable_Model_Mysql4_Sample extends Mage_Downloadable_Model_Resource_Sample { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('downloadable/sample', 'sample_id'); - } - - /** - * Save title of sample item in store scope - * - * @param Mage_Downloadable_Model_Sample $sampleObject - * @return Mage_Downloadable_Model_Mysql4_Sample - */ - public function saveItemTitle($sampleObject) - { - $stmt = $this->_getReadAdapter()->select() - ->from($this->getTable('downloadable/sample_title')) - ->where('sample_id = ?', $sampleObject->getId()) - ->where('store_id = ?', $sampleObject->getStoreId()); - if ($this->_getReadAdapter()->fetchOne($stmt)) { - $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $sampleObject->getId()) . - ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $sampleObject->getStoreId()); - if ($sampleObject->getUseDefaultTitle()) { - $this->_getWriteAdapter()->delete( - $this->getTable('downloadable/sample_title'), $where); - } else { - $this->_getWriteAdapter()->update( - $this->getTable('downloadable/sample_title'), - array('title' => $sampleObject->getTitle()), $where); - } - } else { - if (!$sampleObject->getUseDefaultTitle()) { - $this->_getWriteAdapter()->insert( - $this->getTable('downloadable/sample_title'), - array( - 'sample_id' => $sampleObject->getId(), - 'store_id' => $sampleObject->getStoreId(), - 'title' => $sampleObject->getTitle(), - )); - } - } - return $this; - } - - /** - * Delete data by item(s) - * - * @param Mage_Downloadable_Model_Sample|array|int $items - * @return Mage_Downloadable_Model_Mysql4_Sample - */ - public function deleteItems($items) - { - $adapter = $this->_getWriteAdapter(); - $where = ''; - if ($items instanceof Mage_Downloadable_Model_Sample) { - $where = $adapter->quoteInto('sample_id = ?', $items->getId()); - } - elseif (is_array($items)) { - $where = $adapter->quoteInto('sample_id in (?)', $items); - } - else { - $where = $adapter->quoteInto('sample_id = ?', $items); - } - if ($where) { - $adapter->delete( - $this->getTable('downloadable/sample'),$where); - $adapter->delete( - $this->getTable('downloadable/sample_title'), $where); - } - return $this; - } - - /** - * Retrieve links searchable data - * - * @param int $productId - * @param int $storeId - * @return array - */ - public function getSearchableData($productId, $storeId) - { - $select = $this->_getReadAdapter()->select() - ->from(array('sample' => $this->getMainTable()), null) - ->join( - array('sample_title_default' => $this->getTable('downloadable/sample_title')), - 'sample_title_default.sample_id=sample.sample_id AND sample_title_default.store_id=0', - array()) - ->joinLeft( - array('sample_title_store' => $this->getTable('downloadable/sample_title')), - 'sample_title_store.sample_id=sample.sample_id AND sample_title_store.store_id=' . intval($storeId), - array('title' => 'IFNULL(sample_title_store.title, sample_title_default.title)')) - ->where('sample.product_id=?', $productId); - if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) { - $searchData = array(); - } - return $searchData; - } } diff --git a/app/code/core/Mage/Downloadable/Model/Mysql4/Sample/Collection.php b/app/code/core/Mage/Downloadable/Model/Mysql4/Sample/Collection.php index 07f1fae143..f55cf604e2 100644 --- a/app/code/core/Mage/Downloadable/Model/Mysql4/Sample/Collection.php +++ b/app/code/core/Mage/Downloadable/Model/Mysql4/Sample/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Downloadable samples resource collection * @@ -31,58 +32,6 @@ * @package Mage_Downloadable * @author Magento Core Team */ -class Mage_Downloadable_Model_Mysql4_Sample_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Downloadable_Model_Mysql4_Sample_Collection extends Mage_Downloadable_Model_Resource_Sample_Collection { - - /** - * Enter description here... - * - */ - protected function _construct() - { - $this->_init('downloadable/sample'); - } - - /** - * Enter description here... - * - * @param Mage_Catalog_Model_Product|array|integer|null $product - * @return Mage_Downloadable_Model_Mysql4_Sample_Collection - */ - public function addProductToFilter($product) - { - if (empty($product)) { - $this->addFieldToFilter('product_id', ''); - } elseif (is_array($product)) { - $this->addFieldToFilter('product_id', array('in' => $product)); - } elseif ($product instanceof Mage_Catalog_Model_Product) { - $this->addFieldToFilter('product_id', $product->getId()); - } else { - $this->addFieldToFilter('product_id', $product); - } - - return $this; - } - - /** - * Enter description here... - * - * @param integer $storeId - * @return Mage_Downloadable_Model_Mysql4_Sample_Collection - */ - public function addTitleToResult($storeId=0) - { - $this->getSelect() - ->joinLeft(array('default_title_table' => $this->getTable('downloadable/sample_title')), - '`default_title_table`.sample_id=`main_table`.sample_id AND `default_title_table`.store_id = 0', - array('default_title' => 'title')) - ->joinLeft(array('store_title_table' => $this->getTable('downloadable/sample_title')), - '`store_title_table`.sample_id=`main_table`.sample_id AND `store_title_table`.store_id = ' . intval($storeId), - array('store_title' => 'title','title' => new Zend_Db_Expr('IFNULL(`store_title_table`.title, `default_title_table`.title)'))) - ->order('main_table.sort_order ASC') - ->order('title ASC'); - - return $this; - } - } diff --git a/app/code/core/Mage/Downloadable/Model/Observer.php b/app/code/core/Mage/Downloadable/Model/Observer.php index ec3501cf16..23400d67b4 100644 --- a/app/code/core/Mage/Downloadable/Model/Observer.php +++ b/app/code/core/Mage/Downloadable/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Product/Price.php b/app/code/core/Mage/Downloadable/Model/Product/Price.php index e3f44d5f32..2ae499bece 100644 --- a/app/code/core/Mage/Downloadable/Model/Product/Price.php +++ b/app/code/core/Mage/Downloadable/Model/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Product/Type.php b/app/code/core/Mage/Downloadable/Model/Product/Type.php index b428e614a5..50255203c8 100644 --- a/app/code/core/Mage/Downloadable/Model/Product/Type.php +++ b/app/code/core/Mage/Downloadable/Model/Product/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Indexer/Price.php b/app/code/core/Mage/Downloadable/Model/Resource/Indexer/Price.php new file mode 100755 index 0000000000..25bd48402d --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Indexer/Price.php @@ -0,0 +1,167 @@ + + */ +class Mage_Downloadable_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resource_Product_Indexer_Price_Default +{ + /** + * Reindex temporary (price result data) for all products + * + * @return Mage_Downloadable_Model_Resource_Indexer_Price + */ + public function reindexAll() + { + $this->useIdxTable(true); + $this->_prepareFinalPriceData(); + $this->_applyCustomOption(); + $this->_applyDownloadableLink(); + $this->_movePriceDataToIndexTable(); + + return $this; + } + + /** + * Reindex temporary (price result data) for defined product(s) + * + * @param int|array $entityIds + * @return Mage_Downloadable_Model_Resource_Indexer_Price + */ + public function reindexEntity($entityIds) + { + $this->_prepareFinalPriceData($entityIds); + $this->_applyCustomOption(); + $this->_applyDownloadableLink(); + $this->_movePriceDataToIndexTable(); + + return $this; + } + + /** + * Retrieve downloadable links price temporary index table name + * + * @see _prepareDefaultFinalPriceTable() + * + * @return string + */ + protected function _getDownloadableLinkPriceTable() + { + if ($this->useIdxTable()) { + return $this->getTable('downloadable/product_price_indexer_idx'); + } + return $this->getTable('downloadable/product_price_indexer_tmp'); + } + + /** + * Prepare downloadable links price temporary index table + * + * @return Mage_Downloadable_Model_Resource_Indexer_Price + */ + protected function _prepareDownloadableLinkPriceTable() + { + $this->_getWriteAdapter()->delete($this->_getDownloadableLinkPriceTable()); + return $this; + } + + /** + * Calculate and apply Downloadable links price to index + * + * @return Mage_Downloadable_Model_Resource_Indexer_Price + */ + protected function _applyDownloadableLink() + { + $write = $this->_getWriteAdapter(); + $table = $this->_getDownloadableLinkPriceTable(); + + $this->_prepareDownloadableLinkPriceTable(); + + $dlType = $this->_getAttribute('links_purchased_separately'); + + $ifPrice = $write->getIfNullSql('dlpw.price_id', 'dlpd.price'); + + $select = $write->select() + ->from( + array('i' => $this->_getDefaultFinalPriceTable()), + array('entity_id', 'customer_group_id', 'website_id')) + ->join( + array('dl' => $dlType->getBackend()->getTable()), + "dl.entity_id = i.entity_id AND dl.attribute_id = {$dlType->getAttributeId()}" + . " AND dl.store_id = 0", + array()) + ->join( + array('dll' => $this->getTable('downloadable/link')), + 'dll.product_id = i.entity_id', + array()) + ->join( + array('dlpd' => $this->getTable('downloadable/link_price')), + 'dll.link_id = dlpd.link_id AND dlpd.website_id = 0', + array()) + ->joinLeft( + array('dlpw' => $this->getTable('downloadable/link_price')), + 'dlpd.link_id = dlpw.link_id AND dlpw.website_id = i.website_id', + array()) + ->where('dl.value = ?', 1) + ->group(array('i.entity_id', 'i.customer_group_id', 'i.website_id')) + ->columns(array( + 'min_price' => new Zend_Db_Expr('MIN('.$ifPrice.')'), + 'max_price' => new Zend_Db_Expr('SUM('.$ifPrice.')') + )); + + $query = $select->insertFromSelect($table); + $write->query($query); + + $ifTierPrice = $write->getCheckSql('i.tier_price IS NOT NULL', '(i.tier_price + id.min_price)', 'NULL'); + + $select = $write->select() + ->join( + array('id' => $table), + 'i.entity_id = id.entity_id AND i.customer_group_id = id.customer_group_id' + .' AND i.website_id = id.website_id', + array()) + ->columns(array( + 'min_price' => new Zend_Db_Expr('i.min_price + id.min_price'), + 'max_price' => new Zend_Db_Expr('i.max_price + id.max_price'), + 'tier_price' => new Zend_Db_Expr($ifTierPrice) + )); + + $query = $select->crossUpdateFromSelect(array('i' => $this->_getDefaultFinalPriceTable())); + $write->query($query); + + if ($this->useIdxTable()) { + $write->truncateTable($table); + } else { + $write->delete($table); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Link.php b/app/code/core/Mage/Downloadable/Model/Resource/Link.php new file mode 100755 index 0000000000..6277a626a7 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link.php @@ -0,0 +1,210 @@ + + */ +class Mage_Downloadable_Model_Resource_Link extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define resource + * + */ + protected function _construct() + { + $this->_init('downloadable/link', 'link_id'); + } + + /** + * Save title and price of link item + * + * @param Mage_Downloadable_Model_Link $linkObject + * @return Mage_Downloadable_Model_Resource_Link + */ + public function saveItemTitleAndPrice($linkObject) + { + + $writeAdapter = $this->_getWriteAdapter(); + $linkTitleTable = $this->getTable('downloadable/link_title'); + $linkPriceTable = $this->getTable('downloadable/link_price'); + + $select = $writeAdapter->select() + ->from($this->getTable('downloadable/link_title')) + ->where('link_id=:link_id AND store_id=:store_id'); + $bind = array( + ':link_id' => $linkObject->getId(), + ':store_id' => (int)$linkObject->getStoreId() + ); + + if ($writeAdapter->fetchOne($select, $bind)) { + $where = array( + 'link_id = ?' => $linkObject->getId(), + 'store_id = ?' => (int)$linkObject->getStoreId() + ); + if ($linkObject->getUseDefaultTitle()) { + $writeAdapter->delete( + $linkTitleTable, $where); + } else { + $insertData = array('title' => $linkObject->getTitle()); + $writeAdapter->update( + $linkTitleTable, + $insertData, + $where); + } + } else { + if (!$linkObject->getUseDefaultTitle()) { + $writeAdapter->insert( + $linkTitleTable, + array( + 'link_id' => $linkObject->getId(), + 'store_id' => (int)$linkObject->getStoreId(), + 'title' => $linkObject->getTitle(), + )); + } + } + + $select = $writeAdapter->select() + ->from($linkPriceTable) + ->where('link_id=:link_id AND website_id=:website_id'); + $bind = array( + ':link_id' => $linkObject->getId(), + ':website_id' => (int)$linkObject->getWebsiteId(), + ); + if ($writeAdapter->fetchOne($select, $bind)) { + $where = array( + 'link_id = ?' => $linkObject->getId(), + 'website_id = ?' => $linkObject->getWebsiteId() + ); + if ($linkObject->getUseDefaultPrice()) { + $writeAdapter->delete( + $linkPriceTable, $where); + } else { + $writeAdapter->update( + $linkPriceTable, + array('price' => $linkObject->getPrice()), + $where); + } + } else { + if (!$linkObject->getUseDefaultPrice()) { + $dataToInsert[] = array( + 'link_id' => $linkObject->getId(), + 'website_id' => (int)$linkObject->getWebsiteId(), + 'price' => (float)$linkObject->getPrice() + ); + if ($linkObject->getOrigData('link_id') != $linkObject->getLinkId()) { + $_isNew = true; + } else { + $_isNew = false; + } + if ($linkObject->getWebsiteId() == 0 && $_isNew && !Mage::helper('catalog')->isPriceGlobal()) { + $websiteIds = $linkObject->getProductWebsiteIds(); + foreach ($websiteIds as $websiteId) { + $baseCurrency = Mage::app()->getBaseCurrencyCode(); + $websiteCurrency = Mage::app()->getWebsite($websiteId)->getBaseCurrencyCode(); + if ($websiteCurrency == $baseCurrency) { + continue; + } + $rate = Mage::getModel('directory/currency')->load($baseCurrency)->getRate($websiteCurrency); + if (!$rate) { + $rate = 1; + } + $newPrice = $linkObject->getPrice() * $rate; + $dataToInsert[] = array( + 'link_id' => $linkObject->getId(), + 'website_id' => (int)$websiteId, + 'price' => $newPrice + ); + } + } + $writeAdapter->insertMultiple($linkPriceTable, $dataToInsert); + } + } + return $this; + } + + /** + * Delete data by item(s) + * + * @param Mage_Downloadable_Model_Link|array|int $items + * @return Mage_Downloadable_Model_Resource_Link + */ + public function deleteItems($items) + { + $writeAdapter = $this->_getWriteAdapter(); + $where = array(); + if ($items instanceof Mage_Downloadable_Model_Link) { + $where = array('link_id = ?' => $items->getId()); + } elseif (is_array($items)) { + $where = array('link_id in (?)' => $items); + } else { + $where = array('sample_id = ?' => $items); + } + if ($where) { + $writeAdapter->delete( + $this->getMainTable(), $where); + $writeAdapter->delete( + $this->getTable('downloadable/link_title'), $where); + $writeAdapter->delete( + $this->getTable('downloadable/link_price'), $where); + } + return $this; + } + + /** + * Retrieve links searchable data + * + * @param int $productId + * @param int $storeId + * @return array + */ + public function getSearchableData($productId, $storeId) + { + $adapter = $this->_getReadAdapter(); + $ifNullDefaultTitle = $adapter->getIfNullSql('st.title', 's.title'); + $select = $adapter->select() + ->from(array('m' => $this->getMainTable()), null) + ->join( + array('s' => $this->getTable('downloadable/link_title')), + 's.link_id=m.link_id AND s.store_id=0', + array()) + ->joinLeft( + array('st' => $this->getTable('downloadable/link_title')), + 'st.link_id=m.link_id AND st.store_id=:store_id', + array('title' => $ifNullDefaultTitle)) + ->where('m.product_id=:product_id'); + $bind = array( + ':store_id' => (int)$storeId, + ':product_id' => $productId + ); + + return $adapter->fetchCol($select, $bind); + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Link/Collection.php b/app/code/core/Mage/Downloadable/Model/Resource/Link/Collection.php new file mode 100755 index 0000000000..f2429369b3 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link/Collection.php @@ -0,0 +1,107 @@ + + */ +class Mage_Downloadable_Model_Resource_Link_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init resource model + */ + protected function _construct() + { + $this->_init('downloadable/link'); + } + + /** + * Method for product filter + * + * @param Mage_Catalog_Model_Product|array|integer|null $product + * @return Mage_Downloadable_Model_Resource_Link_Collection + */ + public function addProductToFilter($product) + { + if (empty($product)) { + $this->addFieldToFilter('product_id', ''); + } elseif ($product instanceof Mage_Catalog_Model_Product) { + $this->addFieldToFilter('product_id', $product->getId()); + } else { + $this->addFieldToFilter('product_id', array('in' => $product)); + } + + return $this; + } + + /** + * Retrieve title for for current store + * + * @param integer $storeId + * @return Mage_Downloadable_Model_Resource_Link_Collection + */ + public function addTitleToResult($storeId = 0) + { + $ifNullDefaultTitle = $this->getConnection() + ->getIfNullSql('st.title', 'd.title'); + $this->getSelect() + ->joinLeft(array('d' => $this->getTable('downloadable/link_title')), + 'd.link_id=main_table.link_id AND d.store_id = 0', + array('default_title' => 'title')) + ->joinLeft(array('st' => $this->getTable('downloadable/link_title')), + 'st.link_id=main_table.link_id AND st.store_id = ' . (int)$storeId, + array('store_title' => 'title','title' => $ifNullDefaultTitle)) + ->order('main_table.sort_order ASC') + ->order('title ASC'); + + return $this; + } + + /** + * Retrieve price for for current website + * + * @param integer $websiteId + * @return Mage_Downloadable_Model_Resource_Link_Collection + */ + public function addPriceToResult($websiteId) + { + $ifNullDefaultPrice = $this->getConnection() + ->getIfNullSql('stp.price', 'dp.price'); + $this->getSelect() + ->joinLeft(array('dp' => $this->getTable('downloadable/link_price')), + 'dp.link_id=main_table.link_id AND dp.website_id = 0', + array('default_price' => 'price')) + ->joinLeft(array('stp' => $this->getTable('downloadable/link_price')), + 'stp.link_id=main_table.link_id AND stp.website_id = ' . (int)$websiteId, + array('website_price' => 'price','price' => $ifNullDefaultPrice)); + + return $this; + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased.php b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased.php new file mode 100755 index 0000000000..0e66136cf8 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased.php @@ -0,0 +1,45 @@ + + */ +class Mage_Downloadable_Model_Resource_Link_Purchased extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Varien class constructor + * + */ + protected function _construct() + { + $this->_init('downloadable/link_purchased', 'purchased_id'); + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Collection.php b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Collection.php new file mode 100755 index 0000000000..adff65f5a0 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Collection.php @@ -0,0 +1,58 @@ + + */ +class Mage_Downloadable_Model_Resource_Link_Purchased_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init resource model + * + */ + protected function _construct() + { + $this->_init('downloadable/link_purchased'); + } + + /** + * Add purchased items to collection + * + * @return Mage_Downloadable_Model_Resource_Link_Purchased_Collection + */ + public function addPurchasedItemsToResult() + { + $this->getSelect() + ->join(array('pi'=>$this->getTable('downloadable/link_purchased_item')), + 'pi.purchased_id=main_table.purchased_id'); + return $this; + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item.php b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item.php new file mode 100755 index 0000000000..570fd2cf7e --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item.php @@ -0,0 +1,45 @@ + + */ +class Mage_Downloadable_Model_Resource_Link_Purchased_Item extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Varien class constructor + * + */ + protected function _construct() + { + $this->_init('downloadable/link_purchased_item', 'item_id'); + } +} diff --git a/app/code/core/Mage/Log/Model/Visitor/Aggregator.php b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item/Collection.php old mode 100644 new mode 100755 similarity index 65% rename from app/code/core/Mage/Log/Model/Visitor/Aggregator.php rename to app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item/Collection.php index cfee8122f3..b613597391 --- a/app/code/core/Mage/Log/Model/Visitor/Aggregator.php +++ b/app/code/core/Mage/Downloadable/Model/Resource/Link/Purchased/Item/Collection.php @@ -19,33 +19,28 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Downloadable + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Log visitor aggregator + * Downloadable links purchased items resource collection * + * @category Mage + * @package Mage_Downloadable * @author Magento Core Team */ - -class Mage_Log_Model_Visitor_Aggregator extends Varien_Object +class Mage_Downloadable_Model_Resource_Link_Purchased_Item_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract { - public function getResource() - { - return Mage::getResourceModel('log/visitor_aggregator'); - } - - public function update() - { - $this->getResource()->update(); - return $this; - } - - public function updateOneShot() + /** + * Init resource model + * + */ + protected function _construct() { - $this->getResource()->updateOneShot(); - return $this; + $this->_init('downloadable/link_purchased_item'); } } diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Sample.php b/app/code/core/Mage/Downloadable/Model/Resource/Sample.php new file mode 100755 index 0000000000..b0bc3fc926 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Sample.php @@ -0,0 +1,144 @@ + + */ +class Mage_Downloadable_Model_Resource_Sample extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('downloadable/sample', 'sample_id'); + } + + /** + * Save title of sample item in store scope + * + * @param Mage_Downloadable_Model_Sample $sampleObject + * @return Mage_Downloadable_Model_Resource_Sample + */ + public function saveItemTitle($sampleObject) + { + $writeAdapter = $this->_getWriteAdapter(); + $sampleTitleTable = $this->getTable('downloadable/sample_title'); + $bind = array( + ':sample_id' => $sampleObject->getId(), + ':store_id' => (int)$sampleObject->getStoreId() + ); + $select = $writeAdapter->select() + ->from($sampleTitleTable) + ->where('sample_id=:sample_id AND store_id=:store_id'); + if ($writeAdapter->fetchOne($select, $bind)) { + $where = array( + 'sample_id = ?' => $sampleObject->getId(), + 'store_id = ?' => (int)$sampleObject->getStoreId() + ); + if ($sampleObject->getUseDefaultTitle()) { + $writeAdapter->delete( + $sampleTitleTable, $where); + } else { + $writeAdapter->update( + $sampleTitleTable, + array('title' => $sampleObject->getTitle()), $where); + } + } else { + if (!$sampleObject->getUseDefaultTitle()) { + $writeAdapter->insert( + $sampleTitleTable, + array( + 'sample_id' => $sampleObject->getId(), + 'store_id' => (int)$sampleObject->getStoreId(), + 'title' => $sampleObject->getTitle(), + )); + } + } + return $this; + } + + /** + * Delete data by item(s) + * + * @param Mage_Downloadable_Model_Sample|array|int $items + * @return Mage_Downloadable_Model_Resource_Sample + */ + public function deleteItems($items) + { + + $writeAdapter = $this->_getWriteAdapter(); + $where = ''; + if ($items instanceof Mage_Downloadable_Model_Sample) { + $where = array('sample_id = ?' => $items->getId()); + } else { + $where = array('sample_id in (?)' => $items); + } + if ($where) { + $writeAdapter->delete( + $this->getMainTable(), $where); + $writeAdapter->delete( + $this->getTable('downloadable/sample_title'), $where); + } + return $this; + } + + /** + * Retrieve links searchable data + * + * @param int $productId + * @param int $storeId + * @return array + */ + public function getSearchableData($productId, $storeId) + { + $adapter = $this->_getReadAdapter(); + $ifNullDefaultTitle = $adapter->getIfNullSql('st.title', 'd.title'); + $select = $adapter->select() + ->from(array('m' => $this->getMainTable()), null) + ->join( + array('d' => $this->getTable('downloadable/sample_title')), + 'd.sample_id=m.sample_id AND d.store_id=0', + array()) + ->joinLeft( + array('st' => $this->getTable('downloadable/sample_title')), + 'st.sample_id=m.sample_id AND st.store_id=:store_id', + array('title' => $ifNullDefaultTitle)) + ->where('m.product_id=:product_id', $productId); + $bind = array( + ':store_id' => (int)$storeId, + ':product_id' => $productId + ); + + return $adapter->fetchCol($select, $bind); + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Resource/Sample/Collection.php b/app/code/core/Mage/Downloadable/Model/Resource/Sample/Collection.php new file mode 100755 index 0000000000..71aa90d215 --- /dev/null +++ b/app/code/core/Mage/Downloadable/Model/Resource/Sample/Collection.php @@ -0,0 +1,86 @@ + + */ +class Mage_Downloadable_Model_Resource_Sample_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init resource model + */ + protected function _construct() + { + $this->_init('downloadable/sample'); + } + + /** + * Method for product filter + * + * @param Mage_Catalog_Model_Product|array|integer|null $product + * @return Mage_Downloadable_Model_Resource_Sample_Collection + */ + public function addProductToFilter($product) + { + if (empty($product)) { + $this->addFieldToFilter('product_id', ''); + } elseif (is_array($product)) { + $this->addFieldToFilter('product_id', array('in' => $product)); + } else { + $this->addFieldToFilter('product_id', $product); + } + + return $this; + } + + /** + * Add title column to select + * + * @param integer $storeId + * @return Mage_Downloadable_Model_Resource_Sample_Collection + */ + public function addTitleToResult($storeId = 0) + { + $ifNullDefaultTitle = $this->getConnection() + ->getIfNullSql('st.title', 'd.title'); + $this->getSelect() + ->joinLeft(array('d' => $this->getTable('downloadable/sample_title')), + 'd.sample_id=main_table.sample_id AND d.store_id = 0', + array('default_title' => 'title')) + ->joinLeft(array('st' => $this->getTable('downloadable/sample_title')), + 'st.sample_id=main_table.sample_id AND st.store_id = ' . (int)$storeId, + array('store_title' => 'title','title' => $ifNullDefaultTitle)) + ->order('main_table.sort_order ASC') + ->order('title ASC'); + + return $this; + } +} diff --git a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Abstract.php index dbbd3d987b..d420a07c9f 100644 --- a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Creditmemo.php index e003c32b46..38c82bd606 100644 --- a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Invoice.php index 069c06fdfc..190232d292 100644 --- a/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/core/Mage/Downloadable/Model/Sales/Order/Pdf/Items/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/Sample.php b/app/code/core/Mage/Downloadable/Model/Sample.php index 76f15d54b0..aad0d343fc 100644 --- a/app/code/core/Mage/Downloadable/Model/Sample.php +++ b/app/code/core/Mage/Downloadable/Model/Sample.php @@ -20,13 +20,26 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Downloadable sample model * + * @method Mage_Downloadable_Model_Resource_Sample _getResource() + * @method Mage_Downloadable_Model_Resource_Sample getResource() + * @method int getProductId() + * @method Mage_Downloadable_Model_Sample setProductId(int $value) + * @method string getSampleUrl() + * @method Mage_Downloadable_Model_Sample setSampleUrl(string $value) + * @method string getSampleFile() + * @method Mage_Downloadable_Model_Sample setSampleFile(string $value) + * @method string getSampleType() + * @method Mage_Downloadable_Model_Sample setSampleType(string $value) + * @method int getSortOrder() + * @method Mage_Downloadable_Model_Sample setSortOrder(int $value) + * * @category Mage * @package Mage_Downloadable * @author Magento Core Team diff --git a/app/code/core/Mage/Downloadable/Model/System/Config/Source/Contentdisposition.php b/app/code/core/Mage/Downloadable/Model/System/Config/Source/Contentdisposition.php index a67c63615b..9512c81954 100644 --- a/app/code/core/Mage/Downloadable/Model/System/Config/Source/Contentdisposition.php +++ b/app/code/core/Mage/Downloadable/Model/System/Config/Source/Contentdisposition.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/Model/System/Config/Source/Orderitemstatus.php b/app/code/core/Mage/Downloadable/Model/System/Config/Source/Orderitemstatus.php index 234cbb8c93..f57ba6074b 100644 --- a/app/code/core/Mage/Downloadable/Model/System/Config/Source/Orderitemstatus.php +++ b/app/code/core/Mage/Downloadable/Model/System/Config/Source/Orderitemstatus.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php index ccd7823aa5..6e4f8bd96f 100644 --- a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php +++ b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/FileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/Product/EditController.php b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/Product/EditController.php index 0417ccbf90..03cbaa7503 100644 --- a/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/Product/EditController.php +++ b/app/code/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/Product/EditController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/CustomerController.php b/app/code/core/Mage/Downloadable/controllers/CustomerController.php index 3135b09fd1..70faeea7a1 100644 --- a/app/code/core/Mage/Downloadable/controllers/CustomerController.php +++ b/app/code/core/Mage/Downloadable/controllers/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/DownloadController.php b/app/code/core/Mage/Downloadable/controllers/DownloadController.php index 8e63272d39..0a5b905854 100644 --- a/app/code/core/Mage/Downloadable/controllers/DownloadController.php +++ b/app/code/core/Mage/Downloadable/controllers/DownloadController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/FileController.php b/app/code/core/Mage/Downloadable/controllers/FileController.php index 16c8310333..778cf5c47c 100644 --- a/app/code/core/Mage/Downloadable/controllers/FileController.php +++ b/app/code/core/Mage/Downloadable/controllers/FileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/controllers/Product/EditController.php b/app/code/core/Mage/Downloadable/controllers/Product/EditController.php index be25913427..14cb23cf4f 100644 --- a/app/code/core/Mage/Downloadable/controllers/Product/EditController.php +++ b/app/code/core/Mage/Downloadable/controllers/Product/EditController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/data/downloadable_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Downloadable/data/downloadable_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..07bac6f538 --- /dev/null +++ b/app/code/core/Mage/Downloadable/data/downloadable_setup/data-install-1.6.0.0.php @@ -0,0 +1,47 @@ +getAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to')); + if (!in_array('downloadable', $applyTo)) { + $applyTo[] = 'downloadable'; + $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to', implode(',', $applyTo)); + } +} + diff --git a/app/code/core/Mage/Downloadable/etc/adminhtml.xml b/app/code/core/Mage/Downloadable/etc/adminhtml.xml index f7e6a7e7c8..4956a1f875 100644 --- a/app/code/core/Mage/Downloadable/etc/adminhtml.xml +++ b/app/code/core/Mage/Downloadable/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Downloadable/etc/config.xml b/app/code/core/Mage/Downloadable/etc/config.xml index 3df5655453..f2fb31450c 100644 --- a/app/code/core/Mage/Downloadable/etc/config.xml +++ b/app/code/core/Mage/Downloadable/etc/config.xml @@ -21,38 +21,68 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.3 + 1.6.0.0 - order_id - order_increment_id - * - * - * + + order_id + + + order_increment_id + + + * + + + * + + + * + - order_item_id - product_name - product_sku + + order_item_id + + + product_name + + + product_sku + - * - * - <to_purchased>link_title</to_purchased> - * - * - * - * + + * + + + * + + + <to_purchased>link_title</to_purchased> + + + * + + + * + + + * + + + * + @@ -68,10 +98,11 @@ Mage_Downloadable_Model - downloadable_mysql4 + downloadable_resource - - Mage_Downloadable_Model_Mysql4 + + Mage_Downloadable_Model_Resource + downloadable_mysql4 downloadable_link
    @@ -101,7 +132,7 @@ catalog_product_index_price_downlod_tmp
    -
    +
    @@ -129,19 +160,19 @@ downloadable/indexer_price 0 - - - - - + + + + + - + - + @@ -286,47 +317,47 @@ - + - + - + - + - + - + - + - + - + diff --git a/app/code/core/Mage/Downloadable/etc/system.xml b/app/code/core/Mage/Downloadable/etc/system.xml index 19d42d6562..aea4f332e7 100644 --- a/app/code/core/Mage/Downloadable/etc/system.xml +++ b/app/code/core/Mage/Downloadable/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/install-1.6.0.0.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..10aefb639c --- /dev/null +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/install-1.6.0.0.php @@ -0,0 +1,531 @@ +startSetup(); + +/** + * Create table 'downloadable/link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/link')) + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort order') + ->addColumn('number_of_downloads', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => true, + ), 'Number of downloads') + ->addColumn('is_shareable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Shareable flag') + ->addColumn('link_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link Url') + ->addColumn('link_file', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link File') + ->addColumn('link_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Link Type') + ->addColumn('sample_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sample Url') + ->addColumn('sample_file', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sample File') + ->addColumn('sample_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Sample Type') + ->addIndex($installer->getIdxName('downloadable/link', 'product_id'), 'product_id') + ->addIndex($installer->getIdxName('downloadable/link', array('product_id','sort_order')), + array('product_id','sort_order')) + ->addForeignKey($installer->getFkName('downloadable/link', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Link Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/link_price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/link_price')) + ->addColumn('price_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Price ID') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Link ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website ID') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addIndex($installer->getIdxName('downloadable/link_price', 'link_id'), 'link_id') + ->addForeignKey($installer->getFkName('downloadable/link_price', 'link_id', 'downloadable/link', 'link_id'), + 'link_id', $installer->getTable('downloadable/link'), 'link_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('downloadable/link_price', 'website_id'), 'website_id') + ->addForeignKey($installer->getFkName('downloadable/link_price', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Link Price Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/link_purchased' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/link_purchased')) + ->addColumn('purchased_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Purchased ID') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Order ID') + ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Increment ID') + ->addColumn('order_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Order Item ID') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Date of creation') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Date of modification') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => true, + 'default' => '0', + ), 'Customer ID') + ->addColumn('product_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Product name') + ->addColumn('product_sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Product sku') + ->addColumn('link_section_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link_section_title') + ->addIndex($installer->getIdxName('downloadable/link_purchased', 'order_id'), 'order_id') + ->addIndex($installer->getIdxName('downloadable/link_purchased', 'order_item_id'), 'order_item_id') + ->addIndex($installer->getIdxName('downloadable/link_purchased', 'customer_id'), 'customer_id') + ->addForeignKey($installer->getFkName('downloadable/link_purchased', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('downloadable/link_purchased', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Link Purchased Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/link_purchased_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/link_purchased_item')) + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Item ID') + ->addColumn('purchased_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Purchased ID') + ->addColumn('order_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Order Item ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => true, + 'default' => '0', + ), 'Product ID') + ->addColumn('link_hash', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link hash') + ->addColumn('number_of_downloads_bought', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Number of downloads bought') + ->addColumn('number_of_downloads_used', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Number of downloads used') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Link ID') + ->addColumn('link_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link Title') + ->addColumn('is_shareable', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Shareable Flag') + ->addColumn('link_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link Url') + ->addColumn('link_file', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link File') + ->addColumn('link_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Link Type') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Status') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Creation Time') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Update Time') + ->addIndex($installer->getIdxName('downloadable/link_purchased_item', 'link_hash'), 'link_hash') + ->addIndex($installer->getIdxName('downloadable/link_purchased_item', 'order_item_id'), 'order_item_id') + ->addIndex($installer->getIdxName('downloadable/link_purchased_item', 'purchased_id'), 'purchased_id') + ->addForeignKey( + $installer->getFkName( + 'downloadable/link_purchased_item', + 'purchased_id', + 'downloadable/link_purchased', + 'purchased_id' + ), + 'purchased_id', $installer->getTable('downloadable/link_purchased'), 'purchased_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'downloadable/link_purchased_item', + 'order_item_id', + 'sales/order_item', + 'item_id' + ), + 'order_item_id', $installer->getTable('sales/order_item'), 'item_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Link Purchased Item Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/link_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/link_title')) + ->addColumn('title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Title ID') + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Link ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Title') + ->addIndex( + $installer->getIdxName( + 'downloadable/link_title', + array('link_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('link_id', 'store_id'), + array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('downloadable/link_title', 'link_id'), 'link_id') + ->addForeignKey($installer->getFkName('downloadable/link_title', 'link_id', 'downloadable/link', 'link_id'), + 'link_id', $installer->getTable('downloadable/link'), 'link_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('downloadable/link_title', 'store_id'), 'store_id') + ->addForeignKey($installer->getFkName('downloadable/link_title', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Link Title Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/sample' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/sample')) + ->addColumn('sample_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Sample ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('sample_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sample URL') + ->addColumn('sample_file', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sample file') + ->addColumn('sample_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Sample Type') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex($installer->getIdxName('downloadable/sample', 'product_id'), 'product_id') + ->addForeignKey($installer->getFkName('downloadable/sample', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Sample Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/sample_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/sample_title')) + ->addColumn('title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Title ID') + ->addColumn('sample_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sample ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store ID') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Title') + ->addIndex( + $installer->getIdxName( + 'downloadable/sample_title', + array('sample_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('sample_id', 'store_id'), + array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('downloadable/sample_title', 'sample_id'), 'sample_id') + ->addForeignKey($installer->getFkName('downloadable/sample_title', 'sample_id', 'downloadable/sample', 'sample_id'), + 'sample_id', $installer->getTable('downloadable/sample'), 'sample_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('downloadable/sample_title', 'store_id'), 'store_id') + ->addForeignKey($installer->getFkName('downloadable/sample_title', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Downloadable Sample Title Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/product_price_indexer_idx' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/product_price_indexer_idx')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Minimum price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Maximum price') + ->setComment('Indexer Table for price of downloadable products'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'downloadable/product_price_indexer_tmp' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('downloadable/product_price_indexer_tmp')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity ID') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group ID') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website ID') + ->addColumn('min_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Minimum price') + ->addColumn('max_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Maximum price') + ->setComment('Temporary Indexer Table for price of downloadable products') + ->setOption('type', 'MEMORY'); +$installer->getConnection()->createTable($table); + + +/** + * Add attributes to the eav/attribute table + */ +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'links_purchased_separately', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Links can be purchased separately', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'downloadable', + 'is_configurable' => false, + 'used_in_product_listing' => true +)); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'samples_title', array( + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Samples title', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'downloadable', + 'is_configurable' => false +)); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'links_title', array( + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Links title', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'visible' => false, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'downloadable', + 'is_configurable' => false +)); + +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'links_exist', array( + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => '', + 'input' => '', + 'class' => '', + 'source' => '', + 'global' => true, + 'visible' => false, + 'required' => false, + 'user_defined' => false, + 'default' => '0', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => 'downloadable', + 'is_configurable' => false, + 'used_in_product_listing' => 1 +)); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-0.1.0.php index a6121095f2..488b6e981b 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-0.1.0.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-0.1.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -43,10 +43,10 @@ // make these attributes applicable to downloadable products foreach ($fieldList as $field) { - $applyTo = explode(',', $installer->getAttribute('catalog_product', $field, 'apply_to')); + $applyTo = explode(',', $installer->getAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to')); if (!in_array('downloadable', $applyTo)) { $applyTo[] = 'downloadable'; - $installer->updateAttribute('catalog_product', $field, 'apply_to', join(',', $applyTo)); + $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, $field, 'apply_to', join(',', $applyTo)); } } diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-1.4.0.0.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-1.4.0.0.php index 339d1323ff..6897a313c9 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-1.4.0.0.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-install-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.0-0.1.1.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.0-0.1.1.php index 4edd26c0bf..3934e21426 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.0-0.1.1.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.0-0.1.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.1-0.1.2.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.1-0.1.2.php index 769658b438..fdeb5adade 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.1-0.1.2.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.1-0.1.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.10-0.1.11.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.10-0.1.11.php index 5959f16948..00daa4bd6b 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.10-0.1.11.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.10-0.1.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.11-0.1.12.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.11-0.1.12.php index a34186dba9..ac0e6e4e33 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.11-0.1.12.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.11-0.1.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.12-0.1.13.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.12-0.1.13.php index 08310f0311..f4303e7484 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.12-0.1.13.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.12-0.1.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.13-0.1.14.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.13-0.1.14.php index a47ef4ff26..b432d4ee8d 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.13-0.1.14.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.13-0.1.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.14-0.1.15.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.14-0.1.15.php index 42453fb815..fc9293baa4 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.14-0.1.15.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.14-0.1.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.15-0.1.16.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.15-0.1.16.php index 470ad0606d..e6457c4850 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.15-0.1.16.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.15-0.1.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.2-0.1.3.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.2-0.1.3.php index eabc4d88cc..7beabe1a2f 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.2-0.1.3.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.2-0.1.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.3-0.1.4.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.3-0.1.4.php index e23bc997dc..ee2a1c0b68 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.3-0.1.4.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.3-0.1.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.4-0.1.5.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.4-0.1.5.php index 51e0bb455b..127bc3e060 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.4-0.1.5.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.4-0.1.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.5-0.1.6.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.5-0.1.6.php index 40ece3d566..fe01d5cfd6 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.5-0.1.6.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.5-0.1.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.6-0.1.7.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.6-0.1.7.php index cd9bf09909..aab5fcc8ec 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.6-0.1.7.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.6-0.1.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.7-0.1.8.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.7-0.1.8.php index 3318a261ff..e9771bfb35 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.7-0.1.8.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.7-0.1.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.8-0.1.9.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.8-0.1.9.php index c8ef9926e8..9a0283c432 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.8-0.1.9.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.8-0.1.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.9-0.1.10.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.9-0.1.10.php index 7defd31f33..ffa3b60276 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.9-0.1.10.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-0.1.9-0.1.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.3.9-1.4.0.0.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.3.9-1.4.0.0.php index 726341622b..dc933cbd1e 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.3.9-1.4.0.0.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.3.9-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php index 5b0ef6c29c..6608d6068b 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php index b238c63c81..839aee5b6e 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php index f76216cb5e..f3e4b3ee67 100644 --- a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -93,6 +93,3 @@ 'item_id', 'set null' ); - - - diff --git a/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..164b8ac2cb --- /dev/null +++ b/app/code/core/Mage/Downloadable/sql/downloadable_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,867 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link'), + 'FK_DOWNLODABLE_LINK_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_price'), + 'FK_DOWNLOADABLE_LINK_PRICE_LINK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_price'), + 'FK_DOWNLOADABLE_LINK_PRICE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_purchased'), + 'FK_DOWNLOADABLE_LINK_ORDER_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_purchased_item'), + 'FK_DOWNLOADABLE_LINK_PURCHASED_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_purchased_item'), + 'FK_DOWNLOADABLE_LINK_ORDER_ITEM_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_title'), + 'FK_DOWNLOADABLE_LINK_TITLE_LINK' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/link_title'), + 'FK_DOWNLOADABLE_LINK_TITLE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable/sample'), + 'FK_DOWNLODABLE_SAMPLE_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable_sample_title'), + 'FK_DOWNLOADABLE_SAMPLE_TITLE_SAMPLE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('downloadable_sample_title'), + 'FK_DOWNLOADABLE_SAMPLE_TITLE_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link'), + 'DOWNLODABLE_LINK_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link'), + 'DOWNLODABLE_LINK_PRODUCT_SORT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_price'), + 'DOWNLOADABLE_LINK_PRICE_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_price'), + 'DOWNLOADABLE_LINK_PRICE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased'), + 'DOWNLOADABLE_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased'), + 'DOWNLOADABLE_CUSTOMER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased'), + 'KEY_DOWNLOADABLE_ORDER_ITEM_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased_item'), + 'DOWNLOADABLE_LINK_PURCHASED_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased_item'), + 'DOWNLOADABLE_ORDER_ITEM_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_purchased_item'), + 'DOWNLOADALBE_LINK_HASH' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_title'), + 'UNQ_LINK_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_title'), + 'DOWNLOADABLE_LINK_TITLE_LINK' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/link_title'), + 'DOWNLOADABLE_LINK_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/sample'), + 'DOWNLODABLE_SAMPLE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/sample_title'), + 'UNQ_SAMPLE_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/sample_title'), + 'DOWNLOADABLE_SAMPLE_TITLE_SAMPLE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('downloadable/sample_title'), + 'DOWNLOADABLE_SAMPLE_TITLE_STORE' +); + + +/** + * Change columns + */ + +$tables = array( + $installer->getTable('downloadable/link') => array( + 'columns' => array( + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort order' + ), + 'number_of_downloads' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Number of downloads' + ), + 'is_shareable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Shareable flag' + ), + 'link_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link Url' + ), + 'link_file' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link File' + ), + 'link_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Link Type' + ), + 'sample_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sample Url' + ), + 'sample_file' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sample File' + ), + 'sample_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Sample Type' + ) + ), + 'comment' => 'Downloadable Link Table' + ), + $installer->getTable('downloadable/link_title') => array( + 'columns' => array( + 'title_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Title ID' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Title' + ) + ), + 'comment' => 'Link Title Table' + ), + $installer->getTable('downloadable/link_price') => array( + 'columns' => array( + 'price_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Price ID' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website ID' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ) + ), + 'comment' => 'Downloadable Link Price Table' + ), + $installer->getTable('downloadable/sample') => array( + 'columns' => array( + 'sample_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Sample ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'sample_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sample URL' + ), + 'sample_file' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sample file' + ), + 'sample_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Sample Type' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Downloadable Sample Table' + ), + $installer->getTable('downloadable/sample_title') => array( + 'columns' => array( + 'title_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Title ID' + ), + 'sample_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sample ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ID' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Title' + ) + ), + 'comment' => 'Downloadable Sample Title Table' + ), + $installer->getTable('downloadable/link_purchased') => array( + 'columns' => array( + 'purchased_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Purchased ID' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Order ID' + ), + 'order_increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Increment ID' + ), + 'order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Order Item ID' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Date of creation' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Date of modification' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer ID' + ), + 'product_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product name' + ), + 'product_sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product sku' + ), + 'link_section_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link_section_title' + ) + ), + 'comment' => 'Downloadable Link Purchased Table' + ), + $installer->getTable('downloadable/link_purchased_item') => array( + 'columns' => array( + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Item ID' + ), + 'purchased_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Purchased ID' + ), + 'order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Order Item ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'link_hash' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link hash' + ), + 'number_of_downloads_bought' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Number of downloads bought' + ), + 'number_of_downloads_used' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Number of downloads used' + ), + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Link ID' + ), + 'link_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link Title' + ), + 'is_shareable' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Shareable Flag' + ), + 'link_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link Url' + ), + 'link_file' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link File' + ), + 'link_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Link Type' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Status' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Creation Time' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Update Time' + ) + ), + 'comment' => 'Downloadable Link Purchased Item Table' + ), + $installer->getTable('downloadable/product_price_indexer_idx') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Minimum price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Maximum price' + ) + ), + 'comment' => 'Indexer Table for price of downloadable products' + ), + $installer->getTable('downloadable/product_price_indexer_tmp') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity ID' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group ID' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website ID' + ), + 'min_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Minimum price' + ), + 'max_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Maximum price' + ) + ), + 'comment' => 'Temporary Indexer Table for price of downloadable products' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link'), + $installer->getIdxName('downloadable/link', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link'), + $installer->getIdxName('downloadable/link', array('product_id', 'sort_order')), + array('product_id', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_price'), + $installer->getIdxName('downloadable/link_price', array('link_id')), + array('link_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_price'), + $installer->getIdxName('downloadable/link_price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased'), + $installer->getIdxName('downloadable/link_purchased', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased'), + $installer->getIdxName('downloadable/link_purchased', array('order_item_id')), + array('order_item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased'), + $installer->getIdxName('downloadable/link_purchased', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased_item'), + $installer->getIdxName('downloadable/link_purchased_item', array('link_hash')), + array('link_hash') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased_item'), + $installer->getIdxName('downloadable/link_purchased_item', array('order_item_id')), + array('order_item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_purchased_item'), + $installer->getIdxName('downloadable/link_purchased_item', array('purchased_id')), + array('purchased_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_title'), + $installer->getIdxName( + 'downloadable/link_title', + array('link_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('link_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_title'), + $installer->getIdxName('downloadable/link_title', array('link_id')), + array('link_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/link_title'), + $installer->getIdxName('downloadable/link_title', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/sample'), + $installer->getIdxName('downloadable/sample', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/sample_title'), + $installer->getIdxName( + 'downloadable/sample_title', + array('sample_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('sample_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/sample_title'), + $installer->getIdxName('downloadable/sample_title', array('sample_id')), + array('sample_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('downloadable/sample_title'), + $installer->getIdxName('downloadable/sample_title', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('downloadable/link'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_price', 'link_id', 'downloadable/link', 'link_id'), + $installer->getTable('downloadable/link_price'), + 'link_id', + $installer->getTable('downloadable/link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('downloadable/link_price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_purchased', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('downloadable/link_purchased'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_purchased', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('downloadable/link_purchased'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'downloadable/link_purchased_item', + 'purchased_id', + 'downloadable/link_purchased', + 'purchased_id' + ), + $installer->getTable('downloadable/link_purchased_item'), + 'purchased_id', + $installer->getTable('downloadable/link_purchased'), + 'purchased_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_purchased_item', 'order_item_id', 'sales/order_item', 'item_id'), + $installer->getTable('downloadable/link_purchased_item'), + 'order_item_id', + $installer->getTable('sales/order_item'), + 'item_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_title', 'link_id', 'downloadable/link', 'link_id'), + $installer->getTable('downloadable/link_title'), + 'link_id', + $installer->getTable('downloadable/link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/link_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('downloadable/link_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/sample', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('downloadable/sample'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/sample_title', 'sample_id', 'downloadable/sample', 'sample_id'), + $installer->getTable('downloadable/sample_title'), + 'sample_id', + $installer->getTable('downloadable/sample'), + 'sample_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('downloadable/sample_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('downloadable/sample_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php index a4360e61f0..10ac585a4f 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php index 82274a240b..b2b77455c6 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -78,12 +78,15 @@ protected function _prepareForm() $yesno = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); + $validateClass = sprintf('validate-code validate-length maximum-length-%d', + Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH); $fieldset->addField('attribute_code', 'text', array( 'name' => 'attribute_code', 'label' => Mage::helper('eav')->__('Attribute Code'), 'title' => Mage::helper('eav')->__('Attribute Code'), - 'note' => Mage::helper('eav')->__('For internal use. Must be unique with no spaces'), - 'class' => 'validate-code', + 'note' => Mage::helper('eav')->__('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less then %s symbols', + Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH), + 'class' => $validateClass, 'required' => true, )); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php index 0df6153f14..44112f0595 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php index 1c0432c1d1..0253b1b4ed 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Exception.php b/app/code/core/Mage/Eav/Exception.php index 04092a3b6a..7792d9e7cd 100644 --- a/app/code/core/Mage/Eav/Exception.php +++ b/app/code/core/Mage/Eav/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index 27a0a6ac9c..b7e733b7a3 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php index a134bee807..84fb7ff0b6 100644 --- a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php +++ b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php @@ -20,12 +20,11 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype { - public function toOptionArray() { return array( @@ -37,5 +36,4 @@ public function toOptionArray() array('value' => 'select', 'label' => Mage::helper('eav')->__('Dropdown')) ); } - } diff --git a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php index e5fdd02c37..cbcdc5bcfb 100644 --- a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php +++ b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Config.php b/app/code/core/Mage/Eav/Model/Config.php index e8ede89c2c..45edfac40e 100644 --- a/app/code/core/Mage/Eav/Model/Config.php +++ b/app/code/core/Mage/Eav/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -49,21 +49,21 @@ class Mage_Eav_Model_Config * * @var array */ - protected $_preloadedAttributes = array(); + protected $_preloadedAttributes = array(); /** * Information about entity types with initialized attributes * * @var array */ - protected $_initializedAttributes = array(); + protected $_initializedAttributes = array(); /** * Attribute codes cache array * * @var array */ - protected $_attributeCodes = array(); + protected $_attributeCodes = array(); /** * Initialized objects @@ -91,14 +91,14 @@ class Mage_Eav_Model_Config * * @var unknown_type */ - protected $_isCacheEnabled = null; + protected $_isCacheEnabled = null; /** * Array of attributes objects used in collections * * @var array */ - protected $_collectionAttributes = array(); + protected $_collectionAttributes = array(); /** * Reset object state @@ -108,11 +108,11 @@ class Mage_Eav_Model_Config */ public function clear() { - $this->_entityData = null; - $this->_attributeData = null; - $this->_objects = null; - $this->_references = null; - $this->_preloadedAttributes = array(); + $this->_entityData = null; + $this->_attributeData = null; + $this->_objects = null; + $this->_references = null; + $this->_preloadedAttributes = array(); $this->_initializedAttributes = array(); return $this; } @@ -202,7 +202,7 @@ protected function _getAttributeReference($id, $entityTypeCode) */ protected function _getEntityKey($code) { - return 'ENTITY/'.$code; + return 'ENTITY/' . $code; } /** @@ -214,7 +214,7 @@ protected function _getEntityKey($code) */ protected function _getAttributeKey($entityTypeCode, $attributeCode) { - return 'ATTRIBUTE/'. $entityTypeCode .'/' . $attributeCode; + return 'ATTRIBUTE/' . $entityTypeCode . '/' . $attributeCode; } /** @@ -258,7 +258,7 @@ protected function _initEntityTypes() } $entityTypesData = Mage::getModel('eav/entity_type')->getCollection()->getData(); - $types = array(); + $types = array(); /** * prepare entity type data @@ -298,18 +298,17 @@ public function getEntityType($code) return $code; } Varien_Profiler::start('EAV: '.__METHOD__); - //$this->_initEntityTypes(); if (is_numeric($code)) { $entityCode = $this->_getEntityTypeReference($code); if ($entityCode !== null) { $code = $entityCode; - //Mage::throwException(Mage::helper('eav')->__('Invalid entity_type specified: %s', $code)); } } $entityKey = $this->_getEntityKey($code); - if ($entityType = $this->_load($entityKey)) { + $entityType = $this->_load($entityKey); + if ($entityType) { Varien_Profiler::stop('EAV: '.__METHOD__); return $entityType; } @@ -318,8 +317,7 @@ public function getEntityType($code) $entityType = Mage::getModel('eav/entity_type'); if (isset($this->_entityData[$code])) { $entityType->setData($this->_entityData[$code]); - } - else { + } else { if (is_numeric($code)) { $entityType->load($code); } else { @@ -355,7 +353,6 @@ protected function _initAttributes($entityType) $attributesInfo = Mage::getResourceModel($entityType->getEntityAttributeCollection()) ->setEntityTypeFilter($entityType) -// ->addSetInfo() ->getData(); $codes = array(); @@ -403,23 +400,18 @@ public function getAttribute($entityType, $code) /** * Try use loaded attribute */ - if ($attribute = $this->_load($attributeKey)) { + $attribute = $this->_load($attributeKey); + if ($attribute) { Varien_Profiler::stop('EAV: '.__METHOD__); return $attribute; } -// if (!isset($this->_preloadedAttributes[$entityTypeCode]) -// || !in_array($code, $this->_preloadedAttributes[$entityTypeCode])) { -// $this->_initAttributes($entityType); -// } - $attribute = false; if (isset($this->_attributeData[$entityTypeCode][$code])) { $data = $this->_attributeData[$entityTypeCode][$code]; unset($this->_attributeData[$entityTypeCode][$code]); $attribute = Mage::getModel($data['attribute_model'], $data); - } - else { + } else { if (is_numeric($code)) { $attribute = Mage::getModel($entityType->getAttributeModel())->load($code); if ($attribute->getEntityTypeId() != $entityType->getId()) { @@ -445,6 +437,7 @@ public function getAttribute($entityType, $code) $this->_save($attribute, $attributeKey); } Varien_Profiler::stop('EAV: '.__METHOD__); + return $attribute; } @@ -455,7 +448,7 @@ public function getAttribute($entityType, $code) * @param Varien_Object $object * @return array */ - public function getEntityAttributeCodes($entityType, $object=null) + public function getEntityAttributeCodes($entityType, $object = null) { $entityType = $this->getEntityType($entityType); $attributeSetId = 0; @@ -472,11 +465,9 @@ public function getEntityAttributeCodes($entityType, $object=null) } if ($attributeSetId) { - $attributesInfo = Mage::getResourceModel($entityType->getEntityAttributeCollection()) ->setEntityTypeFilter($entityType) ->setAttributeSetFilter($attributeSetId) -// ->addSetInfo() ->addStoreLabel($storeId) ->getData(); $attributes = array(); @@ -484,13 +475,13 @@ public function getEntityAttributeCodes($entityType, $object=null) $attributes[] = $attributeData['attribute_code']; $this->_createAttribute($entityType, $attributeData); } - } - else { + } else { $this->_initAttributes($entityType); $attributes = $this->getEntityType($entityType)->getAttributeCodes(); } $this->_attributeCodes[$cacheKey] = $attributes; + return $attributes; } @@ -512,8 +503,7 @@ public function preloadAttributes($entityType, $attributes) if (!isset($this->_preloadedAttributes[$entityTypeCode])) { $this->_preloadedAttributes[$entityTypeCode] = $attributes; - } - else { + } else { $attributes = array_diff($attributes, $this->_preloadedAttributes[$entityTypeCode]); $this->_preloadedAttributes[$entityTypeCode] = array_merge($this->_preloadedAttributes[$entityTypeCode], $attributes); } @@ -526,7 +516,6 @@ public function preloadAttributes($entityType, $attributes) $attributesInfo = Mage::getResourceModel($entityType->getEntityAttributeCollection()) ->setEntityTypeFilter($entityType) ->setCodeFilter($attributes) -// ->addSetInfo() ->getData(); if (!$attributesInfo) { @@ -534,8 +523,7 @@ public function preloadAttributes($entityType, $attributes) return $this; } - $attributesData = array(); - $codes = array(); + $attributesData = $codes = array(); foreach ($attributesInfo as $attribute) { if (empty($attribute['attribute_model'])) { @@ -547,12 +535,13 @@ public function preloadAttributes($entityType, $attributes) $this->_addAttributeReference($attributeId, $attributeCode, $entityTypeCode); $attributesData[$attributeCode] = $attribute; - $codes[] = $attributeCode; + $codes[] = $attributeCode; } $this->_attributeData[$entityTypeCode] = $attributesData; Varien_Profiler::stop('EAV: '.__METHOD__ . ':'.$entityTypeCode); + return $this; } @@ -561,7 +550,7 @@ public function preloadAttributes($entityType, $attributes) * * @param mixed $entityType * @param string $attribute - * @return Mage_Eav_Model_Entity_Attribute_Abstract + * @return Mage_Eav_Model_Entity_Attribute_Abstract|null */ public function getCollectionAttribute($entityType, $attribute) { @@ -575,8 +564,9 @@ public function getCollectionAttribute($entityType, $attribute) } } - $attributeKey = $this->_getAttributeKey($entityTypeCode, $attribute); - if ($attributeObject = $this->_load($attributeKey)) { + $attributeKey = $this->_getAttributeKey($entityTypeCode, $attribute); + $attributeObject = $this->_load($attributeKey); + if ($attributeObject) { return $attributeObject; } @@ -592,7 +582,7 @@ public function getCollectionAttribute($entityType, $attribute) */ public function loadCollectionAttributes($entityType, $attributes) { - $entityType = $this->getEntityType($entityType); + $entityType = $this->getEntityType($entityType); $entityTypeCode = $entityType->getEntityTypeCode(); if (!isset($this->_collectionAttributes[$entityTypeCode])) { @@ -642,7 +632,8 @@ protected function _createAttribute($entityType, $attributeData) $entityTypeCode = $entityType->getEntityTypeCode(); $attributeKey = $this->_getAttributeKey($entityTypeCode, $attributeData['attribute_code']); - if (($attribute = $this->_load($attributeKey))) { + $attribute = $this->_load($attributeKey); + if ($attribute) { $existsFullAttribute = $attribute->hasIsRequired(); $fullAttributeData = array_key_exists('is_required', $attributeData); @@ -653,8 +644,7 @@ protected function _createAttribute($entityType, $attributeData) if (!empty($attributeData['attribute_model'])) { $model = $attributeData['attribute_model']; - } - else { + } else { $model = $entityType->getAttributeModel(); } $attribute = Mage::getModel($model)->setData($attributeData); @@ -665,6 +655,7 @@ protected function _createAttribute($entityType, $attributeData) ); $attributeKey = $this->_getAttributeKey($entityTypeCode, $attributeData['attribute_code']); $this->_save($attribute, $attributeKey); + return $attribute; } diff --git a/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php b/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php index 0a37f4588d..29e8ac8265 100644 --- a/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php +++ b/app/code/core/Mage/Eav/Model/Convert/Adapter/Entity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Convert/Adapter/Grid.php b/app/code/core/Mage/Eav/Model/Convert/Adapter/Grid.php index 81a4bd0b13..5303900351 100644 --- a/app/code/core/Mage/Eav/Model/Convert/Adapter/Grid.php +++ b/app/code/core/Mage/Eav/Model/Convert/Adapter/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Convert/Parser/Abstract.php b/app/code/core/Mage/Eav/Model/Convert/Parser/Abstract.php index 2b9969b68a..79def77707 100644 --- a/app/code/core/Mage/Eav/Model/Convert/Parser/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Convert/Parser/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity.php b/app/code/core/Mage/Eav/Model/Entity.php index e233d63f7f..623d176621 100644 --- a/app/code/core/Mage/Eav/Model/Entity.php +++ b/app/code/core/Mage/Eav/Model/Entity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,7 +33,6 @@ */ class Mage_Eav_Model_Entity extends Mage_Eav_Model_Entity_Abstract { - const DEFAULT_ENTITY_MODEL = 'eav/entity'; const DEFAULT_ATTRIBUTE_MODEL = 'eav/entity_attribute'; const DEFAULT_BACKEND_MODEL = 'eav/entity_attribute_backend_default'; @@ -45,12 +44,12 @@ class Mage_Eav_Model_Entity extends Mage_Eav_Model_Entity_Abstract const DEFAULT_VALUE_TABLE_PREFIX= 'eav/entity_attribute'; /** - * Enter description here... - * + * Resource initialization */ public function __construct() { - $this->setConnection(Mage::getSingleton('core/resource')->getConnection('core_read')); + $resource = Mage::getSingleton('core/resource'); + $this->setConnection($resource->getConnection('eav_read')); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index 88438f93cf..9fcf5bd80e 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,8 +32,7 @@ * @package Mage_Eav * @author Magento Core Team */ -abstract class Mage_Eav_Model_Entity_Abstract - extends Mage_Core_Model_Resource_Abstract +abstract class Mage_Eav_Model_Entity_Abstract extends Mage_Core_Model_Resource_Abstract implements Mage_Eav_Model_Entity_Interface { /** @@ -62,21 +61,21 @@ abstract class Mage_Eav_Model_Entity_Abstract * * @var array */ - protected $_attributesById = array(); + protected $_attributesById = array(); /** * Attributes array by attribute name * * @var unknown_type */ - protected $_attributesByCode = array(); + protected $_attributesByCode = array(); /** * 2-dimentional array by table name and attribute name * * @var array */ - protected $_attributesByTable = array(); + protected $_attributesByTable = array(); /** * Attributes that are static fields in entity table @@ -90,10 +89,10 @@ abstract class Mage_Eav_Model_Entity_Abstract * * @var array */ - protected static $_defaultAttributes = array(); + protected static $_defaultAttributes = array(); /** - * Enter description here... + * Entity table * * @var string */ @@ -104,38 +103,44 @@ abstract class Mage_Eav_Model_Entity_Abstract * * @var array */ - protected $_describeTable = array(); + protected $_describeTable = array(); /** - * Enter description here... + * Entity table identification field name * * @var string */ protected $_entityIdField; /** - * Enter description here... + * Entity values table identification field name * * @var string */ protected $_valueEntityIdField; /** - * Enter description here... + * Entity value table prefix * * @var string */ protected $_valueTablePrefix; + /* Entity table string + * + * @var string + */ + protected $_entityTablePrefix; + /** - * Enter description here... + * Partial load flag * * @var boolean */ protected $_isPartialLoad = false; /** - * Enter description here... + * Partial save flag * * @var boolean */ @@ -162,6 +167,14 @@ abstract class Mage_Eav_Model_Entity_Abstract */ protected $_attributeValuesToSave = array(); + /** + * Array of describe attribute backend tables + * The table name as key + * + * @var array + */ + protected static $_attributeBackendTables = array(); + /** * Set connections for entity operations * @@ -169,10 +182,11 @@ abstract class Mage_Eav_Model_Entity_Abstract * @param Zend_Db_Adapter_Abstract|string|null $write * @return Mage_Eav_Model_Entity_Abstract */ - public function setConnection($read, $write=null) + public function setConnection($read, $write = null) { - $this->_read = $read; + $this->_read = $read; $this->_write = $write ? $write : $read; + return $this; } @@ -180,14 +194,12 @@ public function setConnection($read, $write=null) * Resource initialization */ protected function _construct() - { - - } + {} /** * Retrieve connection for read data * - * @return Varien_Db_Adapter_Pdo_Mysql + * @return Varien_Db_Adapter_Interface */ protected function _getReadAdapter() { @@ -200,7 +212,7 @@ protected function _getReadAdapter() /** * Retrieve connection for write data * - * @return Varien_Db_Adapter_Pdo_Mysql + * @return Varien_Db_Adapter_Interface */ protected function _getWriteAdapter() { @@ -213,7 +225,7 @@ protected function _getWriteAdapter() /** * Retrieve read DB connection * - * @return Varien_Db_Adapter_Pdo_Mysql + * @return Varien_Db_Adapter_Interface */ public function getReadConnection() { @@ -223,7 +235,7 @@ public function getReadConnection() /** * Retrieve write DB connection * - * @return Varien_Db_Adapter_Pdo_Mysql + * @return Varien_Db_Adapter_Interface */ public function getWriteConnection() { @@ -241,7 +253,7 @@ public function getIdFieldName() } /** - * Enter description here... + * Retreive table name * * @param string $alias * @return string @@ -274,7 +286,7 @@ public function setType($type) public function getEntityType() { if (empty($this->_type)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Entity is not initialized.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Entity is not initialized')); } return $this->_type; } @@ -292,7 +304,7 @@ public function getType() /** * Get entity type id * - * @return integer + * @return int */ public function getTypeId() { @@ -308,12 +320,12 @@ public function getTypeId() * @param array|string|null $attributes * @return Mage_Eav_Model_Entity_Abstract */ - public function unsetAttributes($attributes=null) + public function unsetAttributes($attributes = null) { - if (is_null($attributes)) { - $this->_attributesByCode = array(); - $this->_attributesById = array(); - $this->_attributesByTable = array(); + if ($attributes === null) { + $this->_attributesByCode = array(); + $this->_attributesById = array(); + $this->_attributesByTable = array(); return $this; } @@ -322,7 +334,7 @@ public function unsetAttributes($attributes=null) } if (!is_array($attributes)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Unknown parameter.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Unknown parameter')); } foreach ($attributes as $attrCode) { @@ -362,7 +374,7 @@ public function getAttribute($attribute) $attributeCode = $attributeInstance->getAttributeCode(); } - } elseif (is_string($attribute)) { + } else if (is_string($attribute)) { $attributeCode = $attribute; if (isset($this->_attributesByCode[$attributeCode])) { @@ -379,7 +391,7 @@ public function getAttribute($attribute) ->setEntityType($this->getEntityType()) ->setEntityTypeId($this->getEntityType()->getId()); } - } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + } else if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { $attributeInstance = $attribute; $attributeCode = $attributeInstance->getAttributeCode(); @@ -454,35 +466,36 @@ public function addAttribute(Mage_Eav_Model_Entity_Attribute_Abstract $attribute $this->_attributesById[$attribute->getId()] = $attribute; $this->_attributesByTable[$attribute->getBackendTable()][$attributeCode] = $attribute; } + return $this; } /** - * Enter description here... + * Retreive partial load flag * * @param boolean $flag * @return boolean */ - public function isPartialLoad($flag=null) + public function isPartialLoad($flag = null) { $result = $this->_isPartialLoad; - if (!is_null($flag)) { - $this->_isPartialLoad = $flag; + if ($flag !== null) { + $this->_isPartialLoad = (bool)$flag; } return $result; } /** - * Enter description here... + * Retreive partial save flag * * @param boolean $flag * @return boolean */ - public function isPartialSave($flag=null) + public function isPartialSave($flag = null) { $result = $this->_isPartialSave; - if (!is_null($flag)) { - $this->_isPartialSave = $flag; + if ($flag !== null) { + $this->_isPartialSave = (bool)$flag; } return $result; } @@ -527,7 +540,7 @@ public function loadAllAttributes($object=null) public function getSortedAttributes($setId = null) { $attributes = $this->getAttributesByCode(); - if (is_null($setId)) { + if ($setId === null) { $setId = $this->getEntityType()->getDefaultAttributeSetId(); } @@ -547,10 +560,17 @@ public function getSortedAttributes($setId = null) return $attributes; } + /** + * Compare attributes + * + * @param Mage_Eav_Model_Entity_Attribute $attribute1 + * @param Mage_Eav_Model_Entity_Attribute $attribute2 + * @return int + */ public function attributesCompare($attribute1, $attribute2) { - $sortPath = 'attribute_set_info/' . $this->_sortingSetId . '/sort'; - $groupSortPath = 'attribute_set_info/' . $this->_sortingSetId . '/group_sort'; + $sortPath = sprintf('attribute_set_info/%s/sort', $this->_sortingSetId); + $groupSortPath = sprintf('attribute_set_info/%s/group_sort', $this->_sortingSetId); $sort1 = ($attribute1->getData($groupSortPath) * 1000) + ($attribute1->getData($sortPath) * 0.0001); $sort2 = ($attribute2->getData($groupSortPath) * 1000) + ($attribute2->getData($sortPath) * 0.0001); @@ -589,22 +609,22 @@ protected function _isApplicableAttribute($object, $attribute) * @param array $part attribute, backend, frontend, source * @return array */ - public function walkAttributes($partMethod, array $args=array()) + public function walkAttributes($partMethod, array $args = array()) { $methodArr = explode('/', $partMethod); switch (sizeof($methodArr)) { case 1: - $part = 'attribute'; + $part = 'attribute'; $method = $methodArr[0]; break; case 2: - $part = $methodArr[0]; + $part = $methodArr[0]; $method = $methodArr[1]; break; } $results = array(); - foreach ($this->getAttributesByCode() as $attrCode=>$attribute) { + foreach ($this->getAttributesByCode() as $attrCode => $attribute) { if (isset($args[0]) && is_object($args[0]) && !$this->_isApplicableAttribute($args[0], $attribute)) { continue; @@ -634,16 +654,15 @@ public function walkAttributes($partMethod, array $args=array()) try { $results[$attrCode] = call_user_func_array(array($instance, $method), $args); - } - catch (Mage_Eav_Model_Entity_Attribute_Exception $e) { + } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) { + throw $e; + } catch (Exception $e) { + $e = Mage::getModel('eav/entity_attribute_exception', $e->getMessage()); + $e->setAttributeCode($attrCode)->setPart($part); throw $e; - } - catch (Exception $e) { - $exception = new Mage_Eav_Model_Entity_Attribute_Exception($e->getMessage()); - $exception->setAttributeCode($attrCode)->setPart($part); - throw $exception; } } + return $results; } @@ -701,13 +720,14 @@ public function getAttributesByTable() */ public function getEntityTable() { - if (empty($this->_entityTable)) { + if (!$this->_entityTable) { $table = $this->getEntityType()->getEntityTable(); - if (empty($table)) { + if (!$table) { $table = Mage_Eav_Model_Entity::DEFAULT_ENTITY_TABLE; } $this->_entityTable = Mage::getSingleton('core/resource')->getTableName($table); } + return $this->_entityTable; } @@ -718,12 +738,13 @@ public function getEntityTable() */ public function getEntityIdField() { - if (empty($this->_entityIdField)) { + if (!$this->_entityIdField) { $this->_entityIdField = $this->getEntityType()->getEntityIdField(); - if (empty($this->_entityIdField)) { + if (!$this->_entityIdField) { $this->_entityIdField = Mage_Eav_Model_Entity::DEFAULT_ENTITY_ID_FIELD; } } + return $this->_entityIdField; } @@ -744,7 +765,7 @@ public function getValueEntityIdField() */ public function getValueTablePrefix() { - if (empty($this->_valueTablePrefix)) { + if (!$this->_valueTablePrefix) { $prefix = (string)$this->getEntityType()->getValueTablePrefix(); if (!empty($prefix)) { $this->_valueTablePrefix = $prefix; @@ -756,20 +777,43 @@ public function getValueTablePrefix() $this->_valueTablePrefix = $this->getEntityTable(); } } + return $this->_valueTablePrefix; } + /** + * Get entity table prefix for value + * + * @return string + */ + public function getEntityTablePrefix() + { + if (empty($this->_entityTablePrefix)) { + $prefix = $this->getEntityType()->getEntityTablePrefix(); + if (empty($prefix)) { + $prefix = $this->getEntityType()->getEntityTable(); + if (empty($prefix)) { + $prefix = Mage_Eav_Model_Entity::DEFAULT_ENTITY_TABLE; + } + } + $this->_entityTablePrefix = $prefix; + } + + return $this->_entityTablePrefix; + } + /** * Check whether the attribute is a real field in entity table * * @see Mage_Eav_Model_Entity_Abstract::getAttribute for $attribute format * @param integer|string|Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @return unknown + * @return boolean */ public function isAttributeStatic($attribute) { - $attrInstance = $this->getAttribute($attribute); - return $attrInstance && $attrInstance->getBackend()->isStatic(); + $attrInstance = $this->getAttribute($attribute); + $attrBackendStatic = $attrInstance->getBackend()->isStatic(); + return $attrInstance && $attrBackendStatic; } /** @@ -787,8 +831,7 @@ public function validate($object) foreach ($result as $attributeCode => $error) { if ($error === false) { $errors[$attributeCode] = true; - } - elseif (is_string($error)) { + } elseif (is_string($error)) { $errors[$attributeCode] = $error; } } @@ -800,7 +843,7 @@ public function validate($object) } /** - * Enter description here... + * Set new increment id to object * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Abstract @@ -813,7 +856,7 @@ public function setNewIncrementId(Varien_Object $object) $incrementId = $this->getEntityType()->fetchNewIncrementId($object->getStoreId()); - if (false!==$incrementId) { + if ($incrementId !== false) { $object->setIncrementId($incrementId); } @@ -821,7 +864,7 @@ public function setNewIncrementId(Varien_Object $object) } /** - * Enter description here... + * Check attribute unique value * * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param Varien_Object $object @@ -829,25 +872,36 @@ public function setNewIncrementId(Varien_Object $object) */ public function checkAttributeUniqueValue(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $object) { - if ($attribute->getBackend()->getType()==='static') { - $select = $this->_getWriteAdapter()->select() + $adapter = $this->_getReadAdapter(); + $select = $adapter->select(); + if ($attribute->getBackend()->getType() === 'static') { + $bind = array( + 'entity_type_id' => $this->getTypeId(), + 'attribute_code' => $object->getData($attribute->getAttributeCode()) + ); + + $select ->from($this->getEntityTable(), $this->getEntityIdField()) - ->where('entity_type_id=?', $this->getTypeId()) - ->where($attribute->getAttributeCode().'=?', $object->getData($attribute->getAttributeCode())); + ->where('entity_type_id = :entity_type_id') + ->where($attribute->getAttributeCode() . ' = :attribute_code'); } else { $value = $object->getData($attribute->getAttributeCode()); if ($attribute->getBackend()->getType() == 'datetime') { - $date = new Zend_Date($value, Varien_Date::DATE_INTERNAL_FORMAT); + $date = new Zend_Date($value, Varien_Date::DATE_INTERNAL_FORMAT); $value = $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); } - - $select = $this->_getWriteAdapter()->select() + $bind = array( + 'entity_type_id' => $this->getTypeId(), + 'attribute_id' => $attribute->getId(), + 'value' => $value + ); + $select ->from($attribute->getBackend()->getTable(), $attribute->getBackend()->getEntityIdField()) - ->where('entity_type_id=?', $this->getTypeId()) - ->where('attribute_id=?', $attribute->getId()) - ->where('value=?', $value); + ->where('entity_type_id = :entity_type_id') + ->where('attribute_id = :attribute_id') + ->where('value = :value'); } - $data = $this->_getWriteAdapter()->fetchCol($select); + $data = $adapter->fetchCol($select, $bind); if ($object->getId()) { if (isset($data[0])) { @@ -855,13 +909,12 @@ public function checkAttributeUniqueValue(Mage_Eav_Model_Entity_Attribute_Abstra } return true; } - else { - return !count($data); - } + + return !count($data); } /** - * Enter description here... + * Retreive default source model * * @return string */ @@ -873,22 +926,24 @@ public function getDefaultAttributeSourceModel() /** * Load entity's attributes into the object * - * @param Varien_Object $object + * @param Mage_Core_Model_Abstract $object * @param integer $entityId * @param array|null $attributes * @return Mage_Eav_Model_Entity_Abstract */ - public function load($object, $entityId, $attributes=array()) + public function load($object, $entityId, $attributes = array()) { Varien_Profiler::start('__EAV_LOAD_MODEL__'); /** * Load object base row data */ - $select = $this->_getLoadRowSelect($object, $entityId); - $row = $this->_getReadAdapter()->fetchRow($select); - //$object->setData($row); + $select = $this->_getLoadRowSelect($object, $entityId); + $row = $this->_getReadAdapter()->fetchRow($select); + if (is_array($row)) { $object->addData($row); + } else { + $object->isObjectNew(true); } if (empty($attributes)) { @@ -899,26 +954,11 @@ public function load($object, $entityId, $attributes=array()) } } - /** - * Load data for entity attributes - */ - Varien_Profiler::start('__EAV_LOAD_MODEL_ATTRIBUTES__'); - $selects = array(); - foreach ($this->getAttributesByTable() as $table=>$attributes) { - $selects[] = $this->_getLoadAttributesSelect($object, $table); - } - if (!empty($selects)) { - $select = $this->_prepareLoadSelect($selects); - $values = $this->_getReadAdapter()->fetchAll($select); - foreach ($values as $valueRow) { - $this->_setAttribteValue($object, $valueRow); - } - } - - Varien_Profiler::stop('__EAV_LOAD_MODEL_ATTRIBUTES__'); + $this->_loadModelAttributes($object); $object->setOrigData(); Varien_Profiler::start('__EAV_LOAD_MODEL_AFTER_LOAD__'); + $this->_afterLoad($object); Varien_Profiler::stop('__EAV_LOAD_MODEL_AFTER_LOAD__'); @@ -926,6 +966,43 @@ public function load($object, $entityId, $attributes=array()) return $this; } + /** + * Load model attributes data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Eav_Model_Entity_Abstract + */ + protected function _loadModelAttributes($object) + { + if (!$object->getId()) { + return $this; + } + + Varien_Profiler::start('__EAV_LOAD_MODEL_ATTRIBUTES__'); + + $selects = array(); + foreach (array_keys($this->getAttributesByTable()) as $table) { + $attribute = current($this->_attributesByTable[$table]); + $eavType = $attribute->getBackendType(); + $select = $this->_getLoadAttributesSelect($object, $table); + $selects[$eavType][] = $this->_addLoadAttributesSelectFields($select, $table, $eavType); + } + $selectGroups = Mage::getResourceHelper('eav')->getLoadAttributesSelectGroups($selects); + foreach ($selectGroups as $selects) { + if (!empty($selects)) { + $select = $this->_prepareLoadSelect($selects); + $values = $this->_getReadAdapter()->fetchAll($select); + foreach ($values as $valueRow) { + $this->_setAttributeValue($object, $valueRow); + } + } + } + + Varien_Profiler::stop('__EAV_LOAD_MODEL_ATTRIBUTES__'); + + return $this; + } + /** * Prepare select object for loading entity attributes values * @@ -934,8 +1011,7 @@ public function load($object, $entityId, $attributes=array()) */ protected function _prepareLoadSelect(array $selects) { - $select = $this->_getReadAdapter()->select()->union($selects); - return $select; + return $this->_getReadAdapter()->select()->union($selects, Zend_Db_Select::SQL_UNION_ALL); } /** @@ -949,7 +1025,7 @@ protected function _getLoadRowSelect($object, $rowId) { $select = $this->_getReadAdapter()->select() ->from($this->getEntityTable()) - ->where($this->getEntityIdField()."=?", $rowId); + ->where($this->getEntityIdField() . ' =?', $rowId); return $select; } @@ -964,25 +1040,58 @@ protected function _getLoadRowSelect($object, $rowId) protected function _getLoadAttributesSelect($object, $table) { $select = $this->_getReadAdapter()->select() - ->from($table) - ->where($this->getEntityIdField() . '=?', $object->getId()); + ->from($table, array()) + ->where($this->getEntityIdField() . ' =?', $object->getId()); + + return $select; + } + + /** + * Adds Columns prepared for union + * + * @param Varien_Db_Select $select + * @param string $table + * @param string $type + * @return Varien_Db_Select + */ + protected function _addLoadAttributesSelectFields($select, $table, $type) + { + $select->columns( + Mage::getResourceHelper('eav')->attributeSelectFields($table, $type) + ); return $select; } /** * Initialize attribute value for object * + * @deprecated after 1.5.1.0 - mistake in method name + * * @param Varien_Object $object * @param array $valueRow * @return Mage_Eav_Model_Entity_Abstract */ protected function _setAttribteValue($object, $valueRow) { - if ($attribute = $this->getAttribute($valueRow['attribute_id'])) { + return _setAttributeValue($object, $valueRow); + } + + /** + * Initialize attribute value for object + * + * @param Varien_Object $object + * @param array $valueRow + * @return Mage_Eav_Model_Entity_Abstract + */ + protected function _setAttributeValue($object, $valueRow) + { + $attribute = $this->getAttribute($valueRow['attribute_id']); + if ($attribute) { $attributeCode = $attribute->getAttributeCode(); $object->setData($attributeCode, $valueRow['value']); $attribute->getBackend()->setValueId($valueRow['value_id']); } + return $this; } @@ -1027,6 +1136,7 @@ protected function _getOrigObject($object) $origObject = new $className(); $origObject->setData(array()); $this->load($origObject, $object->getData($this->getEntityIdField())); + return $origObject; } @@ -1116,7 +1226,7 @@ protected function _collectSaveData($newObject) 'attribute_id' => $attrId, 'value_id' => $attribute->getBackend()->getValueId() ); - } else if ($v !== $origData[$k]) { + } elseif ($v !== $origData[$k]) { $update[$attrId] = array( 'value_id' => $attribute->getBackend()->getValueId(), 'value' => $v, @@ -1194,37 +1304,62 @@ protected function _prepareStaticValue($key, $value) protected function _processSaveData($saveData) { extract($saveData); + /** + * Import variables into the current symbol table from save data array + * + * @see Mage_Eav_Model_Entity_Attribute_Abstract::_collectSaveData() + * + * @var array $entityRow + * @var Mage_Core_Model_Abstract $newObject + * @var array $insert + * @var array $update + * @var array $delete + */ + $adapter = $this->_getWriteAdapter(); $insertEntity = true; + $entityTable = $this->getEntityTable(); $entityIdField = $this->getEntityIdField(); $entityId = $newObject->getId(); - $condition = $this->_getWriteAdapter()->quoteInto("$entityIdField=?", $entityId); - if (!empty($entityId)) { - $select = $this->_getWriteAdapter()->select() - ->from($this->getEntityTable(), $entityIdField) - ->where($condition); - if ($this->_getWriteAdapter()->fetchOne($select)) { + unset($entityRow[$entityIdField]); + if (!empty($entityId) && is_numeric($entityId)) { + $bind = array('entity_id' => $entityId); + $select = $adapter->select() + ->from($entityTable, $entityIdField) + ->where("{$entityIdField} = :entity_id"); + $result = $adapter->fetchOne($select, $bind); + if ($result) { $insertEntity = false; } + } else { + $entityId = null; } /** * Process base row */ + $entityObject = new Varien_Object($entityRow); + $entityRow = $this->_prepareDataForTable($entityObject, $entityTable); if ($insertEntity) { - $this->_getWriteAdapter()->insert($this->getEntityTable(), $entityRow); - $entityId = $this->_getWriteAdapter()->lastInsertId(); + if (!empty($entityId)) { + $entityRow[$entityIdField] = $entityId; + $adapter->insertForce($entityTable, $entityRow); + } else { + $adapter->insert($entityTable, $entityRow); + $entityId = $adapter->lastInsertId($entityTable); + } $newObject->setId($entityId); } else { - $this->_getWriteAdapter()->update($this->getEntityTable(), $entityRow, $condition); + $where = sprintf('%s=%d', $adapter->quoteIdentifier($entityIdField), $entityId); + $adapter->update($entityTable, $entityRow, $where); } /** * insert attribute values */ if (!empty($insert)) { - foreach ($insert as $attrId => $value) { - $attribute = $this->getAttribute($attrId); + foreach ($insert as $attributeId => $value) { + $attribute = $this->getAttribute($attributeId); $this->_insertAttribute($newObject, $attribute, $value); } } @@ -1233,8 +1368,8 @@ protected function _processSaveData($saveData) * update attribute values */ if (!empty($update)) { - foreach ($update as $attrId => $v) { - $attribute = $this->getAttribute($attrId); + foreach ($update as $attributeId => $v) { + $attribute = $this->getAttribute($attributeId); $this->_updateAttribute($newObject, $attribute, $v['value_id'], $v['value']); } } @@ -1250,6 +1385,8 @@ protected function _processSaveData($saveData) $this->_processAttributeValues(); + $newObject->isObjectNew(false); + return $this; } @@ -1264,15 +1401,6 @@ protected function _processSaveData($saveData) protected function _insertAttribute($object, $attribute, $value) { return $this->_saveAttribute($object, $attribute, $value); - -// $row = array( -// $entityIdField => $object->getId(), -// 'entity_type_id'=> $object->getEntityTypeId(), -// 'attribute_id' => $attribute->getId(), -// 'value' => $this->_prepareValueForSave($value, $attribute), -// ); -// $this->_getWriteAdapter()->insert($attribute->getBackend()->getTable(), $row); -// return $this; } /** @@ -1287,11 +1415,6 @@ protected function _insertAttribute($object, $attribute, $value) protected function _updateAttribute($object, $attribute, $valueId, $value) { return $this->_saveAttribute($object, $attribute, $value); -// $this->_getWriteAdapter()->update($attribute->getBackend()->getTable(), -// array('value' => $this->_prepareValueForSave($value, $attribute)), -// 'value_id='.(int)$valueId -// ); -// return $this; } /** @@ -1338,7 +1461,7 @@ protected function _processAttributeValues() } foreach ($this->_attributeValuesToDelete as $table => $valueIds) { - $adapter->delete($table, array('value_id IN(?)' => $valueIds)); + $adapter->delete($table, array('value_id IN (?)' => $valueIds)); } // reset data arrays @@ -1360,7 +1483,13 @@ protected function _prepareValueForSave($value, Mage_Eav_Model_Entity_Attribute_ if ($attribute->getBackendType() == 'decimal') { return Mage::app()->getLocale()->getNumber($value); } - return $value; + + $backendTable = $attribute->getBackendTable(); + if (!isset(self::$_attributeBackendTables[$backendTable])) { + self::$_attributeBackendTables[$backendTable] = $this->_getReadAdapter()->describeTable($backendTable); + } + $describe = self::$_attributeBackendTables[$backendTable]; + return $this->_getReadAdapter()->prepareColumnValue($describe['value'], $value); } /** @@ -1389,12 +1518,6 @@ protected function _deleteAttributes($object, $table, $info) } return $this; - -// if (!empty($valueIds)) { -// $condition = $this->_getWriteAdapter()->quoteInto('value_id IN (?)', $valueIds); -// $this->_getWriteAdapter()->delete($table, $condition); -// } -// return $this; } /** @@ -1406,16 +1529,17 @@ protected function _deleteAttributes($object, $table, $info) */ public function saveAttribute(Varien_Object $object, $attributeCode) { - $attribute = $this->getAttribute($attributeCode); - $backend = $attribute->getBackend(); - $table = $backend->getTable(); - $entity = $attribute->getEntity(); - $entityIdField = $entity->getEntityIdField(); + $attribute = $this->getAttribute($attributeCode); + $backend = $attribute->getBackend(); + $table = $backend->getTable(); + $entity = $attribute->getEntity(); + $entityIdField = $entity->getEntityIdField(); + $adapter = $this->_getWriteAdapter(); $row = array( 'entity_type_id' => $entity->getTypeId(), - 'attribute_id' => $attribute->getId(), - $entityIdField=> $object->getData($entityIdField), + 'attribute_id' => $attribute->getId(), + $entityIdField => $object->getData($entityIdField), ); $newValue = $object->getData($attributeCode); @@ -1425,29 +1549,29 @@ public function saveAttribute(Varien_Object $object, $attributeCode) $whereArr = array(); foreach ($row as $field => $value) { - $whereArr[] = $this->_getReadAdapter()->quoteInto("$field=?", $value); + $whereArr[] = $adapter->quoteInto($field . '=?', $value); } - $where = '('.join(') AND (', $whereArr).')'; + $where = implode(' AND ', $whereArr); - $this->_getWriteAdapter()->beginTransaction(); + $adapter->beginTransaction(); try { - $select = $this->_getWriteAdapter()->select() + $select = $adapter->select() ->from($table, 'value_id') ->where($where); - $origValueId = $this->_getWriteAdapter()->fetchOne($select); + $origValueId = $adapter->fetchOne($select); - if ($origValueId === false && !is_null($newValue)) { + if ($origValueId === false && ($newValue !== null)) { $this->_insertAttribute($object, $attribute, $newValue); - } elseif ($origValueId !== false && !is_null($newValue)) { + } elseif ($origValueId !== false && ($newValue !== null)) { $this->_updateAttribute($object, $attribute, $origValueId, $newValue); - } elseif ($origValueId !== false && is_null($newValue)) { - $this->_getWriteAdapter()->delete($table, $where); + } elseif ($origValueId !== false && ($newValue === null)) { + $adapter->delete($table, $where); } $this->_processAttributeValues(); - $this->_getWriteAdapter()->commit(); + $adapter->commit(); } catch (Exception $e) { - $this->_getWriteAdapter()->rollback(); + $adapter->rollback(); throw $e; } @@ -1470,10 +1594,13 @@ public function delete($object) $this->_beforeDelete($object); try { - $this->_getWriteAdapter()->delete($this->getEntityTable(), $this->getEntityIdField()."=".$id); + $where = array( + $this->getEntityIdField() . '=?' => $id + ); + $this->_getWriteAdapter()->delete($this->getEntityTable(), $where); $this->loadAllAttributes($object); - foreach ($this->getAttributesByTable() as $table=>$attributes) { - $this->_getWriteAdapter()->delete($table, $this->getEntityIdField()."=".$id); + foreach ($this->getAttributesByTable() as $table => $attributes) { + $this->_getWriteAdapter()->delete($table, $where); } } catch (Exception $e) { throw $e; @@ -1487,50 +1614,60 @@ public function delete($object) * After Load Entity process * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Abstract */ protected function _afterLoad(Varien_Object $object) { $this->walkAttributes('backend/afterLoad', array($object)); + return $this; } /** * Before delete Entity process * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Abstract */ protected function _beforeSave(Varien_Object $object) { $this->walkAttributes('backend/beforeSave', array($object)); + return $this; } /** * After Save Entity process * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Abstract */ protected function _afterSave(Varien_Object $object) { $this->walkAttributes('backend/afterSave', array($object)); + return $this; } /** * Before Delete Entity process * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Abstract */ protected function _beforeDelete(Varien_Object $object) { $this->walkAttributes('backend/beforeDelete', array($object)); + return $this; } /** * After delete entity process * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Abstract */ protected function _afterDelete(Varien_Object $object) { $this->walkAttributes('backend/afterDelete', array($object)); + return $this; } /** @@ -1571,24 +1708,6 @@ public function getDefaultAttributes() { protected function _afterSetConfig() { return $this; -// Varien_Profiler::start(__METHOD__); -// -// $defaultAttributes = $this->_getDefaultAttributes(); -// $defaultAttributes[] = $this->getEntityIdField(); -// -// $attributes = $this->getAttributesByCode(); -// foreach ($defaultAttributes as $attr) { -// if (empty($attributes[$attr]) && !$this->getAttribute($attr)) { -// $attribute = Mage::getModel($this->getEntityType()->getAttributeModel()); -// $attribute->setAttributeCode($attr) -// ->setBackendType('static') -// ->setEntityType($this->getEntityType()) -// ->setEntityTypeId($this->getEntityType()->getId()); -// $this->addAttribute($attribute); -// } -// } -// Varien_Profiler::stop(__METHOD__); -// return $this; } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 7ade42c8f1..4a20794e70 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -39,7 +39,9 @@ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Ab * * @var string */ - protected $_eventPrefix = 'eav_entity_attribute'; + protected $_eventPrefix = 'eav_entity_attribute'; + + CONST ATTRIBUTE_CODE_MAX_LENGTH = 30; /** * Parameter name in event @@ -53,6 +55,11 @@ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Ab const CACHE_TAG = 'EAV_ATTRIBUTE'; protected $_cacheTag = 'EAV_ATTRIBUTE'; + /** + * Retreive default attribute backend model by attribute code + * + * @return string + */ protected function _getDefaultBackendModel() { switch ($this->getAttributeCode()) { @@ -69,52 +76,80 @@ protected function _getDefaultBackendModel() return 'eav/entity_attribute_backend_increment'; } - - return parent::_getDefaultBackendModel(); } + /** + * Retreive default attribute frontend model + * + * @return string + */ protected function _getDefaultFrontendModel() { return parent::_getDefaultFrontendModel(); } + /** + * Retreive default attribute source model + * + * @return string + */ protected function _getDefaultSourceModel() { - switch ($this->getAttributeCode()) { - case 'store_id': - return 'eav/entity_attribute_source_store'; + if ($this->getAttributeCode() == 'store_id') { + return 'eav/entity_attribute_source_store'; } return parent::_getDefaultSourceModel(); } + /** + * Delete entity + * + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ public function deleteEntity() { return $this->_getResource()->deleteEntity($this); } + /** + * Prepare data for save + * + * @return Mage_Eav_Model_Entity_Attribute + */ protected function _beforeSave() { // prevent overriding product data if (isset($this->_data['attribute_code']) - && Mage::getModel('catalog/product')->isReservedAttribute($this)) { - Mage::throwException(Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code.', $this->_data['attribute_code'])); + && Mage::getModel('catalog/product')->isReservedAttribute($this)) + { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code', $this->_data['attribute_code'])); } - $defaultValue = $this->getDefaultValue(); + /** + * Check for maximum attribute_code length + */ + if(isset($this->_data['attribute_code']) && + !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) + { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)); + } + + $defaultValue = $this->getDefaultValue(); $hasDefaultValue = ((string)$defaultValue != ''); if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => Mage::app()->getLocale()->getLocaleCode()))) { - throw new Exception('Invalid default decimal value.'); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); } + try { $filter = new Zend_Filter_LocalizedToNormalized( array('locale' => Mage::app()->getLocale()->getLocaleCode()) ); $this->setDefaultValue($filter->filter($defaultValue)); } catch (Exception $e) { - throw new Exception('Invalid default decimal value.'); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); } } @@ -134,7 +169,7 @@ protected function _beforeSave() $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue(); $this->setDefaultValue($defaultValue); } catch (Exception $e) { - throw new Exception('Invalid default date.'); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default date')); } } } @@ -148,21 +183,17 @@ protected function _beforeSave() return parent::_beforeSave(); } + /** + * Save additional data + * + * @return Mage_Eav_Model_Entity_Attribute + */ protected function _afterSave() { $this->_getResource()->saveInSetIncluding($this); - return parent::_afterSave(); } - protected function _beforeDelete() - { - if ($this->_getResource()->isUsedBySuperProducts($this)) { - Mage::throwException(Mage::helper('eav')->__('This attribute is used in configurable products.')); - } - return parent::_beforeDelete(); - } - /** * Detect backend storage type using frontend input type * @@ -171,36 +202,35 @@ protected function _beforeDelete() */ public function getBackendTypeByInput($type) { + $field = null; switch ($type) { case 'text': case 'gallery': case 'media_image': case 'multiselect': - return 'varchar'; + $field = 'varchar'; + break; case 'image': case 'textarea': - return 'text'; + $field = 'text'; + break; case 'date': - return 'datetime'; + $field = 'datetime'; + break; case 'select': case 'boolean': - return 'int'; - + $field = 'int'; + break; case 'price': - return 'decimal'; -/* - default: - Mage::dispatchEvent('eav_attribute_get_backend_type_by_input', array('model'=>$this, 'type'=>$type)); - if ($this->hasBackendTypeByInput()) { - return $this->getData('backend_type_by_input'); - } - Mage::throwException('Unknown frontend input type'); -*/ + $field = 'decimal'; + break; } + + return $field; } /** @@ -216,8 +246,10 @@ public function getDefaultValueByInput($type) case 'select': case 'gallery': case 'media_image': + break; case 'multiselect': - return ''; + $field = null; + break; case 'text': case 'price': @@ -236,18 +268,17 @@ public function getDefaultValueByInput($type) case 'boolean': $field = 'default_value_yesno'; break; -/* - default: - Mage::dispatchEvent('eav_attribute_get_default_value_by_input', array('model'=>$this, 'type'=>$type)); - if ($this->hasBackendTypeByInput()) { - return $this->getData('backend_type_by_input'); - } - Mage::throwException('Unknown frontend input type'); -*/ } return $field; } + + /** + * Retreive attribute codes by frontend type + * + * @param string $type + * @return array + */ public function getAttributeCodesByFrontendType($type) { return $this->getResource()->getAttributeCodesByFrontendType($type); @@ -261,7 +292,8 @@ public function getAttributeCodesByFrontendType($type) public function getStoreLabels() { if (!$this->getData('store_labels')) { - $this->setData('store_labels', $this->getResource()->getStoreLabelsByAttributeId($this->getId())); + $storeLabel = $this->getResource()->getStoreLabelsByAttributeId($this->getId()); + $this->setData('store_labels', $storeLabel); } return $this->getData('store_labels'); } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php index 9e9c7ced91..c5685d8c4f 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -77,14 +77,14 @@ abstract class Mage_Eav_Model_Entity_Attribute_Abstract extends Mage_Core_Model_ * * @var array */ - protected $_attributeIdCache = array(); + protected $_attributeIdCache = array(); /** * Attribute data table name * * @var string */ - protected $_dataTable = null; + protected $_dataTable = null; /** * Initialize resource model @@ -263,13 +263,14 @@ public function getIsGlobal() * @param Mage_Eav_Model_Entity_Abstract $entity exclude this entity * @return string */ - public function getAlias($entity=null) + public function getAlias($entity = null) { $alias = ''; - if (is_null($entity) || ($entity->getType() !== $this->getEntity()->getType())) { + if (($entity === null) || ($entity->getType() !== $this->getEntity()->getType())) { $alias .= $this->getEntity()->getType() . '/'; } $alias .= $this->getAttributeCode(); + return $alias; } @@ -284,11 +285,13 @@ public function setName($name) return $this->setData('attribute_code', $name); } + /** + * Retreive entity type + * + * @return string + */ public function getEntityType() { - /*if ($this->hasData('entity_type')) { - return $this->_getData('entity_type'); - }*/ return Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeId()); } @@ -317,6 +320,11 @@ public function getEntity() return $this->_entity; } + /** + * Retreive entity type + * + * @return string + */ public function getEntityIdField() { return $this->getEntity()->getValueEntityIdField(); @@ -335,10 +343,11 @@ public function getBackend() } $backend = Mage::getModel($this->getBackendModel()); if (!$backend) { - throw Mage::exception('Mage_Eav', 'Invalid backend model specified: '.$this->getBackendModel()); + throw Mage::exception('Mage_Eav', 'Invalid backend model specified: ' . $this->getBackendModel()); } $this->_backend = $backend->setAttribute($this); } + return $this->_backend; } @@ -356,6 +365,7 @@ public function getFrontend() $this->_frontend = Mage::getModel($this->getFrontendModel()) ->setAttribute($this); } + return $this->_frontend; } @@ -372,9 +382,9 @@ public function getSource() } $source = Mage::getModel($this->getSourceModel()); if (!$source) { - throw new Exception(sprintf('Source model "%s" not found for attribute "%s".', - $this->getSourceModel(), $this->getAttributeCode() - )); + throw Mage::exception('Mage_Eav', + Mage::helper('eav')->__('Source model "%s" not found for attribute "%s"',$this->getSourceModel(), $this->getAttributeCode()) + ); } $this->_source = $source->setAttribute($this); } @@ -406,9 +416,10 @@ public function isValueEmpty($value) { $attrType = $this->getBackend()->getType(); $isEmpty = is_array($value) - || is_null($value) - || $value===false && $attrType!='int' - || $value==='' && ($attrType=='int' || $attrType=='decimal' || $attrType=='datetime'); + || ($value === null) + || $value === false && $attrType != 'int' + || $value === '' && ($attrType == 'int' || $attrType == 'decimal' || $attrType == 'datetime'); + return $isEmpty; } @@ -446,7 +457,8 @@ public function isInSet($setId) */ public function isInGroup($setId, $groupId) { - if ($this->isInSet($setId) && $this->getData('attribute_set_info/' . $setId . '/group_id') == $groupId) { + $dataPath = sprintf('attribute_set_info/%s/group_id', $setId); + if ($this->isInSet($setId) && $this->getData($dataPath) == $groupId) { return true; } @@ -489,25 +501,45 @@ public function getBackendTable() if ($this->_dataTable === null) { if ($this->isStatic()) { $this->_dataTable = $this->getEntityType()->getValueTablePrefix(); - } elseif ($backendTable = trim($this->_getData('backend_table'))) { - $this->_dataTable = $backendTable; } else { - $this->_dataTable = $this->getEntity()->getValueTablePrefix().'_'.$this->getBackendType(); + $backendTable = trim($this->_getData('backend_table')); + if (empty($backendTable)) { + $entityTable = array($this->getEntity()->getEntityTablePrefix(), $this->getBackendType()); + $backendTable = $this->getResource()->getTable($entityTable); + } + $this->_dataTable = $backendTable; } } return $this->_dataTable; } /** - * Retrieve Flat Column(s) + * Retrieve Flat Column(s) DDL definition * * @return array */ - public function getFlatColumns() { - if ($this->usesSource() && $this->getBackendType() != 'static') { - return $this->getSource()->getFlatColums(); + public function getFlatColumns() + { + // If source model exists - get definition from it + if ($this->usesSource() && $this->getBackendType() != self::TYPE_STATIC) { + $columns = $this->getSource()->getFlatColums(); + /** + * In MMDB flat columns are returned in DDL format. But non-updated extensions may still return them in + * older not-so-strict format. We detect such case and reformat result. + */ + if ($columns) { + $testColumn = current($columns); + if (array_key_exists('is_null', $testColumn)) { + foreach ($columns as $key => $column) { + $columns[$key] = $this->_convertOldColumn2New($column); + } + } + return $columns; + } } + // Generate column definition by common rules + $helper = Mage::getResourceHelper('eav'); $columns = array(); switch ($this->getBackendType()) { case 'static': @@ -517,63 +549,89 @@ public function getFlatColumns() { break; } $prop = $describe[$this->getAttributeCode()]; + $type = $prop['DATA_TYPE']; + $size = ($prop['LENGTH'] ? $prop['LENGTH'] : null); + $columns[$this->getAttributeCode()] = array( - 'type' => $prop['DATA_TYPE'] . ($prop['LENGTH'] ? "({$prop['LENGTH']})" : ""), + 'type' => $helper->getDdlTypeByColumnType($type), + 'length' => $size, 'unsigned' => $prop['UNSIGNED'] ? true: false, - 'is_null' => $prop['NULLABLE'], + 'nullable' => $prop['NULLABLE'], 'default' => $prop['DEFAULT'], 'extra' => null ); break; case 'datetime': $columns[$this->getAttributeCode()] = array( - 'type' => 'datetime', + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, 'extra' => null ); break; case 'decimal': $columns[$this->getAttributeCode()] = array( - 'type' => 'decimal(12,4)', + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'length' => '12,4', 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, 'extra' => null ); break; case 'int': $columns[$this->getAttributeCode()] = array( - 'type' => 'int', + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, 'extra' => null ); break; case 'text': $columns[$this->getAttributeCode()] = array( - 'type' => 'text', + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'length' => Varien_Db_Ddl_Table::MAX_TEXT_SIZE ); break; case 'varchar': $columns[$this->getAttributeCode()] = array( - 'type' => 'varchar(255)', + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '255', 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, 'extra' => null ); break; } + return $columns; } + /** + * Convert older format of flat columns to new MMDB format that uses DDL types and definitions. + * + * @param array $column + * @return array + */ + protected function _convertOldColumn2New($column) + { + $result = Mage::getResourceHelper('eav') + ->convertOldColumnType2Ddl($column['type']); + $result['unsigned'] = $column['unsigned']; + $result['nullable'] = $column['is_null']; + $result['default'] = $column['default']; + $result['identity'] = stripos($column['extra'], 'auto_increment') !== false; + + return $result; + } + /** * Retrieve index data for Flat table * @@ -587,7 +645,7 @@ public function getFlatIndexes() } if ($condition) { - if ($this->usesSource() && $this->getBackendType() != 'static') { + if ($this->usesSource() && $this->getBackendType() != self::TYPE_STATIC) { return $this->getSource()->getFlatIndexes(); } $indexes = array(); @@ -645,6 +703,7 @@ public function getFlatIndexes() return $indexes; } + return array(); } @@ -655,14 +714,14 @@ public function getFlatIndexes() * @return Varien_Db_Select */ public function getFlatUpdateSelect($store = null) { - if (is_null($store)) { + if ($store === null) { foreach (Mage::app()->getStores() as $store) { $this->getFlatUpdateSelect($store->getId()); } return $this; } - if ($this->getBackendType() == 'static') { + if ($this->getBackendType() == self::TYPE_STATIC) { return null; } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php index 972545aca8..ffd89913a8 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -125,8 +125,8 @@ public function getTable() $this->_table = $this->getAttribute()->getBackendTable(); } else { $entity = $this->getAttribute()->getEntity(); - $this->_table = $entity->getValueTablePrefix() - .'_'.$this->getType(); + $tableName = sprintf('%s_%s', $entity->getValueTablePrefix(), $this->getType()); + $this->_table = $tableName; } } @@ -147,32 +147,57 @@ public function getEntityIdField() $this->_entityIdField = $this->getAttribute()->getEntityType()->getValueEntityIdField(); } } + return $this->_entityIdField; } + /** + * Set value id + * + * @param int $valueId + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function setValueId($valueId) { $this->_valueId = $valueId; return $this; } + /** + * Retreive value id + * + * @return int + */ public function getValueId() { return $this->_valueId; } + /** + * Retreive default value + * + * @return mixed + */ public function getDefaultValue() { - if (is_null($this->_defaultValue)) { + if ($this->_defaultValue === null) { if ($this->getAttribute()->getDefaultValue()) { $this->_defaultValue = $this->getAttribute()->getDefaultValue(); } else { $this->_defaultValue = ""; } } + return $this->_defaultValue; } + /** + * Validate object + * + * @param Varien_Object $object + * @throws Mage_Eav_Exception + * @return boolean + */ public function validate($object) { $attrCode = $this->getAttribute()->getAttributeCode(); @@ -181,44 +206,81 @@ public function validate($object) return false; } - if ($this->getAttribute()->getIsUnique() && !$this->getAttribute()->getIsRequired() && ($value == '' || $this->getAttribute()->isValueEmpty($value))) { + if ($this->getAttribute()->getIsUnique() + && !$this->getAttribute()->getIsRequired() + && ($value == '' || $this->getAttribute()->isValueEmpty($value))) + { return true; } if ($this->getAttribute()->getIsUnique()) { if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { $label = $this->getAttribute()->getFrontend()->getLabel(); - Mage::throwException(Mage::helper('eav')->__('The value of attribute "%s" must be unique.', $label)); + throw Mage::exception('Mage_Eav', + Mage::helper('eav')->__('The value of attribute "%s" must be unique', $label) + ); } } + return true; } + /** + * After load method + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function afterLoad($object) { - + return $this; } + /** + * Before save method + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function beforeSave($object) { $attrCode = $this->getAttribute()->getAttributeCode(); if (!$object->hasData($attrCode) && $this->getDefaultValue()) { $object->setData($attrCode, $this->getDefaultValue()); } + + return $this; } + /** + * After save method + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function afterSave($object) { - + return $this; } + /** + * Before delete method + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function beforeDelete($object) { - + return $this; } - + /** + * After delete method + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function afterDelete($object) { - + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Array.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Array.php index 25066c883c..849b6ff0b1 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Array.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Array.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,10 +33,22 @@ */ class Mage_Eav_Model_Entity_Attribute_Backend_Array extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { + /** + * Prepare data for save + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ public function beforeSave($object) { $data = $object->getData($this->getAttribute()->getAttributeCode()); if (is_array($data)) { + foreach ($data as $key => $value) { + if ($value === '') { + unset($data[$key]); + } + } + $object->setData($this->getAttribute()->getAttributeCode(), implode(',', $data)); } return parent::beforeSave($object); diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php index 3f23f2771b..9928af04b8 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -20,29 +20,31 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Eav_Model_Entity_Attribute_Backend_Datetime extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { /** - * Formating date value before save to DB + * Formating date value before save * - * should set (bool, string) correct type for empty value from html form, + * Should set (bool, string) correct type for empty value from html form, * neccessary for farther proccess, else date string * - * @param mixed $object + * @param Varien_Object $object + * @throws Mage_Eav_Exception + * @return Mage_Eav_Model_Entity_Attribute_Backend_Datetime */ public function beforeSave($object) { $attributeName = $this->getAttribute()->getName(); - $_formated = $object->getData($attributeName . '_is_formated'); + $_formated = $object->getData($attributeName . '_is_formated'); if (!$_formated && $object->hasData($attributeName)) { try { $value = $this->formatDate($object->getData($attributeName)); } catch (Exception $e) { - throw new Exception("Invalid date."); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid date')); } if (is_null($value)) { @@ -52,6 +54,8 @@ public function beforeSave($object) $object->setData($attributeName, $value); $object->setData($attributeName . '_is_formated', true); } + + return $this; } /** @@ -86,5 +90,4 @@ public function formatDate($date) } return $date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); } - } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Default.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Default.php index e0e66616e6..c883557e7a 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Default.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Increment.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Increment.php index 6a5080d20c..fe792813c4 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Increment.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Increment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,10 +33,18 @@ */ class Mage_Eav_Model_Entity_Attribute_Backend_Increment extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { + /** + * Set new increment id + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Increment + */ public function beforeSave($object) { if (!$object->getId()) { $this->getAttribute()->getEntity()->setNewIncrementId($object); } + + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Interface.php index 9fd9405785..32f2863c18 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Serialized.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Serialized.php index 352f5d63ac..2d8474cfb3 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Serialized.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Serialized.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,9 @@ class Mage_Eav_Model_Entity_Attribute_Backend_Serialized extends Mage_Eav_Model_ { /** * Serialize before saving + * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized */ public function beforeSave($object) { @@ -40,31 +42,41 @@ public function beforeSave($object) if ($object->hasData($attrCode)) { $object->setData($attrCode, serialize($object->getData($attrCode))); } + + return $this; } /** * Unserialize after saving + * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized */ public function afterSave($object) { parent::afterSave($object); $this->_unserialize($object); + return $this; } /** * Unserialize after loading + * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized */ public function afterLoad($object) { parent::afterLoad($object); $this->_unserialize($object); + return $this; } /** * Try to unserialize the attribute value + * * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized */ protected function _unserialize(Varien_Object $object) { @@ -77,5 +89,7 @@ protected function _unserialize(Varien_Object $object) $object->unsetData($attrCode); } } + + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Store.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Store.php index 794ab9184b..7cc60a8750 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Store.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Store.php @@ -20,17 +20,25 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Eav_Model_Entity_Attribute_Backend_Store extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { + /** + * Prepare data before save + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Store + */ protected function _beforeSave($object) { if (!$object->getData($this->getAttribute()->getAttributeCode())) { $object->setData($this->getAttribute()->getAttributeCode(), Mage::app()->getStore()->getId()); } + + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php index 1c790cde78..e960ce23dc 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,10 +33,19 @@ */ class Mage_Eav_Model_Entity_Attribute_Backend_Time_Created extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { + /** + * Set created date + * + * @param Mage_Core_Model_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Created + */ public function beforeSave($object) { - if (!$object->getId() && is_null($object->getData($this->getAttribute()->getAttributeCode()))) { - $object->setData($this->getAttribute()->getAttributeCode(), now()); + $attributeCode = $this->getAttribute()->getAttributeCode(); + if ($object->isObjectNew() && is_null($object->getData($attributeCode))) { + $object->setData($attributeCode, Varien_Date::now()); } + + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php index b6b3121dee..3233ff8322 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Updated.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,8 +33,15 @@ */ class Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { + /** + * Set modified date + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated + */ public function beforeSave($object) { - $object->setData($this->getAttribute()->getAttributeCode(), now()); + $object->setData($this->getAttribute()->getAttributeCode(), Varien_Date::now()); + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Exception.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Exception.php index 320084c558..1c7dc0dde9 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Exception.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php index 5d538cec13..e5e93ffac5 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -75,27 +75,35 @@ public function getInputType() } /** - * Enter description here... + * Retreive lable * * @return string */ public function getLabel() { $label = $this->getAttribute()->getFrontendLabel(); - if (is_null($label) || $label=='') { + if (($label === null) || $label == '') { $label = $this->getAttribute()->getAttributeCode(); } + return $label; } + /** + * Retreive attribute value + * + * @param $object + * @return mixed + */ public function getValue(Varien_Object $object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); if (in_array($this->getConfigField('input'), array('select','boolean'))) { $valueOption = $this->getOption($value); if (!$valueOption) { - $opt = new Mage_Eav_Model_Entity_Attribute_Source_Boolean(); - if ($options = $opt->getAllOptions()) { + $opt = Mage::getModel('eav/entity_attribute_source_boolean'); + $options = $opt->getAllOptions(); + if ($options) { foreach ($options as $option) { if ($option['value'] == $value) { $valueOption = $option['label']; @@ -104,21 +112,31 @@ public function getValue(Varien_Object $object) } } $value = $valueOption; - } - elseif ($this->getConfigField('input')=='multiselect') { + } elseif ($this->getConfigField('input') == 'multiselect') { $value = $this->getOption($value); if (is_array($value)) { $value = implode(', ', $value); } } + return $value; } + /** + * Checks if attribute is visible on frontend + * + * @return boolean + */ public function isVisible() { return $this->getConfigField('frontend_visible'); } + /** + * Retreive frontend class + * + * @return string + */ public function getClass() { $out = $this->getAttribute()->getFrontendClass(); @@ -128,9 +146,15 @@ public function getClass() return $out; } + /** + * Reireive config field + * + * @param string $fieldName + * @return mixed + */ public function getConfigField($fieldName) { - return $this->getAttribute()->getData('frontend_'.$fieldName); + return $this->getAttribute()->getData('frontend_' . $fieldName); } /** @@ -143,9 +167,16 @@ public function getSelectOptions() return $this->getAttribute()->getSource()->getAllOptions(); } + /** + * Retreive option by option id + * + * @param int $optionId + * @return mixed|boolean + */ public function getOption($optionId) { - if ($source = $this->getAttribute()->getSource()) { + $source = $this->getAttribute()->getSource(); + if ($source) { return $source->getOptionText($optionId); } return false; @@ -157,10 +188,10 @@ public function getOption($optionId) * @return string */ public function getInputRendererClass() { - if ($className = $this->getAttribute()->getData('frontend_input_renderer')) { + $className = $this->getAttribute()->getData('frontend_input_renderer'); + if ($className) { return Mage::getConfig()->getBlockClassName($className); } return null; } - } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Datetime.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Datetime.php index 9088199b48..3adc4a5943 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Datetime.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Datetime.php @@ -20,13 +20,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Eav_Model_Entity_Attribute_Frontend_Datetime extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract { + /** + * Retreive attribute value + * + * @param $object + * @return mixed + */ public function getValue(Varien_Object $object) { $data = ''; diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Default.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Default.php index 6e2e1b372f..5d07cf217b 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Default.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Interface.php index c86be29745..28a6507934 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Group.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Group.php index 5c7487f11c..46b630baa5 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Group.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Group.php @@ -20,13 +20,34 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Eav_Model_Resource_Entity_Attribute_Group _getResource() + * @method Mage_Eav_Model_Resource_Entity_Attribute_Group getResource() + * @method int getAttributeSetId() + * @method Mage_Eav_Model_Entity_Attribute_Group setAttributeSetId(int $value) + * @method string getAttributeGroupName() + * @method Mage_Eav_Model_Entity_Attribute_Group setAttributeGroupName(string $value) + * @method int getSortOrder() + * @method Mage_Eav_Model_Entity_Attribute_Group setSortOrder(int $value) + * @method int getDefaultId() + * @method Mage_Eav_Model_Entity_Attribute_Group setDefaultId(int $value) + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ class Mage_Eav_Model_Entity_Attribute_Group extends Mage_Core_Model_Abstract { + /** + * Resource initialization + */ protected function _construct() { $this->_init('eav/entity_attribute_group'); @@ -42,6 +63,11 @@ public function itemExists() return $this->_getResource()->itemExists($this); } + /** + * Delete groups + * + * @return Mage_Eav_Model_Entity_Attribute_Group + */ public function deleteGroups() { return $this->_getResource()->deleteGroups($this); diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Interface.php index 98be883193..e855040aa4 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Interface.php @@ -20,12 +20,11 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ interface Mage_Eav_Model_Entity_Attribute_Interface { - } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Option.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Option.php index c5c2e64a75..af1513eef1 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Option.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Option.php @@ -20,19 +20,29 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Emtity attribute option model * - * @category Mage - * @package Mage_Eav + * @method Mage_Eav_Model_Resource_Entity_Attribute_Option _getResource() + * @method Mage_Eav_Model_Resource_Entity_Attribute_Option getResource() + * @method int getAttributeId() + * @method Mage_Eav_Model_Entity_Attribute_Option setAttributeId(int $value) + * @method int getSortOrder() + * @method Mage_Eav_Model_Entity_Attribute_Option setSortOrder(int $value) + * + * @category Mage + * @package Mage_Eav * @author Magento Core Team */ class Mage_Eav_Model_Entity_Attribute_Option extends Mage_Core_Model_Abstract { + /** + * Resource initialization + */ public function _construct() { $this->_init('eav/entity_attribute_option'); diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Set.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Set.php index 98234567f8..a428dbafbd 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Set.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Eav attribute set model * - * @category Mage - * @package Mage_Eav - * @author Magento Core Team + * @method Mage_Eav_Model_Resource_Entity_Attribute_Set _getResource() + * @method Mage_Eav_Model_Resource_Entity_Attribute_Set getResource() + * @method int getEntityTypeId() + * @method Mage_Eav_Model_Entity_Attribute_Set setEntityTypeId(int $value) + * @method string getAttributeSetName() + * @method Mage_Eav_Model_Entity_Attribute_Set setAttributeSetName(string $value) + * @method int getSortOrder() + * @method Mage_Eav_Model_Entity_Attribute_Set setSortOrder(int $value) + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team */ class Mage_Eav_Model_Entity_Attribute_Set extends Mage_Core_Model_Abstract { @@ -57,7 +66,7 @@ public function initFromSkeleton($skeletonId) ->load(); $newGroups = array(); - foreach( $groups as $group ) { + foreach ($groups as $group) { $newGroup = clone $group; $newGroup->setId(null) ->setAttributeSetId($this->getId()) @@ -69,7 +78,7 @@ public function initFromSkeleton($skeletonId) ->load(); $newAttributes = array(); - foreach( $groupAttributesCollection as $attribute ) { + foreach ($groupAttributesCollection as $attribute) { $newAttribute = Mage::getModel('eav/entity_attribute') ->setId($attribute->getId()) //->setAttributeGroupId($newGroup->getId()) @@ -82,6 +91,7 @@ public function initFromSkeleton($skeletonId) $newGroups[] = $newGroup; } $this->setGroups($newGroups); + return $this; } @@ -89,6 +99,7 @@ public function initFromSkeleton($skeletonId) * Collect data for save * * @param array $data + * @return Mage_Eav_Model_Entity_Attribute_Set */ public function organizeData($data) { @@ -104,7 +115,7 @@ public function organizeData($data) ->getValidAttributeIds($ids); } if( $data['groups'] ) { - foreach( $data['groups'] as $group ) { + foreach ($data['groups'] as $group) { $modelGroup = Mage::getModel('eav/entity_attribute_group'); $modelGroup->setId(is_numeric($group[0]) && $group[0] > 0 ? $group[0] : null) ->setAttributeGroupName($group[1]) @@ -155,22 +166,25 @@ public function organizeData($data) } $this->setAttributeSetName($data['attribute_set_name']) ->setEntityTypeId($this->getEntityTypeId()); + + return $this; } /** * Validate attribute set name * * @param string $name - * @throws Mage_Core_Exception + * @throws Mage_Eav_Exception * @return bool */ public function validate() { if (!$this->_getResource()->validate($this, $this->getAttributeSetName())) { - Mage::throwException( + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attribute set with the "%s" name already exists.', $this->getAttributeSetName()) ); } + return true; } @@ -219,8 +233,7 @@ public function addSetInfo($entityType, array $attributes, $setId = null) $attributeSetInfo[$setId] = $setInfo[$attribute->getAttributeId()][$setId]; } $attribute->setAttributeSetInfo($attributeSetInfo); - } - else { + } else { if (isset($setInfo[$attribute->getAttributeId()])) { $attribute->setAttributeSetInfo($setInfo[$attribute->getAttributeId()]); } @@ -242,7 +255,7 @@ public function addSetInfo($entityType, array $attributes, $setId = null) */ public function getDefaultGroupId($setId = null) { - if (is_null($setId)) { + if ($setId === null) { $setId = $this->getId(); } if ($setId) { diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Abstract.php index 814c42e743..795c5b2e5c 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -46,7 +46,7 @@ abstract class Mage_Eav_Model_Entity_Attribute_Source_Abstract implements Mage_E * * @var array */ - protected $_options; + protected $_options = null; /** * Set attribute instance @@ -108,7 +108,7 @@ public function getOptionId($value) * @param string $dir direction * @return Mage_Eav_Model_Entity_Attribute_Source_Abstract */ - public function addValueSortToCollection($collection, $dir = 'asc') { + public function addValueSortToCollection($collection, $dir = Varien_Data_Collection::SORT_ORDER_DESC) { return $this; } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Boolean.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Boolean.php index 22cbdd0a7a..44344df0ab 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Boolean.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Boolean.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -89,11 +89,13 @@ public function getFlatColums() { $columns = array(); $columns[$this->getAttribute()->getAttributeCode()] = array( - 'type' => 'tinyint(1)', + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'length' => 1, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => $this->getAttribute()->getAttributeCode() . ' column' ); return $columns; diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Config.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Config.php index 54914e6d27..a9613dc65c 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Config.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -36,23 +36,29 @@ */ class Mage_Eav_Model_Entity_Attribute_Source_Config extends Mage_Eav_Model_Entity_Attribute_Source_Abstract { + /** + * Config Node Path + * + * @var Mage_Core_Model_Config_Element + */ protected $_configNodePath; /** * Retrieve all options for the source from configuration * + * @throws Mage_Eav_Exception * @return array */ public function getAllOptions() { - if (is_null($this->_options)) { + if ($this->_options === null) { $this->_options = array(); $rootNode = null; if ($this->_configNodePath) { $rootNode = Mage::getConfig()->getNode($this->_configNodePath); } if (!$rootNode) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Failed to load node %s from config.', $this->_configNodePath)); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Failed to load node %s from config', $this->_configNodePath)); } $options = $rootNode->children(); if (empty($options)) { diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Interface.php index 94f8ffcacf..26a648fdde 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Store.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Store.php index a3f8f89cab..1bf10023e8 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Store.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,9 +33,14 @@ */ class Mage_Eav_Model_Entity_Attribute_Source_Store extends Mage_Eav_Model_Entity_Attribute_Source_Table { + /** + * Retrieve Full Option values array + * + * @return array + */ public function getAllOptions() { - if (is_null($this->_options)) { + if ($this->_options === null) { $this->_options = Mage::getResourceModel('core/store_collection')->load()->toOptionArray(); } return $this->_options; diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Table.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Table.php index de7e3677d1..e330e99c87 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Table.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Table.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -61,8 +61,9 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) } $options = ($defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId]); if ($withEmpty) { - array_unshift($options, array('label'=>'', 'value'=>'')); + array_unshift($options, array('label' => '', 'value' => '')); } + return $options; } @@ -91,14 +92,13 @@ public function getOptionText($value) } return $values; } - else { - foreach ($options as $item) { - if ($item['value'] == $value) { - return $item['label']; - } + + foreach ($options as $item) { + if ($item['value'] == $value) { + return $item['label']; } - return false; } + return false; } /** @@ -109,39 +109,32 @@ public function getOptionText($value) * * @return Mage_Eav_Model_Entity_Attribute_Source_Table */ - public function addValueSortToCollection($collection, $dir = 'asc') + public function addValueSortToCollection($collection, $dir = Varien_Db_Select::SQL_ASC) { - $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; - $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; - $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; - - $collection->getSelect()->joinLeft( - array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), - "`e`.`entity_id`=`{$valueTable1}`.`entity_id`" - . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'" - . " AND `{$valueTable1}`.`store_id`='{$adminStore}'", - array() - ); - - if ($collection->getStoreId() != $adminStore) { - $collection->getSelect()->joinLeft( + $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1'; + $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2'; + $collection->getSelect() + ->joinLeft( + array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), + "e.entity_id={$valueTable1}.entity_id" + . " AND {$valueTable1}.attribute_id='{$this->getAttribute()->getId()}'" + . " AND {$valueTable1}.store_id=0", + array()) + ->joinLeft( array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), - "`e`.`entity_id`=`{$valueTable2}`.`entity_id`" - . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'" - . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'", + "e.entity_id={$valueTable2}.entity_id" + . " AND {$valueTable2}.attribute_id='{$this->getAttribute()->getId()}'" + . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'", array() ); - $valueExpr = new Zend_Db_Expr("IF(`{$valueTable2}`.`value_id`>0, `{$valueTable2}`.`value`, `{$valueTable1}`.`value`)"); - - } else { - $valueExpr = new Zend_Db_Expr("`{$valueTable1}`.`value`"); - } + $valueExpr = $collection->getSelect()->getAdapter() + ->getCheckSql("{$valueTable2}.value_id > 0", "{$valueTable2}.value", "{$valueTable1}.value"); Mage::getResourceModel('eav/entity_attribute_option') ->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr); $collection->getSelect() - ->order("{$this->getAttribute()->getAttributeCode()}_value {$dir}"); + ->order("{$this->getAttribute()->getAttributeCode()} {$dir}"); return $this; } @@ -155,21 +148,31 @@ public function getFlatColums() { $columns = array(); $isMulti = $this->getAttribute()->getFrontend()->getInputType() == 'multiselect'; + if ($isMulti) { + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + } else { + $type = Varien_Db_Ddl_Table::TYPE_INTEGER; + } + $columns[$this->getAttribute()->getAttributeCode()] = array( - 'type' => $isMulti ? 'varchar(255)' : 'int', + 'type' => $type, + 'length' => $isMulti ? '255' : null, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => $this->getAttribute()->getAttributeCode() . ' column' ); if (!$isMulti) { $columns[$this->getAttribute()->getAttributeCode() . '_value'] = array( - 'type' => 'varchar(255)', + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => $this->getAttribute()->getAttributeCode() . ' column' ); } @@ -185,15 +188,16 @@ public function getFlatIndexes() { $indexes = array(); - $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode()); + $index = sprintf('IDX_%s', strtoupper($this->getAttribute()->getAttributeCode())); $indexes[$index] = array( 'type' => 'index', 'fields' => array($this->getAttribute()->getAttributeCode()) ); $sortable = $this->getAttribute()->getUsedForSortBy(); - if ($sortable and $this->getAttribute()->getFrontend()->getInputType() != 'multiselect') { - $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode()) . '_VALUE'; + if ($sortable && $this->getAttribute()->getFrontend()->getInputType() != 'multiselect') { + $index = sprintf('IDX_%s_VALUE', strtoupper($this->getAttribute()->getAttributeCode())); + $indexes[$index] = array( 'type' => 'index', 'fields' => array($this->getAttribute()->getAttributeCode() . '_value') @@ -206,7 +210,6 @@ public function getFlatIndexes() /** * Retrieve Select For Flat Attribute update * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param int $store * @return Varien_Db_Select|null */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Collection.php b/app/code/core/Mage/Eav/Model/Entity/Collection.php index 87134fc7d0..adaa14348b 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Collection.php +++ b/app/code/core/Mage/Eav/Model/Entity/Collection.php @@ -20,18 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - class Mage_Eav_Model_Entity_Collection extends Mage_Eav_Model_Entity_Collection_Abstract { + /** + * Initialize resource + */ public function __construct() { $resources = Mage::getSingleton('core/resource'); - parent::__construct($resources->getConnection('customeralert_type')); - - #$this->setConnection(Mage::getSingleton('core/resource')->getConnection('core_read')); + parent::__construct($resources->getConnection('eav_setup')); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php index 85d88071cf..4878f6329c 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -38,14 +38,14 @@ abstract class Mage_Eav_Model_Entity_Collection_Abstract extends Varien_Data_Col * * @var array */ - protected $_itemsById = array(); + protected $_itemsById = array(); /** * Entity static fields * * @var array */ - protected $_staticFields = array(); + protected $_staticFields = array(); /** * Entity object to define collection's attributes @@ -59,49 +59,57 @@ abstract class Mage_Eav_Model_Entity_Collection_Abstract extends Varien_Data_Col * * @var array */ - protected $_selectEntityTypes = array(); + protected $_selectEntityTypes = array(); /** * Attributes to be fetched for objects in collection * * @var array */ - protected $_selectAttributes=array(); + protected $_selectAttributes = array(); /** * Attributes to be filtered order sorted by * * @var array */ - protected $_filterAttributes=array(); + protected $_filterAttributes = array(); /** * Joined entities * * @var array */ - protected $_joinEntities = array(); + protected $_joinEntities = array(); /** * Joined attributes * * @var array */ - protected $_joinAttributes = array(); + protected $_joinAttributes = array(); /** * Joined fields data * * @var array */ - protected $_joinFields = array(); + protected $_joinFields = array(); + + /** + * Use analytic function flag + * If true - allows to prepare final select with analytic functions + * + * @var bool + */ + protected $_useAnalyticFunction = false; /** * Collection constructor * - * @param Mage_Core_Model_Mysql4_Abstract $resource + * @param Mage_Core_Model_Resource_Abstract $resource */ - public function __construct($resource=null) + public function __construct($resource = null) { parent::__construct(); $this->_construct(); @@ -118,6 +126,12 @@ protected function _construct() } + /** + * Retreive table name + * + * @param string $table + * @return string + */ public function getTable($table) { return $this->getResource()->getTable($table); @@ -136,9 +150,14 @@ protected function _prepareStaticFields() return $this; } + /** + * Init select + * + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ protected function _initSelect() { - $this->getSelect()->from(array('e'=>$this->getEntity()->getEntityTable())); + $this->getSelect()->from(array('e' => $this->getEntity()->getEntityTable())); if ($this->getEntity()->getTypeId()) { $this->addAttributeToFilter('entity_type_id', $this->getEntity()->getTypeId()); } @@ -151,14 +170,15 @@ protected function _initSelect() * @param string $model * @return Mage_Core_Model_Mysql4_Collection_Abstract */ - protected function _init($model, $entityModel=null) + protected function _init($model, $entityModel = null) { $this->setItemObjectClass(Mage::getConfig()->getModelClassName($model)); - if (is_null($entityModel)) { + if ($entityModel === null) { $entityModel = $model; } $entity = Mage::getResourceSingleton($entityModel); $this->setEntity($entity); + return $this; } @@ -166,6 +186,7 @@ protected function _init($model, $entityModel=null) * Set entity to use for attributes * * @param Mage_Eav_Model_Entity_Abstract $entity + * @throws Mage_Eav_Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function setEntity($entity) @@ -175,7 +196,7 @@ public function setEntity($entity) } elseif (is_string($entity) || $entity instanceof Mage_Core_Model_Config_Element) { $this->_entity = Mage::getModel('eav/entity')->setType($entity); } else { - Mage::throwException(Mage::helper('eav')->__('Invalid entity supplied: %s.', print_r($entity,1))); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid entity supplied: %s', print_r($entity, 1))); } return $this; } @@ -188,7 +209,7 @@ public function setEntity($entity) public function getEntity() { if (empty($this->_entity)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Entity is not initialized.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Entity is not initialized')); } return $this->_entity; } @@ -213,8 +234,7 @@ public function setObject($object=null) { if (is_object($object)) { $this->setItemObjectClass(get_class($object)); - } - else { + } else { $this->setItemObjectClass($object); } @@ -230,8 +250,8 @@ public function setObject($object=null) */ public function addItem(Varien_Object $object) { - if (get_class($object)!== $this->_itemObjectClass) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attempt to add an invalid object.')); + if (get_class($object) !== $this->_itemObjectClass) { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attempt to add an invalid object')); } return parent::addItem($object); } @@ -246,9 +266,9 @@ public function getAttribute($attributeCode) { if (isset($this->_joinAttributes[$attributeCode])) { return $this->_joinAttributes[$attributeCode]['attribute']; - } else { - return $this->getEntity()->getAttribute($attributeCode); } + + return $this->getEntity()->getAttribute($attributeCode); } /** @@ -266,9 +286,9 @@ public function getAttribute($attributeCode) * @param string $operator * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function addAttributeToFilter($attribute, $condition=null, $joinType='inner') + public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner') { - if ($attribute===null) { + if ($attribute === null) { $this->getSelect(); return $this; } @@ -284,9 +304,9 @@ public function addAttributeToFilter($attribute, $condition=null, $joinType='inn foreach ($attribute as $condition) { $sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType); } - $conditionSql = '('.join(') OR (', $sqlArr).')'; - } elseif (is_string($attribute)) { - if (is_null($condition)) { + $conditionSql = '('.implode(') OR (', $sqlArr).')'; + } else if (is_string($attribute)) { + if ($condition === null) { $condition = ''; } $conditionSql = $this->_getAttributeConditionSql($attribute, $condition, $joinType); @@ -307,7 +327,7 @@ public function addAttributeToFilter($attribute, $condition=null, $joinType='inn * @param mixed $attribute * @param mixed $condition */ - public function addFieldToFilter($attribute, $condition=null) + public function addFieldToFilter($attribute, $condition = null) { return $this->addAttributeToFilter($attribute, $condition); } @@ -319,7 +339,7 @@ public function addFieldToFilter($attribute, $condition=null) * @param string $dir * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function addAttributeToSort($attribute, $dir='asc') + public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) { if (isset($this->_joinFields[$attribute])) { $this->getSelect()->order($this->_getAttributeFieldName($attribute).' '.$dir); @@ -327,23 +347,24 @@ public function addAttributeToSort($attribute, $dir='asc') } if (isset($this->_staticFields[$attribute])) { $this->getSelect()->order("e.{$attribute} {$dir}"); + return $this; } if (isset($this->_joinAttributes[$attribute])) { $attrInstance = $this->_joinAttributes[$attribute]['attribute']; - $entityField = $this->_getAttributeTableAlias($attribute).'.'.$attrInstance->getAttributeCode(); + $entityField = $this->_getAttributeTableAlias($attribute) . '.' . $attrInstance->getAttributeCode(); } else { $attrInstance = $this->getEntity()->getAttribute($attribute); - $entityField = 'e.'.$attribute; + $entityField = 'e.' . $attribute; } if ($attrInstance) { if ($attrInstance->getBackend()->isStatic()) { - $this->getSelect()->order($entityField.' '.$dir); + $this->getSelect()->order($entityField . ' ' . $dir); } else { $this->_addAttributeJoin($attribute, 'left'); - if (isset($this->_joinAttributes[$attribute])) { - $this->getSelect()->order($attribute.' '.$dir); + if (isset($this->_joinAttributes[$attribute])||isset($this->_joinFields[$attribute])) { + $this->getSelect()->order($attribute . ' ' . $dir); } else { - $this->getSelect()->order($this->_getAttributeTableAlias($attribute).'.value '.$dir); + $this->getSelect()->order($this->_getAttributeTableAlias($attribute) . '.value ' . $dir); } } } @@ -359,7 +380,7 @@ public function addAttributeToSort($attribute, $dir='asc') * @param false|string $joinType flag for joining attribute * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function addAttributeToSelect($attribute, $joinType=false) + public function addAttributeToSelect($attribute, $joinType = false) { if (is_array($attribute)) { Mage::getSingleton('eav/config')->loadCollectionAttributes($this->getEntity()->getType(), $attribute); @@ -368,9 +389,9 @@ public function addAttributeToSelect($attribute, $joinType=false) } return $this; } - if ($joinType!==false && !$this->getEntity()->getAttribute($attribute)->isStatic()) { + if ($joinType !== false && !$this->getEntity()->getAttribute($attribute)->isStatic()) { $this->_addAttributeJoin($attribute, $joinType); - } elseif ('*'===$attribute) { + } elseif ('*' === $attribute) { $attributes = $this->getEntity() ->loadAllAttributes() ->getAttributesByCode(); @@ -381,13 +402,14 @@ public function addAttributeToSelect($attribute, $joinType=false) if (isset($this->_joinAttributes[$attribute])) { $attrInstance = $this->_joinAttributes[$attribute]['attribute']; } else { - //$attrInstance = $this->getEntity()->getAttribute($attribute); $attrInstance = Mage::getSingleton('eav/config') ->getCollectionAttribute($this->getEntity()->getType(), $attribute); } if (empty($attrInstance)) { - throw Mage::exception('Mage_Eav', - Mage::helper('eav')->__('Invalid attribute requested: %s', (string)$attribute)); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('Invalid attribute requested: %s', (string)$attribute) + ); } $this->_selectAttributes[$attrInstance->getAttributeCode()] = $attrInstance->getId(); } @@ -397,7 +419,7 @@ public function addAttributeToSelect($attribute, $joinType=false) public function addEntityTypeToSelect($entityType, $prefix) { $this->_selectEntityTypes[$entityType] = array( - 'prefix'=>$prefix, + 'prefix' => $prefix, ); return $this; } @@ -433,20 +455,21 @@ public function addExpressionAttributeToSelect($alias, $expression, $attribute) { // validate alias if (isset($this->_joinFields[$alias])) { - throw Mage::exception('Mage_Eav', - Mage::helper('eav')->__('Joint field or attribute expression with this alias is already declared.')); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('Joint field or attribute expression with this alias is already declared') + ); } - if(!is_array($attribute)) { + if (!is_array($attribute)) { $attribute = array($attribute); } $fullExpression = $expression; // Replacing multiple attributes - foreach($attribute as $attributeItem) { + foreach ($attribute as $attributeItem) { if (isset($this->_staticFields[$attributeItem])) { $attrField = sprintf('e.%s', $attributeItem); - } - else { + } else { $attributeInstance = $this->getAttribute($attributeItem); if ($attributeInstance->getBackend()->isStatic()) { @@ -461,7 +484,7 @@ public function addExpressionAttributeToSelect($alias, $expression, $attribute) $fullExpression = str_replace('{{' . $attributeItem . '}}', $attrField, $fullExpression); } - $this->getSelect()->columns(array($alias=>$fullExpression)); + $this->getSelect()->columns(array($alias => $fullExpression)); $this->_joinFields[$alias] = array( 'table' => false, @@ -479,7 +502,7 @@ public function addExpressionAttributeToSelect($alias, $expression, $attribute) */ public function groupByAttribute($attribute) { - if(is_array($attribute)) { + if (is_array($attribute)) { foreach ($attribute as $attributeItem) { $this->groupByAttribute($attributeItem); } @@ -496,10 +519,10 @@ public function groupByAttribute($attribute) if (isset($this->_joinAttributes[$attribute])) { $attrInstance = $this->_joinAttributes[$attribute]['attribute']; - $entityField = $this->_getAttributeTableAlias($attribute).'.'.$attrInstance->getAttributeCode(); + $entityField = $this->_getAttributeTableAlias($attribute) . '.' . $attrInstance->getAttributeCode(); } else { $attrInstance = $this->getEntity()->getAttribute($attribute); - $entityField = 'e.'.$attribute; + $entityField = 'e.' . $attribute; } if ($attrInstance->getBackend()->isStatic()) { @@ -538,8 +561,10 @@ public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType { // validate alias if (isset($this->_joinAttributes[$alias])) { - throw Mage::exception('Mage_Eav', - Mage::helper('eav')->__('Invalid alias, already exists in joint attributes.')); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('Invalid alias, already exists in joint attributes') + ); } // validate bind attribute @@ -548,14 +573,14 @@ public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType } if (!$bindAttribute || (!$bindAttribute->isStatic() && !$bindAttribute->getId())) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid foreign key.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid foreign key')); } // try to explode combined entity/attribute if supplied if (is_string($attribute)) { $attrArr = explode('/', $attribute); if (isset($attrArr[1])) { - $entity = $attrArr[0]; + $entity = $attrArr[0]; $attribute = $attrArr[1]; } } @@ -572,7 +597,7 @@ public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType } } if (!$entity || !$entity->getTypeId()) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid entity type.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid entity type')); } // cache entity @@ -585,7 +610,7 @@ public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType $attribute = $entity->getAttribute($attribute); } if (!$attribute) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute type.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute type')); } if (empty($filter)) { @@ -625,8 +650,10 @@ public function joinField($alias, $table, $field, $bind, $cond=null, $joinType=' { // validate alias if (isset($this->_joinFields[$alias])) { - throw Mage::exception('Mage_Eav', - Mage::helper('eav')->__('Joined field with this alias is already declared.')); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('Joined field with this alias is already declared') + ); } // validate table @@ -652,7 +679,7 @@ public function joinField($alias, $table, $field, $bind, $cond=null, $joinType=' $condArr = array($bindCond); // add where condition if needed - if (!is_null($cond)) { + if ($cond !== null) { if (is_array($cond)) { foreach ($cond as $k=>$v) { $condArr[] = $this->_getConditionSql($tableAlias.'.'.$k, $v); @@ -661,10 +688,11 @@ public function joinField($alias, $table, $field, $bind, $cond=null, $joinType=' $condArr[] = str_replace('{{table}}', $tableAlias, $cond); } } - $cond = '(' . join(') AND (', $condArr) . ')'; + $cond = '(' . implode(') AND (', $condArr) . ')'; // join table - $this->getSelect()->$joinMethod(array($tableAlias=>$table), $cond, ($field ? array($alias=>$field) : array())); + $this->getSelect() + ->$joinMethod(array($tableAlias => $table), $cond, ($field ? array($alias=>$field) : array())); // save joined attribute $this->_joinFields[$alias] = array( @@ -685,13 +713,12 @@ public function joinField($alias, $table, $field, $bind, $cond=null, $joinType=' * @param string $joinType * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function joinTable($table, $bind, $fields=null, $cond=null, $joinType='inner') + public function joinTable($table, $bind, $fields = null, $cond = null, $joinType = 'inner') { $tableAlias = null; if (is_array($table)) { list($tableAlias, $tableName) = each($table); - } - else { + } else { $tableName = $table; } @@ -705,12 +732,14 @@ public function joinTable($table, $bind, $fields=null, $cond=null, $joinType='in // validate fields and aliases if (!$fields) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid joint fields.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid joint fields')); } foreach ($fields as $alias=>$field) { if (isset($this->_joinFields[$alias])) { - throw Mage::exception('Mage_Eav', - Mage::helper('eav')->__('A joint field with this alias (%s) is already declared.', $alias)); + throw Mage::exception( + 'Mage_Eav', + Mage::helper('eav')->__('A joint field with this alias (%s) is already declared', $alias) + ); } $this->_joinFields[$alias] = array( 'table' => $tableAlias, @@ -734,16 +763,16 @@ public function joinTable($table, $bind, $fields=null, $cond=null, $joinType='in $condArr = array($bindCond); // add where condition if needed - if (!is_null($cond)) { + if ($cond !== null) { if (is_array($cond)) { - foreach ($cond as $k=>$v) { + foreach ($cond as $k => $v) { $condArr[] = $this->_getConditionSql($tableAlias.'.'.$k, $v); } } else { $condArr[] = str_replace('{{table}}', $tableAlias, $cond); } } - $cond = '('.join(') AND (', $condArr).')'; + $cond = '('.implode(') AND (', $condArr).')'; // join table $this->getSelect()->$joinMethod(array($tableAlias => $tableName), $cond, $fields); @@ -757,9 +786,9 @@ public function joinTable($table, $bind, $fields=null, $cond=null, $joinType='in * @param string $attribute * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function removeAttributeToSelect($attribute=null) + public function removeAttributeToSelect($attribute = null) { - if (is_null($attribute)) { + if ($attribute === null) { $this->_selectAttributes = array(); } else { unset($this->_selectAttributes[$attribute]); @@ -823,15 +852,16 @@ public function load($printQuery = false, $logQuery = false) * * @return Mage_Eav_Model_Entity_Collection_Abstract */ - protected function _getAllIdsSelect($limit=null, $offset=null) + protected function _getAllIdsSelect($limit = null, $offset = null) { $idsSelect = clone $this->getSelect(); $idsSelect->reset(Zend_Db_Select::ORDER); $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns('e.'.$this->getEntity()->getIdFieldName()); + $idsSelect->columns('e.' . $this->getEntity()->getIdFieldName()); $idsSelect->limit($limit, $offset); + return $idsSelect; } @@ -840,7 +870,7 @@ protected function _getAllIdsSelect($limit=null, $offset=null) * * @return array */ - public function getAllIds($limit=null, $offset=null) + public function getAllIds($limit = null, $offset = null) { return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); } @@ -859,6 +889,7 @@ public function getAllIdsSql() $idsSelect->reset(Zend_Db_Select::COLUMNS); $idsSelect->reset(Zend_Db_Select::GROUP); $idsSelect->columns('e.'.$this->getEntity()->getIdFieldName()); + return $idsSelect; } @@ -906,7 +937,7 @@ public function importFromArray($arr) if (!isset($this->_items[$entityId])) { $this->_items[$entityId] = $this->getNewEmptyItem(); $this->_items[$entityId]->setData($row); - } else { + } else { $this->_items[$entityId]->addData($row); } } @@ -928,15 +959,24 @@ public function exportToArray() return $result; } - + /** + * Retreive row id field name + * + * @return string + */ public function getRowIdFieldName() { - if (is_null($this->_idFieldName)) { + if ($this->_idFieldName === null) { $this->_setIdFieldName($this->getEntity()->getIdFieldName()); } return $this->getIdFieldName(); } + /** + * Set row id field name + * @param string $fieldName + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ public function setRowIdFieldName($fieldName) { return $this->_setIdFieldName($fieldName); @@ -945,12 +985,12 @@ public function setRowIdFieldName($fieldName) /** * Load entities records into items * + * @throws Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function _loadEntities($printQuery = false, $logQuery = false) { $entity = $this->getEntity(); -// $entityIdField = $entity->getEntityIdField(); if ($this->_pageSize) { $this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize); @@ -959,10 +999,15 @@ public function _loadEntities($printQuery = false, $logQuery = false) $this->printLogQuery($printQuery, $logQuery); try { - $rows = $this->_fetchAll($this->getSelect()); + /** + * Prepare select query + * @var string $query + */ + $query = $this->_prepareSelect($this->getSelect()); + $rows = $this->_fetchAll($query); } catch (Exception $e) { - Mage::printException($e, $this->getSelect()); - $this->printLogQuery(true, true, $this->getSelect()); + Mage::printException($e, $query); + $this->printLogQuery(true, true, $query); throw $e; } @@ -972,17 +1017,18 @@ public function _loadEntities($printQuery = false, $logQuery = false) $this->addItem($object); if (isset($this->_itemsById[$object->getId()])) { $this->_itemsById[$object->getId()][] = $object; - } - else { + } else { $this->_itemsById[$object->getId()] = array($object); } } + return $this; } /** * Load attributes into loaded entities * + * @throws Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function _loadAttributes($printQuery = false, $logQuery = false) @@ -992,9 +1038,9 @@ public function _loadAttributes($printQuery = false, $logQuery = false) } $entity = $this->getEntity(); - $entityIdField = $entity->getEntityIdField(); $tableAttributes = array(); + $attributeTypes = array(); foreach ($this->_selectAttributes as $attributeCode => $attributeId) { if (!$attributeId) { continue; @@ -1002,27 +1048,35 @@ public function _loadAttributes($printQuery = false, $logQuery = false) $attribute = Mage::getSingleton('eav/config')->getCollectionAttribute($entity->getType(), $attributeCode); if ($attribute && !$attribute->isStatic()) { $tableAttributes[$attribute->getBackendTable()][] = $attributeId; + if (!isset($attributeTypes[$attribute->getBackendTable()])) { + $attributeTypes[$attribute->getBackendTable()] = $attribute->getBackendType(); + } } } $selects = array(); foreach ($tableAttributes as $table=>$attributes) { - $selects[] = $this->_getLoadAttributesSelect($table, $attributes); - } - if (!empty($selects)) { - try { - $select = implode(' UNION ', $selects); - $values = $this->_fetchAll($select); - } catch (Exception $e) { - Mage::printException($e, $select); - $this->printLogQuery(true, true, $select); - throw $e; - } + $select = $this->_getLoadAttributesSelect($table, $attributes); + $selects[$attributeTypes[$table]][] = $this->_addLoadAttributesSelectValues($select, $table, $attributeTypes[$table]); + } + $selectGroups = Mage::getResourceHelper('eav')->getLoadAttributesSelectGroups($selects); + foreach ($selectGroups as $selects) { + if (!empty($selects)) { + try { + $select = implode(' UNION ALL ', $selects); + $values = $this->getConnection()->fetchAll($select); + } catch (Exception $e) { + Mage::printException($e, $select); + $this->printLogQuery(true, true, $select); + throw $e; + } - foreach ($values as $value) { - $this->_setItemAttributeValue($value); + foreach ($values as $value) { + $this->_setItemAttributeValue($value); + } } } + return $this; } @@ -1032,17 +1086,34 @@ public function _loadAttributes($printQuery = false, $logQuery = false) * @param string $table * @return Mage_Eav_Model_Entity_Collection_Abstract */ - protected function _getLoadAttributesSelect($table, $attributeIds=array()) + protected function _getLoadAttributesSelect($table, $attributeIds = array()) { if (empty($attributeIds)) { $attributeIds = $this->_selectAttributes; } + $helper = Mage::getResourceHelper('eav'); $entityIdField = $this->getEntity()->getEntityIdField(); $select = $this->getConnection()->select() - ->from($table, array($entityIdField, 'attribute_id', 'value')) - ->where('entity_type_id=?', $this->getEntity()->getTypeId()) - ->where("$entityIdField in (?)", array_keys($this->_itemsById)) - ->where('attribute_id in (?)', $attributeIds); + ->from($table, array($entityIdField, 'attribute_id')) + ->where('entity_type_id =?', $this->getEntity()->getTypeId()) + ->where("$entityIdField IN (?)", array_keys($this->_itemsById)) + ->where('attribute_id IN (?)', $attributeIds); + return $select; + } + + /** + * @param Varien_Db_Select $select + * @param string $table + * @param string $type + * @return Varien_Db_Select + */ + protected function _addLoadAttributesSelectValues($select, $table, $type) + { + $helper = Mage::getResourceHelper('eav'); + $select->columns(array( + 'value' => $helper->prepareEavAttributeValue($table. '.value', $type), + )); + return $select; } @@ -1052,6 +1123,7 @@ protected function _getLoadAttributesSelect($table, $attributeIds=array()) * $valueInfo is _getLoadAttributesSelect fetch result row * * @param array $valueInfo + * @throws Mage_Eav_Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _setItemAttributeValue($valueInfo) @@ -1059,8 +1131,8 @@ protected function _setItemAttributeValue($valueInfo) $entityIdField = $this->getEntity()->getEntityIdField(); $entityId = $valueInfo[$entityIdField]; if (!isset($this->_itemsById[$entityId])) { - Mage::throwException('Mage_Eav', - Mage::helper('eav')->__('Data integrity: No header row found for attribute.') + throw Mage::exception('Mage_Eav', + Mage::helper('eav')->__('Data integrity: No header row found for attribute') ); } $attributeCode = array_search($valueInfo['attribute_id'], $this->_selectAttributes); @@ -1075,6 +1147,7 @@ protected function _setItemAttributeValue($valueInfo) foreach ($this->_itemsById[$entityId] as $object) { $object->setData($attributeCode, $valueInfo['value']); } + return $this; } @@ -1086,9 +1159,15 @@ protected function _setItemAttributeValue($valueInfo) */ protected function _getAttributeTableAlias($attributeCode) { - return '_table_'.$attributeCode; + return 'at_' . $attributeCode; } + /** + * Retreive attribute field name by attribute code + * + * @param string $attributeCode + * @return string + */ protected function _getAttributeFieldName($attributeCode) { if (isset($this->_joinAttributes[$attributeCode]['condition_alias'])) { @@ -1099,23 +1178,24 @@ protected function _getAttributeFieldName($attributeCode) } if (isset($this->_joinFields[$attributeCode])) { $attr = $this->_joinFields[$attributeCode]; - return $attr['table'] ? $attr['table'] .'.'.$attr['field'] : $attr['field']; + return $attr['table'] ? $attr['table'] . '.' . $attr['field'] : $attr['field']; } $attribute = $this->getAttribute($attributeCode); if (!$attribute) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute name: %s.', $attributeCode)); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute name: %s', $attributeCode)); } if ($attribute->isStatic()) { if (isset($this->_joinAttributes[$attributeCode])) { - $fieldName = $this->_getAttributeTableAlias($attributeCode).'.'.$attributeCode; + $fieldName = $this->_getAttributeTableAlias($attributeCode) . '.' . $attributeCode; } else { - $fieldName = 'e.'.$attributeCode; + $fieldName = 'e.' . $attributeCode; } } else { - $fieldName = $this->_getAttributeTableAlias($attributeCode).'.value'; + $fieldName = $this->_getAttributeTableAlias($attributeCode) . '.value'; } + return $fieldName; } @@ -1124,9 +1204,10 @@ protected function _getAttributeFieldName($attributeCode) * * @param string $attributeCode * @param string $joinType inner|left + * @throws Mage_Eav_Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ - protected function _addAttributeJoin($attributeCode, $joinType='inner') + protected function _addAttributeJoin($attributeCode, $joinType = 'inner') { if (!empty($this->_filterAttributes[$attributeCode])) { return $this; @@ -1145,31 +1226,31 @@ protected function _addAttributeJoin($attributeCode, $joinType='inner') if ($fkAttribute->getBackend()->isStatic()) { if (isset($this->_joinAttributes[$fkName])) { - $fk = $fkTable.".".$fkAttribute->getAttributeCode(); + $fk = $fkTable . '.' . $fkAttribute->getAttributeCode(); } else { - $fk = "e.".$fkAttribute->getAttributeCode(); + $fk = 'e.' . $fkAttribute->getAttributeCode(); } } else { $this->_addAttributeJoin($fkAttribute->getAttributeCode(), $joinType); - $fk = "$fkTable.value"; + $fk = $fkTable . '.value'; } - $pk = $attrTable.'.'.$this->_joinAttributes[$attributeCode]['filter']; + $pk = $attrTable . '.' . $this->_joinAttributes[$attributeCode]['filter']; } else { $entity = $this->getEntity(); $entityIdField = $entity->getEntityIdField(); $attribute = $entity->getAttribute($attributeCode); - $fk = "e.$entityIdField"; - $pk = "$attrTable.$entityIdField"; + $fk = 'e.' . $entityIdField; + $pk = $attrTable . '.' . $entityIdField; } if (!$attribute) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute name: %s.', $attributeCode)); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid attribute name: %s', $attributeCode)); } if ($attribute->getBackend()->isStatic()) { - $attrFieldName = "$attrTable.".$attribute->getAttributeCode(); + $attrFieldName = $attrTable . '.' . $attribute->getAttributeCode(); } else { - $attrFieldName = "$attrTable.value"; + $attrFieldName = $attrTable . '.value'; } $fk = $adapter->quoteColumnAs($fk, null); @@ -1217,8 +1298,8 @@ protected function _joinAttributeToSelect($method, $attribute, $tableAlias, $con { $this->getSelect()->$method( array($tableAlias => $attribute->getBackend()->getTable()), - '('.join(') AND (', $condition).')', - array($fieldCode=>$fieldAlias) + '('.implode(') AND (', $condition).')', + array($fieldCode => $fieldAlias) ); return $this; } @@ -1232,35 +1313,38 @@ protected function _joinAttributeToSelect($method, $attribute, $tableAlias, $con * @param string $joinType * @return string */ - protected function _getAttributeConditionSql($attribute, $condition, $joinType='inner') + protected function _getAttributeConditionSql($attribute, $condition, $joinType = 'inner') { if (isset($this->_joinFields[$attribute])) { + return $this->_getConditionSql($this->_getAttributeFieldName($attribute), $condition); } if (isset($this->_staticFields[$attribute])) { - return $this->_getConditionSql(sprintf('e.%s', $attribute), $condition); + return $this->_getConditionSql($this->getConnection()->quoteIdentifier('e.' . $attribute), $condition); } // process linked attribute if (isset($this->_joinAttributes[$attribute])) { - $entity = $this->getAttribute($attribute)->getEntity(); + $entity = $this->getAttribute($attribute)->getEntity(); $entityTable = $entity->getEntityTable(); } else { - $entity = $this->getEntity(); + $entity = $this->getEntity(); $entityTable = 'e'; } if ($entity->isAttributeStatic($attribute)) { - $conditionSql = $this->_getConditionSql('e.'.$attribute, $condition); + $conditionSql = $this->_getConditionSql($this->getConnection()->quoteIdentifier('e.' . $attribute), $condition); } else { $this->_addAttributeJoin($attribute, $joinType); if (isset($this->_joinAttributes[$attribute]['condition_alias'])) { $field = $this->_joinAttributes[$attribute]['condition_alias']; + } else { + $field = $this->_getAttributeTableAlias($attribute) . '.value'; + } - else { - $field = $this->_getAttributeTableAlias($attribute).'.value'; - } + $conditionSql = $this->_getConditionSql($field, $condition); } + return $conditionSql; } @@ -1273,7 +1357,7 @@ protected function _getAttributeConditionSql($attribute, $condition, $joinType=' * @param string $dir * @return Mage_Eav_Model_Entity_Collection_Abstract */ - public function setOrder($attribute, $dir='desc') + public function setOrder($attribute, $dir = self::SORT_ORDER_ASC) { if (is_array($attribute)) { foreach ($attribute as $attr) { @@ -1285,21 +1369,36 @@ public function setOrder($attribute, $dir='desc') return $this; } - + /** + * Retreive array of attributes + * + * @param array $arrAttributes + * @return array + */ public function toArray($arrAttributes = array()) { $arr = array(); - foreach ($this->_items as $k=>$item) { + foreach ($this->_items as $k => $item) { $arr[$k] = $item->toArray($arrAttributes); } return $arr; } + /** + * Before load method + * + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ protected function _beforeLoad() { return $this; } + /** + * After load method + * + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ protected function _afterLoad() { return $this; @@ -1315,11 +1414,11 @@ protected function _reset() parent::_reset(); $this->_selectEntityTypes = array(); - $this->_selectAttributes = array(); - $this->_filterAttributes = array(); - $this->_joinEntities = array(); - $this->_joinAttributes = array(); - $this->_joinFields = array(); + $this->_selectAttributes = array(); + $this->_filterAttributes = array(); + $this->_joinEntities = array(); + $this->_joinAttributes = array(); + $this->_joinFields = array(); return $this; } @@ -1333,4 +1432,20 @@ public function getLoadedIds() { return array_keys($this->_items); } + + /** + * Prepare select for load + * + * @param Varien_Db_Select $select OPTIONAL + * @return string + */ + public function _prepareSelect(Varien_Db_Select $select) + { + if ($this->_useAnalyticFunction) { + $helper = Mage::getResourceHelper('core'); + return $helper->getQueryUsingAnalyticFunction($select); + } + + return (string)$select; + } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Increment/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Increment/Abstract.php index ca1e59c17e..9a55e8b371 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Increment/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Increment/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,8 +34,7 @@ * - pad_char * - last_id */ -abstract class Mage_Eav_Model_Entity_Increment_Abstract - extends Varien_Object +abstract class Mage_Eav_Model_Entity_Increment_Abstract extends Varien_Object implements Mage_Eav_Model_Entity_Increment_Interface { public function getPadLength() @@ -46,7 +45,7 @@ public function getPadLength() } return $padLength; } - + public function getPadChar() { $padChar = $this->getData('pad_char'); @@ -55,17 +54,16 @@ public function getPadChar() } return $padChar; } - + public function format($id) { $result = $this->getPrefix(); $result.= str_pad((string)$id, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT); return $result; } - + public function frontendFormat($id) { - $result = $id; - return $result; + return $id; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Increment/Alphanum.php b/app/code/core/Mage/Eav/Model/Entity/Increment/Alphanum.php index 81ae74440a..c4233bd21e 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Increment/Alphanum.php +++ b/app/code/core/Mage/Eav/Model/Entity/Increment/Alphanum.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,30 +34,29 @@ * - pad_char * - last_id */ -class Mage_Eav_Model_Entity_Increment_Alphanum - extends Mage_Eav_Model_Entity_Increment_Abstract +class Mage_Eav_Model_Entity_Increment_Alphanum extends Mage_Eav_Model_Entity_Increment_Abstract { public function getAllowedChars() { return '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; } - + public function getNextId() { $lastId = $this->getLastId(); - + if (strpos($lastId, $this->getPrefix())===0) { $lastId = substr($lastId, strlen($this->getPrefix())); } - + $lastId = str_pad((string)$lastId, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT); - + $nextId = ''; $bumpNextChar = true; $chars = $this->getAllowedChars(); $lchars = strlen($chars); $lid = strlen($lastId)-1; - + for ($i = $lid; $i >= 0; $i--) { $p = strpos($chars, $lastId{$i}); if (false===$p) { @@ -73,7 +72,7 @@ public function getNextId() } $nextId = $chars{$p}.$nextId; } - + return $this->format($nextId); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Increment/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Increment/Interface.php index ef51d8dd40..0b93c64b65 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Increment/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Increment/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php b/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php index 99e29b4f9b..679c4d46db 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php +++ b/app/code/core/Mage/Eav/Model/Entity/Increment/Numeric.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,21 +34,20 @@ * - pad_char * - last_id */ -class Mage_Eav_Model_Entity_Increment_Numeric - extends Mage_Eav_Model_Entity_Increment_Abstract +class Mage_Eav_Model_Entity_Increment_Numeric extends Mage_Eav_Model_Entity_Increment_Abstract { public function getNextId() { $last = $this->getLastId(); - - if (strpos($last, $this->getPrefix())===0) { + + if (strpos($last, $this->getPrefix()) === 0) { $last = (int)substr($last, strlen($this->getPrefix())); } else { $last = (int)$last; } - + $next = $last+1; - + return $this->format($next); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Interface.php b/app/code/core/Mage/Eav/Model/Entity/Interface.php index 7572807083..f469e3992d 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Interface.php +++ b/app/code/core/Mage/Eav/Model/Entity/Interface.php @@ -20,12 +20,11 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ interface Mage_Eav_Model_Entity_Interface { - } diff --git a/app/code/core/Mage/Eav/Model/Entity/Setup.php b/app/code/core/Mage/Eav/Model/Entity/Setup.php index baae8ca516..a1f6b9614b 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Setup.php +++ b/app/code/core/Mage/Eav/Model/Entity/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,10 +34,35 @@ */ class Mage_Eav_Model_Entity_Setup extends Mage_Core_Model_Resource_Setup { - protected $_attributeTableFields; - protected $_generalGroupName = 'General'; + /** + * General Attribute Group Name + * + * @var string + */ + protected $_generalGroupName = 'General'; + + /** + * Default attribute group name to id pairs + * + * @var array + */ + public $defaultGroupIdAssociations = array( + 'General' => 1 + ); - public $defaultGroupIdAssociations = array('General'=>1); + /** + * Default attribute group name + * + * @var string + */ + protected $_defaultGroupName = 'Default'; + + /** + * Default attribute set name + * + * @var string + */ + protected $_defaultAttributeSetName = 'Default'; /** * Clean cache @@ -58,7 +83,7 @@ public function cleanCache() public function installDefaultGroupIds() { $setIds = $this->getAllAttributeSetIds(); - foreach ($this->defaultGroupIdAssociations as $defaultGroupName=>$defaultGroupId) { + foreach ($this->defaultGroupIdAssociations as $defaultGroupName => $defaultGroupId) { foreach ($setIds as $set) { $groupId = $this->getTableRow('eav/attribute_group', 'attribute_group_name', $defaultGroupName, 'attribute_group_id', 'attribute_set_id', $set @@ -69,11 +94,11 @@ public function installDefaultGroupIds() ); } $this->updateTableRow('eav/attribute_group', - 'attribute_group_id', $groupId, - 'default_id', $defaultGroupId + 'attribute_group_id', $groupId, 'default_id', $defaultGroupId ); } } + return $this; } @@ -92,14 +117,18 @@ public function installDefaultGroupIds() public function addEntityType($code, array $params) { $data = array( - 'entity_type_code' => $code, - 'entity_model' => $params['entity_model'], - 'attribute_model' => isset($params['attribute_model']) ? $params['attribute_model'] : '', - 'entity_table' => isset($params['table']) ? $params['table'] : 'eav/entity', - 'increment_model' => isset($params['increment_model']) ? $params['increment_model'] : '', - 'increment_per_store' => isset($params['increment_per_store']) ? $params['increment_per_store'] : 0, - 'additional_attribute_table' => isset($params['additional_attribute_table']) ? $params['additional_attribute_table'] : '', - 'entity_attribute_collection'=> isset($params['entity_attribute_collection']) ? $params['entity_attribute_collection'] : '', + 'entity_type_code' => $code, + 'entity_model' => $params['entity_model'], + 'attribute_model' => $this->_getValue($params, 'attribute_model'), + 'entity_table' => $this->_getValue($params, 'table', 'eav/entity'), + 'value_table_prefix' => $this->_getValue($params, 'table_prefix'), + 'entity_id_field' => $this->_getValue($params, 'id_field'), + 'increment_model' => $this->_getValue($params, 'increment_model'), + 'increment_per_store' => $this->_getValue($params, 'increment_per_store', 0), + 'increment_pad_length' => $this->_getValue($params, 'increment_pad_length', 8), + 'increment_pad_char' => $this->_getValue($params, 'increment_pad_char', 0), + 'additional_attribute_table' => $this->_getValue($params, 'additional_attribute_table'), + 'entity_attribute_collection' => $this->_getValue($params, 'entity_attribute_collection'), ); if ($this->getEntityType($code, 'entity_type_id')) { @@ -108,8 +137,14 @@ public function addEntityType($code, array $params) $this->_conn->insert($this->getTable('eav/entity_type'), $data); } - $this->addAttributeSet($code, 'Default'); - $this->addAttributeGroup($code, 'Default', $this->_generalGroupName); + if (!empty($params['default_group'])) { + $defaultGroup = $params['default_group']; + } else { + $defaultGroup = $this->_defaultGroupName; + } + + $this->addAttributeSet($code, $this->_defaultAttributeSetName); + $this->addAttributeGroup($code, $this->_defaultGroupName, $this->_generalGroupName); return $this; } @@ -122,11 +157,10 @@ public function addEntityType($code, array $params) * @param string $value * @return Mage_Eav_Model_Entity_Setup */ - public function updateEntityType($code, $field, $value=null) + public function updateEntityType($code, $field, $value = null) { $this->updateTableRow('eav/entity_type', - 'entity_type_id', $this->getEntityTypeId($code), - $field, $value + 'entity_type_id', $this->getEntityTypeId($code), $field, $value ); return $this; } @@ -138,11 +172,10 @@ public function updateEntityType($code, $field, $value=null) * @param string $field * @return mixed */ - public function getEntityType($id, $field=null) + public function getEntityType($id, $field = null) { return $this->getTableRow('eav/entity_type', - is_numeric($id) ? 'entity_type_id' : 'entity_type_code', $id, - $field + is_numeric($id) ? 'entity_type_id' : 'entity_type_code', $id, $field ); } @@ -158,8 +191,9 @@ public function getEntityTypeId($entityTypeId) $entityTypeId = $this->getEntityType($entityTypeId, 'entity_type_id'); } if (!is_numeric($entityTypeId)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong entity ID.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong entity ID')); } + return $entityTypeId; } @@ -173,10 +207,10 @@ public function removeEntityType($id) { if (is_numeric($id)) { $this->deleteTableRow('eav/entity_type', 'entity_type_id', $id); - } - else { + } else { $this->deleteTableRow('eav/entity_type', 'entity_type_code', (string)$id); } + return $this; } @@ -189,15 +223,17 @@ public function removeEntityType($id) * @param int $sortOrder * @return int */ - public function getAttributeSetSortOrder($entityTypeId, $sortOrder=null) + public function getAttributeSetSortOrder($entityTypeId, $sortOrder = null) { if (!is_numeric($sortOrder)) { - $sortOrder = $this->_conn->fetchOne("select max(sort_order) - from ".$this->getTable('eav/attribute_set')." - where entity_type_id=".$this->getEntityTypeId($entityTypeId) - ); - $sortOrder++; + $bind = array('entity_type_id' => $this->getEntityTypeId($entityTypeId)); + $select = $this->_conn->select() + ->from($this->getTable('eav/attribute_set'), 'MAX(sort_order)') + ->where('entity_type_id = :entity_type_id'); + + $sortOrder = $this->_conn->fetchOne($select, $bind) + 1; } + return $sortOrder; } @@ -209,16 +245,17 @@ public function getAttributeSetSortOrder($entityTypeId, $sortOrder=null) * @param int $sortOrder * @return Mage_Eav_Model_Entity_Setup */ - public function addAttributeSet($entityTypeId, $name, $sortOrder=null) + public function addAttributeSet($entityTypeId, $name, $sortOrder = null) { $data = array( - 'entity_type_id'=>$this->getEntityTypeId($entityTypeId), - 'attribute_set_name'=>$name, - 'sort_order'=>$this->getAttributeSetSortOrder($entityTypeId, $sortOrder), + 'entity_type_id' => $this->getEntityTypeId($entityTypeId), + 'attribute_set_name' => $name, + 'sort_order' => $this->getAttributeSetSortOrder($entityTypeId, $sortOrder), ); - if ($id = $this->getAttributeSet($entityTypeId, $name, 'attribute_set_id')) { - $this->updateAttributeSet($entityTypeId, $id, $data); + $setId = $this->getAttributeSet($entityTypeId, $name, 'attribute_set_id'); + if ($setId) { + $this->updateAttributeSet($entityTypeId, $setId, $data); } else { $this->_conn->insert($this->getTable('eav/attribute_set'), $data); @@ -237,7 +274,7 @@ public function addAttributeSet($entityTypeId, $name, $sortOrder=null) * @param mixed $value * @return Mage_Eav_Model_Entity_Setup */ - public function updateAttributeSet($entityTypeId, $id, $field, $value=null) + public function updateAttributeSet($entityTypeId, $id, $field, $value = null) { $this->updateTableRow('eav/attribute_set', 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $id), @@ -255,7 +292,7 @@ public function updateAttributeSet($entityTypeId, $id, $field, $value=null) * @param string $field * @return mixed */ - public function getAttributeSet($entityTypeId, $id, $field=null) + public function getAttributeSet($entityTypeId, $id, $field = null) { return $this->getTableRow('eav/attribute_set', is_numeric($id) ? 'attribute_set_id' : 'attribute_set_name', $id, @@ -278,8 +315,9 @@ public function getAttributeSetId($entityTypeId, $setId) $setId = $this->getAttributeSet($entityTypeId, $setId, 'attribute_set_id'); } if (!is_numeric($setId)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute set ID.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute set ID')); } + return $setId; } @@ -305,7 +343,7 @@ public function removeAttributeSet($entityTypeId, $id) public function setDefaultSetToEntityType($entityType, $attributeSet = 'Default') { $entityTypeId = $this->getEntityTypeId($entityType); - $setId = $this->getAttributeSetId($entityTypeId, $attributeSet); + $setId = $this->getAttributeSetId($entityTypeId, $attributeSet); $this->updateEntityType($entityTypeId, 'default_attribute_set_id', $setId); return $this; } @@ -315,14 +353,18 @@ public function setDefaultSetToEntityType($entityType, $attributeSet = 'Default' * * @return array */ - public function getAllAttributeSetIds($entityTypeId=null) + public function getAllAttributeSetIds($entityTypeId = null) { - $where = ''; - if (!is_null($entityTypeId)) { - $where = " WHERE `entity_type_id` = '" . $this->getEntityTypeId($entityTypeId) . "'"; + $select = $this->_conn->select() + ->from($this->getTable('eav/attribute_set'), 'attribute_set_id'); + + $bind = array(); + if ($entityTypeId !== null) { + $bind['entity_type_id'] = $this->getEntityTypeId($entityTypeId); + $select->where('entity_type_id = :entity_type_id'); } - $sql = "SELECT `attribute_set_id` FROM `{$this->getTable('eav/attribute_set')}`" . $where; - return $this->_conn->fetchCol($sql); + + return $this->_conn->fetchCol($select, $bind); } /** @@ -333,10 +375,17 @@ public function getAllAttributeSetIds($entityTypeId=null) */ public function getDefaultAttributeSetId($entityType) { + $bind = array('entity_type' => $entityType); + if (is_numeric($entityType)) { + $where = 'entity_type_id = :entity_type'; + } else { + $where = 'entity_type_code = :entity_type'; + } $select = $this->getConnection()->select() ->from($this->getTable('eav/entity_type'), 'default_attribute_set_id') - ->where(is_numeric($entityType) ? 'entity_type_id=?' : 'entity_type_code=?', $entityType); - return $this->getConnection()->fetchOne($select); + ->where($where); + + return $this->getConnection()->fetchOne($select, $bind); } /******************* ATTRIBUTE GROUPS *****************/ @@ -349,15 +398,17 @@ public function getDefaultAttributeSetId($entityType) * @param int $sortOrder * @return int */ - public function getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder=null) + public function getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder = null) { if (!is_numeric($sortOrder)) { - $sortOrder = $this->_conn->fetchOne("select max(sort_order) - from ".$this->getTable('eav/attribute_group')." - where attribute_set_id=".$this->getAttributeSetId($entityTypeId, $setId) - ); - $sortOrder++; + $bind = array('attribute_set_id' => $this->getAttributeSetId($entityTypeId, $setId)); + $select = $this->_conn->select() + ->from($this->getTable('eav/attribute_group'), 'MAX(sort_order)') + ->where('attribute_set_id = :attribute_set_id'); + + $sortOrder = $this->_conn->fetchOne($select, $bind) + 1; } + return $sortOrder; } @@ -370,24 +421,27 @@ public function getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder=nul * @param int $sortOrder * @return Mage_Eav_Model_Entity_Setup */ - public function addAttributeGroup($entityTypeId, $setId, $name, $sortOrder=null) + public function addAttributeGroup($entityTypeId, $setId, $name, $sortOrder = null) { - $setId = $this->getAttributeSetId($entityTypeId, $setId); - $data = array( - 'attribute_set_id'=>$setId, - 'attribute_group_name'=>$name, + $setId = $this->getAttributeSetId($entityTypeId, $setId); + $data = array( + 'attribute_set_id' => $setId, + 'attribute_group_name' => $name, ); + if (isset($this->defaultGroupIdAssociations[$name])) { $data['default_id'] = $this->defaultGroupIdAssociations[$name]; } - if (!is_null($sortOrder)) { + + if ($sortOrder !== null) { $data['sort_order'] = $sortOrder; } - if ($id = $this->getAttributeGroup($entityTypeId, $setId, $name, 'attribute_group_id')) { - $this->updateAttributeGroup($entityTypeId, $setId, $id, $data); + $groupId = $this->getAttributeGroup($entityTypeId, $setId, $name, 'attribute_group_id'); + if ($groupId) { + $this->updateAttributeGroup($entityTypeId, $setId, $groupId, $data); } else { - if (is_null($sortOrder)) { + if ($sortOrder === null) { $data['sort_order'] = $this->getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder); } $this->_conn->insert($this->getTable('eav/attribute_group'), $data); @@ -406,13 +460,14 @@ public function addAttributeGroup($entityTypeId, $setId, $name, $sortOrder=null) * @param mixed $value * @return Mage_Eav_Model_Entity_Setup */ - public function updateAttributeGroup($entityTypeId, $setId, $id, $field, $value=null) + public function updateAttributeGroup($entityTypeId, $setId, $id, $field, $value = null) { $this->updateTableRow('eav/attribute_group', 'attribute_group_id', $this->getAttributeGroupId($entityTypeId, $setId, $id), $field, $value, 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $setId) ); + return $this; } @@ -425,7 +480,7 @@ public function updateAttributeGroup($entityTypeId, $setId, $id, $field, $value= * @param string $field * @return mixed */ - public function getAttributeGroup($entityTypeId, $setId, $id, $field=null) + public function getAttributeGroup($entityTypeId, $setId, $id, $field = null) { $searchId = $id; if (is_numeric($id)) { @@ -464,7 +519,7 @@ public function getAttributeGroupId($entityTypeId, $setId, $groupId) } if (!is_numeric($groupId)) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute group ID.')); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute group ID')); } return $groupId; } @@ -500,13 +555,14 @@ public function getDefaultAttributeGroupId($entityType, $attributeSetId = null) if (!is_numeric($attributeSetId)) { $attributeSetId = $this->getDefaultAttributeSetId($entityType); } - + $bind = array('attribute_set_id' => $attributeSetId); $select = $this->getConnection()->select() ->from($this->getTable('eav/attribute_group'), 'attribute_group_id') - ->where('attribute_set_id=?', $attributeSetId) - ->order('default_id DESC, sort_order') + ->where('attribute_set_id = :attribute_set_id') + ->order(array('default_id ' . Varien_Db_Select::SQL_DESC, 'sort_order')) ->limit(1); - return $this->getConnection()->fetchOne($select); + + return $this->getConnection()->fetchOne($select, $bind); } /******************* ATTRIBUTES *****************/ @@ -521,6 +577,9 @@ public function getDefaultAttributeGroupId($entityType, $attributeSetId = null) */ protected function _getValue($array, $key, $default = null) { + if (isset($array[$key]) && is_bool($array[$key])) { + $array[$key] = (int) $array[$key]; + } return isset($array[$key]) ? $array[$key] : $default; } @@ -532,25 +591,47 @@ protected function _getValue($array, $key, $default = null) */ protected function _prepareValues($attr) { - $data = array(); $data = array( - 'backend_model' => $this->_getValue($attr, 'backend', ''), + 'backend_model' => $this->_getValue($attr, 'backend'), 'backend_type' => $this->_getValue($attr, 'type', 'varchar'), - 'backend_table' => $this->_getValue($attr, 'table', ''), - 'frontend_model' => $this->_getValue($attr, 'frontend', ''), + 'backend_table' => $this->_getValue($attr, 'table'), + 'frontend_model' => $this->_getValue($attr, 'frontend'), 'frontend_input' => $this->_getValue($attr, 'input', 'text'), - 'frontend_label' => $this->_getValue($attr, 'label', ''), - 'frontend_class' => $this->_getValue($attr, 'frontend_class', ''), - 'source_model' => $this->_getValue($attr, 'source', ''), + 'frontend_label' => $this->_getValue($attr, 'label'), + 'frontend_class' => $this->_getValue($attr, 'frontend_class'), + 'source_model' => $this->_getValue($attr, 'source'), 'is_required' => $this->_getValue($attr, 'required', 1), 'is_user_defined' => $this->_getValue($attr, 'user_defined', 0), - 'default_value' => $this->_getValue($attr, 'default', ''), + 'default_value' => $this->_getValue($attr, 'default'), 'is_unique' => $this->_getValue($attr, 'unique', 0), - 'note' => $this->_getValue($attr, 'note', ''), + 'note' => $this->_getValue($attr, 'note'), ); + return $data; } + /** + * Validate attribute data before insert into table + * + * @param array $data + * @throws Mage_Eav_Exception + * @return true + */ + protected function _validateAttributeData($data) + { + $attributeCodeMaxLength = Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH; + + if (isset($data['attribute_code']) && + !Zend_Validate::is($data['attribute_code'], 'StringLength', array('max' => $attributeCodeMaxLength))) + { + throw Mage::exception('Mage_Eav', + Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', $attributeCodeMaxLength) + ); + } + + return true; + } + /** * Add attribute to an entity type * @@ -572,24 +653,31 @@ public function addAttribute($entityTypeId, $code, array $attr) $this->_prepareValues($attr) ); + $this->_validateAttributeData($data); + $sortOrder = isset($attr['sort_order']) ? $attr['sort_order'] : null; - if ($id = $this->getAttribute($entityTypeId, $code, 'attribute_id')) { - $this->updateAttribute($entityTypeId, $id, $data, null, $sortOrder); + $attributeId = $this->getAttribute($entityTypeId, $code, 'attribute_id'); + if ($attributeId) { + $this->updateAttribute($entityTypeId, $attributeId, $data, null, $sortOrder); } else { $this->_insertAttribute($data); } - if (!empty($attr['group'])) { - $sets = $this->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId); - foreach ($sets as $set) { - $this->addAttributeGroup($entityTypeId, $set['attribute_set_id'], $attr['group']); - $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $attr['group'], $code, $sortOrder); - } - } - if (empty($attr['user_defined'])) { - $sets = $this->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId); + if (!empty($attr['group']) || empty($attr['user_defined'])) { + $select = $this->_conn->select() + ->from($this->getTable('eav/attribute_set')) + ->where('entity_type_id = :entity_type_id'); + $sets = $this->_conn->fetchAll($select, array('entity_type_id' => $entityTypeId)); foreach ($sets as $set) { - $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $this->_generalGroupName, $code, $sortOrder); + if (!empty($attr['group'])) { + $this->addAttributeGroup($entityTypeId, $set['attribute_set_id'], + $attr['group']); + $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], + $attr['group'], $code, $sortOrder); + } else { + $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], + $this->_generalGroupName, $code, $sortOrder); + } } } @@ -609,15 +697,15 @@ public function addAttribute($entityTypeId, $code, array $attr) */ public function addAttributeOption($option) { - if (isset($option['value'])) { - $optionTable = $this->getTable('eav/attribute_option'); - $optionValueTable = $this->getTable('eav/attribute_option_value'); + $optionTable = $this->getTable('eav/attribute_option'); + $optionValueTable = $this->getTable('eav/attribute_option_value'); + if (isset($option['value'])) { foreach ($option['value'] as $optionId => $values) { $intOptionId = (int) $optionId; if (!empty($option['delete'][$optionId])) { if ($intOptionId) { - $condition = $this->_conn->quoteInto('option_id=?', $intOptionId); + $condition = array('option_id =?' => $intOptionId); $this->_conn->delete($optionTable, $condition); } continue; @@ -629,20 +717,20 @@ public function addAttributeOption($option) 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, ); $this->_conn->insert($optionTable, $data); - $intOptionId = $this->_conn->lastInsertId(); + $intOptionId = $this->_conn->lastInsertId($optionTable); } else { $data = array( 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, ); - $this->_conn->update($optionTable, $data, $this->_conn->quoteInto('option_id=?', $intOptionId)); + $this->_conn->update($optionTable, $data, array('option_id=?' => $intOptionId)); } // Default value if (!isset($values[0])) { - Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.')); + Mage::throwException(Mage::helper('eav')->__('Default option value is not defined')); } - - $this->_conn->delete($optionValueTable, $this->_conn->quoteInto('option_id=?', $intOptionId)); + $condition = array('option_id =?' => $intOptionId); + $this->_conn->delete($optionValueTable, $condition); foreach ($values as $storeId => $value) { $data = array( 'option_id' => $intOptionId, @@ -652,6 +740,23 @@ public function addAttributeOption($option) $this->_conn->insert($optionValueTable, $data); } } + } else if (isset($option['values'])) { + foreach ($option['values'] as $sortOrder => $label) { + // add option + $data = array( + 'attribute_id' => $option['attribute_id'], + 'sort_order' => $sortOrder, + ); + $this->_conn->insert($optionTable, $data); + $intOptionId = $this->_conn->lastInsertId($optionTable); + + $data = array( + 'option_id' => $intOptionId, + 'store_id' => 0, + 'value' => $label, + ); + $this->_conn->insert($optionValueTable, $data); + } } } @@ -665,7 +770,7 @@ public function addAttributeOption($option) * @param int $sortOrder * @return Mage_Eav_Model_Entity_Setup */ - public function updateAttribute($entityTypeId, $id, $field, $value=null, $sortOrder=null) + public function updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) { $this->_updateAttribute($entityTypeId, $id, $field, $value, $sortOrder); $this->_updateAttributeAdditionalData($entityTypeId, $id, $field, $value); @@ -682,9 +787,9 @@ public function updateAttribute($entityTypeId, $id, $field, $value=null, $sortOr * @param int $sortOrder * @return Mage_Eav_Model_Entity_Setup */ - protected function _updateAttribute($entityTypeId, $id, $field, $value=null, $sortOrder=null) + protected function _updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) { - if (!is_null($sortOrder)) { + if ($sortOrder !== null) { $this->updateTableRow('eav/entity_attribute', 'attribute_id', $this->getAttributeId($entityTypeId, $id), 'sort_order', $sortOrder @@ -696,15 +801,14 @@ protected function _updateAttribute($entityTypeId, $id, $field, $value=null, $so $bind = array(); foreach ($field as $k => $v) { if (isset($attributeFields[$k])) { - $bind[$k] = $v; + $bind[$k] = $this->getConnection()->prepareColumnValue($attributeFields[$k], $v); } } if (!$bind) { return $this; } $field = $bind; - } - else { + } else { if (!isset($attributeFields[$field])) { return $this; } @@ -715,6 +819,7 @@ protected function _updateAttribute($entityTypeId, $id, $field, $value=null, $so $field, $value, 'entity_type_id', $this->getEntityTypeId($entityTypeId) ); + return $this; } @@ -727,28 +832,27 @@ protected function _updateAttribute($entityTypeId, $id, $field, $value=null, $so * @param mixed $value * @return Mage_Eav_Model_Entity_Setup */ - protected function _updateAttributeAdditionalData($entityTypeId, $id, $field, $value=null) + protected function _updateAttributeAdditionalData($entityTypeId, $id, $field, $value = null) { $additionalTable = $this->getEntityType($entityTypeId, 'additional_attribute_table'); if (!$additionalTable) { return $this; } - $additionalTableExists = $this->getConnection()->showTableStatus($this->getTable($additionalTable)); + $additionalTableExists = $this->getConnection()->isTableExists($this->getTable($additionalTable)); if ($additionalTable && $additionalTableExists) { $attributeFields = $this->getConnection()->describeTable($this->getTable($additionalTable)); if (is_array($field)) { $bind = array(); foreach ($field as $k => $v) { if (isset($attributeFields[$k])) { - $bind[$k] = $v; + $bind[$k] = $this->getConnection()->prepareColumnValue($attributeFields[$k], $v); } } if (!$bind) { return $this; } $field = $bind; - } - else { + } else { if (!isset($attributeFields[$field])) { return $this; } @@ -758,6 +862,7 @@ protected function _updateAttributeAdditionalData($entityTypeId, $id, $field, $v $field, $value ); } + return $this; } @@ -773,7 +878,7 @@ public function getAttribute($entityTypeId, $id, $field = null) { $additionalTable = $this->getEntityType($entityTypeId, 'additional_attribute_table'); $entityTypeId = $this->getEntityTypeId($entityTypeId); - $idField = (is_numeric($id) ? 'attribute_id' : 'attribute_code'); + $idField = is_numeric($id) ? 'attribute_id' : 'attribute_code'; if (!$additionalTable) { return $this->getTableRow('eav/attribute', $idField, $id, $field, 'entity_type_id', $entityTypeId); } @@ -781,15 +886,19 @@ public function getAttribute($entityTypeId, $id, $field = null) $mainTable = $this->getTable('eav/attribute'); if (empty($this->_setupCache[$mainTable][$entityTypeId][$id])) { $additionalTable = $this->getTable($additionalTable); + $bind = array( + 'id' => $id, + 'entity_type_id' => $entityTypeId + ); $select = $this->_conn->select() ->from(array('main' => $mainTable)) ->join( array('additional' => $additionalTable), - 'main.attribute_id=additional.attribute_id') - ->where("main.{$idField}=?", $id) - ->where("main.entity_type_id=?", $entityTypeId); - $row = $this->_conn->fetchRow($select); + 'main.attribute_id = additional.attribute_id') + ->where("main.{$idField} = :id") + ->where('main.entity_type_id = :entity_type_id'); + $row = $this->_conn->fetchRow($select, $bind); if (!$row) { $this->_setupCache[$mainTable][$entityTypeId][$id] = false; } else { @@ -799,9 +908,10 @@ public function getAttribute($entityTypeId, $id, $field = null) } $row = $this->_setupCache[$mainTable][$entityTypeId][$id]; - if (!is_null($field)) { + if ($field !== null) { return isset($row[$field]) ? $row[$field] : false; } + return $row; } @@ -818,7 +928,6 @@ public function getAttributeId($entityTypeId, $id) $id = $this->getAttribute($entityTypeId, $id, 'attribute_id'); } if (!is_numeric($id)) { - //throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute ID.')); return false; } return $id; @@ -833,21 +942,27 @@ public function getAttributeId($entityTypeId, $id) */ public function getAttributeTable($entityTypeId, $id) { - $entityKeyName = is_numeric($entityTypeId) ? 'entity_type_id' : 'entity_type_code'; + $entityKeyName = is_numeric($entityTypeId) ? 'entity_type_id' : 'entity_type_code'; $attributeKeyName = is_numeric($id) ? 'attribute_id' : 'attribute_code'; + $bind = array( + 'id' => $id, + 'entity_type_id' => $entityTypeId + ); $select = $this->getConnection()->select() ->from( - array('e' => $this->getTable('eav/entity_type')), + array('entity_type' => $this->getTable('eav/entity_type')), array('entity_table')) ->join( - array('a' => $this->getTable('eav/attribute')), - 'a.entity_type_id=e.entity_type_id', + array('attribute' => $this->getTable('eav/attribute')), + 'attribute.entity_type_id = entity_type.entity_type_id', array('backend_type')) - ->where("e.{$entityKeyName}=?", $entityTypeId) - ->where("a.{$attributeKeyName}=?", $id) + ->where("entity_type.{$entityKeyName} = :entity_type_id") + ->where("attribute.{$attributeKeyName} = :id") ->limit(1); - if ($result = $this->getConnection()->fetchRow($select)) { + + $result = $this->getConnection()->fetchRow($select, $bind); + if ($result) { $table = $this->getTable($result['entity_table']); if ($result['backend_type'] != 'static') { $table .= '_' . $result['backend_type']; @@ -887,15 +1002,17 @@ public function removeAttribute($entityTypeId, $code) * @param int $sortOrder * @return Mage_Eav_Model_Entity_Setup */ - public function getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrder=null) + public function getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrder = null) { if (!is_numeric($sortOrder)) { - $sortOrder = $this->_conn->fetchOne("select max(sort_order) - from ".$this->getTable('eav/entity_attribute')." - where attribute_group_id=".$this->getAttributeGroupId($entityTypeId, $setId, $groupId) - ); - $sortOrder++; + $bind = array('attribute_group_id' => $this->getAttributeGroupId($entityTypeId, $setId, $groupId)); + $select = $this->_conn->select() + ->from($this->getTable('eav/entity_attribute'), 'MAX(sort_order)') + ->where('attribute_group_id = :attribute_group_id'); + + $sortOrder = $this->_conn->fetchOne($select, $bind) + 1; } + return $sortOrder; } @@ -911,28 +1028,39 @@ public function getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrde */ public function addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId, $sortOrder=null) { - $entityTypeId = $this->getEntityTypeId($entityTypeId); - $setId = $this->getAttributeSetId($entityTypeId, $setId); - $groupId = $this->getAttributeGroupId($entityTypeId, $setId, $groupId); - $attributeId = $this->getAttributeId($entityTypeId, $attributeId); - $generalGroupId = $this->getAttributeGroupId($entityTypeId, $setId, $this->_generalGroupName); - - $oldId = $this->_conn->fetchOne("select entity_attribute_id from ".$this->getTable('eav/entity_attribute')." where attribute_set_id=$setId and attribute_id=$attributeId"); - if ($oldId) { - if ($groupId && $groupId != $generalGroupId) { - $newGroupData = array('attribute_group_id'=>$groupId); - $condition = $this->_conn->quoteInto('entity_attribute_id = ?', $oldId); - $this->_conn->update($this->getTable('eav/entity_attribute'), $newGroupData, $condition); + $entityTypeId = $this->getEntityTypeId($entityTypeId); + $setId = $this->getAttributeSetId($entityTypeId, $setId); + $groupId = $this->getAttributeGroupId($entityTypeId, $setId, $groupId); + $attributeId = $this->getAttributeId($entityTypeId, $attributeId); + $table = $this->getTable('eav/entity_attribute'); + + $bind = array( + 'attribute_set_id' => $setId, + 'attribute_id' => $attributeId + ); + $select = $this->_conn->select() + ->from($table) + ->where('attribute_set_id = :attribute_set_id') + ->where('attribute_id = :attribute_id'); + $result = $this->_conn->fetchRow($select, $bind); + + if ($result) { + if ($result['attribute_group_id'] != $groupId) { + $where = array('entity_attribute_id =?' => $result['entity_attribute_id']); + $data = array('attribute_group_id' => $groupId); + $this->_conn->update($table, $data, $where); } - return $this; + } else { + $data = array( + 'entity_type_id' => $entityTypeId, + 'attribute_set_id' => $setId, + 'attribute_group_id' => $groupId, + 'attribute_id' => $attributeId, + 'sort_order' => $this->getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrder), + ); + + $this->_conn->insert($table, $data); } - $this->_conn->insert($this->getTable('eav/entity_attribute'), array( - 'entity_type_id' =>$entityTypeId, - 'attribute_set_id' =>$setId, - 'attribute_group_id'=>$groupId, - 'attribute_id' =>$attributeId, - 'sort_order' =>$this->getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrder), - )); return $this; } @@ -954,43 +1082,48 @@ public function addAttributeToGroup($entityType, $setId, $groupId, $attributeId, $groupId = $this->getAttributeGroupId($entityType, $setId, $groupId); $attributeId = $this->getAttributeId($entityType, $attributeId); - $bind = array( + $data = array( 'entity_type_id' => $entityType, 'attribute_set_id' => $setId, 'attribute_group_id' => $groupId, 'attribute_id' => $attributeId, ); + $bind = array( + 'entity_type_id' => $entityType, + 'attribute_set_id' => $setId, + 'attribute_id' => $attributeId + ); $select = $this->getConnection()->select() ->from($this->getTable('eav/entity_attribute')) - ->where('entity_type_id=?', $entityType) - ->where('attribute_set_id=?', $setId) - ->where('attribute_id=?', $attributeId); - $row = $this->getConnection()->fetchRow($select); + ->where('entity_type_id = :entity_type_id') + ->where('attribute_set_id = :attribute_set_id') + ->where('attribute_id = :attribute_id'); + $row = $this->getConnection()->fetchRow($select, $bind); if ($row) { // update - if (!is_null($sortOrder)) { - $bind['sort_order'] = $sortOrder; + if ($sortOrder !== null) { + $data['sort_order'] = $sortOrder; } $this->getConnection()->update( $this->getTable('eav/entity_attribute'), - $bind, + $data, $this->getConnection()->quoteInto('entity_attribute_id=?', $row['entity_attribute_id']) ); - } - else { - if (is_null($sortOrder)) { + } else { + if ($sortOrder === null) { $select = $this->getConnection()->select() - ->from($this->getTable('eav/entity_attribute'), 'MAX(sort_order) + 10') - ->where('entity_type_id=?', $entityType) - ->where('attribute_set_id=?', $setId) - ->where('attribute_group_id=?', $groupId); - $sortOrder = $this->getConnection()->fetchOne($select); + ->from($this->getTable('eav/entity_attribute'), 'MAX(sort_order)') + ->where('entity_type_id = :entity_type_id') + ->where('attribute_set_id = :attribute_set_id') + ->where('attribute_id = :attribute_id'); + + $sortOrder = $this->getConnection()->fetchOne($select, $bind) + 10; } $sortOrder = is_numeric($sortOrder) ? $sortOrder : 1; - $bind['sort_order'] = $sortOrder; - $this->getConnection()->insert($this->getTable('eav/entity_attribute'), $bind); + $data['sort_order'] = $sortOrder; + $this->getConnection()->insert($this->getTable('eav/entity_attribute'), $data); } return $this; @@ -1004,11 +1137,11 @@ public function addAttributeToGroup($entityType, $setId, $groupId, $attributeId, * @param array $entities * @return Mage_Eav_Model_Entity_Setup */ - public function installEntities($entities=null) + public function installEntities($entities = null) { $this->cleanCache(); - if (is_null($entities)) { + if ($entities === null) { $entities = $this->getDefaultEntities(); } @@ -1016,33 +1149,33 @@ public function installEntities($entities=null) $this->addEntityType($entityName, $entity); $frontendPrefix = isset($entity['frontend_prefix']) ? $entity['frontend_prefix'] : ''; - $backendPrefix = isset($entity['backend_prefix']) ? $entity['backend_prefix'] : ''; - $sourcePrefix = isset($entity['source_prefix']) ? $entity['source_prefix'] : ''; + $backendPrefix = isset($entity['backend_prefix']) ? $entity['backend_prefix'] : ''; + $sourcePrefix = isset($entity['source_prefix']) ? $entity['source_prefix'] : ''; - foreach ($entity['attributes'] as $attrCode=>$attr) { + foreach ($entity['attributes'] as $attrCode => $attr) { if (!empty($attr['backend'])) { - if ('_'===$attr['backend']) { + if ('_' === $attr['backend']) { $attr['backend'] = $backendPrefix; - } elseif ('_'===$attr['backend']{0}) { + } elseif ('_' === $attr['backend']{0}) { $attr['backend'] = $backendPrefix.$attr['backend']; } else { $attr['backend'] = $attr['backend']; } } if (!empty($attr['frontend'])) { - if ('_'===$attr['frontend']) { + if ('_' === $attr['frontend']) { $attr['frontend'] = $frontendPrefix; - } elseif ('_'===$attr['frontend']{0}) { + } elseif ('_' === $attr['frontend']{0}) { $attr['frontend'] = $frontendPrefix.$attr['frontend']; } else { $attr['frontend'] = $attr['frontend']; } } if (!empty($attr['source'])) { - if ('_'===$attr['source']) { + if ('_' === $attr['source']) { $attr['source'] = $sourcePrefix; - } elseif ('_'===$attr['source']{0}) { - $attr['source'] = $sourcePrefix.$attr['source']; + } elseif ('_' === $attr['source']{0}) { + $attr['source'] = $sourcePrefix . $attr['source']; } else { $attr['source'] = $attr['source']; } @@ -1060,79 +1193,170 @@ public function installEntities($entities=null) /****************************** CREATE ENTITY TABLES ***********************************/ /** - * Enter description here... + * Create entity tables * - * @param unknown_type $baseName + * @param string $baseName * @param array $options * - no-main * - no-default-types * - types * @return unknown */ - public function createEntityTables($baseName, array $options=array()) + public function createEntityTables($baseTableName, array $options = array()) { - $sql = ''; - - if (empty($options['no-main'])) { - $sql = " -DROP TABLE IF EXISTS `{$baseName}`; -CREATE TABLE `{$baseName}` ( -`entity_id` int(10) unsigned NOT NULL auto_increment, -`entity_type_id` smallint(8) unsigned NOT NULL default '0', -`attribute_set_id` smallint(5) unsigned NOT NULL default '0', -`increment_id` varchar(50) NOT NULL default '', -`parent_id` int(10) unsigned NULL default '0', -`store_id` smallint(5) unsigned NOT NULL default '0', -`created_at` datetime NOT NULL default '0000-00-00 00:00:00', -`updated_at` datetime NOT NULL default '0000-00-00 00:00:00', -`is_active` tinyint(1) unsigned NOT NULL default '1', -PRIMARY KEY (`entity_id`), -CONSTRAINT `FK_{$baseName}_type` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE, -CONSTRAINT `FK_{$baseName}_store` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + $isNoCreateMainTable = $this->_getValue($options, 'no-main', false); + $isNoDefaultTypes = $this->_getValue($options, 'no-default-types', false); + $customTypes = $this->_getValue($options, 'types', array()); + $tables = array(); + + if (!$isNoCreateMainTable) { + /** + * Create table main eav table + */ + $connection = $this->getConnection(); + $mainTable = $connection + ->newTable($this->getTable($baseTableName)) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Set Id') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Increment Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Defines Is Entity Active') + ->addIndex($this->getIdxName($baseTableName, array('entity_type_id')), + array('entity_type_id')) + ->addIndex($this->getIdxName($baseTableName, array('store_id')), + array('store_id')) + ->addForeignKey($this->getFkName($baseTableName, 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $this->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($this->getFkName($baseTableName, 'store_id', 'core/store', 'store_id'), + 'store_id', $this->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Main Table'); + + $tables[$this->getTable($baseTableName)] = $mainTable; } - $types = array( - 'datetime'=>'datetime', - 'decimal'=>'decimal(12,4)', - 'int'=>'int', - 'text'=>'text', - 'varchar'=>'varchar(255)', - ); - if (!empty($options['types']) && is_array($options['types'])) { - if ($options['no-default-types']) { - $types = array(); + $types = array(); + if (!$isNoDefaultTypes) { + $types = array( + 'datetime' => array(Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null), + 'decimal' => array(Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4'), + 'int' => array(Varien_Db_Ddl_Table::TYPE_INTEGER, null), + 'text' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '64k'), + 'varchar' => array(Varien_Db_Ddl_Table::TYPE_TEXT, '255') + ); + } + + if (!empty($customTypes)) { + foreach ($customTypes as $type => $fieldType) { + if (count($fieldType) != 2) { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong type definition for %s', $type)); + } + $types[$type] = $fieldType; } - $types = array_merge($types, $options['types']); } - foreach ($types as $type=>$fieldType) { - $sql .= " -DROP TABLE IF EXISTS `{$baseName}_{$type}`; -CREATE TABLE `{$baseName}_{$type}` ( -`value_id` int(11) NOT NULL auto_increment, -`entity_type_id` smallint(8) unsigned NOT NULL default '0', -`attribute_id` smallint(5) unsigned NOT NULL default '0', -`store_id` smallint(5) unsigned NOT NULL default '0', -`entity_id` int(10) unsigned NOT NULL default '0', -`value` {$fieldType} NOT NULL, -PRIMARY KEY (`value_id`), -UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`), -".($type!=='text' ? " -KEY `value_by_attribute` (`attribute_id`,`value`), -KEY `value_by_entity_type` (`entity_type_id`,`value`), -" : "")." -CONSTRAINT `FK_{$baseName}_{$type}` FOREIGN KEY (`entity_id`) REFERENCES `{$baseName}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, -CONSTRAINT `FK_{$baseName}_{$type}_attribute` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE, -CONSTRAINT `FK_{$baseName}_{$type}_entity_type` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE, -CONSTRAINT `FK_{$baseName}_{$type}_store` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + /** + * Create table array($baseTableName, $type) + */ + foreach ($types as $type => $fieldType) { + $eavTableName = array($baseTableName, $type); + + $eavTable = $connection + ->newTable($this->getTable($eavTableName)) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', $fieldType[0], $fieldType[1], array( + 'nullable' => false, + ), 'Attribute Value') + ->addIndex($this->getIdxName($eavTableName, array('entity_type_id')), + array('entity_type_id')) + ->addIndex($this->getIdxName($eavTableName, array('attribute_id')), + array('attribute_id')) + ->addIndex($this->getIdxName($eavTableName, array('store_id')), + array('store_id')) + ->addIndex($this->getIdxName($eavTableName, array('entity_id')), + array('entity_id')) + ->addIndex($this->getIdxName($eavTableName, array('attribute_id', 'value')), + array('attribute_id', 'value')) + ->addIndex($this->getIdxName($eavTableName, array('entity_type_id', 'value')), + array('entity_type_id', 'value')) + ->addForeignKey($this->getFkName($eavTableName, 'entity_id', 'eav/entity', 'entity_id'), + 'entity_id', $this->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($this->getFkName($eavTableName, 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $this->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($this->getFkName($eavTableName, 'store_id', 'core/store', 'store_id'), + 'store_id', $this->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Table'); + + $tables[$this->getTable($eavTableName)] = $eavTable; } + $connection->beginTransaction(); try { - $this->_conn->multi_query($sql); + foreach ($tables as $tableName => $table) { + $connection->createTable($table); + } + $connection->commit(); } catch (Exception $e) { - throw $e; + $connection->rollBack(); + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Can\'t create table: %s', $tableName)); } return $this; @@ -1143,23 +1367,26 @@ public function createEntityTables($baseName, array $options=array()) * * @return array */ - protected function _getAttributeTableFields() { + protected function _getAttributeTableFields() + { return $this->getConnection()->describeTable($this->getTable('eav/attribute')); } /** * Insert attribute and filter data * + * @param array $data * @return Mage_Eav_Model_Entity_Setup */ - protected function _insertAttribute(array $data) { + protected function _insertAttribute(array $data) + { $bind = array(); $fields = $this->_getAttributeTableFields(); foreach ($data as $k => $v) { if (isset($fields[$k])) { - $bind[$k] = $v; + $bind[$k] = $this->getConnection()->prepareColumnValue($fields[$k], $v); } } if (!$bind) { @@ -1167,17 +1394,19 @@ protected function _insertAttribute(array $data) { } $this->getConnection()->insert($this->getTable('eav/attribute'), $bind); - $attributeId = $this->getConnection()->lastInsertId(); + $attributeId = $this->getConnection()->lastInsertId($this->getTable('eav/attribute')); $this->_insertAttributeAdditionalData( $data['entity_type_id'], array_merge(array('attribute_id' => $attributeId), $data) ); + return $this; } /** * Insert attribute additional data * + * @param int $entityTypeId * @param array $data * @return Mage_Eav_Model_Entity_Setup */ @@ -1187,13 +1416,13 @@ protected function _insertAttributeAdditionalData($entityTypeId, array $data) if (!$additionalTable) { return $this; } - $additionalTableExists = $this->getConnection()->showTableStatus($this->getTable($additionalTable)); + $additionalTableExists = $this->getConnection()->isTableExists($this->getTable($additionalTable)); if ($additionalTable && $additionalTableExists) { $bind = array(); $fields = $this->getConnection()->describeTable($this->getTable($additionalTable)); foreach ($data as $k => $v) { if (isset($fields[$k])) { - $bind[$k] = $v; + $bind[$k] = $this->getConnection()->prepareColumnValue($fields[$k], $v); } } if (!$bind) { @@ -1201,6 +1430,7 @@ protected function _insertAttributeAdditionalData($entityTypeId, array $data) } $this->getConnection()->insert($this->getTable($additionalTable), $bind); } + return $this; } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Store.php b/app/code/core/Mage/Eav/Model/Entity/Store.php index 28447c0664..50c85621f7 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Store.php +++ b/app/code/core/Mage/Eav/Model/Entity/Store.php @@ -20,18 +20,46 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Entity_Store extends Mage_Core_Model_Abstract +/** + * Enter description here ... + * + * @method Mage_Eav_Model_Resource_Entity_Store _getResource() + * @method Mage_Eav_Model_Resource_Entity_Store getResource() + * @method int getEntityTypeId() + * @method Mage_Eav_Model_Entity_Store setEntityTypeId(int $value) + * @method int getStoreId() + * @method Mage_Eav_Model_Entity_Store setStoreId(int $value) + * @method string getIncrementPrefix() + * @method Mage_Eav_Model_Entity_Store setIncrementPrefix(string $value) + * @method string getIncrementLastId() + * @method Mage_Eav_Model_Entity_Store setIncrementLastId(string $value) + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Entity_Store extends Mage_Core_Model_Abstract { + /** + * Resource initialization + */ protected function _construct() { $this->_init('eav/entity_store'); } - + + /** + * Load entity by store + * + * @param int $entityTypeId + * @param int $storeId + * @return Mage_Eav_Model_Entity_Store + */ public function loadByEntityStore($entityTypeId, $storeId) { $this->_getResource()->loadByEntityStore($this, $entityTypeId, $storeId); diff --git a/app/code/core/Mage/Eav/Model/Entity/Type.php b/app/code/core/Mage/Eav/Model/Entity/Type.php index 16302ad01d..15ee7b7bf8 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Type.php +++ b/app/code/core/Mage/Eav/Model/Entity/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,37 +28,61 @@ /** * Entity type model * - * @category Mage - * @package Mage_Eav + * @method Mage_Eav_Model_Resource_Entity_Type _getResource() + * @method Mage_Eav_Model_Resource_Entity_Type getResource() + * @method Mage_Eav_Model_Entity_Type setEntityTypeCode(string $value) + * @method string getEntityModel() + * @method Mage_Eav_Model_Entity_Type setEntityModel(string $value) + * @method Mage_Eav_Model_Entity_Type setAttributeModel(string $value) + * @method Mage_Eav_Model_Entity_Type setEntityTable(string $value) + * @method Mage_Eav_Model_Entity_Type setValueTablePrefix(string $value) + * @method Mage_Eav_Model_Entity_Type setEntityIdField(string $value) + * @method int getIsDataSharing() + * @method Mage_Eav_Model_Entity_Type setIsDataSharing(int $value) + * @method string getDataSharingKey() + * @method Mage_Eav_Model_Entity_Type setDataSharingKey(string $value) + * @method Mage_Eav_Model_Entity_Type setDefaultAttributeSetId(int $value) + * @method string getIncrementModel() + * @method Mage_Eav_Model_Entity_Type setIncrementModel(string $value) + * @method int getIncrementPerStore() + * @method Mage_Eav_Model_Entity_Type setIncrementPerStore(int $value) + * @method int getIncrementPadLength() + * @method Mage_Eav_Model_Entity_Type setIncrementPadLength(int $value) + * @method string getIncrementPadChar() + * @method Mage_Eav_Model_Entity_Type setIncrementPadChar(string $value) + * @method string getAdditionalAttributeTable() + * @method Mage_Eav_Model_Entity_Type setAdditionalAttributeTable(string $value) + * @method Mage_Eav_Model_Entity_Type setEntityAttributeCollection(string $value) + * + * @category Mage + * @package Mage_Eav * @author Magento Core Team */ class Mage_Eav_Model_Entity_Type extends Mage_Core_Model_Abstract { - /** - * Enter description here... + * Collection of attributes * * @var Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ protected $_attributes; /** - * Enter description here... + * Array of attributes * * @var array */ - protected $_attributesBySet = array(); + protected $_attributesBySet = array(); /** - * Enter description here... + * Collection of sets * * @var Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection */ protected $_sets; /** - * Enter description here... - * + * Resource initialization */ protected function _construct() { @@ -66,7 +90,7 @@ protected function _construct() } /** - * Enter description here... + * Load type by code * * @param string $code * @return Mage_Eav_Model_Entity_Type @@ -86,14 +110,13 @@ public function loadByCode($code) */ public function getAttributeCollection($setId = null) { - if (is_null($setId)) { - if (is_null($this->_attributes)) { + if ($setId === null) { + if ($this->_attributes === null) { $this->_attributes = $this->_getAttributeCollection() ->setEntityTypeFilter($this); } $collection = $this->_attributes; - } - else { + } else { if (!isset($this->_attributesBySet[$setId])) { $this->_attributesBySet[$setId] = $this->_getAttributeCollection() ->setEntityTypeFilter($this) @@ -101,20 +124,23 @@ public function getAttributeCollection($setId = null) } $collection = $this->_attributesBySet[$setId]; } + return $collection; } /** - * Enter description here... + * Init and retreive attribute collection * * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ protected function _getAttributeCollection() { $collection = Mage::getModel('eav/entity_attribute')->getCollection(); - if ($objectsModel = $this->getAttributeModel()) { + $objectsModel = $this->getAttributeModel(); + if ($objectsModel) { $collection->setModel($objectsModel); } + return $collection; } @@ -133,26 +159,22 @@ public function getAttributeSetCollection() } /** - * Enter description here... + * Retreive new incrementId * * @param int $storeId * @return string */ - public function fetchNewIncrementId($storeId=null) + public function fetchNewIncrementId($storeId = null) { if (!$this->getIncrementModel()) { return false; } - if (!$this->getIncrementPerStore()) { - $storeId = 0; - } - elseif (is_null($storeId)) { + if (!$this->getIncrementPerStore() || ($storeId === null)) { /** * store_id null we can have for entity from removed store */ $storeId = 0; - //throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Valid store_id is expected.')); } // Start transaction to run SELECT ... FOR UPDATE @@ -192,9 +214,9 @@ public function fetchNewIncrementId($storeId=null) } /** - * Enter description here... + * Retreive entity id field * - * @return string + * @return string|null */ public function getEntityIdField() { @@ -202,9 +224,9 @@ public function getEntityIdField() } /** - * Enter description here... + * Retreive entity table name * - * @return string + * @return string|null */ public function getEntityTable() { @@ -212,43 +234,71 @@ public function getEntityTable() } /** - * Enter description here... + * Retrieve entity table prefix name * * @return string */ public function getValueTablePrefix() { - if (empty($this->_data['value_table_prefix'])) { - $this->_data['value_table_prefix'] = $this->_getResource()->getTable($this->getEntityTable()); + $prefix = $this->getEntityTablePrefix(); + if ($prefix) { + return $this->getResource()->getTable($prefix); } - return $this->_data['value_table_prefix']; + + return null; } /** - * Get default attribute set identifier for etity type + * Retrieve entity table prefix * * @return string */ + public function getEntityTablePrefix() + { + $tablePrefix = trim($this->_data['value_table_prefix']); + + if (empty($tablePrefix)) { + $tablePrefix = $this->getEntityTable(); + } + + return $tablePrefix; + } + + /** + * Get default attribute set identifier for etity type + * + * @return string|null + */ public function getDefaultAttributeSetId() { return isset($this->_data['default_attribute_set_id']) ? $this->_data['default_attribute_set_id'] : null; } /** - * Enter description here... + * Retreive entity type id * - * @return string + * @return string|null */ public function getEntityTypeId() { return isset($this->_data['entity_type_id']) ? $this->_data['entity_type_id'] : null; } + /** + * Retreive entity type code + * + * @return string|null + */ public function getEntityTypeCode() { return isset($this->_data['entity_type_code']) ? $this->_data['entity_type_code'] : null; } + /** + * Retreive attribute codes + * + * @return array|null + */ public function getAttributeCodes() { return isset($this->_data['attribute_codes']) ? $this->_data['attribute_codes'] : null; @@ -264,11 +314,15 @@ public function getAttributeModel() if (empty($this->_data['attribute_model'])) { return Mage_Eav_Model_Entity::DEFAULT_ATTRIBUTE_MODEL; } - else { - return $this->_data['attribute_model']; - } + + return $this->_data['attribute_model']; } + /** + * Retreive resource entity object + * + * @return Mage_Core_Model_Resource_Abstract + */ public function getEntity() { return Mage::getResourceSingleton($this->_data['entity_model']); @@ -281,7 +335,8 @@ public function getEntity() */ public function getEntityAttributeCollection() { - if ($collection = $this->_getData('entity_attribute_collection')) { + $collection = $this->_getData('entity_attribute_collection'); + if ($collection) { return $collection; } return 'eav/entity_attribute_collection'; diff --git a/app/code/core/Mage/Eav/Model/Form/Element.php b/app/code/core/Mage/Eav/Model/Form/Element.php index 462cd7842c..9292c6ddaf 100644 --- a/app/code/core/Mage/Eav/Model/Form/Element.php +++ b/app/code/core/Mage/Eav/Model/Form/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,17 @@ /** * Eav Form Element Model * + * @method Mage_Eav_Model_Resource_Form_Element _getResource() + * @method Mage_Eav_Model_Resource_Form_Element getResource() + * @method int getTypeId() + * @method Mage_Eav_Model_Form_Element setTypeId(int $value) + * @method int getFieldsetId() + * @method Mage_Eav_Model_Form_Element setFieldsetId(int $value) + * @method int getAttributeId() + * @method Mage_Eav_Model_Form_Element setAttributeId(int $value) + * @method int getSortOrder() + * @method Mage_Eav_Model_Form_Element setSortOrder(int $value) + * * @category Mage * @package Mage_Eav * @author Magento Core Team diff --git a/app/code/core/Mage/Eav/Model/Form/Fieldset.php b/app/code/core/Mage/Eav/Model/Form/Fieldset.php index 34916219e1..36e68879e9 100644 --- a/app/code/core/Mage/Eav/Model/Form/Fieldset.php +++ b/app/code/core/Mage/Eav/Model/Form/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,15 @@ /** * Eav Form Fieldset Model * + * @method Mage_Eav_Model_Resource_Form_Fieldset _getResource() + * @method Mage_Eav_Model_Resource_Form_Fieldset getResource() + * @method int getTypeId() + * @method Mage_Eav_Model_Form_Fieldset setTypeId(int $value) + * @method string getCode() + * @method Mage_Eav_Model_Form_Fieldset setCode(string $value) + * @method int getSortOrder() + * @method Mage_Eav_Model_Form_Fieldset setSortOrder(int $value) + * * @category Mage * @package Mage_Eav * @author Magento Core Team diff --git a/app/code/core/Mage/Eav/Model/Form/Type.php b/app/code/core/Mage/Eav/Model/Form/Type.php index cc8cec4ce3..704583f470 100644 --- a/app/code/core/Mage/Eav/Model/Form/Type.php +++ b/app/code/core/Mage/Eav/Model/Form/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,19 @@ /** * Eav Form Type Model * + * @method Mage_Eav_Model_Resource_Form_Type _getResource() + * @method Mage_Eav_Model_Resource_Form_Type getResource() + * @method string getCode() + * @method Mage_Eav_Model_Form_Type setCode(string $value) + * @method string getLabel() + * @method Mage_Eav_Model_Form_Type setLabel(string $value) + * @method int getIsSystem() + * @method Mage_Eav_Model_Form_Type setIsSystem(int $value) + * @method string getTheme() + * @method Mage_Eav_Model_Form_Type setTheme(string $value) + * @method int getStoreId() + * @method Mage_Eav_Model_Form_Type setStoreId(int $value) + * * @category Mage * @package Mage_Eav * @author Magento Core Team diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Config.php b/app/code/core/Mage/Eav/Model/Mysql4/Config.php index 3eee79da6c..191740f5fc 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Config.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Config.php @@ -20,76 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Config extends Mage_Eav_Model_Resource_Config { - protected static $_entityTypes; - protected static $_attributes = array(); - - protected function _construct() - { - $this->_init('eav/entity_type', 'entity_type_id'); - } - - /** - * Load all entity types - * - * @return Mage_Eav_Model_Mysql4_Config - */ - protected function _loadTypes() - { - if (!$this->_getReadAdapter()) { - self::$_entityTypes = array(); - return $this; - } - if (is_null(self::$_entityTypes)) { - self::$_entityTypes = array(); - $select = $this->_getReadAdapter()->select()->from($this->getMainTable()); - $data = $this->_getReadAdapter()->fetchAll($select); - foreach ($data as $row) { - self::$_entityTypes['by_id'][$row['entity_type_id']] = $row; - self::$_entityTypes['by_code'][$row['entity_type_code']] = $row; - } - } - - return $this; - } - - protected function _loadTypeAttributes($typeId) - { - if (!isset(self::$_attributes[$typeId])) { - $select = $this->_getReadAdapter()->select()->from($this->getTable('eav/attribute')) - ->where('entity_type_id=?', $typeId); - self::$_attributes[$typeId] = $this->_getReadAdapter()->fetchAll($select); - } - return self::$_attributes[$typeId]; - } - - public function fetchEntityTypeData($entityType) - { - $this->_loadTypes(); - - if (is_numeric($entityType)) { - $info = isset(self::$_entityTypes['by_id'][$entityType]) ? self::$_entityTypes['by_id'][$entityType] : null; - } - else { - $info = isset(self::$_entityTypes['by_code'][$entityType]) ? self::$_entityTypes['by_code'][$entityType] : null; - } - - $data = array(); - if ($info) { - $data['entity'] = $info; - $attributes = $this->_loadTypeAttributes($info['entity_type_id']); - $data['attributes'] = array(); - foreach ($attributes as $attribute) { - $data['attributes'][$attribute['attribute_id']] = $attribute; - $data['attributes'][$attribute['attribute_code']] = $attribute['attribute_id']; - } - } - return $data; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute.php index 4157be4d5e..4415f24d65 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,520 +28,10 @@ /** * EAV attribute model * - * @category Mage - * @package Mage_Eav + * @category Mage + * @package Mage_Eav + * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Attribute extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Entity_Attribute extends Mage_Eav_Model_Resource_Entity_Attribute { - protected static $_entityAttributes = null; - - protected function _construct() - { - $this->_init('eav/attribute', 'attribute_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => array('attribute_code','entity_type_id'), - 'title' => Mage::helper('eav')->__('Attribute with the same code') - )); - return $this; - } - - protected function _loadTypeAttributes($entityTypeId) - { - if (!isset(self::$_entityAttributes[$entityTypeId])) { - $select = $this->_getReadAdapter()->select()->from($this->getMainTable()) - ->where('entity_type_id=?', $entityTypeId); - $data = $this->_getReadAdapter()->fetchAll($select); - foreach ($data as $row) { - self::$_entityAttributes[$entityTypeId][$row['attribute_code']] = $row; - } - } - return $this; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @param int $entityTypeId - * @param string $code - * @return boolean - */ - public function loadByCode(Mage_Core_Model_Abstract $object, $entityTypeId, $code) - { - $select = $this->_getLoadSelect('attribute_code', $code, $object) - ->where('entity_type_id=?', $entityTypeId); - $data = $this->_getReadAdapter()->fetchRow($select); - - if ($data) { - $object->setData($data); - $this->_afterLoad($object); - return true; - } - return false; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return int - */ - private function _getMaxSortOrder(Mage_Core_Model_Abstract $object) - { - if( intval($object->getAttributeGroupId()) > 0 ) { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from($this->getTable('entity_attribute'), new Zend_Db_Expr("MAX(`sort_order`)")) - ->where("{$this->getTable('entity_attribute')}.attribute_set_id = ?", $object->getAttributeSetId()) - ->where("{$this->getTable('entity_attribute')}.attribute_group_id = ?", $object->getAttributeGroupId()); - $maxOrder = $read->fetchOne($select); - return $maxOrder; - } - - return 0; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - public function deleteEntity(Mage_Core_Model_Abstract $object) - { - $write = $this->_getWriteAdapter(); - $condition = $write->quoteInto($this->getTable('entity_attribute').'.entity_attribute_id = ?', $object->getEntityAttributeId()); - /** - * Delete attribute values - */ - $select = $write->select() - ->from($this->getTable('entity_attribute')) - ->where($condition); - $data = $write->fetchRow($select); - if (!empty($data)) { - /** - * @todo !!!! need fix retrieving attribute entity, this realization is temprary - */ - $attribute = Mage::getModel('eav/entity_attribute') - ->load($data['attribute_id']) - ->setEntity(Mage::getSingleton('catalog/product')->getResource()); - - if ($this->isUsedBySuperProducts($attribute, $data['attribute_set_id'])) { - Mage::throwException(Mage::helper('eav')->__("Attribute '%s' used in configurable products.", $attribute->getAttributeCode())); - } - - if ($backendTable = $attribute->getBackend()->getTable()) { - $clearCondition = array( - $write->quoteInto('entity_type_id=?',$attribute->getEntityTypeId()), - $write->quoteInto('attribute_id=?',$attribute->getId()), - $write->quoteInto('entity_id IN ( - SELECT entity_id FROM '.$attribute->getEntity()->getEntityTable().' WHERE attribute_set_id=?)', - $data['attribute_set_id']) - ); - $write->delete($backendTable, $clearCondition); - } - } - - $write->delete($this->getTable('entity_attribute'), $condition); - return $this; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $frontendLabel = $object->getFrontendLabel(); - if (is_array($frontendLabel)) { - if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0]=='') { - Mage::throwException(Mage::helper('eav')->__('Frontend label is not defined.')); - } - $object->setFrontendLabel($frontendLabel[0]); - $object->setStoreLabels($frontendLabel); - } - - /** - * @todo need use default source model of entity type !!! - */ - if (!$object->getId()) { - if ($object->getFrontendInput()=='select') { - $object->setSourceModel('eav/entity_attribute_source_table'); - } - } - - return parent::_beforeSave($object); - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $this->_saveStoreLabels($object) - ->_saveAdditionalAttributeData($object) - ->saveInSetIncluding($object) - ->_saveOption($object); - return parent::_afterSave($object); - } - - /** - * Save store labels - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _saveStoreLabels(Mage_Core_Model_Abstract $object) - { - $storeLabels = $object->getStoreLabels(); - if (is_array($storeLabels)) { - if ($object->getId()) { - $condition = $this->_getWriteAdapter()->quoteInto('attribute_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('eav/attribute_label'), $condition); - } - foreach ($storeLabels as $storeId => $label) { - if ($storeId == 0 || !strlen($label)) { - continue; - } - $this->_getWriteAdapter()->insert( - $this->getTable('eav/attribute_label'), - array( - 'attribute_id' => $object->getId(), - 'store_id' => $storeId, - 'value' => $label - ) - ); - } - } - return $this; - } - - /** - * Save additional data of attribute - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _saveAdditionalAttributeData(Mage_Core_Model_Abstract $object) - { - if ($additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId())) { - $describe = $this->describeTable($this->getTable($additionalTable)); - $data = array(); - foreach (array_keys($describe) as $field) { - if (null !== ($value = $object->getData($field))) { - $data[$field] = $value; - } - } - $select = $this->_getWriteAdapter()->select() - ->from($this->getTable($additionalTable), array('attribute_id')) - ->where('attribute_id = ?', $object->getId()); - if ($this->_getWriteAdapter()->fetchOne($select)) { - $this->_getWriteAdapter()->update( - $this->getTable($additionalTable), - $data, - $this->_getWriteAdapter()->quoteInto('attribute_id = ?', $object->getId()) - ); - } else { - $this->_getWriteAdapter()->insert($this->getTable($additionalTable), $data); - } - } - return $this; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - public function saveInSetIncluding(Mage_Core_Model_Abstract $object) - { - $attrId = $object->getId(); - $setId = (int) $object->getAttributeSetId(); - $groupId= (int) $object->getAttributeGroupId(); - - if ($setId && $groupId && $object->getEntityTypeId()) { - $write = $this->_getWriteAdapter(); - $table = $this->getTable('entity_attribute'); - - - $data = array( - 'entity_type_id' => $object->getEntityTypeId(), - 'attribute_set_id' => $setId, - 'attribute_group_id' => $groupId, - 'attribute_id' => $attrId, - 'sort_order' => (($object->getSortOrder()) ? $object->getSortOrder() : $this->_getMaxSortOrder($object) + 1), - ); - - $condition = "$table.attribute_id = '$attrId' - AND $table.attribute_set_id = '$setId'"; - $write->delete($table, $condition); - $write->insert($table, $data); - - } - return $this; - } - - /** - * Enter description here... - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _saveOption(Mage_Core_Model_Abstract $object) - { - $option = $object->getOption(); - if (is_array($option)) { - $write = $this->_getWriteAdapter(); - $optionTable = $this->getTable('attribute_option'); - $optionValueTable = $this->getTable('attribute_option_value'); - $stores = Mage::getModel('core/store') - ->getResourceCollection() - ->setLoadDefault(true) - ->load(); - - if (isset($option['value'])) { - $attributeDefaultValue = array(); - if (!is_array($object->getDefault())) { - $object->setDefault(array()); - } - - foreach ($option['value'] as $optionId => $values) { - $intOptionId = (int) $optionId; - if (!empty($option['delete'][$optionId])) { - if ($intOptionId) { - $condition = $write->quoteInto('option_id=?', $intOptionId); - $write->delete($optionTable, $condition); - } - - continue; - } - - if (!$intOptionId) { - $data = array( - 'attribute_id' => $object->getId(), - 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, - ); - $write->insert($optionTable, $data); - $intOptionId = $write->lastInsertId(); - } - else { - $data = array( - 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, - ); - $write->update($optionTable, $data, $write->quoteInto('option_id=?', $intOptionId)); - } - - if (in_array($optionId, $object->getDefault())) { - if ($object->getFrontendInput() == 'multiselect') { - $attributeDefaultValue[] = $intOptionId; - } else if ($object->getFrontendInput() == 'select') { - $attributeDefaultValue = array($intOptionId); - } - } - - - // Default value - if (!isset($values[0])) { - Mage::throwException(Mage::helper('eav')->__('Default option value is not defined.')); - } - - $write->delete($optionValueTable, $write->quoteInto('option_id=?', $intOptionId)); - foreach ($stores as $store) { - if (isset($values[$store->getId()]) && (!empty($values[$store->getId()]) || $values[$store->getId()] == "0")) { - $data = array( - 'option_id' => $intOptionId, - 'store_id' => $store->getId(), - 'value' => $values[$store->getId()], - ); - $write->insert($optionValueTable, $data); - } - } - } - - $write->update($this->getMainTable(), array( - 'default_value' => implode(',', $attributeDefaultValue) - ), $write->quoteInto($this->getIdFieldName() . '=?', $object->getId())); - } - } - return $this; - } - - public function isUsedBySuperProducts(Mage_Core_Model_Abstract $object, $attributeSet=null) - { - $read = $this->_getReadAdapter(); - $attrTable = $this->getTable('catalog/product_super_attribute'); - $productTable = $this->getTable('catalog/product'); - $select = $read->select() - ->from(array('_main_table' => $attrTable), 'COUNT(*)') - ->join(array('_entity'=> $productTable), '_main_table.product_id = _entity.entity_id') - ->where("_main_table.attribute_id = ?", $object->getAttributeId()) - ->group('_main_table.attribute_id') - ->limit(1); - - if (!is_null($attributeSet)) { - $select->where('_entity.attribute_set_id = ?', $attributeSet); - } - $valueCount = $read->fetchOne($select); - return $valueCount; - } - - /** - * Return attribute id - * - * @param string $entityType - * @param string $code - * @return int - */ - public function getIdByCode($entityType, $code) - { - $select = $this->_getReadAdapter()->select() - ->from(array('a'=>$this->getTable('eav/attribute')), array('a.attribute_id')) - ->join(array('t'=>$this->getTable('eav/entity_type')), 'a.entity_type_id = t.entity_type_id', array()) - ->where('t.entity_type_code = ?', $entityType) - ->where('a.attribute_code = ?', $code); - - return $this->_getReadAdapter()->fetchOne($select); - } - - public function getAttributeCodesByFrontendType($type) - { - $select = $this->_getReadAdapter()->select(); - $select - ->from($this->getTable('eav/attribute'), 'attribute_code') - ->where('frontend_input = ?', $type); - - $result = $this->_getReadAdapter()->fetchCol($select); - - if ($result) { - return $result; - } else { - return array(); - } - } - - /** - * Retrieve Select For Flat Attribute update - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param int $store - * @return Varien_Db_Select - */ - public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $store) - { - $joinConditionTemplate = "`e`.`entity_id`=`%s`.`entity_id`" - ." AND `%s`.`entity_type_id` = ".$attribute->getEntityTypeId() - ." AND `%s`.`attribute_id` = ".$attribute->getId() - ." AND `%s`.`store_id` = %d"; - $joinCondition = sprintf($joinConditionTemplate, 't1', 't1', 't1', 't1', Mage_Core_Model_App::ADMIN_STORE_ID); - if ($attribute->getFlatAddChildData()) { - $joinCondition .= " AND `e`.`child_id`=`t1`.`entity_id`"; - } - $select = $this->_getReadAdapter()->select() - ->joinLeft( - array('t1' => $attribute->getBackend()->getTable()), - $joinCondition, - array() - ) - ->joinLeft( - array('t2' => $attribute->getBackend()->getTable()), - sprintf($joinConditionTemplate, 't2', 't2', 't2', 't2', $store), - array($attribute->getAttributeCode() => "IF(t2.value_id>0, t2.value, t1.value)")); - if ($attribute->getFlatAddChildData()) { - $select->where("e.is_child=?", 0); - } - return $select; - } - - /** - * Describe table - * - * @param string $table - * @return array - */ - public function describeTable($table) { - return $this->_getReadAdapter()->describeTable($table); - } - - /** - * Retrieve additional attribute table name for specified entity type - * - * @param integer $entityTypeId - * @return string - */ - public function getAdditionalAttributeTable($entityTypeId) - { - return Mage::getResourceSingleton('eav/entity_type')->getAdditionalAttributeTable($entityTypeId); - } - - /** - * Load additional attribute data. - * Load label of current active store - * - * @param Varien_Object $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - if ($entityType = $object->getData('entity_type')) { - $additionalTable = $entityType->getAdditionalAttributeTable(); - } else { - $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId()); - } - if ($additionalTable) { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable($additionalTable)) - ->where('attribute_id = ?', $object->getId()); - if ($result = $this->_getReadAdapter()->fetchRow($select)) { - $object->addData($result); - } - } - return $this; - } - - /** - * Retrieve store labels by given attribute id - * - * @param integer $attributeId - * @return array - */ - public function getStoreLabelsByAttributeId($attributeId) - { - $values = array(); - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('eav/attribute_label')) - ->where('attribute_id = ?', $attributeId); - foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { - $values[$row['store_id']] = $row['value']; - } - return $values; - } - - /** - * Load by given attributes ids and return only exist attribute ids - * - * @param array $attributeIds - * @return array - */ - public function getValidAttributeIds($attributeIds) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('attribute_id')) - ->where('attribute_id in (?)', $attributeIds); - return $this->_getReadAdapter()->fetchCol($select); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Collection.php index 67d26f7b2d..3b31f9dfa6 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,361 +28,10 @@ /** * EAV attribute resource collection * - * @category Mage - * @package Mage_Eav + * @category Mage + * @package Mage_Eav + * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Eav_Model_Mysql4_Entity_Attribute_Collection extends Mage_Eav_Model_Resource_Entity_Attribute_Collection { - /** - * Add attribute set info flag - * - * @var boolean - */ - protected $_addSetInfoFlag = false; - - /** - * Resource model initialization - */ - public function _construct() - { - $this->_init('eav/entity_attribute'); - } - - /** - * Return array of fields to load attribute values - * - * @return array - */ - protected function _getLoadDataFields() - { - $fields = array( - 'attribute_id', - 'entity_type_id', - 'attribute_code', - 'attribute_model', - 'backend_model', - 'backend_type', - 'backend_table', - 'frontend_input', - 'source_model', - ); - return $fields; - } - - /** - * Specify select columns which are used for load arrtibute values - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function useLoadDataFields() - { - $this->getSelect()->reset(Zend_Db_Select::COLUMNS); - $this->getSelect()->columns($this->_getLoadDataFields()); - return $this; - } - - /** - * Specify attribute entity type filter - * - * @param Mage_Eav_Model_Entity_Type | int $type - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setEntityTypeFilter($type) - { - if ($type instanceof Mage_Eav_Model_Entity_Type) { - $additionalTable = $type->getAdditionalAttributeTable(); - $id = $type->getId(); - } else { - $additionalTable = $this->getResource()->getAdditionalAttributeTable($type); - $id = $type; - } - $this->getSelect()->where('main_table.entity_type_id=?', $id); - if ($additionalTable) { - $this->getSelect()->join( - array('additional_table' => $this->getTable($additionalTable)), - 'additional_table.attribute_id=main_table.attribute_id' - ); - } - return $this; - } - - /** - * Specify attribute set filter - * - * @param int $setId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setAttributeSetFilter($setId) - { - if (is_array($setId)) { - if (!empty($setId)) { - $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', 'attribute_id'); - $this->getSelect()->where('entity_attribute.attribute_set_id IN(?)', $setId); - } - } - elseif($setId) { - $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*'); - $this->getSelect()->where('entity_attribute.attribute_set_id=?', $setId); - $this->setOrder('sort_order', 'asc'); - } - return $this; - } - - /** - * Specify multiple attribute sets filter - * Result will be ordered by sort_order - * - * @param array $setIds - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setAttributeSetsFilter(array $setIds) - { - $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', 'attribute_id'); - $this->getSelect()->distinct(true); - $this->getSelect()->where('entity_attribute.attribute_set_id IN(?)', $setIds); - $this->setOrder('sort_order', 'asc'); - return $this; - } - - /** - * Filter for selecting of attributes that is in all sets - * - * @param array $setIds - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setInAllAttributeSetsFilter(array $setIds) - { - foreach ($setIds as $setId) { - $setId = (int) $setId; - if (!$setId) { - continue; - } - $this->getSelect()->join(array('entity_attribute_'.$setId=>$this->getTable('entity_attribute')), 'entity_attribute_' . $setId . '.attribute_id=main_table.attribute_id and entity_attribute_' . $setId . '.attribute_set_id=' . $setId, 'attribute_id'); - } - - $this->getSelect()->distinct(true); - $this->setOrder('is_user_defined', 'asc'); - return $this; - } - - /** - * Add filter which exclude attributes assigned to attribute set - * - * @param int $setId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setAttributeSetExcludeFilter($setId) - { - $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*'); - $this->getSelect()->where('entity_attribute.attribute_set_id != ?', $setId); - $this->setOrder('sort_order', 'asc'); - return $this; - } - - /** - * Exclude attributes filter - * - * @param array $attributes - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setAttributesExcludeFilter($attributes) - { - $this->getSelect()->where('main_table.attribute_id NOT IN(?)', $attributes); - return $this; - } - - /** - * Filter by attribute group id - * - * @param int $groupId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setAttributeGroupFilter($groupId) - { - $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*'); - $this->getSelect()->where('entity_attribute.attribute_group_id=?', $groupId); - $this->setOrder('sort_order', 'asc'); - return $this; - } - - /** - * Declare group by attribute id condition for collection select - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addAttributeGrouping() - { - $this->getSelect()->group('entity_attribute.attribute_id'); - return $this; - } - - /** - * Specify "is_unique" filter as true - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addIsUniqueFilter() - { - $this->getSelect()->where('main_table.is_unique>0'); - return $this; - } - - /** - * Specify "is_unique" filter as false - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addIsNotUniqueFilter() - { - $this->getSelect()->where('main_table.is_unique=0'); - return $this; - } - - /** - * Specify filter to select just attributes with options - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addHasOptionsFilter() - { - $this->getSelect() - ->joinLeft( - array('ao'=>$this->getTable('eav/attribute_option')), 'ao.attribute_id = main_table.attribute_id', 'option_id' - ) - ->group('main_table.attribute_id') - ->where('(main_table.frontend_input = ? and option_id > 0) or (main_table.frontend_input <> ?) or (main_table.is_user_defined = 0)', 'select', 'select'); - - return $this; - } - - /** - * Apply filter by attribute frontend input type - * - * @param string $frontendInputType - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setFrontendInputTypeFilter($frontendInputType) - { - $this->getSelect() - ->where('main_table.frontend_input = ?', $frontendInputType); - return $this; - } - - /** - * Flag for adding information about attributes sets to result - * - * @param bool $flag - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addSetInfo($flag=true) - { - $this->_addSetInfoFlag = $flag; - return $this; - } - - /** - * Ad information about attribute sets to collection result data - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - protected function _addSetInfo() - { - if ($this->_addSetInfoFlag) { - $attributeIds = array(); - foreach ($this->_data as &$dataItem) { - $attributeIds[] = $dataItem['attribute_id']; - } - $attributeToSetInfo = array(); - - if (count($attributeIds) > 0) { - $select = $this->getConnection()->select() - ->from( - array('entity' => $this->getTable('entity_attribute')), - array('attribute_id','attribute_set_id', 'attribute_group_id', 'sort_order') - ) - ->joinLeft( - array('group' => $this->getTable('attribute_group')), - 'entity.attribute_group_id=group.attribute_group_id', - array('group_sort_order' => 'sort_order') - ) - ->where('attribute_id IN (?)', $attributeIds); - $result = $this->getConnection()->fetchAll($select); - - foreach ($result as $row) { - $data = array( - 'group_id' => $row['attribute_group_id'], - 'group_sort' => $row['group_sort_order'], - 'sort' => $row['sort_order'] - ); - $attributeToSetInfo[$row['attribute_id']][$row['attribute_set_id']] = $data; - } - } - - foreach ($this->_data as &$attributeData) { - if (isset($attributeToSetInfo[$attributeData['attribute_id']])) { - $setInfo = $attributeToSetInfo[$attributeData['attribute_id']]; - } else { - $setInfo = array(); - } - - $attributeData['attribute_set_info'] = $setInfo; - } - - unset($attributeToSetInfo); - unset($attributeIds); - } - return $this; - } - - protected function _afterLoadData() - { - $this->_addSetInfo(); - - return parent::_afterLoadData(); - } - - /** - * Load is used in configurable products flag - * - * @deprecated - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function checkConfigurableProducts() - { - return $this; - } - - /** - * Specify collection attribute codes filter - * - * @param string || array $code - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function setCodeFilter($code) - { - if (empty($code)) { - return $this; - } - if (!is_array($code)) { - $code = array($code); - } - $this->getSelect()->where('main_table.attribute_code IN(?)', $code); - return $this; - } - - /** - * Add store label to attribute by specified store id - * - * @param integer $storeId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection - */ - public function addStoreLabel($storeId) - { - $this->getSelect()->joinLeft( - array('al' => $this->getTable('eav/attribute_label')), - 'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $storeId, - array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)')) - ); - return $this; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group.php index 0a441110c9..343cd92180 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group.php @@ -20,87 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Group extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Entity_Attribute_Group extends Mage_Eav_Model_Resource_Entity_Attribute_Group { - protected function _construct() - { - $this->_init('eav/attribute_group', 'attribute_group_id'); - } - - /** - * Checks if attribute group exists - * - * @param Mage_Eav_Model_Entity_Attribute_Group $object - * @return boolean - */ - public function itemExists($object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('attribute_set_id = ?', $object->getAttributeSetId()) - ->where('attribute_group_name = ?', $object->getAttributeGroupName()); - if ($this->_getReadAdapter()->fetchRow($select)) { - return true; - } - return false; - } - - /** - * Perform actions before object save - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getSortOrder()) { - $object->setSortOrder($this->_getMaxSortOrder($object) + 1); - } - return parent::_beforeSave($object); - } - - /** - * Perform actions after object save - * - * @param Mage_Core_Model_Abstract $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->getAttributes()) { - foreach ($object->getAttributes() as $attribute) { - $attribute->setAttributeGroupId($object->getId()); - $attribute->save(); - } - } - return parent::_afterSave($object); - } - - private function _getMaxSortOrder($object) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from($this->getMainTable(), new Zend_Db_Expr("MAX(`sort_order`)")) - ->where("{$this->getMainTable()}.attribute_set_id = ?", $object->getAttributeSetId()); - $maxOrder = $read->fetchOne($select); - return $maxOrder; - } - - /** - * Set any group default if old one was removed - * - * @param integer $attributeSetId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Group - */ - public function updateDefaultGroup($attributeSetId) - { - $this->_getWriteAdapter()->query( - "UPDATE `{$this->getMainTable()}` SET default_id = 1 WHERE attribute_set_id = :attribute_set_id ORDER BY default_id DESC LIMIT 1", - array('attribute_set_id' => $attributeSetId) - ); - return $this; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group/Collection.php index 38252181cc..11f0a79a0c 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Group/Collection.php @@ -20,32 +20,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection + extends Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection { - /** - * Init resource model for collection - * - */ - public function _construct() - { - $this->_init('eav/entity_attribute_group'); - } - - /** - * Set Attribute Set Filter - * - * @param int $setId - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection - */ - public function setAttributeSetFilter($setId) - { - $this->getSelect()->where('main_table.attribute_set_id=?', $setId); - $this->getSelect()->order('main_table.sort_order'); - return $this; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option.php index a3d4b6ff35..84b28abb7c 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option.php @@ -20,108 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Entity attribute option resource model * - * @category Mage - * @package Mage_Eav + * @category Mage + * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Option extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Entity_Attribute_Option extends Mage_Eav_Model_Resource_Entity_Attribute_Option { - public function _construct() - { - $this->_init('eav/attribute_option', 'option_id'); - } - - /** - * Add Join with option value for collection select - * - * @param Mage_Eav_Model_Entity_Collection_Abstract $collection - * @param Mage_Eav_Model_Entity_Attribute $attribute - * @param Zend_Db_Expr $valueExpr - * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option - */ - public function addOptionValueToCollection($collection, $attribute, $valueExpr) { - $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; - $attributeCode = $attribute->getAttributeCode(); - $optionTable1 = $attributeCode . '_option_value_t1'; - $optionTable2 = $attributeCode . '_option_value_t2'; - - $collection->getSelect()->joinLeft( - array($optionTable1 => $this->getTable('eav/attribute_option_value')), - "`{$optionTable1}`.`option_id`={$valueExpr}" - . " AND `{$optionTable1}`.`store_id`='{$adminStore}'", - ($collection->getStoreId() != $adminStore) ? array() : array($attributeCode.'_value' => "{$optionTable1}.value") - ); - - if ($collection->getStoreId() != $adminStore) { - $collection->getSelect()->joinLeft( - array($optionTable2 => $this->getTable('eav/attribute_option_value')), - "`{$optionTable2}`.`option_id`={$valueExpr}" - . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", - array($attributeCode.'_value' => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)") - ); - } - - return $this; - } - - /** - * Retrieve Select for update Flat data - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute - * @param int $store - * @param bool $hasValueField flag which require option value - * @return Varien_Db_Select - */ - public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $store, $hasValueField=true) - { - $attributeTable = $attribute->getBackend()->getTable(); - $attributeCode = $attribute->getAttributeCode(); - - $joinConditionTemplate = "`e`.`entity_id`=`%s`.`entity_id`" - ." AND `%s`.`entity_type_id` = ".$attribute->getEntityTypeId() - ." AND `%s`.`attribute_id` = ".$attribute->getId() - ." AND `%s`.`store_id` = %d"; - $joinCondition = sprintf($joinConditionTemplate, 't1', 't1', 't1', 't1', Mage_Core_Model_App::ADMIN_STORE_ID); - if ($attribute->getFlatAddChildData()) { - $joinCondition .= " AND `e`.`child_id`=`t1`.`entity_id`"; - } - - $valueExpr = new Zend_Db_Expr("IF(t2.value_id>0, t2.value, t1.value)"); - $select = $this->_getReadAdapter()->select() - ->joinLeft( - array('t1' => $attributeTable), - $joinCondition, - array() - ) - ->joinLeft( - array('t2' => $attributeTable), - sprintf($joinConditionTemplate, 't2', 't2', 't2', 't2', $store), - array($attributeCode => $valueExpr)); - if (($attribute->getFrontend()->getInputType() != 'multiselect') && $hasValueField) { - $select->joinLeft( - array('to1' => $this->getTable('eav/attribute_option_value')), - "`to1`.`option_id`={$valueExpr}" - . " AND `to1`.`store_id`='0'", - array()) - ->joinLeft( - array('to2' => $this->getTable('eav/attribute_option_value')), - "`to2`.`option_id`={$valueExpr}" - . " AND `to2`.`store_id`='{$store}'", - array($attributeCode . '_value' => "IFNULL(`to2`.`value`, `to1`.`value`)") - ); - } - - if ($attribute->getFlatAddChildData()) { - $select->where("e.is_child=?", 0); - } - return $select; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php index 3cfa99482c..43c7dae543 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Option/Collection.php @@ -20,89 +20,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Entity attribute option collection * - * @category Mage - * @package Mage_Eav + * @category Mage + * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Eav_Model_Mysql4_Entity_Attribute_Option_Collection + extends Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection { - protected $_optionValueTable; - - public function _construct() - { - $this->_init('eav/entity_attribute_option'); - $this->_optionValueTable = Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value'); - } - - public function setAttributeFilter($setId) - { - $this->getSelect()->where('main_table.attribute_id=?', $setId); - return $this; - } - - public function setStoreFilter($storeId=null, $useDefaultValue=true) - { - if (is_null($storeId)) { - $storeId = Mage::app()->getStore()->getId(); - } - $sortBy = 'store_default_value'; - if ($useDefaultValue) { - $this->getSelect() - ->join(array('store_default_value'=>$this->_optionValueTable), - 'store_default_value.option_id=main_table.option_id', - array('default_value'=>'value')) - ->joinLeft(array('store_value'=>$this->_optionValueTable), - 'store_value.option_id=main_table.option_id AND '.$this->getConnection()->quoteInto('store_value.store_id=?', $storeId), - array('store_value'=>'value', - 'value' => new Zend_Db_Expr('IF(store_value.value_id>0, store_value.value,store_default_value.value)'))) - ->where($this->getConnection()->quoteInto('store_default_value.store_id=?', 0)); - } - else { - $sortBy = 'store_value'; - $this->getSelect() - ->joinLeft(array('store_value'=>$this->_optionValueTable), - 'store_value.option_id=main_table.option_id AND '.$this->getConnection()->quoteInto('store_value.store_id=?', $storeId), - 'value') - ->where($this->getConnection()->quoteInto('store_value.store_id=?', $storeId)); - } - $this->setOrder("{$sortBy}.value", 'ASC'); - - return $this; - } - - public function setIdFilter($id) - { - if (is_array($id)) { - $this->getSelect()->where('main_table.option_id IN (?)', $id); - } - else { - $this->getSelect()->where('main_table.option_id=?', $id); - } - return $this; - } - - public function toOptionArray($valueKey = 'value') - { - return $this->_toOptionArray('option_id', $valueKey); - } - - public function setPositionOrder($dir = 'ASC', $sortAlpha = false) - { - $this->setOrder('main_table.sort_order', $dir); - // sort alphabetically by values in admin - if ($sortAlpha) { - $this->getSelect()->joinLeft(array('sort_alpha_value' => $this->_optionValueTable), - 'sort_alpha_value.option_id=main_table.option_id AND sort_alpha_value.store_id=0', 'value' - ); - $this->setOrder('sort_alpha_value.value', $dir); - } - return $this; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set.php index ea5e11fd7c..a7a73f32c4 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,138 +28,10 @@ /** * Eav attribute set resource model * - * @category Mage - * @package Mage_Eav - * @author Magento Core Team + * @category Mage + * @package Mage_Eav + * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Set extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Entity_Attribute_Set extends Mage_Eav_Model_Resource_Entity_Attribute_Set { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('eav/attribute_set', 'attribute_set_id'); - } - - /** - * Perform actions after object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Set - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->getGroups()) { - /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ - foreach ($object->getGroups() as $group) { - $group->setAttributeSetId($object->getId()); - if ($group->itemExists() && !$group->getId()) { - continue; - } - $group->save(); - } - } - if ($object->getRemoveGroups()) { - foreach ($object->getRemoveGroups() as $group) { - /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ - $group->delete(); - } - Mage::getResourceModel('eav/entity_attribute_group')->updateDefaultGroup($object->getId()); - } - if ($object->getRemoveAttributes()) { - foreach ($object->getRemoveAttributes() as $attribute) { - /* @var $attribute Mage_Eav_Model_Entity_Attribute */ - $attribute->deleteEntity(); - } - } - return parent::_afterSave($object); - } - - /** - * Validate attribute set name - * - * @param Mage_Eav_Model_Entity_Attribute_Set $object - * @param string $name - * @return bool - */ - public function validate($object,$name) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getMainTable()) - ->where("attribute_set_name=?",$name) - ->where("entity_type_id=?",$object->getEntityTypeId()); - - if ($object->getId()) { - $select->where("attribute_set_id!=?",$object->getId()); - } - - if (!$read->fetchOne($select)) { - return true; - } - - return false; - } - - /** - * Retrieve Set info by attributes - * - * @param array $attributeIds - * @param int $setId - * @return array - */ - public function getSetInfo(array $attributeIds, $setId = null) - { - $setInfo = array(); - $attributeToSetInfo = array(); - if (count($attributeIds) > 0) { - $select = $this->_getReadAdapter()->select() - ->from( - array('entity' => $this->getTable('entity_attribute')), - array('attribute_id','attribute_set_id', 'attribute_group_id', 'sort_order')) - ->joinLeft( - array('group' => $this->getTable('attribute_group')), - 'entity.attribute_group_id=group.attribute_group_id', - array('group_sort_order' => 'sort_order')) - ->where('entity.attribute_id IN (?)', $attributeIds); - if (is_numeric($setId)) { - $select->where('entity.attribute_set_id=?', $setId); - } - $result = $this->_getReadAdapter()->fetchAll($select); - - foreach ($result as $row) { - $data = array( - 'group_id' => $row['attribute_group_id'], - 'group_sort' => $row['group_sort_order'], - 'sort' => $row['sort_order'] - ); - $attributeToSetInfo[$row['attribute_id']][$row['attribute_set_id']] = $data; - } - } - - foreach ($attributeIds as $atttibuteId) { - $setInfo[$atttibuteId] = isset($attributeToSetInfo[$atttibuteId]) - ? $attributeToSetInfo[$atttibuteId] - : array(); - } - - return $setInfo; - } - - /** - * Retrurn default attribute group id for attribute set id - * - * @param int $setId - * @return int|null - */ - public function getDefaultGroupId($setId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('eav/attribute_group'), 'attribute_group_id') - ->where('attribute_set_id = ?', $setId) - ->where('default_id = ?', 1) - ->limit(1); - return $this->_getReadAdapter()->fetchOne($select); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set/Collection.php index 375714c2bd..8f460d10e9 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Attribute/Set/Collection.php @@ -20,31 +20,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection + extends Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection { - public function _construct() - { - $this->_init('eav/entity_attribute_set'); - } - - public function setEntityTypeFilter($typeId) - { - $this->getSelect()->where('main_table.entity_type_id=?', $typeId); - return $this; - } - - public function toOptionArray() - { - return parent::_toOptionArray('attribute_set_id', 'attribute_set_name'); - } - - public function toOptionHash() - { - return parent::_toOptionHash('attribute_set_id', 'attribute_set_name'); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Store.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Store.php index 93fb2ec69d..0d32bf0dc4 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Store.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Store.php @@ -20,44 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Entity_Store extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Entity_Store extends Mage_Eav_Model_Resource_Entity_Store { - protected function _construct() - { - $this->_init('eav/entity_store', 'entity_store_id'); - } - - /** - * Load an object by entity type and store - * - * @param Varien_Object $object - * @param integer $id - * @param string $field field to load by (defaults to model id) - * @return boolean - */ - public function loadByEntityStore(Mage_Core_Model_Abstract $object, $entityTypeId, $storeId) - { - $read = $this->_getWriteAdapter(); - - $select = $read->select()->from($this->getMainTable()) - ->forUpdate(true) - ->where('entity_type_id=?', $entityTypeId) - ->where('store_id=?', $storeId); - $data = $read->fetchRow($select); - - if (!$data) { - return false; - } - - $object->setData($data); - - $this->_afterLoad($object); - - return true; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type.php index 70eb6d2f8d..ec0f4b6bba 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,45 +28,10 @@ /** * EAV entity type resource model * - * @category Mage - * @package Mage_Eav + * @category Mage + * @package Mage_Eav + * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Entity_Type extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Entity_Type extends Mage_Eav_Model_Resource_Entity_Type { - - /** - * Enter description here... - * - */ - protected function _construct() - { - $this->_init('eav/entity_type', 'entity_type_id'); - } - - /** - * Enter description here... - * - * @param unknown_type $object - * @param string $code - * @return Mage_Eav_Model_Mysql4_Entity_Type - */ - public function loadByCode($object, $code) - { - return $this->load($object, $code, 'entity_type_code'); - } - - /** - * Retrieve additional attribute table name for specified entity type - * - * @param integer $entityTypeId - * @return string - */ - public function getAdditionalAttributeTable($entityTypeId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array('additional_attribute_table')) - ->where('entity_type_id = ?', $entityTypeId); - return $this->_getReadAdapter()->fetchOne($select); - } - } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type/Collection.php index 5328e8f985..26def99bc8 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Entity/Type/Collection.php @@ -20,15 +20,18 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Eav_Model_Mysql4_Entity_Type_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Eav + * @author Magento Core Team + */ +class Mage_Eav_Model_Mysql4_Entity_Type_Collection extends Mage_Eav_Model_Resource_Entity_Type_Collection { - public function _construct() - { - $this->_init('eav/entity_type'); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Element.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Element.php index 100d3b9db2..13975a1a88 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Element.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,37 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Element extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Form_Element extends Mage_Eav_Model_Resource_Form_Element { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('eav/form_element', 'element_id'); - $this->addUniqueField(array( - 'field' => array('type_id', 'attribute_id'), - 'title' => Mage::helper('eav')->__('Form Element with the same attribute') - )); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @param Mage_Eav_Model_Form_Element $object - * @return Varien_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $select->join( - $this->getTable('eav/attribute'), - $this->getTable('eav/attribute').'.attribute_id='.$this->getMainTable().'.attribute_id', - array('attribute_code', 'entity_type_id') - ); - return $select; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Element/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Element/Collection.php index 5a4485e20d..bdb61eb2f6 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Element/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Element/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,107 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Element_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Eav_Model_Mysql4_Form_Element_Collection extends Mage_Eav_Model_Resource_Form_Element_Collection { - /** - * Initialize collection model - * - */ - protected function _construct() - { - $this->_init('eav/form_element'); - } - - /** - * Add Form Type filter to collection - * - * @param Mage_Eav_Model_Form_Type|int $type - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - public function addTypeFilter($type) - { - if ($type instanceof Mage_Eav_Model_Form_Type) { - $type = $type->getId(); - } - - $this->addFieldToFilter('type_id', $type); - - return $this; - } - - - /** - * Add Form Fieldset filter to collection - * - * @param Mage_Eav_Model_Form_Fieldset|int $fieldset - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - public function addFieldsetFilter($fieldset) - { - if ($fieldset instanceof Mage_Eav_Model_Form_Fieldset) { - $fieldset = $fieldset->getId(); - } - - $this->addFieldToFilter('main_table.fieldset_id', $fieldset); - - return $this; - } - - /** - * Add Attribute filter to collection - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - public function addAttributeFilter($attribute) - { - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { - $attribute = $attribute->getId(); - } - - $this->addFieldToFilter('main_table.attribute_id', $attribute); - - return $this; - } - - /** - * Set order by element sort order - * - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - public function setSortOrder() - { - $this->setOrder('main_table.sort_order', self::SORT_ORDER_ASC); - - return $this; - } - - /** - * Join attribute data - * - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - protected function _joinAttributeData() - { - $this->getSelect()->join( - array('eav_attribute' => $this->getTable('eav/attribute')), - 'main_table.attribute_id=eav_attribute.attribute_id', - array('attribute_code', 'entity_type_id') - ); - - return $this; - } - - /** - * Load data (join attribute data) - * - * @return Mage_Eav_Model_Mysql4_Form_Element_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if (!$this->isLoaded()) { - $this->_joinAttributeData(); - } - return parent::load($printQuery, $logQuery); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset.php index a4fd6566eb..24e0cbf172 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,130 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Fieldset extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Form_Fieldset extends Mage_Eav_Model_Resource_Form_Fieldset { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('eav/form_fieldset', 'fieldset_id'); - $this->addUniqueField(array( - 'field' => array('type_id', 'code'), - 'title' => Mage::helper('eav')->__('Form Fieldset with the same code') - )); - } - - /** - * After save (save labels) - * - * @param Mage_Eav_Model_Form_Fieldset $object - * @return Mage_Eav_Model_Mysql4_Form_Fieldset - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->hasLabels()) { - $new = $object->getLabels(); - $old = $this->getLabels($object); - - $write = $this->_getWriteAdapter(); - - $insert = array_diff(array_keys($new), array_keys($old)); - $delete = array_diff(array_keys($old), array_keys($new)); - $update = array(); - - foreach ($new as $storeId => $label) { - if (isset($old[$storeId]) && $old[$storeId] != $label) { - $update[$storeId] = $label; - } else if (isset($old[$storeId]) && empty($label)) { - $delete[] = $storeId; - } - } - - if (!empty($insert)) { - $data = array(); - foreach ($insert as $storeId) { - $label = $new[$storeId]; - if (empty($label)) { - continue; - } - $data[] = array( - 'fieldset_id' => (int)$object->getId(), - 'store_id' => (int)$storeId, - 'label' => $label - ); - } - if ($data) { - $write->insertMultiple($this->getTable('eav/form_fieldset_label'), $data); - } - } - - if (!empty($delete)) { - $where = join(' AND ', array( - $write->quoteInto('fieldset_id=?', $object->getId()), - $write->quoteInto('store_id IN(?)', $delete) - )); - $write->delete($this->getTable('eav/form_fieldset_label'), $where); - } - - if (!empty($update)) { - foreach ($update as $storeId => $label) { - $bind = array( - 'label' => $label - ); - $where = join(' AND ', array( - $write->quoteInto('fieldset_id=?', $object->getId()), - $write->quoteInto('store_id=?', $storeId) - )); - $write->update($this->getTable('eav/form_fieldset_label'), $bind, $where); - } - } - } - - return parent::_afterSave($object); - } - - /** - * Retrieve fieldset labels for stores - * - * @param Mage_Eav_Model_Form_Fieldset $object - * @return array - */ - public function getLabels($object) - { - if (!$object->getId()) { - return array(); - } - - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('eav/form_fieldset_label'), array('store_id', 'label')) - ->where('fieldset_id=?', $object->getId()); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @param Mage_Eav_Model_Form_Fieldset $object - * @return Varien_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $select->joinLeft( - array('default_label' => $this->getTable('eav/form_fieldset_label')), - $this->getMainTable().'fieldset_id=default_label.fieldset_id AND default_label.store_id=0', - array()) - ->joinLeft( - array('store_label' => $this->getTable('eav/form_fieldset_label')), - $this->getMainTable().'fieldset_id=store_label.fieldset_id AND default_label.store_id=' - .(int)$object->getStoreId(), - array('label' => new Zend_Db_Expr('IFNULL(store_label.label, default_label.label)')) - ); - - return $select; - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset/Collection.php index 6757b3a379..602102701b 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Fieldset/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,98 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Fieldset_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Eav_Model_Mysql4_Form_Fieldset_Collection extends Mage_Eav_Model_Resource_Form_Fieldset_Collection { - /** - * Store scope ID - * - * @var int - */ - protected $_storeId; - - /** - * Initialize collection model - * - */ - protected function _construct() - { - $this->_init('eav/form_fieldset'); - } - - /** - * Add Form Type filter to collection - * - * @param Mage_Eav_Model_Form_Type|int $type - * @return Mage_Eav_Model_Mysql4_Form_Fieldset_Collection - */ - public function addTypeFilter($type) - { - if ($type instanceof Mage_Eav_Model_Form_Type) { - $type = $type->getId(); - } - - $this->addFieldToFilter('type_id', $type); - - return $this; - } - - /** - * Set order by fieldset sort order - * - * @return Mage_Eav_Model_Mysql4_Form_Fieldset_Collection - */ - public function setSortOrder() - { - $this->setOrder('sort_order', self::SORT_ORDER_ASC); - - return $this; - } - - /** - * Retrieve label store scope - * - * @return int - */ - public function getStoreId() - { - if (is_null($this->_storeId)) { - return Mage::app()->getStore()->getId(); - } - return $this->_storeId; - } - - /** - * Set store scope ID - * - * @param int $storeId - * @return Mage_Eav_Model_Mysql4_Form_Fieldset_Collection - */ - public function setStoreId($storeId) - { - $this->_storeId = $storeId; - return $this; - } - - /** - * Initialize select object - * - */ - protected function _initSelect() - { - parent::_initSelect(); - - $this->getSelect()->join( - array('default_label' => $this->getTable('eav/form_fieldset_label')), - 'main_table.fieldset_id=default_label.fieldset_id AND default_label.store_id=0', - array()); - if ($this->getStoreId() == 0) { - $this->getSelect()->columns('label', 'default_label'); - } else { - $this->getSelect()->joinLeft( - array('store_label' => $this->getTable('eav/form_fieldset_label')), - 'main_table.fieldset_id=store_label.fieldset_id AND store_label.store_id='.(int)$this->getStoreId(), - array('label' => new Zend_Db_Expr('IFNULL(store_label.label, default_label.label)')) - ); - } - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Type.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Type.php index b8d762f676..050ea021ed 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Type.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,116 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Type extends Mage_Core_Model_Mysql4_Abstract +class Mage_Eav_Model_Mysql4_Form_Type extends Mage_Eav_Model_Resource_Form_Type { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('eav/form_type', 'type_id'); - $this->addUniqueField(array( - 'field' => array('code', 'theme', 'store_id'), - 'title' => Mage::helper('eav')->__('Form Type with the same code') - )); - } - - /** - * Load an object - * - * @param Mage_Eav_Model_Form_Type $object - * @param mixed $value - * @param string $field field to load by (defaults to model id) - * @return Mage_Eav_Model_Mysql4_Form_Type - */ - public function load(Mage_Core_Model_Abstract $object, $value, $field = null) - { - if (is_null($field) && !is_numeric($value)) { - $field = 'code'; - } - return parent::load($object, $value, $field); - } - - /** - * Retrieve form type entity types - * - * @param Mage_Eav_Model_Form_Type $object - * @return array - */ - public function getEntityTypes($object) - { - if (!$object->getId()) { - return array(); - } - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('eav/form_type_entity'), 'entity_type_id') - ->where('type_id=?', $object->getId()); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Save entity types after save form type - * - * @param Mage_Eav_Model_Form_Type $object - * @see Mage_Core_Model_Mysql4_Abstract#_afterSave($object) - * @return Mage_Eav_Model_Mysql4_Form_Type - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->hasEntityTypes()) { - $new = $object->getEntityTypes(); - $old = $this->getEntityTypes($object); - - $insert = array_diff($new, $old); - $delete = array_diff($old, $new); - - $write = $this->_getWriteAdapter(); - - if (!empty($insert)) { - $data = array(); - foreach ($insert as $entityId) { - if (empty($entityId)) { - continue; - } - $data[] = array( - 'entity_type_id' => (int)$entityId, - 'type_id' => $object->getId() - ); - } - if ($data) { - $write->insertMultiple($this->getTable('eav/form_type_entity'), $data); - } - } - if (!empty($delete)) { - $where = join(' AND ', array( - $write->quoteInto('type_id=?', $object->getId()), - $write->quoteInto('entity_type_id IN(?)', $delete) - )); - $write->delete($this->getTable('eav/form_type_entity'), $where); - } - } - - return parent::_afterSave($object); - } - - /** - * Retrieve form type filtered by given attribute - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute - * @return array - */ - public function getFormTypesByAttribute($attribute) - { - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { - $attribute = $attribute->getId(); - } - if (!$attribute) { - return array(); - } - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('eav/form_element')) - ->where('attribute_id = ?', $attribute); - return $this->_getReadAdapter()->fetchAll($select); - } } diff --git a/app/code/core/Mage/Eav/Model/Mysql4/Form/Type/Collection.php b/app/code/core/Mage/Eav/Model/Mysql4/Form/Type/Collection.php index 594d7212ef..f3de4528aa 100644 --- a/app/code/core/Mage/Eav/Model/Mysql4/Form/Type/Collection.php +++ b/app/code/core/Mage/Eav/Model/Mysql4/Form/Type/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,45 +32,6 @@ * @package Mage_Eav * @author Magento Core Team */ -class Mage_Eav_Model_Mysql4_Form_Type_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Eav_Model_Mysql4_Form_Type_Collection extends Mage_Eav_Model_Resource_Form_Type_Collection { - /** - * Initialize collection model - * - */ - protected function _construct() - { - $this->_init('eav/form_type'); - } - - /** - * Convert items array to array for select options - * - * @return array - */ - public function toOptionArray() - { - return $this->_toOptionArray('type_id', 'label'); - } - - /** - * Add Entity type filter to collection - * - * @param Mage_Eav_Model_Entity_Type|int $entity - * @return Mage_Eav_Model_Mysql4_Form_Type_Collection - */ - public function addEntityTypeFilter($entity) - { - if ($entity instanceof Mage_Eav_Model_Entity_Type) { - $entity = $entity->getId(); - } - - $this->getSelect()->join( - array('form_type_entity' => $this->getTable('eav/form_type_entity')), - 'main_table.type_id=form_type_entity.type_id', - array()) - ->where('form_type_entity.entity_type_id=?', $entity); - - return $this; - } } diff --git a/app/code/core/Mage/Eav/Model/Resource/Config.php b/app/code/core/Mage/Eav/Model/Resource/Config.php new file mode 100755 index 0000000000..26152e5691 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Config.php @@ -0,0 +1,134 @@ + + */ +class Mage_Eav_Model_Resource_Config extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Array of entity types + * + * @var array + */ + protected static $_entityTypes = array(); + + /** + * Array of attributes + * + * @var array + */ + protected static $_attributes = array(); + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/entity_type', 'entity_type_id'); + } + + /** + * Load all entity types + * + * @return Mage_Eav_Model_Resource_Config + */ + protected function _loadTypes() + { + $adapter = $this->_getReadAdapter(); + if (!$adapter) { + return $this; + } + if (empty(self::$_entityTypes)) { + $select = $adapter->select()->from($this->getMainTable()); + $data = $adapter->fetchAll($select); + foreach ($data as $row) { + self::$_entityTypes['by_id'][$row['entity_type_id']] = $row; + self::$_entityTypes['by_code'][$row['entity_type_code']] = $row; + } + } + + return $this; + } + + /** + * Load attribute types + * + * @param ind $typeId + * @return array + */ + protected function _loadTypeAttributes($typeId) + { + if (!isset(self::$_attributes[$typeId])) { + $adapter = $this->_getReadAdapter(); + $bind = array('entity_type_id' => $typeId); + $select = $adapter->select() + ->from($this->getTable('eav/attribute')) + ->where('entity_type_id = :entity_type_id'); + + self::$_attributes[$typeId] = $adapter->fetchAll($select, $bind); + } + + return self::$_attributes[$typeId]; + } + + /** + * Retrieve entity type data + * + * @param string $entityType + * @return array + */ + public function fetchEntityTypeData($entityType) + { + $this->_loadTypes(); + + if (is_numeric($entityType)) { + $info = isset(self::$_entityTypes['by_id'][$entityType]) + ? self::$_entityTypes['by_id'][$entityType] : null; + } else { + $info = isset(self::$_entityTypes['by_code'][$entityType]) + ? self::$_entityTypes['by_code'][$entityType] : null; + } + + $data = array(); + if ($info) { + $data['entity'] = $info; + $attributes = $this->_loadTypeAttributes($info['entity_type_id']); + $data['attributes'] = array(); + foreach ($attributes as $attribute) { + $data['attributes'][$attribute['attribute_id']] = $attribute; + $data['attributes'][$attribute['attribute_code']] = $attribute['attribute_id']; + } + } + + return $data; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php new file mode 100755 index 0000000000..405c05a6aa --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -0,0 +1,549 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Eav Entity attributes cache + * + * @var array + */ + protected static $_entityAttributes = array(); + + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('eav/attribute', 'attribute_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => array('attribute_code', 'entity_type_id'), + 'title' => Mage::helper('eav')->__('Attribute with the same code') + )); + return $this; + } + + /** + * Load all entity type attributes + * + * @param int $entityTypeId + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _loadTypeAttributes($entityTypeId) + { + if (!isset(self::$_entityAttributes[$entityTypeId])) { + $adapter = $this->_getReadAdapter(); + $bind = array(':entity_type_id' => $entityTypeId); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('entity_type_id = :entity_type_id'); + + $data = $adapter->fetchAll($select, $bind); + foreach ($data as $row) { + self::$_entityAttributes[$entityTypeId][$row['attribute_code']] = $row; + } + } + + return $this; + } + + /** + * Load attribute data by attribute code + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @param int $entityTypeId + * @param string $code + * @return boolean + */ + public function loadByCode(Mage_Core_Model_Abstract $object, $entityTypeId, $code) + { + $bind = array(':entity_type_id' => $entityTypeId); + $select = $this->_getLoadSelect('attribute_code', $code, $object) + ->where('entity_type_id = :entity_type_id'); + $data = $this->_getReadAdapter()->fetchRow($select, $bind); + + if ($data) { + $object->setData($data); + $this->_afterLoad($object); + return true; + } + return false; + } + + /** + * Retrieve Max Sort order for attribute in group + * + * @param Mage_Core_Model_Abstract $object + * @return int + */ + private function _getMaxSortOrder(Mage_Core_Model_Abstract $object) + { + if (intval($object->getAttributeGroupId()) > 0) { + $adapter = $this->_getReadAdapter(); + $bind = array( + ':attribute_set_id' => $object->getAttributeSetId(), + ':attribute_group_id' => $object->getAttributeGroupId() + ); + $select = $adapter->select() + ->from($this->getTable('eav/entity_attribute'), new Zend_Db_Expr("MAX(sort_order)")) + ->where('attribute_set_id = :attribute_set_id') + ->where('attribute_group_id = :attribute_group_id'); + + return $adapter->fetchOne($select, $bind); + } + + return 0; + } + + /** + * Delete entity + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + public function deleteEntity(Mage_Core_Model_Abstract $object) + { + if (!$object->getEntityAttributeId()) { + return $this; + } + + $this->_getWriteAdapter()->delete($this->getTable('eav/entity_attribute'), array( + 'entity_attribute_id = ?' => $object->getEntityAttributeId() + )); + + return $this; + } + + /** + * Validate attribute data before save + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $frontendLabel = $object->getFrontendLabel(); + if (is_array($frontendLabel)) { + if (!isset($frontendLabel[0]) || is_null($frontendLabel[0]) || $frontendLabel[0] == '') { + Mage::throwException(Mage::helper('eav')->__('Frontend label is not defined')); + } + $object->setFrontendLabel($frontendLabel[0]) + ->setStoreLabels($frontendLabel); + } + + /** + * @todo need use default source model of entity type !!! + */ + if (!$object->getId()) { + if ($object->getFrontendInput() == 'select') { + $object->setSourceModel('eav/entity_attribute_source_table'); + } + } + + return parent::_beforeSave($object); + } + + /** + * Save additional attribute data after save attribute + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $this->_saveStoreLabels($object) + ->_saveAdditionalAttributeData($object) + ->saveInSetIncluding($object) + ->_saveOption($object); + + return parent::_afterSave($object); + } + + /** + * Save store labels + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _saveStoreLabels(Mage_Core_Model_Abstract $object) + { + $storeLabels = $object->getStoreLabels(); + if (is_array($storeLabels)) { + $adapter = $this->_getWriteAdapter(); + if ($object->getId()) { + $condition = array('attribute_id =?' => $object->getId()); + $adapter->delete($this->getTable('eav/attribute_label'), $condition); + } + foreach ($storeLabels as $storeId => $label) { + if ($storeId == 0 || !strlen($label)) { + continue; + } + $bind = array ( + 'attribute_id' => $object->getId(), + 'store_id' => $storeId, + 'value' => $label + ); + $adapter->insert($this->getTable('eav/attribute_label'), $bind); + } + } + + return $this; + } + + /** + * Save additional data of attribute + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _saveAdditionalAttributeData(Mage_Core_Model_Abstract $object) + { + $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId()); + if ($additionalTable) { + $adapter = $this->_getWriteAdapter(); + $data = $this->_prepareDataForTable($object, $this->getTable($additionalTable)); + $bind = array(':attribute_id' => $object->getId()); + $select = $adapter->select() + ->from($this->getTable($additionalTable), array('attribute_id')) + ->where('attribute_id = :attribute_id'); + $result = $adapter->fetchOne($select, $bind); + if ($result) { + $where = array('attribute_id = ?' => $object->getId()); + $adapter->update($this->getTable($additionalTable), $data, $where); + } else { + $adapter->insert($this->getTable($additionalTable), $data); + } + } + + return $this; + } + + /** + * Save in set including + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + public function saveInSetIncluding(Mage_Core_Model_Abstract $object) + { + $attributeId = (int) $object->getId(); + $setId = (int) $object->getAttributeSetId(); + $groupId = (int) $object->getAttributeGroupId(); + + if ($setId && $groupId && $object->getEntityTypeId()) { + $adapter = $this->_getWriteAdapter(); + $table = $this->getTable('eav/entity_attribute'); + + $sortOrder = (($object->getSortOrder()) ? $object->getSortOrder() : $this->_getMaxSortOrder($object) + 1); + $data = array( + 'entity_type_id' => $object->getEntityTypeId(), + 'attribute_set_id' => $setId, + 'attribute_group_id' => $groupId, + 'attribute_id' => $attributeId, + 'sort_order' => $sortOrder + ); + + $where = array( + 'attribute_id =?' => $attributeId, + 'attribute_set_id =?' => $setId + ); + + $adapter->delete($table, $where); + $adapter->insert($table, $data); + } + + return $this; + } + + /** + * Save attribute options + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _saveOption(Mage_Core_Model_Abstract $object) + { + $option = $object->getOption(); + if (is_array($option)) { + $adapter = $this->_getWriteAdapter(); + $optionTable = $this->getTable('eav/attribute_option'); + $optionValueTable = $this->getTable('eav/attribute_option_value'); + + $stores = Mage::app()->getStores(true); + if (isset($option['value'])) { + $attributeDefaultValue = array(); + if (!is_array($object->getDefault())) { + $object->setDefault(array()); + } + + foreach ($option['value'] as $optionId => $values) { + $intOptionId = (int) $optionId; + if (!empty($option['delete'][$optionId])) { + if ($intOptionId) { + $adapter->delete($optionTable, array('option_id = ?' => $intOptionId)); + } + continue; + } + + $sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0; + if (!$intOptionId) { + $data = array( + 'attribute_id' => $object->getId(), + 'sort_order' => $sortOrder + ); + $adapter->insert($optionTable, $data); + $intOptionId = $adapter->lastInsertId($optionTable); + } else { + $data = array('sort_order' => $sortOrder); + $where = array('option_id =?' => $intOptionId); + $adapter->update($optionTable, $data, $where); + } + + if (in_array($optionId, $object->getDefault())) { + if ($object->getFrontendInput() == 'multiselect') { + $attributeDefaultValue[] = $intOptionId; + } elseif ($object->getFrontendInput() == 'select') { + $attributeDefaultValue = array($intOptionId); + } + } + + // Default value + if (!isset($values[0])) { + Mage::throwException(Mage::helper('eav')->__('Default option value is not defined')); + } + + $adapter->delete($optionValueTable, array('option_id =?' => $intOptionId)); + foreach ($stores as $store) { + if (isset($values[$store->getId()]) + && (!empty($values[$store->getId()]) + || $values[$store->getId()] == "0") + ) { + $data = array( + 'option_id' => $intOptionId, + 'store_id' => $store->getId(), + 'value' => $values[$store->getId()], + ); + $adapter->insert($optionValueTable, $data); + } + } + } + $bind = array('default_value' => implode(',', $attributeDefaultValue)); + $where = array('attribute_id =?' => $object->getId()); + $adapter->update($this->getMainTable(), $bind, $where); + } + } + + return $this; + } + + + /** + * Retrieve attribute id by entity type code and attribute code + * + * @param string $entityType + * @param string $code + * @return int + */ + public function getIdByCode($entityType, $code) + { + $adapter = $this->_getReadAdapter(); + $bind = array( + ':entity_type_code' => $entityType, + ':attribute_code' => $code + ); + $select = $adapter->select() + ->from(array('a' => $this->getTable('eav/attribute')), array('a.attribute_id')) + ->join( + array('t' => $this->getTable('eav/entity_type')), + 'a.entity_type_id = t.entity_type_id', + array()) + ->where('t.entity_type_code = :entity_type_code') + ->where('a.attribute_code = :attribute_code'); + + return $adapter->fetchOne($select, $bind); + } + + /** + * Retrieve attribute codes by front-end type + * + * @param string $frontendType + * @return array + */ + public function getAttributeCodesByFrontendType($frontendType) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':frontend_input' => $frontendType); + $select = $adapter->select() + ->from($this->getTable('eav/attribute'), 'attribute_code') + ->where('frontend_input = :frontend_input'); + + return $adapter->fetchCol($select, $bind); + } + + /** + * Retrieve Select For Flat Attribute update + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param int $storeId + * @return Varien_Db_Select + */ + public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $storeId) + { + $adapter = $this->_getReadAdapter(); + $joinConditionTemplate = "e.entity_id=%s.entity_id" + ." AND %s.entity_type_id = ".$attribute->getEntityTypeId() + ." AND %s.attribute_id = ".$attribute->getId() + ." AND %s.store_id = %d"; + $joinCondition = sprintf($joinConditionTemplate, 't1', 't1', 't1', 't1', Mage_Core_Model_App::ADMIN_STORE_ID); + if ($attribute->getFlatAddChildData()) { + $joinCondition .= ' AND e.child_id = t1.entity_id'; + } + + $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + + /** @var $select Varien_Db_Select */ + $select = $adapter->select() + ->joinLeft( + array('t1' => $attribute->getBackend()->getTable()), + $joinCondition, + array()) + ->joinLeft( + array('t2' => $attribute->getBackend()->getTable()), + sprintf($joinConditionTemplate, 't2', 't2', 't2', 't2', $storeId), + array($attribute->getAttributeCode() => $valueExpr)); + if ($attribute->getFlatAddChildData()) { + $select->where("e.is_child = ?", 0); + } + + return $select; + } + + /** + * Returns the column descriptions for a table + * + * @param string $table + * @return array + */ + public function describeTable($table) + { + return $this->_getReadAdapter()->describeTable($table); + } + + /** + * Retrieve additional attribute table name for specified entity type + * + * @param integer $entityTypeId + * @return string + */ + public function getAdditionalAttributeTable($entityTypeId) + { + return Mage::getResourceSingleton('eav/entity_type')->getAdditionalAttributeTable($entityTypeId); + } + + /** + * Load additional attribute data. + * Load label of current active store + * + * @param Mage_Eav_Model_Entity_Attribute $object + * @return Mage_Eav_Model_Resource_Entity_Attribute + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + /** @var $entityType Mage_Eav_Model_Entity_Type */ + $entityType = $object->getData('entity_type'); + if ($entityType) { + $additionalTable = $entityType->getAdditionalAttributeTable(); + } else { + $additionalTable = $this->getAdditionalAttributeTable($object->getEntityTypeId()); + } + + if ($additionalTable) { + $adapter = $this->_getReadAdapter(); + $bind = array(':attribute_id' => $object->getId()); + $select = $adapter->select() + ->from($this->getTable($additionalTable)) + ->where('attribute_id = :attribute_id'); + + $result = $adapter->fetchRow($select, $bind); + if ($result) { + $object->addData($result); + } + } + + return $this; + } + + /** + * Retrieve store labels by given attribute id + * + * @param integer $attributeId + * @return array + */ + public function getStoreLabelsByAttributeId($attributeId) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':attribute_id' => $attributeId); + $select = $adapter->select() + ->from($this->getTable('eav/attribute_label'), array('store_id', 'value')) + ->where('attribute_id = :attribute_id'); + + return $adapter->fetchPairs($select, $bind); + } + + /** + * Load by given attributes ids and return only exist attribute ids + * + * @param array $attributeIds + * @return array + */ + public function getValidAttributeIds($attributeIds) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('attribute_id')) + ->where('attribute_id IN (?)', $attributeIds); + + return $adapter->fetchCol($select); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php new file mode 100755 index 0000000000..bc31613be0 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php @@ -0,0 +1,435 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Add attribute set info flag + * + * @var boolean + */ + protected $_addSetInfoFlag = false; + + /** + * Resource model initialization + * + */ + protected function _construct() + { + $this->_init('eav/entity_attribute'); + } + + /** + * Return array of fields to load attribute values + * + * @return array + */ + protected function _getLoadDataFields() + { + return array( + 'attribute_id', + 'entity_type_id', + 'attribute_code', + 'attribute_model', + 'backend_model', + 'backend_type', + 'backend_table', + 'frontend_input', + 'source_model', + ); + } + + /** + * Specify select columns which are used for load arrtibute values + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function useLoadDataFields() + { + $this->getSelect()->reset(Zend_Db_Select::COLUMNS); + $this->getSelect()->columns($this->_getLoadDataFields()); + + return $this; + } + + /** + * Specify attribute entity type filter + * + * @param Mage_Eav_Model_Entity_Type | int $type + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setEntityTypeFilter($type) + { + if ($type instanceof Mage_Eav_Model_Entity_Type) { + $additionalTable = $type->getAdditionalAttributeTable(); + $id = $type->getId(); + } else { + $additionalTable = $this->getResource()->getAdditionalAttributeTable($type); + $id = $type; + } + $this->addFieldToFilter('main_table.entity_type_id', $id); + if ($additionalTable) { + $this->join( + array('additional_table' => $additionalTable), + 'additional_table.attribute_id = main_table.attribute_id' + ); + } + + return $this; + } + + /** + * Specify attribute set filter + * + * @param int $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setAttributeSetFilter($setId) + { + if (is_array($setId)) { + if (!empty($setId)) { + $this->join( + 'entity_attribute', + 'entity_attribute.attribute_id = main_table.attribute_id', + 'attribute_id' + ); + $this->addFieldToFilter('entity_attribute.attribute_set_id', array('in' => $setId)); + $this->addAttributeGrouping(); + $this->_useAnalyticFunction = true; + } + } elseif ($setId) { + $this->join( + 'entity_attribute', + 'entity_attribute.attribute_id = main_table.attribute_id' + ); + $this->addFieldToFilter('entity_attribute.attribute_set_id', $setId); + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + } + + return $this; + } + + /** + * Specify multiple attribute sets filter + * Result will be ordered by sort_order + * + * @param array $setIds + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setAttributeSetsFilter(array $setIds) + { + $this->getSelect()->distinct(true); + $this->join( + array('entity_attribute' => $this->getTable('eav/entity_attribute')), + 'entity_attribute.attribute_id = main_table.attribute_id', + 'attribute_id' + ); + $this->addFieldToFilter('entity_attribute.attribute_set_id', array('in' => $setIds)); + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Filter for selecting of attributes that is in all sets + * + * @param array $setIds + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setInAllAttributeSetsFilter(array $setIds) + { + foreach ($setIds as $setId) { + $setId = (int) $setId; + if (!$setId) { + continue; + } + $alias = sprintf('entity_attribute_%d', $setId); + $joinCondition = $this->getConnection() + ->quoteInto("{$alias}.attribute_id = main_table.attribute_id AND {$alias}.attribute_set_id =?", $setId); + $this->join( + array($alias => 'eav/entity_attribute'), + $joinCondition, + 'attribute_id' + ); + } + + //$this->getSelect()->distinct(true); + $this->setOrder('is_user_defined', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Add filter which exclude attributes assigned to attribute set + * + * @param int $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setAttributeSetExcludeFilter($setId) + { + $this->join( + 'entity_attribute', + 'entity_attribute.attribute_id = main_table.attribute_id' + ); + $this->addFieldToFilter('entity_attribute.attribute_set_id', array('neq' => $setId)); + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Exclude attributes filter + * + * @param array $attributes + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setAttributesExcludeFilter($attributes) + { + return $this->addFieldToFilter('main_table.attribute_id', array('nin' => $attributes)); + } + + /** + * Filter by attribute group id + * + * @param int $groupId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setAttributeGroupFilter($groupId) + { + $this->join( + 'entity_attribute', + 'entity_attribute.attribute_id = main_table.attribute_id' + ); + $this->addFieldToFilter('entity_attribute.attribute_group_id', $groupId); + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Declare group by attribute id condition for collection select + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addAttributeGrouping() + { + $this->getSelect()->group('entity_attribute.attribute_id'); + return $this; + } + + /** + * Specify "is_unique" filter as true + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addIsUniqueFilter() + { + return $this->addFieldToFilter('is_unique', array('gt' => 0)); + } + + /** + * Specify "is_unique" filter as false + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addIsNotUniqueFilter() + { + return $this->addFieldToFilter('is_unique', 0); + } + + /** + * Specify filter to select just attributes with options + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addHasOptionsFilter() + { + $adapter = $this->getConnection(); + $orWhere = implode(' OR ', array( + $adapter->quoteInto('(main_table.frontend_input = ? AND ao.option_id > 0)', 'select'), + $adapter->quoteInto('(main_table.frontend_input <> ?)', 'select'), + '(main_table.is_user_defined = 0)' + )); + + $this->getSelect() + ->joinLeft( + array('ao' => $this->getTable('eav/attribute_option')), + 'ao.attribute_id = main_table.attribute_id', + 'option_id') + ->group('main_table.attribute_id') + ->where($orWhere); + + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Apply filter by attribute frontend input type + * + * @param string $frontendInputType + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setFrontendInputTypeFilter($frontendInputType) + { + return $this->addFieldToFilter('frontend_input', $frontendInputType); + } + + /** + * Flag for adding information about attributes sets to result + * + * @param bool $flag + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addSetInfo($flag = true) + { + $this->_addSetInfoFlag = (bool)$flag; + return $this; + } + + /** + * Ad information about attribute sets to collection result data + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + protected function _addSetInfo() + { + if ($this->_addSetInfoFlag) { + $attributeIds = array(); + foreach ($this->_data as &$dataItem) { + $attributeIds[] = $dataItem['attribute_id']; + } + $attributeToSetInfo = array(); + + $adapter = $this->getConnection(); + if (count($attributeIds) > 0) { + $select = $adapter->select() + ->from( + array('entity' => $this->getTable('eav/entity_attribute')), + array('attribute_id', 'attribute_set_id', 'attribute_group_id', 'sort_order') + ) + ->joinLeft( + array('group' => $this->getTable('eav/attribute_group')), + 'entity.attribute_group_id = group.attribute_group_id', + array('group_sort_order' => 'sort_order') + ) + ->where('attribute_id IN (?)', $attributeIds); + $result = $adapter->fetchAll($select); + + foreach ($result as $row) { + $data = array( + 'group_id' => $row['attribute_group_id'], + 'group_sort' => $row['group_sort_order'], + 'sort' => $row['sort_order'] + ); + $attributeToSetInfo[$row['attribute_id']][$row['attribute_set_id']] = $data; + } + } + + foreach ($this->_data as &$attributeData) { + $setInfo = array(); + if (isset($attributeToSetInfo[$attributeData['attribute_id']])) { + $setInfo = $attributeToSetInfo[$attributeData['attribute_id']]; + } + + $attributeData['attribute_set_info'] = $setInfo; + } + + unset($attributeToSetInfo); + unset($attributeIds); + } + return $this; + } + + /** + * Ad information about attribute sets to collection result data + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _afterLoadData() + { + $this->_addSetInfo(); + + return parent::_afterLoadData(); + } + + /** + * Load is used in configurable products flag + * @deprecated + * + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function checkConfigurableProducts() + { + return $this; + } + + /** + * Specify collection attribute codes filter + * + * @param string || array $code + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function setCodeFilter($code) + { + if (empty($code)) { + return $this; + } + if (!is_array($code)) { + $code = array($code); + } + + return $this->addFieldToFilter('attribute_code', array('in' => $code)); + } + + /** + * Add store label to attribute by specified store id + * + * @param integer $storeId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function addStoreLabel($storeId) + { + $adapter = $this->getConnection(); + $joinExpression = $adapter + ->quoteInto('al.attribute_id = main_table.attribute_id AND al.store_id = ?', (int) $storeId); + $this->getSelect()->joinLeft( + array('al' => $this->getTable('eav/attribute_label')), + $joinExpression, + array('store_label' => $adapter->getIfNullSql('al.value', 'main_table.frontend_label')) + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group.php new file mode 100755 index 0000000000..b77dea7105 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group.php @@ -0,0 +1,140 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Group extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/attribute_group', 'attribute_group_id'); + } + + /** + * Checks if attribute group exists + * + * @param Mage_Eav_Model_Entity_Attribute_Group $object + * @return boolean + */ + public function itemExists($object) + { + $adapter = $this->_getReadAdapter(); + $bind = array( + 'attribute_set_id' => $object->getAttributeSetId(), + 'attribute_group_name' => $object->getAttributeGroupName() + ); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('attribute_set_id = :attribute_set_id') + ->where('attribute_group_name = :attribute_group_name'); + + return $adapter->fetchRow($select, $bind) > 0; + } + + /** + * Perform actions before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getSortOrder()) { + $object->setSortOrder($this->_getMaxSortOrder($object) + 1); + } + return parent::_beforeSave($object); + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->getAttributes()) { + foreach ($object->getAttributes() as $attribute) { + $attribute->setAttributeGroupId($object->getId()); + $attribute->save(); + } + } + + return parent::_afterSave($object); + } + + /** + * Retreive max sort order + * + * @param Mage_Core_Model_Abstract $object + * @return int + */ + protected function _getMaxSortOrder($object) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':attribute_set_id' => $object->getAttributeSetId()); + $select = $adapter->select() + ->from($this->getMainTable(), new Zend_Db_Expr("MAX(sort_order)")) + ->where('attribute_set_id = :attribute_set_id'); + + return $adapter->fetchOne($select, $bind); + } + + /** + * Set any group default if old one was removed + * + * @param integer $attributeSetId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Group + */ + public function updateDefaultGroup($attributeSetId) + { + $adapter = $this->_getWriteAdapter(); + $bind = array(':attribute_set_id' => $attributeSetId); + $select = $adapter->select() + ->from($this->getMainTable(), $this->getIdFieldName()) + ->where('attribute_set_id = :attribute_set_id') + ->order('default_id ' . Varien_Data_Collection::SORT_ORDER_DESC) + ->limit(1); + + $groupId = $adapter->fetchOne($select, $bind); + + if ($groupId) { + $data = array('default_id' => 1); + $where = array('attribute_group_id =?' => $groupId); + $adapter->update($this->getMainTable(), $data, $where); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group/Collection.php new file mode 100755 index 0000000000..869c9fe9df --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Group/Collection.php @@ -0,0 +1,69 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init resource model for collection + * + */ + protected function _construct() + { + $this->_init('eav/entity_attribute_group'); + } + + /** + * Set Attribute Set Filter + * + * @param int $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection + */ + public function setAttributeSetFilter($setId) + { + $this->addFieldToFilter('attribute_set_id', array('eq' => $setId)); + $this->setOrder('sort_order'); + return $this; + } + + /** + * Set sort order + * + * @param string $direction + * @return Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection + */ + public function setSortOrder($direction = self::SORT_ORDER_ASC) + { + return $this->addOrder('sort_order', $direction); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option.php new file mode 100755 index 0000000000..92ba0157ef --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option.php @@ -0,0 +1,135 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/attribute_option', 'option_id'); + } + + /** + * Add Join with option value for collection select + * + * @param Mage_Eav_Model_Entity_Collection_Abstract $collection + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param Zend_Db_Expr $valueExpr + * @return Mage_Eav_Model_Resource_Entity_Attribute_Option + */ + public function addOptionValueToCollection($collection, $attribute, $valueExpr) + { + $adapter = $this->_getReadAdapter(); + $attributeCode = $attribute->getAttributeCode(); + $optionTable1 = $attributeCode . '_option_value_t1'; + $optionTable2 = $attributeCode . '_option_value_t2'; + $tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0" + ; + $tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", + $collection->getStoreId()); + $valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", + "{$optionTable1}.value", + "{$optionTable2}.value"); + + $collection->getSelect() + ->joinLeft( + array($optionTable1 => $this->getTable('eav/attribute_option_value')), + $tableJoinCond1, + array()) + ->joinLeft( + array($optionTable2 => $this->getTable('eav/attribute_option_value')), + $tableJoinCond2, + array($attributeCode => $valueExpr) + ); + + return $this; + } + + /** + * Retrieve Select for update Flat data + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @param int $store + * @param bool $hasValueField flag which require option value + * @return Varien_Db_Select + */ + public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $store, + $hasValueField = true + ) { + $adapter = $this->_getReadAdapter(); + $attributeTable = $attribute->getBackend()->getTable(); + $attributeCode = $attribute->getAttributeCode(); + + $joinConditionTemplate = "e.entity_id = %s.entity_id" + ." AND %s.entity_type_id = ".$attribute->getEntityTypeId() + ." AND %s.attribute_id = ".$attribute->getId() + ." AND %s.store_id = %d"; + $joinCondition = sprintf($joinConditionTemplate, 't1', 't1', 't1', 't1', Mage_Core_Model_App::ADMIN_STORE_ID); + if ($attribute->getFlatAddChildData()) { + $joinCondition .= ' AND e.child_id = t1.entity_id'; + } + + $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); + /** @var $select Varien_Db_Select */ + $select = $adapter->select() + ->joinLeft( + array('t1' => $attributeTable), + $joinCondition, + array()) + ->joinLeft( + array('t2' => $attributeTable), + sprintf($joinConditionTemplate, 't2', 't2', 't2', 't2', $store), + array($attributeCode => $valueExpr)); + if (($attribute->getFrontend()->getInputType() != 'multiselect') && $hasValueField) { + $valueIdExpr = $adapter->getCheckSql('to2.value_id > 0', 'to1.value', 'to2.value'); + $select->joinLeft( + array('to1' => $this->getTable('eav/attribute_option_value')), + "to1.option_id = {$valueExpr} AND to1.store_id = 0", + array()) + ->joinLeft( + array('to2' => $this->getTable('eav/attribute_option_value')), + $adapter->quoteInto("to2.option_id = {$valueExpr} AND to2.store_id = ?", $store), + array($attributeCode . '_value' => $valueIdExpr) + ); + } + + if ($attribute->getFlatAddChildData()) { + $select->where('e.is_child = 0'); + } + + return $select; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php new file mode 100755 index 0000000000..e02af71ccc --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Option/Collection.php @@ -0,0 +1,154 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Option value table + * + * @var string + */ + protected $_optionValueTable; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/entity_attribute_option'); + $this->_optionValueTable = Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value'); + } + + /** + * Set attribute filter + * + * @param int $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection + */ + public function setAttributeFilter($setId) + { + return $this->addFieldToFilter('attribute_id', $setId); + } + + + /** + * Add store filter to collection + * + * @param int $storeId + * @param bolean $useDefaultValue + * @return Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection + */ + public function setStoreFilter($storeId = null, $useDefaultValue = true) + { + if (is_null($storeId)) { + $storeId = Mage::app()->getStore()->getId(); + } + $adapter = $this->getConnection(); + + $joinCondition = $adapter->quoteInto('tsv.option_id = main_table.option_id AND tsv.store_id = ?', $storeId); + + if ($useDefaultValue) { + $this->getSelect() + ->join( + array('tdv' => $this->_optionValueTable), + 'tdv.option_id = main_table.option_id', + array('default_value' => 'value')) + ->joinLeft( + array('tsv' => $this->_optionValueTable), + $joinCondition, + array( + 'store_default_value' => 'value', + 'value' => $adapter->getCheckSql('tsv.value_id > 0', 'tsv.value', 'tdv.value') + )) + ->where('tdv.store_id = ?', 0); + } else { + $this->getSelect() + ->joinLeft( + array('tsv' => $this->_optionValueTable), + $joinCondition, + 'value') + ->where('tsv.store_id = ?', $storeId); + } + + $this->setOrder('tsv.value', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Add option id(s) frilter to collection + * + * @param int|array $optionId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection + */ + public function setIdFilter($optionId) + { + return $this->addFieldToFilter('option_id', array('in' => $optionId)); + } + + /** + * Convert collection items to select options array + * + * @param string $valueKey + * @return array + */ + public function toOptionArray($valueKey = 'value') + { + return $this->_toOptionArray('option_id', $valueKey); + } + + + /** + * Set order by position or alphabetically by values in admin + * + * @param string $dir direction + * @param boolean $sortAlpha sort alphabetically by values in admin + * @return Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection + */ + public function setPositionOrder($dir = self::SORT_ORDER_ASC, $sortAlpha = false) + { + $this->setOrder('main_table.sort_order', $dir); + // sort alphabetically by values in admin + if ($sortAlpha) { + $this->getSelect() + ->joinLeft( + array('sort_alpha_value' => $this->_optionValueTable), + 'sort_alpha_value.option_id = main_table.option_id AND sort_alpha_value.store_id = 0', + array('value')); + $this->setOrder('sort_alpha_value.value', $dir); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set.php new file mode 100755 index 0000000000..00df9979bb --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set.php @@ -0,0 +1,177 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Set extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('eav/attribute_set', 'attribute_set_id'); + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Eav_Model_Resource_Entity_Attribute_Set + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->getGroups()) { + /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ + foreach ($object->getGroups() as $group) { + $group->setAttributeSetId($object->getId()); + if ($group->itemExists() && !$group->getId()) { + continue; + } + $group->save(); + } + } + if ($object->getRemoveGroups()) { + foreach ($object->getRemoveGroups() as $group) { + /* @var $group Mage_Eav_Model_Entity_Attribute_Group */ + $group->delete(); + } + Mage::getResourceModel('eav/entity_attribute_group')->updateDefaultGroup($object->getId()); + } + if ($object->getRemoveAttributes()) { + foreach ($object->getRemoveAttributes() as $attribute) { + /* @var $attribute Mage_Eav_Model_Entity_Attribute */ + $attribute->deleteEntity(); + } + } + + return parent::_afterSave($object); + } + + /** + * Validate attribute set name + * + * @param Mage_Eav_Model_Entity_Attribute_Set $object + * @param string $attributeSetName + * @return bool + */ + public function validate($object, $attributeSetName) + { + + $adapter = $this->_getReadAdapter(); + $bind = array( + 'attribute_set_name' => $attributeSetName, + 'entity_type_id' => $object->getEntityTypeId() + ); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('attribute_set_name = :attribute_set_name') + ->where('entity_type_id = :entity_type_id'); + + if ($object->getId()) { + $bind['attribute_set_id'] = $object->getId(); + $select->where('attribute_set_id != :attribute_set_id'); + } + + return !$adapter->fetchOne($select, $bind) ? true : false; + } + + /** + * Retrieve Set info by attributes + * + * @param array $attributeIds + * @param int $setId + * @return array + */ + public function getSetInfo(array $attributeIds, $setId = null) + { + $adapter = $this->_getReadAdapter(); + $setInfo = array(); + $attributeToSetInfo = array(); + + if (count($attributeIds) > 0) { + $select = $adapter->select() + ->from( + array('entity' => $this->getTable('eav/entity_attribute')), + array('attribute_id', 'attribute_set_id', 'attribute_group_id', 'sort_order')) + ->joinLeft( + array('attribute_group' => $this->getTable('eav/attribute_group')), + 'entity.attribute_group_id = attribute_group.attribute_group_id', + array('group_sort_order' => 'sort_order')) + ->where('entity.attribute_id IN (?)', $attributeIds); + $bind = array(); + if (is_numeric($setId)) { + $bind[':attribute_set_id'] = $setId; + $select->where('entity.attribute_set_id = :attribute_set_id'); + } + $result = $adapter->fetchAll($select, $bind); + + foreach ($result as $row) { + $data = array( + 'group_id' => $row['attribute_group_id'], + 'group_sort' => $row['group_sort_order'], + 'sort' => $row['sort_order'] + ); + $attributeToSetInfo[$row['attribute_id']][$row['attribute_set_id']] = $data; + } + } + + foreach ($attributeIds as $atttibuteId) { + $setInfo[$atttibuteId] = isset($attributeToSetInfo[$atttibuteId]) + ? $attributeToSetInfo[$atttibuteId] + : array(); + } + + return $setInfo; + } + + /** + * Retrurn default attribute group id for attribute set id + * + * @param int $setId + * @return int|null + */ + public function getDefaultGroupId($setId) + { + $adapter = $this->_getReadAdapter(); + $bind = array( + 'attribute_set_id' => (int)$setId + ); + $select = $adapter->select() + ->from($this->getTable('eav/attribute_group'), 'attribute_group_id') + ->where('attribute_set_id = :attribute_set_id') + ->where('default_id = 1') + ->limit(1); + return $adapter->fetchOne($select, $bind); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set/Collection.php new file mode 100755 index 0000000000..84710e93e7 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Set/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('eav/entity_attribute_set'); + } + + /** + * Add filter by entity type id to collection + * + * @param int $typeId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection + */ + public function setEntityTypeFilter($typeId) + { + return $this->addFieldToFilter('entity_type_id', $typeId); + } + + /** + * Convert collection items to select options array + * + * @return array + */ + public function toOptionArray() + { + return parent::_toOptionArray('attribute_set_id', 'attribute_set_name'); + } + + /** + * Convert collection items to select options hash array + * + * @return array + */ + public function toOptionHash() + { + return parent::_toOptionHash('attribute_set_id', 'attribute_set_name'); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Store.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Store.php new file mode 100755 index 0000000000..b0a4a7eef7 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Store.php @@ -0,0 +1,77 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Store extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/entity_store', 'entity_store_id'); + } + + /** + * Load an object by entity type and store + * + * @param Varien_Object $object + * @param int $entityTypeId + * @param int $storeId + * @return boolean + */ + public function loadByEntityStore(Mage_Core_Model_Abstract $object, $entityTypeId, $storeId) + { + $adapter = $this->_getWriteAdapter(); + $bind = array( + ':entity_type_id' => $entityTypeId, + ':store_id' => $storeId + ); + $select = $adapter->select() + ->from($this->getMainTable()) + ->forUpdate(true) + ->where('entity_type_id = :entity_type_id') + ->where('store_id = :store_id'); + $data = $adapter->fetchRow($select, $bind); + + if (!$data) { + return false; + } + + $object->setData($data); + + $this->_afterLoad($object); + + return true; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Type.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Type.php new file mode 100755 index 0000000000..6084681bdb --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Type.php @@ -0,0 +1,73 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Type extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/entity_type', 'entity_type_id'); + } + + /** + * Load Entity Type by Code + * + * @param Mage_Core_Model_Abstract $object + * @param string $code + * @return Mage_Eav_Model_Resource_Entity_Type + */ + public function loadByCode($object, $code) + { + return $this->load($object, $code, 'entity_type_code'); + } + + /** + * Retrieve additional attribute table name for specified entity type + * + * @param integer $entityTypeId + * @return string + */ + public function getAdditionalAttributeTable($entityTypeId) + { + $adapter = $this->_getReadAdapter(); + $bind = array('entity_type_id' => $entityTypeId); + $select = $adapter->select() + ->from($this->getMainTable(), array('additional_attribute_table')) + ->where('entity_type_id = :entity_type_id'); + + return $adapter->fetchOne($select, $bind); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Type/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Type/Collection.php new file mode 100755 index 0000000000..fd50e54653 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Type/Collection.php @@ -0,0 +1,44 @@ + + */ +class Mage_Eav_Model_Resource_Entity_Type_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('eav/entity_type'); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Element.php b/app/code/core/Mage/Eav/Model/Resource/Form/Element.php new file mode 100755 index 0000000000..2eaf000304 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Element.php @@ -0,0 +1,68 @@ + + */ +class Mage_Eav_Model_Resource_Form_Element extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + */ + protected function _construct() + { + $this->_init('eav/form_element', 'element_id'); + $this->addUniqueField(array( + 'field' => array('type_id', 'attribute_id'), + 'title' => Mage::helper('eav')->__('Form Element with the same attribute') + )); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Eav_Model_Form_Element $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $select->join( + $this->getTable('eav/attribute'), + $this->getTable('eav/attribute') . '.attribute_id = ' . $this->getMainTable() . '.attribute_id', + array('attribute_code', 'entity_type_id') + ); + + return $select; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Element/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Form/Element/Collection.php new file mode 100755 index 0000000000..151e910026 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Element/Collection.php @@ -0,0 +1,133 @@ + + */ +class Mage_Eav_Model_Resource_Form_Element_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize collection model + */ + protected function _construct() + { + $this->_init('eav/form_element'); + } + + /** + * Add Form Type filter to collection + * + * @param Mage_Eav_Model_Form_Type|int $type + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + public function addTypeFilter($type) + { + if ($type instanceof Mage_Eav_Model_Form_Type) { + $type = $type->getId(); + } + + return $this->addFieldToFilter('type_id', $type); + } + + /** + * Add Form Fieldset filter to collection + * + * @param Mage_Eav_Model_Form_Fieldset|int $fieldset + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + public function addFieldsetFilter($fieldset) + { + if ($fieldset instanceof Mage_Eav_Model_Form_Fieldset) { + $fieldset = $fieldset->getId(); + } + + return $this->addFieldToFilter('fieldset_id', $fieldset); + } + + /** + * Add Attribute filter to collection + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute + * + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + public function addAttributeFilter($attribute) + { + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + $attribute = $attribute->getId(); + } + + return $this->addFieldToFilter('attribute_id', $attribute); + } + + /** + * Set order by element sort order + * + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + public function setSortOrder() + { + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + + return $this; + } + + /** + * Join attribute data + * + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + protected function _joinAttributeData() + { + $this->getSelect()->join( + array('eav_attribute' => $this->getTable('eav/attribute')), + 'main_table.attribute_id = eav_attribute.attribute_id', + array('attribute_code', 'entity_type_id') + ); + + return $this; + } + + /** + * Load data (join attribute data) + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Eav_Model_Resource_Form_Element_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if (!$this->isLoaded()) { + $this->_joinAttributeData(); + } + return parent::load($printQuery, $logQuery); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset.php b/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset.php new file mode 100755 index 0000000000..4ee112201c --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset.php @@ -0,0 +1,165 @@ + + */ +class Mage_Eav_Model_Resource_Form_Fieldset extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + */ + protected function _construct() + { + $this->_init('eav/form_fieldset', 'fieldset_id'); + $this->addUniqueField(array( + 'field' => array('type_id', 'code'), + 'title' => Mage::helper('eav')->__('Form Fieldset with the same code') + )); + } + + /** + * After save (save labels) + * + * @param Mage_Eav_Model_Form_Fieldset $object + * @return Mage_Eav_Model_Resource_Form_Fieldset + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->hasLabels()) { + $new = $object->getLabels(); + $old = $this->getLabels($object); + + $adapter = $this->_getWriteAdapter(); + + $insert = array_diff(array_keys($new), array_keys($old)); + $delete = array_diff(array_keys($old), array_keys($new)); + $update = array(); + + foreach ($new as $storeId => $label) { + if (isset($old[$storeId]) && $old[$storeId] != $label) { + $update[$storeId] = $label; + } elseif (isset($old[$storeId]) && empty($label)) { + $delete[] = $storeId; + } + } + + if (!empty($insert)) { + $data = array(); + foreach ($insert as $storeId) { + $label = $new[$storeId]; + if (empty($label)) { + continue; + } + $data[] = array( + 'fieldset_id' => (int)$object->getId(), + 'store_id' => (int)$storeId, + 'label' => $label + ); + } + if ($data) { + $adapter->insertMultiple($this->getTable('eav/form_fieldset_label'), $data); + } + } + + if (!empty($delete)) { + $where = array( + 'fieldset_id = ?' => $object->getId(), + 'store_id IN(?)' => $delete + ); + $adapter->delete($this->getTable('eav/form_fieldset_label'), $where); + } + + if (!empty($update)) { + foreach ($update as $storeId => $label) { + $bind = array('label' => $label); + $where = array( + 'fieldset_id =?' => $object->getId(), + 'store_id =?' => $storeId + ); + $adapter->update($this->getTable('eav/form_fieldset_label'), $bind, $where); + } + } + } + + return parent::_afterSave($object); + } + + /** + * Retrieve fieldset labels for stores + * + * @param Mage_Eav_Model_Form_Fieldset $object + * @return array + */ + public function getLabels($object) + { + $objectId = $object->getId(); + if (!$objectId) { + return array(); + } + $adapter = $this->_getReadAdapter(); + $bind = array(':fieldset_id' => $objectId); + $select = $adapter->select() + ->from($this->getTable('eav/form_fieldset_label'), array('store_id', 'label')) + ->where('fieldset_id = :fieldset_id'); + + return $adapter->fetchPairs($select, $bind); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Eav_Model_Form_Fieldset $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + + $labelExpr = $select->getAdapter()->getIfNullSql('store_label.label', 'default_label.label'); + + $select + ->joinLeft( + array('default_label' => $this->getTable('eav/form_fieldset_label')), + $this->getMainTable() . '.fieldset_id = default_label.fieldset_id AND default_label.store_id=0', + array()) + ->joinLeft( + array('store_label' => $this->getTable('eav/form_fieldset_label')), + $this->getMainTable() . '.fieldset_id = store_label.fieldset_id AND default_label.store_id=' + . (int)$object->getStoreId(), + array('label' => $labelExpr) + ); + + return $select; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset/Collection.php new file mode 100755 index 0000000000..b39225bfd9 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Fieldset/Collection.php @@ -0,0 +1,135 @@ + + */ +class Mage_Eav_Model_Resource_Form_Fieldset_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Store scope ID + * + * @var int + */ + protected $_storeId; + + /** + * Initialize collection model + * + */ + protected function _construct() + { + $this->_init('eav/form_fieldset'); + } + + /** + * Add Form Type filter to collection + * + * @param Mage_Eav_Model_Form_Type|int $type + * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection + */ + public function addTypeFilter($type) + { + if ($type instanceof Mage_Eav_Model_Form_Type) { + $type = $type->getId(); + } + + return $this->addFieldToFilter('type_id', $type); + } + + /** + * Set order by fieldset sort order + * + * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection + */ + public function setSortOrder() + { + $this->setOrder('sort_order', self::SORT_ORDER_ASC); + return $this; + } + + /** + * Retrieve label store scope + * + * @return int + */ + public function getStoreId() + { + if (is_null($this->_storeId)) { + return Mage::app()->getStore()->getId(); + } + return $this->_storeId; + } + + /** + * Set store scope ID + * + * @param int $storeId + * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection + */ + public function setStoreId($storeId) + { + $this->_storeId = $storeId; + return $this; + } + + /** + * Initialize select object + * + * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $select = $this->getSelect(); + $select->join( + array('default_label' => $this->getTable('eav/form_fieldset_label')), + 'main_table.fieldset_id = default_label.fieldset_id AND default_label.store_id = 0', + array()); + if ($this->getStoreId() == 0) { + $select->columns('label', 'default_label'); + } else { + $labelExpr = $select->getAdapter() + ->getIfNullSql('store_label.label', 'default_label.label'); + $joinCondition = $this->getConnection() + ->quoteInto( + 'main_table.fieldset_id = store_label.fieldset_id AND store_label.store_id = ?', + (int)$this->getStoreId()); + $select->joinLeft( + array('store_label' => $this->getTable('eav/form_fieldset_label')), + $joinCondition, + array('label' => $labelExpr) + ); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Type.php b/app/code/core/Mage/Eav/Model/Resource/Form/Type.php new file mode 100755 index 0000000000..86f66b7b4d --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Type.php @@ -0,0 +1,155 @@ + + */ +class Mage_Eav_Model_Resource_Form_Type extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('eav/form_type', 'type_id'); + $this->addUniqueField(array( + 'field' => array('code', 'theme', 'store_id'), + 'title' => Mage::helper('eav')->__('Form Type with the same code') + )); + } + + /** + * Load an object + * + * @param Mage_Eav_Model_Form_Type $object + * @param mixed $value + * @param string $field field to load by (defaults to model id) + * @return Mage_Eav_Model_Resource_Form_Type + */ + public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + { + if (is_null($field) && !is_numeric($value)) { + $field = 'code'; + } + return parent::load($object, $value, $field); + } + + /** + * Retrieve form type entity types + * + * @param Mage_Eav_Model_Form_Type $object + * @return array + */ + public function getEntityTypes($object) + { + $objectId = $object->getId(); + if (!$objectId) { + return array(); + } + $adapter = $this->_getReadAdapter(); + $bind = array(':type_id' => $objectId); + $select = $adapter->select() + ->from($this->getTable('eav/form_type_entity'), 'entity_type_id') + ->where('type_id = :type_id'); + + return $adapter->fetchCol($select, $bind); + } + + /** + * Save entity types after save form type + * + * @see Mage_Core_Model_Resource_Db_Abstract#_afterSave($object) + * + * @param Mage_Eav_Model_Form_Type $object + * @return Mage_Eav_Model_Resource_Form_Type + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->hasEntityTypes()) { + $new = $object->getEntityTypes(); + $old = $this->getEntityTypes($object); + + $insert = array_diff($new, $old); + $delete = array_diff($old, $new); + + $adapter = $this->_getWriteAdapter(); + + if (!empty($insert)) { + $data = array(); + foreach ($insert as $entityId) { + if (empty($entityId)) { + continue; + } + $data[] = array( + 'entity_type_id' => (int)$entityId, + 'type_id' => $object->getId() + ); + } + if ($data) { + $adapter->insertMultiple($this->getTable('eav/form_type_entity'), $data); + } + } + + if (!empty($delete)) { + $where = array( + 'entity_type_id IN (?)' => $delete, + 'type_id = ?' => $object->getId() + ); + $adapter->delete($this->getTable('eav/form_type_entity'), $where); + } + } + + return parent::_afterSave($object); + } + + /** + * Retrieve form type filtered by given attribute + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute + * @return array + */ + public function getFormTypesByAttribute($attribute) + { + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + $attribute = $attribute->getId(); + } + if (!$attribute) { + return array(); + } + $bind = array(':attribute_id' => $attribute); + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('eav/form_element')) + ->where('attribute_id = :attribute_id'); + + return $this->_getReadAdapter()->fetchAll($select, $bind); + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Type/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Form/Type/Collection.php new file mode 100755 index 0000000000..2350f42955 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Type/Collection.php @@ -0,0 +1,77 @@ + + */ +class Mage_Eav_Model_Resource_Form_Type_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize collection model + * + */ + protected function _construct() + { + $this->_init('eav/form_type'); + } + + /** + * Convert items array to array for select options + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('type_id', 'label'); + } + + /** + * Add Entity type filter to collection + * + * @param Mage_Eav_Model_Entity_Type|int $entity + * @return Mage_Eav_Model_Resource_Form_Type_Collection + */ + public function addEntityTypeFilter($entity) + { + if ($entity instanceof Mage_Eav_Model_Entity_Type) { + $entity = $entity->getId(); + } + + $this->getSelect() + ->join( + array('form_type_entity' => $this->getTable('eav/form_type_entity')), + 'main_table.type_id = form_type_entity.type_id', + array()) + ->where('form_type_entity.entity_type_id = ?', $entity); + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Eav/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..cc92e1a692 --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,114 @@ + + */ +class Mage_Eav_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Mysql4 +{ + /** + * Mysql column - Table DDL type pairs + * + * @var array + */ + protected $_ddlColumnTypes = array( + Varien_Db_Ddl_Table::TYPE_BOOLEAN => 'bool', + Varien_Db_Ddl_Table::TYPE_SMALLINT => 'smallint', + Varien_Db_Ddl_Table::TYPE_INTEGER => 'int', + Varien_Db_Ddl_Table::TYPE_BIGINT => 'bigint', + Varien_Db_Ddl_Table::TYPE_FLOAT => 'float', + Varien_Db_Ddl_Table::TYPE_DECIMAL => 'decimal', + Varien_Db_Ddl_Table::TYPE_NUMERIC => 'decimal', + Varien_Db_Ddl_Table::TYPE_DATE => 'date', + Varien_Db_Ddl_Table::TYPE_TIMESTAMP => 'timestamp', + Varien_Db_Ddl_Table::TYPE_TEXT => 'text', + Varien_Db_Ddl_Table::TYPE_BLOB => 'blob', + ); + + /** + * Returns columns for select + * + * @param string $tableAlias + * @param string $eavType + * @return string|array + */ + public function attributeSelectFields($tableAlias, $eavType) + { + return '*'; + } + + /** + * Returns DDL type by column type in database + * + * @param string $columnType + * @return string + */ + public function getDdlTypeByColumnType($columnType) + { + switch ($columnType) { + case 'varchar': + $columnType = 'text'; + break; + case 'tinyint': + $columnType = 'smallint'; + break; + } + + return array_search($columnType, $this->_ddlColumnTypes); + } + + /** + * Prepares value fields for unions depend on type + * + * @param string $value + * @param string $eavType + * @return Zend_Db_Expr + */ + public function prepareEavAttributeValue($value, $eavType) + { + return $value; + } + + /** + * Groups selects to separate unions depend on type + * + * @param array $selects + * @return array + */ + public function getLoadAttributesSelectGroups($selects) + { + $mainGroup = array(); + foreach ($selects as $eavType => $selectGroup) { + $mainGroup = array_merge($mainGroup, $selectGroup); + } + return array($mainGroup); + } +} diff --git a/app/code/core/Mage/Eav/etc/config.xml b/app/code/core/Mage/Eav/etc/config.xml index 9b85b61a95..0468570098 100644 --- a/app/code/core/Mage/Eav/etc/config.xml +++ b/app/code/core/Mage/Eav/etc/config.xml @@ -21,46 +21,77 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.16 + 1.6.0.0 Mage_Eav_Model - eav_mysql4 + eav_resource - - - Mage_Eav_Model_Mysql4 + + Mage_Eav_Model_Resource + eav_mysql4 - eav_entity
    - eav_entity
    - eav_entity_type
    - eav_entity_store
    - eav_entity_attribute
    - eav_attribute
    - eav_attribute_set
    - eav_attribute_group
    - eav_attribute_option
    - eav_attribute_option_value
    - eav_attribute_label
    - eav_form_type
    - eav_form_type_entity
    - eav_form_fieldset
    - eav_form_fieldset_label
    - eav_form_element
    + + eav_entity
    +
    + + eav_entity
    +
    + + eav_entity_type
    +
    + + eav_entity_store
    +
    + + eav_entity_attribute
    +
    + + eav_attribute
    +
    + + eav_attribute_set
    +
    + + eav_attribute_group
    +
    + + eav_attribute_option
    +
    + + eav_attribute_option_value
    +
    + + eav_attribute_label
    +
    + + eav_form_type
    +
    + + eav_form_type_entity
    +
    + + eav_form_fieldset
    +
    + + eav_form_fieldset_label
    +
    + + eav_form_element
    +
    -
    +
    - @@ -81,20 +112,8 @@ -
    - @@ -106,7 +125,6 @@ - diff --git a/app/code/core/Mage/Eav/sql/eav_setup/install-1.6.0.0.php b/app/code/core/Mage/Eav/sql/eav_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..e1ec737b38 --- /dev/null +++ b/app/code/core/Mage/Eav/sql/eav_setup/install-1.6.0.0.php @@ -0,0 +1,1157 @@ +startSetup(); + +/** + * Create table 'eav/entity_type' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/entity_type')) + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Type Id') + ->addColumn('entity_type_code', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + ), 'Entity Type Code') + ->addColumn('entity_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Entity Model') + ->addColumn('attribute_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Attribute Model') + ->addColumn('entity_table', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Entity Table') + ->addColumn('value_table_prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Value Table Prefix') + ->addColumn('entity_id_field', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Entity Id Field') + ->addColumn('is_data_sharing', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Defines Is Data Sharing') + ->addColumn('data_sharing_key', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + 'default' => 'default', + ), 'Data Sharing Key') + ->addColumn('default_attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Default Attribute Set Id') + ->addColumn('increment_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + 'default' => '', + ), 'Increment Model') + ->addColumn('increment_per_store', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Increment Per Store') + ->addColumn('increment_pad_length', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '8', + ), 'Increment Pad Length') + ->addColumn('increment_pad_char', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + 'nullable' => false, + 'default' => '0', + ), 'Increment Pad Char') + ->addColumn('additional_attribute_table', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + 'default' => '', + ), 'Additional Attribute Table') + ->addColumn('entity_attribute_collection', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + 'default' => '', + ), 'Entity Attribute Collection') + ->addIndex($installer->getIdxName('eav/entity_type', array('entity_type_code')), + array('entity_type_code')) + ->setComment('Eav Entity Type'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/entity')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Set Id') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Increment Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Parent Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Defines Is Entity Active') + ->addIndex($installer->getIdxName('eav/entity', array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName('eav/entity', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('eav/entity', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/entity', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('eav/entity_value_prefix', 'datetime') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('eav/entity_value_prefix', 'datetime'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Attribute Value') + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('attribute_id', 'value')), + array('attribute_id', 'value')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_type_id', 'value')), + array('entity_type_id', 'value')) + ->addIndex( + $installer->getIdxName( + array('eav/entity_value_prefix', 'datetime'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'datetime'), + 'entity_id', + 'eav/entity', + 'entity_id' + ), + 'entity_id', $installer->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'datetime'), + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'datetime'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Prefix'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('eav/entity_value_prefix', 'decimal') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('eav/entity_value_prefix', 'decimal'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Attribute Value') + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('attribute_id', 'value')), + array('attribute_id', 'value')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_type_id', 'value')), + array('entity_type_id', 'value')) + ->addIndex( + $installer->getIdxName( + array('eav/entity_value_prefix', 'decimal'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'decimal'), + 'entity_id', + 'eav/entity', + 'entity_id' + ), + 'entity_id', $installer->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'decimal'), + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'decimal'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Prefix'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('eav/entity_value_prefix', 'int') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('eav/entity_value_prefix', 'int'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Attribute Value') + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('attribute_id', 'value')), + array('attribute_id', 'value')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_type_id', 'value')), + array('entity_type_id', 'value')) + ->addIndex( + $installer->getIdxName( + array('eav/entity_value_prefix', 'int'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'int'), + 'entity_id', + 'eav/entity', + 'entity_id' + ), + 'entity_id', $installer->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'int'), + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'int'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Prefix'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('eav/entity_value_prefix', 'text') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('eav/entity_value_prefix', 'text'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Attribute Value') + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('entity_id')), + array('entity_id')) + ->addIndex( + $installer->getIdxName( + array('eav/entity_value_prefix', 'text'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'text'), + 'entity_id', + 'eav/entity', + 'entity_id' + ), + 'entity_id', $installer->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'text'), + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'text'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Prefix'); +$installer->getConnection()->createTable($table); + +/** + * Create table array('eav/entity_value_prefix', 'varchar') + */ +$table = $installer->getConnection() + ->newTable($installer->getTable(array('eav/entity_value_prefix', 'varchar'))) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Attribute Value') + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('attribute_id', 'value')), + array('attribute_id', 'value')) + ->addIndex($installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_type_id', 'value')), + array('entity_type_id', 'value')) + ->addIndex( + $installer->getIdxName( + array('eav/entity_value_prefix', 'varchar'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'varchar'), + 'entity_id', + 'eav/entity', + 'entity_id' + ), + 'entity_id', $installer->getTable('eav/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName( + array('eav/entity_value_prefix', 'varchar'), + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + array('eav/entity_value_prefix', 'varchar'), + 'store_id', + 'core/store', + 'store_id' + ), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Value Prefix'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute')) + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Attribute Code') + ->addColumn('attribute_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Attribute Model') + ->addColumn('backend_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Backend Model') + ->addColumn('backend_type', Varien_Db_Ddl_Table::TYPE_TEXT, 8, array( + 'nullable' => false, + 'default' => 'static', + ), 'Backend Type') + ->addColumn('backend_table', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Backend Table') + ->addColumn('frontend_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Frontend Model') + ->addColumn('frontend_input', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Frontend Input') + ->addColumn('frontend_label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Frontend Label') + ->addColumn('frontend_class', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Frontend Class') + ->addColumn('source_model', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Source Model') + ->addColumn('is_required', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Defines Is Required') + ->addColumn('is_user_defined', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Defines Is User Defined') + ->addColumn('default_value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Default Value') + ->addColumn('is_unique', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Defines Is Unique') + ->addColumn('note', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Note') + ->addIndex( + $installer->getIdxName( + 'eav/attribute', + array('entity_type_id', 'attribute_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'attribute_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/attribute', array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName('eav/attribute', array('entity_type_id')), + array('entity_type_id')) + ->addForeignKey($installer->getFkName('eav/attribute', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/entity_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/entity_store')) + ->addColumn('entity_store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Store Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('increment_prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => true, + ), 'Increment Prefix') + ->addColumn('increment_last_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => true, + ), 'Last Incremented Id') + ->addIndex($installer->getIdxName('eav/entity_store', array('entity_type_id')), + array('entity_type_id')) + ->addIndex($installer->getIdxName('eav/entity_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('eav/entity_store', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/entity_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Store'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute_set' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute_set')) + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute Set Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_set_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Attribute Set Name') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex( + $installer->getIdxName( + 'eav/attribute_set', + array('entity_type_id', 'attribute_set_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'attribute_set_name'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/attribute_set', array('entity_type_id', 'sort_order')), + array('entity_type_id', 'sort_order')) + ->addForeignKey($installer->getFkName('eav/attribute_set', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute Set'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute_group' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute_group')) + ->addColumn('attribute_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute Group Id') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Set Id') + ->addColumn('attribute_group_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Attribute Group Name') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addColumn('default_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Default Id') + ->addIndex( + $installer->getIdxName( + 'eav/attribute_group', + array('attribute_set_id', 'attribute_group_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_set_id', 'attribute_group_name'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/attribute_group', array('attribute_set_id', 'sort_order')), + array('attribute_set_id', 'sort_order')) + ->addForeignKey( + $installer->getFkName( + 'eav/attribute_group', + 'attribute_set_id', + 'eav/attribute_set', + 'attribute_set_id' + ), + 'attribute_set_id', $installer->getTable('eav/attribute_set'), 'attribute_set_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute Group'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/entity_attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/entity_attribute')) + ->addColumn('entity_attribute_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Attribute Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Type Id') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Set Id') + ->addColumn('attribute_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Group Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex( + $installer->getIdxName( + 'eav/entity_attribute', + array('attribute_set_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_set_id', 'attribute_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex( + $installer->getIdxName( + 'eav/entity_attribute', + array('attribute_group_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_group_id', 'attribute_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/entity_attribute', array('attribute_set_id', 'sort_order')), + array('attribute_set_id', 'sort_order')) + ->addIndex($installer->getIdxName('eav/entity_attribute', array('attribute_id')), + array('attribute_id')) + ->addForeignKey($installer->getFkName('eav/entity_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName( + 'eav/entity_attribute', + 'attribute_group_id', + 'eav/attribute_group', + 'attribute_group_id' + ), + 'attribute_group_id', $installer->getTable('eav/attribute_group'), 'attribute_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Entity Attributes'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute_option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex($installer->getIdxName('eav/attribute_option', array('attribute_id')), + array('attribute_id')) + ->addForeignKey($installer->getFkName('eav/attribute_option', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute Option'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute_option_value' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute_option_value')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Option Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Value') + ->addIndex($installer->getIdxName('eav/attribute_option_value', array('option_id')), + array('option_id')) + ->addIndex($installer->getIdxName('eav/attribute_option_value', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName('eav/attribute_option_value', 'option_id', 'eav/attribute_option', 'option_id'), + 'option_id', $installer->getTable('eav/attribute_option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('eav/attribute_option_value', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute Option Value'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/attribute_label' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/attribute_label')) + ->addColumn('attribute_label_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute Label Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Attribute Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'Value') + ->addIndex($installer->getIdxName('eav/attribute_label', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('eav/attribute_label', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('eav/attribute_label', array('attribute_id', 'store_id')), + array('attribute_id', 'store_id')) + ->addForeignKey($installer->getFkName('eav/attribute_label', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/attribute_label', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Attribute Label'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/form_type' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/form_type')) + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Type Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + ), 'Code') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Label') + ->addColumn('is_system', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is System') + ->addColumn('theme', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => true, + ), 'Theme') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addIndex( + $installer->getIdxName( + 'eav/form_type', + array('code', 'theme', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code', 'theme', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/form_type', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('eav/form_type', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Form Type'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/form_type_entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/form_type_entity')) + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Type Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Type Id') + ->addIndex($installer->getIdxName('eav/form_type_entity', array('entity_type_id')), + array('entity_type_id')) + ->addForeignKey( + $installer->getFkName( + 'eav/form_type_entity', + 'entity_type_id', + 'eav/entity_type', + 'entity_type_id' + ), + 'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/form_type_entity', 'type_id', 'eav/form_type', 'type_id'), + 'type_id', $installer->getTable('eav/form_type'), 'type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Form Type Entity'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/form_fieldset' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/form_fieldset')) + ->addColumn('fieldset_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Fieldset Id') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Type Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + ), 'Code') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex( + $installer->getIdxName( + 'eav/form_fieldset', + array('type_id', 'code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('type_id', 'code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/form_fieldset', array('type_id')), + array('type_id')) + ->addForeignKey($installer->getFkName('eav/form_fieldset', 'type_id', 'eav/form_type', 'type_id'), + 'type_id', $installer->getTable('eav/form_type'), 'type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Form Fieldset'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/form_fieldset_label' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/form_fieldset_label')) + ->addColumn('fieldset_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Fieldset Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store Id') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Label') + ->addIndex($installer->getIdxName('eav/form_fieldset_label', array('fieldset_id')), + array('fieldset_id')) + ->addIndex($installer->getIdxName('eav/form_fieldset_label', array('store_id')), + array('store_id')) + ->addForeignKey( + $installer->getFkName('eav/form_fieldset_label', 'fieldset_id', 'eav/form_fieldset', 'fieldset_id'), + 'fieldset_id', $installer->getTable('eav/form_fieldset'), 'fieldset_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey( + $installer->getFkName('eav/form_fieldset_label', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Form Fieldset Label'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'eav/form_element' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('eav/form_element')) + ->addColumn('element_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Element Id') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Type Id') + ->addColumn('fieldset_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Fieldset Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Attribute Id') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addIndex( + $installer->getIdxName( + 'eav/form_element', + array('type_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('type_id', 'attribute_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('eav/form_element', array('type_id')), + array('type_id')) + ->addIndex($installer->getIdxName('eav/form_element', array('fieldset_id')), + array('fieldset_id')) + ->addIndex($installer->getIdxName('eav/form_element', array('attribute_id')), + array('attribute_id')) + ->addForeignKey($installer->getFkName('eav/form_element', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/form_element', 'fieldset_id', 'eav/form_fieldset', 'fieldset_id'), + 'fieldset_id', $installer->getTable('eav/form_fieldset'), 'fieldset_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('eav/form_element', 'type_id', 'eav/form_type', 'type_id'), + 'type_id', $installer->getTable('eav/form_type'), 'type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Eav Form Element'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-install-0.7.0.php index 34af6a6c57..20105062e0 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.0-0.7.1.php index 96575be691..91115aecc4 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.1-0.7.2.php index 0c72862972..c1d9f225ea 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.10-0.7.11.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.10-0.7.11.php index c4a1bfee12..d550b65125 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.10-0.7.11.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.10-0.7.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.11-0.7.12.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.11-0.7.12.php index 728143818b..006677731c 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.11-0.7.12.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.11-0.7.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.12-0.7.13.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.12-0.7.13.php index a88736136e..4d41f34c8c 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.12-0.7.13.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.12-0.7.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.13-0.7.14.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.13-0.7.14.php index 532d32ac9a..257bd527ba 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.13-0.7.14.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.13-0.7.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.14-0.7.15.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.14-0.7.15.php index 4ad3ad5436..890a58754c 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.14-0.7.15.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.14-0.7.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.15-0.7.16.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.15-0.7.16.php index 49e4cd1160..d48516f121 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.15-0.7.16.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.15-0.7.16.php @@ -20,11 +20,10 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /* @var $installer Mage_Eav_Model_Entity_Setup */ $installer = $this; diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.2-0.7.3.php index 173305dd97..ba4ca73ea4 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.3-0.7.4.php index 2d09f04084..757265ac67 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.4-0.7.5.php index 86726da2ec..3f7a84c247 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.5-0.7.6.php index 27ce586947..b446d706c9 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.6-0.7.7.php index 1392365457..3733927f8b 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.7-0.7.8.php index ab9a23fd8f..6403521318 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.8-0.7.9.php index 409d0a603f..9207e74d0a 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.9-0.7.10.php index 5041677a0b..b0f89935bf 100644 --- a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..fe762b1125 --- /dev/null +++ b/app/code/core/Mage/Eav/sql/eav_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,2237 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute'), + 'FK_EAV_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_group'), + 'FK_EAV_ATTRIBUTE_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_label'), + 'FK_ATTRIBUTE_LABEL_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_label'), + 'FK_ATTRIBUTE_LABEL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_option'), + 'FK_ATTRIBUTE_OPTION_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_option_value'), + 'FK_ATTRIBUTE_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_option_value'), + 'FK_ATTRIBUTE_OPTION_VALUE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/attribute_set'), + 'FK_EAV_ATTRIBUTE_SET' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity'), + 'FK_EAV_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity'), + 'FK_EAV_ENTITY_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIBUTE_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIBUTE_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIVUTE_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIVUTE_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_store'), + 'FK_EAV_ENTITY_STORE_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/entity_store'), + 'FK_EAV_ENTITY_STORE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_element'), + 'FK_EAV_FORM_ELEMENT_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_element'), + 'FK_EAV_FORM_ELEMENT_FORM_FIELDSET' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_element'), + 'FK_EAV_FORM_ELEMENT_FORM_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_fieldset_label'), + 'FK_EAV_FORM_FIELDSET_LABEL_FORM_FIELDSET' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_fieldset_label'), + 'FK_EAV_FORM_FIELDSET_LABEL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_type'), + 'FK_EAV_FORM_TYPE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_type_entity'), + 'FK_EAV_FORM_TYPE_ENTITY_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_type_entity'), + 'FK_EAV_FORM_TYPE_ENTITY_FORM_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('eav/form_fieldset'), + 'FK_EAV_FORM_FIELDSET_FORM_TYPE' +); + + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_EAV_ENTITY_DATETIME_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_EAV_ENTITY_DATETIME_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_EAV_ENTITY_DATETIME_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_EAV_ENTITY_DECIMAL_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_EAV_ENTITY_DECIMAL_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_EAV_ENTITY_DECIMAL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_EAV_ENTITY_INT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_EAV_ENTITY_INT_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_EAV_ENTITY_INT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_EAV_ENTITY_TEXT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_EAV_ENTITY_TEXT_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_EAV_ENTITY_TEXT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_EAV_ENTITY_VARCHAR_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_EAV_ENTITY_VARCHAR_ENTITY_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_EAV_ENTITY_VARCHAR_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute'), + 'ENTITY_TYPE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_group'), + 'ATTRIBUTE_SET_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_group'), + 'ATTRIBUTE_SET_ID_2' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_label'), + 'IDX_ATTRIBUTE_LABEL_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_label'), + 'IDX_ATTRIBUTE_LABEL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_label'), + 'IDX_ATTRIBUTE_LABEL_ATTRIBUTE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_option'), + 'FK_ATTRIBUTE_OPTION_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_option_value'), + 'FK_ATTRIBUTE_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_option_value'), + 'FK_ATTRIBUTE_OPTION_VALUE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_set'), + 'ENTITY_TYPE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/attribute_set'), + 'ENTITY_TYPE_ID_2' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity'), + 'FK_ENTITY_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity'), + 'FK_ENTITY_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_attribute'), + 'ATTRIBUTE_SET_ID_2' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_attribute'), + 'ATTRIBUTE_GROUP_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_attribute'), + 'ATTRIBUTE_SET_ID_3' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_attribute'), + 'FK_EAV_ENTITY_ATTRIVUTE_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_store'), + 'FK_EAV_ENTITY_STORE_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_store'), + 'FK_EAV_ENTITY_STORE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/entity_type'), + 'ENTITY_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_element'), + 'UNQ_FORM_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_element'), + 'IDX_FORM_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_element'), + 'IDX_FORM_FIELDSET' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_element'), + 'IDX_FORM_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_fieldset'), + 'UNQ_FORM_FIELDSET_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_fieldset'), + 'IDX_FORM_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_fieldset_label'), + 'IDX_FORM_FIELDSET' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_fieldset_label'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_type'), + 'UNQ_FORM_TYPE_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_type'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('eav/form_type_entity'), + 'IDX_EAV_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'UNQ_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_ATTRIBUTE_DATETIME_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_ATTRIBUTE_DATETIME_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_ATTRIBUTE_DATETIME_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'FK_ATTRIBUTE_DATETIME_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'VALUE_BY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'VALUE_BY_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'UNQ_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_ATTRIBUTE_DECIMAL_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_ATTRIBUTE_DECIMAL_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_ATTRIBUTE_DECIMAL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'FK_ATTRIBUTE_DECIMAL_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'VALUE_BY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'VALUE_BY_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'UNQ_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_ATTRIBUTE_INT_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_ATTRIBUTE_INT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_ATTRIBUTE_INT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'FK_ATTRIBUTE_INT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'VALUE_BY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'VALUE_BY_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'UNQ_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_ATTRIBUTE_TEXT_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_ATTRIBUTE_TEXT_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_ATTRIBUTE_TEXT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'FK_ATTRIBUTE_TEXT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'UNQ_ATTRIBUTE_VALUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_ATTRIBUTE_VARCHAR_ENTITY_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_ATTRIBUTE_VARCHAR_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_ATTRIBUTE_VARCHAR_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'FK_ATTRIBUTE_VARCHAR_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'VALUE_BY_ATTRIBUTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'VALUE_BY_ENTITY_TYPE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('eav/entity') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type Id' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Set Id' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Increment Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Parent Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Defines Is Entity Active' + ) + ), + 'comment' => 'Eav Entity' + ), + $installer->getTable('eav/entity_type') => array( + 'columns' => array( + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Type Id' + ), + 'entity_type_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Entity Type Code' + ), + 'entity_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Entity Model' + ), + 'attribute_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Attribute Model' + ), + 'entity_table' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Entity Table' + ), + 'value_table_prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Value Table Prefix' + ), + 'entity_id_field' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Entity Id Field' + ), + 'is_data_sharing' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Defines Is Data Sharing' + ), + 'data_sharing_key' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'default' => 'default', + 'comment' => 'Data Sharing Key' + ), + 'default_attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Default Attribute Set Id' + ), + 'increment_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => true, + 'default' => '', + 'comment' => 'Increment Model' + ), + 'increment_per_store' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Increment Per Store' + ), + 'increment_pad_length' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '8', + 'comment' => 'Increment Pad Length' + ), + 'increment_pad_char' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Increment Pad Char' + ), + 'additional_attribute_table' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => true, + 'default' => '', + 'comment' => 'Additional Attribute Table' + ), + 'entity_attribute_collection' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => true, + 'default' => '', + 'comment' => 'Entity Attribute Collection' + ) + ), + 'comment' => 'Eav Entity Type' + ), + $installer->getTable('eav/entity_store') => array( + 'columns' => array( + 'entity_store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Store Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'increment_prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Increment Prefix' + ), + 'increment_last_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Last Incremented Id' + ) + ), + 'comment' => 'Eav Entity Store' + ), + $installer->getTable('eav/entity_attribute') => array( + 'columns' => array( + 'entity_attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Attribute Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type Id' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Set Id' + ), + 'attribute_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Group Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Id' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Eav Entity Attributes' + ), + $installer->getTable('eav/attribute') => array( + 'columns' => array( + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Attribute Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type Id' + ), + 'attribute_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Attribute Code' + ), + 'attribute_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Attribute Model' + ), + 'backend_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Backend Model' + ), + 'backend_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 8, + 'nullable' => false, + 'default' => 'static', + 'comment' => 'Backend Type' + ), + 'backend_table' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Backend Table' + ), + 'frontend_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Frontend Model' + ), + 'frontend_input' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Frontend Input' + ), + 'frontend_label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Frontend Label' + ), + 'frontend_class' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Frontend Class' + ), + 'source_model' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Source Model' + ), + 'is_required' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Defines Is Required' + ), + 'is_user_defined' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Defines Is User Defined' + ), + 'default_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Default Value' + ), + 'is_unique' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Defines Is Unique' + ), + 'note' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Note' + ) + ), + 'comment' => 'Eav Attribute' + ), + $installer->getTable('eav/attribute_set') => array( + 'columns' => array( + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Attribute Set Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Type Id' + ), + 'attribute_set_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Attribute Set Name' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Eav Attribute Set' + ), + $installer->getTable('eav/attribute_group') => array( + 'columns' => array( + 'attribute_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Attribute Group Id' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Set Id' + ), + 'attribute_group_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Attribute Group Name' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ), + 'default_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Default Id' + ) + ), + 'comment' => 'Eav Attribute Group' + ), + $installer->getTable('eav/attribute_option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Id' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Eav Attribute Option' + ), + $installer->getTable('eav/attribute_option_value') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Option Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Value' + ) + ), + 'comment' => 'Eav Attribute Option Value' + ), + $installer->getTable('eav/attribute_label') => array( + 'columns' => array( + 'attribute_label_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Attribute Label Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Value' + ) + ), + 'comment' => 'Eav Attribute Label' + ), + $installer->getTable('eav/form_type') => array( + 'columns' => array( + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Type Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Code' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Label' + ), + 'is_system' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is System' + ), + 'theme' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Theme' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Eav Form Type' + ), + $installer->getTable('eav/form_type_entity') => array( + 'columns' => array( + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Type Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Entity Type Id' + ) + ), + 'comment' => 'Eav Form Type Entity' + ), + $installer->getTable('eav/form_fieldset') => array( + 'columns' => array( + 'fieldset_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Fieldset Id' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Type Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Code' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Eav Form Fieldset' + ), + $installer->getTable('eav/form_fieldset_label') => array( + 'columns' => array( + 'fieldset_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Fieldset Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Label' + ) + ), + 'comment' => 'Eav Form Fieldset Label' + ), + $installer->getTable('eav/form_element') => array( + 'columns' => array( + 'element_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Element Id' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Type Id' + ), + 'fieldset_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Fieldset Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Attribute Id' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ) + ), + 'comment' => 'Eav Form Element' + ) + , + $installer->getTable(array('eav/entity_value_prefix', 'datetime')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Attribute Value' + ) + ), + 'comment' => 'Eav Entity Value Prefix' + ), + $installer->getTable(array('eav/entity_value_prefix', 'decimal')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Attribute Value' + ) + ), + 'comment' => 'Eav Entity Value Prefix' + ), + $installer->getTable(array('eav/entity_value_prefix', 'int')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Attribute Value' + ) + ), + 'comment' => 'Eav Entity Value Prefix' + ), + $installer->getTable(array('eav/entity_value_prefix', 'text')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Attribute Value' + ) + ), + 'comment' => 'Eav Entity Value Prefix' + ), + $installer->getTable(array('eav/entity_value_prefix', 'varchar')) => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Attribute Value' + ) + ), + 'comment' => 'Eav Entity Value Prefix' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute'), + $installer->getIdxName( + 'eav/attribute', + array('entity_type_id', 'attribute_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'attribute_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute'), + $installer->getIdxName('eav/attribute', array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_group'), + $installer->getIdxName( + 'eav/attribute_group', + array('attribute_set_id', 'attribute_group_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_set_id', 'attribute_group_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_group'), + $installer->getIdxName('eav/attribute_group', array('attribute_set_id', 'sort_order')), + array('attribute_set_id', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_label'), + $installer->getIdxName('eav/attribute_label', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_label'), + $installer->getIdxName('eav/attribute_label', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_label'), + $installer->getIdxName('eav/attribute_label', array('attribute_id', 'store_id')), + array('attribute_id', 'store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_option'), + $installer->getIdxName('eav/attribute_option', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_option_value'), + $installer->getIdxName('eav/attribute_option_value', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_option_value'), + $installer->getIdxName('eav/attribute_option_value', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_set'), + $installer->getIdxName( + 'eav/attribute_set', + array('entity_type_id', 'attribute_set_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_type_id', 'attribute_set_name'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/attribute_set'), + $installer->getIdxName('eav/attribute_set', array('entity_type_id', 'sort_order')), + array('entity_type_id', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity'), + $installer->getIdxName('eav/entity', array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity'), + $installer->getIdxName('eav/entity', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_attribute'), + $installer->getIdxName( + 'eav/entity_attribute', + array('attribute_set_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_set_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_attribute'), + $installer->getIdxName( + 'eav/entity_attribute', + array('attribute_group_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('attribute_group_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_attribute'), + $installer->getIdxName('eav/entity_attribute', array('attribute_set_id', 'sort_order')), + array('attribute_set_id', 'sort_order') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_attribute'), + $installer->getIdxName('eav/entity_attribute', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_store'), + $installer->getIdxName('eav/entity_store', array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_store'), + $installer->getIdxName('eav/entity_store', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/entity_type'), + $installer->getIdxName('eav/entity_type', array('entity_type_code')), + array('entity_type_code') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_element'), + $installer->getIdxName( + 'eav/form_element', + array('type_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('type_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_element'), + $installer->getIdxName('eav/form_element', array('type_id')), + array('type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_element'), + $installer->getIdxName('eav/form_element', array('fieldset_id')), + array('fieldset_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_element'), + $installer->getIdxName('eav/form_element', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_fieldset'), + $installer->getIdxName( + 'eav/form_fieldset', + array('type_id', 'code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('type_id', 'code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_fieldset'), + $installer->getIdxName('eav/form_fieldset', array('type_id')), + array('type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_fieldset_label'), + $installer->getIdxName('eav/form_fieldset_label', array('fieldset_id')), + array('fieldset_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_fieldset_label'), + $installer->getIdxName('eav/form_fieldset_label', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_type'), + $installer->getIdxName( + 'eav/form_type', + array('code', 'theme', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code', 'theme', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_type'), + $installer->getIdxName('eav/form_type', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('eav/form_type_entity'), + $installer->getIdxName('eav/form_type_entity', array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName( + array('eav/entity_value_prefix', 'datetime'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('attribute_id', 'value')), + array('attribute_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + $installer->getIdxName(array('eav/entity_value_prefix', 'datetime'), array('entity_type_id', 'value')), + array('entity_type_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName( + array('eav/entity_value_prefix', 'decimal'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('attribute_id', 'value')), + array('attribute_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + $installer->getIdxName(array('eav/entity_value_prefix', 'decimal'), array('entity_type_id', 'value')), + array('entity_type_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName( + array('eav/entity_value_prefix', 'int'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('attribute_id', 'value')), + array('attribute_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'int')), + $installer->getIdxName(array('eav/entity_value_prefix', 'int'), array('entity_type_id', 'value')), + array('entity_type_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + $installer->getIdxName( + array('eav/entity_value_prefix', 'text'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + $installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + $installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + $installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'text')), + $installer->getIdxName(array('eav/entity_value_prefix', 'text'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName( + array('eav/entity_value_prefix', 'varchar'), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_id', 'attribute_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_type_id')), + array('entity_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('attribute_id', 'value')), + array('attribute_id', 'value') +); + +$installer->getConnection()->addIndex( + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + $installer->getIdxName(array('eav/entity_value_prefix', 'varchar'), array('entity_type_id', 'value')), + array('entity_type_id', 'value') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable('eav/attribute'), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_group', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'), + $installer->getTable('eav/attribute_group'), + 'attribute_set_id', + $installer->getTable('eav/attribute_set'), + 'attribute_set_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_label', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('eav/attribute_label'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_label', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/attribute_label'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_option', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('eav/attribute_option'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_option_value', 'option_id', 'eav/attribute_option', 'option_id'), + $installer->getTable('eav/attribute_option_value'), + 'option_id', + $installer->getTable('eav/attribute_option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_option_value', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/attribute_option_value'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/attribute_set', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable('eav/attribute_set'), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable('eav/entity'), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/entity'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('eav/entity_attribute'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity_attribute', 'attribute_group_id', 'eav/attribute_group', 'attribute_group_id'), + $installer->getTable('eav/entity_attribute'), + 'attribute_group_id', + $installer->getTable('eav/attribute_group'), + 'attribute_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity_store', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable('eav/entity_store'), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/entity_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/entity_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_element', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('eav/form_element'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_element', 'fieldset_id', 'eav/form_fieldset', 'fieldset_id'), + $installer->getTable('eav/form_element'), + 'fieldset_id', + $installer->getTable('eav/form_fieldset'), + 'fieldset_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_element', 'type_id', 'eav/form_type', 'type_id'), + $installer->getTable('eav/form_element'), + 'type_id', + $installer->getTable('eav/form_type'), + 'type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_fieldset', 'type_id', 'eav/form_type', 'type_id'), + $installer->getTable('eav/form_fieldset'), + 'type_id', + $installer->getTable('eav/form_type'), + 'type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_fieldset_label', 'fieldset_id', 'eav/form_fieldset', 'fieldset_id'), + $installer->getTable('eav/form_fieldset_label'), + 'fieldset_id', + $installer->getTable('eav/form_fieldset'), + 'fieldset_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_fieldset_label', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/form_fieldset_label'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_type', 'store_id', 'core/store', 'store_id'), + $installer->getTable('eav/form_type'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_type_entity', 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable('eav/form_type_entity'), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('eav/form_type_entity', 'type_id', 'eav/form_type', 'type_id'), + $installer->getTable('eav/form_type_entity'), + 'type_id', + $installer->getTable('eav/form_type'), + 'type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'datetime'), 'entity_id', 'eav/entity', 'entity_id'), + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'entity_id', + $installer->getTable('eav/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'datetime'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'datetime'), 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable(array('eav/entity_value_prefix', 'datetime')), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'decimal'), 'entity_id', 'eav/entity', 'entity_id'), + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'entity_id', + $installer->getTable('eav/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'decimal'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'decimal'), 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable(array('eav/entity_value_prefix', 'decimal')), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'int'), 'entity_id', 'eav/entity', 'entity_id'), + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'entity_id', + $installer->getTable('eav/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'int'), 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'int'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('eav/entity_value_prefix', 'int')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'text'), 'entity_id', 'eav/entity', 'entity_id'), + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'entity_id', + $installer->getTable('eav/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'text'), 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'text'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('eav/entity_value_prefix', 'text')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'varchar'), 'entity_id', 'eav/entity', 'entity_id'), + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'entity_id', + $installer->getTable('eav/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'varchar'), 'store_id', 'core/store', 'store_id'), + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName(array('eav/entity_value_prefix', 'varchar'), 'entity_type_id', 'eav/entity_type', 'entity_type_id'), + $installer->getTable(array('eav/entity_value_prefix', 'varchar')), + 'entity_type_id', + $installer->getTable('eav/entity_type'), + 'entity_type_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php index 4551f1d8fb..fbec821c35 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Product/Helper/Form/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php index cfcafa29d0..cf121368ad 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Giftoptions.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Giftoptions.php index 22c70b07d8..aa68d28548 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Giftoptions.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Giftoptions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php index 8cfd281b6e..65f54e7b95 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Form.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Form.php index 82a0d3bc56..a3ddbe355b 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Form.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Giftoptions.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Giftoptions.php index fc011089b5..1ae7f4cde2 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Giftoptions.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Giftoptions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Items.php b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Items.php index 2ede214ac0..61aa686244 100644 --- a/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Items.php +++ b/app/code/core/Mage/GiftMessage/Block/Adminhtml/Sales/Order/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Message/Form.php b/app/code/core/Mage/GiftMessage/Block/Message/Form.php index c1eb92d611..b728a52ce8 100644 --- a/app/code/core/Mage/GiftMessage/Block/Message/Form.php +++ b/app/code/core/Mage/GiftMessage/Block/Message/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Message/Helper.php b/app/code/core/Mage/GiftMessage/Block/Message/Helper.php index eca0208226..48eb3147cd 100644 --- a/app/code/core/Mage/GiftMessage/Block/Message/Helper.php +++ b/app/code/core/Mage/GiftMessage/Block/Message/Helper.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Block/Message/Inline.php b/app/code/core/Mage/GiftMessage/Block/Message/Inline.php index abdb5dc7ee..a8c01b5727 100644 --- a/app/code/core/Mage/GiftMessage/Block/Message/Inline.php +++ b/app/code/core/Mage/GiftMessage/Block/Message/Inline.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Helper/Data.php b/app/code/core/Mage/GiftMessage/Helper/Data.php index 41de72d412..db5be0b396 100644 --- a/app/code/core/Mage/GiftMessage/Helper/Data.php +++ b/app/code/core/Mage/GiftMessage/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Helper/Message.php b/app/code/core/Mage/GiftMessage/Helper/Message.php index 660a2a03a5..bd34c60d4e 100644 --- a/app/code/core/Mage/GiftMessage/Helper/Message.php +++ b/app/code/core/Mage/GiftMessage/Helper/Message.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Helper/Url.php b/app/code/core/Mage/GiftMessage/Helper/Url.php index 24886b6543..60f7cd9301 100644 --- a/app/code/core/Mage/GiftMessage/Helper/Url.php +++ b/app/code/core/Mage/GiftMessage/Helper/Url.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Model/Api.php b/app/code/core/Mage/GiftMessage/Model/Api.php index bf44cb17a1..c444913e1b 100644 --- a/app/code/core/Mage/GiftMessage/Model/Api.php +++ b/app/code/core/Mage/GiftMessage/Model/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Model/Api/V2.php b/app/code/core/Mage/GiftMessage/Model/Api/V2.php index d402a2b2fe..62c9d32216 100644 --- a/app/code/core/Mage/GiftMessage/Model/Api/V2.php +++ b/app/code/core/Mage/GiftMessage/Model/Api/V2.php @@ -1,105 +1,105 @@ - - */ -class Mage_GiftMessage_Model_Api_V2 extends Mage_GiftMessage_Model_Api -{ - - /** - * Return an Array of Object attributes. - * - * @param Mixed $data - * @return Array - */ - protected function _prepareData($data){ - if (is_object($data)) { - $arr = get_object_vars($data); - foreach ($arr as $key => $value) { - $assocArr = array(); - if (is_array($value)) { - foreach ($value as $v) { - if (is_object($v) && count(get_object_vars($v))==2 - && isset($v->key) && isset($v->value)) { - $assocArr[$v->key] = $v->value; - } - } - } - if (!empty($assocArr)) { - $arr[$key] = $assocArr; - } - } - $arr = $this->_prepareData($arr); - return parent::_prepareData($arr); - } - if (is_array($data)) { - foreach ($data as $key => $value) { - if (is_object($value) || is_array($value)) { - $data[$key] = $this->_prepareData($value); - } else { - $data[$key] = $value; - } - } - return parent::_prepareData($data); - } - return $data; - } - - /** - * Raise event for setting a giftMessage. - * - * @param String $entityId - * @param Mage_Core_Controller_Request_Http $request - * @param Mage_Sales_Model_Quote $quote - * @return stdClass - */ - protected function _setGiftMessage($entityId, $request, $quote) { - $response = new stdClass(); - $response->entityId = $entityId; - - /** - * Below code will catch exceptions only in DeveloperMode - * @see Mage_Core_Model_App::_callObserverMethod($object, $method, $observer) - * And result of Mage::dispatchEvent will always return an Object of Mage_Core_Model_App. - */ - try { - Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$request, 'quote'=>$quote)); - $response->result = true; - $response->error = ''; - } catch (Exception $e) { - $response->result = false; - $response->error = $e->getMessage(); - } - return $response; - } - -} -?> + + */ +class Mage_GiftMessage_Model_Api_V2 extends Mage_GiftMessage_Model_Api +{ + + /** + * Return an Array of Object attributes. + * + * @param Mixed $data + * @return Array + */ + protected function _prepareData($data){ + if (is_object($data)) { + $arr = get_object_vars($data); + foreach ($arr as $key => $value) { + $assocArr = array(); + if (is_array($value)) { + foreach ($value as $v) { + if (is_object($v) && count(get_object_vars($v))==2 + && isset($v->key) && isset($v->value)) { + $assocArr[$v->key] = $v->value; + } + } + } + if (!empty($assocArr)) { + $arr[$key] = $assocArr; + } + } + $arr = $this->_prepareData($arr); + return parent::_prepareData($arr); + } + if (is_array($data)) { + foreach ($data as $key => $value) { + if (is_object($value) || is_array($value)) { + $data[$key] = $this->_prepareData($value); + } else { + $data[$key] = $value; + } + } + return parent::_prepareData($data); + } + return $data; + } + + /** + * Raise event for setting a giftMessage. + * + * @param String $entityId + * @param Mage_Core_Controller_Request_Http $request + * @param Mage_Sales_Model_Quote $quote + * @return stdClass + */ + protected function _setGiftMessage($entityId, $request, $quote) { + $response = new stdClass(); + $response->entityId = $entityId; + + /** + * Below code will catch exceptions only in DeveloperMode + * @see Mage_Core_Model_App::_callObserverMethod($object, $method, $observer) + * And result of Mage::dispatchEvent will always return an Object of Mage_Core_Model_App. + */ + try { + Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$request, 'quote'=>$quote)); + $response->result = true; + $response->error = ''; + } catch (Exception $e) { + $response->result = false; + $response->error = $e->getMessage(); + } + return $response; + } + +} +?> diff --git a/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Backend/Boolean/Config.php b/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Backend/Boolean/Config.php index 655ca7ea1d..be091c320d 100644 --- a/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Backend/Boolean/Config.php +++ b/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Backend/Boolean/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Source/Boolean/Config.php b/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Source/Boolean/Config.php index 7439fe28a8..1e19bb589f 100644 --- a/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Source/Boolean/Config.php +++ b/app/code/core/Mage/GiftMessage/Model/Entity/Attribute/Source/Boolean/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Model/Message.php b/app/code/core/Mage/GiftMessage/Model/Message.php index ede384ba09..031d36ec25 100644 --- a/app/code/core/Mage/GiftMessage/Model/Message.php +++ b/app/code/core/Mage/GiftMessage/Model/Message.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,19 @@ /** * Gift Message model * - * @category Mage - * @package Mage_GiftMessage + * @method Mage_GiftMessage_Model_Resource_Message _getResource() + * @method Mage_GiftMessage_Model_Resource_Message getResource() + * @method int getCustomerId() + * @method Mage_GiftMessage_Model_Message setCustomerId(int $value) + * @method string getSender() + * @method Mage_GiftMessage_Model_Message setSender(string $value) + * @method string getRecipient() + * @method Mage_GiftMessage_Model_Message setRecipient(string $value) + * @method string getMessage() + * @method Mage_GiftMessage_Model_Message setMessage(string $value) + * + * @category Mage + * @package Mage_GiftMessage * @author Magento Core Team */ class Mage_GiftMessage_Model_Message extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/GiftMessage/Model/Mysql4/Message.php b/app/code/core/Mage/GiftMessage/Model/Mysql4/Message.php index a09156a948..37fdb9d222 100644 --- a/app/code/core/Mage/GiftMessage/Model/Mysql4/Message.php +++ b/app/code/core/Mage/GiftMessage/Model/Mysql4/Message.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,10 @@ /** * Gift Message resource model * - * @category Mage - * @package Mage_GiftMessage + * @category Mage + * @package Mage_GiftMessage * @author Magento Core Team */ -class Mage_GiftMessage_Model_Mysql4_Message extends Mage_Core_Model_Mysql4_Abstract +class Mage_GiftMessage_Model_Mysql4_Message extends Mage_GiftMessage_Model_Resource_Message { - - protected function _construct() - { - $this->_init('giftmessage/message', 'gift_message_id'); - } - } diff --git a/app/code/core/Mage/GiftMessage/Model/Mysql4/Message/Collection.php b/app/code/core/Mage/GiftMessage/Model/Mysql4/Message/Collection.php index 2aaae1592b..4d02befac5 100644 --- a/app/code/core/Mage/GiftMessage/Model/Mysql4/Message/Collection.php +++ b/app/code/core/Mage/GiftMessage/Model/Mysql4/Message/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,10 @@ /** * Gift Message collection * - * @category Mage - * @package Mage_GiftMessage + * @category Mage + * @package Mage_GiftMessage * @author Magento Core Team */ -class Mage_GiftMessage_Model_Mysql4_Message_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_GiftMessage_Model_Mysql4_Message_Collection extends Mage_GiftMessage_Model_Resource_Message_Collection { - - protected function _construct() - { - $this->_init('giftmessage/message'); - } - } diff --git a/app/code/core/Mage/GiftMessage/Model/Mysql4/Setup.php b/app/code/core/Mage/GiftMessage/Model/Mysql4/Setup.php index 611d9aea3b..45558f511d 100644 --- a/app/code/core/Mage/GiftMessage/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/GiftMessage/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,10 +28,10 @@ /** * Gift Message resource setup * - * @category Mage - * @package Mage_GiftMessage + * @category Mage + * @package Mage_GiftMessage * @author Magento Core Team */ -class Mage_GiftMessage_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup +class Mage_GiftMessage_Model_Mysql4_Setup extends Mage_GiftMessage_Model_Resource_Setup { } diff --git a/app/code/core/Mage/GiftMessage/Model/Observer.php b/app/code/core/Mage/GiftMessage/Model/Observer.php index 7ac998738e..fabd9288a5 100644 --- a/app/code/core/Mage/GiftMessage/Model/Observer.php +++ b/app/code/core/Mage/GiftMessage/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/Model/Resource/Message.php b/app/code/core/Mage/GiftMessage/Model/Resource/Message.php new file mode 100755 index 0000000000..75067bebca --- /dev/null +++ b/app/code/core/Mage/GiftMessage/Model/Resource/Message.php @@ -0,0 +1,45 @@ + + */ +class Mage_GiftMessage_Model_Resource_Message extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('giftmessage/message', 'gift_message_id'); + } +} diff --git a/app/code/core/Mage/GiftMessage/Model/Resource/Message/Collection.php b/app/code/core/Mage/GiftMessage/Model/Resource/Message/Collection.php new file mode 100755 index 0000000000..b63b414636 --- /dev/null +++ b/app/code/core/Mage/GiftMessage/Model/Resource/Message/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_GiftMessage_Model_Resource_Message_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('giftmessage/message'); + } +} diff --git a/app/code/core/Mage/GiftMessage/Model/Resource/Setup.php b/app/code/core/Mage/GiftMessage/Model/Resource/Setup.php new file mode 100755 index 0000000000..f5f4560d64 --- /dev/null +++ b/app/code/core/Mage/GiftMessage/Model/Resource/Setup.php @@ -0,0 +1,37 @@ + + */ +class Mage_GiftMessage_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/GiftMessage/controllers/IndexController.php b/app/code/core/Mage/GiftMessage/controllers/IndexController.php index 5b66657856..938c66188e 100644 --- a/app/code/core/Mage/GiftMessage/controllers/IndexController.php +++ b/app/code/core/Mage/GiftMessage/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/etc/api.xml b/app/code/core/Mage/GiftMessage/etc/api.xml index ce9eeda49c..955ea21876 100644 --- a/app/code/core/Mage/GiftMessage/etc/api.xml +++ b/app/code/core/Mage/GiftMessage/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GiftMessage/etc/config.xml b/app/code/core/Mage/GiftMessage/etc/config.xml index 9ec490b907..f7b5b90893 100644 --- a/app/code/core/Mage/GiftMessage/etc/config.xml +++ b/app/code/core/Mage/GiftMessage/etc/config.xml @@ -21,42 +21,47 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.6 + 1.6.0.0 - Mage_GiftMessage_Block + + Mage_GiftMessage_Block + - - Mage_GiftMessage_Helper + + + Mage_GiftMessage_Helper + Mage_GiftMessage_Model - giftmessage_mysql4 + giftmessage_resource - - Mage_GiftMessage_Model_Mysql4 + + Mage_GiftMessage_Model_Resource + giftmessage_mysql4 gift_message
    -
    +
    - Mage_GiftMessage - Mage_GiftMessage_Model_Mysql4_Setup + Mage_GiftMessage + Mage_GiftMessage_Model_Resource_Setup @@ -70,7 +75,6 @@
    - @@ -79,7 +83,6 @@ - @@ -134,7 +137,7 @@ giftmessage/observer salesEventOrderToQuote - + @@ -143,7 +146,7 @@ giftmessage/observer salesEventOrderItemToQuoteItem - + diff --git a/app/code/core/Mage/GiftMessage/etc/system.xml b/app/code/core/Mage/GiftMessage/etc/system.xml index c1f502d35f..90e14b2b1b 100644 --- a/app/code/core/Mage/GiftMessage/etc/system.xml +++ b/app/code/core/Mage/GiftMessage/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/install-1.6.0.0.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..6a671fa540 --- /dev/null +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/install-1.6.0.0.php @@ -0,0 +1,102 @@ +startSetup(); + +/** + * Create table 'gift_message' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('giftmessage/message')) + ->addColumn('gift_message_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'GiftMessage Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer id') + ->addColumn('sender', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sender') + ->addColumn('recipient', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Recipient') + ->addColumn('message', Varien_Db_Ddl_Table::TYPE_TEXT, null, array( + ), 'Message') + ->setComment('Gift Message'); + +$installer->getConnection()->createTable($table); + +/** + * Add 'gift_message_id' attributes for entities + */ +$entities = array( + 'quote', + 'quote_address', + 'quote_item', + 'quote_address_item', + 'order', + 'order_item' +); +$options = array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'visible' => false, + 'required' => false +); +foreach ($entities as $entity) { + $installer->addAttribute($entity, 'gift_message_id', $options); +} + +/** + * Add 'gift_message_available' attributes for entities + */ +$installer->addAttribute('order_item', 'gift_message_available', $options) + ->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'gift_message_available', array( + 'group' => 'Gift Options', + 'backend' => 'catalog/product_attribute_backend_boolean', + 'frontend' => '', + 'label' => 'Allow Gift Message', + 'input' => 'select', + 'class' => '', + 'source' => 'eav/entity_attribute_source_boolean', + 'global' => true, + 'visible' => true, + 'required' => false, + 'user_defined' => false, + 'default' => '', + 'apply_to' => '', + 'input_renderer' => 'giftmessage/adminhtml_product_helper_form_config', + 'is_configurable' => 0, + 'visible_on_front' => false + )); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-install-0.7.0.php index ebbde8890b..796fe48cab 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-install-0.7.0.php @@ -20,12 +20,12 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; -/* $installer Mage_Core_Model_Resource_Setup */ +/* $installer Mage_GiftMessage_Model_Resource_Setup */ $installer->startSetup(); diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.1.3-0.7.0.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.1.3-0.7.0.php index 12263e2ace..63847e559c 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.1.3-0.7.0.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.1.3-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $this->startSetup() diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.0-0.7.1.php index 19124d8851..a0cb1e93cb 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.1-0.7.2.php index a7a23d8433..495b8fd1ec 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,4 +33,4 @@ $installer->addAttribute('quote_address_item', 'gift_message_id', array('type' => 'int', 'visible' => false, 'required' => false)); $installer->addAttribute('order', 'gift_message_id', array('type' => 'int', 'visible' => false, 'required' => false)); $installer->addAttribute('order_item', 'gift_message_id', array('type' => 'int', 'visible' => false, 'required' => false)); -$installer->addAttribute('order_item', 'gift_message_available', array('type' => 'int', 'visible' => false, 'required' => false)); +$installer->addAttribute('order_item', 'gift_message_available', array('type' => 'int', 'visible' => false, 'required' => false)); diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.2-0.7.3.php index 4158e52c6e..6ba6d46ff1 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.3-0.7.4.php index 427966989d..ae0c9fe8cc 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php index 3dccfde6ec..91cbebd9a4 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php index c6b2eb2931..0e9744859d 100644 --- a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GiftMessage - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..e6755c77fb --- /dev/null +++ b/app/code/core/Mage/GiftMessage/sql/giftmessage_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,125 @@ +startSetup(); + +/** + * Change columns + */ +$tables = array( + $installer->getTable('giftmessage/message') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'GiftMessage Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer id' + ), + 'sender' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sender' + ), + 'recipient' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Recipient' + ), + 'message' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'comment' => 'Message' + ) + ), + 'comment' => 'Gift Message' + ), + $installer->getTable('sales/quote') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ) + ) + ), + $installer->getTable('sales/quote_address') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ) + ) + ), + $installer->getTable('sales/quote_item') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ) + ) + ), + $installer->getTable('sales/quote_address_item') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ) + ) + ), + $installer->getTable('sales/order') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ) + ) + ), + $installer->getTable('sales/order_item') => array( + 'columns' => array( + 'gift_message_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Id' + ), + 'gift_message_available' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Gift Message Available' + ) + ) + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php index d41aa0d856..e6a7cb41e0 100644 --- a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php +++ b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleAnalytics/Helper/Data.php b/app/code/core/Mage/GoogleAnalytics/Helper/Data.php index 4c159f9469..bc988e3b11 100644 --- a/app/code/core/Mage/GoogleAnalytics/Helper/Data.php +++ b/app/code/core/Mage/GoogleAnalytics/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleAnalytics/Model/Observer.php b/app/code/core/Mage/GoogleAnalytics/Model/Observer.php index 6c30581162..b0c645b252 100644 --- a/app/code/core/Mage/GoogleAnalytics/Model/Observer.php +++ b/app/code/core/Mage/GoogleAnalytics/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -95,7 +95,7 @@ public function injectAnalyticsInGoogleCheckoutLink(Varien_Event_Observer $obser $beforeHtml = $block->getBeforeHtml(); $protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http'; $block->setBeforeHtml($beforeHtml . '' + . '://checkout.google.com/files/digital/ga_post.js" type="text/javascript">' ); $this->_isGoogleCheckoutLinkAdded = true; } diff --git a/app/code/core/Mage/GoogleAnalytics/etc/adminhtml.xml b/app/code/core/Mage/GoogleAnalytics/etc/adminhtml.xml index 1aa3054727..aa55a986f6 100644 --- a/app/code/core/Mage/GoogleAnalytics/etc/adminhtml.xml +++ b/app/code/core/Mage/GoogleAnalytics/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GoogleAnalytics/etc/config.xml b/app/code/core/Mage/GoogleAnalytics/etc/config.xml index 2e89b3f2db..9dc495e591 100644 --- a/app/code/core/Mage/GoogleAnalytics/etc/config.xml +++ b/app/code/core/Mage/GoogleAnalytics/etc/config.xml @@ -21,23 +21,26 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 - - Mage_GoogleAnalytics_Model + + Mage_GoogleAnalytics_Model + - Mage_GoogleAnalytics_Block + + Mage_GoogleAnalytics_Block + @@ -45,7 +48,6 @@ - @@ -90,7 +92,6 @@ - diff --git a/app/code/core/Mage/GoogleAnalytics/etc/system.xml b/app/code/core/Mage/GoogleAnalytics/etc/system.xml index c18a717b54..48e034a3e6 100644 --- a/app/code/core/Mage/GoogleAnalytics/etc/system.xml +++ b/app/code/core/Mage/GoogleAnalytics/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleAnalytics - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php index 71c7bfaaec..a278708f26 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -48,7 +48,9 @@ public function getConfirmButtonHtml() 'label' => $this->__('Confirm'), 'onclick' => "if($('user_confirm').value != '') { - setLocation('".$this->getUrl('*/*/confirmCaptcha', array('_current'=>true))."' + 'user_confirm/' + $('user_confirm').value + '/'); + setLocation('" + . $this->getUrl('*/*/confirmCaptcha', array('_current'=>true)) + . "' + 'user_confirm/' + $('user_confirm').value + '/'); }", 'class' => 'task' )); diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php index 065e5c88a7..43abb68b12 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php index 513c202414..71aeaabf19 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -128,23 +128,23 @@ protected function _prepareMassaction() $this->getMassactionBlock()->addItem('delete', array( 'label' => $this->__('Delete'), - 'url' => $this->getUrl('*/*/massDelete', array('_current'=>true)), + 'url' => $this->getUrl('*/*/massDelete', array('_current' => true)), 'confirm' => $this->__('Are you sure?') )); $this->getMassactionBlock()->addItem('publish', array( 'label' => $this->__('Publish'), - 'url' => $this->getUrl('*/*/massPublish', array('_current'=>true)) + 'url' => $this->getUrl('*/*/massPublish', array('_current' => true)) )); $this->getMassactionBlock()->addItem('unpublish', array( 'label' => $this->__('Hide'), - 'url' => $this->getUrl('*/*/massHide', array('_current'=>true)) + 'url' => $this->getUrl('*/*/massHide', array('_current' => true)) )); $this->getMassactionBlock()->addItem('refresh', array( 'label' => $this->__('Synchronize'), - 'url' => $this->getUrl('*/*/refresh', array('_current'=>true)), + 'url' => $this->getUrl('*/*/refresh', array('_current' => true)), 'confirm' => $this->__('This action will update items statistics and remove the items which are not available in Google Base. Continue?') )); return $this; @@ -174,7 +174,7 @@ protected function _prepareMassaction() public function getGridUrl() { - return $this->getUrl('*/*/grid', array('_current'=>true)); + return $this->getUrl('*/*/grid', array('_current' => true)); } protected function _getStore() diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php index 4cc9d47642..1dd0601e6b 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -44,9 +44,9 @@ public function __construct() protected function _beforeToHtml() { - $this->setId($this->getId().'_'.$this->getIndex()); - $this->getChild('reset_filter_button')->setData('onclick', $this->getJsObjectName().'.resetFilter()'); - $this->getChild('search_button')->setData('onclick', $this->getJsObjectName().'.doFilter()'); + $this->setId($this->getId() . '_' . $this->getIndex()); + $this->getChild('reset_filter_button')->setData('onclick', $this->getJsObjectName() . '.resetFilter()'); + $this->getChild('search_button')->setData('onclick', $this->getJsObjectName() . '.doFilter()'); return parent::_beforeToHtml(); } @@ -138,14 +138,14 @@ protected function _prepareMassaction() $this->getMassactionBlock()->addItem('add', array( 'label' => $this->__('Add to Google Base'), - 'url' => $this->getUrl('*/*/massAdd', array('_current'=>true)), + 'url' => $this->getUrl('*/*/massAdd', array('_current' => true)), )); return $this; } public function getGridUrl() { - return $this->getUrl('*/googlebase_selection/grid', array('index' => $this->getIndex(),'_current'=>true)); + return $this->getUrl('*/googlebase_selection/grid', array('index' => $this->getIndex(), '_current' => true)); } protected function _getGoogleBaseProductIds() diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php index bd4d26469b..e0fd55b668 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Items/Renderer/Id.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php index 6f1f31bf56..409cd4232d 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Store/Switcher.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php index 6596942f8e..f07108391e 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php index b6806131fd..5b246e234b 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php index d1e0df64e7..c675b4c15c 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -82,8 +82,8 @@ public function getGbaseAttributesSelectHtml() } $select = $this->getLayout()->createBlock('adminhtml/html_select') - ->setId($this->getFieldId().'_{{index}}_gattribute') - ->setName($this->getFieldName().'[{{index}}][gbase_attribute]') + ->setId($this->getFieldId() . '_{{index}}_gattribute') + ->setName($this->getFieldName() . '[{{index}}][gbase_attribute]') ->setOptions($options); return $select->getHtml(); } @@ -97,8 +97,8 @@ public function getGbaseAttributesSelectHtml() public function getAttributesSelectHtml($escapeJsQuotes = false) { $select = $this->getLayout()->createBlock('adminhtml/html_select') - ->setId($this->getFieldId().'_{{index}}_attribute') - ->setName($this->getFieldName().'[{{index}}][attribute_id]') + ->setId($this->getFieldId() . '_{{index}}_attribute') + ->setName($this->getFieldName() . '[{{index}}][attribute_id]') ->setOptions($this->_getAttributes($this->getAttributeSetId(), $escapeJsQuotes)); return $select->getHtml(); } diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php index 674d1ed389..a7426c335f 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php index 21dafa21f0..b697e539da 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php index 094ba9261f..c569b4fb2d 100644 --- a/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php +++ b/app/code/core/Mage/GoogleBase/Block/Adminhtml/Types/Renderer/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/Helper/Data.php b/app/code/core/Mage/GoogleBase/Helper/Data.php index 0f1c16fe85..7ae7c11957 100644 --- a/app/code/core/Mage/GoogleBase/Helper/Data.php +++ b/app/code/core/Mage/GoogleBase/Helper/Data.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Data Helper * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Attribute.php index 54beb4b16c..eab2bf953f 100644 --- a/app/code/core/Mage/GoogleBase/Model/Attribute.php +++ b/app/code/core/Mage/GoogleBase/Model/Attribute.php @@ -20,13 +20,23 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Attributes Model * + * @method Mage_GoogleBase_Model_Resource_Attribute _getResource() + * @method Mage_GoogleBase_Model_Resource_Attribute getResource() + * @method int getAttributeId() + * @method Mage_GoogleBase_Model_Attribute setAttributeId(int $value) + * @method string getGbaseAttribute() + * @method Mage_GoogleBase_Model_Attribute setGbaseAttribute(string $value) + * @method int getTypeId() + * @method Mage_GoogleBase_Model_Attribute setTypeId(int $value) + * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Config.php b/app/code/core/Mage/GoogleBase/Model/Config.php index 6232b09b6f..753b86e60e 100644 --- a/app/code/core/Mage/GoogleBase/Model/Config.php +++ b/app/code/core/Mage/GoogleBase/Model/Config.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Config model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team @@ -38,7 +39,7 @@ class Mage_GoogleBase_Model_Config extends Varien_Object * * @param string $key Var path key * @param int $storeId Store View Id - * @return mixed + * @return mixed */ public function getConfigData($key, $storeId = null) { diff --git a/app/code/core/Mage/GoogleBase/Model/Item.php b/app/code/core/Mage/GoogleBase/Model/Item.php index 590dc54b2a..7fb2170f3f 100644 --- a/app/code/core/Mage/GoogleBase/Model/Item.php +++ b/app/code/core/Mage/GoogleBase/Model/Item.php @@ -20,13 +20,37 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Item Types Model * + * @method Mage_GoogleBase_Model_Resource_Item _getResource() + * @method Mage_GoogleBase_Model_Resource_Item getResource() + * @method int getTypeId() + * @method Mage_GoogleBase_Model_Item setTypeId(int $value) + * @method int getProductId() + * @method Mage_GoogleBase_Model_Item setProductId(int $value) + * @method string getGbaseItemId() + * @method Mage_GoogleBase_Model_Item setGbaseItemId(string $value) + * @method int getStoreId() + * @method Mage_GoogleBase_Model_Item setStoreId(int $value) + * @method string getPublished() + * @method Mage_GoogleBase_Model_Item setPublished(string $value) + * @method string getExpires() + * @method Mage_GoogleBase_Model_Item setExpires(string $value) + * @method int getImpr() + * @method Mage_GoogleBase_Model_Item setImpr(int $value) + * @method int getClicks() + * @method Mage_GoogleBase_Model_Item setClicks(int $value) + * @method int getViews() + * @method Mage_GoogleBase_Model_Item setViews(int $value) + * @method int getIsHidden() + * @method Mage_GoogleBase_Model_Item setIsHidden(int $value) + * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team @@ -264,8 +288,10 @@ protected function _getAttributeLabel($attribute, $storeId) $frontendLabel = array_shift($frontendLabel); } if (!$this->_translations) { + $moduleName = Mage_Catalog_Model_Entity_Attribute::MODULE_NAME; + $separator = Mage_Core_Model_Translate::SCOPE_SEPARATOR; $this->_translations = Mage::getModel('core/translate_string') - ->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel) + ->load($moduleName . $separator . $frontendLabel) ->getStoreTranslations(); } if (isset($this->_translations[$storeId])) { diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php index 35202d181f..8846a796a3 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Base Attributes resource model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Attribute extends Mage_Core_Model_Mysql4_Abstract +class Mage_GoogleBase_Model_Mysql4_Attribute extends Mage_GoogleBase_Model_Resource_Attribute { - protected function _construct() - { - $this->_init('googlebase/attributes', 'id'); - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php index 4fbe21bc51..3047ff99a6 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Attribute/Collection.php @@ -20,75 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * GoogleBase Attributes collection * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Attribute_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_GoogleBase_Model_Mysql4_Attribute_Collection extends Mage_GoogleBase_Model_Resource_Attribute_Collection { - /** - * Whether to join attribute_set_id to attributes or not - */ - protected $_joinAttributeSetFlag = true; - - - protected function _construct() - { - $this->_init('googlebase/attribute'); - } - - public function addAttributeSetFilter($attributeSetId, $targetCountry) - { - if (!$this->getJoinAttributeSetFlag()) { - return $this; - } - $this->getSelect()->where('attribute_set_id = ?', $attributeSetId); - $this->getSelect()->where('target_country = ?', $targetCountry); - return $this; - } - - public function addTypeFilter($type_id) - { - $this->getSelect()->where('main_table.type_id = ?', $type_id); - return $this; - } - - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - if ($this->getJoinAttributeSetFlag()) { - $this->_joinAttributeSet(); - } - parent::load($printQuery, $logQuery); - return $this; - } - - protected function _joinAttributeSet() - { - $this->getSelect() - ->joinInner( - array('types'=>$this->getTable('googlebase/types')), - 'main_table.type_id=types.type_id', - array('attribute_set_id' => 'types.attribute_set_id', 'target_country' => 'types.target_country')); - return $this; - } - - public function getJoinAttributeSetFlag() - { - return $this->_joinAttributeSetFlag; - } - - public function setJoinAttributeSetFlag($flag) - { - return $this->_joinAttributeSetFlag = (bool)$flag; - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php index 8cd8f9de9a..0755730899 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item.php @@ -20,52 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Base Item resource model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Item extends Mage_Core_Model_Mysql4_Abstract +class Mage_GoogleBase_Model_Mysql4_Item extends Mage_GoogleBase_Model_Resource_Item { - protected function _construct() - { - $this->_init('googlebase/items', 'item_id'); - } - - /** - * Load Item model by product - * - * @param Mage_GoogleBase_Model_Item $model - * @return Mage_GoogleBase_Model_Mysql4_Item - */ - public function loadByProduct($model) - { - if (!($model->getProduct() instanceof Varien_Object)) { - return $this; - } - - $product = $model->getProduct(); - $productId = $product->getId(); - $storeId = $model->getStoreId() ? $model->getStoreId() : $product->getStoreId(); - - $read = $this->_getReadAdapter(); - $select = $read->select(); - - if ($productId !== null) { - $select->from($this->getMainTable()) - ->where("product_id = ?", $productId) - ->where('store_id = ?', (int)$storeId); - - $data = $read->fetchRow($select); - $data = is_array($data) ? $data : array(); - $model->addData($data); - } - return $this; - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php index 1b239b32a0..6fa9a7cf83 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Item/Collection.php @@ -20,105 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Base items collection * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_GoogleBase_Model_Mysql4_Item_Collection extends Mage_GoogleBase_Model_Resource_Item_Collection { - protected function _construct() - { - $this->_init('googlebase/item'); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinTables(); - return $this; - } - - /** - * Deprecated - * - * @param int $storeId - * @return Mage_GoogleBase_Model_Mysql4_Item_Collection - */ - public function addStoreFilterId($storeId) - { - return $this->addStoreFilter($storeId); - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_GoogleBase_Model_Mysql4_Item_Collection - */ - public function addStoreFilter($storeIds) - { - $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); - return $this; - } - - public function addProductFilterId($productId) - { - $this->getSelect()->where('main_table.product_id=?', $productId); - return $this; - } - - public function addFieldToFilter($field, $condition=null) - { - if ($field == 'name') { - $conditionSql = $this->_getConditionSql('IFNULL(p.value, p_d.value)', $condition); - $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); - } else { - parent::addFieldToFilter($field, $condition); - } - } - - /** - * Join product and type data - * - * @return Mage_GoogleBase_Model_Mysql4_Item_Collection - */ - protected function _joinTables() - { - $entityType = Mage::getSingleton('eav/config')->getEntityType('catalog_product'); - $attribute = Mage::getModel('eav/config')->getAttribute($entityType->getEntityTypeId(),'name'); - - $joinConditionDefault = sprintf("p_d.attribute_id=%d AND p_d.store_id='0' AND main_table.product_id=p_d.entity_id", - $attribute->getAttributeId() - ); - $joinCondition = sprintf("p.attribute_id=%d AND p.store_id=main_table.store_id AND main_table.product_id=p.entity_id", - $attribute->getAttributeId() - ); - - $this->getSelect() - ->joinLeft( - array('p_d' => $attribute->getBackend()->getTable()), - $joinConditionDefault, - array()); - - $this->getSelect() - ->joinLeft( - array('p' => $attribute->getBackend()->getTable()), - $joinCondition, - array('name' => new Zend_Db_Expr('IFNULL(p.value, p_d.value)'))); - - $this->getSelect() - ->joinLeft( - array('types' => $this->getTable('googlebase/types')), - 'main_table.type_id=types.type_id', - array('gbase_itemtype' => new Zend_Db_Expr('IFNULL(types.gbase_itemtype, \''.Mage_GoogleBase_Model_Service_Item::DEFAULT_ITEM_TYPE .'\')'))); - - return $this; - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php index 6e61d1ac8e..048c048ab5 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type.php @@ -20,38 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Base Type resource model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Type extends Mage_Core_Model_Mysql4_Abstract +class Mage_GoogleBase_Model_Mysql4_Type extends Mage_GoogleBase_Model_Resource_Type { - protected function _construct() - { - $this->_init('googlebase/types', 'type_id'); - } - - /** - * Return Type ID by Attribute Set Id and target country - * - * @param int $attributeSetId Attribute Set - * @param string $targetCountry Two-letters country ISO code - * @return int - */ - public function getTypeIdByAttributeSetId($attributeSetId, $targetCountry) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'type_id') - ->where('attribute_set_id=?', $attributeSetId) - ->where('target_country=?', $targetCountry); - - return $this->_getReadAdapter()->fetchOne($select); - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php index e0eec59a38..ba2e43d8db 100644 --- a/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php +++ b/app/code/core/Mage/GoogleBase/Model/Mysql4/Type/Collection.php @@ -20,72 +20,19 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * GoogleBase Item Types collection * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team */ -class Mage_GoogleBase_Model_Mysql4_Type_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_GoogleBase_Model_Mysql4_Type_Collection extends Mage_GoogleBase_Model_Resource_Type_Collection { - - protected function _construct() - { - $this->_init('googlebase/type'); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinAttributeSet(); - return $this; - } - - /** - * Add total count of Items for each type - * - * @return Mage_GoogleBase_Model_Mysql4_Type_Collection - */ - public function addItemsCount() - { - $this->getSelect() - ->joinLeft( - array('items'=>$this->getTable('googlebase/items')), - 'main_table.type_id=items.type_id', - array('items_total' => 'COUNT(items.item_id)')) - ->group('main_table.type_id'); - return $this; - } - - /** - * Add country ISO filter to collection - * - * @param string $iso Two-letter country ISO code - * @return Mage_GoogleBase_Model_Mysql4_Type_Collection - */ - public function addCountryFilter($iso) - { - $this->getSelect()->where('target_country=?', $iso); - return $this; - } - - /** - * Join Attribute Set data - * - * @return Mage_GoogleBase_Model_Mysql4_Type_Collection - */ - protected function _joinAttributeSet() - { - $this->getSelect() - ->join( - array('set'=>$this->getTable('eav/attribute_set')), - 'main_table.attribute_set_id=set.attribute_set_id', - array('attribute_set_name' => 'set.attribute_set_name')); - return $this; - } } diff --git a/app/code/core/Mage/GoogleBase/Model/Observer.php b/app/code/core/Mage/GoogleBase/Model/Observer.php index 327fbd8021..9949c7b426 100644 --- a/app/code/core/Mage/GoogleBase/Model/Observer.php +++ b/app/code/core/Mage/GoogleBase/Model/Observer.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Observer * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team @@ -57,7 +58,8 @@ public function saveProductItem($observer) } catch (Exception $e) { if (Mage::app()->getStore()->isAdmin()) { Mage::getSingleton('adminhtml/session')->addNotice( - Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", Mage::app()->getStore($item->getStoreId())->getName()) + Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", + Mage::app()->getStore($item->getStoreId())->getName()) ); } else { throw $e; @@ -87,7 +89,8 @@ public function deleteProductItem($observer) } catch (Exception $e) { if (Mage::app()->getStore()->isAdmin()) { Mage::getSingleton('adminhtml/session')->addNotice( - Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", Mage::app()->getStore($item->getStoreId())->getName()) + Mage::helper('googlebase')->__("Cannot update Google Base Item for Store '%s'", + Mage::app()->getStore($item->getStoreId())->getName()) ); } else { throw $e; diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php new file mode 100755 index 0000000000..279bf23841 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute.php @@ -0,0 +1,46 @@ + + */ +class Mage_GoogleBase_Model_Resource_Attribute extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/attributes', 'id'); + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php new file mode 100755 index 0000000000..9386765994 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Attribute/Collection.php @@ -0,0 +1,140 @@ + + */ +class Mage_GoogleBase_Model_Resource_Attribute_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Whether to join attribute_set_id to attributes or not + * + * @var boolean + */ + protected $_joinAttributeSetFlag = true; + + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/attribute'); + } + + /** + * Filter collection by attribute set id + * + * @param int $attributeSetId + * @param string $targetCountry + * @return Mage_GoogleBase_Model_Resource_Attribute_Collection + */ + public function addAttributeSetFilter($attributeSetId, $targetCountry) + { + if (!$this->getJoinAttributeSetFlag()) { + return $this; + } + $select = $this->getSelect(); + $select->where('attribute_set_id = ?', $attributeSetId); + $select->where('target_country = ?', $targetCountry); + return $this; + } + + /** + * Add type filter + * + * @param int $type_id + * @return Mage_GoogleBase_Model_Resource_Attribute_Collection + */ + public function addTypeFilter($type_id) + { + $this->getSelect()->where('main_table.type_id = ?', $type_id); + return $this; + } + + /** + * Load data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_GoogleBase_Model_Resource_Attribute_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + if ($this->getJoinAttributeSetFlag()) { + $this->_joinAttributeSet(); + } + parent::load($printQuery, $logQuery); + return $this; + } + + /** + * Join attribute set + * + * @return Mage_GoogleBase_Model_Resource_Attribute_Collection + */ + protected function _joinAttributeSet() + { + $this->getSelect() + ->joinInner( + array('types'=>$this->getTable('googlebase/types')), + 'main_table.type_id=types.type_id', + array('attribute_set_id' => 'types.attribute_set_id', + 'target_country' => 'types.target_country') + ); + return $this; + } + + /** + * retrieve Flag + * + * @return boolean + */ + public function getJoinAttributeSetFlag() + { + return $this->_joinAttributeSetFlag; + } + + /** + * Set flag + * + * @param unknown_type $flag + * @return boolean + */ + public function setJoinAttributeSetFlag($flag) + { + return $this->_joinAttributeSetFlag = (bool)$flag; + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Item.php b/app/code/core/Mage/GoogleBase/Model/Resource/Item.php new file mode 100755 index 0000000000..f9c8fbe8c6 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Item.php @@ -0,0 +1,77 @@ + + */ +class Mage_GoogleBase_Model_Resource_Item extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/items', 'item_id'); + } + + /** + * Load Item model by product + * + * @param Mage_GoogleBase_Model_Item $model + * @return Mage_GoogleBase_Model_Resource_Item + */ + public function loadByProduct($model) + { + if (!($model->getProduct() instanceof Varien_Object)) { + return $this; + } + + $product = $model->getProduct(); + $productId = $product->getId(); + $storeId = $model->getStoreId() ? $model->getStoreId() : $product->getStoreId(); + + $adapter = $this->_getReadAdapter(); + $select = $adapter->select(); + + if ($productId !== null) { + $select->from($this->getMainTable()) + ->where('product_id = ?', $productId) + ->where('store_id = ?', (int)$storeId); + + $data = $adapter->fetchRow($select); + $data = is_array($data) ? $data : array(); + $model->addData($data); + } + return $this; + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php new file mode 100755 index 0000000000..d156a0aadd --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Item/Collection.php @@ -0,0 +1,160 @@ + + */ +class Mage_GoogleBase_Model_Resource_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/item'); + } + + /** + * Init collection select + * + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinTables(); + return $this; + } + + /** + * Deprecated + * + * @param int $storeId + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + public function addStoreFilterId($storeId) + { + return $this->addStoreFilter($storeId); + } + + /** + * Filter collection by specified store ids + * + * @param array|int $storeIds + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + public function addStoreFilter($storeIds) + { + $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); + return $this; + } + + /** + * Filter collection by product id + * + * @param int $productId + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + public function addProductFilterId($productId) + { + $this->getSelect()->where('main_table.product_id=?', $productId); + return $this; + } + + /** + * Add field filter to collection + * + * @param string $field + * @param null|string|array $condition + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + public function addFieldToFilter($field, $condition = null) + { + if ($field == 'name') { + $codeExpr = $this->getConnection()->getCheckSql('p.value IS NOT NULL', 'p.value', 'p_d.value'); + $conditionSql = $this->_getConditionSql($codeExpr, $condition); + $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); + } else { + parent::addFieldToFilter($field, $condition); + } + return $this; + } + + /** + * Join product and type data + * + * @return Mage_GoogleBase_Model_Resource_Item_Collection + */ + protected function _joinTables() + { + $adapter = $this->getConnection(); + $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY); + $attribute = Mage::getModel('eav/config')->getAttribute($entityType->getEntityTypeId(), 'name'); + + $joinConditionDefault = $adapter->quoteInto('p_d.attribute_id=?', $attribute->getAttributeId()) . + $adapter->quoteInto(' AND p_d.store_id=?', 0) . ' AND main_table.product_id=p_d.entity_id'; + + $joinCondition = $adapter->quoteInto('p.attribute_id=?', $attribute->getAttributeId()) . + ' AND p.store_id=main_table.store_id AND main_table.product_id=p.entity_id'; + + $this->getSelect() + ->joinLeft( + array('p_d' => $attribute->getBackend()->getTable()), + $joinConditionDefault, + array() + ); + + $codeExpr = $adapter->getCheckSql('p.value IS NOT NULL', 'p.value', 'p_d.value'); + $this->getSelect() + ->joinLeft( + array('p' => $attribute->getBackend()->getTable()), + $joinCondition, + array('name' => $codeExpr) + ); + + $codeExpr = $adapter->getCheckSql( + 'types.gbase_itemtype IS NOT NULL', + 'types.gbase_itemtype', + $adapter->quote(Mage_GoogleBase_Model_Service_Item::DEFAULT_ITEM_TYPE) + ); + + $this->getSelect() + ->joinLeft( + array('types' => $this->getTable('googlebase/types')), + 'main_table.type_id=types.type_id', + array('gbase_itemtype' => $codeExpr) + ); + + return $this; + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Type.php b/app/code/core/Mage/GoogleBase/Model/Resource/Type.php new file mode 100755 index 0000000000..847ff75f36 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Type.php @@ -0,0 +1,64 @@ + + */ +class Mage_GoogleBase_Model_Resource_Type extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/types', 'type_id'); + } + + /** + * Return Type ID by Attribute Set Id and target country + * + * @param int $attributeSetId Attribute Set + * @param string $targetCountry Two-letters country ISO code + * @return int + */ + public function getTypeIdByAttributeSetId($attributeSetId, $targetCountry) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), 'type_id') + ->where('attribute_set_id=?', $attributeSetId) + ->where('target_country=?', $targetCountry); + + return $adapter->fetchOne($select); + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php b/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php new file mode 100755 index 0000000000..7711e67ddf --- /dev/null +++ b/app/code/core/Mage/GoogleBase/Model/Resource/Type/Collection.php @@ -0,0 +1,108 @@ + + */ +class Mage_GoogleBase_Model_Resource_Type_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('googlebase/type'); + } + + /** + * Init collection select + * + * @return Mage_GoogleBase_Model_Resource_Type_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinAttributeSet(); + return $this; + } + + /** + * Add total count of Items for each type + * + * @return Mage_GoogleBase_Model_Resource_Type_Collection + */ + public function addItemsCount() + { + $innerSelect = $this->getConnection()->select() + ->from( + array('inner_items' => $this->getTable('googlebase/items')), + array('type_id', 'cnt' => new Zend_Db_Expr('COUNT(inner_items.item_id)')) + ) + ->group('inner_items.type_id'); + + $this->getSelect() + ->joinLeft( + array('items' => $innerSelect), + 'main_table.type_id=items.type_id', + array('items_total' => 'items.cnt')); + + return $this; + } + + /** + * Add country ISO filter to collection + * + * @param string $iso Two-letter country ISO code + * @return Mage_GoogleBase_Model_Resource_Type_Collection + */ + public function addCountryFilter($iso) + { + $this->getSelect()->where('target_country=?', $iso); + return $this; + } + + /** + * Join Attribute Set data + * + * @return Mage_GoogleBase_Model_Resource_Type_Collection + */ + protected function _joinAttributeSet() + { + $this->getSelect() + ->join( + array('a_set'=>$this->getTable('eav/attribute_set')), + 'main_table.attribute_set_id=a_set.attribute_set_id', + array('attribute_set_name' => 'a_set.attribute_set_name')); + return $this; + } +} diff --git a/app/code/core/Mage/GoogleBase/Model/Service.php b/app/code/core/Mage/GoogleBase/Model/Service.php index 469a8e2cb0..deb998be36 100644 --- a/app/code/core/Mage/GoogleBase/Model/Service.php +++ b/app/code/core/Mage/GoogleBase/Model/Service.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Item Types Model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team @@ -55,7 +56,10 @@ public function getClient($storeId = null, $loginToken = null, $loginCaptcha = n $errorMsg = Mage::helper('googlebase')->__('Unable to connect to Google Base. Please, check Account settings in configuration.'); try { if (! Mage::registry($this->_clientRegistryId)) { - $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, Zend_Gdata_Gbase::AUTH_SERVICE_NAME, null, '', + $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, + Zend_Gdata_Gbase::AUTH_SERVICE_NAME, + null, + '', $loginToken, $loginCaptcha, Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, $type diff --git a/app/code/core/Mage/GoogleBase/Model/Service/Feed.php b/app/code/core/Mage/GoogleBase/Model/Service/Feed.php index 9e467410f2..5a4968029e 100644 --- a/app/code/core/Mage/GoogleBase/Model/Service/Feed.php +++ b/app/code/core/Mage/GoogleBase/Model/Service/Feed.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Feed Model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Service/Item.php b/app/code/core/Mage/GoogleBase/Model/Service/Item.php index 38187fdef5..f79957334d 100644 --- a/app/code/core/Mage/GoogleBase/Model/Service/Item.php +++ b/app/code/core/Mage/GoogleBase/Model/Service/Item.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Item Model * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team @@ -252,7 +253,8 @@ protected function _prepareEnrtyForSave() */ protected function _cleanAtomAttribute($string) { - return Mage::helper('core/string')->substr(preg_replace('/[\pC¢€•—™°½]|shipping/ui', '', $string), 0, 3500); + return Mage::helper('core/string') + ->substr(preg_replace('/[\pC¢€•—™°½]|shipping/ui', '', $string), 0, 3500); } /** @@ -399,7 +401,9 @@ protected function _getAttributeValue($attribute) */ protected function _getItemType() { - return $this->getItemType() ? $this->getItemType() : $this->getConfig()->getDefaultItemType($this->getStoreId()); + return $this->getItemType() + ? $this->getItemType() + : $this->getConfig()->getDefaultItemType($this->getStoreId()); } /** diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php b/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php index ac6ca4136a..d483531766 100644 --- a/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php +++ b/app/code/core/Mage/GoogleBase/Model/Source/Accounttype.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Data Api account types Source * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php b/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php index a569d254ec..4b049e4bcf 100644 --- a/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php +++ b/app/code/core/Mage/GoogleBase/Model/Source/Authtype.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Data Api authorization types Source * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Country.php b/app/code/core/Mage/GoogleBase/Model/Source/Country.php index de8e40c2a4..e19e6eab32 100644 --- a/app/code/core/Mage/GoogleBase/Model/Source/Country.php +++ b/app/code/core/Mage/GoogleBase/Model/Source/Country.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Target country Source * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php b/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php index 3ed4ff7611..44d68cb5e3 100644 --- a/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php +++ b/app/code/core/Mage/GoogleBase/Model/Source/Statuses.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Item statues Source * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/Model/Type.php b/app/code/core/Mage/GoogleBase/Model/Type.php index f4da8b8baa..c9d57fe18f 100644 --- a/app/code/core/Mage/GoogleBase/Model/Type.php +++ b/app/code/core/Mage/GoogleBase/Model/Type.php @@ -20,13 +20,23 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Base Item Types Model * + * @method Mage_GoogleBase_Model_Resource_Type _getResource() + * @method Mage_GoogleBase_Model_Resource_Type getResource() + * @method int getAttributeSetId() + * @method Mage_GoogleBase_Model_Type setAttributeSetId(int $value) + * @method string getGbaseItemtype() + * @method Mage_GoogleBase_Model_Type setGbaseItemtype(string $value) + * @method string getTargetCountry() + * @method Mage_GoogleBase_Model_Type setTargetCountry(string $value) + * + * @deprecated after 1.5.1.0 * @category Mage * @package Mage_GoogleBase * @author Magento Core Team diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php index 266e1f6bb7..cff64df43c 100755 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php +++ b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/ItemsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php index 050fcd1cae..ed362a8d5f 100755 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php +++ b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/SelectionController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php index 1c6bb32952..2fba490bec 100755 --- a/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php +++ b/app/code/core/Mage/GoogleBase/controllers/Adminhtml/Googlebase/TypesController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/controllers/ItemsController.php b/app/code/core/Mage/GoogleBase/controllers/ItemsController.php index a7dca1b6aa..cf2ec99218 100644 --- a/app/code/core/Mage/GoogleBase/controllers/ItemsController.php +++ b/app/code/core/Mage/GoogleBase/controllers/ItemsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/controllers/SelectionController.php b/app/code/core/Mage/GoogleBase/controllers/SelectionController.php index f47397684f..dc5cf26a43 100644 --- a/app/code/core/Mage/GoogleBase/controllers/SelectionController.php +++ b/app/code/core/Mage/GoogleBase/controllers/SelectionController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/controllers/TypesController.php b/app/code/core/Mage/GoogleBase/controllers/TypesController.php index ce840a701a..3043cfd1ce 100644 --- a/app/code/core/Mage/GoogleBase/controllers/TypesController.php +++ b/app/code/core/Mage/GoogleBase/controllers/TypesController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/etc/adminhtml.xml b/app/code/core/Mage/GoogleBase/etc/adminhtml.xml index ce7ad2b65a..f0c80a2266 100644 --- a/app/code/core/Mage/GoogleBase/etc/adminhtml.xml +++ b/app/code/core/Mage/GoogleBase/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -29,20 +29,20 @@ - - Google Base - - - Manage Attributes - adminhtml/googlebase_types - - - Manage Items - adminhtml/googlebase_items - - - 70 - + + + + + + + + + + + + + + @@ -52,20 +52,20 @@ - - Google Base - 500 - - - Manage Attributes - 0 - - - Manage Items - 5 - - - + + + + + + + + + + + + + + diff --git a/app/code/core/Mage/GoogleBase/etc/config.xml b/app/code/core/Mage/GoogleBase/etc/config.xml index d79f191556..85c82997b4 100644 --- a/app/code/core/Mage/GoogleBase/etc/config.xml +++ b/app/code/core/Mage/GoogleBase/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.1.2 + 1.6.0.0 Mage_GoogleBase_Model - googlebase_mysql4 + googlebase_resource - - Mage_GoogleBase_Model_Mysql4 + + Mage_GoogleBase_Model_Resource + googlebase_mysql4 googlebase_types
    @@ -50,7 +51,7 @@ googlebase_attributes
    -
    +
    @@ -65,94 +66,96 @@
    - Mage_GoogleBase_Block + + Mage_GoogleBase_Block +
    - - - - Mage_GoogleBase_Adminhtml - - - + + + + + + + - - - Mage_GoogleBase.csv - - + + + + + - - - - googlebase/observer - saveProductItem - - - - - - - googlebase/observer - deleteProductItem - - - + + + + + + + + + + + + + + + + - - googlebase.xml - + + + - - 0 - - - US - HOSTED_OR_GOOGLE - - - United States - EN - en_US - USD - US Dollar - products - price - - - United Kingdom - EN - en_GB - GBP - British Pound Sterling - products - price - - - Germany - DE - de_DE - EUR - Euro - produkte - preis - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/app/code/core/Mage/GoogleBase/etc/system.xml b/app/code/core/Mage/GoogleBase/etc/system.xml index 9f111995d7..ffa9a6d672 100644 --- a/app/code/core/Mage/GoogleBase/etc/system.xml +++ b/app/code/core/Mage/GoogleBase/etc/system.xml @@ -21,69 +21,69 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - - - - - text - 20 - 1 - 1 - 1 - - - - text - 1 - 1 - 1 - 1 - - - - obscure - adminhtml/system_config_backend_encrypted - 2 - 1 - 1 - 1 - - - - select - googlebase/source_accounttype - 3 - 1 - 1 - 1 - - - - select - googlebase/source_country - 90 - 1 - 1 - 1 - - - - select - adminhtml/system_config_source_yesno - 100 - 1 - 1 - 1 - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..69ac4a5287 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/install-1.6.0.0.php @@ -0,0 +1,168 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); + +/** + * Create table 'googlebase/types' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('googlebase/types')) + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Type id') + ->addColumn('attribute_set_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Attribute set id') + ->addColumn('gbase_itemtype', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Google base item type') + ->addColumn('target_country', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + 'default' => 'US', + ), 'Target country') + ->addIndex($installer->getIdxName('googlebase/types', array('attribute_set_id')), + array('attribute_set_id')) + ->addForeignKey($installer->getFkName('googlebase/types', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'), + 'attribute_set_id', $installer->getTable('eav/attribute_set'), 'attribute_set_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Google Base Item Types link Attribute Sets'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'googlebase/items' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('googlebase/items')) + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Item id') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Type id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product id') + ->addColumn('gbase_item_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Google base item id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addColumn('published', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Published') + ->addColumn('expires', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Expires') + ->addColumn('impr', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Google impressions') + ->addColumn('clicks', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Google clicks') + ->addColumn('views', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Google views') + ->addColumn('is_hidden', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Hidden flag') + ->addIndex($installer->getIdxName('googlebase/items', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('googlebase/items', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('googlebase/items', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('googlebase/items', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Google Base Items Products'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'googlebase/attributes' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('googlebase/attributes')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Attribute id') + ->addColumn('gbase_attribute', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Google base attribute') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Type id') + ->addIndex($installer->getIdxName('googlebase/attributes', array('attribute_id')), + array('attribute_id')) + ->addIndex($installer->getIdxName('googlebase/attributes', array('type_id')), + array('type_id')) + ->addForeignKey($installer->getFkName('googlebase/attributes', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('googlebase/attributes', 'type_id', 'googlebase/types', 'type_id'), + 'type_id', $installer->getTable('googlebase/types'), 'type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Google Base Attributes link Product Attributes'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php index e432455b3c..1f1e46bda7 100644 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php +++ b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-install-0.1.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php index 8e73996420..b0239d00a6 100644 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php +++ b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.0-0.1.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php index 83c45aa094..fdaad09c15 100644 --- a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php +++ b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-0.1.1-0.1.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleBase - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..39b7bfadf1 --- /dev/null +++ b/app/code/core/Mage/GoogleBase/sql/googlebase_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,322 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('googlebase/attributes'), + 'FK_GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('googlebase/attributes'), + 'GOOGLEBASE_ATTRIBUTES_TYPE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('googlebase/items'), + 'FK_GOOGLEBASE_ITEMS_PRODUCT_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('googlebase/items'), + 'FK_GOOGLEBASE_ITEMS_STORE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('googlebase/types'), + 'FK_GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('googlebase/attributes'), + 'GOOGLEBASE_ATTRIBUTES_ATTRIBUTE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('googlebase/attributes'), + 'GOOGLEBASE_ATTRIBUTES_TYPE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('googlebase/items'), + 'GOOGLEBASE_ITEMS_PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('googlebase/items'), + 'GOOGLEBASE_ITEMS_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('googlebase/types'), + 'GOOGLEBASE_TYPES_ATTRIBUTE_SET_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('googlebase/types') => array( + 'columns' => array( + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Type id' + ), + 'attribute_set_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute set id' + ), + 'gbase_itemtype' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Google base item type' + ), + 'target_country' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'default' => 'US', + 'comment' => 'Target country' + ) + ), + 'comment' => 'Google Base Item Types link Attribute Sets' + ), + $installer->getTable('googlebase/items') => array( + 'columns' => array( + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Item id' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Type id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product id' + ), + 'gbase_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Google base item id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'published' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Published' + ), + 'expires' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Expires' + ), + 'impr' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Google impressions' + ), + 'clicks' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Google clicks' + ), + 'views' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Google views' + ), + 'is_hidden' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Hidden flag' + ) + ), + 'comment' => 'Google Base Items Products' + ), + $installer->getTable('googlebase/attributes') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute id' + ), + 'gbase_attribute' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Google base attribute' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Type id' + ) + ), + 'comment' => 'Google Base Attributes link Product Attributes' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('googlebase/attributes'), + $installer->getIdxName('googlebase/attributes', array('attribute_id')), + array('attribute_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('googlebase/attributes'), + $installer->getIdxName('googlebase/attributes', array('type_id')), + array('type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('googlebase/items'), + $installer->getIdxName('googlebase/items', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('googlebase/items'), + $installer->getIdxName('googlebase/items', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('googlebase/types'), + $installer->getIdxName('googlebase/types', array('attribute_set_id')), + array('attribute_set_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('googlebase/attributes', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('googlebase/attributes'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('googlebase/attributes', 'type_id', 'googlebase/types', 'type_id'), + $installer->getTable('googlebase/attributes'), + 'type_id', + $installer->getTable('googlebase/types'), + 'type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('googlebase/items', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('googlebase/items'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('googlebase/items', 'store_id', 'core/store', 'store_id'), + $installer->getTable('googlebase/items'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('googlebase/types', 'attribute_set_id', 'eav/attribute_set', 'attribute_set_id'), + $installer->getTable('googlebase/types'), + 'attribute_set_id', + $installer->getTable('eav/attribute_set'), + 'attribute_set_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Applicable/Countries.php b/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Applicable/Countries.php index 350417eefa..44c8143f27 100644 --- a/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Applicable/Countries.php +++ b/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Applicable/Countries.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Merchant.php b/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Merchant.php index 5546d780fc..a55fbebbab 100644 --- a/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Merchant.php +++ b/app/code/core/Mage/GoogleCheckout/Block/Adminhtml/Shipping/Merchant.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) $html .= '
      '; if ($this->_getValue('method')) { - foreach ($this->_getValue('method') as $i=>$f) { + foreach ($this->_getValue('method') as $i => $f) { if ($i) { $html .= $this->_getRowTemplateHtml($i); } @@ -56,21 +56,28 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) protected function _getRowTemplateHtml($i=0) { $html = '
    • '; - $html .= '_getDisabled() . '>'; + $html .= ''; + foreach ($this->getShippingMethods() as $carrierCode=>$carrier) { - $html .= ''; + $html .= ''; + foreach ($carrier['methods'] as $methodCode=>$method) { - $code = $carrierCode.'/'.$methodCode; - $html .= ''; + $code = $carrierCode . '/' . $methodCode; + $html .= ''; } $html .= ''; } $html .= ''; $html .= '
      '; - $html .= ' '; - $html .= '_getDisabled().'/> '; + $html .= ' '; + $html .= '_getDisabled() . '/> '; $html .= $this->_getRemoveRowButtonHtml(); $html .= '
      '; @@ -87,9 +94,14 @@ protected function getShippingMethods() $storeId = null; if (!is_null($website)) { - $storeId = Mage::getModel('core/website')->load($website, 'code')->getDefaultGroup()->getDefaultStoreId(); + $storeId = Mage::getModel('core/website') + ->load($website, 'code') + ->getDefaultGroup() + ->getDefaultStoreId(); } elseif (!is_null($store)) { - $storeId = Mage::getModel('core/store')->load($store, 'code')->getId(); + $storeId = Mage::getModel('core/store') + ->load($store, 'code') + ->getId(); } $methods = array(); @@ -102,14 +114,14 @@ protected function getShippingMethods() if (!$carrierMethods) { continue; } - $carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title', $storeId); + $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/title', $storeId); $methods[$carrierCode] = array( 'title' => $carrierTitle, 'methods' => array(), ); foreach ($carrierMethods as $methodCode=>$methodTitle) { $methods[$carrierCode]['methods'][$methodCode] = array( - 'title' => '['.$carrierCode.'] '.$methodTitle, + 'title' => '[' . $carrierCode . '] ' . $methodTitle, ); } } @@ -125,12 +137,12 @@ protected function _getDisabled() protected function _getValue($key) { - return $this->getElement()->getData('value/'.$key); + return $this->getElement()->getData('value/' . $key); } protected function _getSelected($key, $value) { - return $this->getElement()->getData('value/'.$key)==$value ? 'selected="selected"' : ''; + return $this->getElement()->getData('value/' . $key) == $value ? 'selected="selected"' : ''; } protected function _getAddRowButtonHtml($container, $template, $title='Add') @@ -138,25 +150,25 @@ protected function _getAddRowButtonHtml($container, $template, $title='Add') if (!isset($this->_addRowButtonHtml[$container])) { $this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('adminhtml/widget_button') ->setType('button') - ->setClass('add '.$this->_getDisabled()) + ->setClass('add ' . $this->_getDisabled()) ->setLabel($this->__($title)) //$this->__('Add') - ->setOnClick("Element.insert($('".$container."'), {bottom: $('".$template."').innerHTML})") + ->setOnClick("Element.insert($('" . $container . "'), {bottom: $('" . $template . "').innerHTML})") ->setDisabled($this->_getDisabled()) ->toHtml(); } return $this->_addRowButtonHtml[$container]; } - protected function _getRemoveRowButtonHtml($selector='li', $title='Remove') + protected function _getRemoveRowButtonHtml($selector = 'li', $title = 'Remove') { if (!$this->_removeRowButtonHtml) { $this->_removeRowButtonHtml = $this->getLayout()->createBlock('adminhtml/widget_button') ->setType('button') - ->setClass('delete v-middle '.$this->_getDisabled()) + ->setClass('delete v-middle ' . $this->_getDisabled()) ->setLabel($this->__($title)) //$this->__('Remove') - ->setOnClick("Element.remove($(this).up('".$selector."'))") + ->setOnClick("Element.remove($(this).up('" . $selector . "'))") ->setDisabled($this->_getDisabled()) ->toHtml(); } diff --git a/app/code/core/Mage/GoogleCheckout/Block/Form.php b/app/code/core/Mage/GoogleCheckout/Block/Form.php index 6bdf540374..acf29bb8be 100644 --- a/app/code/core/Mage/GoogleCheckout/Block/Form.php +++ b/app/code/core/Mage/GoogleCheckout/Block/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Block/Link.php b/app/code/core/Mage/GoogleCheckout/Block/Link.php index d8339d0ed1..3ed2392c22 100644 --- a/app/code/core/Mage/GoogleCheckout/Block/Link.php +++ b/app/code/core/Mage/GoogleCheckout/Block/Link.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Block/Redirect.php b/app/code/core/Mage/GoogleCheckout/Block/Redirect.php index c9e3762b49..71f735f591 100644 --- a/app/code/core/Mage/GoogleCheckout/Block/Redirect.php +++ b/app/code/core/Mage/GoogleCheckout/Block/Redirect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,9 +34,9 @@ class Mage_GoogleCheckout_Block_Redirect extends Mage_Page_Block_Redirect { /** - * Description goes here... + * Get target URL * - * @return string + * @return string */ public function getTargetURL () { diff --git a/app/code/core/Mage/GoogleCheckout/Exception.php b/app/code/core/Mage/GoogleCheckout/Exception.php index e003f6919d..4eac7748c1 100644 --- a/app/code/core/Mage/GoogleCheckout/Exception.php +++ b/app/code/core/Mage/GoogleCheckout/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Helper/Data.php b/app/code/core/Mage/GoogleCheckout/Helper/Data.php index b631ec5488..ed8afa56a7 100644 --- a/app/code/core/Mage/GoogleCheckout/Helper/Data.php +++ b/app/code/core/Mage/GoogleCheckout/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api.php b/app/code/core/Mage/GoogleCheckout/Model/Api.php index 33b37a5c08..8a1c3a96ea 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -35,7 +35,7 @@ class Mage_GoogleCheckout_Model_Api extends Varien_Object protected function _getApi($area) { - $api = Mage::getModel('googlecheckout/api_xml_'.$area)->setStoreId($this->getStoreId()); + $api = Mage::getModel('googlecheckout/api_xml_' . $area)->setStoreId($this->getStoreId()); $api->setApi($this); return $api; } @@ -66,7 +66,7 @@ public function charge($gOrderId, $amount) return $api; } - public function refund($gOrderId, $amount, $reason, $comment='') + public function refund($gOrderId, $amount, $reason, $comment = '') { $api = $this->_getApi('order') ->setGoogleOrderNumber($gOrderId) @@ -74,7 +74,7 @@ public function refund($gOrderId, $amount, $reason, $comment='') return $api; } - public function cancel($gOrderId, $reason, $comment='') + public function cancel($gOrderId, $reason, $comment = '') { $api = $this->_getApi('order') ->setGoogleOrderNumber($gOrderId) @@ -92,9 +92,9 @@ public function process($gOrderId) return $api; } - public function deliver($gOrderId, $carrier, $trackingNo, $sendMail=true) + public function deliver($gOrderId, $carrier, $trackingNo, $sendMail = true) { - $gCarriers = array('dhl'=>'DHL', 'fedex'=>'FedEx', 'ups'=>'UPS', 'usps'=>'USPS'); + $gCarriers = array('dhl' => 'DHL', 'fedex' => 'FedEx', 'ups' => 'UPS', 'usps' => 'USPS'); $carrier = strtolower($carrier); $carrier = isset($gCarriers[$carrier]) ? $gCarriers[$carrier] : 'Other'; diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Debug.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Debug.php index 153bf2d90f..b094321077 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Debug.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Debug.php @@ -20,11 +20,29 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_GoogleCheckout_Model_Resource_Api_Debug _getResource() + * @method Mage_GoogleCheckout_Model_Resource_Api_Debug getResource() + * @method string getDir() + * @method Mage_GoogleCheckout_Model_Api_Debug setDir(string $value) + * @method string getUrl() + * @method Mage_GoogleCheckout_Model_Api_Debug setUrl(string $value) + * @method string getRequestBody() + * @method Mage_GoogleCheckout_Model_Api_Debug setRequestBody(string $value) + * @method string getResponseBody() + * @method Mage_GoogleCheckout_Model_Api_Debug setResponseBody(string $value) + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team + */ class Mage_GoogleCheckout_Model_Api_Debug extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Abstract.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Abstract.php index e80f90b60a..52c89bc4b8 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Abstract.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -35,7 +35,7 @@ abstract class Mage_GoogleCheckout_Model_Api_Xml_Abstract extends Varien_Object { public function log($text, $nl=true) { - error_log(print_r($text,1).($nl?"\n":''), 3, Mage::getBaseDir('log').DS.'callback.log'); + error_log(print_r($text, 1) . ($nl ? "\n" : ''), 3, Mage::getBaseDir('log') . DS . 'callback.log'); return $this; } @@ -106,8 +106,8 @@ public function getGRequest() //Setup the log file $logDir = Mage::getBaseDir('log'); $this->getData('g_request')->SetLogFiles( - $logDir.DS.'googleerror.log', - $logDir.DS.'googlemessage.log', + $logDir . DS . 'googleerror.log', + $logDir . DS . 'googlemessage.log', L_ALL ); } @@ -130,8 +130,8 @@ public function getGResponse() //Setup the log file $logDir = Mage::getBaseDir('log'); $this->getData('g_response')->SetLogFiles( - $logDir.DS.'googleerror.log', - $logDir.DS.'googlemessage.log', + $logDir . DS . 'googleerror.log', + $logDir . DS . 'googlemessage.log', L_ALL ); } @@ -153,16 +153,16 @@ abstract protected function _getApiUrl(); public function _call($xml) { - $auth = 'Basic '.base64_encode($this->getMerchantId().':'.$this->getMerchantKey()); + $auth = 'Basic ' . base64_encode($this->getMerchantId() . ':' . $this->getMerchantKey()); $headers = array( - 'Authorization: '.$auth, + 'Authorization: ' . $auth, 'Content-Type: application/xml;charset=UTF-8', 'Accept: application/xml;charset=UTF-8', ); $url = $this->_getApiUrl(); - $xml = ''."\r\n".$xml; + $xml = '' . "\r\n" . $xml; $debugData = array('request' => $xml, 'dir' => 'out'); @@ -185,7 +185,7 @@ public function _call($xml) if (!$result) { $result = simplexml_load_string('Invalid response from Google Checkout server'); } - if ($result->getName()=='error') { + if ($result->getName() == 'error') { $this->setError($this->__('Google Checkout: %s', (string)$result->{'error-message'})); $this->setWarnings((array)$result->{'warning-messages'}); } else { diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Calculate.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Calculate.php index 73648edb28..c8f9a92fb4 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Calculate.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Calculate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 2adfe87527..449f879aa9 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Callback.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -83,7 +83,7 @@ public function process() $notification->startProcess(); } - $method = '_response'.uc_words($root, '', '-'); + $method = '_response' . uc_words($root, '', '-'); if (method_exists($this, $method)) { ob_start(); @@ -410,12 +410,12 @@ protected function _responseNewOrderNotification() $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH); $order->setCanShipPartiallyItem(false); - $emailAllowed = ($this->getData('root/buyer-marketing-preferences/email-allowed/VALUE')==='true'); + $emailAllowed = ($this->getData('root/buyer-marketing-preferences/email-allowed/VALUE') === 'true'); $emailStr = $emailAllowed ? $this->__('Yes') : $this->__('No'); - $message = $this->__('Google Order Number: %s', ''.$this->getGoogleOrderNumber()).'
      '. - $this->__('Google Buyer ID: %s', ''.$this->getData('root/buyer-id/VALUE').'
      '). - $this->__('Is Buyer Willing to Receive Marketing Emails: %s', '' . $emailStr . ''); + $message = $this->__('Google Order Number: %s', '' . $this->getGoogleOrderNumber() . '
      ') + . $this->__('Google Buyer ID: %s', '' . $this->getData('root/buyer-id/VALUE') . '
      ') + . $this->__('Is Buyer Willing to Receive Marketing Emails: %s', '' . $emailStr . ''); if ($taxMessage) { $message .= $this->__('
      Warning: %s
      ', $taxMessage); } @@ -525,7 +525,7 @@ protected function _importGoogleAddress($gAddress, Varien_Object $qAddress=null) $qAddress->setCompany($gAddress->getData('company-name/VALUE')) ->setEmail($gAddress->getData('email/VALUE')) - ->setStreet(trim($gAddress->getData('address1/VALUE')."\n".$gAddress->getData('address2/VALUE'))) + ->setStreet(trim($gAddress->getData('address1/VALUE') . "\n" . $gAddress->getData('address2/VALUE'))) ->setCity($gAddress->getData('city/VALUE')) ->setRegion($gAddress->getData('region/VALUE')) ->setRegionId($region->getId()) @@ -647,16 +647,16 @@ protected function _importGoogleTotals($qAddress) $method = null; $prefix = 'root/order-adjustment/shipping/'; - if (null !== ($shipping = $this->getData($prefix.'carrier-calculated-shipping-adjustment'))) { + if (null !== ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment'))) { $method = 'googlecheckout_carrier'; - } else if (null !== ($shipping = $this->getData($prefix.'merchant-calculated-shipping-adjustment'))) { + } else if (null !== ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment'))) { $method = $this->_getShippingMethodByName($shipping['shipping-name']['VALUE']); if ($method === false) { $method = 'googlecheckout_merchant'; } - } else if (null !== ($shipping = $this->getData($prefix.'flat-rate-shipping-adjustment'))) { + } else if (null !== ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment'))) { $method = 'googlecheckout_flatrate'; - } else if (null !== ($shipping = $this->getData($prefix.'pickup-shipping-adjustment'))) { + } else if (null !== ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment'))) { $method = 'googlecheckout_pickup'; } @@ -694,7 +694,7 @@ protected function _importGoogleTotals($qAddress) } /** - * Enter description here... + * Order getter * * @return Mage_Sales_Model_Order */ @@ -704,7 +704,7 @@ public function getOrder() $order = Mage::getModel('sales/order') ->loadByAttribute('ext_order_id', $this->getGoogleOrderNumber()); if (!$order->getId()) { - Mage::throwException('Invalid Order: '.$this->getGoogleOrderNumber()); + Mage::throwException('Invalid Order: ' . $this->getGoogleOrderNumber()); } $this->setData('order', $order); } @@ -727,12 +727,12 @@ protected function _responseRiskInformationNotification() ->setCcCidStatus($this->getData('root/risk-information/cvn-response/VALUE')); $msg = $this->__('Google Risk Information:'); - $msg .= '
      '.$this->__('IP Address: %s', ''.$order->getRemoteIp().''); - $msg .= '
      '.$this->__('CC Partial: xxxx-%s', ''.$payment->getCcLast4().''); - $msg .= '
      '.$this->__('AVS Status: %s', ''.$payment->getCcAvsStatus().''); - $msg .= '
      '.$this->__('CID Status: %s', ''.$payment->getCcCidStatus().''); - $msg .= '
      '.$this->__('Eligible for Protection: %s', ''.($this->getData('root/risk-information/eligible-for-protection/VALUE')=='true' ? 'Yes' : 'No').''); - $msg .= '
      '.$this->__('Buyer Account Age: %s days', ''.$this->getData('root/risk-information/buyer-account-age/VALUE').''); + $msg .= '
      ' . $this->__('IP Address: %s', '' . $order->getRemoteIp() . ''); + $msg .= '
      ' . $this->__('CC Partial: xxxx-%s', '' . $payment->getCcLast4() . ''); + $msg .= '
      ' . $this->__('AVS Status: %s', '' . $payment->getCcAvsStatus() . ''); + $msg .= '
      ' . $this->__('CID Status: %s', '' . $payment->getCcCidStatus() . ''); + $msg .= '
      ' . $this->__('Eligible for Protection: %s', '' . ($this->getData('root/risk-information/eligible-for-protection/VALUE')=='true' ? 'Yes' : 'No') . ''); + $msg .= '
      ' . $this->__('Buyer Account Age: %s days', '' . $this->getData('root/risk-information/buyer-account-age/VALUE') . ''); $order->addStatusToHistory($order->getStatus(), $msg); $order->save(); @@ -753,8 +753,8 @@ protected function _responseAuthorizationAmountNotification() $expDate = $this->getData('root/authorization-expiration-date/VALUE'); $expDate = new Zend_Date($expDate); $msg = $this->__('Google Authorization:'); - $msg .= '
      '.$this->__('Amount: %s', '' . $this->_formatAmount($payment->getAmountAuthorized()) . ''); - $msg .= '
      '.$this->__('Expiration: %s', '' . $expDate->toString() . ''); + $msg .= '
      ' . $this->__('Amount: %s', '' . $this->_formatAmount($payment->getAmountAuthorized()) . ''); + $msg .= '
      ' . $this->__('Expiration: %s', '' . $expDate->toString() . ''); $order->addStatusToHistory($order->getStatus(), $msg); @@ -781,12 +781,12 @@ protected function _responseChargeAmountNotification() $order->setIsInProcess(true); $msg = $this->__('Google Charge:'); - $msg .= '
      '.$this->__('Latest Charge: %s', '' . $this->_formatAmount($latestCharged) . ''); - $msg .= '
      '.$this->__('Total Charged: %s', '' . $this->_formatAmount($totalCharged) . ''); + $msg .= '
      ' . $this->__('Latest Charge: %s', '' . $this->_formatAmount($latestCharged) . ''); + $msg .= '
      ' . $this->__('Total Charged: %s', '' . $this->_formatAmount($totalCharged) . ''); - if (!$order->hasInvoices() && abs($order->getBaseGrandTotal() - $latestCharged)<.0001) { + if (!$order->hasInvoices() && abs($order->getBaseGrandTotal() - $latestCharged) < .0001) { $invoice = $this->_createInvoice(); - $msg .= '
      '.$this->__('Invoice Auto-Created: %s', ''.$invoice->getIncrementId().''); + $msg .= '
      ' . $this->__('Invoice Auto-Created: %s', '' . $invoice->getIncrementId() . ''); } $this->_addChildTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); @@ -864,8 +864,8 @@ protected function _responseChargebackAmountNotification() $creditmemo->save(); } $msg = $this->__('Google Chargeback:'); - $msg .= '
      '.$this->__('Latest Chargeback: %s', '' . $this->_formatAmount($latestChargeback) . ''); - $msg .= '
      '.$this->__('Total Chargeback: %s', '' . $this->_formatAmount($totalChargeback) . ''); + $msg .= '
      ' . $this->__('Latest Chargeback: %s', '' . $this->_formatAmount($latestChargeback) . ''); + $msg .= '
      ' . $this->__('Total Chargeback: %s', '' . $this->_formatAmount($totalChargeback) . ''); $this->_addChildTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); @@ -906,8 +906,8 @@ protected function _responseRefundAmountNotification() ->save(); $msg = $this->__('Google Refund:'); - $msg .= '
      '.$this->__('Latest Refund: %s', '' . $this->_formatAmount($latestRefunded) . ''); - $msg .= '
      '.$this->__('Total Refunded: %s', '' . $this->_formatAmount($totalRefunded) . ''); + $msg .= '
      ' . $this->__('Latest Refund: %s', '' . $this->_formatAmount($latestRefunded) . ''); + $msg .= '
      ' . $this->__('Total Refunded: %s', '' . $this->_formatAmount($totalRefunded) . ''); $this->_addChildTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); @@ -927,21 +927,21 @@ protected function _responseOrderStateChangeNotification() $msg = $this->__('Google Order Status Change:'); if ($prevFinancial!=$newFinancial) { - $msg .= "
      ".$this->__('Financial: %s -> %s', ''.$prevFinancial.'', ''.$newFinancial.''); + $msg .= "
      " . $this->__('Financial: %s -> %s', '' . $prevFinancial . '', '' . $newFinancial . ''); } if ($prevFulfillment!=$newFulfillment) { - $msg .= "
      ".$this->__('Fulfillment: %s -> %s', ''.$prevFulfillment.'', ''.$newFulfillment.''); + $msg .= "
      " . $this->__('Fulfillment: %s -> %s', '' . $prevFulfillment . '', '' . $newFulfillment . ''); } $this->getOrder() ->addStatusToHistory($this->getOrder()->getStatus(), $msg) ->save(); - $method = '_orderStateChangeFinancial'.uc_words(strtolower($newFinancial), '', '_'); + $method = '_orderStateChangeFinancial' . uc_words(strtolower($newFinancial), '', '_'); if (method_exists($this, $method)) { $this->$method(); } - $method = '_orderStateChangeFulfillment'.uc_words(strtolower($newFulfillment), '', '_'); + $method = '_orderStateChangeFulfillment' . uc_words(strtolower($newFulfillment), '', '_'); if (method_exists($this, $method)) { $this->$method(); } @@ -1013,8 +1013,15 @@ protected function _orderStateChangeFinancialCancelled() protected function _orderStateChangeFinancialCancelledByGoogle() { - $this->getOrder()->setBeingCanceledFromGoogleApi(true)->cancel()->save(); - $this->getGRequest()->SendBuyerMessage($this->getGoogleOrderNumber(), "Sorry, your order is cancelled by Google", true); + $this + ->getOrder() + ->setBeingCanceledFromGoogleApi(true) + ->cancel() + ->save(); + + $this + ->getGRequest() + ->SendBuyerMessage($this->getGoogleOrderNumber(), "Sorry, your order is cancelled by Google", true); } protected function _orderStateChangeFulfillmentNew() diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Checkout.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Checkout.php index b6bc33992c..c6d3db83c9 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Checkout.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Checkout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -745,7 +745,7 @@ protected function _getTaxTableXml($rules, $type) EOT; if ($rate['country'] === Mage_Usa_Model_Shipping_Carrier_Abstract::USA_COUNTRY_ID) { - if (!empty($rate['postcode']) && $rate['postcode']!=='*') { + if (!empty($rate['postcode']) && $rate['postcode'] !== '*') { $xml .= << {$rate['postcode']} @@ -773,7 +773,7 @@ protected function _getTaxTableXml($rules, $type) {$rate['country']} EOT; - if (!empty($rate['postcode']) && $rate['postcode']!=='*') { + if (!empty($rate['postcode']) && $rate['postcode'] !== '*') { $xml .= <<{$rate['postcode']} @@ -937,7 +937,7 @@ protected function _getShippingTaxRules() } /** - * Retrieve yax rules + * Retrieve tax rules * * @return array */ diff --git a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Order.php b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Order.php index 1d5d60ca87..00e5c45853 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Order.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Api/Xml/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -52,9 +52,12 @@ public function authorize() { $GRequest = $this->getGRequest(); - $postargs = " - schema_url. - "\" google-order-number=\"". $this->getGoogleOrderNumber() . "\"/>"; + $postargs = ' + '; $response = $GRequest->SendReq($GRequest->request_url, $GRequest->GetAuthenticationHeaders(), $postargs); @@ -68,14 +71,14 @@ public function charge($amount) return $this->_processGResponse($response); } - public function refund($amount, $reason, $comment='') + public function refund($amount, $reason, $comment = '') { $response = $this->getGRequest() ->SendRefundOrder($this->getGoogleOrderNumber(), $amount, $reason, $comment); return $this->_processGResponse($response); } - public function cancel($reason, $comment='') + public function cancel($reason, $comment = '') { $response = $this->getGRequest() ->SendCancelOrder($this->getGoogleOrderNumber(), $reason, $comment); @@ -91,10 +94,10 @@ public function process() return $this->_processGResponse($response); } - public function deliver($carrier, $trackingNo, $sendMail=true) + public function deliver($carrier, $trackingNo, $sendMail = true) { $response = $this->getGRequest() - ->SendDeliverOrder($this->getGoogleOrderNumber(), $carrier, $trackingNo, $sendMail?'true':'false'); + ->SendDeliverOrder($this->getGoogleOrderNumber(), $carrier, $trackingNo, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } @@ -105,7 +108,7 @@ public function addTrackingData($carrier, $trackingNo) return $this->_processGResponse($response); } - public function shipItems($items, $sendMail=true) + public function shipItems($items, $sendMail = true) { $googleShipItems = array(); foreach ($items as $item) { @@ -113,35 +116,35 @@ public function shipItems($items, $sendMail=true) } $response = $this->getGRequest() - ->SendShipItems($this->getGoogleOrderNumber(), $googleShipItems, $sendMail?'true':'false'); + ->SendShipItems($this->getGoogleOrderNumber(), $googleShipItems, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } - public function backorderItems($items, $sendMail=true) + public function backorderItems($items, $sendMail = true) { $response = $this->getGRequest() - ->SendBackorderItems($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false'); + ->SendBackorderItems($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } - public function cancelItems($items, $reason, $comment='', $sendMail=true) + public function cancelItems($items, $reason, $comment = '', $sendMail = true) { $response = $this->getGRequest() - ->SendCancelItems($this->getGoogleOrderNumber(), $items, $reason, $comment, $sendMail?'true':'false'); + ->SendCancelItems($this->getGoogleOrderNumber(), $items, $reason, $comment, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } - public function returnItems($items, $sendMail=true) + public function returnItems($items, $sendMail = true) { $response = $this->getGRequest() - ->SendReturnItems($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false'); + ->SendReturnItems($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } - public function resetItems($items, $sendMail=true) + public function resetItems($items, $sendMail = true) { $response = $this->getGRequest() - ->SendRResetItemsShippingInformation($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false'); + ->SendRResetItemsShippingInformation($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } @@ -169,10 +172,10 @@ public function addOrderNumber($merchantOrder) } - public function addBuyerMessage($message, $sendMail=true) + public function addBuyerMessage($message, $sendMail = true) { $response = $this->getGRequest() - ->SendBuyerMessage($this->getGoogleOrderNumber(), $message, $sendMail?'true':'false'); + ->SendBuyerMessage($this->getGoogleOrderNumber(), $message, $sendMail ? 'true' : 'false'); return $this->_processGResponse($response); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug.php b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug.php index 6a6708856e..2fddaf725d 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug.php @@ -20,15 +20,18 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_GoogleCheckout_Model_Mysql4_Api_Debug extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team + */ +class Mage_GoogleCheckout_Model_Mysql4_Api_Debug extends Mage_GoogleCheckout_Model_Resource_Api_Debug { - protected function _construct() - { - $this->_init('googlecheckout/api_debug', 'debug_id'); - } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug/Collection.php b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug/Collection.php index ee6b7eef34..7f3767307d 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug/Collection.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Api/Debug/Collection.php @@ -20,15 +20,19 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_GoogleCheckout_Model_Mysql4_Api_Debug_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team + */ +class Mage_GoogleCheckout_Model_Mysql4_Api_Debug_Collection + extends Mage_GoogleCheckout_Model_Resource_Api_Debug_Collection { - protected function _construct() - { - $this->_init('googlecheckout/api_debug'); - } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Notification.php b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Notification.php index e2834af6bd..755a18b5d4 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Notification.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Notification.php @@ -20,85 +20,18 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Checkout resource notification model * - * @category Mage - * @package Mage_GoogleCheckout - * @author Magento Core Team + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team */ -class Mage_GoogleCheckout_Model_Mysql4_Notification extends Mage_Core_Model_Mysql4_Abstract +class Mage_GoogleCheckout_Model_Mysql4_Notification extends Mage_GoogleCheckout_Model_Resource_Notification { - /** - * Intialize resource model - */ - protected function _construct() - { - $this->_init('googlecheckout/notification', 'serial_number'); - } - - /** - * Return notification data by serial number - * - * @param string $serialNumber - * @return array - */ - public function getNotificationData($serialNumber) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), array('*')) - ->where($this->_getWriteAdapter()->quoteInto('serial_number = ?', $serialNumber)); - return $this->_getWriteAdapter()->fetchRow($select); - } - - /** - * Start notification processing - * - * @param string $serialNumber - * @return Mage_GoogleCheckout_Model_Mysql4_Notification - */ - public function startProcess($serialNumber) - { - $data = array( - 'serial_number' => $serialNumber, - 'started_at' => $this->formatDate(time()), - 'status' => Mage_GoogleCheckout_Model_Notification::STATUS_INPROCESS - ); - $this->_getWriteAdapter()->insert($this->getMainTable(), $data); - return $this; - } - - /** - * Stop notification processing - * - * @param string $serialNumber - * @return Mage_GoogleCheckout_Model_Mysql4_Notification - */ - public function stopProcess($serialNumber) - { - $this->_getWriteAdapter()->update($this->getMainTable(), - array('status' => Mage_GoogleCheckout_Model_Notification::STATUS_PROCESSED), - array($this->_getWriteAdapter()->quoteInto('serial_number = ?', $serialNumber)) - ); - return $this; - } - - /** - * Update notification processing - * - * @param string $serialNumber - * @return Mage_GoogleCheckout_Model_Mysql4_Notification - */ - public function updateProcess($serialNumber) - { - $this->_getWriteAdapter()->update($this->getMainTable(), - array('started_at' => $this->formatDate(time())), - array($this->_getWriteAdapter()->quoteInto('serial_number = ?', $serialNumber)) - ); - return $this; - } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Setup.php b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Setup.php index 2e16eeeb37..775b594dca 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Setup.php @@ -20,12 +20,18 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_GoogleCheckout_Model_Mysql4_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup +/** + * Enter description here ... + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team + */ +class Mage_GoogleCheckout_Model_Mysql4_Setup extends Mage_GoogleCheckout_Model_Resource_Setup { - } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Tax.php b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Tax.php index 6ccd55406f..a427b069ce 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Tax.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Mysql4/Tax.php @@ -20,28 +20,18 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_GoogleCheckout_Model_Mysql4_Tax extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('tax/tax_rule', 'rule_id'); - } - - public function fetchRuleRatesForCustomerTaxClass($customerTaxClass) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('rule'=>$this->getTable('tax/tax_rule'))) - ->join(array('rd'=>$this->getTable('tax/tax_rate_data')), "rd.rate_type_id=rule.tax_rate_type_id", array('value'=>new Zend_Db_Expr('rate_value/100'))) - ->join(array('r'=>$this->getTable('tax/tax_rate')), "r.tax_rate_id=rd.tax_rate_id", array('country'=>'tax_country_id', 'postcode'=>'tax_postcode')) - ->joinLeft(array('reg'=>$this->getTable('directory/country_region')), "reg.region_id=r.tax_region_id", array('state'=>'code')) - ->where('rule.tax_customer_class_id=?', $customerTaxClass); - $rows = $read->fetchAll($select); - return $rows; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team + */ +class Mage_GoogleCheckout_Model_Mysql4_Tax extends Mage_GoogleCheckout_Model_Resource_Tax +{ } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Notification.php b/app/code/core/Mage/GoogleCheckout/Model/Notification.php index fd5e1aadc0..4ec2cbfc87 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Notification.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Notification.php @@ -20,16 +20,25 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Checkout notification model * - * @category Mage - * @package Mage_GoogleCheckout - * @author Magento Core Team + * @method Mage_GoogleCheckout_Model_Resource_Notification _getResource() + * @method Mage_GoogleCheckout_Model_Resource_Notification getResource() + * @method string getSerialNumber() + * @method Mage_GoogleCheckout_Model_Notification setSerialNumber(string $value) + * @method string getStartedAt() + * @method Mage_GoogleCheckout_Model_Notification setStartedAt(string $value) + * @method int getStatus() + * @method Mage_GoogleCheckout_Model_Notification setStatus(int $value) + * + * @category Mage + * @package Mage_GoogleCheckout + * @author Magento Core Team */ class Mage_GoogleCheckout_Model_Notification extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/GoogleCheckout/Model/Observer.php b/app/code/core/Mage/GoogleCheckout/Model/Observer.php index b64053e3ad..251de42903 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Observer.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/Model/Payment.php b/app/code/core/Mage/GoogleCheckout/Model/Payment.php index 9121c538dd..6028996379 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Payment.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -175,7 +175,7 @@ public function getConfigData($field, $storeId = null) if (null === $storeId) { $storeId = $this->getStore(); } - $path = 'google/checkout/'.$field; + $path = 'google/checkout/' . $field; return Mage::getStoreConfig($path, $storeId); } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug.php b/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug.php new file mode 100755 index 0000000000..414976b95d --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug.php @@ -0,0 +1,45 @@ + + */ +class Mage_GoogleCheckout_Model_Resource_Api_Debug extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource constructor + * + */ + protected function _construct() + { + $this->_init('googlecheckout/api_debug', 'debug_id'); + } +} diff --git a/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug/Collection.php b/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug/Collection.php new file mode 100755 index 0000000000..79f10c04ad --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/Model/Resource/Api/Debug/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_GoogleCheckout_Model_Resource_Api_Debug_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Collection constructor + * + */ + protected function _construct() + { + $this->_init('googlecheckout/api_debug'); + } +} diff --git a/app/code/core/Mage/GoogleCheckout/Model/Resource/Notification.php b/app/code/core/Mage/GoogleCheckout/Model/Resource/Notification.php new file mode 100755 index 0000000000..fc9f4e6510 --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/Model/Resource/Notification.php @@ -0,0 +1,109 @@ + + */ +class Mage_GoogleCheckout_Model_Resource_Notification extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Intialize resource model. + * Set main entity table name and primary key field name. + * + */ + protected function _construct() + { + $this->_init('googlecheckout/notification', 'serial_number'); + } + + /** + * Return notification data by serial number + * + * @param string $serialNumber + * @return array + */ + public function getNotificationData($serialNumber) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('*')) + ->where('serial_number = ?', $serialNumber); + + return $this->_getReadAdapter()->fetchRow($select); + } + + /** + * Start notification processing + * + * @param string $serialNumber + * @return Mage_GoogleCheckout_Model_Resource_Notification + */ + public function startProcess($serialNumber) + { + $data = array( + 'serial_number' => $serialNumber, + 'started_at' => Varien_Date::now(), + 'status' => Mage_GoogleCheckout_Model_Notification::STATUS_INPROCESS + ); + $this->_getWriteAdapter()->insert($this->getMainTable(), $data); + return $this; + } + + /** + * Stop notification processing + * + * @param string $serialNumber + * @return Mage_GoogleCheckout_Model_Resource_Notification + */ + public function stopProcess($serialNumber) + { + $this->_getWriteAdapter()->update($this->getMainTable(), + array('status' => Mage_GoogleCheckout_Model_Notification::STATUS_PROCESSED), + array('serial_number = ?' => $serialNumber) + ); + return $this; + } + + /** + * Update notification processing + * + * @param string $serialNumber + * @return Mage_GoogleCheckout_Model_Resource_Notification + */ + public function updateProcess($serialNumber) + { + $this->_getWriteAdapter()->update($this->getMainTable(), + array('started_at' => Varien_Date::now()), + array('serial_number = ?' => $serialNumber) + ); + + return $this; + } +} diff --git a/app/code/core/Mage/GoogleCheckout/Model/Resource/Setup.php b/app/code/core/Mage/GoogleCheckout/Model/Resource/Setup.php new file mode 100755 index 0000000000..ec0fddd8bf --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/Model/Resource/Setup.php @@ -0,0 +1,37 @@ + + */ +class Mage_GoogleCheckout_Model_Resource_Setup extends Mage_Catalog_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/GoogleCheckout/Model/Resource/Tax.php b/app/code/core/Mage/GoogleCheckout/Model/Resource/Tax.php new file mode 100755 index 0000000000..857325b4dc --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/Model/Resource/Tax.php @@ -0,0 +1,76 @@ + + */ +class Mage_GoogleCheckout_Model_Resource_Tax extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource model initialization + * Set main entity table name and primary key field name. + * + */ + protected function _construct() + { + $this->_init('tax/tax_rule', 'rule_id'); + } + + /** + * Retrieve array of rule rates for customers tax class + * + * @param int $customerTaxClass + * @return array + */ + public function fetchRuleRatesForCustomerTaxClass($customerTaxClass) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('rule' => $this->getMainTable())) + ->join( + array('rd' => $this->getTable('tax/tax_rate_data')), + 'rd.rate_type_id = rule.tax_rate_type_id', + array('value' => new Zend_Db_Expr('rate_value/100'))) + ->join( + array('r' => $this->getTable('tax/tax_rate')), + 'r.tax_rate_id = rd.tax_rate_id', + array('country' => 'tax_country_id', 'postcode' => 'tax_postcode')) + ->joinLeft( + array('reg' => $this->getTable('directory/country_region')), + 'reg.region_id = r.tax_region_id', + array('state' => 'code')) + ->where('rule.tax_customer_class_id = ?', (int)$customerTaxClass); + + $rows = $read->fetchAll($select); + + return $rows; + } +} diff --git a/app/code/core/Mage/GoogleCheckout/Model/Shipping.php b/app/code/core/Mage/GoogleCheckout/Model/Shipping.php index 28b69e5cfa..c29aeb6f7b 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Shipping.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -67,10 +67,10 @@ public function getAllowedMethods() public function getInternallyAllowedMethods() { return array( - 'carrier' => 'Carrier', + 'carrier' => 'Carrier', 'merchant' => 'Merchant', 'flatrate' => 'Flat Rate', - 'pickup' => 'Pickup' + 'pickup' => 'Pickup' ); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Checkout/Image.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Checkout/Image.php index db862a502f..c9d3d64f5a 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Checkout/Image.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Checkout/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,15 +37,15 @@ public function toOptionArray() $styles = array( 'trans' => Mage::helper('googlecheckout')->__('Transparent'), - 'white' => Mage::helper('googlecheckout')->__('White Background'), + 'white' => Mage::helper('googlecheckout')->__('White Background'), ); $options = array(); - foreach ($sizes as $size=>$sizeLabel) { - foreach ($styles as $style=>$styleLabel) { + foreach ($sizes as $size => $sizeLabel) { + foreach ($styles as $style => $styleLabel) { $options[] = array( - 'value' => $size.'/'.$style, - 'label' => $sizeLabel.' ('.$styleLabel.')' + 'value' => $size . '/' . $style, + 'label' => $sizeLabel . ' (' . $styleLabel . ')' ); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Locale.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Locale.php index 477a3a7609..41e743c574 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Locale.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Locale.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,8 +30,8 @@ class Mage_GoogleCheckout_Model_Source_Locale public function toOptionArray() { return array( - array('value'=>'en_US', 'label'=>Mage::helper('googlecheckout')->__('United States')), - array('value'=>'en_GB', 'label'=>Mage::helper('googlecheckout')->__('United Kingdom')), + array('value' => 'en_US', 'label'=>Mage::helper('googlecheckout')->__('United States')), + array('value' => 'en_GB', 'label'=>Mage::helper('googlecheckout')->__('United Kingdom')), ); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Carrier.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Carrier.php index 89110c27b2..66ea14961a 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Carrier.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Carrier.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,29 +31,29 @@ public function toOptionArray() { $hlp = Mage::helper('googlecheckout'); return array( - array('label'=>$hlp->__('FedEx'), 'value'=>array( - array('label'=>$hlp->__('Ground'), 'value'=>'FedEx/Ground'), - array('label'=>$hlp->__('Home Delivery'), 'value'=>'FedEx/Home Delivery'), - array('label'=>$hlp->__('Express Saver'), 'value'=>'FedEx/Express Saver'), - array('label'=>$hlp->__('First Overnight'), 'value'=>'FedEx/First Overnight'), - array('label'=>$hlp->__('Priority Overnight'), 'value'=>'FedEx/Priority Overnight'), - array('label'=>$hlp->__('Standard Overnight'), 'value'=>'FedEx/Standard Overnight'), - array('label'=>$hlp->__('2Day'), 'value'=>'FedEx/2Day'), + array('label' => $hlp->__('FedEx'), 'value' => array( + array('label' => $hlp->__('Ground'), 'value' => 'FedEx/Ground'), + array('label' => $hlp->__('Home Delivery'), 'value' => 'FedEx/Home Delivery'), + array('label' => $hlp->__('Express Saver'), 'value' => 'FedEx/Express Saver'), + array('label' => $hlp->__('First Overnight'), 'value' => 'FedEx/First Overnight'), + array('label' => $hlp->__('Priority Overnight'), 'value' => 'FedEx/Priority Overnight'), + array('label' => $hlp->__('Standard Overnight'), 'value' => 'FedEx/Standard Overnight'), + array('label' => $hlp->__('2Day'), 'value' => 'FedEx/2Day'), )), - array('label'=>$hlp->__('UPS'), 'value'=>array( - array('label'=>$hlp->__('Next Day Air'), 'value'=>'UPS/Next Day Air'), - array('label'=>$hlp->__('Next Day Air Early AM'), 'value'=>'UPS/Next Day Air Early AM'), - array('label'=>$hlp->__('Next Day Air Saver'), 'value'=>'UPS/Next Day Air Saver'), - array('label'=>$hlp->__('2nd Day Air'), 'value'=>'UPS/2nd Day Air'), - array('label'=>$hlp->__('2nd Day Air AM'), 'value'=>'UPS/2nd Day Air AM'), - array('label'=>$hlp->__('3 Day Select'), 'value'=>'UPS/3 Day Select'), - array('label'=>$hlp->__('Ground'), 'value'=>'UPS/Ground'), + array('label' => $hlp->__('UPS'), 'value' => array( + array('label' => $hlp->__('Next Day Air'), 'value' => 'UPS/Next Day Air'), + array('label' => $hlp->__('Next Day Air Early AM'), 'value' => 'UPS/Next Day Air Early AM'), + array('label' => $hlp->__('Next Day Air Saver'), 'value' => 'UPS/Next Day Air Saver'), + array('label' => $hlp->__('2nd Day Air'), 'value' => 'UPS/2nd Day Air'), + array('label' => $hlp->__('2nd Day Air AM'), 'value' => 'UPS/2nd Day Air AM'), + array('label' => $hlp->__('3 Day Select'), 'value' => 'UPS/3 Day Select'), + array('label' => $hlp->__('Ground'), 'value' => 'UPS/Ground'), )), - array('label'=>$hlp->__('USPS'), 'value'=>array( - array('label'=>$hlp->__('Express Mail'), 'value'=>'USPS/Express Mail'), - array('label'=>$hlp->__('Priority Mail'), 'value'=>'USPS/Priority Mail'), - array('label'=>$hlp->__('Parcel Post'), 'value'=>'USPS/Parcel Post'), - array('label'=>$hlp->__('Media Mail'), 'value'=>'USPS/Media Mail'), + array('label' => $hlp->__('USPS'), 'value' => array( + array('label' => $hlp->__('Express Mail'), 'value' => 'USPS/Express Mail'), + array('label' => $hlp->__('Priority Mail'), 'value' => 'USPS/Priority Mail'), + array('label' => $hlp->__('Parcel Post'), 'value' => 'USPS/Parcel Post'), + array('label' => $hlp->__('Media Mail'), 'value' => 'USPS/Media Mail'), )), ); } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Category.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Category.php index abf86ac448..7c9028a2fd 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Category.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,8 +31,8 @@ public function toOptionArray() { $hlp = Mage::helper('googlecheckout'); return array( - array('value'=>'COMMERCIAL', 'label'=>$hlp->__('Commercial')), - array('value'=>'RESIDENTIAL', 'label'=>$hlp->__('Residential')), + array('value' => 'COMMERCIAL', 'label' => $hlp->__('Commercial')), + array('value' => 'RESIDENTIAL', 'label' => $hlp->__('Residential')), ); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Units.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Units.php index 6d1f113bf4..88720402a7 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Units.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Units.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ public function toOptionArray() { $hlp = Mage::helper('googlecheckout'); return array( - array('value'=>'IN', 'label'=>$hlp->__('Inches')), + array('value' => 'IN', 'label' => $hlp->__('Inches')), ); } } diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Method.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Method.php index 5007444800..2408a46531 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Method.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ public function toOptionArray() { $hlp = Mage::helper('googlecheckout'); return array( - array('value'=>'email', 'label'=>$hlp->__('Email delivery')), + array('value' => 'email', 'label' => $hlp->__('Email delivery')), // array('value'=>'key_url', 'label'=>$hlp->__('Key/URL delivery')), // array('value'=>'description_based', 'label'=>$hlp->__('Description-based delivery')), ); diff --git a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Schedule.php b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Schedule.php index abac3c046d..8a2651625b 100644 --- a/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Schedule.php +++ b/app/code/core/Mage/GoogleCheckout/Model/Source/Shipping/Virtual/Schedule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,8 +31,8 @@ public function toOptionArray() { $hlp = Mage::helper('googlecheckout'); return array( - array('value'=>'OPTIMISTIC', 'label'=>$hlp->__('Optimistic')), - array('value'=>'PESSIMISTIC', 'label'=>$hlp->__('Pessimistic')), + array('value' => 'OPTIMISTIC', 'label' => $hlp->__('Optimistic')), + array('value' => 'PESSIMISTIC', 'label' => $hlp->__('Pessimistic')), ); } } diff --git a/app/code/core/Mage/GoogleCheckout/controllers/ApiController.php b/app/code/core/Mage/GoogleCheckout/controllers/ApiController.php index 6d01091731..cf9bcc7869 100644 --- a/app/code/core/Mage/GoogleCheckout/controllers/ApiController.php +++ b/app/code/core/Mage/GoogleCheckout/controllers/ApiController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php b/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php index a2b2eca36f..c0d8e4d8b0 100644 --- a/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php +++ b/app/code/core/Mage/GoogleCheckout/controllers/RedirectController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -156,7 +156,7 @@ public function continueAction() $url = Mage::getStoreConfig('google/checkout/continue_shopping_url'); if (empty($url)) { $this->_redirect(''); - } elseif (substr($url, 0, 4)==='http') { + } elseif (substr($url, 0, 4) === 'http') { $this->getResponse()->setRedirect($url); } else { $this->_redirect($url); diff --git a/app/code/core/Mage/GoogleCheckout/etc/adminhtml.xml b/app/code/core/Mage/GoogleCheckout/etc/adminhtml.xml index 4338d386c9..36138b6d40 100644 --- a/app/code/core/Mage/GoogleCheckout/etc/adminhtml.xml +++ b/app/code/core/Mage/GoogleCheckout/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GoogleCheckout/etc/config.xml b/app/code/core/Mage/GoogleCheckout/etc/config.xml index b32e43441c..8a1e8cccfd 100644 --- a/app/code/core/Mage/GoogleCheckout/etc/config.xml +++ b/app/code/core/Mage/GoogleCheckout/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.4 + 1.6.0.0 @@ -44,15 +44,20 @@ Mage_GoogleCheckout_Model - googlecheckout_mysql4 + googlecheckout_resource - - Mage_GoogleCheckout_Model_Mysql4 + + Mage_GoogleCheckout_Model_Resource + googlecheckout_mysql4 - googlecheckout_api_debug
      - googlecheckout_notification
      + + googlecheckout_api_debug
      +
      + + googlecheckout_notification
      +
      -
      +
      @@ -63,26 +68,16 @@ Mage_GoogleCheckout - Mage_GoogleCheckout_Model_Mysql4_Setup + Mage_GoogleCheckout_Model_Resource_Setup - Mage_GoogleCheckout_Block - -
      - + + /googlecheckout/redirect/ @@ -114,7 +109,6 @@ Something like this is to be added to resolve bug #4890 - @@ -146,7 +140,6 @@ Something like this is to be added to resolve bug #4890 - diff --git a/app/code/core/Mage/GoogleCheckout/etc/system.xml b/app/code/core/Mage/GoogleCheckout/etc/system.xml index e3b9494a9a..f24b66aeda 100644 --- a/app/code/core/Mage/GoogleCheckout/etc/system.xml +++ b/app/code/core/Mage/GoogleCheckout/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/install-1.6.0.0.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..a77e92cf42 --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/install-1.6.0.0.php @@ -0,0 +1,83 @@ +startSetup(); + +/** + * Create table 'googlecheckout/notification' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('googlecheckout/notification')) + ->addColumn('serial_number', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + 'primary' => true, + ), 'Serial Number') + ->addColumn('started_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Started At') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Status') + ->setComment('Google Checkout Notification Table'); +$installer->getConnection()->createTable($table); + +/** + * Add 'disable_googlecheckout' attribute to the 'eav/attribute' table + */ +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'enable_googlecheckout', array( + 'group' => 'Prices', + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Is product available for purchase with Google Checkout', + 'input' => 'select', + 'class' => '', + 'source' => 'eav/entity_attribute_source_boolean', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'visible' => true, + 'required' => false, + 'user_defined' => false, + 'default' => '1', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'unique' => false, + 'apply_to' => '', + 'is_configurable' => false +)); + +/** + * Prepare database after tables setup + */ +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-install-0.7.0.php index 89ec24ddb7..7affa14070 100644 --- a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.0-0.7.1.php index a7db2116e2..b5b1966b79 100644 --- a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.1-0.7.2.php index cb98bb5bc3..249bdcf190 100644 --- a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.2-0.7.3.php index 41502aa96e..14a990e485 100644 --- a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.3-0.7.4.php index 403dbf2f83..0bf30c7ee9 100644 --- a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleCheckout - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..079f41c938 --- /dev/null +++ b/app/code/core/Mage/GoogleCheckout/sql/googlecheckout_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,62 @@ +startSetup(); + +/** + * Change columns + */ +$tables = array( + $installer->getTable('googlecheckout/notification') => array( + 'columns' => array( + 'serial_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Serial Number' + ), + 'started_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Started At' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Status' + ) + ), + 'comment' => 'Google Checkout Notification Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php index 6b20f479b2..18e5dc1213 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Category/Edit/Tab/Googleoptimizer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -57,7 +57,7 @@ public function _prepareLayout() $form = new Varien_Data_Form(); $fieldset = $form->addFieldset('base_fieldset', - array('legend'=>Mage::helper('googleoptimizer')->__('Google Optimizer Scripts')) + array('legend' => Mage::helper('googleoptimizer')->__('Google Optimizer Scripts')) ); if ($this->getCategory()->getStoreId() == '0') { @@ -124,7 +124,7 @@ public function _prepareLayout() ); } - $fieldset->addField('export_controls', 'text', array('name' => 'export_controls',)); + $fieldset->addField('export_controls', 'text', array('name' => 'export_controls')); $fieldset->addField('control_script', 'textarea', array( diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php index 7232fff9b0..edefae1b19 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Catalog/Product/Edit/Tab/Googleoptimizer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -40,7 +40,7 @@ protected function _prepareForm() $form = new Varien_Data_Form(); $fieldset = $form->addFieldset('googleoptimizer_fields', - array('legend'=>Mage::helper('googleoptimizer')->__('Google Optimizer Scripts')) + array('legend' => Mage::helper('googleoptimizer')->__('Google Optimizer Scripts')) ); if ($this->getProduct()->getStoreId() == '0') { @@ -109,7 +109,7 @@ protected function _prepareForm() ); } - $fieldset->addField('export_controls', 'text', array('name' => 'export_controls')); + $fieldset->addField('export_controls', 'text', array('name' => 'export_controls')); $fieldset->addField('control_script', 'textarea', array( diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Enable.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Enable.php index d755e50bb2..2d91fbe7c8 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Enable.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Enable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Renderer/Conversion.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Renderer/Conversion.php index bba6e9690f..ad67363f26 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Renderer/Conversion.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Renderer/Conversion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php index 0c01ed6cb6..3243e9ddbc 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Adminhtml/Cms/Page/Edit/Tab/Googleoptimizer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Code.php b/app/code/core/Mage/GoogleOptimizer/Block/Code.php index 3f1781557b..956e05c02a 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Code.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Code.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Code/Category.php b/app/code/core/Mage/GoogleOptimizer/Block/Code/Category.php index 3d00997ac8..d9a6c54ab5 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Code/Category.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Code/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Code/Conversion.php b/app/code/core/Mage/GoogleOptimizer/Block/Code/Conversion.php index cf9c2e3907..062b6638f5 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Code/Conversion.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Code/Conversion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Code/Page.php b/app/code/core/Mage/GoogleOptimizer/Block/Code/Page.php index 7a19474d5d..5165a3f19c 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Code/Page.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Code/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Code/Product.php b/app/code/core/Mage/GoogleOptimizer/Block/Code/Product.php index 8a323e81ed..5ba6892fa3 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Code/Product.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Code/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Block/Js.php b/app/code/core/Mage/GoogleOptimizer/Block/Js.php index 92a0d60ac3..1bc465b35f 100644 --- a/app/code/core/Mage/GoogleOptimizer/Block/Js.php +++ b/app/code/core/Mage/GoogleOptimizer/Block/Js.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Helper/Data.php b/app/code/core/Mage/GoogleOptimizer/Helper/Data.php index 341d17587b..fb09056717 100644 --- a/app/code/core/Mage/GoogleOptimizer/Helper/Data.php +++ b/app/code/core/Mage/GoogleOptimizer/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -135,11 +135,11 @@ public function categoryAttribute($callObject, $attributeHtml, $params) $newAttributeName = 'category_'.$attributeName.'_'.$category->getId(); if (strlen($newAttributeName) > self::MAX_ATTRIBUTE_LENGTH_LIMIT) { $newAttributeName = 'category_'; - $newAttributeName .= substr($attributeName, 0, (self::MAX_ATTRIBUTE_LENGTH_LIMIT - strlen('category__'.$category->getId()))); - $newAttributeName .= '_'.$category->getId(); + $newAttributeName .= substr($attributeName, 0, (self::MAX_ATTRIBUTE_LENGTH_LIMIT - strlen('category__' . $category->getId()))); + $newAttributeName .= '_' . $category->getId(); } - $attributeHtml = '' . $attributeHtml . ''; + $attributeHtml = '' . $attributeHtml . ''; return $attributeHtml; } @@ -197,7 +197,9 @@ public function getConversionPagesUrl() if ($storeBaseUrl == $websiteBaseUrl && !Mage::app()->isSingleStoreMode()) { $_query = array('__store' => $store->getCode()); } - $urls[$choice['value']] = $url->setStore($this->getStoreId())->getUrl($route, array('_secure' => true, '_query' => $_query)); + $urls[$choice['value']] = $url->setStore($this->getStoreId())->getUrl($route, + array('_secure' => true, '_query' => $_query) + ); } } $session->setSkipSessionIdFlag(false); diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Adminhtml/System/Config/Source/Googleoptimizer/Conversionpages.php b/app/code/core/Mage/GoogleOptimizer/Model/Adminhtml/System/Config/Source/Googleoptimizer/Conversionpages.php index 03153619a2..dfa4e62616 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Adminhtml/System/Config/Source/Googleoptimizer/Conversionpages.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Adminhtml/System/Config/Source/Googleoptimizer/Conversionpages.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Code.php b/app/code/core/Mage/GoogleOptimizer/Model/Code.php index 137c99c2d4..a00c09cc55 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Code.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Code.php @@ -20,16 +20,33 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Google Optimizer Scripts Model * - * @category Mage - * @package Mage_GoogleOptimizer - * @author Magento Core Team + * @method Mage_GoogleOptimizer_Model_Resource_Code _getResource() + * @method Mage_GoogleOptimizer_Model_Resource_Code getResource() + * @method Mage_GoogleOptimizer_Model_Code setEntityId(int $value) + * @method Mage_GoogleOptimizer_Model_Code setEntityType(string $value) + * @method int getStoreId() + * @method Mage_GoogleOptimizer_Model_Code setStoreId(int $value) + * @method string getControlScript() + * @method Mage_GoogleOptimizer_Model_Code setControlScript(string $value) + * @method string getTrackingScript() + * @method Mage_GoogleOptimizer_Model_Code setTrackingScript(string $value) + * @method string getConversionScript() + * @method Mage_GoogleOptimizer_Model_Code setConversionScript(string $value) + * @method string getConversionPage() + * @method Mage_GoogleOptimizer_Model_Code setConversionPage(string $value) + * @method string getAdditionalData() + * @method Mage_GoogleOptimizer_Model_Code setAdditionalData(string $value) + * + * @category Mage + * @package Mage_GoogleOptimizer + * @author Magento Core Team */ class Mage_GoogleOptimizer_Model_Code extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Code/Category.php b/app/code/core/Mage/GoogleOptimizer/Model/Code/Category.php index 7f93fe1c06..3240a51d6b 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Code/Category.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Code/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Code/Page.php b/app/code/core/Mage/GoogleOptimizer/Model/Code/Page.php index 46cc5d0cd5..a9a1da973f 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Code/Page.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Code/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Code/Product.php b/app/code/core/Mage/GoogleOptimizer/Model/Code/Product.php index ad059502d7..05b5b67278 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Code/Product.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Code/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -67,7 +67,7 @@ protected function _validate() $attributesFlag = false; if ($attributes = $this->getAttributes()) { $attributesCount = 0; - foreach ($attributes as $_attributeId=>$_attributeValue) { + foreach ($attributes as $_attributeId => $_attributeValue) { if ($_attributeValue != '') { $attributesCount++; } diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code.php b/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code.php index 9b66cd356f..5bf7dc87e9 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code.php @@ -20,91 +20,18 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Google Optimizer resource model * - * @category Mage - * @package Mage_GoogleOptimizer - * @author Magento Core Team + * @category Mage + * @package Mage_GoogleOptimizer + * @author Magento Core Team */ -class Mage_GoogleOptimizer_Model_Mysql4_Code extends Mage_Core_Model_Mysql4_Abstract +class Mage_GoogleOptimizer_Model_Mysql4_Code extends Mage_GoogleOptimizer_Model_Resource_Code { - protected function _construct() - { - $this->_init('googleoptimizer/code', 'code_id'); - } - - /** - * Load scripts by entity and store - * - * @param Mage_GoogleOptimizer_Model_Code $object - * @param integer $storeId - * @return Mage_GoogleOptimizer_Model_Mysql4_Code - */ - public function loadbyEntityType($object, $storeId) - { - $read = $this->_getReadAdapter(); - if ($read) { - //preapre colums to fetch, except scope columns - $_columns = array_keys($read->describeTable($this->getMainTable())); - $columnsToFetch = array(); - foreach ($_columns as $_column) { - if (in_array($_column, array('entity_id', 'entity_type'))) { - $columnsToFetch[] = $_column; - } - } - $select = $read->select() - ->from(array('_default_table' => $this->getMainTable()), $columnsToFetch) - ->joinLeft(array('_store_table' => $this->getMainTable()), - "_store_table.entity_id = _default_table.entity_id AND _store_table.entity_type = _default_table.entity_type AND _store_table.store_id = {$storeId}", - array('code_id' => new Zend_Db_Expr("IFNULL(_store_table.code_id, _default_table.code_id)"), - 'store_id' => new Zend_Db_Expr("IFNULL(_store_table.store_id, _default_table.store_id)"), - 'control_script' => new Zend_Db_Expr("IFNULL(_store_table.control_script, _default_table.control_script)"), - 'tracking_script' => new Zend_Db_Expr("IFNULL(_store_table.tracking_script, _default_table.tracking_script)"), - 'conversion_script' => new Zend_Db_Expr("IFNULL(_store_table.conversion_script, _default_table.conversion_script)"), - 'conversion_page' => new Zend_Db_Expr("IFNULL(_store_table.conversion_page, _default_table.conversion_page)"), - 'additional_data' => new Zend_Db_Expr("IFNULL(_store_table.additional_data, _default_table.additional_data)"))) - ->where('_default_table.entity_id=?', $object->getEntity()->getId()) - ->where('_default_table.entity_type=?', $object->getEntityType()) - ->where('_default_table.store_id IN (0, ?)', $storeId) - ->order('_default_table.store_id DESC') - ->limit(1); - $data = $read->fetchRow($select); - if ($data) { - $object->setData($data); - } - } - $this->_afterLoad($object); - return $this; - } - - /** - * Delete scripts by entity and store - * - * @param Mage_GoogleOptimizer_Model_Code $object - * @param integer $store_id - * @return Mage_GoogleOptimizer_Model_Mysql4_Code - */ - public function deleteByEntityType($object, $store_id) - { - $write = $this->_getWriteAdapter(); - if ($write) { - $entityIds = $object->getEntityIds(); - if (!empty($entityIds)) { - $where = $write->quoteInto($this->getMainTable().'.entity_id IN (?)', $entityIds); - } else { - $where = $write->quoteInto($this->getMainTable().'.entity_id=?', $object->getEntity()->getId()); - } - $where.= ' AND ' . $write->quoteInto($this->getMainTable().'.entity_type=?', $object->getEntityType()) . - ' AND ' . $write->quoteInto($this->getMainTable().'.store_id=?', $store_id); - $write->delete($this->getMainTable(), $where); - } - - $this->_afterDelete($object); - return $this; - } } diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code/Collection.php b/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code/Collection.php index dae57d0619..75447ad631 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code/Collection.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Mysql4/Code/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,14 +28,10 @@ /** * Google Optimizer collection * - * @category Mage - * @package Mage_GoogleOptimizer - * @author Magento Core Team + * @category Mage + * @package Mage_GoogleOptimizer + * @author Magento Core Team */ -class Mage_GoogleOptimizer_Model_Mysql4_Code_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_GoogleOptimizer_Model_Mysql4_Code_Collection extends Mage_GoogleOptimizer_Model_Resource_Code_Collection { - protected function _construct() - { - $this->_init('googleoptimizer/code'); - } } diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Observer.php b/app/code/core/Mage/GoogleOptimizer/Model/Observer.php index 8548f07464..711407e185 100644 --- a/app/code/core/Mage/GoogleOptimizer/Model/Observer.php +++ b/app/code/core/Mage/GoogleOptimizer/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code.php b/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code.php new file mode 100755 index 0000000000..c05886519f --- /dev/null +++ b/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code.php @@ -0,0 +1,139 @@ + + */ +class Mage_GoogleOptimizer_Model_Resource_Code extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('googleoptimizer/code', 'code_id'); + } + + /** + * Load scripts by entity and store + * + * @param Mage_GoogleOptimizer_Model_Code $object + * @param integer $storeId + * @return Mage_GoogleOptimizer_Model_Resource_Code + */ + public function loadbyEntityType($object, $storeId) + { + $adapter = $this->_getReadAdapter(); + + $codeIdExpr = $adapter->getCheckSql( + 't_store.code_id IS NOT NULL', + 't_store.code_id', + 't_def.code_id'); + $storeIdExpr = $adapter->getCheckSql( + 't_store.store_id IS NOT NULL', + 't_store.store_id', + 't_def.store_id'); + $controlScriptExpr = $adapter->getCheckSql( + 't_store.control_script IS NOT NULL', + 't_store.control_script', + 't_def.control_script'); + $trackingScriptExpr = $adapter->getCheckSql( + 't_store.tracking_script IS NOT NULL', + 't_store.tracking_script', + 't_def.tracking_script'); + $conversionScriptExpr = $adapter->getCheckSql( + 't_store.conversion_script IS NOT NULL', + 't_store.conversion_script', + 't_def.conversion_script'); + $conversionPageExpr = $adapter->getCheckSql( + 't_store.conversion_page IS NOT NULL', + 't_store.conversion_page', + 't_def.conversion_page'); + $additionalDataExpr = $adapter->getCheckSql( + 't_store.additional_data IS NOT NULL', + 't_store.additional_data', + 't_def.additional_data'); + + $select = $adapter->select() + ->from( + array('t_def' => $this->getMainTable()), + array('entity_id', 'entity_type')) + ->joinLeft( + array('t_store' => $this->getMainTable()), + 't_store.entity_id = t_def.entity_id AND t_store.entity_type = t_def.entity_type AND ' + . $adapter->quoteInto('t_store.store_id = ?', $storeId), + array( + 'code_id' => $codeIdExpr, + 'store_id' => $storeIdExpr, + 'control_script' => $controlScriptExpr, + 'tracking_script' => $trackingScriptExpr, + 'conversion_script' => $conversionScriptExpr, + 'conversion_page' => $conversionPageExpr, + 'additional_data' => $additionalDataExpr)) + ->where('t_def.entity_id=?', $object->getEntity()->getId()) + ->where('t_def.entity_type=?', $object->getEntityType()) + ->where('t_def.store_id IN (0, ?)', $storeId) + ->order('t_def.store_id DESC') + ->limit(1); + $data = $adapter->fetchRow($select); + if ($data) { + $object->setData($data); + } + $this->_afterLoad($object); + return $this; + } + + /** + * Delete scripts by entity and store + * + * @param Mage_GoogleOptimizer_Model_Code $object + * @param integer $store_id + * @return Mage_GoogleOptimizer_Model_Resource_Code + */ + public function deleteByEntityType($object, $store_id) + { + $adapter = $this->_getWriteAdapter(); + + $entityIds = $object->getEntityIds(); + if (!empty($entityIds)) { + $where[$this->getMainTable() . '.entity_id IN (?)'] = $entityIds; + } else { + $where[$this->getMainTable() . '.entity_id=?'] = $object->getEntity()->getId(); + } + $where[$this->getMainTable() . '.entity_type=?'] = $object->getEntityType(); + $where[$this->getMainTable() . '.store_id=?'] = $store_id; + $adapter->delete($this->getMainTable(), $where); + + $this->_afterDelete($object); + return $this; + } +} diff --git a/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code/Collection.php b/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code/Collection.php new file mode 100755 index 0000000000..4382a4b64b --- /dev/null +++ b/app/code/core/Mage/GoogleOptimizer/Model/Resource/Code/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_GoogleOptimizer_Model_Resource_Code_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource collection initialization + * + */ + protected function _construct() + { + $this->_init('googleoptimizer/code'); + } +} diff --git a/app/code/core/Mage/GoogleOptimizer/controllers/Adminhtml/Googleoptimizer/IndexController.php b/app/code/core/Mage/GoogleOptimizer/controllers/Adminhtml/Googleoptimizer/IndexController.php index 9ec487c79a..131607f4f0 100755 --- a/app/code/core/Mage/GoogleOptimizer/controllers/Adminhtml/Googleoptimizer/IndexController.php +++ b/app/code/core/Mage/GoogleOptimizer/controllers/Adminhtml/Googleoptimizer/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/controllers/IndexController.php b/app/code/core/Mage/GoogleOptimizer/controllers/IndexController.php index fafa3dd180..4367077769 100644 --- a/app/code/core/Mage/GoogleOptimizer/controllers/IndexController.php +++ b/app/code/core/Mage/GoogleOptimizer/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/etc/config.xml b/app/code/core/Mage/GoogleOptimizer/etc/config.xml index 658976ac5d..9fd6db9066 100644 --- a/app/code/core/Mage/GoogleOptimizer/etc/config.xml +++ b/app/code/core/Mage/GoogleOptimizer/etc/config.xml @@ -21,31 +21,31 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.1.2 + 1.6.0.0 Mage_GoogleOptimizer_Model - googleoptimizer_mysql4 + googleoptimizer_resource - - - Mage_GoogleOptimizer_Model_Mysql4 + + Mage_GoogleOptimizer_Model_Resource + googleoptimizer_mysql4 googleoptimizer_code
      -
      +
      @@ -60,7 +60,9 @@ - Mage_GoogleOptimizer_Block + + Mage_GoogleOptimizer_Block + @@ -134,7 +136,6 @@ - diff --git a/app/code/core/Mage/GoogleOptimizer/etc/system.xml b/app/code/core/Mage/GoogleOptimizer/etc/system.xml index c57deff9ae..6912c44e36 100644 --- a/app/code/core/Mage/GoogleOptimizer/etc/system.xml +++ b/app/code/core/Mage/GoogleOptimizer/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/install-1.6.0.0.php b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..39133c5a57 --- /dev/null +++ b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/install-1.6.0.0.php @@ -0,0 +1,78 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); + +/** + * Create table 'googleoptimizer/code' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('googleoptimizer/code')) + ->addColumn('code_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Google optimizer code id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Optimized entity id product id or catalog id') + ->addColumn('entity_type', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Optimized entity type') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store id') + ->addColumn('control_script', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Google optimizer control script') + ->addColumn('tracking_script', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Google optimizer tracking script') + ->addColumn('conversion_script', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Google optimizer conversion script') + ->addColumn('conversion_page', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Google optimizer conversion page') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Google optimizer additional data') + ->addIndex($installer->getIdxName('googleoptimizer/code', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('googleoptimizer/code', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Googleoptimizer code'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-install-0.1.0.php index 0fee1211cb..38da846c8a 100644 --- a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-install-0.1.0.php +++ b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-install-0.1.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.0-0.1.1.php b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.0-0.1.1.php index 5fbd488621..31365974b0 100644 --- a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.0-0.1.1.php +++ b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.0-0.1.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.1-0.1.2.php b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.1-0.1.2.php index 964877f2f0..e3e2f0e648 100644 --- a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.1-0.1.2.php +++ b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-0.1.1-0.1.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_GoogleOptimizer - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..7eedc97647 --- /dev/null +++ b/app/code/core/Mage/GoogleOptimizer/sql/googleoptimizer_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,134 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('googleoptimizer/code'), + 'FK_GOOGLEOPTIMIZER_CODE_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('googleoptimizer/code'), + 'GOOGLEOPTIMIZER_CODE_STORE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('googleoptimizer/code') => array( + 'columns' => array( + 'code_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Google optimizer code id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Optimized entity id product id or catalog id' + ), + 'entity_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Optimized entity type' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store id' + ), + 'control_script' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Google optimizer control script' + ), + 'tracking_script' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Google optimizer tracking script' + ), + 'conversion_script' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Google optimizer conversion script' + ), + 'conversion_page' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Google optimizer conversion page' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Google optimizer additional data' + ) + ), + 'comment' => 'Googleoptimizer code' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('googleoptimizer/code'), + $installer->getIdxName('googleoptimizer/code', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('googleoptimizer/code', 'store_id', 'core/store', 'store_id'), + $installer->getTable('googleoptimizer/code'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit.php index 2fceec23f3..b947a7d413 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit/Form.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit/Form.php index 250e792b32..f1b7b78f31 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit/Form.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -43,7 +43,7 @@ protected function _prepareForm() $helper = Mage::helper('importexport'); $form = new Varien_Data_Form(array( 'id' => 'edit_form', - 'action' => $this->getUrl('*/*/getfilter'), + 'action' => $this->getUrl('*/*/getFilter'), 'method' => 'post' )); $fieldset = $form->addFieldset('base_fieldset', array('legend' => $helper->__('Export Settings'))); diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php index c6514dcc02..64fca7ceb4 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -63,6 +63,7 @@ public function __construct() /** * Date 'from-to' filter HTML. * + * @deprecated * @param Mage_Eav_Model_Entity_Attribute $attribute * @return string */ @@ -84,6 +85,7 @@ protected function _getDateFromToHtml(Mage_Eav_Model_Entity_Attribute $attribute /** * Input text filter HTML. * + * @deprecated * @param Mage_Eav_Model_Entity_Attribute $attribute * @return string */ @@ -96,6 +98,7 @@ protected function _getInputHtml(Mage_Eav_Model_Entity_Attribute $attribute) /** * Multiselect field filter HTML. * + * @deprecated * @param Mage_Eav_Model_Entity_Attribute $attribute * @return string */ @@ -130,6 +133,7 @@ protected function _getMultiSelectHtml(Mage_Eav_Model_Entity_Attribute $attribut /** * Number 'from-to' field filter HTML. * + * @deprecated * @param Mage_Eav_Model_Entity_Attribute $attribute * @return string */ @@ -146,6 +150,7 @@ protected function _getNumberFromToHtml(Mage_Eav_Model_Entity_Attribute $attribu /** * Select field filter HTML. * + * @deprecated * @param Mage_Eav_Model_Entity_Attribute $attribute * @return string */ @@ -181,6 +186,158 @@ protected function _getSelectHtml(Mage_Eav_Model_Entity_Attribute $attribute) } } + /** + * Date 'from-to' filter HTML with values + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $value + * @return string + */ + protected function _getDateFromToHtmlWithValue(Mage_Eav_Model_Entity_Attribute $attribute, $value) + { + $dateBlock = new Mage_Core_Block_Html_Date(array( + 'name' => $this->getFilterElementName($attribute->getAttributeCode()) . '[]', + 'id' => $this->getFilterElementId($attribute->getAttributeCode()), + 'class' => 'input-text', + 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), + 'extra_params' => 'style="width:85px !important"', + 'image' => $this->getSkinUrl('images/grid-cal.gif') + )); + $fromValue = null; + $toValue = null; + if (is_array($value) && count($value) == 2) { + $fromValue = $this->_helper->escapeHtml(reset($value)); + $toValue = $this->_helper->escapeHtml(next($value)); + } + + + return '' . $this->_helper->__('From') . ': ' + . $dateBlock->setValue($fromValue)->getHtml() + . ' ' . $this->_helper->__('To') . ': ' + . $dateBlock->setId($dateBlock->getId() . '_to')->setValue($toValue)->getHtml(); + } + + /** + * Input text filter HTML with value + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $value + * @return string + */ + protected function _getInputHtmlWithValue(Mage_Eav_Model_Entity_Attribute $attribute, $value) + { + $html = '_helper->escapeHtml($value) . '"'; + } + + return $html . ' />'; + } + + /** + * Multiselect field filter HTML with selected values + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $value + * @return string + */ + protected function _getMultiSelectHtmlWithValue(Mage_Eav_Model_Entity_Attribute $attribute, $value) + { + if ($attribute->getFilterOptions()) { + $options = $attribute->getFilterOptions(); + } else { + $options = $attribute->getSource()->getAllOptions(false); + + foreach ($options as $key => $optionParams) { + if ('' === $optionParams['value']) { + unset($options[$key]); + break; + } + } + } + if (($size = count($options))) { + $selectBlock = new Mage_Core_Block_Html_Select(array( + 'name' => $this->getFilterElementName($attribute->getAttributeCode()). '[]', + 'id' => $this->getFilterElementId($attribute->getAttributeCode()), + 'class' => 'multiselect', + 'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)) + . '" style="width:280px"' + )); + return $selectBlock->setOptions($options) + ->setValue($value) + ->getHtml(); + } else { + return $this->_helper->__('Attribute does not has options, so filtering is impossible'); + } + } + + /** + * Number 'from-to' field filter HTML with selected value. + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $value + * @return string + */ + protected function _getNumberFromToHtmlWithValue(Mage_Eav_Model_Entity_Attribute $attribute, $value) + { + $fromValue = null; + $toValue = null; + $name = $this->getFilterElementName($attribute->getAttributeCode()); + if (is_array($value) && count($value) == 2) { + $fromValue = $this->_helper->escapeHtml(reset($value)); + $toValue = $this->_helper->escapeHtml(next($value)); + } + + return '' . $this->_helper->__('From') . ': ' + . ' ' + . '' . $this->_helper->__('To') + . ': '; + } + + /** + * Select field filter HTML with selected value. + * + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @param mixed $value + * @return string + */ + protected function _getSelectHtmlWithValue(Mage_Eav_Model_Entity_Attribute $attribute, $value) + { + if ($attribute->getFilterOptions()) { + $options = array(); + + foreach ($attribute->getFilterOptions() as $value => $label) { + $options[] = array('value' => $value, 'label' => $label); + } + } else { + $options = $attribute->getSource()->getAllOptions(false); + } + if (($size = count($options))) { + // add empty vaue option + $firstOption = reset($options); + + if ('' === $firstOption['value']) { + $options[key($options)]['label'] = ''; + } else { + array_unshift($options, array('value' => '', 'label' => '')); + } + $selectBlock = new Mage_Core_Block_Html_Select(array( + 'name' => $this->getFilterElementName($attribute->getAttributeCode()), + 'id' => $this->getFilterElementId($attribute->getAttributeCode()), + 'class' => 'select', + 'extra_params' => 'style="width:280px"' + )); + return $selectBlock->setOptions($options) + ->setValue($value) + ->getHtml(); + } else { + return $this->_helper->__('Attribute does not has options, so filtering is impossible'); + } + } + /** * Add columns to grid * @@ -216,6 +373,20 @@ protected function _prepareColumns() 'frame_callback' => array($this, 'decorateFilter') )); + if ($this->hasOperation()) { + $operation = $this->getOperation(); + $skipAttr = $operation->getSkipAttr(); + if ($skipAttr) { + $this->getColumn('skip') + ->setData('values', $skipAttr); + } + $filter = $operation->getExportFilter(); + if ($filter) { + $this->getColumn('filter') + ->setData('values', $filter); + } + } + return $this; } @@ -230,18 +401,23 @@ protected function _prepareColumns() */ public function decorateFilter($value, Mage_Eav_Model_Entity_Attribute $row, Varien_Object $column, $isExport) { + $value = null; + $values = $column->getValues(); + if (is_array($values) && isset($values[$row->getAttributeCode()])) { + $value = $values[$row->getAttributeCode()]; + } switch (Mage_ImportExport_Model_Export::getAttributeFilterType($row)) { case Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT: - $cell = $this->_getSelectHtml($row); + $cell = $this->_getSelectHtmlWithValue($row, $value); break; case Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT: - $cell = $this->_getInputHtml($row); + $cell = $this->_getInputHtmlWithValue($row, $value); break; case Mage_ImportExport_Model_Export::FILTER_TYPE_DATE: - $cell = $this->_getDateFromToHtml($row); + $cell = $this->_getDateFromToHtmlWithValue($row, $value); break; case Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER: - $cell = $this->_getNumberFromToHtml($row); + $cell = $this->_getNumberFromToHtmlWithValue($row, $value); break; default: $cell = $this->_helper->__('Unknown attribute filter type'); @@ -284,10 +460,10 @@ public function getRowUrl($row) /** * Prepare collection by setting page number, sorting etc.. * - * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ - public function prepareCollection(Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection) + public function prepareCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection) { $this->_collection = $collection; diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit.php index 71705f70d6..abce0562ed 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit/Form.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit/Form.php index 54be28d568..592d89498e 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit/Form.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Frame/Result.php b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Frame/Result.php index 0e3409c7a5..163bb69c70 100644 --- a/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Frame/Result.php +++ b/app/code/core/Mage/ImportExport/Block/Adminhtml/Import/Frame/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Helper/Data.php b/app/code/core/Mage/ImportExport/Helper/Data.php index 3cce83ae0d..4b13bf6e7d 100644 --- a/app/code/core/Mage/ImportExport/Helper/Data.php +++ b/app/code/core/Mage/ImportExport/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Abstract.php b/app/code/core/Mage/ImportExport/Model/Abstract.php new file mode 100644 index 0000000000..4b8f1a48d6 --- /dev/null +++ b/app/code/core/Mage/ImportExport/Model/Abstract.php @@ -0,0 +1,117 @@ + + */ +abstract class Mage_ImportExport_Model_Abstract extends Varien_Object +{ + /** + * Enable loging + * + * @var boolean + */ + protected $_debugMode = false; + + /** + * Loger instance + * @var Mage_Core_Model_Log_Adapter + */ + protected $_logInstance; + + /** + * Fields that should be replaced in debug with '***' + * + * @var array + */ + protected $_debugReplacePrivateDataKeys = array(); + + /** + * Contains all log information + * + * @var array + */ + protected $_logTrace = array(); + + /** + * Log debug data to file. + * Log file dir: var/log/import_export/%Y/%m/%d/%time%_%operation_type%_%entity_type%.log + * + * @param mixed $debugData + * @return Mage_ImportExport_Model_Abstract + */ + public function addLogComment($debugData) + { + if (is_array($debugData)) { + $this->_logTrace = array_merge($this->_logTrace, $debugData); + } else { + $this->_logTrace[] = $debugData; + } + if (!$this->_debugMode) { + return $this; + } + + if (!$this->_logInstance) { + $dirName = date('Y' . DS .'m' . DS .'d' . DS); + $fileName = join('_', array( + str_replace(':', '-', $this->getRunAt()), + $this->getScheduledOperationId(), + $this->getOperationType(), + $this->getEntity() + )); + $dirPath = Mage::getBaseDir('var') . DS . Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY + . $dirName; + if (!is_dir($dirPath)) { + mkdir($dirPath, 0777, true); + } + $fileName = substr(strstr(Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY, DS), 1) + . $dirName . $fileName . '.log'; + $this->_logInstance = Mage::getModel('core/log_adapter', $fileName) + ->setFilterDataKeys($this->_debugReplacePrivateDataKeys); + } + $this->_logInstance->log($debugData); + return $this; + } + + /** + * Return human readable debug trace. + * + * @return array + */ + public function getFormatedLogTrace() + { + $trace = ''; + $lineNumber = 1; + foreach ($this->_logTrace as &$info) { + $trace .= $lineNumber++ . ': ' . $info . "\n"; + } + return $trace; + } +} diff --git a/app/code/core/Mage/ImportExport/Model/Config.php b/app/code/core/Mage/ImportExport/Model/Config.php index ce4d686ac9..3c8ea7bc3b 100644 --- a/app/code/core/Mage/ImportExport/Model/Config.php +++ b/app/code/core/Mage/ImportExport/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -38,7 +38,7 @@ class Mage_ImportExport_Model_Config * * @static * @param string $configKey - * @throws Exception + * @throws Mage_Core_Exception * @return array */ public static function getModels($configKey) @@ -77,4 +77,24 @@ public static function getModelsComboOptions($configKey, $withEmpty = false) } return $options; } + + /** + * Get model params as array of options. + * + * @static + * @param string $configKey + * @param boolean $withEmpty OPTIONAL Include 'Please Select' option or not + * @return array + */ + public static function getModelsArrayOptions($configKey, $withEmpty = false) + { + $options = array(); + if ($withEmpty) { + $options[0] = Mage::helper('importexport')->__('-- Please Select --'); + } + foreach (self::getModels($configKey) as $type => $params) { + $options[$type] = $params['label']; + } + return $options; + } } diff --git a/app/code/core/Mage/ImportExport/Model/Export.php b/app/code/core/Mage/ImportExport/Model/Export.php index 15cf2f4fd3..c4c9584099 100644 --- a/app/code/core/Mage/ImportExport/Model/Export.php +++ b/app/code/core/Mage/ImportExport/Model/Export.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ * @package Mage_ImportExport * @author Magento Core Team */ -class Mage_ImportExport_Model_Export extends Varien_Object +class Mage_ImportExport_Model_Export extends Mage_ImportExport_Model_Abstract { const FILTER_ELEMENT_GROUP = 'export_filter'; const FILTER_ELEMENT_SKIP = 'skip_attr'; @@ -138,15 +138,29 @@ protected function _getWriter() /** * Export data. * - * @throws Exception + * @throws Mage_Core_Exception * @return string */ public function export() { if (isset($this->_data[self::FILTER_ELEMENT_GROUP])) { - return $this->_getEntityAdapter() + $this->addLogComment(Mage::helper('importexport')->__('Begin export of %s', $this->getEntity())); + $result = $this->_getEntityAdapter() ->setWriter($this->_getWriter()) ->export(); + $countRows = substr_count(trim($result), "\n"); + if (!$countRows) { + Mage::throwException( + Mage::helper('importexport')->__('There is no data for export') + ); + } + if ($result) { + $this->addLogComment(array( + Mage::helper('importexport')->__('Exported %s rows.', $countRows), + Mage::helper('importexport')->__('Export has been done.') + )); + } + return $result; } else { Mage::throwException( Mage::helper('importexport')->__('No filter data provided') @@ -157,10 +171,10 @@ public function export() /** * Clean up already loaded attribute collection. * - * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ - public function filterAttributeCollection(Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection) + public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection) { return $this->_getEntityAdapter()->filterAttributeCollection($collection); } @@ -177,15 +191,15 @@ public static function getAttributeFilterType(Mage_Eav_Model_Entity_Attribute $a { if ($attribute->usesSource() || $attribute->getFilterOptions()) { return self::FILTER_TYPE_SELECT; + } elseif ('datetime' == $attribute->getBackendType()) { + return self::FILTER_TYPE_DATE; + } elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) { + return self::FILTER_TYPE_NUMBER; } elseif ($attribute->isStatic() || 'varchar' == $attribute->getBackendType() || 'text' == $attribute->getBackendType() ) { return self::FILTER_TYPE_INPUT; - } elseif ('datetime' == $attribute->getBackendType()) { - return self::FILTER_TYPE_DATE; - } elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) { - return self::FILTER_TYPE_NUMBER; } else { Mage::throwException( Mage::helper('importexport')->__('Can not determine attribute filter type') @@ -220,7 +234,7 @@ public function getEntity() /** * Entity attributes collection getter. * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ public function getEntityAttributeCollection() { diff --git a/app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php b/app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php index 58ff265c88..6229267a5e 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Export/Adapter/Csv.php b/app/code/core/Mage/ImportExport/Model/Export/Adapter/Csv.php index 789f8d41df..f3735fcd6e 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Adapter/Csv.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Adapter/Csv.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php index 5e919c2b0c..a94c955db2 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -324,10 +324,10 @@ abstract public function export(); /** * Clean up attribute collection. * - * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ - public function filterAttributeCollection(Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection) + public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection) { $collection->load(); @@ -342,7 +342,7 @@ public function filterAttributeCollection(Mage_Eav_Model_Mysql4_Entity_Attribute /** * Entity attributes collection getter. * - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ abstract public function getAttributeCollection(); diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php index 2a71004483..f9924bd514 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -176,7 +176,8 @@ public function export() if ($attrValues) { $value = $attrValues[$value]; } - $addrRow[Mage_ImportExport_Model_Import_Entity_Customer_Address::getColNameForAttrCode($attrCode)] = $value; + $column = Mage_ImportExport_Model_Import_Entity_Customer_Address::getColNameForAttrCode($attrCode); + $addrRow[$column] = $value; } } $customerAddrs[$address['parent_id']][$address->getId()] = $addrRow; @@ -236,10 +237,10 @@ public function export() /** * Clean up already loaded attribute collection. * - * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ - public function filterAttributeCollection(Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection) + public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection) { foreach (parent::filterAttributeCollection($collection) as $attribute) { if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) { diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php index 606afa5009..0942b25808 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -487,7 +487,7 @@ public function export() $stockItemRows = $this->_prepareCatalogInventory($productIds); // prepare links information - $this->_prepareLinks($productIds); + $linksRows = $this->_prepareLinks($productIds); $linkIdColPrefix = array( Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED => '_links_related_', Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL => '_links_upsell_', @@ -748,10 +748,10 @@ public function export() /** * Clean up already loaded attribute collection. * - * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection - * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection + * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ - public function filterAttributeCollection(Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection) + public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection) { $validTypes = array_keys($this->_productTypeModels); diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php index 6a2dd6a5fa..c460bc169c 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Configurable.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Configurable.php index 8df6a37828..e78478c9cb 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Configurable.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Grouped.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Grouped.php index 1e24100015..1619047ba6 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Grouped.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Simple.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Simple.php index ff4c89f39b..1d23a4a571 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Simple.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import.php b/app/code/core/Mage/ImportExport/Model/Import.php index ba2781b745..76dfcad09b 100644 --- a/app/code/core/Mage/ImportExport/Model/Import.php +++ b/app/code/core/Mage/ImportExport/Model/Import.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,12 +31,12 @@ * @package Mage_ImportExport * @author Magento Core Team */ -class Mage_ImportExport_Model_Import extends Varien_Object +class Mage_ImportExport_Model_Import extends Mage_ImportExport_Model_Abstract { /** * Key in config with entities. */ - const CONFIG_KEY_ENTITIES = 'global/importexport/import_entities'; + const CONFIG_KEY_ENTITIES = 'global/importexport/import_entities'; /** * Import behavior. @@ -128,6 +128,58 @@ protected function _getSourceAdapter($sourceFile) return Mage_ImportExport_Model_Import_Adapter::findAdapterFor($sourceFile); } + /** + * Return operation result messages + * + * @param bool $validationResult + * @return array + */ + public function getOperationResultMessages($validationResult) + { + $messages = array(); + if ($this->getProcessedRowsCount()) { + if (!$validationResult) { + if ($this->getProcessedRowsCount() == $this->getInvalidRowsCount()) { + $messages[] = Mage::helper('importexport')->__('File is totally invalid. Please fix errors and re-upload file'); + } elseif ($this->getErrorsCount() >= $this->getErrorsLimit()) { + $messages[] = Mage::helper('importexport')->__('Errors limit (%d) reached. Please fix errors and re-upload file', + $this->getErrorsLimit() + ); + } else { + if ($this->isImportAllowed()) { + $messages[] = Mage::helper('importexport')->__('Please fix errors and re-upload file'); + } else { + $messages[] = Mage::helper('importexport')->__('File is partially valid, but import is not possible'); + } + } + // errors info + foreach ($this->getErrors() as $errorCode => $rows) { + $error = $errorCode . ' ' + . Mage::helper('importexport')->__('in rows') . ': ' + . implode(', ', $rows); + $messages[] = $error; + } + } else { + if ($this->isImportAllowed()) { + $messages[] = Mage::helper('importexport')->__('Validation finished successfully'); + } else { + $messages[] = Mage::helper('importexport')->__('File is valid, but import is not possible'); + } + } + $notices = $this->getNotices(); + if (is_array($notices)) { + $messages = array_merge($messages, $notices); + } + $messages[] = Mage::helper('importexport')->__('Checked rows: %d, checked entities: %d, invalid rows: %d, total errors: %d', + $this->getProcessedRowsCount(), $this->getProcessedEntitiesCount(), + $this->getInvalidRowsCount(), $this->getErrorsCount() + ); + } else { + $messages[] = Mage::helper('importexport')->__('File does not contain data.'); + } + return $messages; + } + /** * Get attribute type for upcoming validation. * @@ -272,7 +324,16 @@ public function importSource() 'entity' => self::getDataSourceModel()->getEntityTypeCode(), 'behavior' => self::getDataSourceModel()->getBehavior() )); - return $this->_getEntityAdapter()->importData(); + $this->addLogComment(Mage::helper('importexport')->__('Begin import of "%s" with "%s" behavior', $this->getEntity(), $this->getBehavior())); + $result = $this->_getEntityAdapter()->importData(); + $this->addLogComment(array( + Mage::helper('importexport')->__('Checked rows: %d, checked entities: %d, invalid rows: %d, total errors: %d', + $this->getProcessedRowsCount(), $this->getProcessedEntitiesCount(), + $this->getInvalidRowsCount(), $this->getErrorsCount() + ), + Mage::helper('importexport')->__('Import has been done successfuly.') + )); + return $result; } /** @@ -383,12 +444,17 @@ public function uploadSource() */ public function validateSource($sourceFile) { + $this->addLogComment(Mage::helper('importexport')->__('Begin data validation')); $result = $this->_getEntityAdapter() ->setSource($this->_getSourceAdapter($sourceFile)) ->isDataValid(); @unlink($sourceFile); - + $messages = $this->getOperationResultMessages($result); + $this->addLogComment($messages); + if ($result) { + $this->addLogComment(Mage::helper('importexport')->__('Done import data validation')); + } return $result; } @@ -405,7 +471,8 @@ public function invalidateIndex() $indexers = self::$_entityInvalidatedIndexes[$this->getEntity()]; foreach ($indexers as $indexer) { - if ($indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode($indexer)) { + $indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode($indexer); + if ($indexProcess) { $indexProcess->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); } } @@ -413,3 +480,4 @@ public function invalidateIndex() return $this; } } + diff --git a/app/code/core/Mage/ImportExport/Model/Import/Adapter.php b/app/code/core/Mage/ImportExport/Model/Import/Adapter.php index 389f329e49..76e7eb955e 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Adapter.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Adapter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Adapter/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Adapter/Abstract.php index c0518bbe5e..a07899316f 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Adapter/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Adapter/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php b/app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php index b589d5200b..5c24845131 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php index 80cab19bf9..6e67e8cf83 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php index 5fb61b3561..5b9f38c6f0 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php index 859071d7f7..1d5590671e 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php index b520c2c4af..6f002bcae8 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1234,12 +1234,12 @@ protected function _saveStockItem() 'notify_stock_qty' => 1, 'use_config_notify_stock_qty' => 1, 'enable_qty_increments' => 0, - 'use_config_enable_qty_increments' => 1, + 'use_config_enable_qty_inc' => 1, 'qty_increments' => 0, 'use_config_qty_increments' => 1, 'is_in_stock' => 0, 'low_stock_date' => null, - 'stock_status_changed_automatically' => 0 + 'stock_status_changed_auto' => 0 ); $entityTable = Mage::getResourceModel('cataloginventory/stock_item')->getMainTable(); @@ -1274,7 +1274,7 @@ protected function _saveStockItem() } else { $stockItem->setQty(0); } - $stockData[] = $stockItem->getData(); + $stockData[] = $stockItem->unsetOldData()->getData(); } } if ($stockData) { diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Abstract.php index cef415df7e..397a2f1782 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Abstract.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Configurable.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Configurable.php index 2ce72fe8b4..b98796229b 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Configurable.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php index 6f64c0ce15..0937eff0ff 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Simple.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Simple.php index 0847dd65b7..4fff52364f 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Simple.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product.php index 36ad4065e2..643c380c8c 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product/Resource.php b/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product/Resource.php index e27291ab35..24070d4e2d 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product/Resource.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Proxy/Product/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Mysql4/Import/Data.php b/app/code/core/Mage/ImportExport/Model/Mysql4/Import/Data.php index 1b7e22640f..1e55199b1d 100644 --- a/app/code/core/Mage/ImportExport/Model/Mysql4/Import/Data.php +++ b/app/code/core/Mage/ImportExport/Model/Mysql4/Import/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,117 +31,6 @@ * @package Mage_ImportExport * @author Magento Core Team */ -class Mage_ImportExport_Model_Mysql4_Import_Data extends Mage_Core_Model_Mysql4_Abstract implements IteratorAggregate +class Mage_ImportExport_Model_Mysql4_Import_Data extends Mage_ImportExport_Model_Resource_Import_Data { - /** - * @var IteratorIterator - */ - protected $_iterator = null; - - /** - * Resource initialization - */ - protected function _construct() - { - $this->_init('importexport/importdata', 'id'); - } - - /** - * Retrieve an external iterator - * - * @return IteratorIterator - */ - public function getIterator () - { - $stmt = $this->_getWriteAdapter()->query( - $this->_getWriteAdapter()->select()->from($this->getMainTable(), array('data'))->order('id ASC') - ); - $stmt->setFetchMode(PDO::FETCH_NUM); - - return $stmt->getIterator(); - } - - /** - * Clean all bunches from table. - * - * @return int - */ - public function cleanBunches() - { - return $this->_getWriteAdapter()->query( - 'TRUNCATE ' . $this->_getWriteAdapter()->quoteIdentifier($this->getMainTable()) - ); - } - - /** - * Return behavior from import data table. - * - * @throws Exception - * @return string - */ - public function getBehavior() - { - $behaviors = array_unique($this->_getReadAdapter()->fetchCol( - $this->_getReadAdapter()->select()->from($this->getMainTable(), array('behavior')) - )); - if (count($behaviors) != 1) { - Mage::throwException(Mage::helper('importexport')->__('Error in data structure: behaviors are mixed')); - } - return $behaviors[0]; - } - - /** - * Return entity type code from import data table. - * - * @throws Exception - * @return string - */ - public function getEntityTypeCode() - { - $entityCodes = array_unique($this->_getReadAdapter()->fetchCol( - $this->_getReadAdapter()->select()->from($this->getMainTable(), array('entity')) - )); - if (count($entityCodes) != 1) { - Mage::throwException(Mage::helper('importexport')->__('Error in data structure: entity codes are mixed')); - } - return $entityCodes[0]; - } - - /** - * Get next bunch of validatetd rows. - * - * @return array|null - */ - public function getNextBunch() - { - if (null === $this->_iterator) { - $this->_iterator = $this->getIterator(); - $this->_iterator->rewind(); - } - if ($this->_iterator->valid()) { - $dataRow = $this->_iterator->current(); - $dataRow = unserialize($dataRow[0]); - $this->_iterator->next(); - } else { - $this->_iterator = null; - $dataRow = null; - } - return $dataRow; - } - - /** - * Save import rows bunch. - * - * @param string $entity - * @param string $behavior - * @param array $data - * @return int - */ - public function saveBunch($entity, $behavior, array $data) - { - return $this->_getWriteAdapter()->insert( - $this->getMainTable(), - array('behavior' => $behavior, 'entity' => $entity, 'data' => serialize($data)) - ); - } } diff --git a/app/code/core/Mage/ImportExport/Model/Mysql4/Setup.php b/app/code/core/Mage/ImportExport/Model/Mysql4/Setup.php index 52df17990f..08f4d82029 100644 --- a/app/code/core/Mage/ImportExport/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/ImportExport/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,6 +31,6 @@ * @package Mage_ImportExport * @author Magento Core Team */ -class Mage_ImportExport_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup +class Mage_ImportExport_Model_Mysql4_Setup extends Mage_ImportExport_Model_Resource_Setup { } diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Import/Data.php b/app/code/core/Mage/ImportExport/Model/Resource/Import/Data.php new file mode 100644 index 0000000000..5849b51ad0 --- /dev/null +++ b/app/code/core/Mage/ImportExport/Model/Resource/Import/Data.php @@ -0,0 +1,154 @@ + + */ +class Mage_ImportExport_Model_Resource_Import_Data + extends Mage_Core_Model_Resource_Db_Abstract + implements IteratorAggregate +{ + /** + * @var IteratorIterator + */ + protected $_iterator = null; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('importexport/importdata', 'id'); + } + + /** + * Retrieve an external iterator + * + * @return IteratorIterator + */ + public function getIterator() + { + $adapter = $this->_getWriteAdapter(); + $stmt = $adapter->query( + $adapter->select() + ->from($this->getMainTable(), array('data')) + ->order('id ASC') + ); + $stmt->setFetchMode(PDO::FETCH_NUM); + + return $stmt->getIterator(); + } + + /** + * Clean all bunches from table. + * + * @return Varien_Db_Adapter_Interface + */ + public function cleanBunches() + { + return $this->_getWriteAdapter()->truncateTable($this->getMainTable()); + } + + /** + * Return behavior from import data table. + * + * @throws Exception + * @return string + */ + public function getBehavior() + { + $adapter = $this->_getReadAdapter(); + $behaviors = array_unique($adapter->fetchCol( + $adapter->select() + ->from($this->getMainTable(), array('behavior')) + )); + if (count($behaviors) != 1) { + Mage::throwException(Mage::helper('importexport')->__('Error in data structure: behaviors are mixed')); + } + return $behaviors[0]; + } + + /** + * Return entity type code from import data table. + * + * @throws Exception + * @return string + */ + public function getEntityTypeCode() + { + $adapter = $this->_getReadAdapter(); + $entityCodes = array_unique($adapter->fetchCol( + $adapter->select() + ->from($this->getMainTable(), array('entity')) + )); + if (count($entityCodes) != 1) { + Mage::throwException(Mage::helper('importexport')->__('Error in data structure: entity codes are mixed')); + } + return $entityCodes[0]; + } + + /** + * Get next bunch of validatetd rows. + * + * @return array|null + */ + public function getNextBunch() + { + if (null === $this->_iterator) { + $this->_iterator = $this->getIterator(); + $this->_iterator->rewind(); + } + if ($this->_iterator->valid()) { + $dataRow = $this->_iterator->current(); + $dataRow = unserialize($dataRow[0]); + $this->_iterator->next(); + } else { + $this->_iterator = null; + $dataRow = null; + } + return $dataRow; + } + + /** + * Save import rows bunch. + * + * @param string $entity + * @param string $behavior + * @param array $data + * @return int + */ + public function saveBunch($entity, $behavior, array $data) + { + return $this->_getWriteAdapter()->insert( + $this->getMainTable(), + array('behavior' => $behavior, 'entity' => $entity, 'data' => serialize($data)) + ); + } +} diff --git a/app/code/core/Mage/ImportExport/Model/Resource/Setup.php b/app/code/core/Mage/ImportExport/Model/Resource/Setup.php new file mode 100644 index 0000000000..15962428fe --- /dev/null +++ b/app/code/core/Mage/ImportExport/Model/Resource/Setup.php @@ -0,0 +1,36 @@ + + */ +class Mage_ImportExport_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/ImportExport/Model/Source/Export/Entity.php b/app/code/core/Mage/ImportExport/Model/Source/Export/Entity.php index eeb8690f72..a15166668d 100644 --- a/app/code/core/Mage/ImportExport/Model/Source/Export/Entity.php +++ b/app/code/core/Mage/ImportExport/Model/Source/Export/Entity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Source/Export/Format.php b/app/code/core/Mage/ImportExport/Model/Source/Export/Format.php index b3f6a392db..d50ee0917e 100644 --- a/app/code/core/Mage/ImportExport/Model/Source/Export/Format.php +++ b/app/code/core/Mage/ImportExport/Model/Source/Export/Format.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Source/Import/Behavior.php b/app/code/core/Mage/ImportExport/Model/Source/Import/Behavior.php index 6ee5873b36..bb369c05ab 100644 --- a/app/code/core/Mage/ImportExport/Model/Source/Import/Behavior.php +++ b/app/code/core/Mage/ImportExport/Model/Source/Import/Behavior.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/Model/Source/Import/Entity.php b/app/code/core/Mage/ImportExport/Model/Source/Import/Entity.php index af755ef425..78af736ea7 100644 --- a/app/code/core/Mage/ImportExport/Model/Source/Import/Entity.php +++ b/app/code/core/Mage/ImportExport/Model/Source/Import/Entity.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php index 60616f0b76..ed2e07d754 100644 --- a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php +++ b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ExportController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -71,21 +71,20 @@ protected function _isAllowed() /** * Load data with filter applying and create file for download. * - * @return void + * @return Mage_ImportExport_Adminhtml_ExportController */ public function exportAction() { if ($this->getRequest()->getPost(Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP)) { try { /** @var $export Mage_ImportExport_Model_Export */ - $export = Mage::getModel('importexport/export'); - - $export->setData($this->getRequest()->getParams()); + $model = Mage::getModel('importexport/export'); + $model->setData($this->getRequest()->getParams()); return $this->_prepareDownloadResponse( - $export->getFileName(), - $export->export(), - $export->getContentType() + $model->getFileName(), + $model->export(), + $model->getContentType() ); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); @@ -100,13 +99,28 @@ public function exportAction() } /** - * Get grid of entity attributes and filter action. + * Index action. * * @return void */ - public function getfilterAction() + public function indexAction() { - if ($this->getRequest()->isXmlHttpRequest() && ($data = $this->getRequest()->getParams())) { + $this->_initAction() + ->_title($this->__('Export')) + ->_addBreadcrumb($this->__('Export'), $this->__('Export')); + + $this->renderLayout(); + } + + /** + * Get grid-filter of entity attributes action. + * + * @return void + */ + public function getFilterAction() + { + $data = $this->getRequest()->getParams(); + if ($this->getRequest()->isXmlHttpRequest() && $data) { try { $this->loadLayout(); @@ -127,20 +141,6 @@ public function getfilterAction() } else { $this->_getSession()->addError($this->__('No valid data sent')); } - return $this->_redirect('*/*/index'); - } - - /** - * Index action. - * - * @return void - */ - public function indexAction() - { - $this->_initAction() - ->_title($this->__('Export')) - ->_addBreadcrumb($this->__('Export'), $this->__('Export')); - - $this->renderLayout(); + $this->_redirect('*/*/index'); } } diff --git a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php index 51412f1db8..c23c4fa106 100644 --- a/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php +++ b/app/code/core/Mage/ImportExport/controllers/Adminhtml/ImportController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ImportExport/etc/adminhtml.xml b/app/code/core/Mage/ImportExport/etc/adminhtml.xml index 2a55716a9c..0ffcddbe3c 100644 --- a/app/code/core/Mage/ImportExport/etc/adminhtml.xml +++ b/app/code/core/Mage/ImportExport/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/ImportExport/etc/config.xml b/app/code/core/Mage/ImportExport/etc/config.xml index c6f90ddb99..b58ad2863f 100644 --- a/app/code/core/Mage/ImportExport/etc/config.xml +++ b/app/code/core/Mage/ImportExport/etc/config.xml @@ -21,30 +21,30 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.1.0 + 1.6.0.1 Mage_ImportExport_Model - importexport_mysql4 + importexport_resource - - Mage_ImportExport_Model_Mysql4 + + Mage_ImportExport_Model_Resource importexport_importdata
      -
      +
      @@ -60,7 +60,7 @@ Mage_ImportExport - Mage_ImportExport_Model_Mysql4_Setup + Mage_ImportExport_Model_Resource_Setup diff --git a/app/code/core/Mage/ImportExport/sql/importexport_setup/install-1.6.0.0.php b/app/code/core/Mage/ImportExport/sql/importexport_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..7ddff2bf27 --- /dev/null +++ b/app/code/core/Mage/ImportExport/sql/importexport_setup/install-1.6.0.0.php @@ -0,0 +1,140 @@ +startSetup(); + +/** + * Create table 'importexport/importdata' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('importexport/importdata')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('entity', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + ), 'Entity') + ->addColumn('behavior', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array( + 'nullable' => false, + 'default' => Mage_ImportExport_Model_Import::BEHAVIOR_APPEND, + ), 'Behavior') + ->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'default' => '', + ), 'Data') + ->setComment('Import Data Table'); +$installer->getConnection()->createTable($table); + +/** + * Add unique key for parent-child pairs which makes easier configurable products import + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_link'), + $installer->getIdxName( + 'catalog/product_super_link', + array('product_id', 'parent_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'parent_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +/** + * Add unique key for 'catalog/product_super_attribute' table + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute'), + $installer->getIdxName( + 'catalog/product_super_attribute', + array('product_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_id', 'attribute_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +/** + * Add unique key for 'catalog/product_super_attribute_pricing' table + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_super_attribute_pricing'), + $installer->getIdxName( + 'catalog/product_super_attribute_pricing', + array('product_super_attribute_id', 'value_index', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_super_attribute_id', 'value_index', 'website_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +/** + * Add unique key for 'catalog/product_link_attribute_int' table + */ +$installer->getConnection()->addIndex( + $installer->getTable('catalog/product_link_attribute_int'), + $installer->getIdxName( + 'catalog/product_link_attribute_int', + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('product_link_attribute_id', 'link_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +/** + * Add foreign keys for 'catalog/product_link_attribute_int' table + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_int', + 'link_id', + 'catalog/product_link', + 'link_id' + ), + $installer->getTable('catalog/product_link_attribute_int'), + 'link_id', + $installer->getTable('catalog/product_link'), + 'link_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'catalog/product_link_attribute_int', + 'product_link_attribute_id', + 'catalog/product_link_attribute', + 'product_link_attribute_id' + ), + $installer->getTable('catalog/product_link_attribute_int'), + 'product_link_attribute_id', + $installer->getTable('catalog/product_link_attribute'), + 'product_link_attribute_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/ImportExport/sql/importexport_setup/mysql4-install-0.1.0.php b/app/code/core/Mage/ImportExport/sql/importexport_setup/mysql4-install-0.1.0.php index e1ce5b41f9..4eff7951f8 100644 --- a/app/code/core/Mage/ImportExport/sql/importexport_setup/mysql4-install-0.1.0.php +++ b/app/code/core/Mage/ImportExport/sql/importexport_setup/mysql4-install-0.1.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php index 6db26b0519..12de6cd103 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process.php b/app/code/core/Mage/Index/Block/Adminhtml/Process.php index 911ed3930e..49493b6284 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit.php b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit.php index 250840df9e..867791a901 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Form.php b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Form.php index 21a358c4a3..eb19e29951 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Form.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tab/Main.php b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tab/Main.php index 4668e9e17a..8a10972abf 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tab/Main.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tabs.php b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tabs.php index 1b259a48be..4bc1ac9973 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tabs.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php b/app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php index 66e334467a..0ad486e601 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Process/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Helper/Data.php b/app/code/core/Mage/Index/Helper/Data.php index 5e4b0a13bf..f9f8cb3798 100644 --- a/app/code/core/Mage/Index/Helper/Data.php +++ b/app/code/core/Mage/Index/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index 40bc39fc04..3cb6452165 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -20,10 +20,28 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Index_Model_Resource_Event _getResource() + * @method Mage_Index_Model_Resource_Event getResource() + * @method Mage_Index_Model_Event setType(string $value) + * @method Mage_Index_Model_Event setEntity(string $value) + * @method int getEntityPk() + * @method Mage_Index_Model_Event setEntityPk(int $value) + * @method string getCreatedAt() + * @method Mage_Index_Model_Event setCreatedAt(string $value) + * @method Mage_Index_Model_Event setOldData(string $value) + * @method Mage_Index_Model_Event setNewData(string $value) + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ class Mage_Index_Model_Event extends Mage_Core_Model_Abstract { /** diff --git a/app/code/core/Mage/Index/Model/Indexer.php b/app/code/core/Mage/Index/Model/Indexer.php index ee9cc0d70d..74a222b2c4 100644 --- a/app/code/core/Mage/Index/Model/Indexer.php +++ b/app/code/core/Mage/Index/Model/Indexer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,7 +32,7 @@ class Mage_Index_Model_Indexer /** * Collection of available processes * - * @var Mage_Index_Model_Mysql4_Process_Collection + * @var Mage_Index_Model_Resource_Process_Collection */ protected $_processesCollection; @@ -54,7 +54,7 @@ public function __construct() /** * Get collection of all available processes * - * @return Mage_Index_Model_Mysql4_Process_Collection + * @return Mage_Index_Model_Resource_Process_Collection */ public function getProcessesCollection() { diff --git a/app/code/core/Mage/Index/Model/Indexer/Abstract.php b/app/code/core/Mage/Index/Model/Indexer/Abstract.php index dc35c1734c..c22f3a97f8 100644 --- a/app/code/core/Mage/Index/Model/Indexer/Abstract.php +++ b/app/code/core/Mage/Index/Model/Indexer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Model/Mysql4/Abstract.php b/app/code/core/Mage/Index/Model/Mysql4/Abstract.php index 9a5b0e2b3c..dd4fc583da 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Abstract.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Abstract.php @@ -20,213 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Abstract resource model. Can be used as base for indexer resources + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team */ -abstract class Mage_Index_Model_Mysql4_Abstract extends Mage_Core_Model_Mysql4_Abstract +abstract class Mage_Index_Model_Mysql4_Abstract extends Mage_Index_Model_Resource_Abstract { - const IDX_SUFFIX = '_idx'; - const TMP_SUFFIX = '_tmp'; - - /** - * Flag that defines if need to use "_idx" index table suffix instead of "_tmp" - * - * @var bool - */ - protected $_isNeedUseIdxTable = false; - - /** - * Flag that defines if need to disable keys during data inserting - * - * @var bool - */ - protected $_isDisableKeys = true; - - public function reindexAll() - { - $this->useIdxTable(true); - return $this; - } - - /** - * Get DB adapter for index data processing - * - * @return Varien_Db_Adapter_Pdo_Mysql - */ - protected function _getIndexAdapter() - { - return $this->_getWriteAdapter(); - } - - /** - * Get index table name with additional suffix - * - * @param string $table - * @return string - */ - public function getIdxTable($table = null) - { - $suffix = self::TMP_SUFFIX; - if ($this->_isNeedUseIdxTable) { - $suffix = self::IDX_SUFFIX; - } - if ($table) { - return $table . $suffix; - } - return $this->getMainTable() . $suffix; - } - - /** - * Synchronize data between index storage and original storage - * - * @return Mage_Index_Model_Mysql4_Abstract - */ - public function syncData() - { - $this->beginTransaction(); - /** - * Can't use truncate because of transaction - */ - $this->_getWriteAdapter()->delete($this->getMainTable()); - $this->insertFromTable($this->getIdxTable(), $this->getMainTable(), false); - $this->commit(); - return $this; - } - - /** - * Create temporary table for index data pregeneration - * - * @return Mage_Index_Model_Mysql4_Abstract - */ - public function cloneIndexTable($asOriginal = false) - { - $mainTable = $this->getMainTable(); - $idxTable = $this->getIdxTable(); - $idxAdapter = $this->_getIndexAdapter(); - - $sql = 'DROP TABLE IF EXISTS ' . $idxAdapter->quoteIdentifier($idxTable); - $idxAdapter->query($sql); - if ($asOriginal) { - $sql = 'CREATE TABLE ' . $idxAdapter->quoteIdentifier($idxTable) - . ' LIKE ' . $idxAdapter->quoteIdentifier($this->getMainTable()); - } else { - $sql = 'CREATE TABLE ' . $idxAdapter->quoteIdentifier($idxTable) - . ' SELECT * FROM ' . $idxAdapter->quoteIdentifier($mainTable) . ' LIMIT 0'; - } - $idxAdapter->query($sql); - return $this; - } - - /** - * Copy data from source table of read adapter to destination table of index adapter - * - * @param string $sourceTable - * @param string $destTable - * @param bool $readToIndex data migration direction (true - read=>index, false - index=>read) - * @return Mage_Index_Model_Mysql4_Abstract - */ - public function insertFromTable($sourceTable, $destTable, $readToIndex=true) - { - if ($readToIndex) { - $columns = $this->_getWriteAdapter()->describeTable($sourceTable); - } else { - $columns = $this->_getIndexAdapter()->describeTable($sourceTable); - } - $columns = array_keys($columns); - $select = 'SELECT * FROM ' . $sourceTable; - return $this->insertFromSelect($select, $destTable, $columns, $readToIndex); - } - - /** - * Insert data from select statement of read adapter to - * destination table related with index adapter - * - * @param string $select - * @param string $destTable - * @param array $columns - * @param bool $readToIndex data migration direction (true - read=>index, false - index=>read) - * @return Mage_Index_Model_Mysql4_Abstract - * */ - public function insertFromSelect($select, $destTable, array $columns, $readToIndex=true) - { - if ($readToIndex) { - $from = $this->_getWriteAdapter(); - $to = $this->_getIndexAdapter(); - } else { - $from = $this->_getIndexAdapter(); - $to = $this->_getWriteAdapter(); - } - - if ($this->useDisableKeys()) { - $to->query("ALTER TABLE {$destTable} DISABLE KEYS"); - } - - if ($from === $to) { - $sql = 'INSERT INTO ' . $destTable . ' ' . $select; - $to->query($sql); - } else { - $stmt = $from->query($select); - $data = array(); - $counter = 0; - while ($row = $stmt->fetch(PDO::FETCH_NUM)) { - $data[] = $row; - $counter++; - if ($counter>2000) { - $to->insertArray($destTable, $columns, $data); - $data = array(); - $counter = 0; - } - } - if (!empty($data)) { - $to->insertArray($destTable, $columns, $data); - } - } - - if ($this->useDisableKeys()) { - $to->query("ALTER TABLE {$destTable} ENABLE KEYS"); - } - - return $this; - } - - /** - * Set or get what either "_idx" or "_tmp" suffixed temporary index table need to use - * - * @param bool $value - * @return Mage_Index_Model_Mysql4_Abstract - */ - public function useIdxTable($value = null) - { - if (!is_null($value)) { - $this->_isNeedUseIdxTable = (bool)$value; - } - return $this->_isNeedUseIdxTable; - } - - /** - * Set or get flag that defines if need to disable keys during data inserting - * - * @param bool $value - * @return Mage_Index_Model_Mysql4_Abstract - */ - public function useDisableKeys($value = null) - { - if (!is_null($value)) { - $this->_isDisableKeys = (bool)$value; - } - return $this->_isDisableKeys; - } - - - /** - * Clean up temporary index table - */ - public function clearTemporaryIndexTable() - { - $this->_getWriteAdapter()->delete($this->getIdxTable()); - } } diff --git a/app/code/core/Mage/Index/Model/Mysql4/Event.php b/app/code/core/Mage/Index/Model/Mysql4/Event.php index 0159a3deed..ef45814a98 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Event.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Event.php @@ -20,68 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Index_Model_Mysql4_Event extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('index/event', 'event_id'); - } - - /** - * Check if semilar event exist before start saving data - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Index_Model_Mysql4_Event - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - /** - * Check if event already exist and merge previous data - */ - if (!$object->getId()) { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('type=?', $object->getType()) - ->where('entity=?', $object->getEntity()); - if ($object->hasEntityPk()) { - $select->where('entity_pk=?', $object->getEntityPk()); - } - $data = $this->_getWriteAdapter()->fetchRow($select); - if ($data) { - $object->mergePreviousData($data); - } - } - return parent::_beforeSave($object); - } - /** - * Save assigned processes - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Index_Model_Mysql4_Event - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $processIds = $object->getProcessIds(); - if (is_array($processIds)) { - $processTable = $this->getTable('index/process_event'); - if (empty($processIds)) { - $this->_getWriteAdapter()->delete($processTable); - } else { - foreach ($processIds as $processId => $processStatus) { - $data = array( - 'process_id'=> $processId, - 'event_id' => $object->getId(), - 'status' => $processStatus - ); - $this->_getWriteAdapter()->insertOnDuplicate($processTable, $data, array('status')); - } - } - } - return parent::_afterSave($object); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ +class Mage_Index_Model_Mysql4_Event extends Mage_Index_Model_Resource_Event +{ } diff --git a/app/code/core/Mage/Index/Model/Mysql4/Event/Collection.php b/app/code/core/Mage/Index/Model/Mysql4/Event/Collection.php index 5f6bb12515..b743b4e580 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Event/Collection.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Event/Collection.php @@ -20,103 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Index_Model_Mysql4_Event_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - /** - * Initialize resource - */ - protected function _construct() - { - $this->_init('index/event'); - } - - /** - * Add filter by entity - * - * @param string | array $entity - * @return Mage_Index_Model_Mysql4_Event_Collection - */ - public function addEntityFilter($entity) - { - if (is_array($entity) && !empty($entity)) { - $this->getSelect()->where('entity IN (?)', $entity); - } else { - $this->getSelect()->where('entity = ?', $entity); - } - return $this; - } - - /** - * Add filter by type - * - * @param string | array $type - * @return Mage_Index_Model_Mysql4_Event_Collection - */ - public function addTypeFilter($type) - { - if (is_array($type) && !empty($type)) { - $this->getSelect()->where('type IN (?)', $type); - } else { - $this->getSelect()->where('type = ?', $type); - } - return $this; - } - - /** - * Add filter by process and status to events collection - * - * @param $process - * @param $status - * @return Mage_Index_Model_Mysql4_Event_Collection - */ - public function addProcessFilter($process, $status=null) - { - $this->_joinProcessEventTable(); - if ($process instanceof Mage_Index_Model_Process) { - $this->getSelect()->where('process_event.process_id = ?', $process->getId()); - } elseif (is_array($process) && !empty($process)) { - $this->getSelect()->where('process_event.process_id IN (?)', $process); - } else { - $this->getSelect()->where('process_event.process_id = ?', $process); - } - - if ($status !== null) { - $this->getSelect()->where('process_event.status = ?', $status); - } - return $this; - } - - /** - * Join index_process_event table to event table - * - * @return Mage_Index_Model_Mysql4_Event_Collection - */ - protected function _joinProcessEventTable() - { - if (!$this->getFlag('process_event_table_joined')) { - $this->getSelect()->join(array('process_event' => $this->getTable('index/process_event')), - 'process_event.event_id=main_table.event_id', - array('process_event_status' => 'status') - ); - $this->setFlag('process_event_table_joined', true); - } - return $this; - } - /** - * Reset collection state - * - * @return Mage_Index_Model_Mysql4_Event_Collection - */ - public function reset() - { - $this->_totalRecords = null; - $this->_data = null; - $this->_isCollectionLoaded = false; - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ +class Mage_Index_Model_Mysql4_Event_Collection extends Mage_Index_Model_Resource_Event_Collection +{ } diff --git a/app/code/core/Mage/Index/Model/Mysql4/Process.php b/app/code/core/Mage/Index/Model/Mysql4/Process.php index 4628b4e16f..81042aae11 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Process.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Process.php @@ -20,91 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Index_Model_Mysql4_Process extends Mage_Core_Model_Mysql4_Abstract -{ - /** - * Initialize table and table pk - */ - protected function _construct() - { - $this->_init('index/process', 'process_id'); - } - - /** - * Update process/event association row status - * - * @param int $processId - * @param int $eventId - * @param string $status - * @return Mage_Index_Model_Mysql4_Process - */ - public function updateEventStatus($processId, $eventId, $status) - { - $adapter = $this->_getWriteAdapter(); - $condition = $adapter->quoteInto('process_id = ? AND ', $processId) - . $adapter->quoteInto('event_id = ?', $eventId); - $adapter->update($this->getTable('index/process_event'), array('status' => $status), $condition); - return $this; - } - - /** - * Register process end - * - * @param Mage_Index_Model_Process $process - * @return Mage_Index_Model_Mysql4_Process - */ - public function endProcess(Mage_Index_Model_Process $process) - { - $data = array( - 'status' => Mage_Index_Model_Process::STATUS_PENDING, - 'ended_at' =>$this->formatDate(time()), - ); - $this->_getWriteAdapter()->update( - $this->getMainTable(), - $data, - $this->_getWriteAdapter()->quoteInto('process_id=?', $process->getId()) - ); - return $this; - } - /** - * Register process start - * - * @param Mage_Index_Model_Process $process - * @return Mage_Index_Model_Mysql4_Process - */ - public function startProcess(Mage_Index_Model_Process $process) - { - $data = array( - 'status' => Mage_Index_Model_Process::STATUS_RUNNING, - 'started_at'=>$this->formatDate(time()), - ); - $this->_getWriteAdapter()->update( - $this->getMainTable(), - $data, - $this->_getWriteAdapter()->quoteInto('process_id=?', $process->getId()) - ); - return $this; - } - /** - * Update process status field - * - * @param Mage_Index_Model_Process - * @param string status - * @return Mage_Index_Model_Mysql4_Process - */ - public function updateStatus($process, $status) - { - $data = array('status' => $status); - $this->_getWriteAdapter()->update( - $this->getMainTable(), - $data, - $this->_getWriteAdapter()->quoteInto('process_id=?', $process->getId()) - ); - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ +class Mage_Index_Model_Mysql4_Process extends Mage_Index_Model_Resource_Process +{ } diff --git a/app/code/core/Mage/Index/Model/Mysql4/Process/Collection.php b/app/code/core/Mage/Index/Model/Mysql4/Process/Collection.php index 953c47b20d..51b4bc66d5 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Process/Collection.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Process/Collection.php @@ -20,13 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Index_Model_Mysql4_Process_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ +class Mage_Index_Model_Mysql4_Process_Collection extends Mage_Index_Model_Resource_Process_Collection { - protected function _construct() - { - $this->_init('index/process'); - } } diff --git a/app/code/core/Mage/Index/Model/Mysql4/Setup.php b/app/code/core/Mage/Index/Model/Mysql4/Setup.php index 603ea87ba4..768e04c9ca 100644 --- a/app/code/core/Mage/Index/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Index/Model/Mysql4/Setup.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Index_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup -{ - /** - * Apply Index moduke DB updates and sync indexes declaration - */ - public function applyUpdates() - { - parent::applyUpdates(); - $this->_syncIndexes(); - } - - /** - * Sync indexes declarations in config and in DB - */ - protected function _syncIndexes() - { - $connection = $this->getConnection(); - if (!$connection) { - return $this; - } - $indexes = Mage::getConfig()->getNode(Mage_Index_Model_Process::XML_PATH_INDEXER_DATA); - $indexCodes = array(); - foreach ($indexes->children() as $code => $index) { - $indexCodes[] = $code; - } - $table = $this->getTable('index/process'); - $existingIndexes = $connection->fetchCol('SELECT indexer_code FROM '.$table); - $delete = array_diff($existingIndexes, $indexCodes); - $insert = array_diff($indexCodes, $existingIndexes); - if (!empty($delete)) { - $connection->delete($table, $connection->quoteInto('indexer_code IN (?)', $delete)); - } - if (!empty($insert)) { - $inserData = array(); - foreach ($insert as $code) { - $inserData[] = array( - 'indexer_code' => $code, - 'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX - ); - } - if (method_exists($connection, 'insertArray')) { - $connection->insertArray($table, array('indexer_code', 'status'), $inserData); - } - } - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ +class Mage_Index_Model_Mysql4_Setup extends Mage_Index_Model_Resource_Setup +{ } diff --git a/app/code/core/Mage/Index/Model/Observer.php b/app/code/core/Mage/Index/Model/Observer.php index a4184a7a9c..2f0e0bd806 100644 --- a/app/code/core/Mage/Index/Model/Observer.php +++ b/app/code/core/Mage/Index/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/Model/Process.php b/app/code/core/Mage/Index/Model/Process.php index b7ab106d66..afe0407d90 100644 --- a/app/code/core/Mage/Index/Model/Process.php +++ b/app/code/core/Mage/Index/Model/Process.php @@ -20,10 +20,30 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Index_Model_Resource_Process _getResource() + * @method Mage_Index_Model_Resource_Process getResource() + * @method string getIndexerCode() + * @method Mage_Index_Model_Process setIndexerCode(string $value) + * @method string getStatus() + * @method Mage_Index_Model_Process setStatus(string $value) + * @method string getStartedAt() + * @method Mage_Index_Model_Process setStartedAt(string $value) + * @method string getEndedAt() + * @method Mage_Index_Model_Process setEndedAt(string $value) + * @method string getMode() + * @method Mage_Index_Model_Process setMode(string $value) + * + * @category Mage + * @package Mage_Index + * @author Magento Core Team + */ class Mage_Index_Model_Process extends Mage_Core_Model_Abstract { const XML_PATH_INDEXER_DATA = 'global/index/indexer'; diff --git a/app/code/core/Mage/Index/Model/Resource/Abstract.php b/app/code/core/Mage/Index/Model/Resource/Abstract.php new file mode 100755 index 0000000000..a88ac0dbf0 --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Abstract.php @@ -0,0 +1,228 @@ + + */ +abstract class Mage_Index_Model_Resource_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + const IDX_SUFFIX= '_idx'; + const TMP_SUFFIX= '_tmp'; + + /** + * Flag that defines if need to use "_idx" index table suffix instead of "_tmp" + * + * @var bool + */ + protected $_isNeedUseIdxTable = false; + + /** + * Flag that defines if need to disable keys during data inserting + * + * @var bool + */ + protected $_isDisableKeys = true; + + /** + * Reindex all + * + * @return Mage_Index_Model_Resource_Abstract + */ + public function reindexAll() + { + $this->useIdxTable(true); + return $this; + } + + /** + * Get DB adapter for index data processing + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getIndexAdapter() + { + return $this->_getWriteAdapter(); + } + + /** + * Get index table name with additional suffix + * + * @param string $table + * @return string + */ + public function getIdxTable($table = null) + { + $suffix = self::TMP_SUFFIX; + if ($this->_isNeedUseIdxTable) { + $suffix = self::IDX_SUFFIX; + } + if ($table) { + return $table . $suffix; + } + return $this->getMainTable() . $suffix; + } + + /** + * Synchronize data between index storage and original storage + * + * @return Mage_Index_Model_Resource_Abstract + */ + public function syncData() + { + $this->beginTransaction(); + /** + * Can't use truncate because of transaction + */ + $this->_getWriteAdapter()->delete($this->getMainTable()); + $this->insertFromTable($this->getIdxTable(), $this->getMainTable(), false); + $this->commit(); + return $this; + } + + /** + * Create temporary table for index data pregeneration + * + * @deprecated since 1.5.0.0 + * @param bool $asOriginal + * @return Mage_Index_Model_Resource_Abstract + */ + public function cloneIndexTable($asOriginal = false) + { + return $this; + } + + /** + * Copy data from source table of read adapter to destination table of index adapter + * + * @param string $sourceTable + * @param string $destTable + * @param bool $readToIndex data migration direction (true - read=>index, false - index=>read) + * @return Mage_Index_Model_Resource_Abstract + */ + public function insertFromTable($sourceTable, $destTable, $readToIndex = true) + { + if ($readToIndex) { + $sourceColumns = array_keys($this->_getWriteAdapter()->describeTable($sourceTable)); + $targetColumns = array_keys($this->_getWriteAdapter()->describeTable($destTable)); + } else { + $sourceColumns = array_keys($this->_getIndexAdapter()->describeTable($sourceTable)); + $targetColumns = array_keys($this->_getWriteAdapter()->describeTable($destTable)); + } + $select = $this->_getIndexAdapter()->select()->from($sourceTable, $sourceColumns); + + return $this->insertFromSelect($select, $destTable, $targetColumns, $readToIndex); + } + + /** + * Insert data from select statement of read adapter to + * destination table related with index adapter + * + * @param Varien_Db_Select $select + * @param string $destTable + * @param array $columns + * @param bool $readToIndex data migration direction (true - read=>index, false - index=>read) + * @return Mage_Index_Model_Resource_Abstract + */ + public function insertFromSelect($select, $destTable, array $columns, $readToIndex = true) + { + if ($readToIndex) { + $from = $this->_getWriteAdapter(); + $to = $this->_getIndexAdapter(); + } else { + $from = $this->_getIndexAdapter(); + $to = $this->_getWriteAdapter(); + } + + if ($this->useDisableKeys()) { + $to->disableTableKeys($destTable); + } + if ($from === $to) { + $query = $select->insertFromSelect($destTable, $columns); + $to->query($query); + } else { + $stmt = $from->query($select); + $data = array(); + $counter = 0; + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { + $data[] = $row; + $counter++; + if ($counter>2000) { + $to->insertArray($destTable, $columns, $data); + $data = array(); + $counter = 0; + } + } + if (!empty($data)) { + $to->insertArray($destTable, $columns, $data); + } + } + if ($this->useDisableKeys()) { + $to->enableTableKeys($destTable); + } + return $this; + } + + /** + * Set or get what either "_idx" or "_tmp" suffixed temporary index table need to use + * + * @param bool $value + * @return bool + */ + public function useIdxTable($value = null) + { + if (!is_null($value)) { + $this->_isNeedUseIdxTable = (bool)$value; + } + return $this->_isNeedUseIdxTable; + } + + /** + * Set or get flag that defines if need to disable keys during data inserting + * + * @param bool $value + * @return bool + */ + public function useDisableKeys($value = null) + { + if (!is_null($value)) { + $this->_isDisableKeys = (bool)$value; + } + return $this->_isDisableKeys; + } + + /** + * Clean up temporary index table + * + */ + public function clearTemporaryIndexTable() + { + $this->_getWriteAdapter()->delete($this->getIdxTable()); + } +} diff --git a/app/code/core/Mage/Index/Model/Resource/Event.php b/app/code/core/Mage/Index/Model/Resource/Event.php new file mode 100755 index 0000000000..32aa54804e --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Event.php @@ -0,0 +1,99 @@ + + */ +class Mage_Index_Model_Resource_Event extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Enter description here ... + * + */ + protected function _construct() + { + $this->_init('index/event', 'event_id'); + } + + /** + * Check if semilar event exist before start saving data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Index_Model_Resource_Event + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + /** + * Check if event already exist and merge previous data + */ + if (!$object->getId()) { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable()) + ->where('type=?', $object->getType()) + ->where('entity=?', $object->getEntity()); + if ($object->hasEntityPk()) { + $select->where('entity_pk=?', $object->getEntityPk()); + } + $data = $this->_getWriteAdapter()->fetchRow($select); + if ($data) { + $object->mergePreviousData($data); + } + } + return parent::_beforeSave($object); + } + + /** + * Save assigned processes + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Index_Model_Resource_Event + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $processIds = $object->getProcessIds(); + if (is_array($processIds)) { + $processTable = $this->getTable('index/process_event'); + if (empty($processIds)) { + $this->_getWriteAdapter()->delete($processTable); + } else { + foreach ($processIds as $processId => $processStatus) { + $data = array( + 'process_id'=> $processId, + 'event_id' => $object->getId(), + 'status' => $processStatus + ); + $this->_getWriteAdapter()->insertOnDuplicate($processTable, $data, array('status')); + } + } + } + return parent::_afterSave($object); + } +} diff --git a/app/code/core/Mage/Index/Model/Resource/Event/Collection.php b/app/code/core/Mage/Index/Model/Resource/Event/Collection.php new file mode 100755 index 0000000000..3e998a2441 --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Event/Collection.php @@ -0,0 +1,131 @@ + + */ +class Mage_Index_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('index/event'); + } + + /** + * Add filter by entity + * + * @param string | array $entity + * @return Mage_Index_Model_Resource_Event_Collection + */ + public function addEntityFilter($entity) + { + if (is_array($entity) && !empty($entity)) { + $this->addFieldToFilter('entity', array('in'=>$entity)); + } else { + $this->addFieldToFilter('entity', $entity); + } + return $this; + } + + /** + * Add filter by type + * + * @param string | array $type + * @return Mage_Index_Model_Resource_Event_Collection + */ + public function addTypeFilter($type) + { + if (is_array($type) && !empty($type)) { + $this->addFieldToFilter('type', array('in'=>$type)); + } else { + $this->addFieldToFilter('type', $type); + } + return $this; + } + + /** + * Add filter by process and status to events collection + * + * @param int|array|Mage_Index_Model_Process $process + * @param string $status + * @return Mage_Index_Model_Resource_Event_Collection + */ + public function addProcessFilter($process, $status = null) + { + $this->_joinProcessEventTable(); + if ($process instanceof Mage_Index_Model_Process) { + $this->addFieldToFilter('process_event.process_id', $process->getId()); + } elseif (is_array($process) && !empty($process)) { + $this->addFieldToFilter('process_event.process_id', array('in'=>$process)); + } else { + $this->addFieldToFilter('process_event.process_id', $process); + } + + if ($status !== null) { + $this->addFieldToFilter('process_event.status', $status); + } + return $this; + } + + /** + * Join index_process_event table to event table + * + * @return Mage_Index_Model_Resource_Event_Collection + */ + protected function _joinProcessEventTable() + { + if (!$this->getFlag('process_event_table_joined')) { + $this->getSelect()->join(array('process_event' => $this->getTable('index/process_event')), + 'process_event.event_id=main_table.event_id', + array('process_event_status' => 'status') + ); + $this->setFlag('process_event_table_joined', true); + } + return $this; + } + + /** + * Reset collection state + * + * @return Mage_Index_Model_Resource_Event_Collection + */ + public function reset() + { + $this->_totalRecords = null; + $this->_data = null; + $this->_isCollectionLoaded = false; + return $this; + } +} diff --git a/app/code/core/Mage/Index/Model/Resource/Process.php b/app/code/core/Mage/Index/Model/Resource/Process.php new file mode 100755 index 0000000000..1b7554d566 --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Process.php @@ -0,0 +1,125 @@ + + */ +class Mage_Index_Model_Resource_Process extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize table and table pk + * + */ + protected function _construct() + { + $this->_init('index/process', 'process_id'); + } + + /** + * Update process/event association row status + * + * @param int $processId + * @param int $eventId + * @param string $status + * @return Mage_Index_Model_Resource_Process + */ + public function updateEventStatus($processId, $eventId, $status) + { + $adapter = $this->_getWriteAdapter(); + $condition = array( + 'process_id = ?' => $processId, + 'event_id = ?' => $eventId + ); + $adapter->update($this->getTable('index/process_event'), array('status' => $status), $condition); + return $this; + } + + /** + * Register process end + * + * @param Mage_Index_Model_Process $process + * @return Mage_Index_Model_Resource_Process + */ + public function endProcess(Mage_Index_Model_Process $process) + { + $data = array( + 'status' => Mage_Index_Model_Process::STATUS_PENDING, + 'ended_at' => $this->formatDate(time()), + ); + $this->_updateProcessData($process->getId(), $data); + return $this; + } + + /** + * Register process start + * + * @param Mage_Index_Model_Process $process + * @return Mage_Index_Model_Resource_Process + */ + public function startProcess(Mage_Index_Model_Process $process) + { + $data = array( + 'status' => Mage_Index_Model_Process::STATUS_RUNNING, + 'started_at' => $this->formatDate(time()), + ); + $this->_updateProcessData($process->getId(), $data); + return $this; + } + + /** + * Update process status field + * + * + * @param Mage_Index_Model_Process $process + * @param string $status + * @return Mage_Index_Model_Resource_Process + */ + public function updateStatus($process, $status) + { + $data = array('status' => $status); + $this->_updateProcessData($process->getId(), $data); + return $this; + } + + /** + * Updates process data + * @param int $processId + * @param array $data + * @return Mage_Index_Model_Resource_Process + */ + protected function _updateProcessData($processId,$data) + { + $bind = array('process_id=?' => $processId); + $this->_getWriteAdapter()->update($this->getMainTable(), $data, $bind); + + return $this; + } +} diff --git a/app/code/core/Mage/Index/Model/Resource/Process/Collection.php b/app/code/core/Mage/Index/Model/Resource/Process/Collection.php new file mode 100755 index 0000000000..3f3390daef --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Process/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Index_Model_Resource_Process_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('index/process'); + } +} diff --git a/app/code/core/Mage/Index/Model/Resource/Setup.php b/app/code/core/Mage/Index/Model/Resource/Setup.php new file mode 100755 index 0000000000..4eab0bcde1 --- /dev/null +++ b/app/code/core/Mage/Index/Model/Resource/Setup.php @@ -0,0 +1,86 @@ + + */ +class Mage_Index_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup +{ + /** + * Apply Index module DB updates and sync indexes declaration + * + * @return void + */ + public function applyUpdates() + { + parent::applyUpdates(); + $this->_syncIndexes(); + } + + /** + * Sync indexes declarations in config and in DB + * + * @return Mage_Index_Model_Resource_Setup + */ + protected function _syncIndexes() + { + $connection = $this->getConnection(); + if (!$connection) { + return $this; + } + $indexes = Mage::getConfig()->getNode(Mage_Index_Model_Process::XML_PATH_INDEXER_DATA); + $indexCodes = array(); + foreach ($indexes->children() as $code => $index) { + $indexCodes[] = $code; + } + $table = $this->getTable('index/process'); + $select = $connection->select()->from($table, 'indexer_code'); + $existingIndexes = $connection->fetchCol($select); + $delete = array_diff($existingIndexes, $indexCodes); + $insert = array_diff($indexCodes, $existingIndexes); + + if (!empty($delete)) { + $connection->delete($table, $connection->quoteInto('indexer_code IN (?)', $delete)); + } + if (!empty($insert)) { + $insertData = array(); + foreach ($insert as $code) { + $insertData[] = array( + 'indexer_code' => $code, + 'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX + ); + } + if (method_exists($connection, 'insertArray')) { + $connection->insertArray($table, array('indexer_code', 'status'), $insertData); + } + } + } +} diff --git a/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php b/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php index e609b5447a..dc0bfa1c04 100644 --- a/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php +++ b/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Index_Adminhtml_ProcessController extends Mage_Adminhtml_Controller_Action diff --git a/app/code/core/Mage/Index/etc/adminhtml.xml b/app/code/core/Mage/Index/etc/adminhtml.xml index b88464bf78..8bede62655 100644 --- a/app/code/core/Mage/Index/etc/adminhtml.xml +++ b/app/code/core/Mage/Index/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Index/etc/config.xml b/app/code/core/Mage/Index/etc/config.xml index 5c0a93ebdc..6dbe4f3d99 100644 --- a/app/code/core/Mage/Index/etc/config.xml +++ b/app/code/core/Mage/Index/etc/config.xml @@ -21,46 +21,49 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.2 + 1.6.0.0 Mage_Index_Model - index_mysql4 + index_resource - - Mage_Index_Model_Mysql4 + + Mage_Index_Model_Resource + index_mysql4 - index_event
      - index_process
      - index_process_event
      + + index_event
      +
      + + index_process
      +
      + + index_process_event
      +
      -
      +
      Mage_Index - Mage_Index_Model_Mysql4_Setup + Mage_Index_Model_Resource_Setup - + diff --git a/app/code/core/Mage/Index/sql/index_setup/install-1.6.0.0.php b/app/code/core/Mage/Index/sql/index_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..01e4a12d41 --- /dev/null +++ b/app/code/core/Mage/Index/sql/index_setup/install-1.6.0.0.php @@ -0,0 +1,124 @@ +startSetup(); + +/** + * Create table 'index/event' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('index/event')) + ->addColumn('event_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Event Id') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + ), 'Type') + ->addColumn('entity', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + ), 'Entity') + ->addColumn('entity_pk', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + ), 'Entity Primary Key') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Creation Time') + ->addColumn('old_data', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Old Data') + ->addColumn('new_data', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'New Data') + ->addIndex($installer->getIdxName('index/event', array('type', 'entity', 'entity_pk'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('type', 'entity', 'entity_pk'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Index Event'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'index/process' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('index/process')) + ->addColumn('process_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Process Id') + ->addColumn('indexer_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Indexer Code') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 15, array( + 'nullable' => false, + 'default' => 'pending', + ), 'Status') + ->addColumn('started_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Started At') + ->addColumn('ended_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Ended At') + ->addColumn('mode', Varien_Db_Ddl_Table::TYPE_TEXT, 9, array( + 'nullable' => false, + 'default' => 'real_time', + ), 'Mode') + ->addIndex($installer->getIdxName('index/process', array('indexer_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('indexer_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Index Process'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'index/process_event' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('index/process_event')) + ->addColumn('process_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Process Id') + ->addColumn('event_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Event Id') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 7, array( + 'nullable' => false, + 'default' => 'new', + ), 'Status') + ->addIndex($installer->getIdxName('index/process_event', array('event_id')), + array('event_id')) + ->addForeignKey($installer->getFkName('index/process_event', 'event_id', 'index/event', 'event_id'), + 'event_id', $installer->getTable('index/event'), 'event_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('index/process_event', 'process_id', 'index/process', 'process_id'), + 'process_id', $installer->getTable('index/process'), 'process_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Index Process Event'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Index/sql/index_setup/mysql4-install-1.4.0.0.php b/app/code/core/Mage/Index/sql/index_setup/mysql4-install-1.4.0.0.php index 0b38d6bbfa..afd875b49e 100644 --- a/app/code/core/Mage/Index/sql/index_setup/mysql4-install-1.4.0.0.php +++ b/app/code/core/Mage/Index/sql/index_setup/mysql4-install-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php index 785a0f00af..6f6d733beb 100644 --- a/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php +++ b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php index 086d0f240e..c64c0f6078 100644 --- a/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php +++ b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Index - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..f665567a63 --- /dev/null +++ b/app/code/core/Mage/Index/sql/index_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,235 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('index_process_event'), + 'FK_INDEX_EVNT_PROCESS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('index/process_event'), + 'FK_INDEX_PROCESS_EVENT' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('index/event'), + 'IDX_UNIQUE_EVENT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('index/process'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('index/process_event'), + 'FK_INDEX_EVNT_PROCESS' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('index/event') => array( + 'columns' => array( + 'event_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Event Id' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Type' + ), + 'entity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Entity' + ), + 'entity_pk' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'comment' => 'Entity Primary Key' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Creation Time' + ), + 'old_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Old Data' + ), + 'new_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'New Data' + ) + ), + 'comment' => 'Index Event' + ), + $installer->getTable('index/process') => array( + 'columns' => array( + 'process_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Process Id' + ), + 'indexer_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Indexer Code' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 15, + 'nullable' => false, + 'default' => 'pending', + 'comment' => 'Status' + ), + 'started_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Started At' + ), + 'ended_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Ended At' + ), + 'mode' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 9, + 'nullable' => false, + 'default' => 'real_time', + 'comment' => 'Mode' + ) + ), + 'comment' => 'Index Process' + ), + $installer->getTable('index/process_event') => array( + 'columns' => array( + 'process_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Process Id' + ), + 'event_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Event Id' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 7, + 'nullable' => false, + 'default' => 'new', + 'comment' => 'Status' + ) + ), + 'comment' => 'Index Process Event' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('index/event'), + $installer->getIdxName( + 'index/event', + array('type', 'entity', 'entity_pk'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('type', 'entity', 'entity_pk'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('index/process'), + $installer->getIdxName( + 'index/process', + array('indexer_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('indexer_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('index/process_event'), + $installer->getIdxName('index/process_event', array('event_id')), + array('event_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('index/process_event', 'event_id', 'index/event', 'event_id'), + $installer->getTable('index/process_event'), + 'event_id', + $installer->getTable('index/event'), + 'event_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('index/process_event', 'process_id', 'index/process', 'process_id'), + $installer->getTable('index/process_event'), + 'process_id', + $installer->getTable('index/process'), + 'process_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Install/Block/Abstract.php b/app/code/core/Mage/Install/Block/Abstract.php index 488ea683b9..7fa3b0ebf0 100644 --- a/app/code/core/Mage/Install/Block/Abstract.php +++ b/app/code/core/Mage/Install/Block/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/Admin.php b/app/code/core/Mage/Install/Block/Admin.php index 44a8e8ab7d..e1287ba268 100644 --- a/app/code/core/Mage/Install/Block/Admin.php +++ b/app/code/core/Mage/Install/Block/Admin.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/Begin.php b/app/code/core/Mage/Install/Block/Begin.php index 8d954baf18..47ef67ba32 100644 --- a/app/code/core/Mage/Install/Block/Begin.php +++ b/app/code/core/Mage/Install/Block/Begin.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/Config.php b/app/code/core/Mage/Install/Block/Config.php index 420db9a544..5dbf971163 100644 --- a/app/code/core/Mage/Install/Block/Config.php +++ b/app/code/core/Mage/Install/Block/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/Db/Main.php b/app/code/core/Mage/Install/Block/Db/Main.php new file mode 100644 index 0000000000..461c81b5e9 --- /dev/null +++ b/app/code/core/Mage/Install/Block/Db/Main.php @@ -0,0 +1,117 @@ + + */ +class Mage_Install_Block_Db_Main extends Mage_Core_Block_Template +{ + /** + * Array of Database blocks keyed by name + * + * @var array + */ + protected $_databases = array(); + + /** + * Adding customized database block template for database model type + * + * @param string $type database type + * @param string $block database block type + * @param string $template + * @return Mage_Install_Block_Db_Main + */ + public function addDatabaseBlock($type, $block, $template) + { + $this->_databases[$type] = array( + 'block' => $block, + 'template' => $template, + 'instance' => null + ); + + return $this; + } + + /** + * Retrieve database block by type + * + * @param string $type database model type + * @return bool | Mage_Core_Block_Template + */ + public function getDatabaseBlock($type) + { + $block = false; + if (isset($this->_databases[$type])) { + if ($this->_databases[$type]['instance']) { + $block = $this->_databases[$type]['instance']; + } else { + $block = $this->getLayout()->createBlock($this->_databases[$type]['block']) + ->setTemplate($this->_databases[$type]['template']) + ->setIdPrefix($type); + $this->_databases[$type]['instance'] = $block; + } + } + return $block; + } + + /** + * Retrieve database blocks + * + * @return array + */ + public function getDatabaseBlocks() + { + $databases = array(); + foreach ($this->_databases as $type => $blockData) { + $databases[] = $this->getDatabaseBlock($type); + } + return $databases; + } + + /** + * Retrieve configuration form data object + * + * @return Varien_Object + */ + public function getFormData() + { + $data = $this->getData('form_data'); + if (is_null($data)) { + $data = Mage::getSingleton('install/session')->getConfigData(true); + if (empty($data)) { + $data = Mage::getModel('install/installer_config')->getFormData(); + } + else { + $data = new Varien_Object($data); + } + $this->setFormData($data); + } + return $data; + } + +} diff --git a/app/code/core/Mage/Install/Block/Db/Type.php b/app/code/core/Mage/Install/Block/Db/Type.php new file mode 100644 index 0000000000..0263f49026 --- /dev/null +++ b/app/code/core/Mage/Install/Block/Db/Type.php @@ -0,0 +1,70 @@ + + */ +class Mage_Install_Block_Db_Type extends Mage_Core_Block_Template +{ + /** + * Db title + * + * @var string + */ + protected $_title = null; + + /** + * Return Db title + * + * @return string + */ + public function getTitle() + { + return $this->_title; + } + + /** + * Retrieve configuration form data object + * + * @return Varien_Object + */ + public function getFormData() + { + $data = $this->getData('form_data'); + if (is_null($data)) { + $data = Mage::getSingleton('install/session')->getConfigData(true); + if (empty($data)) { + $data = Mage::getModel('install/installer_config')->getFormData(); + } else { + $data = new Varien_Object($data); + } + $this->setFormData($data); + } + return $data; + } +} diff --git a/app/code/core/Mage/Install/Block/Db/Type/Mysql4.php b/app/code/core/Mage/Install/Block/Db/Type/Mysql4.php new file mode 100644 index 0000000000..e42bc05a6f --- /dev/null +++ b/app/code/core/Mage/Install/Block/Db/Type/Mysql4.php @@ -0,0 +1,40 @@ + + */ +class Mage_Install_Block_Db_Type_Mysql4 extends Mage_Install_Block_Db_Type +{ + /** + * Db title + * + * @var string + */ + protected $_title = 'Mysql'; +} diff --git a/app/code/core/Mage/Install/Block/Download.php b/app/code/core/Mage/Install/Block/Download.php index 729cf442f3..4497d72a81 100644 --- a/app/code/core/Mage/Install/Block/Download.php +++ b/app/code/core/Mage/Install/Block/Download.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/End.php b/app/code/core/Mage/Install/Block/End.php index b2dbed7d87..c216100552 100644 --- a/app/code/core/Mage/Install/Block/End.php +++ b/app/code/core/Mage/Install/Block/End.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -55,8 +55,7 @@ public function getEncryptionKey() public function getIframeSourceUrl() { if (!Mage_AdminNotification_Model_Survey::isSurveyUrlValid() - || Mage::getSingleton('install/installer')->getHideIframe()) - { + || Mage::getSingleton('install/installer')->getHideIframe()) { return null; } return Mage_AdminNotification_Model_Survey::getSurveyUrl(); diff --git a/app/code/core/Mage/Install/Block/Locale.php b/app/code/core/Mage/Install/Block/Locale.php index bd83de9db5..f643c633f3 100644 --- a/app/code/core/Mage/Install/Block/Locale.php +++ b/app/code/core/Mage/Install/Block/Locale.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Block/State.php b/app/code/core/Mage/Install/Block/State.php index 44ff2bcf8c..c5ae41a9ff 100644 --- a/app/code/core/Mage/Install/Block/State.php +++ b/app/code/core/Mage/Install/Block/State.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Controller/Action.php b/app/code/core/Mage/Install/Controller/Action.php index 8e50367498..31466a8d49 100644 --- a/app/code/core/Mage/Install/Controller/Action.php +++ b/app/code/core/Mage/Install/Controller/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Helper/Data.php b/app/code/core/Mage/Install/Helper/Data.php index 465cf2efb0..cfe36d6094 100644 --- a/app/code/core/Mage/Install/Helper/Data.php +++ b/app/code/core/Mage/Install/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Model/Config.php b/app/code/core/Mage/Install/Model/Config.php index 6ccc36001c..5ea19a7c99 100644 --- a/app/code/core/Mage/Install/Model/Config.php +++ b/app/code/core/Mage/Install/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -56,7 +56,7 @@ public function __construct() public function getWizardSteps() { $steps = array(); - foreach ((array)$this->getNode(self::XML_PATH_WIZARD_STEPS) as $stepName=>$step) { + foreach ((array)$this->getNode(self::XML_PATH_WIZARD_STEPS) as $stepName => $step) { $stepObject = new Varien_Object((array)$step); $stepObject->setName($stepName); $steps[] = $stepObject; @@ -101,10 +101,10 @@ public function getExtensionsForCheck() $res = array(); $items = (array) $this->getNode(self::XML_PATH_CHECK_EXTENSIONS); - foreach ($items as $name=>$value) { + foreach ($items as $name => $value) { if (!empty($value)) { $res[$name] = array(); - foreach ($value as $subname=>$subvalue) { + foreach ($value as $subname => $subvalue) { $res[$name][] = $subname; } } diff --git a/app/code/core/Mage/Install/Model/Installer.php b/app/code/core/Mage/Install/Model/Installer.php index 622b170512..607b2cbbf1 100644 --- a/app/code/core/Mage/Install/Model/Installer.php +++ b/app/code/core/Mage/Install/Model/Installer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -142,7 +142,9 @@ public function getServerCheckStatus() public function installConfig($data) { $data['db_active'] = true; - Mage::getSingleton('install/installer_db')->checkDatabase($data); + + $data = Mage::getSingleton('install/installer_db')->checkDbConnectionData($data); + Mage::getSingleton('install/installer_config') ->setConfigData($data) ->install(); @@ -246,7 +248,7 @@ public function createAdministrator($data) { $user = Mage::getModel('admin/user') ->load('admin', 'username'); - if ($user && $user->getPassword()=='4297f44b13955235245b2497399d7a93') { + if ($user && $user->getPassword() == '4297f44b13955235245b2497399d7a93') { $user->delete(); } @@ -320,7 +322,7 @@ public function finish() Mage::app()->cleanCache(); $cacheData = array(); - foreach (Mage::helper('core')->getCacheTypes() as $type=>$label) { + foreach (Mage::helper('core')->getCacheTypes() as $type => $label) { $cacheData[$type] = 1; } Mage::app()->saveUseCache($cacheData); diff --git a/app/code/core/Mage/Install/Model/Installer/Abstract.php b/app/code/core/Mage/Install/Model/Installer/Abstract.php index 1e384f5e4d..2b6d650777 100644 --- a/app/code/core/Mage/Install/Model/Installer/Abstract.php +++ b/app/code/core/Mage/Install/Model/Installer/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ * * @category Mage * @package Mage_Install - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Install_Model_Installer_Abstract { diff --git a/app/code/core/Mage/Install/Model/Installer/Config.php b/app/code/core/Mage/Install/Model/Installer/Config.php index d5d4274797..da0edfc988 100644 --- a/app/code/core/Mage/Install/Model/Installer/Config.php +++ b/app/code/core/Mage/Install/Model/Installer/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -46,7 +46,7 @@ class Mage_Install_Model_Installer_Config extends Mage_Install_Model_Installer_A public function __construct() { - $this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml'; + $this->_localConfigFile = Mage::getBaseDir('etc') . DS . 'local.xml'; } public function setConfigData($data) @@ -72,18 +72,18 @@ public function install() } if (isset($data['unsecure_base_url'])) { - $data['unsecure_base_url'] .= substr($data['unsecure_base_url'],-1) != '/' ? '/' : ''; + $data['unsecure_base_url'] .= substr($data['unsecure_base_url'], -1) != '/' ? '/' : ''; if (strpos($data['unsecure_base_url'], 'http') !== 0) { - $data['unsecure_base_url'] = 'http://'.$data['unsecure_base_url']; + $data['unsecure_base_url'] = 'http://' . $data['unsecure_base_url']; } if (!$this->_getInstaller()->getDataModel()->getSkipBaseUrlValidation()) { $this->_checkUrl($data['unsecure_base_url']); } } if (isset($data['secure_base_url'])) { - $data['secure_base_url'] .= substr($data['secure_base_url'],-1) != '/' ? '/' : ''; + $data['secure_base_url'] .= substr($data['secure_base_url'], -1) != '/' ? '/' : ''; if (strpos($data['secure_base_url'], 'http') !== 0) { - $data['secure_base_url'] = 'https://'.$data['secure_base_url']; + $data['secure_base_url'] = 'https://' . $data['secure_base_url']; } if (!empty($data['use_secure']) @@ -100,9 +100,9 @@ public function install() $this->_getInstaller()->getDataModel()->setConfigData($data); - $template = file_get_contents(Mage::getBaseDir('etc').DS.'local.xml.template'); - foreach ($data as $index=>$value) { - $template = str_replace('{{'.$index.'}}', '', $template); + $template = file_get_contents(Mage::getBaseDir('etc') . DS . 'local.xml.template'); + foreach ($data as $index => $value) { + $template = str_replace('{{' . $index . '}}', '', $template); } file_put_contents($this->_localConfigFile, $template); chmod($this->_localConfigFile, 0777); @@ -113,17 +113,21 @@ public function getFormData() $uri = Zend_Uri::factory(Mage::getBaseUrl('web')); $baseUrl = $uri->getUri(); - if ($uri->getScheme()!=='https') { + if ($uri->getScheme() !== 'https') { $uri->setPort(null); $baseSecureUrl = str_replace('http://', 'https://', $uri->getUri()); } else { $baseSecureUrl = $uri->getUri(); } + $connectDefault = Mage::getConfig() + ->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE); + $data = Mage::getModel('varien/object') - ->setDbHost('localhost') - ->setDbName('magento') - ->setDbUser('root') + ->setDbHost($connectDefault->host) + ->setDbName($connectDefault->dbname) + ->setDbUser($connectDefault->username) + ->setDbModel($connectDefault->model) ->setDbPass('') ->setSecureBaseUrl($baseSecureUrl) ->setUnsecureBaseUrl($baseUrl) @@ -135,9 +139,9 @@ public function getFormData() protected function _checkHostsInfo($data) { - $url = $data['protocol'] . '://' . $data['host'] . ':' . $data['port'] . $data['base_path']; - $surl= $data['secure_protocol'] . '://' . $data['secure_host'] . ':' - . $data['secure_port'] . $data['secure_base_path']; + $url = $data['protocol'] . '://' . $data['host'] . ':' . $data['port'] . $data['base_path']; + $surl = $data['secure_protocol'] . '://' . $data['secure_host'] . ':' . $data['secure_port'] + . $data['secure_base_path']; $this->_checkUrl($url); $this->_checkUrl($surl, true); @@ -145,22 +149,24 @@ protected function _checkHostsInfo($data) return $this; } - protected function _checkUrl($url, $secure=false) + protected function _checkUrl($url, $secure = false) { $prefix = $secure ? 'install/wizard/checkSecureHost/' : 'install/wizard/checkHost/'; try { - $client = new Varien_Http_Client($url.'index.php/'.$prefix); + $client = new Varien_Http_Client($url . 'index.php/' . $prefix); $response = $client->request('GET'); /* @var $responce Zend_Http_Response */ $body = $response->getBody(); } catch (Exception $e){ - $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('The URL "%s" is not accessible.', $url)); + $this->_getInstaller()->getDataModel() + ->addError(Mage::helper('install')->__('The URL "%s" is not accessible.', $url)); throw $e; } if ($body != Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE) { - $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('The URL "%s" is invalid.', $url)); + $this->_getInstaller()->getDataModel() + ->addError(Mage::helper('install')->__('The URL "%s" is invalid.', $url)); Mage::throwException(Mage::helper('install')->__('Response from server isn\'t valid.')); } return $this; diff --git a/app/code/core/Mage/Install/Model/Installer/Console.php b/app/code/core/Mage/Install/Model/Installer/Console.php index 0a93b2cf24..1753e49ddd 100644 --- a/app/code/core/Mage/Install/Model/Installer/Console.php +++ b/app/code/core/Mage/Install/Model/Installer/Console.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -75,6 +75,7 @@ protected function _getOptions() 'locale' => array('required' => true, 'comment' => ''), 'timezone' => array('required' => true, 'comment' => ''), 'default_currency' => array('required' => true, 'comment' => ''), + 'db_model' => array('comment' => ''), 'db_host' => array('required' => true, 'comment' => ''), 'db_name' => array('required' => true, 'comment' => ''), 'db_user' => array('required' => true, 'comment' => ''), @@ -143,7 +144,7 @@ public function setArgs($args = null) */ foreach ($this->_getOptions() as $name => $option) { if (isset($option['required']) && $option['required'] && !isset($args[$name])) { - $error = 'ERROR: ' . 'You should provide the value for --' . $name .' parameter'; + $error = 'ERROR: ' . 'You should provide the value for --' . $name . ' parameter'; if (!empty($option['comment'])) { $error .= ': ' . $option['comment']; } @@ -286,6 +287,7 @@ protected function _prepareData() * Database and web config */ $this->_getDataModel()->setConfigData(array( + 'db_model' => $this->_args['db_model'], 'db_host' => $this->_args['db_host'], 'db_name' => $this->_args['db_name'], 'db_user' => $this->_args['db_user'], @@ -310,7 +312,7 @@ protected function _prepareData() 'lastname' => $this->_args['admin_lastname'], 'email' => $this->_args['admin_email'], 'username' => $this->_args['admin_username'], - 'new_password' => $this->_args['admin_password'], + 'new_password' => $this->_args['admin_password'], )); return $this; @@ -353,7 +355,7 @@ public function install() /** * Install configuration */ - $installer->installConfig($this->_getDataModel()->getConfigData()); // TODO fix wizard and simplify this everythere + $installer->installConfig($this->_getDataModel()->getConfigData()); // TODO fix wizard and simplify this everywhere if ($this->hasErrors()) { return false; @@ -375,6 +377,9 @@ public function install() return false; } + // apply data updates + Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); + /** * Validate entered data for administrator user */ diff --git a/app/code/core/Mage/Install/Model/Installer/Data.php b/app/code/core/Mage/Install/Model/Installer/Data.php index 332782c4e0..0efb75fd65 100644 --- a/app/code/core/Mage/Install/Model/Installer/Data.php +++ b/app/code/core/Mage/Install/Model/Installer/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Model/Installer/Db.php b/app/code/core/Mage/Install/Model/Installer/Db.php index 697b3fe225..992d9dc1f3 100644 --- a/app/code/core/Mage/Install/Model/Installer/Db.php +++ b/app/code/core/Mage/Install/Model/Installer/Db.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,64 +33,160 @@ */ class Mage_Install_Model_Installer_Db extends Mage_Install_Model_Installer_Abstract { + /** + * @var database resource + */ + protected $_dbResource; + /** * Check database connection - * - * $data = array( - * [db_host] - * [db_name] - * [db_user] - * [db_pass] - * ) + * and return checked connection data * * @param array $data + * @return array */ - public function checkDatabase($data) + public function checkDbConnectionData($data) { - if (!isset($data['db_name']) || empty($data['db_name'])) { - Mage::throwException(Mage::helper('install')->__('Database Name cannot be empty.')); - } - $config = array( - 'host' => $data['db_host'], - 'username' => $data['db_user'], - 'password' => $data['db_pass'], - 'dbname' => $data['db_name'] - ); + $data = $this->_getCheckedData($data); try { - $connection = Mage::getSingleton('core/resource')->createConnection('install', $this->_getConnenctionType(), $config); - $variables = $connection->fetchPairs("SHOW VARIABLES"); + $dbModel = ($data['db_model']); - $version = isset($variables['version']) ? $variables['version'] : 'undefined'; - $match = array(); - if (preg_match("#^([0-9\.]+)#", $version, $match)) { - $version = $match[0]; + if (!$resource = $this->_getDbResource($dbModel)) { + Mage::throwException(Mage::helper('install')->__('No resource for %s DB model.', $dbModel)); } - $requiredVersion = (string)Mage::getSingleton('install/config')->getNode('check/mysql/version'); - // check MySQL Server version + $resource->setConfig($data); + + // check required extensions + $absenteeExtensions = array(); + $extensions = $resource->getRequiredExtensions(); + foreach ($extensions as $extName) { + if (!extension_loaded($extName)) { + $absenteeExtensions[] = $extName; + } + } + if (!empty($absenteeExtensions)) { + Mage::throwException(Mage::helper('install')->__('PHP Extensions "%s" must be loaded.', + implode(',', $absenteeExtensions)) + ); + } + + $version = $resource->getVersion(); + $requiredVersion = (string) Mage::getConfig() + ->getNode(sprintf('install/databases/%s/min_version', $dbModel)); + + // check DB server version if (version_compare($version, $requiredVersion) == -1) { - Mage::throwException(Mage::helper('install')->__('The database server version does not match system requirements (required: %s, actual: %s).', $requiredVersion, $version)); + Mage::throwException(Mage::helper('install')->__('The database server version ' + . 'does not match system requirements (required: %s, actual: %s).', $requiredVersion, $version)); } // check InnoDB support - if (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') { - Mage::throwException(Mage::helper('install')->__('Database server does not support the InnoDB storage engine.')); + if (!$resource->supportEngine()) { + Mage::throwException(Mage::helper('install')->__('Database server does not support ' + . 'the InnoDB storage engine.')); } + + // TODO: check user roles } - catch (Exception $e){ + catch (Mage_Core_Exception $e) { + Mage::logException($e); + Mage::throwException(Mage::helper('install')->__($e->getMessage())); + } + catch (Exception $e) { Mage::logException($e); Mage::throwException(Mage::helper('install')->__('Database connection error.')); } + + return $data; + } + + /** + * Check database connection data + * + * @param array $data + * @return array + */ + protected function _getCheckedData($data) + { + if (!isset($data['db_name']) || empty($data['db_name'])) { + Mage::throwException(Mage::helper('install')->__('Database Name cannot be empty.')); + } + //make all table prefix to lower letter + if ($data['db_prefix'] != '') { + $data['db_prefix'] = strtolower($data['db_prefix']); + } + //check table prefix + if ($data['db_prefix'] != '') { + if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $data['db_prefix'])) { + Mage::throwException( + Mage::helper('install')->__('The table prefix should contain only letters (a-z), ' + . 'numbers (0-9) or underscores (_), the first character should be a letter.')); + } + } + //set default db model + if (!isset($data['db_model']) || empty($data['db_model'])) { + $data['db_model'] = Mage::getConfig() + ->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE)->model; + } + //set db type according the db model + if (!isset($data['db_type'])) { + $data['db_type'] = (string) Mage::getConfig() + ->getNode(sprintf('install/databases/%s/type', $data['db_model'])); + } + + $dbResource = $this->_getDbResource($data['db_model']); + $data['db_pdo_type'] = $dbResource->getPdoType(); + + if (!isset($data['db_init_statemants'])) { + $data['db_init_statemants'] = (string) Mage::getConfig() + ->getNode(sprintf('install/databases/%s/initStatements', $data['db_model'])); + } + + return $data; + } + + /** + * Retrieve the database resource + * + * @param string $model database type + * @return Mage_Install_Model_Installer_Db_Abstract + */ + protected function _getDbResource($model) + { + if (!isset($this->_dbResource)) { + $resource = Mage::getSingleton(sprintf('install/installer_db_%s', $model)); + if (!$resource) { + Mage::throwException(Mage::helper('install')->__(sprintf('Installer does not exist for %s database type', $model))); + } + $this->_dbResource = $resource; + } + return $this->_dbResource; } /** * Retrieve Connection Type * * @return string + * + * @deprecated since 1.5.0.0 */ protected function _getConnenctionType() { return (string) Mage::getConfig()->getNode('global/resources/default_setup/connection/type'); } + + + /** + * Check database connection + * + * @param array $data + * + * @deprecated since 1.5.0.0 + */ + public function checkDatabase($data) + { + $this->checkDbConnectionData($data); + } } diff --git a/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php new file mode 100644 index 0000000000..2d2026ce19 --- /dev/null +++ b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php @@ -0,0 +1,158 @@ + + */ +abstract class Mage_Install_Model_Installer_Db_Abstract +{ + /** + * Adapter instance + * + * @var Varien_Db_Adapter_Interface + */ + protected $_connection; + + /** + * Connection configuration + * + * @var array + */ + protected $_connectionData; + + /** + * Connection configuration + * + * @var array + */ + protected $_configData; + + + /** + * Return the name of DB model from config + * + * @return string + */ + public function getModel() + { + return $this->_configData['db_model']; + } + + + /** + * Return the DB type from config + * + * @return string + */ + public function getType() + { + return $this->_configData['db_type']; + } + + /** + * Set configuration data + * + * @param array $config the connection configuration + */ + public function setConfig($config) + { + $this->_configData = $config; + } + + /** + * Retrieve connection data from config + * + * @return array + */ + public function getConnectionData() + { + if (!$this->_connectionData) { + $connectionData = array( + 'host' => $this->_configData['db_host'], + 'username' => $this->_configData['db_user'], + 'password' => $this->_configData['db_pass'], + 'dbname' => $this->_configData['db_name'], + 'pdoType' => $this->getPdoType() + ); + $this->_connectionData = $connectionData; + } + return $this->_connectionData; + } + + /** + * Check InnoDB support + * + * @return bool + */ + public function supportEngine() + { + return true; + } + + /** + * Create new connection with custom config + * + * @return Varien_Db_Adapter_Interface + */ + protected function _getConnection() + { + if (!isset($this->_connection)) { + $resource = Mage::getSingleton('core/resource'); + $connection = $resource->createConnection('install', $this->getType(), $this->getConnectionData()); + $this->_connection = $connection; + } + return $this->_connection; + } + + /** + * Return pdo type + * + * @return null + */ + public function getPdoType() + { + return null; + } + + /** + * Retrieve required PHP extension list for database + * + * @return array + */ + public function getRequiredExtensions() + { + $extensions = array(); + $configExt = (array)Mage::getConfig()->getNode(sprintf('install/databases/%s/extensions', $this->getModel())); + foreach ($configExt as $name=>$value) { + $extensions[] = $name; + } + return $extensions; + } +} diff --git a/app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php b/app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php new file mode 100644 index 0000000000..4ef7e60068 --- /dev/null +++ b/app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php @@ -0,0 +1,65 @@ + + */ +class Mage_Install_Model_Installer_Db_Mysql4 extends Mage_Install_Model_Installer_Db_Abstract +{ + /** + * Retrieve DB server version + * + * @return string (string version number | 'undefined') + */ + public function getVersion() + { + $version = $this->_getConnection() + ->fetchOne('SELECT VERSION()'); + $version = $version ? $version : 'undefined'; + $match = array(); + if (preg_match("#^([0-9\.]+)#", $version, $match)) { + $version = $match[0]; + } + return $version; + } + + /** + * Check InnoDB support + * + * @return bool + */ + public function supportEngine() + { + $variables = $this->_getConnection() + ->fetchPairs('SHOW VARIABLES'); + return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true; + } +} diff --git a/app/code/core/Mage/Install/Model/Installer/Env.php b/app/code/core/Mage/Install/Model/Installer/Env.php index 76cc1e1e12..09360b8aaa 100644 --- a/app/code/core/Mage/Install/Model/Installer/Env.php +++ b/app/code/core/Mage/Install/Model/Installer/Env.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -75,10 +75,10 @@ protected function _checkExtension($extension) return false; } } - elseif(!extension_loaded($extension)) { - Mage::getSingleton('install/session')->addError( - Mage::helper('install')->__('PHP extension "%s" must be loaded.', $extension) - ); + elseif (!extension_loaded($extension)) { + Mage::getSingleton('install/session')->addError( + Mage::helper('install')->__('PHP extension "%s" must be loaded.', $extension) + ); return false; } else { diff --git a/app/code/core/Mage/Install/Model/Installer/Filesystem.php b/app/code/core/Mage/Install/Model/Installer/Filesystem.php index 2d8c0f3751..3ae5a88e67 100644 --- a/app/code/core/Mage/Install/Model/Installer/Filesystem.php +++ b/app/code/core/Mage/Install/Model/Installer/Filesystem.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -85,7 +85,7 @@ protected function _checkFilesystem() protected function _checkPath($path, $recursive, $existence, $mode) { $res = true; - $fullPath = dirname(Mage::getRoot()).$path; + $fullPath = dirname(Mage::getRoot()) . $path; if ($mode == self::MODE_WRITE) { $setError = false; if ($existence) { @@ -110,7 +110,7 @@ protected function _checkPath($path, $recursive, $existence, $mode) if ($recursive && is_dir($fullPath)) { foreach (new DirectoryIterator($fullPath) as $file) { if (!$file->isDot() && $file->getFilename() != '.svn' && $file->getFilename() != '.htaccess') { - $res = $res && $this->_checkPath($path.DS.$file->getFilename(), $recursive, $existence, $mode); + $res = $res && $this->_checkPath($path . DS . $file->getFilename(), $recursive, $existence, $mode); } } } diff --git a/app/code/core/Mage/Install/Model/Installer/Pear.php b/app/code/core/Mage/Install/Model/Installer/Pear.php index 04f31949a8..65ebae8227 100644 --- a/app/code/core/Mage/Install/Model/Installer/Pear.php +++ b/app/code/core/Mage/Install/Model/Installer/Pear.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Model/Observer.php b/app/code/core/Mage/Install/Model/Observer.php index caca2cf104..3d3df06d98 100644 --- a/app/code/core/Mage/Install/Model/Observer.php +++ b/app/code/core/Mage/Install/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Model/Session.php b/app/code/core/Mage/Install/Model/Session.php index a0fcfa2b7a..1911d3822c 100644 --- a/app/code/core/Mage/Install/Model/Session.php +++ b/app/code/core/Mage/Install/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/Model/Wizard.php b/app/code/core/Mage/Install/Model/Wizard.php index 91f7f2c4d2..50f9715909 100644 --- a/app/code/core/Mage/Install/Model/Wizard.php +++ b/app/code/core/Mage/Install/Model/Wizard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -49,20 +49,20 @@ public function __construct() $this->_getUrl($this->_steps[$index]->getController(), $this->_steps[$index]->getAction()) ); - if (isset($this->_steps[$index+1])) { + if (isset($this->_steps[$index + 1])) { $this->_steps[$index]->setNextUrl( - $this->_getUrl($this->_steps[$index+1]->getController(), $this->_steps[$index+1]->getAction()) + $this->_getUrl($this->_steps[$index + 1]->getController(), $this->_steps[$index + 1]->getAction()) ); $this->_steps[$index]->setNextUrlPath( - $this->_getUrlPath($this->_steps[$index+1]->getController(), $this->_steps[$index+1]->getAction()) + $this->_getUrlPath($this->_steps[$index + 1]->getController(), $this->_steps[$index + 1]->getAction()) ); } - if (isset($this->_steps[$index-1])) { + if (isset($this->_steps[$index - 1])) { $this->_steps[$index]->setPrevUrl( - $this->_getUrl($this->_steps[$index-1]->getController(), $this->_steps[$index-1]->getAction()) + $this->_getUrl($this->_steps[$index - 1]->getController(), $this->_steps[$index - 1]->getAction()) ); $this->_steps[$index]->setPrevUrlPath( - $this->_getUrlPath($this->_steps[$index-1]->getController(), $this->_steps[$index-1]->getAction()) + $this->_getUrlPath($this->_steps[$index - 1]->getController(), $this->_steps[$index - 1]->getAction()) ); } } @@ -77,7 +77,8 @@ public function __construct() public function getStepByRequest(Zend_Controller_Request_Abstract $request) { foreach ($this->_steps as $step) { - if ($step->getController() == $request->getControllerName() && $step->getAction() == $request->getActionName()) { + if ($step->getController() == $request->getControllerName() + && $step->getAction() == $request->getActionName()) { return $step; } } @@ -124,6 +125,6 @@ protected function _getUrl($controller, $action) */ protected function _getUrlPath($controller, $action) { - return 'install/'.$controller.'/'.$action; + return 'install/' . $controller . '/' . $action; } } diff --git a/app/code/core/Mage/Install/controllers/IndexController.php b/app/code/core/Mage/Install/controllers/IndexController.php index 36ea18195c..08d8fb20eb 100644 --- a/app/code/core/Mage/Install/controllers/IndexController.php +++ b/app/code/core/Mage/Install/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Install/controllers/WizardController.php b/app/code/core/Mage/Install/controllers/WizardController.php index ec502d341f..8756974e41 100644 --- a/app/code/core/Mage/Install/controllers/WizardController.php +++ b/app/code/core/Mage/Install/controllers/WizardController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -234,11 +234,11 @@ public function downloadAutoAction() public function installAction() { $pear = Varien_Pear::getInstance(); - $params = array('comment'=>Mage::helper('install')->__("Downloading and installing Magento, please wait...")."\r\n\r\n"); + $params = array('comment'=>Mage::helper('install')->__("Downloading and installing Magento, please wait...") . "\r\n\r\n"); if ($this->getRequest()->getParam('do')) { if ($state = $this->getRequest()->getParam('state', 'beta')) { $result = $pear->runHtmlConsole(array( - 'comment' => Mage::helper('install')->__("Setting preferred state to: %s", $state)."\r\n\r\n", + 'comment' => Mage::helper('install')->__("Setting preferred state to: %s", $state) . "\r\n\r\n", 'command' => 'config-set', 'params' => array('preferred_state', $state) )); @@ -309,23 +309,18 @@ public function configPostAction() $this->_checkIfInstalled(); $step = $this->_getWizard()->getStepByName('config'); - if ($data = $this->getRequest()->getPost('config')) { - //make all table prefix to lower letter - if ($data['db_prefix'] !='') { - $data['db_prefix'] = strtolower($data['db_prefix']); - } + $config = $this->getRequest()->getPost('config'); + $connectionConfig = $this->getRequest()->getPost('connection'); + + if ($config && $connectionConfig && isset($connectionConfig[$config['db_model']])) { + + $data = array_merge($config, $connectionConfig[$config['db_model']]); Mage::getSingleton('install/session') ->setConfigData($data) ->setSkipUrlValidation($this->getRequest()->getPost('skip_url_validation')) ->setSkipBaseUrlValidation($this->getRequest()->getPost('skip_base_url_validation')); try { - if($data['db_prefix']!='') { - if(!preg_match('/^[a-z]+[a-z0-9_]*$/',$data['db_prefix'])) { - Mage::throwException( - Mage::helper('install')->__('The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter.')); - } - } $this->_getInstaller()->installConfig($data); $this->_redirect('*/*/installDb'); return $this; @@ -363,7 +358,7 @@ public function installDbAction() } /** - * Install admininstrator account + * Install administrator account */ public function administratorAction() { diff --git a/app/code/core/Mage/Install/etc/config.xml b/app/code/core/Mage/Install/etc/config.xml index 70e26ba983..19278abd80 100644 --- a/app/code/core/Mage/Install/etc/config.xml +++ b/app/code/core/Mage/Install/etc/config.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -35,14 +35,17 @@ Mage_Install_Model - install_mysql4 + install_resource - - Mage_Install_Model_Mysql4 - + + Mage_Install_Model_Resource + install_mysql4 + - Mage_Install_Block + + Mage_Install_Block +
      @@ -60,9 +63,21 @@ + + + pdo_mysql + SET NAMES utf8 + 4.1.20 + + + + + -
      main.xml
      +
      + main.xml +
      diff --git a/app/code/core/Mage/Install/etc/install.xml b/app/code/core/Mage/Install/etc/install.xml index f3c73e88be..7be419507d 100644 --- a/app/code/core/Mage/Install/etc/install.xml +++ b/app/code/core/Mage/Install/etc/install.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Install - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -80,7 +80,6 @@ - @@ -89,8 +88,5 @@ - - 4.1.20 -
      diff --git a/app/code/core/Mage/Log/Helper/Data.php b/app/code/core/Mage/Log/Helper/Data.php index 7a84c6611b..3e373039a1 100644 --- a/app/code/core/Mage/Log/Helper/Data.php +++ b/app/code/core/Mage/Log/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/Model/Aggregation.php b/app/code/core/Mage/Log/Model/Aggregation.php index b27f194878..11a0941052 100644 --- a/app/code/core/Mage/Log/Model/Aggregation.php +++ b/app/code/core/Mage/Log/Model/Aggregation.php @@ -20,40 +20,74 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Log Aggregation Model + * + * @method Mage_Log_Model_Resource_Aggregation getResource() + * @method Mage_Log_Model_Resource_Aggregation _getResource() + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team + */ class Mage_Log_Model_Aggregation extends Mage_Core_Model_Abstract { + + /** + * Last record data + * + * @var string + */ + protected $_lastRecord; + + /** + * Init model + */ protected function _construct() { $this->_init('log/aggregation'); } + /** + * Run action + */ public function run() { $this->_lastRecord = $this->_timestamp($this->_round($this->getLastRecordDate())); - $stores = Mage::getResourceModel('core/store_collection'); - - foreach ($stores as $store) { + foreach (Mage::app()->getStores(false) as $store) { $this->_process($store->getId()); } } - private function _removeEmpty($last) + /** + * Remove empty records before $lastDate + * + * @param string $lastDate + * @return void + */ + private function _removeEmpty($lastDate) { - return $this->_getResource()->removeEmpty($last); + return $this->_getResource()->removeEmpty($lastDate); } + /** + * Process + * + * @param int $store + * @return mixed + */ private function _process($store) { $lastDateRecord = null; - $start = $this->_lastRecord; - $end = time(); - $date = $start; + $start = $this->_lastRecord; + $end = time(); + $date = $start; - while($date < $end){ + while ($date < $end) { $to = $date + 3600; $counts = $this->_getCounts($this->_date($date), $this->_date($to), $store); $data = array( @@ -68,11 +102,18 @@ private function _process($store) } $lastDateRecord = $date; - $date = $to; + $date = $to; } return $lastDateRecord; } + /** + * Save log data + * + * @param array $data + * @param string $from + * @param string $to + */ private function _save($data, $from, $to) { if ($logId = $this->_getResource()->getLogId($from, $to)) { @@ -122,6 +163,10 @@ private function _timestamp($in, $offset = null) return $out; } + /** + * @param $in + * @return string + */ private function _round($in) { return date("Y-m-d H:00:00", $this->_timestamp($in)); diff --git a/app/code/core/Mage/Log/Model/Cron.php b/app/code/core/Mage/Log/Model/Cron.php index 2a4a89ca9c..1094a01376 100644 --- a/app/code/core/Mage/Log/Model/Cron.php +++ b/app/code/core/Mage/Log/Model/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/Model/Customer.php b/app/code/core/Mage/Log/Model/Customer.php index 297a1886ec..74698f91d5 100644 --- a/app/code/core/Mage/Log/Model/Customer.php +++ b/app/code/core/Mage/Log/Model/Customer.php @@ -20,36 +20,69 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer log model * - * @category Mage - * @package Mage_Log + * @method Mage_Log_Model_Resource_Customer _getResource() + * @method Mage_Log_Model_Resource_Customer getResource() + * @method int getVisitorId() + * @method Mage_Log_Model_Customer setVisitorId(int $value) + * @method int getCustomerId() + * @method Mage_Log_Model_Customer setCustomerId(int $value) + * @method string getLoginAt() + * @method Mage_Log_Model_Customer setLoginAt(string $value) + * @method string getLogoutAt() + * @method Mage_Log_Model_Customer setLogoutAt(string $value) + * @method int getStoreId() + * @method Mage_Log_Model_Customer setStoreId(int $value) + * + * @category Mage + * @package Mage_Log * @author Magento Core Team */ class Mage_Log_Model_Customer extends Mage_Core_Model_Abstract { - public function __construct() + /** + * Define resource model + * + */ + protected function _construct() { - parent::__construct(); - $this->_setResourceModel('log/customer'); + parent::_construct(); + $this->_init('log/customer'); } - public function load($customerId, $field=null) + /** + * Load last log by customer id + * + * @param Mage_Customer_Model_Customer|int $customer + * @return Mage_Log_Model_Customer + */ + public function loadByCustomer($customer) { - $this->_getResource()->load($this, $customerId); - return $this; + if ($customer instanceof Mage_Customer_Model_Customer) { + $customer = $customer->getId(); + } + + return $this->load($customer, 'customer_id'); } + /** + * Return last login at in Unix time format + * + * @return int + */ public function getLoginAtTimestamp() { - if ($date = $this->getLoginAt()) { - return strtotime($date); + $loginAt = $this->getLoginAt(); + if ($loginAt) { + return Varien_Date::toTimestamp($loginAt); } + return null; } } diff --git a/app/code/core/Mage/Log/Model/Log.php b/app/code/core/Mage/Log/Model/Log.php index 0bdbac89e2..811f25f52e 100644 --- a/app/code/core/Mage/Log/Model/Log.php +++ b/app/code/core/Mage/Log/Model/Log.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,22 @@ /** * Log Model * - * @category Mage - * @package Mage_Log - * @author Magento Core Team + * @method Mage_Log_Model_Resource_Log _getResource() + * @method Mage_Log_Model_Resource_Log getResource() + * @method string getSessionId() + * @method Mage_Log_Model_Log setSessionId(string $value) + * @method string getFirstVisitAt() + * @method Mage_Log_Model_Log setFirstVisitAt(string $value) + * @method string getLastVisitAt() + * @method Mage_Log_Model_Log setLastVisitAt(string $value) + * @method int getLastUrlId() + * @method Mage_Log_Model_Log setLastUrlId(int $value) + * @method int getStoreId() + * @method Mage_Log_Model_Log setStoreId(int $value) + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team */ class Mage_Log_Model_Log extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Log/Model/Mysql4/Aggregation.php b/app/code/core/Mage/Log/Model/Mysql4/Aggregation.php index 9f817e11cb..2591a9cb6e 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Aggregation.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Aggregation.php @@ -20,81 +20,18 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Log_Model_Mysql4_Aggregation extends Mage_Core_Model_Mysql4_Abstract -{ - public function _construct() - { - $this->_init('log/summary_table', 'log_summary_id'); - } - - public function getLastRecordDate() - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('summary_table'), array('date'=>'MAX(add_date)')); - - return $this->_getReadAdapter()->fetchOne($select); - } - - public function getCounts($from, $to, $store) - { - $result = array('customers'=>0, 'visitors'=>0); - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('customer'), 'visitor_id') - ->where('login_at >= ?', $from) - ->where('login_at <= ?', $to); - if ($store) { - $select->where('store_id = ?', $store); - } - - $customers = $this->_getReadAdapter()->fetchCol($select); - $result['customers'] = count($customers); - - - $select = $this->_getReadAdapter()->select(); - $select->from($this->getTable('visitor'), 'COUNT(*)') - ->where('first_visit_at >= ?', $from) - ->where('first_visit_at <= ?', $to); - - if ($store) { - $select->where('store_id = ?', $store); - } - if ($result['customers']) { - $select->where('visitor_id NOT IN(?)', $customers); - } - - $result['visitors'] = $this->_getReadAdapter()->fetchOne($select); - - return $result; - } - - public function saveLog($data, $id = null) - { - if (is_null($id)) { - $this->_getWriteAdapter()->insert($this->getTable('summary_table'), $data); - } else { - $condition = $this->_getWriteAdapter()->quoteInto('summary_id = ?', $id); - $this->_getWriteAdapter()->update($this->getTable('summary_table'), $data, $condition); - } - } - - public function removeEmpty($date) - { - $condition = $this->_getWriteAdapter()->quoteInto('add_date < ? AND customer_count = 0 AND visitor_count = 0', $date); - $this->_getWriteAdapter()->delete($this->getTable('summary_table'), $condition); - } - - public function getLogId($from, $to) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('summary_table'), 'summary_id') - ->where('add_date >= ?', $from) - ->where('add_date <= ?', $to); - - return $this->_getReadAdapter()->fetchOne($select); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team + */ +class Mage_Log_Model_Mysql4_Aggregation extends Mage_Log_Model_Resource_Aggregation +{ } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Customer.php b/app/code/core/Mage/Log/Model/Mysql4/Customer.php index a9bffb0426..026b13b8ba 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Customer.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Customer.php @@ -20,102 +20,18 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customer log resource * - * @category Mage - * @package Mage_Log + * @category Mage + * @package Mage_Log * @author Magento Core Team */ - -class Mage_Log_Model_Mysql4_Customer +class Mage_Log_Model_Mysql4_Customer extends Mage_Log_Model_Resource_Customer { - /** - * Visitor data table name - * - * @var string - */ - protected $_visitorTable; - - /** - * Visitor info data table - * - * @var string - */ - protected $_visitorInfoTable; - - /** - * Customer data table - * - * @var string - */ - protected $_customerTable; - - /** - * Url info data table - * - * @var string - */ - protected $_urlInfoTable; - - /** - * Log URL data table name. - * - * @var string - */ - protected $_urlTable; - - /** - * Log quote data table name. - * - * @var string - */ - protected $_quoteTable; - - /** - * Database read connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_read; - - /** - * Database write connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_write; - - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - - $this->_visitorTable = $resource->getTableName('log/visitor'); - $this->_visitorInfoTable= $resource->getTableName('log/visitor_info'); - $this->_urlTable = $resource->getTableName('log/url_table'); - $this->_urlInfoTable = $resource->getTableName('log/url_info_table'); - $this->_customerTable = $resource->getTableName('log/customer'); - $this->_quoteTable = $resource->getTableName('log/quote_table'); - - $this->_read = $resource->getConnection('log_read'); - $this->_write = $resource->getConnection('log_write'); - } - - public function load($object, $customerId) - { - $select = $this->_read->select(); - $select->from($this->_customerTable, array('login_at', 'logout_at')) - ->joinInner($this->_visitorTable, $this->_visitorTable.'.visitor_id='.$this->_customerTable.'.visitor_id', array('last_visit_at')) - ->joinInner($this->_visitorInfoTable, $this->_visitorTable.'.visitor_id='.$this->_visitorInfoTable.'.visitor_id', array('http_referer', 'remote_addr')) - ->joinInner($this->_urlInfoTable, $this->_urlInfoTable.'.url_id='.$this->_visitorTable.'.last_url_id', array('url')) - ->where($this->_read->quoteInto($this->_customerTable.'.customer_id=?', $customerId)) - ->order($this->_customerTable.'.login_at desc') - ->limit(1); - $object->setData($this->_read->fetchRow($select)); - return $object; - } } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Log.php b/app/code/core/Mage/Log/Model/Mysql4/Log.php index 7076515f55..137a7be2ae 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Log.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Log.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,243 +28,10 @@ /** * Log Resource Model * - * @category Mage - * @package Mage_Log - * @author Magento Core Team + * @category Mage + * @package Mage_Log + * @author Magento Core Team */ -class Mage_Log_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract +class Mage_Log_Model_Mysql4_Log extends Mage_Log_Model_Resource_Log { - /** - * Init Resource model and connection - * - */ - protected function _construct() - { - $this->_init('log/visitor', 'visitor_id'); - } - - /** - * Clean logs - * - * @param Mage_Log_Model_Log $object - * @return Mage_Log_Model_Mysql4_Log - */ - public function clean(Mage_Log_Model_Log $object) - { - $cleanTime = $object->getLogCleanTime(); - - Mage::dispatchEvent('log_log_clean_before', array( - 'log' => $object - )); - - $this->_cleanVisitors($cleanTime); - $this->_cleanCustomers($cleanTime); - $this->_cleanUrls(); - - Mage::dispatchEvent('log_log_clean_after', array( - 'log' => $object - )); - - return $this; - } - - /** - * Clean visitors table - * - * @param int $time - * @return Mage_Log_Model_Mysql4_Log - */ - protected function _cleanVisitors($time) - { - while (true) { - $select = $this->_getReadAdapter()->select() - ->from( - array('visitor_table' => $this->getTable('log/visitor')), - array('visitor_id' => 'visitor_table.visitor_id')) - ->joinLeft( - array('customer_table' => $this->getTable('log/customer')), - 'visitor_table.visitor_id = customer_table.visitor_id AND customer_table.log_id IS NULL', - array()) - ->where('visitor_table.last_visit_at < ?', gmdate('Y-m-d H:i:s', time() - $time)) - ->limit(100); - - $query = $this->_getReadAdapter()->query($select); - $visitorIds = array(); - while ($row = $query->fetch()) { - $visitorIds[] = $row['visitor_id']; - } - - if (!$visitorIds) { - break; - } - - // remove visitors from log/quote - $this->_getWriteAdapter()->delete( - $this->getTable('log/quote_table'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/url - $this->_getWriteAdapter()->delete( - $this->getTable('log/url_table'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/visitor_info - $this->_getWriteAdapter()->delete( - $this->getTable('log/visitor_info'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/visitor - $this->_getWriteAdapter()->delete( - $this->getTable('log/visitor'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - } - - return $this; - } - - /** - * Clean customer table - * - * @param int $time - * @return Mage_Log_Model_Mysql4_Log - */ - protected function _cleanCustomers($time) - { - // retrieve last active customer log id - $row = $this->_getReadAdapter()->fetchRow( - $this->_getReadAdapter()->select() - ->from($this->getTable('log/customer'), 'log_id') - ->where('login_at < ?', gmdate('Y-m-d H:i:s', time() - $time)) - ->order('log_id DESC') - ->limit(1) - ); - - if (!$row) { - return $this; - } - - $lastLogId = $row['log_id']; - - // Order by desc log_id before grouping (within-group aggregates query pattern) - $select = $this->_getReadAdapter()->select() - ->from( - array('log_customer_main' => $this->getTable('log/customer')), - array('log_id')) - ->joinLeft( - array('log_customer' => $this->getTable('log/customer')), - 'log_customer_main.customer_id = log_customer.customer_id AND log_customer_main.log_id < log_customer.log_id', - array()) - ->where('log_customer.customer_id IS NULL') - ->where('log_customer_main.log_id_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $needLogIds[$row['log_id']] = 1; - } - - $customerLogId = 0; - while (true) { - $visitorIds = array(); - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('log/customer'), - array('log_id', 'visitor_id')) - ->where('log_id>?', $customerLogId) - ->where('log_idorder('log_id') - ->limit(100); - - $query = $this->_getReadAdapter()->query($select); - $count = 0; - while ($row = $query->fetch()) { - $count++; - $customerLogId = $row['log_id']; - if (!isset($needLogIds[$row['log_id']])) { - $visitorIds[] = $row['visitor_id']; - } - } - - if (!$count) { - break; - } - - if ($visitorIds) { - // remove visitors from log/quote - $this->_getWriteAdapter()->delete( - $this->getTable('log/quote_table'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/url - $this->_getWriteAdapter()->delete( - $this->getTable('log/url_table'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/visitor_info - $this->_getWriteAdapter()->delete( - $this->getTable('log/visitor_info'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove visitors from log/visitor - $this->_getWriteAdapter()->delete( - $this->getTable('log/visitor'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - - // remove customers from log/customer - $this->_getWriteAdapter()->delete( - $this->getTable('log/customer'), - $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) - ); - } - - if ($customerLogId == $lastLogId) { - break; - } - } - - return $this; - } - - /** - * Clean url table - * - * @return Mage_Log_Model_Mysql4_Log - */ - protected function _cleanUrls() - { - while (true) { - $urlIds = array(); - $select = $this->_getReadAdapter()->select() - ->from( - array('url_info_table' => $this->getTable('log/url_info_table')), - array('url_id')) - ->joinLeft( - array('url_table' => $this->getTable('log/url_table')), - 'url_info_table.url_id = url_table.url_id', - array()) - ->where('url_table.url_id IS NULL') - ->limit(100); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $urlIds[] = $row['url_id']; - } - - if (!$urlIds) { - break; - } - - $this->_getWriteAdapter()->delete( - $this->getTable('log/url_info_table'), - $this->_getWriteAdapter()->quoteInto('url_id IN(?)', $urlIds) - ); - } - } } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor.php index c9c49e406e..0462f5a156 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Visitor.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor.php @@ -20,198 +20,18 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Visitor log resource * - * @category Mage - * @package Mage_Log + * @category Mage + * @package Mage_Log * @author Magento Core Team */ -class Mage_Log_Model_Mysql4_Visitor extends Mage_Core_Model_Mysql4_Abstract +class Mage_Log_Model_Mysql4_Visitor extends Mage_Log_Model_Resource_Visitor { - protected function _construct() - { - $this->_init('log/visitor', 'visitor_id'); - } - - protected function _prepareDataForSave(Mage_Core_Model_Abstract $visitor) - { - return array( - 'session_id' => $visitor->getSessionId(), - 'first_visit_at'=> $visitor->getFirstVisitAt(), - 'last_visit_at' => $visitor->getLastVisitAt(), - 'last_url_id' => $visitor->getLastUrlId() ? $visitor->getLastUrlId() : 0, - 'store_id' => Mage::app()->getStore()->getId(), - ); - } - - /** - * Saving information about url - * - * @param Mage_Log_Model_Visitor $visitor - * @return Mage_Log_Model_Mysql4_Visitor - */ - protected function _saveUrlInfo($visitor) - { - $this->_getWriteAdapter()->insert($this->getTable('log/url_info_table'), array( - 'url' => Mage::helper('core/string')->substr($visitor->getUrl(), 0, 250), - 'referer'=> Mage::helper('core/string')->substr($visitor->getHttpReferer(), 0, 250) - )); - $visitor->setLastUrlId($this->_getWriteAdapter()->lastInsertId()); - return $this; - } - - protected function _beforeSave(Mage_Core_Model_Abstract $visitor) - { - if (!$visitor->getIsNewVisitor()) { - $this->_saveUrlInfo($visitor); - } - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $visitor) - { - if ($visitor->getIsNewVisitor()) { - $this->_saveVisitorInfo($visitor); - $visitor->setIsNewVisitor(false); - } - else { - $this->_saveVisitorUrl($visitor); - if ($visitor->getDoCustomerLogin() || $visitor->getDoCustomerLogout()) { - $this->_saveCustomerInfo($visitor); - } - if ($visitor->getDoQuoteCreate() || $visitor->getDoQuoteDestroy()) { - $this->_saveQuoteInfo($visitor); - } - } - return $this; - } - - /** - * Saving visitor information - * - * @param Mage_Log_Model_Visitor $visitor - * @return Mage_Log_Model_Mysql4_Visitor - */ - protected function _saveVisitorInfo($visitor) - { - /* @var $stringHelper Mage_Core_Helper_String */ - $stringHelper = Mage::helper('core/string'); - - $referer = $stringHelper->cleanString($visitor->getHttpReferer()); - $referer = $stringHelper->substr($referer, 0, 255); - $userAgent = $stringHelper->cleanString($visitor->getHttpUserAgent()); - $userAgent = $stringHelper->substr($userAgent, 0, 255); - $charset = $stringHelper->cleanString($visitor->getHttpAcceptCharset()); - $charset = $stringHelper->substr($charset, 0, 255); - $language = $stringHelper->cleanString($visitor->getHttpAcceptLanguage()); - $language = $stringHelper->substr($language, 0, 255); - - $write = $this->_getWriteAdapter(); - $data = array( - 'visitor_id' => $visitor->getId(), - 'http_referer' => $stringHelper->substr($visitor->getHttpReferer(), 0, 255), - 'http_user_agent' => $stringHelper->substr($visitor->getHttpUserAgent(), 0, 255), - 'http_accept_charset' => $stringHelper->substr($visitor->getHttpAcceptCharset(), 0, 255), - 'http_accept_language' => $stringHelper->substr($visitor->getHttpAcceptLanguage(), 0, 255), - 'server_addr' => $visitor->getServerAddr(), - 'remote_addr' => $visitor->getRemoteAddr(), - ); - - $write->insert($this->getTable('log/visitor_info'), $data); - return $this; - } - - /** - * Saving visitor and url relation - * - * @param Mage_Log_Model_Visitor $visitor - * @return Mage_Log_Model_Mysql4_Visitor - */ - protected function _saveVisitorUrl($visitor) - { - $write = $this->_getWriteAdapter(); - $write->insert($this->getTable('log/url_table'), array( - 'url_id' => $visitor->getLastUrlId(), - 'visitor_id'=> $visitor->getId(), - 'visit_time'=> now(), - )); - return $this; - } - - /** - * Saving information about customer - * - * @param Mage_Log_Model_Visitor $visitor - * @return Mage_Log_Model_Mysql4_Visitor - */ - protected function _saveCustomerInfo($visitor) - { - $write = $this->_getWriteAdapter(); - - if ($visitor->getDoCustomerLogin()) { - $write->insert($this->getTable('log/customer'), array( - 'visitor_id' => $visitor->getVisitorId(), - 'customer_id' => $visitor->getCustomerId(), - 'login_at' => now(), - 'store_id' => Mage::app()->getStore()->getId(), - )); - $visitor->setCustomerLogId($write->lastInsertId()); - $visitor->setDoCustomerLogin(false); - } - - if ($visitor->getDoCustomerLogout() && $logId = $visitor->getCustomerLogId()) { - $write->update($this->getTable('log/customer'), - array( - 'logout_at' => now(), - 'store_id' => Mage::app()->getStore()->getId(), - ), - $write->quoteInto('log_id=?', $logId) - ); - $visitor->setDoCustomerLogout(false); - $visitor->setCustomerId(null); - $visitor->setCustomerLogId(null); - } - return $this; - } - - /** - * Saving information about quote - * - * @param Mage_Log_Model_Visitor $visitor - * @return Mage_Log_Model_Mysql4_Visitor - */ - protected function _saveQuoteInfo($visitor) - { - $write = $this->_getWriteAdapter(); - if ($visitor->getDoQuoteCreate()) { - $write->insert($this->getTable('log/quote_table'), array( - 'quote_id' => $visitor->getQuoteId(), - 'visitor_id'=> $visitor->getId(), - 'created_at'=> now() - )); - $visitor->setDoQuoteCreate(false); - } - - if ($visitor->getDoQuoteDestroy()) { - /** - * We have delete quote from log because if original quote was - * deleted and Mysql restarted we will get key duplication error - */ - $write->delete($this->getTable('log/quote_table'), - $write->quoteInto('quote_id=?', $visitor->getQuoteId()) - ); -// $write->update($this->getTable('log/quote_table'), -// array('deleted_at'=> now()), -// $write->quoteInto('quote_id=?', $visitor->getQuoteId()) -// ); - $visitor->setDoQuoteDestroy(false); - $visitor->setQuoteId(null); - } - return $this; - } } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Aggregator.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Aggregator.php deleted file mode 100644 index 486f0760a7..0000000000 --- a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Aggregator.php +++ /dev/null @@ -1,189 +0,0 @@ - - */ - -class Mage_Log_Model_Mysql4_Visitor_Aggregator -{ - /** - * Visitor data table name - * - * @var string - */ - protected $_visitorTable; - - /** - * Customer data table - * - * @var string - */ - protected $_customerTable; - - /** - * Log URL data table name. - * - * @var string - */ - protected $_urlTable; - - /** - * Aggregator data table. - * - * @var string - */ - protected $_summaryTable; - - /** - * Aggregator type data table. - * - * @var string - */ - protected $_summaryTypeTable; - - /** - * Database read connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_read; - - /** - * Database write connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_write; - - public function __construct() - { - $resource = Mage::getSingleton('core/resource'); - - $this->_visitorTable = $resource->getTableName('log/visitor'); - $this->_urlTable = $resource->getTableName('log/url_table'); - $this->_customerTable = $resource->getTableName('log/customer'); - $this->_summaryTable = $resource->getTableName('log/summary_table'); - $this->_summaryTypeTable= $resource->getTableName('log/summary_type_table'); - - $this->_read = $resource->getConnection('log_read'); - $this->_write = $resource->getConnection('log_write'); - } - - public function update() - { - $types = $this->_getSummaryTypes(); - foreach( $types as $type ) { - $this->_update($type); - } - } - - protected function _getSummaryTypes() - { - $types = $this->_read->fetchAll("SELECT type_id, period, period_type FROM {$this->_summaryTypeTable}"); - return $types; - } - - protected function _update($type) - { - $countSelect = $this->_read->select() - ->from($this->_summaryTable, 'summary_id') - ->where('type_id=?', $type['type_id']) - ->having("('".now()."' - INTERVAL {$type['period']} {$type['period_type']}) <= MAX(add_date)"); - - $summaryIds = $this->_read->fetchCol($countSelect); - - $customerSelect = $this->_read->select() - ->from($this->_customerTable, 'visitor_id') - ->where("? - INTERVAL {$type['period']} {$type['period_type']} <= login_at", now()) - ->where("logout_at IS NULL OR logout_at <= ? - INTERVAL {$type['period']} {$type['period_type']}", now()); - - $customers = $this->_read->fetchCol($customerSelect); - - $customerCount = count($customers); - - $customers = ( $customerCount > 0 ) ? $customers : 0; - - $customersCondition = $this->_read->quoteInto('visitor_id NOT IN(?)', $customers); - $visitorCount = $this->_read->fetchOne("SELECT COUNT(visitor_id) FROM {$this->_visitorTable} WHERE ('".now()."' - INTERVAL {$type['period']} {$type['period_type']}) <= first_visit_at OR (NOW() - INTERVAL {$type['period']} {$type['period_type']}) <= last_visit_at AND {$customersCondition}"); - - if( $customerCount == 0 && $visitorCount == 0 ) { - return; - } - - $data = array( - 'type_id' => $type['type_id'], - 'visitor_count' => $visitorCount, - 'customer_count' => $customerCount, - 'add_date' => now() - ); - - - if(count($summaryIds)==0) { - $this->_write->insert($this->_summaryTable, $data); - } else { - $conditionSql = $this->_write->quoteInto('summary_id in (?)', $summaryIds); - $this->_write->update($this->_summaryTable, $data, $conditionSql); - } - - } - - public function updateOneshot($minutes=60, $interval=300) - { - $last_update = $this->_read->fetchOne("SELECT UNIX_TIMESTAMP(MAX(add_date)) FROM {$this->_summaryTable} WHERE type_id IS NULL"); - $next_update = $last_update + $interval; - - if( time() >= $next_update ) { - $stats = $this->_read->fetchAssoc("SELECT - u.visit_time, - v.visitor_id, - c.customer_id, - ROUND( (UNIX_TIMESTAMP(u.visit_time) - UNIX_TIMESTAMP(".now()." - INTERVAL {$minutes} MINUTE )) / {$interval} ) as _diff, - COUNT(DISTINCT(v.visitor_id)) as visitor_count, - COUNT(DISTINCT(c.customer_id)) as customer_count - FROM - {$this->_urlTable} u - LEFT JOIN {$this->_visitorTable} v ON(v.visitor_id = u.visitor_id) - LEFT JOIN {$this->_customerTable} c on(c.visitor_id = v.visitor_id) - WHERE - UNIX_TIMESTAMP(u.visit_time) > {$next_update} - group by _diff"); - - foreach( $stats as $stat ) { - $data = array( - 'type_id' => new Zend_Db_Expr('NULL'), - 'visitor_count' => $stat['visitor_count'], - 'customer_count' => $stat['customer_count'], - 'add_date' => $stat['visit_time'] - ); - $this->_write->insert($this->_summaryTable, $data); - } - } - - } -} diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Collection.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Collection.php index 94f6b80291..1e592465d1 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Collection.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Collection.php @@ -20,298 +20,18 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Mage_Log_Model_Mysql4_Customers_Collection * - * @category Mage - * @package Mage_Log + * @category Mage + * @package Mage_Log * @author Magento Core Team */ - -class Mage_Log_Model_Mysql4_Visitor_Collection extends Varien_Data_Collection_Db +class Mage_Log_Model_Mysql4_Visitor_Collection extends Mage_Log_Model_Resource_Visitor_Collection { - /** - * Visitor data table name - * - * @var string - */ - protected $_visitorTable; - - /** - * Visitor data info table name - * - * @var string - */ - protected $_visitorInfoTable; - - /** - * Customer data table - * - * @var string - */ - protected $_customerTable; - - /** - * Log URL data table name. - * - * @var string - */ - protected $_urlTable; - - /** - * Log URL expanded data table name. - * - * @var string - */ - protected $_urlInfoTable; - - /** - * Aggregator data table. - * - * @var string - */ - protected $_summaryTable; - - /** - * Aggregator type data table. - * - * @var string - */ - protected $_summaryTypeTable; - - /** - * Quote data table. - * - * @var string - */ - protected $_quoteTable; - - protected $_isOnlineFilterUsed = false; - - protected $_fieldMap = array( - 'customer_firstname' => 'customer_firstname_table.value', - 'customer_lastname' => 'customer_lastname_table.value', - 'customer_email' => 'customer_email_table.email', - 'customer_id' => 'customer_table.customer_id', - 'url' => 'url_info_table.url' - ); - - /** - * Construct - * - */ - function __construct() - { - $resource = Mage::getSingleton('core/resource'); - parent::__construct($resource->getConnection('log_read')); - - $this->_visitorTable = $resource->getTableName('log/visitor'); - $this->_visitorInfoTable = $resource->getTableName('log/visitor_info'); - $this->_urlTable = $resource->getTableName('log/url_table'); - $this->_urlInfoTable = $resource->getTableName('log/url_info_table'); - $this->_customerTable = $resource->getTableName('log/customer'); - $this->_summaryTable = $resource->getTableName('log/summary_table'); - $this->_summaryTypeTable = $resource->getTableName('log/summary_type_table'); - $this->_quoteTable = $resource->getTableName('log/quote_table'); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('log/visitor')); - } - - /** - * Enables online only select - * - * @param int $minutes - * @return object - */ - public function useOnlineFilter($minutes=null) - { - if (is_null($minutes)) { - $minutes = Mage_Log_Model_Visitor::getOnlineMinutesInterval(); - } - $this->_select->from(array('visitor_table'=>$this->_visitorTable)) - //->joinLeft(array('url_table'=>$this->_urlTable), 'visitor_table.last_url_id=url_table.url_id') - ->joinLeft(array('info_table'=>$this->_visitorInfoTable), 'info_table.visitor_id=visitor_table.visitor_id') - ->joinLeft(array('customer_table'=>$this->_customerTable), - 'customer_table.visitor_id = visitor_table.visitor_id AND customer_table.logout_at IS NULL', - array('log_id', 'customer_id', 'login_at', 'logout_at')) - ->joinLeft(array('url_info_table'=>$this->_urlInfoTable), - 'url_info_table.url_id = visitor_table.last_url_id') - //->joinLeft(array('quote_table'=>$this->_quoteTable), 'quote_table.visitor_id=visitor_table.visitor_id') - ->where( 'visitor_table.last_visit_at >= ( ? - INTERVAL '.$minutes.' MINUTE)', now() ); - - - $customersCollection = Mage::getModel('customer/customer')->getCollection(); - /* @var $customersCollection Mage_Customer_Model_Entity_Customer_Collection */ - $firstname = $customersCollection->getAttribute('firstname'); - $lastname = $customersCollection->getAttribute('lastname'); - $email = $customersCollection->getAttribute('email'); - - $this->_select - ->columns(array('type' => 'IF(customer_id, \''.Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER.'\', \''.Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR.'\')')) - ->joinLeft( - array('customer_lastname_table'=>$lastname->getBackend()->getTable()), - 'customer_lastname_table.entity_id=customer_table.customer_id - AND customer_lastname_table.attribute_id = '.(int) $lastname->getAttributeId() . ' - ', - array('customer_lastname'=>'value') - ) - ->joinLeft( - array('customer_firstname_table'=>$firstname->getBackend()->getTable()), - 'customer_firstname_table.entity_id=customer_table.customer_id - AND customer_firstname_table.attribute_id = '.(int) $firstname->getAttributeId() . ' - ', - array('customer_firstname'=>'value') - ) - ->joinLeft( - array('customer_email_table'=>$email->getBackend()->getTable()), - 'customer_email_table.entity_id=customer_table.customer_id', - array('customer_email'=>'email') - ); - $this->_isOnlineFilterUsed = true; - return $this; - } - - public function showCustomersOnly() - { - $this->_select->where('customer_table.customer_id > 0') - ->group('customer_table.customer_id'); - return $this; - } - - public function getAggregatedData($period=720, $type_code=null, $customFrom=null, $customTo=null) - { - /** - * @todo : need remove agregation logic - */ - $timeZoneOffset = Mage::getModel('core/date')->getGmtOffset();//Mage::app()->getLocale()->date()->getGmtOffset(); - $this->_itemObjectClass = 'Varien_Object'; - $this->_setIdFieldName('summary_id'); - -/* - $this->_select->from(array('summary'=>$this->_summaryTable), array('summary_id','customer_count','visitor_count','add_date'=>"DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND)")) - ->join(array('type'=>$this->_summaryTypeTable), 'type.type_id=summary.type_id', array()); - - if (is_null($customFrom) && is_null($customTo)) { - $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ( DATE_SUB(?, INTERVAL $timeZoneOffset SECOND) - INTERVAL {$period} {$this->_getRangeByType($type_code)} )", now() ); - } else { - if($customFrom) { - $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ", $this->_read->convertDate($customFrom)); - } - if($customTo) { - $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) <= ", $this->_read->convertDate($customTo)); - } - } - - - if( is_null($type_code) ) { - $this->_select->where("summary.type_id IS NULL"); - } else { - $this->_select->where("type.type_code = ? ", $type_code); - } -*/ - - $this->_select->from(array('summary'=>$this->_summaryTable), - array('summary_id', - 'customer_count'=>'SUM(customer_count)', - 'visitor_count'=>'SUM(visitor_count)', - 'add_date'=>"DATE_ADD(summary.add_date, INTERVAL $timeZoneOffset SECOND)" - )); - - $this->_select->where("DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ( DATE_SUB(?, INTERVAL $timeZoneOffset SECOND) - INTERVAL {$period} {$this->_getRangeByType($type_code)} )", now() ); - $this->_select->group('DATE_FORMAT(add_date, \''.$this->_getGroupByDateFormat($type_code).'\')'); - $this->_select->order('add_date ASC'); - - return $this; - } - - protected function _getGroupByDateFormat($type) - { - switch ($type) { - case 'day': - $format = '%Y-%m-%d'; - break; - default: - case 'hour': - $format = '%Y-%m-%d %H'; - break; - } - return $format; - } - - protected function _getRangeByType($type_code) - { - switch ($type_code) - { - case 'day': - $range = 'DAY'; - break; - case 'hour': - $range = 'HOUR'; - break; - case 'minute': - default: - $range = 'MINUTE'; - break; - - } - - return $range; - } - - /** - * Filter by customer ID, as 'type' field does not exist - * - * @param string $fieldName - * @param array $condition - * @return Mage_Log_Model_Mysql4_Visitor_Collection - */ - public function addFieldToFilter($fieldName, $condition=null) - { - if ($fieldName == 'type' && is_array($condition) && isset($condition['eq'])) { - $fieldName = 'customer_id'; - if ($condition['eq'] === Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR) { - $condition = array('null' => 1); - } else { - $condition = array('moreq' => 1); - } - } - return parent::addFieldToFilter($this->_getFieldMap($fieldName), $condition); - } - - protected function _getFieldMap($fieldName) - { - if(isset($this->_fieldMap[$fieldName])) { - return $this->_fieldMap[$fieldName]; - } else { - return 'visitor_table.' . $fieldName; - } - } - - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - Mage::dispatchEvent('log_visitor_collection_load_before', array('collection' => $this)); - return parent::load($printQuery, $logQuery); - } - - public function getIsOnlineFilterUsed() - { - return $this->_isOnlineFilterUsed; - } - - /** - * Filter visitors by specified store ids - * - * @param array|int $storeIds - */ - public function addVisitorStoreFilter($storeIds) - { - $this->_select->where('visitor_table.store_id IN (?)', $storeIds); - } } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php index 2f0cf1fc0b..ad700caf55 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,105 +28,10 @@ /** * Log Prepare Online visitors resource collection * - * @category Mage - * @package Mage_Log - * @author Magento Core Team + * @category Mage + * @package Mage_Log + * @author Magento Core Team */ -class Mage_Log_Model_Mysql4_Visitor_Online extends Mage_Core_Model_Mysql4_Abstract +class Mage_Log_Model_Mysql4_Visitor_Online extends Mage_Log_Model_Resource_Visitor_Online { - /** - * Initialize connection and define resource - * - */ - protected function _construct() - { - $this->_init('log/visitor_online', 'visitor_id'); - } - - /** - * Prepare online visitors for collection - * - * @param Mage_Log_Model_Visitor_Online $object - * @return Mage_Log_Model_Mysql4_Visitor_Online - */ - public function prepare(Mage_Log_Model_Visitor_Online $object) - { - if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) { - return $this; - } - - $this->_getWriteAdapter()->beginTransaction(); - $this->_getWriteAdapter()->truncate($this->getMainTable()); - - $visitors = array(); - $lastUrls = array(); - - // retrieve online visitors general data - $whereCond = sprintf('last_visit_at >= (? - INTERVAL %d MINUTE)', - $object->getOnlineInterval()); - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('log/visitor'), - array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id')) - ->where($whereCond, now()); - - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $visitors[$row['visitor_id']] = $row; - $lastUrls[$row['last_url_id']] = $row['visitor_id']; - $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR; - $visitors[$row['visitor_id']]['customer_id'] = null; - } - - if (!$visitors) { - $this->commit(); - return $this; - } - - // retrieve visitor remote addr - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('log/visitor_info'), - array('visitor_id', 'remote_addr')) - ->where('visitor_id IN(?)', array_keys($visitors)); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr']; - } - - // retrieve visitor last URLs - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('log/url_info_table'), - array('url_id', 'url')) - ->where('url_id IN(?)', array_keys($lastUrls)); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $visitorId = $lastUrls[$row['url_id']]; - $visitors[$visitorId]['last_url'] = $row['url']; - } - - // retrieve customers - $select = $this->_getReadAdapter()->select() - ->from( - $this->getTable('log/customer'), - array('visitor_id', 'customer_id')) - ->where('visitor_id IN(?)', array_keys($visitors)); - $query = $this->_getReadAdapter()->query($select); - while ($row = $query->fetch()) { - $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER; - $visitors[$row['visitor_id']]['customer_id'] = $row['customer_id']; - } - - foreach ($visitors as $visitorData) { - unset($visitorData['last_url_id']); - $this->_getWriteAdapter()->insert($this->getMainTable(), $visitorData); - } - - $this->_getWriteAdapter()->commit(); - - $object->setPrepareAt(); - - return $this; - } } diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php index 8ccc4a07f2..71384dbb67 100644 --- a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,115 +28,10 @@ /** * Log Online visitors collection * - * @category Mage - * @package Mage_Log - * @author Magento Core Team + * @category Mage + * @package Mage_Log + * @author Magento Core Team */ -class Mage_Log_Model_Mysql4_Visitor_Online_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Log_Model_Mysql4_Visitor_Online_Collection extends Mage_Log_Model_Resource_Visitor_Online_Collection { - /** - * joined fields array - * - * @var array - */ - protected $_fields = array(); - - /** - * Initialize collection model - * - */ - protected function _construct() - { - $this->_init('log/visitor_online'); - } - - /** - * Add Customer data to collection - * - * @return Mage_Log_Model_Mysql4_Visitor_Online_Collection - */ - public function addCustomerData() - { - $customer = Mage::getModel('customer/customer'); - // alias => attribute_code - $attributes = array( - 'customer_lastname' => 'lastname', - 'customer_firstname' => 'firstname', - 'customer_email' => 'email' - ); - - foreach ($attributes as $alias => $attributeCode) { - $attribute = $customer->getAttribute($attributeCode); - /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ - - if ($attribute->getBackendType() == 'static') { - $tableAlias = 'customer_' . $attribute->getAttributeCode(); - - $this->getSelect()->joinLeft( - array($tableAlias => $attribute->getBackend()->getTable()), - sprintf('%s.entity_id=main_table.customer_id', $tableAlias), - array($alias => $attribute->getAttributeCode()) - ); - - $this->_fields[$alias] = sprintf('%s.%s', $tableAlias, $attribute->getAttributeCode()); - } - else { - $tableAlias = 'customer_' . $attribute->getAttributeCode(); - - $joinConds = array( - sprintf('%s.entity_id=main_table.customer_id', $tableAlias), - $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute->getAttributeId()) - ); - - $this->getSelect()->joinLeft( - array($tableAlias => $attribute->getBackend()->getTable()), - join(' AND ', $joinConds), - array($alias => 'value') - ); - - $this->_fields[$alias] = sprintf('%s.value', $tableAlias); - } - } - - $this->setFlag('has_customer_data', true); - return $this; - } - - /** - * Filter collection by specified website(s) - * - * @param int|array $websiteIds - * @return Mage_Log_Model_Mysql4_Visitor_Online_Collection - */ - public function addWebsiteFilter($websiteIds) - { - if ($this->getFlag('has_customer_data')) { - $this->getSelect() - ->where('customer_email.website_id IN (?)', $websiteIds); - } - return $this; - } - - /** - * Add field filter to collection - * - * If $attribute is an array will add OR condition with following format: - * array( - * array('attribute'=>'firstname', 'like'=>'test%'), - * array('attribute'=>'lastname', 'like'=>'test%'), - * ) - * - * @see self::_getConditionSql for $condition - * @param string|array $attribute - * @param null|string|array $condition - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addFieldToFilter($field, $condition=null) - { - if (isset($this->_fields[$field])) { - $field = $this->_fields[$field]; - } - - return parent::addFieldToFilter($field, $condition); - } } diff --git a/app/code/core/Mage/Log/Model/Resource/Aggregation.php b/app/code/core/Mage/Log/Model/Resource/Aggregation.php new file mode 100644 index 0000000000..719aaedb34 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Aggregation.php @@ -0,0 +1,153 @@ + + */ +class Mage_Log_Model_Resource_Aggregation extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('log/summary_table', 'log_summary_id'); + } + + /** + * Retrieve last added record + * + * @return string + */ + public function getLastRecordDate() + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('log/summary_table'), + array($adapter->quoteIdentifier('date')=>'MAX(add_date)')); + + return $adapter->fetchOne($select); + } + + /** + * Retrieve count of visitors, customers + * + * @param string $from + * @param string $to + * @param int $store + * @return array + */ + public function getCounts($from, $to, $store) + { + $adapter = $this->_getReadAdapter(); + $result = array('customers'=>0, 'visitors'=>0); + $select = $adapter->select() + ->from($this->getTable('log/customer'), 'visitor_id') + ->where('login_at >= ?', $from) + ->where('login_at <= ?', $to); + if ($store) { + $select->where('store_id = ?', $store); + } + + $customers = $adapter->fetchCol($select); + $result['customers'] = count($customers); + + + $select = $adapter->select(); + $select->from($this->getTable('log/visitor'), 'COUNT(*)') + ->where('first_visit_at >= ?', $from) + ->where('first_visit_at <= ?', $to); + + if ($store) { + $select->where('store_id = ?', $store); + } + if ($result['customers']) { + $select->where('visitor_id NOT IN(?)', $customers); + } + + $result['visitors'] = $adapter->fetchOne($select); + + + return $result; + } + + /** + * Save log + * + * @param array $data + * @param int $id + */ + public function saveLog($data, $id = null) + { + $adapter = $this->_getWriteAdapter(); + if (is_null($id)) { + $adapter->insert($this->getTable('log/summary_table'), $data); + } else { + $condition = $adapter->quoteInto('summary_id = ?', $id); + $adapter->update($this->getTable('log/summary_table'), $data, $condition); + } + } + + /** + * Remove empty records + * + * @param string $date + */ + public function removeEmpty($date) + { + $adapter = $this->_getWriteAdapter(); + $condition = array( + 'add_date < ?' => $date, + 'customer_count = 0', + 'visitor_count = 0' + ); + $adapter->delete($this->getTable('log/summary_table'), $condition); + } + + /** + * Retrieve log id + * + * @param string $from + * @param string $to + * @return string + */ + public function getLogId($from, $to) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('log/summary_table'), 'summary_id') + ->where('add_date >= ?', $from) + ->where('add_date <= ?', $to); + + return $adapter->fetchOne($select); + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Customer.php b/app/code/core/Mage/Log/Model/Resource/Customer.php new file mode 100755 index 0000000000..5f3c15d002 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Customer.php @@ -0,0 +1,127 @@ + + */ + +class Mage_Log_Model_Resource_Customer extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Visitor data table name + * + * @var string + */ + protected $_visitorTable; + + /** + * Visitor info data table + * + * @var string + */ + protected $_visitorInfoTable; + + /** + * Customer data table + * + * @var string + */ + protected $_customerTable; + + /** + * Url info data table + * + * @var string + */ + protected $_urlInfoTable; + + /** + * Log URL data table name. + * + * @var string + */ + protected $_urlTable; + + /** + * Log quote data table name. + * + * @var string + */ + protected $_quoteTable; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('log/customer', 'log_id'); + + $this->_visitorTable = $this->getTable('log/visitor'); + $this->_visitorInfoTable = $this->getTable('log/visitor_info'); + $this->_urlTable = $this->getTable('log/url_table'); + $this->_urlInfoTable = $this->getTable('log/url_info_table'); + $this->_customerTable = $this->getTable('log/customer'); + $this->_quoteTable = $this->getTable('log/quote_table'); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Log_Model_Customer $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($field == 'customer_id') { + // load additional data by last login + $table = $this->getMainTable(); + $select + ->joinInner( + array('lvt' => $this->_visitorTable), + "lvt.visitor_id = {$table}.visitor_id", + array('last_visit_at')) + ->joinInner( + array('lvit' => $this->_visitorInfoTable), + 'lvt.visitor_id = lvit.visitor_id', + array('http_referer', 'remote_addr')) + ->joinInner( + array('luit' => $this->_urlInfoTable), + 'luit.url_id = lvt.last_url_id', + array('url')) + ->order("{$table}.login_at DESC") + ->limit(1); + } + return $select; + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Log.php b/app/code/core/Mage/Log/Model/Resource/Log.php new file mode 100755 index 0000000000..a7ba21f871 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Log.php @@ -0,0 +1,254 @@ + + */ +class Mage_Log_Model_Resource_Log extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init Resource model and connection + * + */ + protected function _construct() + { + $this->_init('log/visitor', 'visitor_id'); + } + + /** + * Clean logs + * + * @param Mage_Log_Model_Log $object + * @return Mage_Log_Model_Resource_Log + */ + public function clean(Mage_Log_Model_Log $object) + { + $cleanTime = $object->getLogCleanTime(); + + Mage::dispatchEvent('log_log_clean_before', array( + 'log' => $object + )); + + $this->_cleanVisitors($cleanTime); + $this->_cleanCustomers($cleanTime); + $this->_cleanUrls(); + + Mage::dispatchEvent('log_log_clean_after', array( + 'log' => $object + )); + + return $this; + } + + /** + * Clean visitors table + * + * @param int $time + * @return Mage_Log_Model_Resource_Log + */ + protected function _cleanVisitors($time) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + $timeLimit = $this->formatDate(Mage::getModel('core/date')->gmtTimestamp() - $time); + + while (true) { + $select = $readAdapter->select() + ->from( + array('visitor_table' => $this->getTable('log/visitor')), + array('visitor_id' => 'visitor_table.visitor_id')) + ->joinLeft( + array('customer_table' => $this->getTable('log/customer')), + 'visitor_table.visitor_id = customer_table.visitor_id AND customer_table.log_id IS NULL', + array()) + ->where('visitor_table.last_visit_at < ?', $timeLimit) + ->limit(100); + + $visitorIds = $readAdapter->fetchCol($select); + + if (!$visitorIds) { + break; + } + + $condition = array('visitor_id IN (?)' => $visitorIds); + + // remove visitors from log/quote + $writeAdapter->delete($this->getTable('log/quote_table'), $condition); + + // remove visitors from log/url + $writeAdapter->delete($this->getTable('log/url_table'), $condition); + + // remove visitors from log/visitor_info + $writeAdapter->delete($this->getTable('log/visitor_info'), $condition); + + // remove visitors from log/visitor + $writeAdapter->delete($this->getTable('log/visitor'), $condition); + } + + return $this; + } + + /** + * Clean customer table + * + * @param int $time + * @return Mage_Log_Model_Resource_Log + */ + protected function _cleanCustomers($time) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + $timeLimit = $this->formatDate(Mage::getModel('core/date')->gmtTimestamp() - $time); + + // retrieve last active customer log id + $lastLogId = $readAdapter->fetchOne( + $readAdapter->select() + ->from($this->getTable('log/customer'), 'log_id') + ->where('login_at < ?', $timeLimit) + ->order('log_id DESC') + ->limit(1) + ); + + if (!$lastLogId) { + return $this; + } + + // Order by desc log_id before grouping (within-group aggregates query pattern) + $select = $readAdapter->select() + ->from( + array('log_customer_main' => $this->getTable('log/customer')), + array('log_id')) + ->joinLeft( + array('log_customer' => $this->getTable('log/customer')), + 'log_customer_main.customer_id = log_customer.customer_id ' + . 'AND log_customer_main.log_id < log_customer.log_id', + array()) + ->where('log_customer.customer_id IS NULL') + ->where('log_customer_main.log_id < ?', $lastLogId + 1); + + $needLogIds = array(); + $query = $readAdapter->query($select); + while ($row = $query->fetch()) { + $needLogIds[$row['log_id']] = 1; + } + + $customerLogId = 0; + while (true) { + $visitorIds = array(); + $select = $readAdapter->select() + ->from( + $this->getTable('log/customer'), + array('log_id', 'visitor_id')) + ->where('log_id > ?', $customerLogId) + ->where('log_id < ?', $lastLogId + 1) + ->order('log_id') + ->limit(100); + + $query = $readAdapter->query($select); + $count = 0; + while ($row = $query->fetch()) { + $count++; + $customerLogId = $row['log_id']; + if (!isset($needLogIds[$row['log_id']])) { + $visitorIds[] = $row['visitor_id']; + } + } + + if (!$count) { + break; + } + + if ($visitorIds) { + $condition = array('visitor_id IN (?)' => $visitorIds); + + // remove visitors from log/quote + $writeAdapter->delete($this->getTable('log/quote_table'), $condition); + + // remove visitors from log/url + $writeAdapter->delete($this->getTable('log/url_table'), $condition); + + // remove visitors from log/visitor_info + $writeAdapter->delete($this->getTable('log/visitor_info'), $condition); + + // remove visitors from log/visitor + $writeAdapter->delete($this->getTable('log/visitor'), $condition); + + // remove customers from log/customer + $writeAdapter->delete($this->getTable('log/customer'), $condition); + } + + if ($customerLogId == $lastLogId) { + break; + } + } + + return $this; + } + + /** + * Clean url table + * + * @return Mage_Log_Model_Resource_Log + */ + protected function _cleanUrls() + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + while (true) { + $select = $readAdapter->select() + ->from( + array('url_info_table' => $this->getTable('log/url_info_table')), + array('url_id')) + ->joinLeft( + array('url_table' => $this->getTable('log/url_table')), + 'url_info_table.url_id = url_table.url_id', + array()) + ->where('url_table.url_id IS NULL') + ->limit(100); + + $urlIds = $readAdapter->fetchCol($select); + + if (!$urlIds) { + break; + } + + $writeAdapter->delete( + $this->getTable('log/url_info_table'), + array('url_id IN (?)' => $urlIds) + ); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor.php b/app/code/core/Mage/Log/Model/Resource/Visitor.php new file mode 100755 index 0000000000..a015174447 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Visitor.php @@ -0,0 +1,262 @@ + + */ +class Mage_Log_Model_Resource_Visitor extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('log/visitor', 'visitor_id'); + } + + /** + * Prepare data for save + * + * @param Mage_Core_Model_Abstract $visitor + * @return array + */ + protected function _prepareDataForSave(Mage_Core_Model_Abstract $visitor) + { + return array( + 'session_id' => $visitor->getSessionId(), + 'first_visit_at' => $visitor->getFirstVisitAt(), + 'last_visit_at' => $visitor->getLastVisitAt(), + 'last_url_id' => $visitor->getLastUrlId() ? $visitor->getLastUrlId() : 0, + 'store_id' => Mage::app()->getStore()->getId(), + ); + } + + /** + * Saving information about url + * + * @param Mage_Log_Model_Visitor $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _saveUrlInfo($visitor) + { + $adapter = $this->_getWriteAdapter(); + $data = new Varien_Object(array( + 'url' => Mage::helper('core/string')->substr($visitor->getUrl(), 0, 250), + 'referer'=> Mage::helper('core/string')->substr($visitor->getHttpReferer(), 0, 250) + )); + $bind = $this->_prepareDataForTable($data, $this->getTable('log/url_info_table')); + + $adapter->insert($this->getTable('log/url_info_table'), $bind); + + $visitor->setLastUrlId($adapter->lastInsertId($this->getTable('log/url_info_table'))); + + return $this; + } + + /** + * Save url info before save + * + * @param Mage_Core_Model_Abstract $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _beforeSave(Mage_Core_Model_Abstract $visitor) + { + if (!$visitor->getIsNewVisitor()) { + $this->_saveUrlInfo($visitor); + } + return $this; + } + + /** + * Actions after save + * + * @param Mage_Core_Model_Abstract $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _afterSave(Mage_Core_Model_Abstract $visitor) + { + if ($visitor->getIsNewVisitor()) { + $this->_saveVisitorInfo($visitor); + $visitor->setIsNewVisitor(false); + } else { + $this->_saveVisitorUrl($visitor); + if ($visitor->getDoCustomerLogin() || $visitor->getDoCustomerLogout()) { + $this->_saveCustomerInfo($visitor); + } + if ($visitor->getDoQuoteCreate() || $visitor->getDoQuoteDestroy()) { + $this->_saveQuoteInfo($visitor); + } + } + return $this; + } + + /** + * Saving visitor information + * + * @param Mage_Log_Model_Visitor $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _saveVisitorInfo($visitor) + { + /* @var $stringHelper Mage_Core_Helper_String */ + $stringHelper = Mage::helper('core/string'); + + $referer = $stringHelper->cleanString($visitor->getHttpReferer()); + $referer = $stringHelper->substr($referer, 0, 255); + $userAgent = $stringHelper->cleanString($visitor->getHttpUserAgent()); + $userAgent = $stringHelper->substr($userAgent, 0, 255); + $charset = $stringHelper->cleanString($visitor->getHttpAcceptCharset()); + $charset = $stringHelper->substr($charset, 0, 255); + $language = $stringHelper->cleanString($visitor->getHttpAcceptLanguage()); + $language = $stringHelper->substr($language, 0, 255); + + $adapter = $this->_getWriteAdapter(); + $data = new Varien_Object(array( + 'visitor_id' => $visitor->getId(), + 'http_referer' => $referer, + 'http_user_agent' => $userAgent, + 'http_accept_charset' => $charset, + 'http_accept_language' => $language, + 'server_addr' => $visitor->getServerAddr(), + 'remote_addr' => $visitor->getRemoteAddr(), + )); + $bind = $this->_prepareDataForTable($data, $this->getTable('log/visitor_info')); + + $adapter->insert($this->getTable('log/visitor_info'), $bind); + return $this; + } + + /** + * Saving visitor and url relation + * + * @param Mage_Log_Model_Visitor $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _saveVisitorUrl($visitor) + { + $data = new Varien_Object(array( + 'url_id' => $visitor->getLastUrlId(), + 'visitor_id' => $visitor->getId(), + 'visit_time' => Mage::getSingleton('core/date')->gmtDate() + )); + $bind = $this->_prepareDataForTable($data, $this->getTable('log/url_table')); + + $this->_getWriteAdapter()->insert($this->getTable('log/url_table'), $bind); + return $this; + } + + /** + * Saving information about customer + * + * @param Mage_Log_Model_Visitor $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _saveCustomerInfo($visitor) + { + $adapter = $this->_getWriteAdapter(); + + if ($visitor->getDoCustomerLogin()) { + $data = new Varien_Object(array( + 'visitor_id' => $visitor->getVisitorId(), + 'customer_id' => $visitor->getCustomerId(), + 'login_at' => Mage::getSingleton('core/date')->gmtDate(), + 'store_id' => Mage::app()->getStore()->getId() + )); + $bind = $this->_prepareDataForTable($data, $this->getTable('log/customer')); + + $adapter->insert($this->getTable('log/customer'), $bind); + $visitor->setCustomerLogId($adapter->lastInsertId($this->getTable('log/customer'))); + $visitor->setDoCustomerLogin(false); + } + + if ($visitor->getDoCustomerLogout() && $logId = $visitor->getCustomerLogId()) { + $data = new Varien_Object(array( + 'logout_at' => Mage::getSingleton('core/date')->gmtDate(), + 'store_id' => (int)Mage::app()->getStore()->getId(), + )); + + $bind = $this->_prepareDataForTable($data, $this->getTable('log/customer')); + + $condition = array( + 'log_id = ?' => (int) $logId, + ); + + $adapter->update($this->getTable('log/customer'), $bind, $condition); + + $visitor->setDoCustomerLogout(false); + $visitor->setCustomerId(null); + $visitor->setCustomerLogId(null); + } + + return $this; + } + + /** + * Saving information about quote + * + * @param Mage_Log_Model_Visitor $visitor + * @return Mage_Log_Model_Resource_Visitor + */ + protected function _saveQuoteInfo($visitor) + { + $adapter = $this->_getWriteAdapter(); + if ($visitor->getDoQuoteCreate()) { + $data = new Varien_Object(array( + 'quote_id' => (int) $visitor->getQuoteId(), + 'visitor_id' => (int) $visitor->getId(), + 'created_at' => Mage::getSingleton('core/date')->gmtDate() + )); + + $bind = $this->_prepareDataForTable($data, $this->getTable('log/quote_table')); + + $adapter->insert($this->getTable('log/quote_table'), $bind); + + $visitor->setDoQuoteCreate(false); + } + + if ($visitor->getDoQuoteDestroy()) { + /** + * We have delete quote from log because if original quote was + * deleted and Mysql restarted we will get key duplication error + */ + $condition = array( + 'quote_id = ?' => (int) $visitor->getQuoteId(), + ); + + $adapter->delete($this->getTable('log/quote_table'), $condition); + + $visitor->setDoQuoteDestroy(false); + $visitor->setQuoteId(null); + } + return $this; + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php new file mode 100755 index 0000000000..2c8f9f5afc --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Collection.php @@ -0,0 +1,263 @@ + + */ + +class Mage_Log_Model_Resource_Visitor_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Visitor data table name + * + * @var string + */ + protected $_visitorTable; + + /** + * Visitor data info table name + * + * @var string + */ + protected $_visitorInfoTable; + + /** + * Customer data table + * + * @var string + */ + protected $_customerTable; + + /** + * Log URL data table name. + * + * @var string + */ + protected $_urlTable; + + /** + * Log URL expanded data table name. + * + * @var string + */ + protected $_urlInfoTable; + + /** + * Aggregator data table. + * + * @var string + */ + protected $_summaryTable; + + /** + * Aggregator type data table. + * + * @var string + */ + protected $_summaryTypeTable; + + /** + * Quote data table. + * + * @var string + */ + protected $_quoteTable; + + /** + * Online filter used flag + * + * @var bool + */ + protected $_isOnlineFilterUsed = false; + + /** + * Field map + * + * @var array + */ + protected $_fieldMap = array( + 'customer_firstname' => 'customer_firstname_table.value', + 'customer_lastname' => 'customer_lastname_table.value', + 'customer_email' => 'customer_email_table.email', + 'customer_id' => 'customer_table.customer_id', + 'url' => 'url_info_table.url' + ); + + /** + * Collection resource initialization + */ + protected function _construct() + { + $this->_init('log/visitor'); + + $this->_visitorTable = $this->getTable('log/visitor'); + $this->_visitorInfoTable = $this->getTable('log/visitor_info'); + $this->_urlTable = $this->getTable('log/url_table'); + $this->_urlInfoTable = $this->getTable('log/url_info_table'); + $this->_customerTable = $this->getTable('log/customer'); + $this->_summaryTable = $this->getTable('log/summary_table'); + $this->_summaryTypeTable = $this->getTable('log/summary_type_table'); + $this->_quoteTable = $this->getTable('log/quote_table'); + } + + /** + * Filter for customers only + * + * @return Mage_Log_Model_Resource_Visitor_Collection + */ + public function showCustomersOnly() + { + $this->getSelect() + ->where('customer_table.customer_id > 0') + ->group('customer_table.customer_id'); + + return $this; + } + + /** + * Get GROUP BY date format + * + * @deprecated since 1.5.0.0 + * @param string $type + * @return string + */ + protected function _getGroupByDateFormat($type) + { + switch ($type) { + case 'day': + $format = '%Y-%m-%d'; + break; + default: + case 'hour': + $format = '%Y-%m-%d %H'; + break; + } + return $format; + } + + /** + * Get range by type + * + * @deprecated since 1.5.0.0 + * @param string $typeCode + * @return string + */ + protected function _getRangeByType($typeCode) + { + switch ($typeCode) + { + case 'day': + $range = 'DAY'; + break; + case 'hour': + $range = 'HOUR'; + break; + case 'minute': + default: + $range = 'MINUTE'; + break; + + } + + return $range; + } + + /** + * Filter by customer ID, as 'type' field does not exist + * + * @param string $fieldName + * @param array $condition + * @return Mage_Log_Model_Resource_Visitor_Collection + */ + public function addFieldToFilter($fieldName, $condition = null) + { + if ($fieldName == 'type' && is_array($condition) && isset($condition['eq'])) { + $fieldName = 'customer_id'; + if ($condition['eq'] === Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR) { + $condition = array('null' => 1); + } else { + $condition = array('moreq' => 1); + } + } + return parent::addFieldToFilter($this->_getFieldMap($fieldName), $condition); + } + + /** + * Return field with table prefix + * + * @param string $fieldName + * @return string + */ + protected function _getFieldMap($fieldName) + { + if(isset($this->_fieldMap[$fieldName])) { + return $this->_fieldMap[$fieldName]; + } else { + return 'main_table.' . $fieldName; + } + } + + /** + * Load data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + Mage::dispatchEvent('log_visitor_collection_load_before', array('collection' => $this)); + return parent::load($printQuery, $logQuery); + } + + /** + * Return true if online filter used + * + * @return boolean + */ + public function getIsOnlineFilterUsed() + { + return $this->_isOnlineFilterUsed; + } + + /** + * Filter visitors by specified store ids + * + * @param array|int $storeIds + */ + public function addVisitorStoreFilter($storeIds) + { + $this->getSelect()->where('visitor_table.store_id IN (?)', $storeIds); + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php new file mode 100755 index 0000000000..f0c7d541e3 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php @@ -0,0 +1,146 @@ + + */ +class Mage_Log_Model_Resource_Visitor_Online extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define resource + * + */ + protected function _construct() + { + $this->_init('log/visitor_online', 'visitor_id'); + } + + /** + * Prepare online visitors for collection + * + * @param Mage_Log_Model_Visitor_Online $object + * @return Mage_Log_Model_Resource_Visitor_Online + */ + public function prepare(Mage_Log_Model_Visitor_Online $object) + { + if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) { + return $this; + } + + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + $writeAdapter->beginTransaction(); + + try{ + $writeAdapter->delete($this->getMainTable()); + + $visitors = array(); + $lastUrls = array(); + + // retrieve online visitors general data + + $lastDate = Mage::getModel('core/date')->gmtTimestamp() - $object->getOnlineInterval() * 60; + + $select = $readAdapter->select() + ->from( + $this->getTable('log/visitor'), + array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id')) + ->where('last_visit_at >= ?', $readAdapter->formatDate($lastDate)); + + $query = $readAdapter->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']] = $row; + $lastUrls[$row['last_url_id']] = $row['visitor_id']; + $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR; + $visitors[$row['visitor_id']]['customer_id'] = null; + } + + if (!$visitors) { + $this->commit(); + return $this; + } + + // retrieve visitor remote addr + $select = $readAdapter->select() + ->from( + $this->getTable('log/visitor_info'), + array('visitor_id', 'remote_addr')) + ->where('visitor_id IN(?)', array_keys($visitors)); + + $query = $readAdapter->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr']; + } + + // retrieve visitor last URLs + $select = $readAdapter->select() + ->from( + $this->getTable('log/url_info_table'), + array('url_id', 'url')) + ->where('url_id IN(?)', array_keys($lastUrls)); + + $query = $readAdapter->query($select); + while ($row = $query->fetch()) { + $visitorId = $lastUrls[$row['url_id']]; + $visitors[$visitorId]['last_url'] = $row['url']; + } + + // retrieve customers + $select = $readAdapter->select() + ->from( + $this->getTable('log/customer'), + array('visitor_id', 'customer_id')) + ->where('visitor_id IN(?)', array_keys($visitors)); + + $query = $readAdapter->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER; + $visitors[$row['visitor_id']]['customer_id'] = $row['customer_id']; + } + + foreach ($visitors as $visitorData) { + unset($visitorData['last_url_id']); + + $writeAdapter->insertForce($this->getMainTable(), $visitorData); + } + + $writeAdapter->commit(); + } catch (Exception $e) { + $writeAdapter->rollBack(); + throw $e; + } + + $object->setPrepareAt(); + + return $this; + } +} diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Online/Collection.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Online/Collection.php new file mode 100755 index 0000000000..d9504fd7c1 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Online/Collection.php @@ -0,0 +1,142 @@ + + */ +class Mage_Log_Model_Resource_Visitor_Online_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * joined fields array + * + * @var array + */ + protected $_fields = array(); + + /** + * Initialize collection model + * + */ + protected function _construct() + { + $this->_init('log/visitor_online'); + } + + /** + * Add Customer data to collection + * + * @return Mage_Log_Model_Resource_Visitor_Online_Collection + */ + public function addCustomerData() + { + $customer = Mage::getModel('customer/customer'); + // alias => attribute_code + $attributes = array( + 'customer_lastname' => 'lastname', + 'customer_firstname' => 'firstname', + 'customer_email' => 'email' + ); + + foreach ($attributes as $alias => $attributeCode) { + $attribute = $customer->getAttribute($attributeCode); + /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ + + if ($attribute->getBackendType() == 'static') { + $tableAlias = 'customer_' . $attribute->getAttributeCode(); + + $this->getSelect()->joinLeft( + array($tableAlias => $attribute->getBackend()->getTable()), + sprintf('%s.entity_id=main_table.customer_id', $tableAlias), + array($alias => $attribute->getAttributeCode()) + ); + + $this->_fields[$alias] = sprintf('%s.%s', $tableAlias, $attribute->getAttributeCode()); + } + else { + $tableAlias = 'customer_' . $attribute->getAttributeCode(); + + $joinConds = array( + sprintf('%s.entity_id=main_table.customer_id', $tableAlias), + $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute->getAttributeId()) + ); + + $this->getSelect()->joinLeft( + array($tableAlias => $attribute->getBackend()->getTable()), + join(' AND ', $joinConds), + array($alias => 'value') + ); + + $this->_fields[$alias] = sprintf('%s.value', $tableAlias); + } + } + + $this->setFlag('has_customer_data', true); + return $this; + } + + /** + * Filter collection by specified website(s) + * + * @param int|array $websiteIds + * @return Mage_Log_Model_Resource_Visitor_Online_Collection + */ + public function addWebsiteFilter($websiteIds) + { + if ($this->getFlag('has_customer_data')) { + $this->getSelect() + ->where('customer_email.website_id IN (?)', $websiteIds); + } + return $this; + } + + /** + * Add field filter to collection + * If $attribute is an array will add OR condition with following format: + * array( + * array('attribute'=>'firstname', 'like'=>'test%'), + * array('attribute'=>'lastname', 'like'=>'test%'), + * ) + * + * @see self::_getConditionSql for $condition + * + * @param string $field + * @param null|string|array $condition + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + public function addFieldToFilter($field, $condition = null) + { + if (isset($this->_fields[$field])) { + $field = $this->_fields[$field]; + } + + return parent::addFieldToFilter($field, $condition); + } +} diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index d14e4e501a..f1620224eb 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -20,11 +20,29 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Log_Model_Resource_Visitor _getResource() + * @method Mage_Log_Model_Resource_Visitor getResource() + * @method string getSessionId() + * @method Mage_Log_Model_Visitor setSessionId(string $value) + * @method Mage_Log_Model_Visitor setFirstVisitAt(string $value) + * @method Mage_Log_Model_Visitor setLastVisitAt(string $value) + * @method int getLastUrlId() + * @method Mage_Log_Model_Visitor setLastUrlId(int $value) + * @method int getStoreId() + * @method Mage_Log_Model_Visitor setStoreId(int $value) + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team + */ class Mage_Log_Model_Visitor extends Mage_Core_Model_Abstract { const DEFAULT_ONLINE_MINUTES_INTERVAL = 15; diff --git a/app/code/core/Mage/Log/Model/Visitor/Online.php b/app/code/core/Mage/Log/Model/Visitor/Online.php index 4f6f2c6043..d7239eb199 100644 --- a/app/code/core/Mage/Log/Model/Visitor/Online.php +++ b/app/code/core/Mage/Log/Model/Visitor/Online.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,24 @@ /** * Prepare Log Online Visitors Model * - * @category Mage - * @package Mage_Log - * @author Magento Core Team + * @method Mage_Log_Model_Resource_Visitor_Online _getResource() + * @method Mage_Log_Model_Resource_Visitor_Online getResource() + * @method string getVisitorType() + * @method Mage_Log_Model_Visitor_Online setVisitorType(string $value) + * @method int getRemoteAddr() + * @method Mage_Log_Model_Visitor_Online setRemoteAddr(int $value) + * @method string getFirstVisitAt() + * @method Mage_Log_Model_Visitor_Online setFirstVisitAt(string $value) + * @method string getLastVisitAt() + * @method Mage_Log_Model_Visitor_Online setLastVisitAt(string $value) + * @method int getCustomerId() + * @method Mage_Log_Model_Visitor_Online setCustomerId(int $value) + * @method string getLastUrl() + * @method Mage_Log_Model_Visitor_Online setLastUrl(string $value) + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team */ class Mage_Log_Model_Visitor_Online extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Log/data/log_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Log/data/log_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..06a1737ee2 --- /dev/null +++ b/app/code/core/Mage/Log/data/log_setup/data-install-1.6.0.0.php @@ -0,0 +1,48 @@ + 1, + 'type_code' => 'hour', + 'period' => 1, + 'period_type' => 'HOUR', + ), + + array( + 'type_id' => 2, + 'type_code' => 'day', + 'period' => 1, + 'period_type' => 'DAY', + ), +); + +foreach ($data as $bind) { + $installer->getConnection()->insertForce($installer->getTable('log/summary_type_table'), $bind); +} diff --git a/app/code/core/Mage/Log/etc/config.xml b/app/code/core/Mage/Log/etc/config.xml index ac5c1fa402..a8c30af020 100644 --- a/app/code/core/Mage/Log/etc/config.xml +++ b/app/code/core/Mage/Log/etc/config.xml @@ -21,22 +21,22 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - - 0.7.7 - + + 1.6.0.0 + - - - + + + @@ -47,22 +47,41 @@ Mage_Log_Model - log_mysql4 + log_resource - - Mage_Log_Model_Mysql4 + + Mage_Log_Model_Resource + log_mysql4 - log_customer
      - log_visitor
      - log_visitor_info
      - log_url
      - log_url_info
      - log_summary
      - log_summary_type
      - log_quote
      - log_visitor_online
      + + log_customer
      +
      + + log_visitor
      +
      + + log_visitor_info
      +
      + + log_url
      +
      + + log_url_info
      +
      + + log_summary
      +
      + + log_summary_type
      +
      + + log_quote
      +
      + + log_visitor_online
      +
      -
      +
      @@ -133,7 +152,6 @@ - @@ -145,7 +163,6 @@ - @@ -156,15 +173,14 @@ 180 0 - + - @@ -172,14 +188,6 @@ log/cron::logClean -
      diff --git a/app/code/core/Mage/Log/etc/system.xml b/app/code/core/Mage/Log/etc/system.xml index 01056483c0..d829e24632 100644 --- a/app/code/core/Mage/Log/etc/system.xml +++ b/app/code/core/Mage/Log/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Log/sql/log_setup/install-1.6.0.0.php b/app/code/core/Mage/Log/sql/log_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..83a4e88c64 --- /dev/null +++ b/app/code/core/Mage/Log/sql/log_setup/install-1.6.0.0.php @@ -0,0 +1,280 @@ +startSetup(); + +/** + * Create table 'log/customer' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/customer')) + ->addColumn('log_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Log ID') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + ), 'Visitor ID') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Customer ID') + ->addColumn('login_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Login Time') + ->addColumn('logout_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Logout Time') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store ID') + ->addIndex($installer->getIdxName('log/customer', array('visitor_id')), + array('visitor_id')) + ->setComment('Log Customers Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/quote_table' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/quote_table')) + ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Quote ID') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + ), 'Visitor ID') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Creation Time') + ->addColumn('deleted_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Deletion Time') + ->setComment('Log Quotes Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/summary_table' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/summary_table')) + ->addColumn('summary_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Summary ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store ID') + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Type ID') + ->addColumn('visitor_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Visitor Count') + ->addColumn('customer_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Customer Count') + ->addColumn('add_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Date') + ->setComment('Log Summary Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/summary_type_table' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/summary_type_table')) + ->addColumn('type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Type ID') + ->addColumn('type_code', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + 'default' => '', + ), 'Type Code') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Period') + ->addColumn('period_type', Varien_Db_Ddl_Table::TYPE_TEXT, 6, array( + 'nullable' => false, + 'default' => 'MINUTE', + ), 'Period Type') + ->setComment('Log Summary Types Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/url_table' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/url_table')) + ->addColumn('url_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'URL ID') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + ), 'Visitor ID') + ->addColumn('visit_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Visit Time') + ->addIndex($installer->getIdxName('log/url_table', array('visitor_id')), + array('visitor_id')) + ->setComment('Log URL Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/url_info_table' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/url_info_table')) + ->addColumn('url_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'URL ID') + ->addColumn('url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '', + ), 'URL') + ->addColumn('referer', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Referrer') + ->setComment('Log URL Info Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/visitor' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/visitor')) + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Visitor ID') + ->addColumn('session_id', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + 'default' => '', + ), 'Session ID') + ->addColumn('first_visit_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'First Visit Time') + ->addColumn('last_visit_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Last Visit Time') + ->addColumn('last_url_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Last URL ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store ID') + ->setComment('Log Visitors Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/visitor_info' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/visitor_info')) + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Visitor ID') + ->addColumn('http_referer', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'HTTP Referrer') + ->addColumn('http_user_agent', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'HTTP User-Agent') + ->addColumn('http_accept_charset', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'HTTP Accept-Charset') + ->addColumn('http_accept_language', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'HTTP Accept-Language') + ->addColumn('server_addr', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + ), 'Server Address') + ->addColumn('remote_addr', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + ), 'Remote Address') + ->setComment('Log Visitor Info Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'log/visitor_online' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('log/visitor_online')) + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Visitor ID') + ->addColumn('visitor_type', Varien_Db_Ddl_Table::TYPE_TEXT, 1, array( + 'nullable' => false, + ), 'Visitor Type') + ->addColumn('remote_addr', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'nullable' => false, + ), 'Remote Address') + ->addColumn('first_visit_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'First Visit Time') + ->addColumn('last_visit_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Last Visit Time') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer ID') + ->addColumn('last_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Last URL') + ->addIndex($installer->getIdxName('log/visitor_online', array('visitor_type')), + array('visitor_type')) + ->addIndex($installer->getIdxName('log/visitor_online', array('first_visit_at', 'last_visit_at')), + array('first_visit_at', 'last_visit_at')) + ->addIndex($installer->getIdxName('log/visitor_online', array('customer_id')), + array('customer_id')) + ->setComment('Log Visitor Online Table'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-install-0.7.0.php index b157875963..8bff39f5d8 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.0-0.7.1.php index f568d10fae..77944931fd 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.1-0.7.2.php index c8fb68ffa1..2904f9309c 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.3-0.7.4.php index 6ae5523652..6e39dfbd99 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php index 7796519d67..13a328f1bb 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php index 726c46963d..e7138a23fc 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.6-0.7.7.php index c0f830d46d..c2c60bcca1 100644 --- a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Log - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..3d7fc81487 --- /dev/null +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,414 @@ +startSetup(); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('log/customer'), + 'IDX_VISITOR' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('log_visitor_online'), + 'IDX_VISITOR_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('log_visitor_online'), + 'IDX_VISIT_TIME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('log_visitor_online'), + 'IDX_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('log_url'), + 'IDX_VISITOR' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('log/customer') => array( + 'columns' => array( + 'log_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Log ID' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'comment' => 'Visitor ID' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer ID' + ), + 'login_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Login Time' + ), + 'logout_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Logout Time' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ) + ), + 'comment' => 'Log Customers Table' + ), + $installer->getTable('log/visitor') => array( + 'columns' => array( + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Visitor ID' + ), + 'session_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Session ID' + ), + 'first_visit_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'First Visit Time' + ), + 'last_visit_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Last Visit Time' + ), + 'last_url_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Last URL ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ) + ), + 'comment' => 'Log Visitors Table' + ), + $installer->getTable('log/visitor_info') => array( + 'columns' => array( + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Visitor ID' + ), + 'http_referer' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'HTTP Referrer' + ), + 'http_user_agent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'HTTP User-Agent' + ), + 'http_accept_charset' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'HTTP Accept-Charset' + ), + 'http_accept_language' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'HTTP Accept-Language' + ), + 'server_addr' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'comment' => 'Server Address' + ), + 'remote_addr' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'comment' => 'Remote Address' + ) + ), + 'comment' => 'Log Visitor Info Table' + ), + $installer->getTable('log/url_table') => array( + 'columns' => array( + 'url_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'URL ID' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'comment' => 'Visitor ID' + ), + 'visit_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Visit Time' + ) + ), + 'comment' => 'Log URL Table' + ), + $installer->getTable('log/url_info_table') => array( + 'columns' => array( + 'url_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'URL ID' + ), + 'url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => '', + 'comment' => 'URL' + ), + 'referer' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Referrer' + ) + ), + 'comment' => 'Log URL Info Table' + ), + $installer->getTable('log/summary_table') => array( + 'columns' => array( + 'summary_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Summary ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store ID' + ), + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Type ID' + ), + 'visitor_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Visitor Count' + ), + 'customer_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Count' + ), + 'add_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Date' + ) + ), + 'comment' => 'Log Summary Table' + ), + $installer->getTable('log/summary_type_table') => array( + 'columns' => array( + 'type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Type ID' + ), + 'type_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Type Code' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Period' + ), + 'period_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 6, + 'nullable' => false, + 'default' => 'MINUTE', + 'comment' => 'Period Type' + ) + ), + 'comment' => 'Log Summary Types Table' + ), + $installer->getTable('log/quote_table') => array( + 'columns' => array( + 'quote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Quote ID' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'comment' => 'Visitor ID' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Creation Time' + ), + 'deleted_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Deletion Time' + ) + ), + 'comment' => 'Log Quotes Table' + ), + $installer->getTable('log/visitor_online') => array( + 'columns' => array( + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Visitor ID' + ), + 'visitor_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 1, + 'nullable' => false, + 'comment' => 'Visitor Type' + ), + 'remote_addr' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'nullable' => false, + 'comment' => 'Remote Address' + ), + 'first_visit_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'First Visit Time' + ), + 'last_visit_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Last Visit Time' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer ID' + ), + 'last_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Last URL' + ) + ), + 'comment' => 'Log Visitor Online Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('log/customer'), + $installer->getIdxName('log/customer', array('visitor_id')), + array('visitor_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('log/url_table'), + $installer->getIdxName('log/url_table', array('visitor_id')), + array('visitor_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('log/visitor_online'), + $installer->getIdxName('log/visitor_online', array('visitor_type')), + array('visitor_type') +); + +$installer->getConnection()->addIndex( + $installer->getTable('log/visitor_online'), + $installer->getIdxName('log/visitor_online', array('first_visit_at', 'last_visit_at')), + array('first_visit_at', 'last_visit_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('log/visitor_online'), + $installer->getIdxName('log/visitor_online', array('customer_id')), + array('customer_id') +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Media/Helper/Data.php b/app/code/core/Mage/Media/Helper/Data.php index 536e73f180..b5613f0f04 100644 --- a/app/code/core/Mage/Media/Helper/Data.php +++ b/app/code/core/Mage/Media/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Media - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Media/Model/File/Image.php b/app/code/core/Mage/Media/Model/File/Image.php index 8e8ffb4922..346c7c2e1c 100644 --- a/app/code/core/Mage/Media/Model/File/Image.php +++ b/app/code/core/Mage/Media/Model/File/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Media - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Media/Model/Image.php b/app/code/core/Mage/Media/Model/Image.php index a6093ef714..e05bfd6c3d 100644 --- a/app/code/core/Mage/Media/Model/Image.php +++ b/app/code/core/Mage/Media/Model/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Media - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Media/Model/Image/Config/Interface.php b/app/code/core/Mage/Media/Model/Image/Config/Interface.php index 7138f741c5..8b5fac849c 100644 --- a/app/code/core/Mage/Media/Model/Image/Config/Interface.php +++ b/app/code/core/Mage/Media/Model/Image/Config/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Media - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Media/etc/config.xml b/app/code/core/Mage/Media/etc/config.xml index 68d04f8e0b..7115d4c05e 100644 --- a/app/code/core/Mage/Media/etc/config.xml +++ b/app/code/core/Mage/Media/etc/config.xml @@ -21,25 +21,26 @@ * * @category Mage * @package Mage_Media - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 Mage_Media_Model - media_file + media_resource - - Mage_Media_Model_File - + + Mage_Media_Model_Resource + media_mysql4 + @@ -72,5 +73,5 @@
      - +
      diff --git a/app/code/core/Mage/Newsletter/Block/Subscribe.php b/app/code/core/Mage/Newsletter/Block/Subscribe.php index 2c0a72f128..2e104b2430 100644 --- a/app/code/core/Mage/Newsletter/Block/Subscribe.php +++ b/app/code/core/Mage/Newsletter/Block/Subscribe.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/Helper/Data.php b/app/code/core/Mage/Newsletter/Helper/Data.php index 6a40563315..e1f06c2c5a 100644 --- a/app/code/core/Mage/Newsletter/Helper/Data.php +++ b/app/code/core/Mage/Newsletter/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/Model/Message.php b/app/code/core/Mage/Newsletter/Model/Message.php index 610bbf130f..b5b00aafdc 100644 --- a/app/code/core/Mage/Newsletter/Model/Message.php +++ b/app/code/core/Mage/Newsletter/Model/Message.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Problem.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Problem.php index 055e9d727c..77ac9f478f 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Problem.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Problem.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,16 +28,10 @@ /** * Mage newsletter problem resource model * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ -class Mage_Newsletter_Model_Mysql4_Problem extends Mage_Core_Model_Mysql4_Abstract +class Mage_Newsletter_Model_Mysql4_Problem extends Mage_Newsletter_Model_Resource_Problem { - - protected function _construct() - { - $this->_init('newsletter/problem', 'problem_id'); - } - } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Problem/Collection.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Problem/Collection.php index 9f0897408a..b6c44eef18 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Problem/Collection.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Problem/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,84 +28,10 @@ /** * Newsletter problem model collection * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ -class Mage_Newsletter_Model_Mysql4_Problem_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Newsletter_Model_Mysql4_Problem_Collection extends Mage_Newsletter_Model_Resource_Problem_Collection { - - protected $_subscribersInfoJoinedFlag = false; - protected $_problemGrouped = false; - - protected function _construct() - { - $this->_init('newsletter/problem'); - } - - public function addSubscriberInfo() - { - $this->getSelect() - ->joinLeft(array('subscriber'=>$this->getTable('subscriber')),'main_table.subscriber_id = subscriber.subscriber_id', - array('subscriber_email','customer_id','subscriber_status')); - $this->_subscribersInfoJoinedFlag = true; - - return $this; - } - - public function addQueueInfo() - { - $this->getSelect() - ->joinLeft(array('queue'=>$this->getTable('queue')),'main_table.queue_id = queue.queue_id', - array('queue_start_at', 'queue_finish_at')) - ->joinLeft(array('template'=>$this->getTable('template')),'main_table.queue_id = queue.queue_id', - array('template_subject','template_code','template_sender_name','template_sender_email')); - return $this; - } - - - /** - * Loads customers info to collection - * - */ - protected function _addCustomersData( ) - { - $customersIds = array(); - - foreach ($this->getItems() as $item) { - if($item->getCustomerId()) { - $customersIds[] = $item->getCustomerId(); - } - } - - if(count($customersIds) == 0) { - return; - } - - $customers = Mage::getResourceModel('customer/customer_collection') - ->addNameToSelect() - ->addAttributeToFilter('entity_id', array("in"=>$customersIds)); - - $customers->load(); - - foreach($customers->getItems() as $customer) { - $problems = $this->getItemsByColumnValue('customer_id', $customer->getId()); - foreach ($problems as $problem) { - $problem->setCustomerName($customer->getName()) - ->setCustomerFirstName($customer->getFirstName()) - ->setCustomerLastName($customer->getLastName()); - } - } - - } - - public function load($printQuery=false, $logQuery=false) - { - parent::load($printQuery, $logQuery); - if($this->_subscribersInfoJoinedFlag && !$this->isLoaded()) { - $this->_addCustomersData(); - } - return $this; - } - } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Queue.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Queue.php index ae1421fab2..e8acfcd4c9 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Queue.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Queue.php @@ -20,160 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Newsletter queue saver - * - * @category Mage - * @package Mage_Newsletter + * + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team - */ -class Mage_Newsletter_Model_Mysql4_Queue extends Mage_Core_Model_Mysql4_Abstract + */ +class Mage_Newsletter_Model_Mysql4_Queue extends Mage_Newsletter_Model_Resource_Queue { - - protected function _construct() - { - $this->_init('newsletter/queue', 'queue_id'); - } - - /** - * Add subscribers to queue - * - * @param Mage_Newsletter_Model_Queue $queue - * @param array $subscriberIds - */ - public function addSubscribersToQueue(Mage_Newsletter_Model_Queue $queue, array $subscriberIds) - { - if (count($subscriberIds)==0) { - Mage::throwException(Mage::helper('newsletter')->__('No subscribers selected.')); - } - - if (!$queue->getId() && $queue->getQueueStatus()!=Mage_Newsletter_Model_Queue::STATUS_NEVER) { - Mage::throwException(Mage::helper('newsletter')->__('Invalid queue selected.')); - } - - $select = $this->_getWriteAdapter()->select(); - $select->from($this->getTable('queue_link'),'subscriber_id') - ->where('queue_id = ?', $queue->getId()) - ->where('subscriber_id in (?)', $subscriberIds); - - $usedIds = $this->_getWriteAdapter()->fetchCol($select); - $this->_getWriteAdapter()->beginTransaction(); - try { - foreach($subscriberIds as $subscriberId) { - if(in_array($subscriberId, $usedIds)) { - continue; - } - $data = array(); - $data['queue_id'] = $queue->getId(); - $data['subscriber_id'] = $subscriberId; - $this->_getWriteAdapter()->insert($this->getTable('queue_link'), $data); - } - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - } - - } - - public function removeSubscribersFromQueue(Mage_Newsletter_Model_Queue $queue) - { - try { - $this->_getWriteAdapter()->delete( - $this->getTable('queue_link'), - array( - $this->_getWriteAdapter()->quoteInto('queue_id = ?', $queue->getId()), - 'letter_sent_at IS NULL' - ) - ); - - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - } - - } - - public function setStores(Mage_Newsletter_Model_Queue $queue) - { - $this->_getWriteAdapter() - ->delete( - $this->getTable('queue_store_link'), - $this->_getWriteAdapter()->quoteInto('queue_id = ?', $queue->getId()) - ); - - if (!is_array($queue->getStores())) { - $stores = array(); - } else { - $stores = $queue->getStores(); - } - - foreach ($stores as $storeId) { - $data = array(); - $data['store_id'] = $storeId; - $data['queue_id'] = $queue->getId(); - $this->_getWriteAdapter()->insert($this->getTable('queue_store_link'), $data); - } - $this->removeSubscribersFromQueue($queue); - - if(count($stores) == 0) { - return $this; - } - - $subscribers = Mage::getResourceSingleton('newsletter/subscriber_collection') - ->addFieldToFilter('store_id', array('in'=>$stores)) - ->useOnlySubscribed() - ->load(); - - $subscriberIds = array(); - - foreach ($subscribers as $subscriber) { - $subscriberIds[] = $subscriber->getId(); - } - - if (count($subscriberIds) > 0) { - $this->addSubscribersToQueue($queue, $subscriberIds); - } - - return $this; - } - - /* - * Retrieving store id-s if they defined - * - * @param Mage_Newsletter_Model_Queue - * @return array - * */ - public function getStores(Mage_Newsletter_Model_Queue $queue) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('queue_store_link'), 'store_id') - ->where('queue_id = ?', $queue->getId()); - - if(!($result = $this->_getReadAdapter()->fetchCol($select))) { - $result = array(); - } - - return $result; - } - - /** - * Saving template after saving queue action - * - * @param Mage_Core_Model_Abstract $queue - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _afterSave(Mage_Core_Model_Abstract $queue) - { - if($queue->getSaveStoresFlag()) { - $this->setStores($queue); - } - return $this; - } - } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Queue/Collection.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Queue/Collection.php index f8cb6a8025..158a02b92e 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Queue/Collection.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Queue/Collection.php @@ -20,184 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Newsletter queue collection. * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ - -class Mage_Newsletter_Model_Mysql4_Queue_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Newsletter_Model_Mysql4_Queue_Collection extends Mage_Newsletter_Model_Resource_Queue_Collection { - protected $_addSubscribersFlag = false; - /** - * @var bool - */ - protected $_isStoreFilter = false; - - /** - * Initializes collection - */ - protected function _construct() - { - $this->_map['fields']['queue_id'] = 'main_table.queue_id'; - $this->_init('newsletter/queue'); - } - - /** - * Joines templates information - * - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - * @deprecated since 1.4.0.1 - */ - public function addTemplateInfo() { - $this->getSelect()->joinLeft(array('template'=>$this->getTable('template')), - 'template.template_id=main_table.template_id', - array('template_subject','template_sender_name','template_sender_email')); - $this->_joinedTables['template'] = true; - return $this; - } - - protected function _addSubscriberInfoToSelect() - { - $this->_addSubscribersFlag = true; - $this->getSize(); // Executing of count query! - $select = $this->getConnection() - ->select() - ->from(array('link_total' => $this->getTable('queue_link')), 'COUNT(DISTINCT `link_total`.`queue_link_id`)') - ->where('`main_table`.`queue_id` = `link_total`.`queue_id`'); - $this->getSelect() - ->joinLeft(array('link_sent'=>$this->getTable('queue_link')), - 'main_table.queue_id=link_sent.queue_id and link_sent.letter_sent_at IS NOT NULL', - array( - new Zend_Db_Expr('COUNT(DISTINCT `link_sent`.`queue_link_id`) AS `subscribers_sent`'), - new Zend_Db_Expr('(' . $select . ') AS `subscribers_total`') - )) - ->group('main_table.queue_id'); - return $this; - } - - public function load($printQuery=false, $logQuery=false) - { - if($this->_addSubscribersFlag && !$this->isLoaded()) { - $this->_addSubscriberInfoToSelect(); - } - return parent::load($printQuery, $logQuery); - } - - /** - * Joines subscribers information - * - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - */ - public function addSubscribersInfo() - { - $this->_addSubscribersFlag = true; - return $this; - } - - public function addFieldToFilter($field, $condition=null) - { - if(in_array($field, array('subscribers_total', 'subscribers_sent'))) { - $this->addFieldToFilter('main_table.queue_id', array('in'=>$this->_getIdsFromLink($field, $condition))); - return $this; - } else { - return parent::addFieldToFilter($field, $condition); - } - } - - protected function _getIdsFromLink($field, $condition) { - $select = $this->getConnection()->select() - ->from($this->getTable('queue_link'), array('queue_id', 'COUNT(queue_link_id) as total')) - ->group('queue_id') - ->having($this->_getConditionSql('total', $condition)); - - if($field == 'subscribers_sent') { - $select->where('letter_sent_at IS NOT NULL'); - } - - $idList = $this->getConnection()->fetchCol($select); - - if(count($idList)) { - return $idList; - } - - return array(0); - } - - /** - * Set filter for queue by subscriber. - * - * @param int $subscriberId - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - */ - public function addSubscriberFilter($subscriberId) - { - $this->getSelect() - ->join(array('link'=>$this->getTable('queue_link')), - 'main_table.queue_id=link.queue_id', - array('letter_sent_at') - ) - ->where('link.subscriber_id = ?', $subscriberId); - - return $this; - } - - /** - * Add filter by only ready fot sending item - * - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - */ - public function addOnlyForSendingFilter() - { - $this->getSelect() - ->where('main_table.queue_status in (?)', array(Mage_Newsletter_Model_Queue::STATUS_SENDING, - Mage_Newsletter_Model_Queue::STATUS_NEVER)) - ->where('main_table.queue_start_at < ?', Mage::getSingleton('core/date')->gmtdate()) - ->where('main_table.queue_start_at IS NOT NULL'); - - return $this; - } - - /** - * Add filter by only not sent items - * - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - */ - public function addOnlyUnsentFilter() - { - $this->getSelect() - ->where('main_table.queue_status = ?', Mage_Newsletter_Model_Queue::STATUS_NEVER); - - return $this; - } - - public function toOptionArray() - { - return $this->_toOptionArray('queue_id', 'template_subject'); - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_Newsletter_Model_Mysql4_Queue_Collection - */ - public function addStoreFilter($storeIds) - { - if (!$this->_isStoreFilter) { - $this->getSelect()->joinInner(array('store_link' => $this->getTable('queue_store_link')), - 'main_table.queue_id = store_link.queue_id', array() - ) - ->where('store_link.store_id IN (?)', $storeIds) - ->group('main_table.queue_id'); - $this->_isStoreFilter = true; - } - return $this; - } } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php index d7a3646a62..9d0fcaa2db 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber.php @@ -20,156 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Newsletter subscriber model for MySQL4 * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ -class Mage_Newsletter_Model_Mysql4_Subscriber extends Mage_Core_Model_Mysql4_Abstract +class Mage_Newsletter_Model_Mysql4_Subscriber extends Mage_Newsletter_Model_Resource_Subscriber { - /** - * DB read connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_read; - - /** - * DB write connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_write; - - /** - * Name of subscriber DB table - * - * @var string - */ - protected $_subscriberTable; - - /** - * Name of subscriber link DB table - * - * @var string - */ - protected $_subscriberLinkTable; - - /** - * Name of scope for error messages - * - * @var string - */ - protected $_messagesScope = 'newsletter/session'; - - /** - * Initialize resource model - * - * Get tablename from config - */ - protected function _construct() - { - $this->_init('newsletter/subscriber', 'subscriber_id'); - $this->_subscriberTable = Mage::getSingleton('core/resource')->getTableName("newsletter/subscriber"); - $this->_subscriberLinkTable = Mage::getSingleton('core/resource')->getTableName("newsletter/queue_link"); - $this->_read = $this->_getReadAdapter(); - $this->_write = $this->_getWriteAdapter(); - } - /** - * Set error messages scope - * - * @param string $scope - */ - public function setMessagesScope($scope) - { - $this->_messagesScope = $scope; - } - - /** - * Load subscriber from DB by email - * - * @param string $subscriberEmail - * @return array - */ - public function loadByEmail($subscriberEmail) - { - $select = $this->_read->select() - ->from($this->_subscriberTable) - ->where('subscriber_email=?',$subscriberEmail); - - $result = $this->_read->fetchRow($select); - - if(!$result) { - return array(); - } - - return $result; - } - - - - /** - * Load subscriber by customer - * - * @param Mage_Customer_Model_Customer $customer - * @return array - */ - public function loadByCustomer(Mage_Customer_Model_Customer $customer) - { - $select = $this->_read->select() - ->from($this->_subscriberTable) - ->where('customer_id=?',$customer->getId()); - - $result = $this->_read->fetchRow($select); - - if ($result) { - return $result; - } - - $select = $this->_read->select() - ->from($this->_subscriberTable) - ->where('subscriber_email=?',$customer->getEmail()); - - $result = $this->_read->fetchRow($select); - - if ($result) { - return $result; - } - - return array(); - } - - /** - * Generates random code for subscription confirmation - * - * @return string - */ - protected function _generateRandomCode() - { - return Mage::helper('core')->uniqHash(); - } - - public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) - { - $this->_write->beginTransaction(); - try { - $data['letter_sent_at'] = now(); - $this->_write->update($this->_subscriberLinkTable, - $data, - array($this->_write->quoteInto('subscriber_id=?', $subscriber->getId()), - $this->_write->quoteInto('queue_id=?', $queue->getId()))); - $this->_write->commit(); - } - catch (Exception $e) { - $this->_write->rollBack(); - Mage::throwException(Mage::helper('newsletter')->__('Cannot mark as received subscriber.')); - } - return $this; - } } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber/Collection.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber/Collection.php index 51867e4a45..98741c10d3 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber/Collection.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Subscriber/Collection.php @@ -20,251 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Newsletter Subscribers Collection * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team - * @todo Refactoring this collection to Mage_Core_Model_Mysql4_Collection_Abstract. */ - -class Mage_Newsletter_Model_Mysql4_Subscriber_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Newsletter_Model_Mysql4_Subscriber_Collection extends Mage_Newsletter_Model_Resource_Subscriber_Collection { - /** - * Subscribers table name - * - * @var string - */ - protected $_subscriberTable; - - /** - * Queue link table name - * - * @var string - */ - protected $_queueLinkTable; - - /** - * Store table name - * - * @var string - */ - protected $_storeTable; - - /** - * Queue joined flag - * - * @var boolean - */ - protected $_queueJoinedFlag = false; - - /** - * Flag that indicates apply of customers info on load - * - * @var boolean - */ - protected $_showCustomersInfo = false; - - /** - * Filter for count - * - * @var unknown_type - */ - protected $_countFilterPart = array(); - - /** - * Constructor - * - * Configures collection - */ - protected function _construct() - { - parent::_construct(); - $this->_subscriberTable = Mage::getSingleton('core/resource')->getTableName('newsletter/subscriber'); - $this->_queueLinkTable = Mage::getSingleton('core/resource')->getTableName('newsletter/queue_link'); - $this->_storeTable = Mage::getSingleton('core/resource')->getTableName('core/store'); - $this->_init('newsletter/subscriber'); - - // defining mapping for fields represented in several tables - $this->_map['fields']['customer_lastname'] = 'customer_lastname_table.value'; - $this->_map['fields']['customer_firstname'] = 'customer_firstname_table.value'; - $this->_map['fields']['type'] = 'IF(main_table.customer_id = 0, 1, 2)'; - $this->_map['fields']['website_id'] = 'store.website_id'; - $this->_map['fields']['group_id'] = 'store.group_id'; - $this->_map['fields']['store_id'] = 'main_table.store_id'; - } - - /** - * Set loading mode subscribers by queue - * - * @param Mage_Newsletter_Model_Queue $queue - */ - public function useQueue(Mage_Newsletter_Model_Queue $queue) - { - $this->getSelect()->join(array('link'=>$this->_queueLinkTable), "link.subscriber_id = main_table.subscriber_id", array()) - ->where("link.queue_id = ? ", $queue->getId()); - $this->_queueJoinedFlag = true; - return $this; - } - - /** - * Set using of links to only unsendet letter subscribers. - */ - public function useOnlyUnsent( ) - { - if($this->_queueJoinedFlag) { - $this->getSelect()->where("link.letter_sent_at IS NULL"); - } - - return $this; - } - - /** - * Adds customer info to select - * - * @return Mage_Newsletter_Model_Mysql4_Subscriber_Collection - */ - public function showCustomerInfo() - { - $customer = Mage::getModel('customer/customer'); - /* @var $customer Mage_Customer_Model_Customer */ - $firstname = $customer->getAttribute('firstname'); - $lastname = $customer->getAttribute('lastname'); - -// $customersCollection = Mage::getModel('customer/customer')->getCollection(); -// /* @var $customersCollection Mage_Customer_Model_Entity_Customer_Collection */ -// $firstname = $customersCollection->getAttribute('firstname'); -// $lastname = $customersCollection->getAttribute('lastname'); - - $this->getSelect() - ->joinLeft( - array('customer_lastname_table'=>$lastname->getBackend()->getTable()), - 'customer_lastname_table.entity_id=main_table.customer_id - AND customer_lastname_table.attribute_id = '.(int) $lastname->getAttributeId() . ' - ', - array('customer_lastname'=>'value') - ) - ->joinLeft( - array('customer_firstname_table'=>$firstname->getBackend()->getTable()), - 'customer_firstname_table.entity_id=main_table.customer_id - AND customer_firstname_table.attribute_id = '.(int) $firstname->getAttributeId() . ' - ', - array('customer_firstname'=>'value') - ); - - return $this; - } - - /** - * Add type field expression to select - * - * @return Mage_Newsletter_Model_Mysql4_Subscriber_Collection - */ - public function addSubscriberTypeField() - { - $this->getSelect() - ->columns(array('type'=>new Zend_Db_Expr($this->_getMappedField('type')))); - return $this; - } - - /** - * Sets flag for customer info loading on load - * - * @param boolean $show - * @return Mage_Newsletter_Model_Mysql4_Subscriber_Collection - */ - public function showStoreInfo() - { - $this->getSelect()->join( - array('store' => $this->_storeTable), - 'store.store_id = main_table.store_id', - array('group_id', 'website_id') - ); - - return $this; - } - - /** - * @deprecated after 1.4.0.0-rc1 - * - * @param string $field - * @return string - */ - public function _getFieldTableAlias($field) - { - if (strpos($field,'customer') === 0) { - return $field .'_table.value'; - } - - if($field=='type') { - return new Zend_Db_Expr('IF(main_table.customer_id = 0, 1, 2)'); - } - - if(in_array($field, array('website_id','group_id'))) { - return 'store.' . $field; - } - - return 'main_table.' . $field; - } - - public function getSelectCountSql() - { - $this->_renderFilters(); - - $countSelect = clone $this->getSelect(); - - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - foreach ($this->_countFilterPart as $where) { - $countSelect->where($where); - } - - - // TODO: $ql->from('table',new Zend_Db_Expr('COUNT(*)')); - $sql = $countSelect->__toString(); - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(*) from ', $sql); - - return $sql; - } - - - /** - * Load only subscribed customers - */ - public function useOnlyCustomers() - { - $this->getSelect()->where("main_table.customer_id > 0"); - - return $this; - } - - /** - * Show only with subscribed status - */ - public function useOnlySubscribed() - { - $this->getSelect()->where("main_table.subscriber_status = ?", Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED); - - return $this; - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_Newsletter_Model_Mysql4_Subscriber_Collection - */ - public function addStoreFilter($storeIds) - { - $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); - return $this; - } } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Template.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Template.php index dc0095abb1..bd0010ffe6 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Template.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Template.php @@ -20,121 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Template db resource * - * @category Mage - * @package Mage_Newsletter + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ -class Mage_Newsletter_Model_Mysql4_Template extends Mage_Core_Model_Mysql4_Abstract +class Mage_Newsletter_Model_Mysql4_Template extends Mage_Newsletter_Model_Resource_Template { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('newsletter/template', 'template_id'); - } - - /** - * Load an object by template code - * - * @param Mage_Newsletter_Model_Template $object - * @param string $templateCode - * @return Mage_Newsletter_Model_Mysql4_Template - */ - public function loadByCode(Mage_Newsletter_Model_Template $object, $templateCode) - { - $read = $this->_getReadAdapter(); - if ($read && !is_null($templateCode)) { - $select = $this->_getLoadSelect('template_code', $templateCode, $object) - ->where('template_actual=?', 1); - $data = $read->fetchRow($select); - - if ($data) { - $object->setData($data); - } - } - - $this->_afterLoad($object); - - return $this; - } - - /** - * Check usage of template in queue - * - * @param Mage_Newsletter_Model_Template $template - * @return boolean - */ - public function checkUsageInQueue(Mage_Newsletter_Model_Template $template) - { - if ($template->getTemplateActual() !== 0 && !$template->getIsSystem()) { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('newsletter/queue'), new Zend_Db_Expr('COUNT(queue_id)')) - ->where('template_id=?',$template->getId()); - - $countOfQueue = $this->_getReadAdapter()->fetchOne($select); - - return $countOfQueue > 0; - } - elseif ($template->getIsSystem()) { - return false; - } - else { - return true; - } - } - - /** - * Check usage of template code in other templates - * - * @param Mage_Newsletter_Model_Template $template - * @return boolean - */ - public function checkCodeUsage(Mage_Newsletter_Model_Template $template) - { - if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), new Zend_Db_Expr('COUNT(template_id)')) - ->where('template_id!=?',$template->getId()) - ->where('template_code=?',$template->getTemplateCode()) - ->where('template_actual=?',1); - - $countOfCodes = $this->_getReadAdapter()->fetchOne($select); - - return $countOfCodes > 0; - } else { - return false; - } - } - - /** - * Perform actions before object save - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Newsletter_Model_Mysql4_Template - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if ($this->checkCodeUsage($object)) { - Mage::throwException(Mage::helper('newsletter')->__('Duplicate template code.')); - } - - if (!$object->hasTemplateActual()) { - $object->setTemplateActual(1); - } - if (!$object->hasAddedAt()) { - $object->setAddedAt(Mage::getSingleton('core/date')->gmtDate()); - } - $object->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); - - return parent::_beforeSave($object); - } } diff --git a/app/code/core/Mage/Newsletter/Model/Mysql4/Template/Collection.php b/app/code/core/Mage/Newsletter/Model/Mysql4/Template/Collection.php index 32a88b5f92..0bcd66f4c1 100644 --- a/app/code/core/Mage/Newsletter/Model/Mysql4/Template/Collection.php +++ b/app/code/core/Mage/Newsletter/Model/Mysql4/Template/Collection.php @@ -20,55 +20,18 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Templates collection - * - * @category Mage - * @package Mage_Newsletter + * + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ -class Mage_Newsletter_Model_Mysql4_Template_Collection extends Varien_Data_Collection_Db +class Mage_Newsletter_Model_Mysql4_Template_Collection extends Mage_Newsletter_Model_Resource_Template_Collection { - /** - * Template table name - * - * @var string - */ - protected $_templateTable; - - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('newsletter_read')); - $this->_templateTable = Mage::getSingleton('core/resource')->getTableName('newsletter/template'); - $this->_select->from($this->_templateTable, array('template_id','template_code', - 'template_type', - 'template_subject','template_sender_name', - 'template_sender_email', - 'added_at', - 'modified_at' - )); - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('newsletter/template')); - } - - /** - * Load only actual template - * - * @return Mage_Newsletter_Model_Mysql4_Template_Collection - */ - public function useOnlyActual() - { - $this->_select->where('template_actual=?', 1); - - return $this; - } - - public function toOptionArray() - { - return $this->_toOptionArray('template_id', 'template_code'); - } - } diff --git a/app/code/core/Mage/Newsletter/Model/Observer.php b/app/code/core/Mage/Newsletter/Model/Observer.php index 139324ed31..26b3e1c793 100644 --- a/app/code/core/Mage/Newsletter/Model/Observer.php +++ b/app/code/core/Mage/Newsletter/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/Model/Problem.php b/app/code/core/Mage/Newsletter/Model/Problem.php index ede295eaa7..59b5b65783 100644 --- a/app/code/core/Mage/Newsletter/Model/Problem.php +++ b/app/code/core/Mage/Newsletter/Model/Problem.php @@ -20,15 +20,26 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Newsletter problem model * - * @category Mage - * @package Mage_Newsletter + * @method Mage_Newsletter_Model_Resource_Problem _getResource() + * @method Mage_Newsletter_Model_Resource_Problem getResource() + * @method int getSubscriberId() + * @method Mage_Newsletter_Model_Problem setSubscriberId(int $value) + * @method int getQueueId() + * @method Mage_Newsletter_Model_Problem setQueueId(int $value) + * @method int getProblemErrorCode() + * @method Mage_Newsletter_Model_Problem setProblemErrorCode(int $value) + * @method string getProblemErrorText() + * @method Mage_Newsletter_Model_Problem setProblemErrorText(string $value) + * + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ class Mage_Newsletter_Model_Problem extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Newsletter/Model/Queue.php b/app/code/core/Mage/Newsletter/Model/Queue.php index 7486bf4d3d..01151e27aa 100644 --- a/app/code/core/Mage/Newsletter/Model/Queue.php +++ b/app/code/core/Mage/Newsletter/Model/Queue.php @@ -20,16 +20,39 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Newsletter queue model. * - * @category Mage - * @package Mage_Newsletter - * @author Magento Core Team + * @method Mage_Newsletter_Model_Resource_Queue _getResource() + * @method Mage_Newsletter_Model_Resource_Queue getResource() + * @method int getTemplateId() + * @method Mage_Newsletter_Model_Queue setTemplateId(int $value) + * @method int getNewsletterType() + * @method Mage_Newsletter_Model_Queue setNewsletterType(int $value) + * @method string getNewsletterText() + * @method Mage_Newsletter_Model_Queue setNewsletterText(string $value) + * @method string getNewsletterStyles() + * @method Mage_Newsletter_Model_Queue setNewsletterStyles(string $value) + * @method string getNewsletterSubject() + * @method Mage_Newsletter_Model_Queue setNewsletterSubject(string $value) + * @method string getNewsletterSenderName() + * @method Mage_Newsletter_Model_Queue setNewsletterSenderName(string $value) + * @method string getNewsletterSenderEmail() + * @method Mage_Newsletter_Model_Queue setNewsletterSenderEmail(string $value) + * @method int getQueueStatus() + * @method Mage_Newsletter_Model_Queue setQueueStatus(int $value) + * @method string getQueueStartAt() + * @method Mage_Newsletter_Model_Queue setQueueStartAt(string $value) + * @method string getQueueFinishAt() + * @method Mage_Newsletter_Model_Queue setQueueFinishAt(string $value) + * + * @category Mage + * @package Mage_Newsletter + * @author Magento Core Team */ class Mage_Newsletter_Model_Queue extends Mage_Core_Model_Template { @@ -48,22 +71,22 @@ class Mage_Newsletter_Model_Queue extends Mage_Core_Model_Template /** * save template flag - * + * * @var boolean - * @deprecated since 1.4.0.1 + * @deprecated since 1.4.0.1 */ protected $_saveTemplateFlag = false; /** * Save stores flag. - * + * * @var boolean */ protected $_saveStoresFlag = false; /** * Stores assigned to queue. - * + * * @var array */ protected $_stores = array(); @@ -126,7 +149,7 @@ public function addTemplateData($data) /** * Set $_data['queue_start'] based on string from backend, which based on locale. - * + * * @param string|null $startAt start date of the mailing queue * @return Mage_Newsletter_Model_Queue */ @@ -148,7 +171,7 @@ public function setQueueStartAtByString($startAt) * * @param int $count * @param array $additionalVariables - * @return Mage_Newsletter_Model_Queue + * @return Mage_Newsletter_Model_Queue */ public function sendPerSubscriber($count=20, array $additionalVariables=array()) { @@ -199,7 +222,7 @@ public function sendPerSubscriber($count=20, array $additionalVariables=array()) } if(count($collection->getItems()) < $count-1 || count($collection->getItems()) == 0) { - $this->setQueueFinishAt(now()); + $this->setQueueFinishAt(Mage::getSingleton('core/date')->gmtDate()); $this->setQueueStatus(self::STATUS_SENT); $this->save(); } @@ -208,7 +231,7 @@ public function sendPerSubscriber($count=20, array $additionalVariables=array()) /** * Getter data for saving - * + * * @return array */ public function getDataForSave() @@ -223,7 +246,7 @@ public function getDataForSave() /** * Add subscribers to queue. - * + * * @param array $subscriberIds * @return Mage_Newsletter_Model_Queue */ @@ -235,7 +258,7 @@ public function addSubscribersToQueue(array $subscriberIds) /** * Setter for save template flag. - * + * * @param boolean|integer|string $value * @return Mage_Newsletter_Model_Queue * @deprecated since 1.4.0.1 @@ -248,7 +271,7 @@ public function setSaveTemplateFlag($value) /** * Getter for save template flag. - * + * * @param void * @return boolean * @deprecated since 1.4.0.1 @@ -260,7 +283,7 @@ public function getSaveTemplateFlag() /** * Setter for save stores flag. - * + * * @param boolean|integer|string $value * @return Mage_Newsletter_Model_Queue */ @@ -272,7 +295,7 @@ public function setSaveStoresFlag($value) /** * Getter for save stores flag. - * + * * @param void * @return boolean */ @@ -283,7 +306,7 @@ public function getSaveStoresFlag() /** * Setter for stores of queue. - * + * * @param array * @return Mage_Newsletter_Model_Queue */ @@ -296,7 +319,7 @@ public function setStores(array $storesIds) /** * Getter for stores of queue. - * + * * @return array */ public function getStores() diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Problem.php b/app/code/core/Mage/Newsletter/Model/Resource/Problem.php new file mode 100755 index 0000000000..cbbd32b3c9 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Problem.php @@ -0,0 +1,45 @@ + + */ +class Mage_Newsletter_Model_Resource_Problem extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('newsletter/problem', 'problem_id'); + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Problem/Collection.php b/app/code/core/Mage/Newsletter/Model/Resource/Problem/Collection.php new file mode 100755 index 0000000000..faae66c0f3 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Problem/Collection.php @@ -0,0 +1,142 @@ + + */ +class Mage_Newsletter_Model_Resource_Problem_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * True when subscribers info joined + * + * @var bool + */ + protected $_subscribersInfoJoinedFlag = false; + + /** + * True when grouped + * + * @var bool + */ + protected $_problemGrouped = false; + + /** + * Define resource model and model + * + */ + protected function _construct() + { + $this->_init('newsletter/problem'); + } + + /** + * Adds subscribers info + * + * @return Mage_Newsletter_Model_Resource_Problem_Collection + */ + public function addSubscriberInfo() + { + $this->getSelect()->joinLeft(array('subscriber'=>$this->getTable('newsletter/subscriber')), + 'main_table.subscriber_id = subscriber.subscriber_id', + array('subscriber_email','customer_id','subscriber_status') + ); + $this->_subscribersInfoJoinedFlag = true; + + return $this; + } + + /** + * Adds queue info + * + * @return Mage_Newsletter_Model_Resource_Problem_Collection + */ + public function addQueueInfo() + { + $this->getSelect()->joinLeft(array('queue'=>$this->getTable('newsletter/queue')), + 'main_table.queue_id = queue.queue_id', + array('queue_start_at', 'queue_finish_at') + ) + ->joinLeft(array('template'=>$this->getTable('newsletter/template')), 'main_table.queue_id = queue.queue_id', + array('template_subject','template_code','template_sender_name','template_sender_email') + ); + return $this; + } + + /** + * Loads customers info to collection + * + */ + protected function _addCustomersData() + { + $customersIds = array(); + + foreach ($this->getItems() as $item) { + if ($item->getCustomerId()) { + $customersIds[] = $item->getCustomerId(); + } + } + + if (count($customersIds) == 0) { + return; + } + + $customers = Mage::getResourceModel('customer/customer_collection') + ->addNameToSelect() + ->addAttributeToFilter('entity_id', array("in"=>$customersIds)); + + $customers->load(); + + foreach ($customers->getItems() as $customer) { + $problems = $this->getItemsByColumnValue('customer_id', $customer->getId()); + foreach ($problems as $problem) { + $problem->setCustomerName($customer->getName()) + ->setCustomerFirstName($customer->getFirstName()) + ->setCustomerLastName($customer->getLastName()); + } + } + } + + /** + * Loads collecion and adds customers info + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Newsletter_Model_Resource_Problem_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + parent::load($printQuery, $logQuery); + if ($this->_subscribersInfoJoinedFlag && !$this->isLoaded()) { + $this->_addCustomersData(); + } + return $this; + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Queue.php b/app/code/core/Mage/Newsletter/Model/Resource/Queue.php new file mode 100755 index 0000000000..7d5ab93859 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Queue.php @@ -0,0 +1,193 @@ + + */ +class Mage_Newsletter_Model_Resource_Queue extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('newsletter/queue', 'queue_id'); + } + + /** + * Add subscribers to queue + * + * @param Mage_Newsletter_Model_Queue $queue + * @param array $subscriberIds + */ + public function addSubscribersToQueue(Mage_Newsletter_Model_Queue $queue, array $subscriberIds) + { + if (count($subscriberIds)==0) { + Mage::throwException(Mage::helper('newsletter')->__('No subscribers selected.')); + } + + if (!$queue->getId() && $queue->getQueueStatus()!=Mage_Newsletter_Model_Queue::STATUS_NEVER) { + Mage::throwException(Mage::helper('newsletter')->__('Invalid queue selected.')); + } + + $adapter = $this->_getWriteAdapter(); + + $select = $adapter->select(); + $select->from($this->getTable('newsletter/queue_link'), 'subscriber_id') + ->where('queue_id = ?', $queue->getId()) + ->where('subscriber_id in (?)', $subscriberIds); + + $usedIds = $adapter->fetchCol($select); + $adapter->beginTransaction(); + try { + foreach ($subscriberIds as $subscriberId) { + if (in_array($subscriberId, $usedIds)) { + continue; + } + $data = array(); + $data['queue_id'] = $queue->getId(); + $data['subscriber_id'] = $subscriberId; + $adapter->insert($this->getTable('newsletter/queue_link'), $data); + } + $adapter->commit(); + } + catch (Exception $e) { + $adapter->rollBack(); + } + } + + /** + * Removes subscriber from queue + * + * @param Mage_Newsletter_Model_Queue $queue + */ + public function removeSubscribersFromQueue(Mage_Newsletter_Model_Queue $queue) + { + $adapter = $this->_getWriteAdapter(); + try { + $adapter->delete( + $this->getTable('newsletter/queue_link'), + array( + 'queue_id = ?' => $queue->getId(), + 'letter_sent_at IS NULL' + ) + ); + + $adapter->commit(); + } + catch (Exception $e) { + $adapter->rollBack(); + } + } + + /** + * Links queue to store + * + * @param Mage_Newsletter_Model_Queue $queue + * @return Mage_Newsletter_Model_Resource_Queue + */ + public function setStores(Mage_Newsletter_Model_Queue $queue) + { + $adapter = $this->_getWriteAdapter(); + $adapter->delete( + $this->getTable('newsletter/queue_store_link'), + array('queue_id = ?' => $queue->getId()) + ); + + $stores = $queue->getStores(); + if (!is_array($stores)) { + $stores = array(); + } + + foreach ($stores as $storeId) { + $data = array(); + $data['store_id'] = $storeId; + $data['queue_id'] = $queue->getId(); + $adapter->insert($this->getTable('newsletter/queue_store_link'), $data); + } + $this->removeSubscribersFromQueue($queue); + + if (count($stores) == 0) { + return $this; + } + + $subscribers = Mage::getResourceSingleton('newsletter/subscriber_collection') + ->addFieldToFilter('store_id', array('in'=>$stores)) + ->useOnlySubscribed() + ->load(); + + $subscriberIds = array(); + + foreach ($subscribers as $subscriber) { + $subscriberIds[] = $subscriber->getId(); + } + + if (count($subscriberIds) > 0) { + $this->addSubscribersToQueue($queue, $subscriberIds); + } + + return $this; + } + + /** + * Returns queue linked stores + * + * @param Mage_Newsletter_Model_Queue $queue + * @return array + */ + public function getStores(Mage_Newsletter_Model_Queue $queue) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select()->from($this->getTable('newsletter/queue_store_link'), 'store_id') + ->where('queue_id = :queue_id'); + + if (!($result = $adapter->fetchCol($select, array('queue_id'=>$queue->getId())))) { + $result = array(); + } + + return $result; + } + + /** + * Saving template after saving queue action + * + * @param Mage_Core_Model_Abstract $queue + * @return Mage_Newsletter_Model_Resource_Queue + */ + protected function _afterSave(Mage_Core_Model_Abstract $queue) + { + if ($queue->getSaveStoresFlag()) { + $this->setStores($queue); + } + return $this; + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Queue/Collection.php b/app/code/core/Mage/Newsletter/Model/Resource/Queue/Collection.php new file mode 100755 index 0000000000..811710ce52 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Queue/Collection.php @@ -0,0 +1,253 @@ + + */ +class Mage_Newsletter_Model_Resource_Queue_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * True when subscribers info joined + * + * @var bool + */ + protected $_addSubscribersFlag = false; + + /** + * True when filtered by store + * + * @var bool + */ + protected $_isStoreFilter = false; + + /** + * Initializes collection + * + */ + protected function _construct() + { + $this->_map['fields']['queue_id'] = 'main_table.queue_id'; + $this->_init('newsletter/queue'); + } + + /** + * Joines templates information + * + * @deprecated since 1.4.0.1 + * + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addTemplateInfo() + { + $this->getSelect()->joinLeft(array('template'=>$this->getTable('template')), + 'template.template_id=main_table.template_id', + array('template_subject','template_sender_name','template_sender_email') + ); + $this->_joinedTables['template'] = true; + return $this; + } + + /** + * Adds subscribers info to selelect + * + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + protected function _addSubscriberInfoToSelect() + { + if (!$this->_addSubscribersFlag) { + $this->_addSubscribersFlag = true; + //Possibel solution with join select + $select = $this->getConnection()->select() + ->from(array('qlt' => $this->getTable('newsletter/queue_link')), 'COUNT(qlt.queue_link_id)') + ->where('qlt.queue_id = main_table.queue_id'); + $totalExpr = new Zend_Db_Expr(sprintf('(%s)', $select->assemble())); + $select = $this->getConnection()->select() + ->from(array('qls' => $this->getTable('newsletter/queue_link')), 'COUNT(qls.queue_link_id)') + ->where('qls.queue_id = main_table.queue_id') + ->where('qls.letter_sent_at IS NOT NULL'); + $sentExpr = new Zend_Db_Expr(sprintf('(%s)', $select->assemble())); + + $this->getSelect()->columns(array( + 'subscribers_sent' => $sentExpr, + 'subscribers_total' => $totalExpr + )); + } + return $this; + } + + /** + * Adds subscribers info to select and loads collection + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->_addSubscribersFlag && !$this->isLoaded()) { + $this->_addSubscriberInfoToSelect(); + } + return parent::load($printQuery, $logQuery); + } + + /** + * Joines subscribers information + * + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addSubscribersInfo() + { + $this->_addSubscribersFlag = true; + return $this; + } + + /** + * Checks if field is 'subscribers_total', 'subscribers_sent' + * to add specific filter or adds reguler filter + * + * @param string $field + * @param mixed $condition + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addFieldToFilter($field, $condition = null) + { + if (in_array($field, array('subscribers_total', 'subscribers_sent'))) { + $this->addFieldToFilter('main_table.queue_id', array('in'=>$this->_getIdsFromLink($field, $condition))); + return $this; + } else { + return parent::addFieldToFilter($field, $condition); + } + } + + /** + * Returns ids from queue_link table + * + * @param string $field + * @param mixed $condition + * @return array + */ + protected function _getIdsFromLink($field, $condition) + { + $select = $this->getConnection()->select() + ->from( + $this->getTable('newsletter/queue_link'), + array('queue_id', 'total' => new Zend_Db_Expr('COUNT(queue_link_id)')) + ) + ->group('queue_id') + ->having($this->_getConditionSql('total', $condition)); + + if ($field == 'subscribers_sent') { + $select->where('letter_sent_at IS NOT NULL'); + } + + $idList = $this->getConnection()->fetchCol($select); + + if (count($idList)) { + return $idList; + } + + return array(0); + } + + /** + * Set filter for queue by subscriber. + * + * @param int $subscriberId + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addSubscriberFilter($subscriberId) + { + $this->getSelect()->join(array('link'=>$this->getTable('newsletter/queue_link')), + 'main_table.queue_id=link.queue_id', + array('letter_sent_at') + ) + ->where('link.subscriber_id = ?', $subscriberId); + + return $this; + } + + /** + * Add filter by only ready fot sending item + * + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addOnlyForSendingFilter() + { + $this->getSelect() + ->where('main_table.queue_status in (?)', array(Mage_Newsletter_Model_Queue::STATUS_SENDING, + Mage_Newsletter_Model_Queue::STATUS_NEVER)) + ->where('main_table.queue_start_at < ?', Mage::getSingleton('core/date')->gmtdate()) + ->where('main_table.queue_start_at IS NOT NULL'); + + return $this; + } + + /** + * Add filter by only not sent items + * + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addOnlyUnsentFilter() + { + $this->addFieldToFilter('main_table.queue_status', Mage_Newsletter_Model_Queue::STATUS_NEVER); + + return $this; + } + + /** + * Returns options array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('queue_id', 'template_subject'); + } + + /** + * Filter collection by specified store ids + * + * @param array|int $storeIds + * @return Mage_Newsletter_Model_Resource_Queue_Collection + */ + public function addStoreFilter($storeIds) + { + if (!$this->_isStoreFilter) { + $this->getSelect()->joinInner(array('store_link' => $this->getTable('newsletter/queue_store_link')), + 'main_table.queue_id = store_link.queue_id', array() + ) + ->where('store_link.store_id IN (?)', $storeIds) + ->group('main_table.queue_id'); + $this->_isStoreFilter = true; + } + return $this; + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Subscriber.php b/app/code/core/Mage/Newsletter/Model/Resource/Subscriber.php new file mode 100755 index 0000000000..c94b2ef5df --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Subscriber.php @@ -0,0 +1,174 @@ + + */ +class Mage_Newsletter_Model_Resource_Subscriber extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * DB read connection + * + * @var Zend_Db_Adapter_Abstract + */ + protected $_read; + + /** + * DB write connection + * + * @var Zend_Db_Adapter_Abstract + */ + protected $_write; + + /** + * Name of subscriber link DB table + * + * @var string + */ + protected $_subscriberLinkTable; + + /** + * Name of scope for error messages + * + * @var string + */ + protected $_messagesScope = 'newsletter/session'; + + /** + * Initialize resource model + * Get tablename from config + * + */ + protected function _construct() + { + $this->_init('newsletter/subscriber', 'subscriber_id'); + $this->_subscriberLinkTable = $this->getTable('newsletter/queue_link'); + $this->_read = $this->_getReadAdapter(); + $this->_write = $this->_getWriteAdapter(); + } + + /** + * Set error messages scope + * + * @param string $scope + */ + public function setMessagesScope($scope) + { + $this->_messagesScope = $scope; + } + + /** + * Load subscriber from DB by email + * + * @param string $subscriberEmail + * @return array + */ + public function loadByEmail($subscriberEmail) + { + $select = $this->_read->select() + ->from($this->getMainTable()) + ->where('subscriber_email=:subscriber_email'); + + $result = $this->_read->fetchRow($select, array('subscriber_email'=>$subscriberEmail)); + + if (!$result) { + return array(); + } + + return $result; + } + + /** + * Load subscriber by customer + * + * @param Mage_Customer_Model_Customer $customer + * @return array + */ + public function loadByCustomer(Mage_Customer_Model_Customer $customer) + { + $select = $this->_read->select() + ->from($this->getMainTable()) + ->where('customer_id=:customer_id'); + + $result = $this->_read->fetchRow($select, array('customer_id'=>$customer->getId())); + + if ($result) { + return $result; + } + + $select = $this->_read->select() + ->from($this->getMainTable()) + ->where('subscriber_email=:subscriber_email'); + + $result = $this->_read->fetchRow($select, array('subscriber_email'=>$customer->getEmail())); + + if ($result) { + return $result; + } + + return array(); + } + + /** + * Generates random code for subscription confirmation + * + * @return string + */ + protected function _generateRandomCode() + { + return Mage::helper('core')->uniqHash(); + } + + /** + * Updates data when subscriber received + * + * @param Mage_Newsletter_Model_Subscriber $subscriber + * @param Mage_Newsletter_Model_Queue $queue + * @return Mage_Newsletter_Model_Resource_Subscriber + */ + public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) + { + $this->_write->beginTransaction(); + try { + $data['letter_sent_at'] = Mage::getSingleton('core/date')->gmtDate(); + $this->_write->update($this->_subscriberLinkTable, $data, array( + 'subscriber_id = ?' => $subscriber->getId(), + 'queue_id = ?' => $queue->getId() + )); + $this->_write->commit(); + } + catch (Exception $e) { + $this->_write->rollBack(); + Mage::throwException(Mage::helper('newsletter')->__('Cannot mark as received subscriber.')); + } + return $this; + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Subscriber/Collection.php b/app/code/core/Mage/Newsletter/Model/Resource/Subscriber/Collection.php new file mode 100755 index 0000000000..e76f0f4ff4 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Subscriber/Collection.php @@ -0,0 +1,258 @@ + + */ +class Mage_Newsletter_Model_Resource_Subscriber_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + + /** + * Queue link table name + * + * @var string + */ + protected $_queueLinkTable; + + /** + * Store table name + * + * @var string + */ + protected $_storeTable; + + /** + * Queue joined flag + * + * @var boolean + */ + protected $_queueJoinedFlag = false; + + /** + * Flag that indicates apply of customers info on load + * + * @var boolean + */ + protected $_showCustomersInfo = false; + + /** + * Filter for count + * + * @var array + */ + protected $_countFilterPart = array(); + + /** + * Constructor + * Configures collection + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('newsletter/subscriber'); + $this->_queueLinkTable = $this->getTable('newsletter/queue_link'); + $this->_storeTable = $this->getTable('core/store'); + + + // defining mapping for fields represented in several tables + $this->_map['fields']['customer_lastname'] = 'customer_lastname_table.value'; + $this->_map['fields']['customer_firstname'] = 'customer_firstname_table.value'; + $this->_map['fields']['type'] = $this->getResource()->getReadConnection() + ->getCheckSql('main_table.customer_id = 0', 1, 2); + $this->_map['fields']['website_id'] = 'store.website_id'; + $this->_map['fields']['group_id'] = 'store.group_id'; + $this->_map['fields']['store_id'] = 'main_table.store_id'; + } + + /** + * Set loading mode subscribers by queue + * + * @param Mage_Newsletter_Model_Queue $queue + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function useQueue(Mage_Newsletter_Model_Queue $queue) + { + $this->getSelect() + ->join(array('link'=>$this->_queueLinkTable), "link.subscriber_id = main_table.subscriber_id", array()) + ->where("link.queue_id = ? ", $queue->getId()); + $this->_queueJoinedFlag = true; + return $this; + } + + /** + * Set using of links to only unsendet letter subscribers. + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function useOnlyUnsent() + { + if ($this->_queueJoinedFlag) { + $this->addFieldToFilter('link.letter_sent_at', array('null' => 1)); + } + + return $this; + } + + /** + * Adds customer info to select + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function showCustomerInfo() + { + $adapter = $this->getConnection(); + $customer = Mage::getModel('customer/customer'); + $firstname = $customer->getAttribute('firstname'); + $lastname = $customer->getAttribute('lastname'); + + $this->getSelect() + ->joinLeft( + array('customer_lastname_table'=>$lastname->getBackend()->getTable()), + $adapter->quoteInto('customer_lastname_table.entity_id=main_table.customer_id + AND customer_lastname_table.attribute_id = ?', (int)$lastname->getAttributeId()), + array('customer_lastname'=>'value') + ) + ->joinLeft( + array('customer_firstname_table'=>$firstname->getBackend()->getTable()), + $adapter->quoteInto('customer_firstname_table.entity_id=main_table.customer_id + AND customer_firstname_table.attribute_id = ?', (int)$firstname->getAttributeId()), + array('customer_firstname'=>'value') + ); + + return $this; + } + + /** + * Add type field expression to select + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function addSubscriberTypeField() + { + $this->getSelect() + ->columns(array('type'=>new Zend_Db_Expr($this->_getMappedField('type')))); + return $this; + } + + /** + * Sets flag for customer info loading on load + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function showStoreInfo() + { + $this->getSelect()->join( + array('store' => $this->_storeTable), + 'store.store_id = main_table.store_id', + array('group_id', 'website_id') + ); + + return $this; + } + + /** + * Returns field table alias + * + * @deprecated after 1.4.0.0-rc1 + * + * @param string $field + * @return string + */ + public function _getFieldTableAlias($field) + { + if (strpos($field, 'customer') === 0) { + return $field .'_table.value'; + } + + if ($field == 'type') { + return $this->getConnection()->getCheckSql('main_table.customer_id = 0', 1, 2); + } + + if (in_array($field, array('website_id', 'group_id'))) { + return 'store.' . $field; + } + + return 'main_table.' . $field; + } + + /** + * Returns select count sql + * + * @return string + */ + public function getSelectCountSql() + { + + $select = parent::getSelectCountSql(); + $countSelect = clone $this->getSelect(); + + $countSelect->reset(Zend_Db_Select::HAVING); + + return $select; + } + + /** + * Load only subscribed customers + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function useOnlyCustomers() + { + $this->addFieldToFilter('main_table.customer_id', array('gt' => 0)); + + return $this; + } + + /** + * Show only with subscribed status + * + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function useOnlySubscribed() + { + $this->addFieldToFilter('main_table.subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED); + + return $this; + } + + /** + * Filter collection by specified store ids + * + * @param array|int $storeIds + * @return Mage_Newsletter_Model_Resource_Subscriber_Collection + */ + public function addStoreFilter($storeIds) + { + $this->addFieldToFilter('main_table.store_id', array('in'=>$storeIds)); + return $this; + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Template.php b/app/code/core/Mage/Newsletter/Model/Resource/Template.php new file mode 100755 index 0000000000..5b11aaf237 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Template.php @@ -0,0 +1,144 @@ + + */ +class Mage_Newsletter_Model_Resource_Template extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('newsletter/template', 'template_id'); + } + + /** + * Load an object by template code + * + * @param Mage_Newsletter_Model_Template $object + * @param string $templateCode + * @return Mage_Newsletter_Model_Resource_Template + */ + public function loadByCode(Mage_Newsletter_Model_Template $object, $templateCode) + { + $read = $this->_getReadAdapter(); + if ($read && !is_null($templateCode)) { + $select = $this->_getLoadSelect('template_code', $templateCode, $object) + ->where('template_actual = :template_actual'); + $data = $read->fetchRow($select, array('template_actual'=>1)); + + if ($data) { + $object->setData($data); + } + } + + $this->_afterLoad($object); + + return $this; + } + + /** + * Check usage of template in queue + * + * @param Mage_Newsletter_Model_Template $template + * @return boolean + */ + public function checkUsageInQueue(Mage_Newsletter_Model_Template $template) + { + if ($template->getTemplateActual() !== 0 && !$template->getIsSystem()) { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('newsletter/queue'), new Zend_Db_Expr('COUNT(queue_id)')) + ->where('template_id = :template_id'); + + $countOfQueue = $this->_getReadAdapter()->fetchOne($select, array('template_id'=>$template->getId())); + + return $countOfQueue > 0; + } elseif ($template->getIsSystem()) { + return false; + } else { + return true; + } + } + + /** + * Check usage of template code in other templates + * + * @param Mage_Newsletter_Model_Template $template + * @return boolean + */ + public function checkCodeUsage(Mage_Newsletter_Model_Template $template) + { + if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) { + $bind = array( + 'template_id' => $template->getId(), + 'template_code' => $template->getTemplateCode(), + 'template_actual' => 1 + ); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), new Zend_Db_Expr('COUNT(template_id)')) + ->where('template_id != :template_id') + ->where('template_code = :template_code') + ->where('template_actual = :template_actual'); + + $countOfCodes = $this->_getReadAdapter()->fetchOne($select, $bind); + + return $countOfCodes > 0; + } else { + return false; + } + } + + /** + * Perform actions before object save + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Newsletter_Model_Resource_Template + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if ($this->checkCodeUsage($object)) { + Mage::throwException(Mage::helper('newsletter')->__('Duplicate template code.')); + } + + if (!$object->hasTemplateActual()) { + $object->setTemplateActual(1); + } + if (!$object->hasAddedAt()) { + $object->setAddedAt(Mage::getSingleton('core/date')->gmtDate()); + } + $object->setModifiedAt(Mage::getSingleton('core/date')->gmtDate()); + + return parent::_beforeSave($object); + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Resource/Template/Collection.php b/app/code/core/Mage/Newsletter/Model/Resource/Template/Collection.php new file mode 100755 index 0000000000..028763f8f3 --- /dev/null +++ b/app/code/core/Mage/Newsletter/Model/Resource/Template/Collection.php @@ -0,0 +1,67 @@ + + */ +class Mage_Newsletter_Model_Resource_Template_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define resource model and model + * + */ + protected function _construct() + { + $this->_init('newsletter/template'); + } + + /** + * Load only actual template + * + * @return Mage_Newsletter_Model_Resource_Template_Collection + */ + public function useOnlyActual() + { + $this->addFieldToFilter('template_actual', 1); + + return $this; + } + + /** + * Returns options array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('template_id', 'template_code'); + } +} diff --git a/app/code/core/Mage/Newsletter/Model/Session.php b/app/code/core/Mage/Newsletter/Model/Session.php index 1fbd031e06..83b889bd05 100644 --- a/app/code/core/Mage/Newsletter/Model/Session.php +++ b/app/code/core/Mage/Newsletter/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/Model/Subscriber.php b/app/code/core/Mage/Newsletter/Model/Subscriber.php index 926ba2ce2a..fdc9c87954 100644 --- a/app/code/core/Mage/Newsletter/Model/Subscriber.php +++ b/app/code/core/Mage/Newsletter/Model/Subscriber.php @@ -20,15 +20,30 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Subscriber model * - * @category Mage - * @package Mage_Newsletter + * @method Mage_Newsletter_Model_Resource_Subscriber _getResource() + * @method Mage_Newsletter_Model_Resource_Subscriber getResource() + * @method int getStoreId() + * @method Mage_Newsletter_Model_Subscriber setStoreId(int $value) + * @method string getChangeStatusAt() + * @method Mage_Newsletter_Model_Subscriber setChangeStatusAt(string $value) + * @method int getCustomerId() + * @method Mage_Newsletter_Model_Subscriber setCustomerId(int $value) + * @method string getSubscriberEmail() + * @method Mage_Newsletter_Model_Subscriber setSubscriberEmail(string $value) + * @method int getSubscriberStatus() + * @method Mage_Newsletter_Model_Subscriber setSubscriberStatus(int $value) + * @method string getSubscriberConfirmCode() + * @method Mage_Newsletter_Model_Subscriber setSubscriberConfirmCode(string $value) + * + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ class Mage_Newsletter_Model_Subscriber extends Mage_Core_Model_Abstract @@ -68,7 +83,11 @@ class Mage_Newsletter_Model_Subscriber extends Mage_Core_Model_Abstract */ protected $_eventObject = 'subscriber'; - + /** + * True if data changed + * + * @var bool + */ protected $_isStatusChanged = false; /** @@ -118,11 +137,15 @@ public function getConfirmationLink() { return Mage::helper('newsletter')->getConfirmationUrl($this); } + /** + * Returns Insubscribe url + * + * @return string + */ public function getUnsubscriptionLink() { return Mage::helper('newsletter')->getUnsubscribeUrl($this); } - /** * Alias for setSubscriberConfirmCode() * @@ -157,7 +180,7 @@ public function setStatus($value) * Set the error messages scope for subscription * * @param boolean $scope - * @return unknown + * @return Mage_Newsletter_Model_Subscriber */ public function setMessagesScope($scope) @@ -254,7 +277,12 @@ public function loadByCustomer(Mage_Customer_Model_Customer $customer) return $this; } - + /** + * Returns sting of random chars + * + * @param int $length + * @return string + */ public function randomSequence($length=32) { $id = ''; @@ -269,6 +297,13 @@ public function randomSequence($length=32) return $id; } + /** + * Subscribes by email + * + * @param string $email + * @throws Exception + * @return int + */ public function subscribe($email) { $this->loadByEmail($email); @@ -328,6 +363,10 @@ public function subscribe($email) } } + /** + * Unsubscribes loaded subscription + * + */ public function unsubscribe() { if ($this->hasCheckCode() && $this->getCode() != $this->getCheckCode()) { @@ -444,6 +483,11 @@ public function received(Mage_Newsletter_Model_Queue $queue) return $this; } + /** + * Sends out confirmation email + * + * @return Mage_Newsletter_Model_Subscriber + */ public function sendConfirmationRequestEmail() { if ($this->getImportMode()) { @@ -473,6 +517,11 @@ public function sendConfirmationRequestEmail() return $this; } + /** + * Sends out confirmation success email + * + * @return Mage_Newsletter_Model_Subscriber + */ public function sendConfirmationSuccessEmail() { if ($this->getImportMode()) { @@ -502,6 +551,11 @@ public function sendConfirmationSuccessEmail() return $this; } + /** + * Sends out unsubsciption email + * + * @return Mage_Newsletter_Model_Subscriber + */ public function sendUnsubscriptionEmail() { if ($this->getImportMode()) { diff --git a/app/code/core/Mage/Newsletter/Model/Template.php b/app/code/core/Mage/Newsletter/Model/Template.php index b69c925fb3..6eb6c65b8d 100644 --- a/app/code/core/Mage/Newsletter/Model/Template.php +++ b/app/code/core/Mage/Newsletter/Model/Template.php @@ -20,15 +20,38 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Template model * - * @category Mage - * @package Mage_Newsletter + * @method Mage_Newsletter_Model_Resource_Template _getResource() + * @method Mage_Newsletter_Model_Resource_Template getResource() + * @method string getTemplateCode() + * @method Mage_Newsletter_Model_Template setTemplateCode(string $value) + * @method Mage_Newsletter_Model_Template setTemplateText(string $value) + * @method Mage_Newsletter_Model_Template setTemplateTextPreprocessed(string $value) + * @method string getTemplateStyles() + * @method Mage_Newsletter_Model_Template setTemplateStyles(string $value) + * @method int getTemplateType() + * @method Mage_Newsletter_Model_Template setTemplateType(int $value) + * @method string getTemplateSubject() + * @method Mage_Newsletter_Model_Template setTemplateSubject(string $value) + * @method string getTemplateSenderName() + * @method Mage_Newsletter_Model_Template setTemplateSenderName(string $value) + * @method string getTemplateSenderEmail() + * @method Mage_Newsletter_Model_Template setTemplateSenderEmail(string $value) + * @method int getTemplateActual() + * @method Mage_Newsletter_Model_Template setTemplateActual(int $value) + * @method string getAddedAt() + * @method Mage_Newsletter_Model_Template setAddedAt(string $value) + * @method string getModifiedAt() + * @method Mage_Newsletter_Model_Template setModifiedAt(string $value) + * + * @category Mage + * @package Mage_Newsletter * @author Magento Core Team */ class Mage_Newsletter_Model_Template extends Mage_Core_Model_Template diff --git a/app/code/core/Mage/Newsletter/Model/Template/Filter.php b/app/code/core/Mage/Newsletter/Model/Template/Filter.php index 214f0a7de0..88835a0075 100644 --- a/app/code/core/Mage/Newsletter/Model/Template/Filter.php +++ b/app/code/core/Mage/Newsletter/Model/Template/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/controllers/ManageController.php b/app/code/core/Mage/Newsletter/controllers/ManageController.php index 4597c8af64..e2140a7925 100644 --- a/app/code/core/Mage/Newsletter/controllers/ManageController.php +++ b/app/code/core/Mage/Newsletter/controllers/ManageController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/controllers/SubscriberController.php b/app/code/core/Mage/Newsletter/controllers/SubscriberController.php index 5dca26f1b5..f65a8181ef 100644 --- a/app/code/core/Mage/Newsletter/controllers/SubscriberController.php +++ b/app/code/core/Mage/Newsletter/controllers/SubscriberController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/etc/adminhtml.xml b/app/code/core/Mage/Newsletter/etc/adminhtml.xml index 2243cee52e..080085ae93 100644 --- a/app/code/core/Mage/Newsletter/etc/adminhtml.xml +++ b/app/code/core/Mage/Newsletter/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Newsletter/etc/config.xml b/app/code/core/Mage/Newsletter/etc/config.xml index ff38636419..9c9b2e25d9 100644 --- a/app/code/core/Mage/Newsletter/etc/config.xml +++ b/app/code/core/Mage/Newsletter/etc/config.xml @@ -21,27 +21,30 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.8.3 + 1.6.0.0 - Mage_Newsletter_Block + + Mage_Newsletter_Block + Mage_Newsletter_Model - newsletter_mysql4 + newsletter_resource - - Mage_Newsletter_Model_Mysql4 + + Mage_Newsletter_Model_Resource + newsletter_mysql4 newsletter_subscriber
      @@ -62,7 +65,7 @@ newsletter_problem
      -
      +
      @@ -123,11 +126,11 @@ - - - newsletter.xml - - + + + newsletter.xml + + @@ -167,18 +170,17 @@ - - - - newsletter.xml - - - + + + + newsletter.xml + + + /newsletter/manage/ - @@ -196,12 +198,15 @@ - - */5 * * * * - newsletter/observer::scheduledSend + + */5 * * * * + + + newsletter/observer::scheduledSend + diff --git a/app/code/core/Mage/Newsletter/etc/system.xml b/app/code/core/Mage/Newsletter/etc/system.xml index 5c5d8060ca..f5f6b7de09 100644 --- a/app/code/core/Mage/Newsletter/etc/system.xml +++ b/app/code/core/Mage/Newsletter/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/install-1.6.0.0.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..76a679880a --- /dev/null +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/install-1.6.0.0.php @@ -0,0 +1,277 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); + +/** + * Create table 'newsletter/subscriber' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/subscriber')) + ->addColumn('subscriber_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Subscriber Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Store Id') + ->addColumn('change_status_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Change Status At') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Id') + ->addColumn('subscriber_email', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array( + 'nullable' => false, + 'default' => '', + ), 'Subscriber Email') + ->addColumn('subscriber_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Subscriber Status') + ->addColumn('subscriber_confirm_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'default' => 'NULL', + ), 'Subscriber Confirm Code') + ->addIndex($installer->getIdxName('newsletter/subscriber', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('newsletter/subscriber', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('newsletter/subscriber', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Newsletter Subscriber'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'newsletter/template' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/template')) + ->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Template Id') + ->addColumn('template_code', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array( + ), 'Template Code') + ->addColumn('template_text', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Template Text') + ->addColumn('template_text_preprocessed', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Template Text Preprocessed') + ->addColumn('template_styles', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Template Styles') + ->addColumn('template_type', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Template Type') + ->addColumn('template_subject', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Template Subject') + ->addColumn('template_sender_name', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Template Sender Name') + ->addColumn('template_sender_email', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Template Sender Email') + ->addColumn('template_actual', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '1', + ), 'Template Actual') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Added At') + ->addColumn('modified_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Modified At') + ->addIndex($installer->getIdxName('newsletter/template', array('template_actual')), + array('template_actual')) + ->addIndex($installer->getIdxName('newsletter/template', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('newsletter/template', array('modified_at')), + array('modified_at')) + ->setComment('Newsletter Template'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'newsletter/queue' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/queue')) + ->addColumn('queue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Queue Id') + ->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Template Id') + ->addColumn('newsletter_type', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Newsletter Type') + ->addColumn('newsletter_text', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Newsletter Text') + ->addColumn('newsletter_styles', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Newsletter Styles') + ->addColumn('newsletter_subject', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Newsletter Subject') + ->addColumn('newsletter_sender_name', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Newsletter Sender Name') + ->addColumn('newsletter_sender_email', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Newsletter Sender Email') + ->addColumn('queue_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Queue Status') + ->addColumn('queue_start_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Queue Start At') + ->addColumn('queue_finish_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Queue Finish At') + ->addIndex($installer->getIdxName('newsletter/queue', array('template_id')), + array('template_id')) + ->addForeignKey($installer->getFkName('newsletter/queue', 'template_id', 'newsletter/template', 'template_id'), + 'template_id', $installer->getTable('newsletter/template'), 'template_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Newsletter Queue'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'newsletter/queue_link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/queue_link')) + ->addColumn('queue_link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Queue Link Id') + ->addColumn('queue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Queue Id') + ->addColumn('subscriber_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Subscriber Id') + ->addColumn('letter_sent_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Letter Sent At') + ->addIndex($installer->getIdxName('newsletter/queue_link', array('subscriber_id')), + array('subscriber_id')) + ->addIndex($installer->getIdxName('newsletter/queue_link', array('queue_id')), + array('queue_id')) + ->addIndex($installer->getIdxName('newsletter/queue_link', array('queue_id', 'letter_sent_at')), + array('queue_id', 'letter_sent_at')) + ->addForeignKey($installer->getFkName('newsletter/queue_link', 'queue_id', 'newsletter/queue', 'queue_id'), + 'queue_id', $installer->getTable('newsletter/queue'), 'queue_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('newsletter/queue_link', 'subscriber_id', 'newsletter/subscriber', 'subscriber_id'), + 'subscriber_id', $installer->getTable('newsletter/subscriber'), 'subscriber_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Newsletter Queue Link'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'newsletter/queue_store_link' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/queue_store_link')) + ->addColumn('queue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Queue Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store Id') + ->addIndex($installer->getIdxName('newsletter/queue_store_link', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('newsletter/queue_store_link', 'queue_id', 'newsletter/queue', 'queue_id'), + 'queue_id', $installer->getTable('newsletter/queue'), 'queue_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('newsletter/queue_store_link', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Newsletter Queue Store Link'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'newsletter/problem' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('newsletter/problem')) + ->addColumn('problem_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Problem Id') + ->addColumn('subscriber_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Subscriber Id') + ->addColumn('queue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Queue Id') + ->addColumn('problem_error_code', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Problem Error Code') + ->addColumn('problem_error_text', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + ), 'Problem Error Text') + ->addIndex($installer->getIdxName('newsletter/problem', array('subscriber_id')), + array('subscriber_id')) + ->addIndex($installer->getIdxName('newsletter/problem', array('queue_id')), + array('queue_id')) + ->addForeignKey($installer->getFkName('newsletter/problem', 'queue_id', 'newsletter/queue', 'queue_id'), + 'queue_id', $installer->getTable('newsletter/queue'), 'queue_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('newsletter/problem', 'subscriber_id', 'newsletter/subscriber', 'subscriber_id'), + 'subscriber_id', $installer->getTable('newsletter/subscriber'), 'subscriber_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Newsletter Problems'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.7.0.php index d24458184c..b633a5e87d 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.8.0.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.8.0.php index ceb04f3970..d0c74a5ee1 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.8.0.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-install-0.8.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.7.0-0.7.1.php index 2d3a3eedd1..363ee92120 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.0-0.8.1.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.0-0.8.1.php index 7bddda28a5..5192725c05 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.0-0.8.1.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.0-0.8.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.1-0.8.2.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.1-0.8.2.php index 8c0540b3d0..80cc42cc07 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.1-0.8.2.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.1-0.8.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.2-0.8.3.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.2-0.8.3.php index 06dec2d1a5..d42dbc16d8 100644 --- a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.2-0.8.3.php +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-0.8.2-0.8.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Newsletter - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..691df63a5f --- /dev/null +++ b/app/code/core/Mage/Newsletter/sql/newsletter_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,559 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/problem'), + 'FK_PROBLEM_QUEUE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/problem'), + 'FK_PROBLEM_SUBSCRIBER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/queue'), + 'FK_QUEUE_TEMPLATE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/queue_link'), + 'FK_QUEUE_LINK_SUBSCRIBER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/subscriber'), + 'FK_NEWSLETTER_SUBSCRIBER_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/queue_store_link'), + 'FK_LINK_QUEUE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/queue_store_link'), + 'FK_NEWSLETTER_QUEUE_STORE_LINK_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('newsletter/queue_link'), + 'FK_QUEUE_LINK_QUEUE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/problem'), + 'FK_PROBLEM_SUBSCRIBER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/problem'), + 'FK_PROBLEM_QUEUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/queue'), + 'FK_QUEUE_TEMPLATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/queue_link'), + 'FK_QUEUE_LINK_SUBSCRIBER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/queue_link'), + 'FK_QUEUE_LINK_QUEUE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/queue_link'), + 'IDX_NEWSLETTER_QUEUE_LINK_SEND_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/queue_store_link'), + 'FK_NEWSLETTER_QUEUE_STORE_LINK_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/subscriber'), + 'FK_SUBSCRIBER_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/subscriber'), + 'FK_NEWSLETTER_SUBSCRIBER_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/template'), + 'TEMPLATE_ACTUAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/template'), + 'ADDED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('newsletter/template'), + 'MODIFIED_AT' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('newsletter/subscriber') => array( + 'columns' => array( + 'subscriber_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Subscriber Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'change_status_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Change Status At' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Id' + ), + 'subscriber_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 150, + 'nullable' => false, + 'comment' => 'Subscriber Email' + ), + 'subscriber_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Subscriber Status' + ), + 'subscriber_confirm_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'default' => 'NULL', + 'comment' => 'Subscriber Confirm Code' + ) + ), + 'comment' => 'Newsletter Subscriber' + ), + $installer->getTable('newsletter/queue') => array( + 'columns' => array( + 'queue_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Queue Id' + ), + 'template_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Template Id' + ), + 'newsletter_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Newsletter Type' + ), + 'newsletter_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Newsletter Text' + ), + 'newsletter_styles' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Newsletter Styles' + ), + 'newsletter_subject' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Newsletter Subject' + ), + 'newsletter_sender_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Newsletter Sender Name' + ), + 'newsletter_sender_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Newsletter Sender Email' + ), + 'queue_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Queue Status' + ), + 'queue_start_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Queue Start At' + ), + 'queue_finish_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Queue Finish At' + ) + ), + 'comment' => 'Newsletter Queue' + ), + $installer->getTable('newsletter_queue_link') => array( + 'columns' => array( + 'queue_link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Queue Link Id' + ), + 'queue_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Queue Id' + ), + 'subscriber_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Subscriber Id' + ), + 'letter_sent_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Letter Sent At' + ) + ), + 'comment' => 'Newsletter Queue Link' + ), + $installer->getTable('newsletter_queue_store_link') => array( + 'columns' => array( + 'queue_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Queue Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Newsletter Queue Store Link' + ), + $installer->getTable('newsletter/template') => array( + 'columns' => array( + 'template_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Template Id' + ), + 'template_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 150, + 'comment' => 'Template Code' + ), + 'template_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Template Text' + ), + 'template_text_preprocessed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Template Text Preprocessed' + ), + 'template_styles' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Template Styles' + ), + 'template_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Template Type' + ), + 'template_subject' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Template Subject' + ), + 'template_sender_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Template Sender Name' + ), + 'template_sender_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Template Sender Email' + ), + 'template_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '1', + 'comment' => 'Template Actual' + ), + 'added_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Added At' + ), + 'modified_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Modified At' + ) + ), + 'comment' => 'Newsletter Template' + ), + $installer->getTable('newsletter/problem') => array( + 'columns' => array( + 'problem_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Problem Id' + ), + 'subscriber_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Subscriber Id' + ), + 'queue_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Queue Id' + ), + 'problem_error_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Problem Error Code' + ), + 'problem_error_text' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'comment' => 'Problem Error Text' + ) + ), + 'comment' => 'Newsletter Problems' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/problem'), + $installer->getIdxName('newsletter/problem', array('subscriber_id')), + array('subscriber_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/problem'), + $installer->getIdxName('newsletter/problem', array('queue_id')), + array('queue_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/queue'), + $installer->getIdxName('newsletter/queue', array('template_id')), + array('template_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/queue_link'), + $installer->getIdxName('newsletter/queue_link', array('subscriber_id')), + array('subscriber_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/queue_link'), + $installer->getIdxName('newsletter/queue_link', array('queue_id')), + array('queue_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/queue_link'), + $installer->getIdxName('newsletter/queue_link', array('queue_id', 'letter_sent_at')), + array('queue_id', 'letter_sent_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/queue_store_link'), + $installer->getIdxName('newsletter/queue_store_link', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/subscriber'), + $installer->getIdxName('newsletter/subscriber', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/subscriber'), + $installer->getIdxName('newsletter/subscriber', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/template'), + $installer->getIdxName('newsletter/template', array('template_actual')), + array('template_actual') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/template'), + $installer->getIdxName('newsletter/template', array('added_at')), + array('added_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('newsletter/template'), + $installer->getIdxName('newsletter/template', array('modified_at')), + array('modified_at') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/subscriber', 'store_id', 'core/store', 'store_id'), + $installer->getTable('newsletter/subscriber'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/problem', 'queue_id', 'newsletter/queue', 'queue_id'), + $installer->getTable('newsletter/problem'), + 'queue_id', + $installer->getTable('newsletter/queue'), + 'queue_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/problem', 'subscriber_id', 'newsletter/subscriber', 'subscriber_id'), + $installer->getTable('newsletter/problem'), + 'subscriber_id', + $installer->getTable('newsletter/subscriber'), + 'subscriber_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/queue', 'template_id', 'newsletter/template', 'template_id'), + $installer->getTable('newsletter/queue'), + 'template_id', + $installer->getTable('newsletter/template'), + 'template_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/queue_link', 'queue_id', 'newsletter/queue', 'queue_id'), + $installer->getTable('newsletter/queue_link'), + 'queue_id', + $installer->getTable('newsletter/queue'), + 'queue_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/queue_link', 'subscriber_id', 'newsletter/subscriber', 'subscriber_id'), + $installer->getTable('newsletter/queue_link'), + 'subscriber_id', + $installer->getTable('newsletter/subscriber'), + 'subscriber_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/queue_store_link', 'queue_id', 'newsletter/queue', 'queue_id'), + $installer->getTable('newsletter/queue_store_link'), + 'queue_id', + $installer->getTable('newsletter/queue'), + 'queue_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('newsletter/queue_store_link', 'store_id', 'core/store', 'store_id'), + $installer->getTable('newsletter/queue_store_link'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Page/Block/Html.php b/app/code/core/Mage/Page/Block/Html.php index 9abc09530f..b85648f530 100644 --- a/app/code/core/Mage/Page/Block/Html.php +++ b/app/code/core/Mage/Page/Block/Html.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Breadcrumbs.php b/app/code/core/Mage/Page/Block/Html/Breadcrumbs.php index 181a136d43..cb967f9143 100644 --- a/app/code/core/Mage/Page/Block/Html/Breadcrumbs.php +++ b/app/code/core/Mage/Page/Block/Html/Breadcrumbs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Footer.php b/app/code/core/Mage/Page/Block/Html/Footer.php index b1937c4b94..9d8d1d8296 100644 --- a/app/code/core/Mage/Page/Block/Html/Footer.php +++ b/app/code/core/Mage/Page/Block/Html/Footer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Head.php b/app/code/core/Mage/Page/Block/Html/Head.php index 140631a739..fe56438158 100644 --- a/app/code/core/Mage/Page/Block/Html/Head.php +++ b/app/code/core/Mage/Page/Block/Html/Head.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index e4ce1eda75..a6ec5398ad 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Notices.php b/app/code/core/Mage/Page/Block/Html/Notices.php index f3a8791f9e..07eb0bd995 100644 --- a/app/code/core/Mage/Page/Block/Html/Notices.php +++ b/app/code/core/Mage/Page/Block/Html/Notices.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Pager.php b/app/code/core/Mage/Page/Block/Html/Pager.php index 096d147ea9..67efcdca1b 100644 --- a/app/code/core/Mage/Page/Block/Html/Pager.php +++ b/app/code/core/Mage/Page/Block/Html/Pager.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Toplinks.php b/app/code/core/Mage/Page/Block/Html/Toplinks.php index 73f2ce9e74..fe2cc8db1e 100644 --- a/app/code/core/Mage/Page/Block/Html/Toplinks.php +++ b/app/code/core/Mage/Page/Block/Html/Toplinks.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 0c779bf5f4..661e15dd8e 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Html/Wrapper.php b/app/code/core/Mage/Page/Block/Html/Wrapper.php index cf76848aee..1364c8c580 100644 --- a/app/code/core/Mage/Page/Block/Html/Wrapper.php +++ b/app/code/core/Mage/Page/Block/Html/Wrapper.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Js/Cookie.php b/app/code/core/Mage/Page/Block/Js/Cookie.php index 7e20a152a6..2082da4148 100644 --- a/app/code/core/Mage/Page/Block/Js/Cookie.php +++ b/app/code/core/Mage/Page/Block/Js/Cookie.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Js/Translate.php b/app/code/core/Mage/Page/Block/Js/Translate.php index af229bc0bd..13f378eb23 100644 --- a/app/code/core/Mage/Page/Block/Js/Translate.php +++ b/app/code/core/Mage/Page/Block/Js/Translate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Redirect.php b/app/code/core/Mage/Page/Block/Redirect.php index 46577e9c3e..487b25bb6f 100644 --- a/app/code/core/Mage/Page/Block/Redirect.php +++ b/app/code/core/Mage/Page/Block/Redirect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Switch.php b/app/code/core/Mage/Page/Block/Switch.php index 6295d977d3..57e3096458 100644 --- a/app/code/core/Mage/Page/Block/Switch.php +++ b/app/code/core/Mage/Page/Block/Switch.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Template/Container.php b/app/code/core/Mage/Page/Block/Template/Container.php index ed995571c5..f7ef18166c 100644 --- a/app/code/core/Mage/Page/Block/Template/Container.php +++ b/app/code/core/Mage/Page/Block/Template/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Template/Links.php b/app/code/core/Mage/Page/Block/Template/Links.php index d582aa04c9..5b240d12f0 100644 --- a/app/code/core/Mage/Page/Block/Template/Links.php +++ b/app/code/core/Mage/Page/Block/Template/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Block/Template/Links/Block.php b/app/code/core/Mage/Page/Block/Template/Links/Block.php index bdc997f85c..a633ecf16a 100644 --- a/app/code/core/Mage/Page/Block/Template/Links/Block.php +++ b/app/code/core/Mage/Page/Block/Template/Links/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Helper/Data.php b/app/code/core/Mage/Page/Helper/Data.php index 2e524083fc..92305f92e3 100644 --- a/app/code/core/Mage/Page/Helper/Data.php +++ b/app/code/core/Mage/Page/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Helper/Html.php b/app/code/core/Mage/Page/Helper/Html.php index 127cb5ddc2..235e337d75 100644 --- a/app/code/core/Mage/Page/Helper/Html.php +++ b/app/code/core/Mage/Page/Helper/Html.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Helper/Layout.php b/app/code/core/Mage/Page/Helper/Layout.php index 2d6cd8a074..271887eea9 100644 --- a/app/code/core/Mage/Page/Helper/Layout.php +++ b/app/code/core/Mage/Page/Helper/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Model/Config.php b/app/code/core/Mage/Page/Model/Config.php index 5a9aae0b3c..5d81c049bd 100644 --- a/app/code/core/Mage/Page/Model/Config.php +++ b/app/code/core/Mage/Page/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/Model/Source/Layout.php b/app/code/core/Mage/Page/Model/Source/Layout.php index 891a5f27ea..66b2c9b21f 100644 --- a/app/code/core/Mage/Page/Model/Source/Layout.php +++ b/app/code/core/Mage/Page/Model/Source/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Page/etc/config.xml b/app/code/core/Mage/Page/etc/config.xml index 9c093da008..68db7d3d57 100644 --- a/app/code/core/Mage/Page/etc/config.xml +++ b/app/code/core/Mage/Page/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 diff --git a/app/code/core/Mage/Page/etc/system.xml b/app/code/core/Mage/Page/etc/system.xml index cbb7e147de..3e76f84327 100644 --- a/app/code/core/Mage/Page/etc/system.xml +++ b/app/code/core/Mage/Page/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Page - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php index 913ea4543a..b7a425d4f9 100644 --- a/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php +++ b/app/code/core/Mage/PageCache/Block/Adminhtml/Cache/Additional.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/Helper/Data.php b/app/code/core/Mage/PageCache/Helper/Data.php index 99be7a0d4f..93a227313e 100644 --- a/app/code/core/Mage/PageCache/Helper/Data.php +++ b/app/code/core/Mage/PageCache/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/Model/Control/Interface.php b/app/code/core/Mage/PageCache/Model/Control/Interface.php index 7ff01c488c..e3dc6c4d68 100644 --- a/app/code/core/Mage/PageCache/Model/Control/Interface.php +++ b/app/code/core/Mage/PageCache/Model/Control/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/Model/Control/Zend.php b/app/code/core/Mage/PageCache/Model/Control/Zend.php index 5d0b1c52fb..9df13fbd5b 100644 --- a/app/code/core/Mage/PageCache/Model/Control/Zend.php +++ b/app/code/core/Mage/PageCache/Model/Control/Zend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/Model/Observer.php b/app/code/core/Mage/PageCache/Model/Observer.php index 040635f260..8bef649092 100644 --- a/app/code/core/Mage/PageCache/Model/Observer.php +++ b/app/code/core/Mage/PageCache/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php b/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php index 9ca57cf117..b3955293b7 100644 --- a/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php +++ b/app/code/core/Mage/PageCache/Model/System/Config/Source/Controls.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php b/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php index 830e3cda66..1c1ce2b69c 100644 --- a/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php +++ b/app/code/core/Mage/PageCache/controllers/Adminhtml/PageCacheController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PageCache/etc/adminhtml.xml b/app/code/core/Mage/PageCache/etc/adminhtml.xml index 5095fc0898..0bda1d3bce 100644 --- a/app/code/core/Mage/PageCache/etc/adminhtml.xml +++ b/app/code/core/Mage/PageCache/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/PageCache/etc/config.xml b/app/code/core/Mage/PageCache/etc/config.xml index 4b39d286da..49983e7de5 100644 --- a/app/code/core/Mage/PageCache/etc/config.xml +++ b/app/code/core/Mage/PageCache/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.5.0.0.0 + 1.6.0.0 diff --git a/app/code/core/Mage/PageCache/etc/system.xml b/app/code/core/Mage/PageCache/etc/system.xml index aae869c983..3f1850ace1 100644 --- a/app/code/core/Mage/PageCache/etc/system.xml +++ b/app/code/core/Mage/PageCache/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Paygate/Block/Authorizenet/Form/Cc.php b/app/code/core/Mage/Paygate/Block/Authorizenet/Form/Cc.php index 1e4302af39..4cd1fbe477 100644 --- a/app/code/core/Mage/Paygate/Block/Authorizenet/Form/Cc.php +++ b/app/code/core/Mage/Paygate/Block/Authorizenet/Form/Cc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Block/Authorizenet/Info/Cc.php b/app/code/core/Mage/Paygate/Block/Authorizenet/Info/Cc.php index fc2fce2a72..6bfe16de7e 100644 --- a/app/code/core/Mage/Paygate/Block/Authorizenet/Info/Cc.php +++ b/app/code/core/Mage/Paygate/Block/Authorizenet/Info/Cc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Helper/Data.php b/app/code/core/Mage/Paygate/Helper/Data.php index c376901d5b..b4f915be2c 100644 --- a/app/code/core/Mage/Paygate/Helper/Data.php +++ b/app/code/core/Mage/Paygate/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet.php b/app/code/core/Mage/Paygate/Model/Authorizenet.php index ddbdffb134..f2b703b8bc 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1369,4 +1369,4 @@ protected function _generateChecksum(Varien_Object $object, $checkSumDataKeys = } return md5(implode($data, '_')); } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Cards.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Cards.php index 1247428b49..ef50dda474 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Cards.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Cards.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Debug.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Debug.php index 3b9245bedf..5a8b873a80 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Debug.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Debug.php @@ -20,11 +20,33 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Paygate_Model_Resource_Authorizenet_Debug _getResource() + * @method Mage_Paygate_Model_Resource_Authorizenet_Debug getResource() + * @method string getRequestBody() + * @method Mage_Paygate_Model_Authorizenet_Debug setRequestBody(string $value) + * @method string getResponseBody() + * @method Mage_Paygate_Model_Authorizenet_Debug setResponseBody(string $value) + * @method string getRequestSerialized() + * @method Mage_Paygate_Model_Authorizenet_Debug setRequestSerialized(string $value) + * @method string getResultSerialized() + * @method Mage_Paygate_Model_Authorizenet_Debug setResultSerialized(string $value) + * @method string getRequestDump() + * @method Mage_Paygate_Model_Authorizenet_Debug setRequestDump(string $value) + * @method string getResultDump() + * @method Mage_Paygate_Model_Authorizenet_Debug setResultDump(string $value) + * + * @category Mage + * @package Mage_Paygate + * @author Magento Core Team + */ class Mage_Paygate_Model_Authorizenet_Debug extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Request.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Request.php index 9424db15a0..a787417a65 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Request.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Result.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Result.php index 1ef1dcc120..56760c94f2 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Result.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Source/Cctype.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Source/Cctype.php index 059164125c..aeeabc688e 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Source/Cctype.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Source/Cctype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet/Source/PaymentAction.php b/app/code/core/Mage/Paygate/Model/Authorizenet/Source/PaymentAction.php index adc175c803..16d0decc24 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet/Source/PaymentAction.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet/Source/PaymentAction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug.php b/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug.php index 7f26331d34..9805f5633d 100644 --- a/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug.php +++ b/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug.php @@ -20,15 +20,18 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Paygate_Model_Mysql4_Authorizenet_Debug extends Mage_Core_Model_Mysql4_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Paygate + * @author Magento Core Team + */ +class Mage_Paygate_Model_Mysql4_Authorizenet_Debug extends Mage_Paygate_Model_Resource_Authorizenet_Debug { - protected function _construct() - { - $this->_init('paygate/authorizenet_debug', 'debug_id'); - } } diff --git a/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug/Collection.php b/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug/Collection.php index 51b6ab098d..8febd37e10 100644 --- a/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug/Collection.php +++ b/app/code/core/Mage/Paygate/Model/Mysql4/Authorizenet/Debug/Collection.php @@ -20,15 +20,19 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Paygate_Model_Mysql4_Authorizenet_Debug_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Paygate + * @author Magento Core Team + */ +class Mage_Paygate_Model_Mysql4_Authorizenet_Debug_Collection + extends Mage_Paygate_Model_Resource_Authorizenet_Debug_Collection { - protected function _construct() - { - $this->_init('paygate/authorizenet_debug'); - } } diff --git a/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug.php b/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug.php new file mode 100755 index 0000000000..ea36a63198 --- /dev/null +++ b/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug.php @@ -0,0 +1,45 @@ + + */ +class Mage_Paygate_Model_Resource_Authorizenet_Debug extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('paygate/authorizenet_debug', 'debug_id'); + } +} diff --git a/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug/Collection.php b/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug/Collection.php new file mode 100755 index 0000000000..ce7b2fdad8 --- /dev/null +++ b/app/code/core/Mage/Paygate/Model/Resource/Authorizenet/Debug/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Paygate_Model_Resource_Authorizenet_Debug_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('paygate/authorizenet_debug'); + } +} diff --git a/app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php b/app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php index 13b0646464..79330aee70 100644 --- a/app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php +++ b/app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php b/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php index 1785f63a7e..c589f6ccd3 100644 --- a/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php +++ b/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/etc/config.xml b/app/code/core/Mage/Paygate/etc/config.xml index fbf3be22f4..032f41d0fd 100644 --- a/app/code/core/Mage/Paygate/etc/config.xml +++ b/app/code/core/Mage/Paygate/etc/config.xml @@ -21,39 +21,40 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - - - 0.7.1 - - - - - - - Mage_Paygate_Model - paygate_mysql4 - - - Mage_Paygate_Model_Mysql4 - - paygate_authorizenet_debug
      -
      -
      -
      - - - - Mage_Paygate - - - -
      - + + + 1.6.0.0 + + + + + + Mage_Paygate_Model + paygate_resource + + + Mage_Paygate_Model_Resource + paygate_mysql4 + + + paygate_authorizenet_debug
      +
      +
      +
      +
      + + + + Mage_Paygate + + + +
      @@ -65,7 +66,6 @@ - @@ -107,7 +107,7 @@ 0 0 - + paygate/authorizenet processing authorize diff --git a/app/code/core/Mage/Paygate/etc/system.xml b/app/code/core/Mage/Paygate/etc/system.xml index 1cc578ecf5..4bf6b14d04 100644 --- a/app/code/core/Mage/Paygate/etc/system.xml +++ b/app/code/core/Mage/Paygate/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Shipping/Model/Rule/Condition/Abstract.php b/app/code/core/Mage/Paygate/sql/paygate_setup/install-1.6.0.0.php similarity index 83% rename from app/code/core/Mage/Shipping/Model/Rule/Condition/Abstract.php rename to app/code/core/Mage/Paygate/sql/paygate_setup/install-1.6.0.0.php index 31391c7feb..6fe4853369 100644 --- a/app/code/core/Mage/Shipping/Model/Rule/Condition/Abstract.php +++ b/app/code/core/Mage/Paygate/sql/paygate_setup/install-1.6.0.0.php @@ -19,13 +19,10 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Paygate + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - -abstract class Mage_Sales_Model_Shipping_Rule_Condition_Abstract -{ - -} +/** @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; diff --git a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-data-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-data-upgrade-0.7.0-0.7.1.php index ff45feb05f..4d72fe041f 100644 --- a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-data-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-data-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -144,4 +144,3 @@ $connection->rollback(); throw $e; } - diff --git a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-install-0.7.0.php index a3e5f03b12..a7473c5701 100644 --- a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-upgrade-0.7.0-0.7.1.php index c23c06f9df..7214596ce9 100644 --- a/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Paygate/sql/paygate_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paygate - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Catalog/Product/View/Profile.php b/app/code/core/Mage/Payment/Block/Catalog/Product/View/Profile.php index bfd8a4de76..f0d4f4b88c 100644 --- a/app/code/core/Mage/Payment/Block/Catalog/Product/View/Profile.php +++ b/app/code/core/Mage/Payment/Block/Catalog/Product/View/Profile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Form.php b/app/code/core/Mage/Payment/Block/Form.php index ab8f28f6f0..a91cb15ea4 100644 --- a/app/code/core/Mage/Payment/Block/Form.php +++ b/app/code/core/Mage/Payment/Block/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php index 406fb94d98..8ef87137c9 100644 --- a/app/code/core/Mage/Payment/Block/Form/Cc.php +++ b/app/code/core/Mage/Payment/Block/Form/Cc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -157,4 +157,3 @@ protected function _toHtml() return parent::_toHtml(); } } - diff --git a/app/code/core/Mage/Payment/Block/Form/Ccsave.php b/app/code/core/Mage/Payment/Block/Form/Ccsave.php index e05f9c6a5a..b807031972 100644 --- a/app/code/core/Mage/Payment/Block/Form/Ccsave.php +++ b/app/code/core/Mage/Payment/Block/Form/Ccsave.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Form/Checkmo.php b/app/code/core/Mage/Payment/Block/Form/Checkmo.php index 8d3db761c5..39a769ea36 100644 --- a/app/code/core/Mage/Payment/Block/Form/Checkmo.php +++ b/app/code/core/Mage/Payment/Block/Form/Checkmo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Form/Container.php b/app/code/core/Mage/Payment/Block/Form/Container.php index 9b505bb4ae..7be7fb9668 100644 --- a/app/code/core/Mage/Payment/Block/Form/Container.php +++ b/app/code/core/Mage/Payment/Block/Form/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -116,7 +116,7 @@ public function getMethods() $quote = $this->getQuote(); $store = $quote ? $quote->getStoreId() : null; $methods = $this->helper('payment')->getStoreMethods($store, $quote); - $total = $quote->getBaseSubtotal(); + $total = $quote->getGrandTotal(); foreach ($methods as $key => $method) { if ($this->_canUseMethod($method) && ($total != 0 diff --git a/app/code/core/Mage/Payment/Block/Form/Purchaseorder.php b/app/code/core/Mage/Payment/Block/Form/Purchaseorder.php index ebdbf97367..b12f832520 100644 --- a/app/code/core/Mage/Payment/Block/Form/Purchaseorder.php +++ b/app/code/core/Mage/Payment/Block/Form/Purchaseorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info.php b/app/code/core/Mage/Payment/Block/Info.php index 8dcacec635..1f44fccaeb 100644 --- a/app/code/core/Mage/Payment/Block/Info.php +++ b/app/code/core/Mage/Payment/Block/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info/Cc.php b/app/code/core/Mage/Payment/Block/Info/Cc.php index 6435281b79..dfac07e831 100644 --- a/app/code/core/Mage/Payment/Block/Info/Cc.php +++ b/app/code/core/Mage/Payment/Block/Info/Cc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info/Ccsave.php b/app/code/core/Mage/Payment/Block/Info/Ccsave.php index 9e204e0265..511b643a8d 100644 --- a/app/code/core/Mage/Payment/Block/Info/Ccsave.php +++ b/app/code/core/Mage/Payment/Block/Info/Ccsave.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info/Checkmo.php b/app/code/core/Mage/Payment/Block/Info/Checkmo.php index da65fd7089..3fd7ea3492 100644 --- a/app/code/core/Mage/Payment/Block/Info/Checkmo.php +++ b/app/code/core/Mage/Payment/Block/Info/Checkmo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info/Container.php b/app/code/core/Mage/Payment/Block/Info/Container.php index 5574828088..7e48946ab8 100644 --- a/app/code/core/Mage/Payment/Block/Info/Container.php +++ b/app/code/core/Mage/Payment/Block/Info/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Block/Info/Purchaseorder.php b/app/code/core/Mage/Payment/Block/Info/Purchaseorder.php index 962e063e6d..557ca81ffb 100644 --- a/app/code/core/Mage/Payment/Block/Info/Purchaseorder.php +++ b/app/code/core/Mage/Payment/Block/Info/Purchaseorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Exception.php b/app/code/core/Mage/Payment/Exception.php index 94c6cb663d..af6dfc129b 100644 --- a/app/code/core/Mage/Payment/Exception.php +++ b/app/code/core/Mage/Payment/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index 7095fe5fbe..75f0db9da6 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Billing/Agreement/MethodInterface.php b/app/code/core/Mage/Payment/Model/Billing/Agreement/MethodInterface.php index 6fb42249d5..9d02c9b7bf 100644 --- a/app/code/core/Mage/Payment/Model/Billing/Agreement/MethodInterface.php +++ b/app/code/core/Mage/Payment/Model/Billing/Agreement/MethodInterface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Billing/AgreementAbstract.php b/app/code/core/Mage/Payment/Model/Billing/AgreementAbstract.php index c1cd73244a..b3b96792bc 100644 --- a/app/code/core/Mage/Payment/Model/Billing/AgreementAbstract.php +++ b/app/code/core/Mage/Payment/Model/Billing/AgreementAbstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 7029d57cf3..99f620f6fd 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -48,8 +48,11 @@ public function getActiveMethods($store=null) $methods = array(); $config = Mage::getStoreConfig('payment', $store); foreach ($config as $code => $methodConfig) { - if (Mage::getStoreConfigFlag('payment/'.$code.'/active', $store)) { - $methods[$code] = $this->_getMethod($code, $methodConfig); + if (array_key_exists('model', $methodConfig)) { + $methodModel = Mage::getModel($methodConfig['model']); + if ($methodModel && $methodModel->isAvailable()) { + $methods[$code] = $this->_getMethod($code, $methodConfig); + } } } return $methods; diff --git a/app/code/core/Mage/Payment/Model/Info.php b/app/code/core/Mage/Payment/Model/Info.php index 5a35eefe5d..f138350f3c 100644 --- a/app/code/core/Mage/Payment/Model/Info.php +++ b/app/code/core/Mage/Payment/Model/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Info/Exception.php b/app/code/core/Mage/Payment/Model/Info/Exception.php index 43020758b2..1f1888328b 100644 --- a/app/code/core/Mage/Payment/Model/Info/Exception.php +++ b/app/code/core/Mage/Payment/Model/Info/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index 9dee188030..5d869c9f73 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Cc.php b/app/code/core/Mage/Payment/Model/Method/Cc.php index 7049299bdb..b20a9945ce 100644 --- a/app/code/core/Mage/Payment/Model/Method/Cc.php +++ b/app/code/core/Mage/Payment/Model/Method/Cc.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Ccsave.php b/app/code/core/Mage/Payment/Model/Method/Ccsave.php index 05c9a37481..a3bb814004 100644 --- a/app/code/core/Mage/Payment/Model/Method/Ccsave.php +++ b/app/code/core/Mage/Payment/Model/Method/Ccsave.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Checkmo.php b/app/code/core/Mage/Payment/Model/Method/Checkmo.php index c9ff838c97..3c67361a01 100644 --- a/app/code/core/Mage/Payment/Model/Method/Checkmo.php +++ b/app/code/core/Mage/Payment/Model/Method/Checkmo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Free.php b/app/code/core/Mage/Payment/Model/Method/Free.php index 0f0ed3b60a..c77c6b227f 100644 --- a/app/code/core/Mage/Payment/Model/Method/Free.php +++ b/app/code/core/Mage/Payment/Model/Method/Free.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Method/Purchaseorder.php b/app/code/core/Mage/Payment/Model/Method/Purchaseorder.php index 79eb1980b5..2db666ee7c 100644 --- a/app/code/core/Mage/Payment/Model/Method/Purchaseorder.php +++ b/app/code/core/Mage/Payment/Model/Method/Purchaseorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Observer.php b/app/code/core/Mage/Payment/Model/Observer.php index a3da3955db..2e4da4345a 100644 --- a/app/code/core/Mage/Payment/Model/Observer.php +++ b/app/code/core/Mage/Payment/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Paygate/Request.php b/app/code/core/Mage/Payment/Model/Paygate/Request.php index e4b1195d39..52fd18c6a6 100644 --- a/app/code/core/Mage/Payment/Model/Paygate/Request.php +++ b/app/code/core/Mage/Payment/Model/Paygate/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Paygate/Result.php b/app/code/core/Mage/Payment/Model/Paygate/Result.php index 174f480c30..dcd7cdbbd2 100644 --- a/app/code/core/Mage/Payment/Model/Paygate/Result.php +++ b/app/code/core/Mage/Payment/Model/Paygate/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php index a7b8d34c24..460dbfdbd4 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile/MethodInterface.php b/app/code/core/Mage/Payment/Model/Recurring/Profile/MethodInterface.php index f5c060fbf6..b5674fb8eb 100644 --- a/app/code/core/Mage/Payment/Model/Recurring/Profile/MethodInterface.php +++ b/app/code/core/Mage/Payment/Model/Recurring/Profile/MethodInterface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Source/Cctype.php b/app/code/core/Mage/Payment/Model/Source/Cctype.php index 8d73f703c0..ac39968917 100644 --- a/app/code/core/Mage/Payment/Model/Source/Cctype.php +++ b/app/code/core/Mage/Payment/Model/Source/Cctype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/Model/Source/Invoice.php b/app/code/core/Mage/Payment/Model/Source/Invoice.php index 2c07ddcae8..c80bef0206 100644 --- a/app/code/core/Mage/Payment/Model/Source/Invoice.php +++ b/app/code/core/Mage/Payment/Model/Source/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Payment/etc/adminhtml.xml b/app/code/core/Mage/Payment/etc/adminhtml.xml index 885dfea1c1..d3e3d6c9c7 100644 --- a/app/code/core/Mage/Payment/etc/adminhtml.xml +++ b/app/code/core/Mage/Payment/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Payment/etc/config.xml b/app/code/core/Mage/Payment/etc/config.xml index 7b4436b8da..27e207e9b2 100644 --- a/app/code/core/Mage/Payment/etc/config.xml +++ b/app/code/core/Mage/Payment/etc/config.xml @@ -21,24 +21,22 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 - Mage_Payment_Model - @@ -46,15 +44,12 @@ - Mage_Payment_Block - - @@ -99,12 +94,10 @@ - Offline Payment Methods - @@ -116,7 +109,6 @@ - @@ -155,8 +147,7 @@ - - + @@ -168,7 +159,6 @@ 0 offline - 1 payment/method_checkmo @@ -177,21 +167,15 @@ 0 offline - 1 payment/method_free pending No Payment Information Required 0 - 1 offline - 0 payment/method_purchaseorder @@ -200,7 +184,6 @@ 0 offline - - + diff --git a/app/code/core/Mage/Payment/etc/system.xml b/app/code/core/Mage/Payment/etc/system.xml index 0ed7bea589..977c4d7063 100644 --- a/app/code/core/Mage/Payment/etc/system.xml +++ b/app/code/core/Mage/Payment/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Payment - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details.php b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details.php index 201a2a63b1..e84ead6e60 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details/Form.php b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details/Form.php index 80ec270afa..730169cf1a 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details/Form.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Details/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php index 6b8af73a10..7352705112 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report/Grid.php b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report/Grid.php index a1742c1a81..3fbe5230c2 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report/Grid.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/Settlement/Report/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/ApiWizard.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/ApiWizard.php index 3ab93f8c85..0999ecf435 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/ApiWizard.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/ApiWizard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Global.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Global.php index abb1ac3bae..523519d447 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Global.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Global.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Hint.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Hint.php index bc61e9bc39..ed66555b55 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Hint.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Hint.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php index e2de313329..385dbf7ade 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Payflowlink/Info.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Payflowlink/Info.php index 4e9695e1b7..6acdd25124 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Payflowlink/Info.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Payflowlink/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Express/Form.php b/app/code/core/Mage/Paypal/Block/Express/Form.php index a9692facba..39fc6e0fd5 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Form.php +++ b/app/code/core/Mage/Paypal/Block/Express/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Express/Review.php b/app/code/core/Mage/Paypal/Block/Express/Review.php index 5701cccfbe..51d810a684 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Review.php +++ b/app/code/core/Mage/Paypal/Block/Express/Review.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Express/Review/Details.php b/app/code/core/Mage/Paypal/Block/Express/Review/Details.php index 0b838b3727..b92efcef59 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Review/Details.php +++ b/app/code/core/Mage/Paypal/Block/Express/Review/Details.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Express/Shortcut.php b/app/code/core/Mage/Paypal/Block/Express/Shortcut.php index 5fc4322f20..ca80af55de 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Shortcut.php +++ b/app/code/core/Mage/Paypal/Block/Express/Shortcut.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php b/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php index ed5e50a075..393cde8c65 100644 --- a/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Hosted/Pro/Iframe.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Iframe.php b/app/code/core/Mage/Paypal/Block/Iframe.php index 6065e0556e..bcc3bba935 100644 --- a/app/code/core/Mage/Paypal/Block/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Iframe.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Logo.php b/app/code/core/Mage/Paypal/Block/Logo.php index 99c45ba727..a5fb0af7ff 100644 --- a/app/code/core/Mage/Paypal/Block/Logo.php +++ b/app/code/core/Mage/Paypal/Block/Logo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Payflow/Link/Form.php b/app/code/core/Mage/Paypal/Block/Payflow/Link/Form.php index 009d44d160..d68128c23a 100644 --- a/app/code/core/Mage/Paypal/Block/Payflow/Link/Form.php +++ b/app/code/core/Mage/Paypal/Block/Payflow/Link/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php b/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php index 170d46c844..b3db7669ee 100644 --- a/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Payflow/Link/Iframe.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Payflow/Link/Info.php b/app/code/core/Mage/Paypal/Block/Payflow/Link/Info.php index c368a87155..e521d4b1f8 100644 --- a/app/code/core/Mage/Paypal/Block/Payflow/Link/Info.php +++ b/app/code/core/Mage/Paypal/Block/Payflow/Link/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Payment/Info.php b/app/code/core/Mage/Paypal/Block/Payment/Info.php index fd89e46ee9..c9542b7604 100644 --- a/app/code/core/Mage/Paypal/Block/Payment/Info.php +++ b/app/code/core/Mage/Paypal/Block/Payment/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Standard/Form.php b/app/code/core/Mage/Paypal/Block/Standard/Form.php index 88c626399d..0d4e34cd60 100644 --- a/app/code/core/Mage/Paypal/Block/Standard/Form.php +++ b/app/code/core/Mage/Paypal/Block/Standard/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Block/Standard/Redirect.php b/app/code/core/Mage/Paypal/Block/Standard/Redirect.php index 2b6001bb80..48b1d363a2 100644 --- a/app/code/core/Mage/Paypal/Block/Standard/Redirect.php +++ b/app/code/core/Mage/Paypal/Block/Standard/Redirect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Paypal_Block_Standard_Redirect extends Mage_Core_Block_Abstract diff --git a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php index a0cbbb1d0f..ca8a6b484a 100644 --- a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php +++ b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Helper/Data.php b/app/code/core/Mage/Paypal/Helper/Data.php index 9a83955c3a..a32fc67a5e 100644 --- a/app/code/core/Mage/Paypal/Helper/Data.php +++ b/app/code/core/Mage/Paypal/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Helper/Hss.php b/app/code/core/Mage/Paypal/Helper/Hss.php index 7b9cb1f0df..6ac58ab414 100644 --- a/app/code/core/Mage/Paypal/Helper/Hss.php +++ b/app/code/core/Mage/Paypal/Helper/Hss.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Api/Abstract.php b/app/code/core/Mage/Paypal/Model/Api/Abstract.php index 6ad78e2bc2..f909132e94 100644 --- a/app/code/core/Mage/Paypal/Model/Api/Abstract.php +++ b/app/code/core/Mage/Paypal/Model/Api/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Api/Nvp.php b/app/code/core/Mage/Paypal/Model/Api/Nvp.php index be587b7e48..75535dada6 100644 --- a/app/code/core/Mage/Paypal/Model/Api/Nvp.php +++ b/app/code/core/Mage/Paypal/Model/Api/Nvp.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -35,6 +35,7 @@ class Mage_Paypal_Model_Api_Nvp extends Mage_Paypal_Model_Api_Abstract */ const DO_DIRECT_PAYMENT = 'DoDirectPayment'; const DO_CAPTURE = 'DoCapture'; + const DO_AUTHORIZATION = 'DoAuthorization'; const DO_VOID = 'DoVoid'; const REFUND_TRANSACTION = 'RefundTransaction'; const SET_EXPRESS_CHECKOUT = 'SetExpressCheckout'; @@ -274,6 +275,14 @@ class Mage_Paypal_Model_Api_Nvp extends Mage_Paypal_Model_Api_Abstract protected $_doCaptureRequest = array('AUTHORIZATIONID', 'COMPLETETYPE', 'AMT', 'CURRENCYCODE', 'NOTE', 'INVNUM',); protected $_doCaptureResponse = array('TRANSACTIONID', 'CURRENCYCODE', 'AMT', 'PAYMENTSTATUS', 'PENDINGREASON',); + + /** + * DoAuthorization request/response map + * @var array + */ + protected $_doAuthorizationRequest = array('TRANSACTIONID', 'AMT', 'CURRENCYCODE'); + protected $_doAuthorizationResponse = array('TRANSACTIONID', 'AMT'); + /** * DoVoid request map * @var array @@ -673,6 +682,23 @@ public function callDoCapture() $this->_importFromResponse($this->_doCaptureResponse, $response); } + /** + * DoAuthorization call + * + * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoAuthorization + * @return Mage_Paypal_Model_Api_Nvp + */ + public function callDoAuthorization() + { + $request = $this->_exportToRequest($this->_doAuthorizationRequest); + $response = $this->call(self::DO_AUTHORIZATION, $request); + $this->_importFromResponse($this->_paymentInformationResponse, $response); + $this->_importFromResponse($this->_doAuthorizationResponse, $response); + + return $this; + } + + /** * DoVoid call * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoVoid diff --git a/app/code/core/Mage/Paypal/Model/Api/Standard.php b/app/code/core/Mage/Paypal/Model/Api/Standard.php index aa0d17e2d2..cae9b4e0de 100644 --- a/app/code/core/Mage/Paypal/Model/Api/Standard.php +++ b/app/code/core/Mage/Paypal/Model/Api/Standard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Cart.php b/app/code/core/Mage/Paypal/Model/Cart.php index 022293df8f..ab165bb909 100644 --- a/app/code/core/Mage/Paypal/Model/Cart.php +++ b/app/code/core/Mage/Paypal/Model/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Cert.php b/app/code/core/Mage/Paypal/Model/Cert.php index 86e5a6a790..bfd9982641 100644 --- a/app/code/core/Mage/Paypal/Model/Cert.php +++ b/app/code/core/Mage/Paypal/Model/Cert.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Config.php b/app/code/core/Mage/Paypal/Model/Config.php index 0cf10441a7..b8d4bb1769 100644 --- a/app/code/core/Mage/Paypal/Model/Config.php +++ b/app/code/core/Mage/Paypal/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1158,6 +1158,9 @@ protected function _mapExpressFieldset($fieldName) case 'solution_type': case 'visible_on_cart': case 'visible_on_product': + case 'authorization_honor_period': + case 'order_valid_period': + case 'child_authorization_number': case 'allow_ba_signup': return "payment/{$this->_methodCode}/{$fieldName}"; default: diff --git a/app/code/core/Mage/Paypal/Model/Direct.php b/app/code/core/Mage/Paypal/Model/Direct.php index 1c12a61d9b..fa313a7769 100644 --- a/app/code/core/Mage/Paypal/Model/Direct.php +++ b/app/code/core/Mage/Paypal/Model/Direct.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -140,7 +140,7 @@ public function getAllowedCcTypes() */ public function isAvailable($quote = null) { - if ($this->_pro->getConfig()->isMethodAvailable() && parent::isAvailable($quote)) { + if (parent::isAvailable($quote) && $this->_pro->getConfig()->isMethodAvailable()) { return true; } return false; diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php index 77a79fa990..cc08fd08ef 100644 --- a/app/code/core/Mage/Paypal/Model/Express.php +++ b/app/code/core/Mage/Paypal/Model/Express.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -67,6 +67,18 @@ class Mage_Paypal_Model_Express extends Mage_Payment_Model_Method_Abstract */ protected $_pro = null; + /** + * Payment additional information key for payment action + * @var string + */ + protected $_isOrderPaymentActionKey = 'is_order_action'; + + /** + * Payment additional information key for number of used authorizations + * @var string + */ + protected $_authorizationCountKey = 'authorization_count'; + public function __construct($params = array()) { $proInstance = array_shift($params); @@ -123,7 +135,7 @@ public function getConfigPaymentAction() */ public function isAvailable($quote = null) { - if ($this->_pro->getConfig()->isMethodAvailable() && parent::isAvailable($quote)) { + if (parent::isAvailable($quote) && $this->_pro->getConfig()->isMethodAvailable()) { return true; } return false; @@ -150,7 +162,57 @@ public function getConfigData($field, $storeId = null) */ public function order(Varien_Object $payment, $amount) { - return $this->_placeOrder($payment, $amount); + $this->_placeOrder($payment, $amount); + + $payment->setAdditionalInformation($this->_isOrderPaymentActionKey, true); + + if ($payment->getIsFraudDetected()) { + return $this; + } + + $order = $payment->getOrder(); + $orderTransactionId = $payment->getTransactionId(); + + $api = $this->_callDoAuthorize($amount, $payment, $payment->getTransactionId()); + + $state = Mage_Sales_Model_Order::STATE_PROCESSING; + $status = true; + + $formatedPrice = $order->getBaseCurrency()->formatTxt($amount); + if ($payment->getIsTransactionPending()) { + $message = Mage::helper('paypal')->__('Ordering amount of %s is pending approval on gateway.', $formatedPrice); + $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW; + } else { + $message = Mage::helper('paypal')->__('Ordered amount of %s.', $formatedPrice); + } + + $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER, null, false, $message); + + $this->_pro->importPaymentInfo($api, $payment); + + if ($payment->getIsTransactionPending()) { + $message = Mage::helper('paypal')->__('Authorizing amount of %s is pending approval on gateway.', $formatedPrice); + $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW; + if ($payment->getIsFraudDetected()) { + $status = Mage_Sales_Model_Order::STATUS_FRAUD; + } + } else { + $message = Mage::helper('paypal')->__('Authorized amount of %s.', $formatedPrice); + } + + $payment->resetTransactionAdditionalInfo(); + + $payment->setTransactionId($api->getTransactionId()); + $payment->setParentTransactionId($orderTransactionId); + + $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null, false, + $message + ); + + $order->setState($state, $status); + + $payment->setSkipOrderProcessing(true); + return $this; } /** @@ -186,6 +248,59 @@ public function void(Varien_Object $payment) */ public function capture(Varien_Object $payment, $amount) { + $authorizationTransaction = $payment->getAuthorizationTransaction(); + $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period'))); + $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number'))); + $order = $payment->getOrder(); + + if ($authorizationTransaction) { + $transactionDate = new DateTime($authorizationTransaction->getCreatedAt()); + $dateCompass = new DateTime('-' . $authorizationPeriod . ' days'); + + if ($dateCompass > $transactionDate || $authorizationPeriod == 0) { + if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) { + Mage::throwException(Mage::helper('paypal')->__('The maximum number of child authorizations is reached.')); + } + + //Save payment state and configure payment object for voiding + $isCaptureFinal = $payment->getShouldCloseParentTransaction(); + $payment->setShouldCloseParentTransaction(false); + $payment->setParentTransactionId($authorizationTransaction->getTxnId()); + $payment->unsTransactionId(); + $payment->void(new Varien_Object()); + + //Revert payment state after voiding + $payment->unsAuthorizationTransaction(); + $payment->setShouldCloseParentTransaction($isCaptureFinal); + + $api = $this->_callDoAuthorize( + $order->getBaseGrandTotal() - $order->getBaseTotalInvoiced(), + $payment, + $authorizationTransaction->getParentTxnId() + ); + + //Adding authorization transaction + $this->_pro->importPaymentInfo($api, $payment); + $payment->setTransactionId($api->getTransactionId()); + $payment->setParentTransactionId($authorizationTransaction->getParentTxnId()); + $payment->setIsTransactionClosed(false); + + $formatedPrice = $order->getBaseCurrency()-> + formatTxt($order->getBaseGrandTotal() - $order->getBaseTotalInvoiced()); + + if ($payment->getIsTransactionPending()) { + $message = Mage::helper('paypal')->__('Authorizing amount of %s is pending approval on gateway.', $formatedPrice); + } else { + $message = Mage::helper('paypal')->__('Authorized amount of %s.', $formatedPrice); + } + + $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null, + false, $message + ); + + $payment->setParentTransactionId($api->getTransactionId()); + } + } if (false === $this->_pro->capture($payment, $amount)) { $this->_placeOrder($payment, $amount); } @@ -388,6 +503,7 @@ protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount) // call api and get details from it $api->callDoExpressCheckoutPayment(); + $this->_importToPayment($api, $payment); return $this; } @@ -431,4 +547,52 @@ public function canVoid(Varien_Object $payment) return $this->_canVoid; } + + /** + * Check capture availability + * + * @return bool + */ + public function canCapture() + { + $payment = $this->getInfoInstance(); + $this->_pro->getConfig()->setStoreId($payment->getOrder()->getStore()->getId()); + + if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) { + $orderTransaction = $payment->lookupTransaction(false, + Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER + ); + $orderValidPeriod = abs(intval($this->getConfigData('order_valid_period'))); + $transactionDate = new DateTime($orderTransaction->getCreatedAt()); + $dateCompass = new DateTime('-' . $orderValidPeriod . ' days'); + + if ($dateCompass > $transactionDate || $orderValidPeriod == 0) { + return false; + } + } + return $this->_canCapture; + } + + /** + * Call DoAuthorize + * + * @param int $amount + * @param Varien_Object $payment + * @param string $parentTransactionId + * @return Mage_Paypal_Model_Api_Abstract + */ + protected function _callDoAuthorize($amount, $payment, $parentTransactionId) + { + $api = $this->_pro->resetApi()->getApi() + ->setAmount($amount) + ->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode()) + ->setTransactionId($parentTransactionId) + ->callDoAuthorization(); + + $payment->setAdditionalInformation($this->_authorizationCountKey, + $payment->getAdditionalInformation($this->_authorizationCountKey) + 1 + ); + + return $api; + } } diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index b71722416c..cfc426d787 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -352,7 +352,9 @@ public function returnFromPaypal($token) $billingAddress = $this->_quote->getBillingAddress(); $exportedBillingAddress = $this->_api->getExportedBillingAddress(); foreach ($exportedBillingAddress->getExportedKeys() as $key) { - $billingAddress->setDataUsingMethod($key, $exportedBillingAddress->getData($key)); + if (!$billingAddress->getDataUsingMethod($key)) { + $billingAddress->setDataUsingMethod($key, $exportedBillingAddress->getData($key)); + } } // import shipping address @@ -375,7 +377,10 @@ public function returnFromPaypal($token) $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true); } } - $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code); + $this->_quote->getPayment()->setAdditionalInformation( + self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, + $code + ); } } $this->_ignoreAddressValidation(); @@ -500,7 +505,9 @@ public function place($token, $shippingMethodCode = null) $this->_billingAgreement = $order->getPayment()->getBillingAgreement(); // commence redirecting to finish payment, if paypal requires it - if ($order->getPayment()->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT)) { + if ($order->getPayment()->getAdditionalInformation( + Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT + )) { $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token); } diff --git a/app/code/core/Mage/Paypal/Model/Hostedpro.php b/app/code/core/Mage/Paypal/Model/Hostedpro.php index c3a96323f6..c9d60f0bd4 100644 --- a/app/code/core/Mage/Paypal/Model/Hostedpro.php +++ b/app/code/core/Mage/Paypal/Model/Hostedpro.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Hostedpro/Request.php b/app/code/core/Mage/Paypal/Model/Hostedpro/Request.php index 2052b25b48..c110e7f871 100644 --- a/app/code/core/Mage/Paypal/Model/Hostedpro/Request.php +++ b/app/code/core/Mage/Paypal/Model/Hostedpro/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Info.php b/app/code/core/Mage/Paypal/Model/Info.php index a71aabfaf7..7bc009b38d 100644 --- a/app/code/core/Mage/Paypal/Model/Info.php +++ b/app/code/core/Mage/Paypal/Model/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Ipn.php b/app/code/core/Mage/Paypal/Model/Ipn.php index c5a6442878..4673395fcc 100644 --- a/app/code/core/Mage/Paypal/Model/Ipn.php +++ b/app/code/core/Mage/Paypal/Model/Ipn.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Method/Agreement.php b/app/code/core/Mage/Paypal/Model/Method/Agreement.php index 6b96038b32..d3d7d52ffb 100644 --- a/app/code/core/Mage/Paypal/Model/Method/Agreement.php +++ b/app/code/core/Mage/Paypal/Model/Method/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Mysql4/Cert.php b/app/code/core/Mage/Paypal/Model/Mysql4/Cert.php index 7704fb320a..97e5e5c70f 100644 --- a/app/code/core/Mage/Paypal/Model/Mysql4/Cert.php +++ b/app/code/core/Mage/Paypal/Model/Mysql4/Cert.php @@ -20,59 +20,18 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * PayPal resource model for certificate based authentication + * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team */ -class Mage_Paypal_Model_Mysql4_Cert extends Mage_Core_Model_Mysql4_Abstract +class Mage_Paypal_Model_Mysql4_Cert extends Mage_Paypal_Model_Resource_Cert { - /** - * Initialize connection - */ - protected function _construct() - { - $this->_init('paypal/cert', 'cert_id'); - } - - /** - * Set date of last update - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $object->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate()); - return parent::_beforeSave($object); - } - - /** - * Load model by website id - * - * @param Mage_Paypal_Model_Cert $object - * @param bool $strictLoad - * @return Mage_Paypal_Model_Cert - */ - public function loadByWebsite($object, $strictLoad = true) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select()->from(array('main_table' => $this->getMainTable())); - - if ($strictLoad) { - $select->where('main_table.website_id =?', $object->getWebsiteId()); - } else { - $select->where('main_table.website_id IN(0, ?)', $object->getWebsiteId()) - ->order('main_table.website_id DESC') - ->limit(1); - } - - $data = $adapter->fetchRow($select); - if ($data) { - $object->setData($data); - } - return $object; - } } diff --git a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement.php index 03f71e0f5c..1e9fd6cbf7 100644 --- a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement.php @@ -20,74 +20,18 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -/* - * - * Paypal Settlement Report — writing side. - * The resource model + +/** + * Enter description here ... * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team */ -class Mage_Paypal_Model_Mysql4_Report_Settlement extends Mage_Core_Model_Mysql4_Abstract +class Mage_Paypal_Model_Mysql4_Report_Settlement extends Mage_Paypal_Model_Resource_Report_Settlement { - protected $_rowsTable; - - /** - * Init main table - */ - protected function _construct() - { - $this->_init('paypal/settlement_report', 'report_id'); - $this->_rowsTable = Mage::getSingleton('core/resource')->getTableName('paypal/settlement_report_row'); - } - - /** - * Save report rows collected in settlement model - * - * @param Mage_Paypal_Model_Report_Settlement $object - * @return Mage_Paypal_Model_Mysql4_Report_Settlement - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $rows = $object->getRows(); - if (is_array($rows)){ - try { - $this->_getWriteAdapter()->beginTransaction(); - if ($object->getId()) { - $this->_getWriteAdapter()->query(sprintf('DELETE FROM %s WHERE report_id = :report', $this->_rowsTable), array('report' => $object->getId())); - } - foreach ($rows as $key => $row) { - $rows[$key]['report_id'] = $object->getId(); - } - $this->_getWriteAdapter()->insertMultiple($this->_rowsTable, $rows); - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollback(); - } - } - return $this; - } - - /** - * Check if report with same account and report date already fetched - * - * @param Mage_Paypal_Model_Report_Settlement $report - * @param string $accountId - * @param string $reportDate - * @return bool - */ - public function loadByAccountAndDate(Mage_Paypal_Model_Report_Settlement $report, $accountId, $reportDate) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->where('account_id=?', $accountId) - ->where('report_date=?', $reportDate); - if ($data = $this->_getReadAdapter()->fetchRow($select)) { - $report->addData($data); - } - return $this; - } } diff --git a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row.php b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row.php index bc1be215b1..dc3d39ebe8 100644 --- a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row.php +++ b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row.php @@ -20,17 +20,18 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -/* - * Resource for report rows + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team */ -class Mage_Paypal_Model_Mysql4_Report_Settlement_Row extends Mage_Core_Model_Mysql4_Abstract +class Mage_Paypal_Model_Mysql4_Report_Settlement_Row extends Mage_Paypal_Model_Resource_Report_Settlement_Row { - protected function _construct() - { - $this->_init('paypal/settlement_report_row', 'row_id'); - } } diff --git a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row/Collection.php b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row/Collection.php index 772f55d898..a7e8488dbc 100644 --- a/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row/Collection.php +++ b/app/code/core/Mage/Paypal/Model/Mysql4/Report/Settlement/Row/Collection.php @@ -20,49 +20,19 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * * Resource collection for report rows * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team */ -class Mage_Paypal_Model_Mysql4_Report_Settlement_Row_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Paypal_Model_Mysql4_Report_Settlement_Row_Collection + extends Mage_Paypal_Model_Resource_Report_Settlement_Row_Collection { - /** - * Resource initializing - */ - protected function _construct () - { - $this->_init('paypal/report_settlement_row'); - } - - /** - * Join reports info table - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->getSelect() - ->join( - array('report' => $this->getTable('paypal/settlement_report')), - 'report.report_id = main_table.report_id', - array('report.account_id', 'report.report_date') - ); - return $this; - } - - /** - * Filter items collection by account ID - * - * @param string $accountID The account hash as returned by paypal - * @return Mage_Paypal_Model_Mysql4_Report_Settlement_Row_Collection - */ - public function addAccountFilter($accountId) - { - $this->getSelect()->where('report.account_id = ?', $accountId); - return $this; - } } diff --git a/app/code/core/Mage/Paypal/Model/Mysql4/Setup.php b/app/code/core/Mage/Paypal/Model/Mysql4/Setup.php index b8d3e9a29a..432e4ef201 100644 --- a/app/code/core/Mage/Paypal/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Paypal/Model/Mysql4/Setup.php @@ -20,16 +20,18 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * * PayPal Setup Resource class + * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team */ -class Mage_Paypal_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup +class Mage_Paypal_Model_Mysql4_Setup extends Mage_Paypal_Model_Resource_Setup { - } diff --git a/app/code/core/Mage/Paypal/Model/Observer.php b/app/code/core/Mage/Paypal/Model/Observer.php index e6edfad7d2..e0e7fb526f 100644 --- a/app/code/core/Mage/Paypal/Model/Observer.php +++ b/app/code/core/Mage/Paypal/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Payflow/Request.php b/app/code/core/Mage/Paypal/Model/Payflow/Request.php index 5f0fec644d..d3eff5f8d1 100644 --- a/app/code/core/Mage/Paypal/Model/Payflow/Request.php +++ b/app/code/core/Mage/Paypal/Model/Payflow/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Payflowlink.php b/app/code/core/Mage/Paypal/Model/Payflowlink.php index 047dc7b97b..cec352841d 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowlink.php +++ b/app/code/core/Mage/Paypal/Model/Payflowlink.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -94,8 +94,7 @@ public function isAvailable($quote = null) { $storeId = Mage::app()->getStore($this->getStore())->getId(); $config = Mage::getModel('paypal/config')->setStoreId($storeId); - if ($config->isMethodAvailable($this->getCode()) && - Mage_Payment_Model_Method_Abstract::isAvailable($quote)) { + if (Mage_Payment_Model_Method_Abstract::isAvailable($quote) && $config->isMethodAvailable($this->getCode())) { return true; } return false; diff --git a/app/code/core/Mage/Paypal/Model/Payflowpro.php b/app/code/core/Mage/Paypal/Model/Payflowpro.php index 0f3aeff24b..de8ca11df9 100644 --- a/app/code/core/Mage/Paypal/Model/Payflowpro.php +++ b/app/code/core/Mage/Paypal/Model/Payflowpro.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -122,7 +122,7 @@ public function isAvailable($quote = null) { $storeId = Mage::app()->getStore($this->getStore())->getId(); $config = Mage::getModel('paypal/config')->setStoreId($storeId); - if ($config->isMethodAvailable($this->getCode()) && parent::isAvailable($quote)) { + if (parent::isAvailable($quote) && $config->isMethodAvailable($this->getCode())) { return true; } return false; diff --git a/app/code/core/Mage/Paypal/Model/Pro.php b/app/code/core/Mage/Paypal/Model/Pro.php index 4b07777dff..21b6dd26a7 100644 --- a/app/code/core/Mage/Paypal/Model/Pro.php +++ b/app/code/core/Mage/Paypal/Model/Pro.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -136,6 +136,18 @@ public function getApi() return $this->_api; } + /** + * Destroy existing NVP Api object + * + * @return Mage_Paypal_Model_Pro + */ + public function resetApi() + { + $this->_api = null; + + return $this; + } + /** * Instantiate and return info model * @@ -352,8 +364,9 @@ public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $p * @param Mage_Payment_Model_Info $paymentInfo * @throws Mage_Core_Exception */ - public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile, Mage_Payment_Model_Info $paymentInfo) - { + public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile, + Mage_Payment_Model_Info $paymentInfo + ) { $api = $this->getApi(); Varien_Object_Mapper::accumulateByMap($profile, $api, array( 'token', // EC fields diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Report/Settlement.php index a938598e4c..fe21bdffd3 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,6 +31,24 @@ * Prepare report rows for Mage_Paypal_Model_Report_Settlement_Row model * */ +/** + * Enter description here ... + * + * @method Mage_Paypal_Model_Resource_Report_Settlement _getResource() + * @method Mage_Paypal_Model_Resource_Report_Settlement getResource() + * @method string getReportDate() + * @method Mage_Paypal_Model_Report_Settlement setReportDate(string $value) + * @method string getAccountId() + * @method Mage_Paypal_Model_Report_Settlement setAccountId(string $value) + * @method string getFilename() + * @method Mage_Paypal_Model_Report_Settlement setFilename(string $value) + * @method string getLastModified() + * @method Mage_Paypal_Model_Report_Settlement setLastModified(string $value) + * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team + */ class Mage_Paypal_Model_Report_Settlement extends Mage_Core_Model_Abstract { /** diff --git a/app/code/core/Mage/Paypal/Model/Report/Settlement/Row.php b/app/code/core/Mage/Paypal/Model/Report/Settlement/Row.php index c5dbe5a4d0..4ce472f95f 100644 --- a/app/code/core/Mage/Paypal/Model/Report/Settlement/Row.php +++ b/app/code/core/Mage/Paypal/Model/Report/Settlement/Row.php @@ -20,13 +20,55 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /* * Model for report rows */ +/** + * Enter description here ... + * + * @method Mage_Paypal_Model_Resource_Report_Settlement_Row _getResource() + * @method Mage_Paypal_Model_Resource_Report_Settlement_Row getResource() + * @method int getReportId() + * @method Mage_Paypal_Model_Report_Settlement_Row setReportId(int $value) + * @method string getTransactionId() + * @method Mage_Paypal_Model_Report_Settlement_Row setTransactionId(string $value) + * @method string getInvoiceId() + * @method Mage_Paypal_Model_Report_Settlement_Row setInvoiceId(string $value) + * @method string getPaypalReferenceId() + * @method Mage_Paypal_Model_Report_Settlement_Row setPaypalReferenceId(string $value) + * @method string getPaypalReferenceIdType() + * @method Mage_Paypal_Model_Report_Settlement_Row setPaypalReferenceIdType(string $value) + * @method string getTransactionEventCode() + * @method Mage_Paypal_Model_Report_Settlement_Row setTransactionEventCode(string $value) + * @method string getTransactionInitiationDate() + * @method Mage_Paypal_Model_Report_Settlement_Row setTransactionInitiationDate(string $value) + * @method string getTransactionCompletionDate() + * @method Mage_Paypal_Model_Report_Settlement_Row setTransactionCompletionDate(string $value) + * @method string getTransactionDebitOrCredit() + * @method Mage_Paypal_Model_Report_Settlement_Row setTransactionDebitOrCredit(string $value) + * @method float getGrossTransactionAmount() + * @method Mage_Paypal_Model_Report_Settlement_Row setGrossTransactionAmount(float $value) + * @method string getGrossTransactionCurrency() + * @method Mage_Paypal_Model_Report_Settlement_Row setGrossTransactionCurrency(string $value) + * @method string getFeeDebitOrCredit() + * @method Mage_Paypal_Model_Report_Settlement_Row setFeeDebitOrCredit(string $value) + * @method float getFeeAmount() + * @method Mage_Paypal_Model_Report_Settlement_Row setFeeAmount(float $value) + * @method string getFeeCurrency() + * @method Mage_Paypal_Model_Report_Settlement_Row setFeeCurrency(string $value) + * @method string getCustomField() + * @method Mage_Paypal_Model_Report_Settlement_Row setCustomField(string $value) + * @method string getConsumerId() + * @method Mage_Paypal_Model_Report_Settlement_Row setConsumerId(string $value) + * + * @category Mage + * @package Mage_Paypal + * @author Magento Core Team + */ class Mage_Paypal_Model_Report_Settlement_Row extends Mage_Core_Model_Abstract { /** diff --git a/app/code/core/Mage/Paypal/Model/Resource/Cert.php b/app/code/core/Mage/Paypal/Model/Resource/Cert.php new file mode 100644 index 0000000000..78af06bac0 --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/Resource/Cert.php @@ -0,0 +1,83 @@ + + */ +class Mage_Paypal_Model_Resource_Cert extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection + */ + protected function _construct() + { + $this->_init('paypal/cert', 'cert_id'); + } + + /** + * Set date of last update + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $object->setUpdatedAt($this->formatDate(Mage::getSingleton('core/date')->gmtDate())); + return parent::_beforeSave($object); + } + + /** + * Load model by website id + * + * @param Mage_Paypal_Model_Cert $object + * @param bool $strictLoad + * @return Mage_Paypal_Model_Cert + */ + public function loadByWebsite($object, $strictLoad = true) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select()->from(array('main_table' => $this->getMainTable())); + + if ($strictLoad) { + $select->where('main_table.website_id =?', $object->getWebsiteId()); + } else { + $select->where('main_table.website_id IN(0, ?)', $object->getWebsiteId()) + ->order('main_table.website_id DESC') + ->limit(1); + } + + $data = $adapter->fetchRow($select); + if ($data) { + $object->setData($data); + } + return $object; + } +} diff --git a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php new file mode 100755 index 0000000000..2c5a435aa7 --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php @@ -0,0 +1,126 @@ + + */ +class Mage_Paypal_Model_Resource_Report_Settlement extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Table name + * + * @var string + */ + protected $_rowsTable; + + /** + * Init main table + * + */ + protected function _construct() + { + $this->_init('paypal/settlement_report', 'report_id'); + $this->_rowsTable = $this->getTable('paypal/settlement_report_row'); + } + + /** + * Save report rows collected in settlement model + * + * @param Mage_Paypal_Model_Report_Settlement $object + * @return Mage_Paypal_Model_Resource_Report_Settlement + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $rows = $object->getRows(); + if (is_array($rows)) { + $adapter = $this->_getWriteAdapter(); + $reportId = (int)$object->getId(); + try { + $adapter->beginTransaction(); + if ($reportId) { + $adapter->delete($this->_rowsTable, array('report_id = ?' => $reportId)); + } + /** @var $date Mage_Core_Model_Date */ + $date = Mage::getSingleton('core/date'); + + foreach ($rows as $key => $row) { + /* + * Converting dates + */ + $completionDate = new Zend_Date($rows[$key]['transaction_completion_date']); + $rows[$key]['transaction_completion_date'] = $date->date(null, $completionDate->getTimestamp()); + $initiationDate = new Zend_Date($rows[$key]['transaction_initiation_date']); + $rows[$key]['transaction_initiation_date'] = $date->date(null, $initiationDate->getTimestamp()); + /* + * Converting numeric + */ + $rows[$key]['fee_amount'] = (float)$rows[$key]['fee_amount']; + /* + * Setting reportId + */ + $rows[$key]['report_id'] = $reportId; + } + if (!empty($rows)) { + $adapter->insertMultiple($this->_rowsTable, $rows); + } + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollback(); + } + } + + return $this; + } + + /** + * Check if report with same account and report date already fetched + * + * @param Mage_Paypal_Model_Report_Settlement $report + * @param string $accountId + * @param string $reportDate + * @return Mage_Paypal_Model_Resource_Report_Settlement + */ + public function loadByAccountAndDate(Mage_Paypal_Model_Report_Settlement $report, $accountId, $reportDate) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('account_id = :account_id') + ->where('report_date = :report_date'); + + $data = $adapter->fetchRow($select, array(':account_id' => $accountId, ':report_date' => $reportDate)); + if ($data) { + $report->addData($data); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row.php b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row.php new file mode 100755 index 0000000000..0bd52adf11 --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row.php @@ -0,0 +1,45 @@ + + */ +class Mage_Paypal_Model_Resource_Report_Settlement_Row extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource model initialization. + * Set main entity table name and primary key field name. + */ + protected function _construct() + { + $this->_init('paypal/settlement_report_row', 'row_id'); + } +} diff --git a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row/Collection.php b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row/Collection.php new file mode 100755 index 0000000000..a84d937d1b --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement/Row/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Paypal_Model_Resource_Report_Settlement_Row_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initializing + * + */ + protected function _construct() + { + $this->_init('paypal/report_settlement_row'); + } + + /** + * Join reports info table + * + * @return Mage_Paypal_Model_Resource_Report_Settlement_Row_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->getSelect() + ->join( + array('report' => $this->getTable('paypal/settlement_report')), + 'report.report_id = main_table.report_id', + array('report.account_id', 'report.report_date') + ); + return $this; + } + + /** + * Filter items collection by account ID + * + * @param string $accountId + * @return Mage_Paypal_Model_Resource_Report_Settlement_Row_Collection + */ + public function addAccountFilter($accountId) + { + $this->getSelect()->where('report.account_id = ?', $accountId); + return $this; + } +} diff --git a/app/code/core/Mage/Paypal/Model/Resource/Setup.php b/app/code/core/Mage/Paypal/Model/Resource/Setup.php new file mode 100755 index 0000000000..861cac4263 --- /dev/null +++ b/app/code/core/Mage/Paypal/Model/Resource/Setup.php @@ -0,0 +1,37 @@ + + */ +class Mage_Paypal_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/Paypal/Model/Session.php b/app/code/core/Mage/Paypal/Model/Session.php index 7b8f87eb67..8c7e727783 100644 --- a/app/code/core/Mage/Paypal/Model/Session.php +++ b/app/code/core/Mage/Paypal/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/Standard.php b/app/code/core/Mage/Paypal/Model/Standard.php index 55851bb121..c0103016b9 100644 --- a/app/code/core/Mage/Paypal/Model/Standard.php +++ b/app/code/core/Mage/Paypal/Model/Standard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -183,7 +183,7 @@ public function getConfig() */ public function isAvailable($quote = null) { - if ($this->getConfig()->isMethodAvailable() && parent::isAvailable($quote)) { + if (parent::isAvailable($quote) && $this->getConfig()->isMethodAvailable()) { return true; } return false; diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php index fc31f93e9b..8bd826244c 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cert.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cron.php b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cron.php index 5af3bd0164..927246759b 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cron.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Backend/Cron.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Backend/MerchantCountry.php b/app/code/core/Mage/Paypal/Model/System/Config/Backend/MerchantCountry.php index 433e073410..ff8c066e02 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Backend/MerchantCountry.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Backend/MerchantCountry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/BuyerCountry.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/BuyerCountry.php index f4874456f3..3ab846ce25 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/BuyerCountry.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/BuyerCountry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/FetchingSchedule.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/FetchingSchedule.php index 1b8891c064..4b5853af77 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/FetchingSchedule.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/FetchingSchedule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/Logo.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/Logo.php index 89f2ebe8a9..0de192a1e8 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/Logo.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/Logo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/MerchantCountry.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/MerchantCountry.php index beb1e995e1..8192387a6b 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/MerchantCountry.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/MerchantCountry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php index 79068de661..657f94b9a6 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php index e9c0be947d..6071ec4705 100644 --- a/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php +++ b/app/code/core/Mage/Paypal/Model/System/Config/Source/PaymentActions/Express.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php index 57d159e02e..a032fc2376 100644 --- a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php +++ b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/ExpressController.php b/app/code/core/Mage/Paypal/controllers/ExpressController.php index 2ede66bfc7..8f57755905 100644 --- a/app/code/core/Mage/Paypal/controllers/ExpressController.php +++ b/app/code/core/Mage/Paypal/controllers/ExpressController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/HostedproController.php b/app/code/core/Mage/Paypal/controllers/HostedproController.php index dcdf9dc40f..da175a0774 100644 --- a/app/code/core/Mage/Paypal/controllers/HostedproController.php +++ b/app/code/core/Mage/Paypal/controllers/HostedproController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/IpnController.php b/app/code/core/Mage/Paypal/controllers/IpnController.php index a39d1da2aa..e2374febf9 100644 --- a/app/code/core/Mage/Paypal/controllers/IpnController.php +++ b/app/code/core/Mage/Paypal/controllers/IpnController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/PayflowController.php b/app/code/core/Mage/Paypal/controllers/PayflowController.php index 6d2f3d0f49..c6aa62155f 100644 --- a/app/code/core/Mage/Paypal/controllers/PayflowController.php +++ b/app/code/core/Mage/Paypal/controllers/PayflowController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/controllers/StandardController.php b/app/code/core/Mage/Paypal/controllers/StandardController.php index b6c37dfe9f..80da34a773 100644 --- a/app/code/core/Mage/Paypal/controllers/StandardController.php +++ b/app/code/core/Mage/Paypal/controllers/StandardController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/etc/adminhtml.xml b/app/code/core/Mage/Paypal/etc/adminhtml.xml index b887e0813f..fb57830a40 100644 --- a/app/code/core/Mage/Paypal/etc/adminhtml.xml +++ b/app/code/core/Mage/Paypal/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Paypal/etc/config.xml b/app/code/core/Mage/Paypal/etc/config.xml index 49b393f810..c4c0962c25 100644 --- a/app/code/core/Mage/Paypal/etc/config.xml +++ b/app/code/core/Mage/Paypal/etc/config.xml @@ -21,48 +21,60 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.2 + 1.6.0.0 Mage_Paypal_Model - paypal_mysql4 + paypal_resource - - Mage_Paypal_Model_Mysql4 + + Mage_Paypal_Model_Resource + paypal_mysql4 - paypal_api_debug
      - paypal_settlement_report
      - paypal_settlement_report_row
      - paypal_cert
      + + paypal_api_debug
      +
      + + paypal_settlement_report
      +
      + + paypal_settlement_report_row
      +
      + + paypal_cert
      +
      -
      +
      Mage_Paypal - Mage_Paypal_Model_Mysql4_Setup + Mage_Paypal_Model_Resource_Setup - Mage_Paypal_Block + + Mage_Paypal_Block + - - + + + @@ -160,7 +172,6 @@ - 0 dynamic @@ -185,6 +196,9 @@ 1 never paypal + 3 + 29 + 1 paypal/direct @@ -254,7 +268,9 @@ - paypal/observer::fetchReports + + paypal/observer::fetchReports + diff --git a/app/code/core/Mage/Paypal/etc/system.xml b/app/code/core/Mage/Paypal/etc/system.xml index 1a5a92ea97..ce113551b0 100644 --- a/app/code/core/Mage/Paypal/etc/system.xml +++ b/app/code/core/Mage/Paypal/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -466,6 +466,33 @@ 1 1 + + + Specifies what the Authorization Honor Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. + payment/paypal_express/authorization_honor_period + text + 80 + 1 + 1 + + + + Specifies what the Order Valid Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. + payment/paypal_express/order_valid_period + text + 90 + 1 + 1 + + + + The default number of child authorizations in your PayPal account is 1. To do multiple authorizations please contact PayPal to request an increase. + payment/paypal_express/child_authorization_number + text + 100 + 1 + 1 + diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/install-1.6.0.0.php b/app/code/core/Mage/Paypal/sql/paypal_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..26e6873050 --- /dev/null +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/install-1.6.0.0.php @@ -0,0 +1,161 @@ +startSetup(); + +/** + * Create table 'paypal/settlement_report' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('paypal/settlement_report')) + ->addColumn('report_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Report Id') + ->addColumn('report_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Report Date') + ->addColumn('account_id', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + ), 'Account Id') + ->addColumn('filename', Varien_Db_Ddl_Table::TYPE_TEXT, 24, array( + ), 'Filename') + ->addColumn('last_modified', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Last Modified') + ->addIndex($installer->getIdxName('paypal/settlement_report', array('report_date', 'account_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('report_date', 'account_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Paypal Settlement Report Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'paypal/settlement_report_row' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('paypal/settlement_report_row')) + ->addColumn('row_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Row Id') + ->addColumn('report_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Report Id') + ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_TEXT, 19, array( + ), 'Transaction Id') + ->addColumn('invoice_id', Varien_Db_Ddl_Table::TYPE_TEXT, 127, array( + ), 'Invoice Id') + ->addColumn('paypal_reference_id', Varien_Db_Ddl_Table::TYPE_TEXT, 19, array( + ), 'Paypal Reference Id') + ->addColumn('paypal_reference_id_type', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Paypal Reference Id Type') + ->addColumn('transaction_event_code', Varien_Db_Ddl_Table::TYPE_TEXT, 5, array( + ), 'Transaction Event Code') + ->addColumn('transaction_initiation_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Transaction Initiation Date') + ->addColumn('transaction_completion_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Transaction Completion Date') + ->addColumn('transaction_debit_or_credit', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + 'default' => 'CR', + ), 'Transaction Debit Or Credit') + ->addColumn('gross_transaction_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '20,6', array( + 'nullable' => false, + 'default' => '0.000000', + ), 'Gross Transaction Amount') + ->addColumn('gross_transaction_currency', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + 'default' => '', + ), 'Gross Transaction Currency') + ->addColumn('fee_debit_or_credit', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + ), 'Fee Debit Or Credit') + ->addColumn('fee_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '20,6', array( + 'nullable' => false, + 'default' => '0.000000', + ), 'Fee Amount') + ->addColumn('fee_currency', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Fee Currency') + ->addColumn('custom_field', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Custom Field') + ->addColumn('consumer_id', Varien_Db_Ddl_Table::TYPE_TEXT, 127, array( + ), 'Consumer Id') + ->addIndex($installer->getIdxName('paypal/settlement_report_row', array('report_id')), + array('report_id')) + ->addForeignKey($installer->getFkName('paypal/settlement_report_row', 'report_id', 'paypal/settlement_report', 'report_id'), + 'report_id', $installer->getTable('paypal/settlement_report'), 'report_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Paypal Settlement Report Row Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'paypal/cert' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('paypal/cert')) + ->addColumn('cert_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Cert Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0' + ), 'Website Id') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '64K', array( + ), 'Content') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addIndex($installer->getIdxName('paypal/cert', array('website_id')), + array('website_id')) + ->addForeignKey($installer->getFkName('paypal/cert', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Paypal Certificate Table'); +$installer->getConnection()->createTable($table); + +/** + * Add paypal attributes to the: + * - sales/flat_quote_payment_item table + * - sales/flat_order table + */ +$installer->addAttribute('quote_payment', 'paypal_payer_id', array()); +$installer->addAttribute('quote_payment', 'paypal_payer_status', array()); +$installer->addAttribute('quote_payment', 'paypal_correlation_id', array()); +$installer->addAttribute('order', 'paypal_ipn_customer_notified', array('type' => 'int', 'visible' => false, 'default' => 0)); + +/** + * Prepare database after install + */ +$installer->endSetup(); + diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-0.7.0.php index 5628411b64..5b2a4d409b 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-1.4.0.0.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-1.4.0.0.php index 077481d389..062c432819 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-1.4.0.0.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-install-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.1-0.7.2.php index 68f9ff3bc3..8227a56c7f 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.2-0.7.3.php index e86515e2f5..7f7ddb894e 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php index 1d4fc68dbd..1aba46fc36 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php index 131a494833..5781777086 100644 --- a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Paypal - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..99dbbaa7ed --- /dev/null +++ b/app/code/core/Mage/Paypal/sql/paypal_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,280 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('paypal/cert'), + 'FK_PAYPAL_CERT_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('paypal/settlement_report_row'), + 'FK_PAYPAL_SETTLEMENT_ROW_REPORT' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('paypal/cert'), + 'IDX_PAYPAL_CERT_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('paypal/settlement_report'), + 'UNQ_REPORT_DATE_ACCOUNT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('paypal/settlement_report_row'), + 'IDX_REPORT_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('paypal/settlement_report') => array( + 'columns' => array( + 'report_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Report Id' + ), + 'report_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Report Date' + ), + 'account_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Account Id' + ), + 'filename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 24, + 'comment' => 'Filename' + ), + 'last_modified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Last Modified' + ) + ), + 'comment' => 'Paypal Settlement Report Table' + ), + $installer->getTable('paypal/settlement_report_row') => array( + 'columns' => array( + 'row_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Row Id' + ), + 'report_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Report Id' + ), + 'transaction_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 19, + 'comment' => 'Transaction Id' + ), + 'invoice_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 127, + 'comment' => 'Invoice Id' + ), + 'paypal_reference_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 19, + 'comment' => 'Paypal Reference Id' + ), + 'paypal_reference_id_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Paypal Reference Id Type' + ), + 'transaction_event_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 5, + 'comment' => 'Transaction Event Code' + ), + 'transaction_initiation_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Transaction Initiation Date' + ), + 'transaction_completion_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Transaction Completion Date' + ), + 'transaction_debit_or_credit' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'default' => 'CR', + 'comment' => 'Transaction Debit Or Credit' + ), + 'gross_transaction_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 6, + 'precision' => 20, + 'nullable' => false, + 'default' => '0.000000', + 'comment' => 'Gross Transaction Amount' + ), + 'gross_transaction_currency' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'default' => '', + 'comment' => 'Gross Transaction Currency' + ), + 'fee_debit_or_credit' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'comment' => 'Fee Debit Or Credit' + ), + 'fee_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 6, + 'precision' => 20, + 'nullable' => false, + 'default' => '0.000000', + 'comment' => 'Fee Amount' + ), + 'fee_currency' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Fee Currency' + ), + 'custom_field' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Custom Field' + ), + 'consumer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 127, + 'comment' => 'Consumer Id' + ) + ), + 'comment' => 'Paypal Settlement Report Row Table' + ), + $installer->getTable('paypal/cert') => array( + 'columns' => array( + 'cert_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Cert Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Content' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ) + ), + 'comment' => 'Paypal Certificate Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('paypal/cert'), + $installer->getIdxName('paypal/cert', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('paypal/settlement_report'), + $installer->getIdxName( + 'paypal/settlement_report', + array('report_date', 'account_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('report_date', 'account_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('paypal/settlement_report_row'), + $installer->getIdxName('paypal/settlement_report_row', array('report_id')), + array('report_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('paypal/settlement_report_row', 'report_id', 'paypal/settlement_report', 'report_id'), + $installer->getTable('paypal/settlement_report_row'), + 'report_id', + $installer->getTable('paypal/settlement_report'), + 'report_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('paypal/cert', 'website_id', 'core/website', 'website_id'), + $installer->getTable('paypal/cert'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/PaypalUk/Block/Express/Form.php b/app/code/core/Mage/PaypalUk/Block/Express/Form.php index e4751397cf..199e02e618 100644 --- a/app/code/core/Mage/PaypalUk/Block/Express/Form.php +++ b/app/code/core/Mage/PaypalUk/Block/Express/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Block/Express/Shortcut.php b/app/code/core/Mage/PaypalUk/Block/Express/Shortcut.php index 570c80ac9f..119754eda1 100644 --- a/app/code/core/Mage/PaypalUk/Block/Express/Shortcut.php +++ b/app/code/core/Mage/PaypalUk/Block/Express/Shortcut.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Helper/Data.php b/app/code/core/Mage/PaypalUk/Helper/Data.php index 1ab309e468..347bb5411c 100644 --- a/app/code/core/Mage/PaypalUk/Helper/Data.php +++ b/app/code/core/Mage/PaypalUk/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php index 22e50a4bc9..cd3c8776e6 100644 --- a/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php +++ b/app/code/core/Mage/PaypalUk/Model/Api/Nvp.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -29,25 +29,28 @@ */ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp { - /** + /**#@+ * Transaction types declaration - * @var unknown_type + * + * @var mixed */ const TRXTYPE_AUTH_ONLY = 'A'; const TRXTYPE_SALE = 'S'; const TRXTYPE_CREDIT = 'C'; const TRXTYPE_DELAYED_CAPTURE = 'D'; const TRXTYPE_DELAYED_VOID = 'V'; + /**#@-*/ - /** + /**#@+ * Tender definition * - * @var unknown_type + * @var mixed */ const TENDER_CC = 'C'; const TENDER_PAYPAL = 'P'; + /**#@-*/ - /** + /**#@+ * Express Checkout Actions * * @var string @@ -55,24 +58,29 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp const EXPRESS_SET = 'S'; const EXPRESS_GET = 'G'; const EXPRESS_DO_PAYMENT = 'D'; + /**#@-*/ - /** + /**#@+ * Response codes definition * - * @var unknown_type + * @var mixed */ const RESPONSE_CODE_APPROVED = 0; const RESPONSE_CODE_FRAUD = 126; + /**#@-*/ - /** + /**#@+ * Capture types (make authorization close or remain open) + * * @var string */ protected $_captureTypeComplete = 'Y'; protected $_captureTypeNotcomplete = 'N'; + /**#@-*/ /** * Global public interface map + * * @var array */ protected $_globalMap = array( @@ -145,8 +153,9 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'PARTNER', 'USER', 'VENDOR', 'PWD', ); - /** + /**#@+ * DoDirectPayment request/response map + * * @var array */ protected $_doDirectPaymentRequest = array( @@ -158,35 +167,43 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp protected $_doDirectPaymentResponse = array( 'PNREF', 'PPREF', 'CORRELATIONID', 'CVV2MATCH', 'AVSADDR', 'AVSZIP', 'PENDINGREASON' ); + /**#@-*/ - /** + /**#@+ * DoCapture request/response map + * * @var array */ protected $_doCaptureRequest = array('ORIGID', 'CAPTURECOMPLETE', 'AMT', 'TENDER', 'NOTE', 'INVNUM'); protected $_doCaptureResponse = array('PNREF', 'PPREF'); + /**#@-*/ /** * DoVoid request map + * * @var array */ protected $_doVoidRequest = array('ORIGID', 'NOTE', 'TENDER'); /** * Request map for each API call + * * @var array */ protected $_eachCallRequest = array('PARTNER', 'USER', 'VENDOR', 'PWD', 'BUTTONSOURCE'); - /** + /**#@+ * RefundTransaction request/response map + * * @var array */ protected $_refundTransactionRequest = array('ORIGID', 'TENDER'); protected $_refundTransactionResponse = array('PNREF', 'PPREF'); + /**#@-*/ - /** + /**#@+ * SetExpressCheckout request/response map + * * @var array */ protected $_setExpressCheckoutRequest = array( @@ -194,15 +211,18 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'PAGESTYLE', 'HDRIMG', 'HDRBORDERCOLOR', 'HDRBACKCOLOR', 'PAYFLOWCOLOR', 'LOCALECODE', ); protected $_setExpressCheckoutResponse = array('REPMSG', 'TOKEN'); + /**#@-*/ /** * GetExpressCheckoutDetails request/response map + * * @var array */ protected $_getExpressCheckoutDetailsRequest = array('TENDER', 'TOKEN'); - /** + /**#@+ * DoExpressCheckoutPayment request/response map + * * @var array */ protected $_doExpressCheckoutPaymentRequest = array( @@ -212,15 +232,19 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'PNREF', 'PPREF', 'REPMSG', 'AMT', 'PENDINGREASON', 'CVV2MATCH', 'AVSADDR', 'AVSZIP', 'CORRELATIONID' ); + /**#@-*/ - /** + /**#@+ * GetTransactionDetailsRequest + * * @var array */ protected $_getTransactionDetailsRequest = array('ORIGID', 'TENDER'); protected $_getTransactionDetailsResponse = array( - 'PAYERID', 'FIRSTNAME', 'LASTNAME', 'TRANSACTIONID', 'PARENTTRANSACTIONID', 'CURRENCYCODE', 'AMT', 'PAYMENTSTATUS' + 'PAYERID', 'FIRSTNAME', 'LASTNAME', 'TRANSACTIONID', + 'PARENTTRANSACTIONID', 'CURRENCYCODE', 'AMT', 'PAYMENTSTATUS' ); + /**#@-*/ /** * Map for shipping address import/export (extends billing address mapper) @@ -239,6 +263,7 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp /** * Map for billing address import/export + * * @var array */ protected $_billingAddressMap = array( @@ -260,8 +285,9 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'PHONENUM' => 'telephone', ); - /** + /**#@+ * Line items export mapping settings + * * @var array */ protected $_lineItemTotalExportMap = array(); @@ -270,9 +296,11 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp 'qty' => 'L_QTY%d', 'amount' => 'L_COST%d', ); + /**#@-*/ /** * Payment information response specifically to be collected after some requests + * * @var array */ protected $_paymentInformationResponse = array( @@ -288,7 +316,7 @@ class Mage_PaypalUk_Model_Api_Nvp extends Mage_Paypal_Model_Api_Nvp protected $_requiredResponseParams = array( self::DO_DIRECT_PAYMENT => array('RESULT', 'PNREF', 'PPREF') ); - + /** * API endpoint getter * @@ -413,9 +441,9 @@ protected function _mapPaypalMethodName($methodName) case Mage_Paypal_Model_Api_Nvp::GET_EXPRESS_CHECKOUT_DETAILS: case Mage_Paypal_Model_Api_Nvp::SET_EXPRESS_CHECKOUT: case Mage_Paypal_Model_Api_Nvp::DO_DIRECT_PAYMENT: - return ($this->_config->payment_action == Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH) ? - self::TRXTYPE_AUTH_ONLY: - self::TRXTYPE_SALE; + return ($this->_config->payment_action == Mage_Paypal_Model_Config::PAYMENT_ACTION_AUTH) + ? self::TRXTYPE_AUTH_ONLY + : self::TRXTYPE_SALE; case Mage_Paypal_Model_Api_Nvp::DO_CAPTURE: return self::TRXTYPE_DELAYED_CAPTURE; case Mage_Paypal_Model_Api_Nvp::DO_VOID: @@ -455,7 +483,9 @@ protected function _handleCallErrors($response) $message = $response['RESPMSG']; $e = new Exception(sprintf('PayPal gateway errors: %s.', $message)); Mage::logException($e); - Mage::throwException(Mage::helper('paypal')->__('PayPal gateway rejected the request. %s', $message)); + Mage::throwException( + Mage::helper('paypal')->__('PayPal gateway rejected the request. %s', $message) + ); } } @@ -506,7 +536,8 @@ protected function _importFraudFiltersResult(array $from, array $collectedWarnin } /** - * Return each call request fields (PayFlow edition doesn't support Unilateral payments) + * Return each call request fields + * (PayFlow edition doesn't support Unilateral payments) * * @param string $methodName Current method name * @return array @@ -517,7 +548,8 @@ protected function _prepareEachCallRequest($methodName) } /** - * Overwrite parent logic, simply return input data (PayFlow edition doesn't support Unilateral payments) + * Overwrite parent logic, simply return input data + * (PayFlow edition doesn't support Unilateral payments) * * @param array $requestFields Standard set of values * @return array diff --git a/app/code/core/Mage/PaypalUk/Model/Direct.php b/app/code/core/Mage/PaypalUk/Model/Direct.php index 5d8fabcf66..860fed827c 100644 --- a/app/code/core/Mage/PaypalUk/Model/Direct.php +++ b/app/code/core/Mage/PaypalUk/Model/Direct.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Model/Express.php b/app/code/core/Mage/PaypalUk/Model/Express.php index b24c6477c1..a0ef0f123b 100644 --- a/app/code/core/Mage/PaypalUk/Model/Express.php +++ b/app/code/core/Mage/PaypalUk/Model/Express.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Model/Express/Checkout.php b/app/code/core/Mage/PaypalUk/Model/Express/Checkout.php index 58fe6ea259..8a0ed78c7f 100644 --- a/app/code/core/Mage/PaypalUk/Model/Express/Checkout.php +++ b/app/code/core/Mage/PaypalUk/Model/Express/Checkout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/Model/Pro.php b/app/code/core/Mage/PaypalUk/Model/Pro.php index 0c976e0c5a..2620facee1 100644 --- a/app/code/core/Mage/PaypalUk/Model/Pro.php +++ b/app/code/core/Mage/PaypalUk/Model/Pro.php @@ -20,13 +20,14 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * PayPal Website Payments Pro (Payflow Edition) implementation for payment method instaces - * This model was created because right now PayPal Direct and PayPal Express payment (Payflow Edition) methods cannot have same abstract + * PayPal Website Payments Pro (Payflow Edition) implementation for payment method instances + * This model was created because right now PayPal Direct and PayPal Express payment + * (Payflow Edition) methods cannot have same abstract */ class Mage_PaypalUk_Model_Pro extends Mage_Paypal_Model_Pro { @@ -86,7 +87,7 @@ protected function _getParentTransactionId(Varien_Object $payment) { if ($payment->getParentTransactionId()) { return $payment->getTransaction($payment->getParentTransactionId()) - ->getAdditionalInformation(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID); + ->getAdditionalInformation(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID); } return $payment->getParentTransactionId(); } @@ -100,12 +101,32 @@ protected function _getParentTransactionId(Varien_Object $payment) protected function _importCaptureResultToPayment($api, $payment) { $payment->setTransactionId($api->getPaypalTransactionId()) - ->setIsTransactionClosed(false) - ->setTransactionAdditionalInfo(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID, $api->getTransactionId()); - $payment->setPreparedMessage(Mage::helper('paypaluk')->__('Payflow PNREF: #%s.', $api->getTransactionId())); + ->setIsTransactionClosed(false) + ->setTransactionAdditionalInfo( + Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID, + $api->getTransactionId() + ); + $payment->setPreparedMessage( + Mage::helper('paypaluk')->__('Payflow PNREF: #%s.', $api->getTransactionId()) + ); Mage::getModel('paypal/info')->importToPayment($api, $payment); } + /** + * Fetch transaction details info method does not exists in PaypalUK + * + * @param Mage_Payment_Model_Info $payment + * @param string $transactionId + * @throws Mage_Core_Exception + * @return void + */ + public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId) + { + Mage::throwException( + Mage::helper('paypaluk')->__('Fetch transaction details method does not exists in PaypalUK') + ); + } + /** * Import refund results to payment * @@ -116,11 +137,15 @@ protected function _importCaptureResultToPayment($api, $payment) protected function _importRefundResultToPayment($api, $payment, $canRefundMore) { $payment->setTransactionId($api->getPaypalTransactionId()) - ->setIsTransactionClosed(1) // refund initiated by merchant - ->setShouldCloseParentTransaction(!$canRefundMore) - ->setTransactionAdditionalInfo(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID, $api->getTransactionId()); - ; - $payment->setPreparedMessage(Mage::helper('paypaluk')->__('Payflow PNREF: #%s.', $api->getTransactionId())); + ->setIsTransactionClosed(1) // refund initiated by merchant + ->setShouldCloseParentTransaction(!$canRefundMore) + ->setTransactionAdditionalInfo( + Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID, + $api->getTransactionId() + ); + $payment->setPreparedMessage( + Mage::helper('paypaluk')->__('Payflow PNREF: #%s.', $api->getTransactionId()) + ); Mage::getModel('paypal/info')->importToPayment($api, $payment); } } diff --git a/app/code/core/Mage/PaypalUk/Model/Session.php b/app/code/core/Mage/PaypalUk/Model/Session.php index f1e6c495f7..327b702429 100644 --- a/app/code/core/Mage/PaypalUk/Model/Session.php +++ b/app/code/core/Mage/PaypalUk/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/controllers/ExpressController.php b/app/code/core/Mage/PaypalUk/controllers/ExpressController.php index d7ea7125ae..afcc7dbfd9 100644 --- a/app/code/core/Mage/PaypalUk/controllers/ExpressController.php +++ b/app/code/core/Mage/PaypalUk/controllers/ExpressController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/PaypalUk/etc/config.xml b/app/code/core/Mage/PaypalUk/etc/config.xml index 037f679b33..c591592494 100644 --- a/app/code/core/Mage/PaypalUk/etc/config.xml +++ b/app/code/core/Mage/PaypalUk/etc/config.xml @@ -21,28 +21,31 @@ * * @category Mage * @package Mage_PaypalUk - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 Mage_PaypalUk_Model - paypaluk_mysql4 + paypaluk_resource - - Mage_PaypalUk_Model_Mysql4 + + Mage_PaypalUk_Model_Resource + paypaluk_mysql4 - paypaluk_api_debug
      + + paypaluk_api_debug
      +
      -
      +
      @@ -57,7 +60,9 @@
      - Mage_PaypalUk_Block + + Mage_PaypalUk_Block +
      @@ -101,7 +106,6 @@ - diff --git a/app/code/core/Mage/PaypalUk/sql/paypaluk_setup/install-1.6.0.0.php b/app/code/core/Mage/PaypalUk/sql/paypaluk_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..0689c15811 --- /dev/null +++ b/app/code/core/Mage/PaypalUk/sql/paypaluk_setup/install-1.6.0.0.php @@ -0,0 +1,28 @@ + */ - -class Mage_Poll_Model_Mysql4_Poll extends Mage_Core_Model_Mysql4_Abstract +class Mage_Poll_Model_Mysql4_Poll extends Mage_Poll_Model_Resource_Poll { - protected function _construct() - { - $this->_init('poll/poll', 'poll_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'poll_title', - 'title' => Mage::helper('poll')->__('Poll with the same question') - )); - return $this; - } - - /** - * Get random identifier not closed poll - * - * @param Mage_Poll_Model_Poll $object - * @return int - */ - public function getRandomId($object) - { - $read = $this->_getReadAdapter(); - $select = $read->select(); - - if ($object->getExcludeFilter()) { - $select->where('main_table.poll_id NOT IN(?)', $object->getExcludeFilter()); - } - - $select->from(array('main_table'=>$this->getMainTable()), $this->getIdFieldName()) - ->where('closed = ?', 0) - ->order(new Zend_Db_Expr('RAND()')) - ->limit(1); - - if (($storeId = $object->getStoreFilter())) { - $select->join( - array('store' => $this->getTable('poll/poll_store')), - $read->quoteInto('main_table.poll_id=store.poll_id AND store.store_id = ?', $storeId), - array() - ); - } - - return $read->fetchOne($select); - } - - /** - * Check answer id existing for poll - * - * @param Mage_Poll_Model_Poll $poll - * @param int $answerId - * @return bool - */ - public function checkAnswerId($poll, $answerId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('poll_answer'), 'answer_id') - ->where('poll_id=?', $poll->getId()) - ->where('answer_id=?', $answerId); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Get voted poll ids by specified IP-address - * - * Will return non-empty only if appropriate option in config is enabled - * If poll id is not empty, it will look only for records with specified value - * - * @param string $ipAddress - * @param int $pollId - * @return array - */ - public function getVotedPollIdsByIp($ipAddress, $pollId = false) - { - // check if validation by ip is enabled - if (!Mage::getModel('poll/poll')->isValidationByIp()) { - return array(); - } - - // look for ids in database - $select = $this->_getReadAdapter()->select() - ->distinct() - ->from($this->getTable('poll_vote'), 'poll_id') - ->where('ip_address=?', ip2long($ipAddress)); - if (!empty($pollId)) { - $select->where('poll_id=?', $pollId); - } - $result = $this->_getReadAdapter()->fetchCol($select); - if (empty($result)) { - $result = array(); - } - return $result; - } - - 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 = ?", $object->getPollId()); - - $count = $read->fetchOne($select); - - $write = $this->_getWriteAdapter(); - $condition = $write->quoteInto("{$this->getIdFieldName()} = ?", $object->getPollId()); - $write->update($this->getMainTable(), array('votes_count' => $count), $condition); - return $object; - } - - - public function loadStoreIds(Mage_Poll_Model_Poll $object) - { - $pollId = $object->getId(); - $storeIds = array(); - if ($pollId) { - $storeIds = $this->lookupStoreIds($pollId); - } - $object->setStoreIds($storeIds); - } - - public function _afterSave(Mage_Core_Model_Abstract $object) - { - /** stores */ - $deleteWhere = $this->_getWriteAdapter()->quoteInto('poll_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('poll/poll_store'), $deleteWhere); - - foreach ($object->getStoreIds() as $storeId) { - $pollStoreData = array( - 'poll_id' => $object->getId(), - 'store_id' => $storeId - ); - $this->_getWriteAdapter()->insert($this->getTable('poll/poll_store'), $pollStoreData); - } - - /** answers */ - foreach ($object->getAnswers() as $answer) { - $answer->setPollId($object->getId()); - $answer->save(); - } - } - - /** - * Get store ids to which specified item is assigned - * - * @param int $id - * @return array - */ - public function lookupStoreIds($id) - { - return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select() - ->from($this->getTable('poll/poll_store'), 'store_id') - ->where("{$this->getIdFieldName()} = ?", $id) - ); - } } diff --git a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer.php b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer.php index 330ce8ea81..3dc060edf5 100644 --- a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer.php +++ b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Poll answers resource model * @@ -31,26 +32,6 @@ * @package Mage_Poll * @author Magento Core Team */ - -class Mage_Poll_Model_Mysql4_Poll_Answer extends Mage_Core_Model_Mysql4_Abstract +class Mage_Poll_Model_Mysql4_Poll_Answer extends Mage_Poll_Model_Resource_Poll_Answer { - protected function _construct() - { - $this->_init('poll/poll_answer', 'answer_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => array('answer_title', 'poll_id'), - 'title' => Mage::helper('poll')->__('Answer with the same title in this poll') - )); - return $this; - } - } diff --git a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer/Collection.php b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer/Collection.php index a7816eec1c..450152b5ac 100644 --- a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer/Collection.php +++ b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Answer/Collection.php @@ -20,37 +20,18 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @category Mage - * @package Mage_Poll + * Enter description here ... + * + * @category Mage + * @package Mage_Poll * @author Magento Core Team */ -class Mage_Poll_Model_Mysql4_Poll_Answer_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Poll_Model_Mysql4_Poll_Answer_Collection extends Mage_Poll_Model_Resource_Poll_Answer_Collection { - public function _construct() - { - $this->_init('poll/poll_answer'); - } - - public function addPollFilter($pollId) - { - $this->getSelect()->where("poll_id IN(?) ", $pollId); - return $this; - } - - public function countPercent($pollObject) - { - if( !$pollObject ) { - return; - } else { - foreach( $this->getItems() as $answer ) { - $answer->countPercent($pollObject); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Collection.php b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Collection.php index 64e22939c7..c138094253 100644 --- a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Collection.php +++ b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Collection.php @@ -20,119 +20,18 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Pool Mysql4 collection model resource * - * @category Mage - * @package Mage_Poll + * @category Mage + * @package Mage_Poll * @author Magento Core Team */ -class Mage_Poll_Model_Mysql4_Poll_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Poll_Model_Mysql4_Poll_Collection extends Mage_Poll_Model_Resource_Poll_Collection { - public function _construct() - { - $this->_init('poll/poll'); - } - - /** - * Redefine default filters - * - * @param string $field - * @param mixed $condition - * @return Varien_Data_Collection_Db - */ - public function addFieldToFilter($field, $condition=null) - { - if ($field == 'stores') { - return $this->addStoresFilter($condition); - } - else { - return parent::addFieldToFilter($field, $condition); - } - } - - /** - * Deprecated - * - * @param int|array $storeId - * @return Mage_Poll_Model_Mysql4_Poll_Collection - */ - public function addStoresFilter($store) - { - return $this->addStoreFilter($store); - } - - /** - * Add Stores Filter - * - * @param int|array $storeId - * @return Mage_Poll_Model_Mysql4_Poll_Collection - */ - public function addStoreFilter($storeId, $withAdmin = true) - { - $this->getSelect()->join( - array('store_table' => $this->getTable('poll/poll_store')), - 'main_table.poll_id = store_table.poll_id', - array() - ) - ->where('store_table.store_id in (?)', ($withAdmin ? array(0, $storeId) : $storeId)) - ->group('main_table.poll_id'); - - return $this; - } - - /** - * Add stores data - * - * @return Mage_Poll_Model_Mysql4_Poll_Collection - */ - public function addStoreData() - { - $pollIds = $this->getColumnValues('poll_id'); - $storesToPoll = array(); - - if (count($pollIds) > 0) { - $select = $this->getConnection()->select() - ->from($this->getTable('poll/poll_store')) - ->where('poll_id IN(?)', $pollIds); - $result = $this->getConnection()->fetchAll($select); - - foreach ($result as $row) { - if (!isset($storesToPoll[$row['poll_id']])) { - $storesToPoll[$row['poll_id']] = array(); - } - $storesToPoll[$row['poll_id']][] = $row['store_id']; - } - } - - foreach ($this as $item) { - if(isset($storesToPoll[$item->getId()])) { - $item->setStores($storesToPoll[$item->getId()]); - } else { - $item->setStores(array()); - } - } - - return $this; - } - - public function addSelectStores() - { - $pollId = $this->getId(); - $select = $this->getConnection()->select() - ->from($this->getTable('poll/poll_store')) - ->where('poll_id = ?', $pollId); - $result = $this->getConnection()->fetchAll($select); - $stores = array(); - foreach ($result as $row) { - $stores[] = $row['stor_id']; - } - $this->setSelectStores($stores); - - return $this; - } } diff --git a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Vote.php b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Vote.php index 1ba3c1fa51..cf146f2296 100644 --- a/app/code/core/Mage/Poll/Model/Mysql4/Poll/Vote.php +++ b/app/code/core/Mage/Poll/Model/Mysql4/Poll/Vote.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Poll vote resource model * @@ -31,36 +32,6 @@ * @package Mage_Poll * @author Magento Core Team */ - -class Mage_Poll_Model_Mysql4_Poll_Vote extends Mage_Core_Model_Mysql4_Abstract +class Mage_Poll_Model_Mysql4_Poll_Vote extends Mage_Poll_Model_Resource_Poll_Vote { - protected function _construct() - { - $this->_init('poll/poll_vote', 'vote_id'); - } - - /** - * Perform actions after object save - * - * @param Varien_Object $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - /** - * Increase answer votes - */ - $answerTable = $this->getTable('poll/poll_answer'); - $pollAnswerData = array('votes_count' => new Zend_Db_Expr('votes_count+1')); - $condition = $this->_getWriteAdapter()->quoteInto("{$answerTable}.answer_id=?", $object->getPollAnswerId()); - $this->_getWriteAdapter()->update($answerTable, $pollAnswerData, $condition); - - /** - * Increase poll votes - */ - $pollTable = $this->getTable('poll/poll'); - $pollData = array('votes_count' => new Zend_Db_Expr('votes_count+1')); - $condition = $this->_getWriteAdapter()->quoteInto("{$pollTable}.poll_id=?", $object->getPollId()); - $this->_getWriteAdapter()->update($pollTable, $pollData, $condition); - return $this; - } } diff --git a/app/code/core/Mage/Poll/Model/Poll.php b/app/code/core/Mage/Poll/Model/Poll.php index c1f1c1ca0a..a940af8514 100644 --- a/app/code/core/Mage/Poll/Model/Poll.php +++ b/app/code/core/Mage/Poll/Model/Poll.php @@ -20,13 +20,33 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Poll model * + * @method Mage_Poll_Model_Resource_Poll _getResource() + * @method Mage_Poll_Model_Resource_Poll getResource() + * @method string getPollTitle() + * @method Mage_Poll_Model_Poll setPollTitle(string $value) + * @method Mage_Poll_Model_Poll setVotesCount(int $value) + * @method int getStoreId() + * @method Mage_Poll_Model_Poll setStoreId(int $value) + * @method string getDatePosted() + * @method Mage_Poll_Model_Poll setDatePosted(string $value) + * @method string getDateClosed() + * @method Mage_Poll_Model_Poll setDateClosed(string $value) + * @method int getActive() + * @method Mage_Poll_Model_Poll setActive(int $value) + * @method int getClosed() + * @method Mage_Poll_Model_Poll setClosed(int $value) + * @method int getAnswersDisplay() + * @method Mage_Poll_Model_Poll setAnswersDisplay(int $value) + * + * @category Mage + * @package Mage_Poll * @author Magento Core Team */ diff --git a/app/code/core/Mage/Poll/Model/Poll/Answer.php b/app/code/core/Mage/Poll/Model/Poll/Answer.php index cc17a65db3..31b6912ba2 100644 --- a/app/code/core/Mage/Poll/Model/Poll/Answer.php +++ b/app/code/core/Mage/Poll/Model/Poll/Answer.php @@ -20,15 +20,26 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Poll answers model * - * @category Mage - * @package Mage_Poll + * @method Mage_Poll_Model_Resource_Poll_Answer _getResource() + * @method Mage_Poll_Model_Resource_Poll_Answer getResource() + * @method int getPollId() + * @method Mage_Poll_Model_Poll_Answer setPollId(int $value) + * @method string getAnswerTitle() + * @method Mage_Poll_Model_Poll_Answer setAnswerTitle(string $value) + * @method int getVotesCount() + * @method Mage_Poll_Model_Poll_Answer setVotesCount(int $value) + * @method int getAnswerOrder() + * @method Mage_Poll_Model_Poll_Answer setAnswerOrder(int $value) + * + * @category Mage + * @package Mage_Poll * @author Magento Core Team */ diff --git a/app/code/core/Mage/Poll/Model/Poll/Vote.php b/app/code/core/Mage/Poll/Model/Poll/Vote.php index 035dcbba24..55216e3424 100644 --- a/app/code/core/Mage/Poll/Model/Poll/Vote.php +++ b/app/code/core/Mage/Poll/Model/Poll/Vote.php @@ -20,13 +20,26 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Pool vote model * + * @method Mage_Poll_Model_Resource_Poll_Vote _getResource() + * @method Mage_Poll_Model_Resource_Poll_Vote getResource() + * @method int getPollId() + * @method Mage_Poll_Model_Poll_Vote setPollId(int $value) + * @method int getPollAnswerId() + * @method Mage_Poll_Model_Poll_Vote setPollAnswerId(int $value) + * @method int getIpAddress() + * @method Mage_Poll_Model_Poll_Vote setIpAddress(int $value) + * @method int getCustomerId() + * @method Mage_Poll_Model_Poll_Vote setCustomerId(int $value) + * @method string getVoteTime() + * @method Mage_Poll_Model_Poll_Vote setVoteTime(string $value) + * * @category Mage * @package Mage_Poll * @author Magento Core Team diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll.php b/app/code/core/Mage/Poll/Model/Resource/Poll.php new file mode 100755 index 0000000000..8eb0e26af7 --- /dev/null +++ b/app/code/core/Mage/Poll/Model/Resource/Poll.php @@ -0,0 +1,220 @@ + + */ +class Mage_Poll_Model_Resource_Poll extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('poll/poll', 'poll_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Poll_Model_Resource_Poll + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => 'poll_title', + 'title' => Mage::helper('poll')->__('Poll with the same question') + )); + return $this; + } + + /** + * Get random identifier not closed poll + * + * @param Mage_Poll_Model_Poll $object + * @return int + */ + public function getRandomId($object) + { + $read = $this->_getReadAdapter(); + $select = $read->select(); + + if ($object->getExcludeFilter()) { + $select->where('main_table.poll_id NOT IN(?)', $object->getExcludeFilter()); + } + + $select->from(array('main_table'=>$this->getMainTable()), $this->getIdFieldName()) + ->where('closed = :is_closed') + ->orderRand() + ->limit(1); + $bind = array(':is_closed' => 0); + if (($storeId = $object->getStoreFilter())) { + $select->join( + array('store' => $this->getTable('poll/poll_store')), + 'main_table.poll_id=store.poll_id AND store.store_id = :store_id', + array() + ); + $bind[':store_id'] = $storeId; + } + + return $read->fetchOne($select, $bind); + } + + /** + * Check answer id existing for poll + * + * @param Mage_Poll_Model_Poll $poll + * @param int $answerId + * @return bool + */ + public function checkAnswerId($poll, $answerId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('poll_answer'), 'answer_id') + ->where('poll_id = :poll_id') + ->where('answer_id = :answer_id'); + $bind = array(':poll_id' => $poll->getId(), ':answer_id' => $answerId); + return $this->_getReadAdapter()->fetchOne($select, $bind); + } + + /** + * Get voted poll ids by specified IP-address + * Will return non-empty only if appropriate option in config is enabled + * If poll id is not empty, it will look only for records with specified value + * + * @param string $ipAddress + * @param int $pollId + * @return array + */ + public function getVotedPollIdsByIp($ipAddress, $pollId = false) + { + // check if validation by ip is enabled + if (!Mage::getModel('poll/poll')->isValidationByIp()) { + return array(); + } + + // look for ids in database + $select = $this->_getReadAdapter()->select() + ->distinct() + ->from($this->getTable('poll_vote'), 'poll_id') + ->where('ip_address = :ip_address'); + $bind = array(':ip_address' => ip2long($ipAddress)); + if (!empty($pollId)) { + $select->where('poll_id = :poll_id'); + $bind[':poll_id'] = $pollId; + } + $result = $this->_getReadAdapter()->fetchCol($select, $bind); + if (empty($result)) { + $result = array(); + } + return $result; + } + + /** + * Resett votes count + * + * @param Mage_Poll_Model_Poll $object + * @return Mage_Poll_Model_Poll + */ + 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); + return $object; + } + + /** + * Load store Ids array + * + * @param Mage_Poll_Model_Poll $object + */ + public function loadStoreIds(Mage_Poll_Model_Poll $object) + { + $pollId = $object->getId(); + $storeIds = array(); + if ($pollId) { + $storeIds = $this->lookupStoreIds($pollId); + } + $object->setStoreIds($storeIds); + } + + /** + * Delete current poll from the table poll_store and then + * insert to update "poll to store" relations + * + * @param Mage_Core_Model_Abstract $object + */ + public function _afterSave(Mage_Core_Model_Abstract $object) + { + /** stores */ + $deleteWhere = $this->_getWriteAdapter()->quoteInto('poll_id = ?', $object->getId()); + $this->_getWriteAdapter()->delete($this->getTable('poll/poll_store'), $deleteWhere); + + foreach ($object->getStoreIds() as $storeId) { + $pollStoreData = array( + 'poll_id' => $object->getId(), + 'store_id' => $storeId + ); + $this->_getWriteAdapter()->insert($this->getTable('poll/poll_store'), $pollStoreData); + } + + /** answers */ + foreach ($object->getAnswers() as $answer) { + $answer->setPollId($object->getId()); + $answer->save(); + } + } + + /** + * Get store ids to which specified item is assigned + * + * @param int $id + * @return array + */ + public function lookupStoreIds($id) + { + return $this->_getReadAdapter()->fetchCol( + $this->_getReadAdapter()->select() + ->from($this->getTable('poll/poll_store'), 'store_id') + ->where("{$this->getIdFieldName()} = :id_field"), + array(':id_field' => $id) + ); + } +} diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll/Answer.php b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer.php new file mode 100755 index 0000000000..448405ef93 --- /dev/null +++ b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer.php @@ -0,0 +1,59 @@ + + */ +class Mage_Poll_Model_Resource_Poll_Answer extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize Poll_Answer resource + * + */ + protected function _construct() + { + $this->_init('poll/poll_answer', 'answer_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Poll_Model_Resource_Poll_Answer + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => array('answer_title', 'poll_id'), + 'title' => Mage::helper('poll')->__('Answer with the same title in this poll') + )); + return $this; + } +} diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php new file mode 100755 index 0000000000..06cc774bef --- /dev/null +++ b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Poll_Model_Resource_Poll_Answer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize collection + * + */ + public function _construct() + { + $this->_init('poll/poll_answer'); + } + + /** + * Add poll filter + * + * @param int $pollId + * @return Mage_Poll_Model_Resource_Poll_Answer_Collection + */ + public function addPollFilter($pollId) + { + $this->getSelect()->where("poll_id IN(?) ", $pollId); + return $this; + } + + /** + * Count percent + * + * @param Mage_Poll_Model_Poll $pollObject + * @return Mage_Poll_Model_Resource_Poll_Answer_Collection + */ + public function countPercent($pollObject) + { + if (!$pollObject) { + return; + } else { + foreach ($this->getItems() as $answer) { + $answer->countPercent($pollObject); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll/Collection.php b/app/code/core/Mage/Poll/Model/Resource/Poll/Collection.php new file mode 100755 index 0000000000..9ff9d16a5f --- /dev/null +++ b/app/code/core/Mage/Poll/Model/Resource/Poll/Collection.php @@ -0,0 +1,150 @@ + + */ +class Mage_Poll_Model_Resource_Poll_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize collection + * + */ + public function _construct() + { + $this->_init('poll/poll'); + } + + /** + * Redefine default filters + * + * @param string $field + * @param mixed $condition + * @return Varien_Data_Collection_Db + */ + public function addFieldToFilter($field, $condition = null) + { + if ($field == 'stores') { + return $this->addStoresFilter($condition); + } else { + return parent::addFieldToFilter($field, $condition); + } + } + + /** + * Add store filter + * + * @deprecated + * @param mixed $store + * @return Mage_Poll_Model_Resource_Poll_Collection + */ + public function addStoresFilter($store) + { + return $this->addStoreFilter($store); + } + + /** + * Add Stores Filter + * + * @param mixed $storeId + * @param bool $withAdmin + * @return Mage_Poll_Model_Resource_Poll_Collection + */ + public function addStoreFilter($storeId, $withAdmin = true) + { + $this->getSelect()->join( + array('store_table' => $this->getTable('poll/poll_store')), + 'main_table.poll_id = store_table.poll_id', + array() + ) + ->where('store_table.store_id in (?)', ($withAdmin ? array(0, $storeId) : $storeId)) + ->group('main_table.poll_id'); + + /* + * Allow analytic functions usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Add stores data + * + * @return Mage_Poll_Model_Resource_Poll_Collection + */ + public function addStoreData() + { + $pollIds = $this->getColumnValues('poll_id'); + $storesToPoll = array(); + + if (count($pollIds) > 0) { + $select = $this->getConnection()->select() + ->from($this->getTable('poll/poll_store')) + ->where('poll_id IN(?)', $pollIds); + $result = $this->getConnection()->fetchAll($select); + + foreach ($result as $row) { + if (!isset($storesToPoll[$row['poll_id']])) { + $storesToPoll[$row['poll_id']] = array(); + } + $storesToPoll[$row['poll_id']][] = $row['store_id']; + } + } + + foreach ($this as $item) { + if (isset($storesToPoll[$item->getId()])) { + $item->setStores($storesToPoll[$item->getId()]); + } else { + $item->setStores(array()); + } + } + + return $this; + } + + /** + * Set stores of the current poll + * + * @return Mage_Poll_Model_Resource_Poll_Collection + */ + public function addSelectStores() + { + $pollId = $this->getId(); + $select = $this->getConnection()->select() + ->from($this->getTable('poll/poll_store'), array('stor_id')) + ->where('poll_id = :poll_id'); + $stores = $this->getConnection()->fetchCol($select, array(':poll_id' => $pollId)); + $this->setSelectStores($stores); + + return $this; + } +} diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll/Vote.php b/app/code/core/Mage/Poll/Model/Resource/Poll/Vote.php new file mode 100755 index 0000000000..a1e3e74e1b --- /dev/null +++ b/app/code/core/Mage/Poll/Model/Resource/Poll/Vote.php @@ -0,0 +1,71 @@ + + */ +class Mage_Poll_Model_Resource_Poll_Vote extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize vote resource + * + */ + protected function _construct() + { + $this->_init('poll/poll_vote', 'vote_id'); + } + + /** + * Perform actions after object save + * + * @param Varien_Object $object + * @return Mage_Poll_Model_Resource_Poll_Vote + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + /** + * Increase answer votes + */ + $answerTable = $this->getTable('poll/poll_answer'); + $pollAnswerData = array('votes_count' => new Zend_Db_Expr('votes_count+1')); + $condition = array("{$answerTable}.answer_id=?" => $object->getPollAnswerId()); + $this->_getWriteAdapter()->update($answerTable, $pollAnswerData, $condition); + + /** + * Increase poll votes + */ + $pollTable = $this->getTable('poll/poll'); + $pollData = array('votes_count' => new Zend_Db_Expr('votes_count+1')); + $condition = array("{$pollTable}.poll_id=?" => $object->getPollId()); + $this->_getWriteAdapter()->update($pollTable, $pollData, $condition); + return $this; + } +} diff --git a/app/code/core/Mage/Poll/controllers/VoteController.php b/app/code/core/Mage/Poll/controllers/VoteController.php index b33b59f017..8c0ec30814 100644 --- a/app/code/core/Mage/Poll/controllers/VoteController.php +++ b/app/code/core/Mage/Poll/controllers/VoteController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Poll/data/poll_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Poll/data/poll_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..5a64857969 --- /dev/null +++ b/app/code/core/Mage/Poll/data/poll_setup/data-install-1.6.0.0.php @@ -0,0 +1,54 @@ +setDatePosted(now()) + ->setPollTitle('What is your favorite color') + ->setStoreIds(array(1)); + +$answers = array( + array('Green', 4), + array('Red', 1), + array('Black', 0), + array('Magenta', 2) + ); + +foreach( $answers as $key => $answer ) { + $answerModel = Mage::getModel('poll/poll_answer'); + $answerModel->setAnswerTitle($answer[0]) + ->setVotesCount($answer[1]); + + $pollModel->addAnswer($answerModel); +} + +$pollModel->save(); + diff --git a/app/code/core/Mage/Poll/etc/adminhtml.xml b/app/code/core/Mage/Poll/etc/adminhtml.xml index 84ccb7366e..685fddad0b 100644 --- a/app/code/core/Mage/Poll/etc/adminhtml.xml +++ b/app/code/core/Mage/Poll/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Poll/etc/config.xml b/app/code/core/Mage/Poll/etc/config.xml index c0169d2f0e..dad7ec0236 100644 --- a/app/code/core/Mage/Poll/etc/config.xml +++ b/app/code/core/Mage/Poll/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.2 + 1.6.0.0 @@ -58,7 +58,6 @@ - @@ -70,15 +69,15 @@ - Mage_Poll_Model - poll_mysql4 + poll_resource - - Mage_Poll_Model_Mysql4 + + Mage_Poll_Model_Resource + poll_mysql4 poll
      @@ -93,7 +92,7 @@ poll_store
      -
      +
      diff --git a/app/code/core/Mage/Poll/etc/system.xml b/app/code/core/Mage/Poll/etc/system.xml index 618bcfa9d3..a776ee1bba 100644 --- a/app/code/core/Mage/Poll/etc/system.xml +++ b/app/code/core/Mage/Poll/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Poll/sql/poll_setup/install-1.6.0.0.php b/app/code/core/Mage/Poll/sql/poll_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..90aa24c861 --- /dev/null +++ b/app/code/core/Mage/Poll/sql/poll_setup/install-1.6.0.0.php @@ -0,0 +1,185 @@ +startSetup(); + +/** + * Create table 'poll' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('poll/poll')) + ->addColumn('poll_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Poll Id') + ->addColumn('poll_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Poll title') + ->addColumn('votes_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Votes Count') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store id') + ->addColumn('date_posted', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Date posted') + ->addColumn('date_closed', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Date closed') + ->addColumn('active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Is active') + ->addColumn('closed', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is closed') + ->addColumn('answers_display', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => true, + ), 'Answers display') + ->addIndex($installer->getIdxName('poll/poll', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('poll/poll', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Poll'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'poll_answer' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('poll/poll_answer')) + ->addColumn('answer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Answer Id') + ->addColumn('poll_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Poll Id') + ->addColumn('answer_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Answer title') + ->addColumn('votes_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Votes Count') + ->addColumn('answer_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Answers display') + ->addIndex($installer->getIdxName('poll/poll_answer', array('poll_id')), + array('poll_id')) + ->addForeignKey($installer->getFkName('poll/poll_answer', 'poll_id', 'poll/poll', 'poll_id'), + 'poll_id', $installer->getTable('poll/poll'), 'poll_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Poll Answers'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'poll_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('poll/poll_store')) + ->addColumn('poll_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'primary' => true, + 'nullable' => false, + 'default' => '0', + ), 'Poll Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'primary' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store id') + ->addIndex($installer->getIdxName('poll/poll_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('poll/poll_store', 'poll_id', 'poll/poll', 'poll_id'), + 'poll_id', $installer->getTable('poll/poll'), 'poll_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('poll/poll_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Poll Store'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'poll_vote' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('poll/poll_vote')) + ->addColumn('vote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Vote Id') + ->addColumn('poll_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Poll Id') + ->addColumn('poll_answer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Poll answer id') + ->addColumn('ip_address', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'nullable' => true, + ), 'Poll answer id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => true, + ), 'Customer id') + ->addColumn('vote_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Date closed') + ->addIndex($installer->getIdxName('poll/poll_vote', array('poll_answer_id')), + array('poll_answer_id')) + ->addForeignKey($installer->getFkName('poll/poll_vote', 'poll_answer_id', 'poll/poll_answer', 'answer_id'), + 'poll_answer_id', $installer->getTable('poll/poll_answer'), 'answer_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Poll Vote'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-install-0.7.0.php index 4e9f13ba2c..f29ef39222 100644 --- a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.6.0-0.6.1.php b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.6.0-0.6.1.php index e70e038f42..6d909b7cda 100644 --- a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.6.0-0.6.1.php +++ b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.6.0-0.6.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.7.1-0.7.2.php index 4d26e07e24..02d5848ff5 100644 --- a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Poll - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..8ca5d2fb2d --- /dev/null +++ b/app/code/core/Mage/Poll/sql/poll_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,321 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('poll/poll'), + 'FK_POLL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('poll/poll_answer'), + 'FK_POLL_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('poll/poll_store'), + 'FK_POLL_STORE_POLL' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('poll/poll_store'), + 'FK_POLL_STORE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('poll/poll_vote'), + 'FK_POLL_ANSWER' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('poll/poll'), + 'FK_POLL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('poll/poll_answer'), + 'FK_POLL_PARENT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('poll/poll_store'), + 'FK_POLL_STORE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('poll/poll_vote'), + 'FK_POLL_ANSWER' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('poll/poll') => array( + 'columns' => array( + 'poll_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Poll Id' + ), + 'poll_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Poll title' + ), + 'votes_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Votes Count' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store id' + ), + 'date_posted' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Date posted' + ), + 'date_closed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'comment' => 'Date closed' + ), + 'active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is active' + ), + 'closed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is closed' + ), + 'answers_display' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'comment' => 'Answers display' + ) + ), + 'comment' => 'Poll' + ), + $installer->getTable('poll/poll_answer') => array( + 'columns' => array( + 'answer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Answer Id' + ), + 'poll_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Poll Id' + ), + 'answer_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Answer title' + ), + 'votes_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Votes Count' + ), + 'answer_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Answers display' + ) + ), + 'comment' => 'Poll Answers' + ), + $installer->getTable('poll/poll_vote') => array( + 'columns' => array( + 'vote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Vote Id' + ), + 'poll_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Poll Id' + ), + 'poll_answer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Poll answer id' + ), + 'ip_address' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'comment' => 'Poll answer id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Customer id' + ), + 'vote_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'comment' => 'Date closed' + ) + ), + 'comment' => 'Poll Vote' + ), + $installer->getTable('poll/poll_store') => array( + 'columns' => array( + 'poll_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Poll Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store id' + ) + ), + 'comment' => 'Poll Store' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('poll/poll'), + $installer->getIdxName('poll/poll', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('poll/poll_answer'), + $installer->getIdxName('poll/poll_answer', array('poll_id')), + array('poll_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('poll/poll_store'), + $installer->getIdxName('poll/poll_store', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('poll/poll_vote'), + $installer->getIdxName('poll/poll_vote', array('poll_answer_id')), + array('poll_answer_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('poll/poll', 'store_id', 'core/store', 'store_id'), + $installer->getTable('poll/poll'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('poll/poll_answer', 'poll_id', 'poll/poll', 'poll_id'), + $installer->getTable('poll/poll_answer'), + 'poll_id', + $installer->getTable('poll/poll'), + 'poll_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('poll/poll_store', 'poll_id', 'poll/poll', 'poll_id'), + $installer->getTable('poll/poll_store'), + 'poll_id', + $installer->getTable('poll/poll'), + 'poll_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('poll/poll_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('poll/poll_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('poll/poll_vote', 'poll_answer_id', 'poll/poll_answer', 'answer_id'), + $installer->getTable('poll/poll_vote'), + 'poll_answer_id', + $installer->getTable('poll/poll_answer'), + 'answer_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/ProductAlert/Block/Email/Abstract.php b/app/code/core/Mage/ProductAlert/Block/Email/Abstract.php index c6b9a17e85..b6ff4b950e 100644 --- a/app/code/core/Mage/ProductAlert/Block/Email/Abstract.php +++ b/app/code/core/Mage/ProductAlert/Block/Email/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Block/Email/Price.php b/app/code/core/Mage/ProductAlert/Block/Email/Price.php index 034b1b4ead..1429568807 100644 --- a/app/code/core/Mage/ProductAlert/Block/Email/Price.php +++ b/app/code/core/Mage/ProductAlert/Block/Email/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Block/Email/Stock.php b/app/code/core/Mage/ProductAlert/Block/Email/Stock.php index 432914e98c..ad68984f4b 100644 --- a/app/code/core/Mage/ProductAlert/Block/Email/Stock.php +++ b/app/code/core/Mage/ProductAlert/Block/Email/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Block/Price.php b/app/code/core/Mage/ProductAlert/Block/Price.php index c3f123ac2e..5d3bc9cef9 100644 --- a/app/code/core/Mage/ProductAlert/Block/Price.php +++ b/app/code/core/Mage/ProductAlert/Block/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Block/Product/View.php b/app/code/core/Mage/ProductAlert/Block/Product/View.php index 9b867e1e81..bb38c655c3 100644 --- a/app/code/core/Mage/ProductAlert/Block/Product/View.php +++ b/app/code/core/Mage/ProductAlert/Block/Product/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Block/Stock.php b/app/code/core/Mage/ProductAlert/Block/Stock.php index 4bc696ace1..645aaf7027 100644 --- a/app/code/core/Mage/ProductAlert/Block/Stock.php +++ b/app/code/core/Mage/ProductAlert/Block/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Helper/Data.php b/app/code/core/Mage/ProductAlert/Helper/Data.php index b39bf1a52c..87d5fe7eec 100644 --- a/app/code/core/Mage/ProductAlert/Helper/Data.php +++ b/app/code/core/Mage/ProductAlert/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Model/Email.php b/app/code/core/Mage/ProductAlert/Model/Email.php index 1074922d7e..e0cac8991b 100644 --- a/app/code/core/Mage/ProductAlert/Model/Email.php +++ b/app/code/core/Mage/ProductAlert/Model/Email.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price.php index fb3c1ab042..dd432f1a31 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,95 +28,10 @@ /** * Product alert for changed price resource model * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Price extends Mage_Core_Model_Mysql4_Abstract +class Mage_ProductAlert_Model_Mysql4_Price extends Mage_ProductAlert_Model_Resource_Price { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('productalert/price', 'alert_price_id'); - } - - /** - * Before save process, check exists the same alert - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_ProductAlert_Model_Mysql4_Price - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) { - if ($row = $this->_getAlertRow($object)) { - $price = $object->getPrice(); - $object->addData($row); - if ($price) { - $object->setPrice($price); - } - $object->setStatus(0); - } - } - if (is_null($object->getAddDate())) { - $object->setAddDate(Mage::getModel('core/date')->gmtDate()); - } - return parent::_beforeSave($object); - } - - /** - * Retrieve alert row by object parameters - * - * @param Mage_Core_Model_Abstract $object - * @return array|bool - */ - protected function _getAlertRow(Mage_Core_Model_Abstract $object) - { - if ($object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) { - $sql = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('customer_id=?', $object->getCustomerId()) - ->where('product_id=?', $object->getProductId()) - ->where('website_id=?', $object->getWebsiteId()); - return $this->_getWriteAdapter()->fetchRow($sql); - } - return false; - } - - /** - * Load object data by parameters - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_ProductAlert_Model_Mysql4_Price - */ - public function loadByParam(Mage_Core_Model_Abstract $object) - { - $row = $this->_getAlertRow($object); - if ($row) { - $object->setData($row); - } - return $this; - } - - /** - * Delete all customer alerts on website - * - * @param Mage_Core_Model_Abstract $object - * @param int $customerId - * @param int $websiteId - * @return Mage_ProductAlert_Model_Mysql4_Price - */ - public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId = null) - { - $where = array(); - $where[] = $this->_getWriteAdapter()->quoteInto('customer_id=?', $customerId); - if ($websiteId) { - $where[] = $this->_getWriteAdapter()->quoteInto('website_id=?', $websiteId); - } - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Collection.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Collection.php index 06f69fadbb..730a80fcd0 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Collection.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,53 +28,10 @@ /** * Product alert for changed price collection * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Price_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_ProductAlert_Model_Mysql4_Price_Collection extends Mage_ProductAlert_Model_Resource_Price_Collection { - protected function _construct() - { - $this->_init('productalert/price'); - } - - public function addCustomerFilter($customer) - { - if (is_array($customer)) { - $condition = $this->getConnection()->quoteInto('customer_id IN(?)', $customer); - } - elseif ($customer instanceof Mage_Customer_Model_Customer) { - $condition = $this->getConnection()->quoteInto('customer_id=?', $customer->getId()); - } - else { - $condition = $this->getConnection()->quoteInto('customer_id=?', $customer); - } - $this->addFilter('customer_id', $condition, 'string'); - return $this; - } - - public function addWebsiteFilter($website) - { - if (is_null($website) || $website == 0) { - return $this; - } - if (is_array($website)) { - $condition = $this->getConnection()->quoteInto('website_id IN(?)', $website); - } - elseif ($website instanceof Mage_Core_Model_Website) { - $condition = $this->getConnection()->quoteInto('website_id=?', $website->getId()); - } - else { - $condition = $this->getConnection()->quoteInto('website_id=?', $website); - } - $this->addFilter('website_id', $condition, 'string'); - return $this; - } - - public function setCustomerOrder($sort = 'ASC') - { - $this->getSelect()->order('customer_id ' . $sort); - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Customer/Collection.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Customer/Collection.php index 079fe76798..18f21ed58b 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Customer/Collection.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Price/Customer/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,27 +28,11 @@ /** * ProductAlert Price Customer collection * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Price_Customer_Collection extends Mage_Customer_Model_Entity_Customer_Collection +class Mage_ProductAlert_Model_Mysql4_Price_Customer_Collection + extends Mage_ProductAlert_Model_Resource_Price_Customer_Collection { - public function join($productId, $websiteId) - { - $this->getSelect()->join( - array('alert' => $this->getTable('productalert/price')), - 'e.entity_id=alert.customer_id', - array('alert_price_id', 'website_id', 'price', 'add_date', 'last_send_date', 'send_count', 'status') - ); - - $this->getSelect()->where('alert.product_id=?', $productId); - if ($websiteId) { - $this->getSelect()->where('alert.website_id=?', $websiteId); - } - $this->_setIdFieldName('alert_price_id'); - $this->addAttributeToSelect('*'); - - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock.php index e4be42e27e..6fc93f4e45 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,62 +28,10 @@ /** * Product alert for back in stock resource model * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Stock extends Mage_Core_Model_Mysql4_Abstract +class Mage_ProductAlert_Model_Mysql4_Stock extends Mage_ProductAlert_Model_Resource_Stock { - protected function _construct() - { - $this->_init('productalert/stock', 'alert_stock_id'); - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) { - if ($row = $this->_getAlertRow($object)) { - $object->addData($row); - $object->setStatus(0); - } - } - if (is_null($object->getAddDate())) { - $object->setAddDate(Mage::getModel('core/date')->gmtDate()); - $object->setStatus(0); - } - return parent::_beforeSave($object); - } - - protected function _getAlertRow(Mage_Core_Model_Abstract $object) - { - if ($object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) { - $sql = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('customer_id=?', $object->getCustomerId()) - ->where('product_id=?', $object->getProductId()) - ->where('website_id=?', $object->getWebsiteId()); - return $this->_getWriteAdapter()->fetchRow($sql); - } - return false; - } - - public function loadByParam(Mage_Core_Model_Abstract $object) - { - $row = $this->_getAlertRow($object); - if ($row) { - $object->setData($row); - } - return $this; - } - - public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId) - { - $where = array(); - $where[] = $this->_getWriteAdapter()->quoteInto('customer_id=?', $customerId); - if ($websiteId) { - $where[] = $this->_getWriteAdapter()->quoteInto('website_id=?', $websiteId); - } - $this->_getWriteAdapter()->delete($this->getMainTable(), $where); - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Collection.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Collection.php index 22eeeaf304..efb6184039 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Collection.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,60 +28,10 @@ /** * Product alert for back in stock collection * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Stock_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_ProductAlert_Model_Mysql4_Stock_Collection extends Mage_ProductAlert_Model_Resource_Stock_Collection { - protected function _construct() - { - $this->_init('productalert/stock'); - } - - public function addCustomerFilter($customer) - { - if (is_array($customer)) { - $condition = $this->getConnection()->quoteInto('customer_id IN(?)', $customer); - } - elseif ($customer instanceof Mage_Customer_Model_Customer) { - $condition = $this->getConnection()->quoteInto('customer_id=?', $customer->getId()); - } - else { - $condition = $this->getConnection()->quoteInto('customer_id=?', $customer); - } - $this->addFilter('customer_id', $condition, 'string'); - return $this; - } - - public function addWebsiteFilter($website) - { - if (is_null($website) || $website == 0) { - return $this; - } - if (is_array($website)) { - $condition = $this->getConnection()->quoteInto('website_id IN(?)', $website); - } - elseif ($website instanceof Mage_Core_Model_Website) { - $condition = $this->getConnection()->quoteInto('website_id=?', $website->getId()); - } - else { - $condition = $this->getConnection()->quoteInto('website_id=?', $website); - } - $this->addFilter('website_id', $condition, 'string'); - return $this; - } - - public function addStatusFilter($status) - { - $condition = $this->getConnection()->quoteInto('status=?', $status); - $this->addFilter('status', $condition, 'string'); - return $this; - } - - public function setCustomerOrder($sort = 'ASC') - { - $this->getSelect()->order('customer_id ' . $sort); - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Customer/Collection.php b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Customer/Collection.php index 7f5b367c17..e60828a1b4 100644 --- a/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Customer/Collection.php +++ b/app/code/core/Mage/ProductAlert/Model/Mysql4/Stock/Customer/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,27 +28,11 @@ /** * ProductAlert Stock Customer collection * - * @category Mage - * @package Mage_ProductAlert + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ -class Mage_ProductAlert_Model_Mysql4_Stock_Customer_Collection extends Mage_Customer_Model_Entity_Customer_Collection +class Mage_ProductAlert_Model_Mysql4_Stock_Customer_Collection + extends Mage_ProductAlert_Model_Resource_Stock_Customer_Collection { - public function join($productId, $websiteId) - { - $this->getSelect()->join( - array('alert' => $this->getTable('productalert/stock')), - 'alert.customer_id=e.entity_id', - array('alert_stock_id','website_id', 'add_date', 'send_date', 'send_count', 'status') - ); - - $this->getSelect()->where('alert.product_id=?', $productId); - if ($websiteId) { - $this->getSelect()->where('alert.website_id=?', $websiteId); - } - $this->_setIdFieldName('alert_stock_id'); - $this->addAttributeToSelect('*'); - - return $this; - } } diff --git a/app/code/core/Mage/ProductAlert/Model/Observer.php b/app/code/core/Mage/ProductAlert/Model/Observer.php index 6390bcb13c..cf4f3c722f 100644 --- a/app/code/core/Mage/ProductAlert/Model/Observer.php +++ b/app/code/core/Mage/ProductAlert/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/Model/Price.php b/app/code/core/Mage/ProductAlert/Model/Price.php index ac1c3d8d74..dabbb06860 100644 --- a/app/code/core/Mage/ProductAlert/Model/Price.php +++ b/app/code/core/Mage/ProductAlert/Model/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,27 @@ /** * ProductAlert for changed price model * - * @category Mage - * @package Mage_ProductAlert + * @method Mage_ProductAlert_Model_Resource_Price _getResource() + * @method Mage_ProductAlert_Model_Resource_Price getResource() + * @method int getCustomerId() + * @method Mage_ProductAlert_Model_Price setCustomerId(int $value) + * @method int getProductId() + * @method Mage_ProductAlert_Model_Price setProductId(int $value) + * @method float getPrice() + * @method Mage_ProductAlert_Model_Price setPrice(float $value) + * @method int getWebsiteId() + * @method Mage_ProductAlert_Model_Price setWebsiteId(int $value) + * @method string getAddDate() + * @method Mage_ProductAlert_Model_Price setAddDate(string $value) + * @method string getLastSendDate() + * @method Mage_ProductAlert_Model_Price setLastSendDate(string $value) + * @method int getSendCount() + * @method Mage_ProductAlert_Model_Price setSendCount(int $value) + * @method int getStatus() + * @method Mage_ProductAlert_Model_Price setStatus(int $value) + * + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ class Mage_ProductAlert_Model_Price extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Abstract.php b/app/code/core/Mage/ProductAlert/Model/Resource/Abstract.php new file mode 100644 index 0000000000..d09ed0894c --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Abstract.php @@ -0,0 +1,96 @@ + + */ +abstract class Mage_ProductAlert_Model_Resource_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Retrieve alert row by object parameters + * + * @param Mage_Core_Model_Abstract $object + * @return array|bool + */ + protected function _getAlertRow(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getReadAdapter(); + if ($object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) { + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('customer_id = :customer_id') + ->where('product_id = :product_id') + ->where('website_id = :website_id'); + $bind = array( + ':customer_id' => $object->getCustomerId(), + ':product_id' => $object->getProductId(), + ':website_id' => $object->getWebsiteId() + ); + return $adapter->fetchRow($select, $bind); + } + return false; + } + + /** + * Load object data by parameters + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_ProductAlert_Model_Resource_Abstract + */ + public function loadByParam(Mage_Core_Model_Abstract $object) + { + $row = $this->_getAlertRow($object); + if ($row) { + $object->setData($row); + } + return $this; + } + + /** + * Delete all customer alerts on website + * + * @param Mage_Core_Model_Abstract $object + * @param int $customerId + * @param int $websiteId + * @return Mage_ProductAlert_Model_Resource_Abstract + */ + public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId=null) + { + $adapter = $this->_getWriteAdapter(); + $where = array(); + $where[] = $adapter->quoteInto('customer_id=?', $customerId); + if ($websiteId) { + $where[] = $adapter->quoteInto('website_id=?', $websiteId); + } + $adapter->delete($this->getMainTable(), $where); + return $this; + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Price.php b/app/code/core/Mage/ProductAlert/Model/Resource/Price.php new file mode 100755 index 0000000000..81ffb2bfee --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Price.php @@ -0,0 +1,70 @@ + + */ +class Mage_ProductAlert_Model_Resource_Price extends Mage_ProductAlert_Model_Resource_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('productalert/price', 'alert_price_id'); + } + + /** + * Before save process, check exists the same alert + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_ProductAlert_Model_Resource_Price + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (is_null($object->getId()) && $object->getCustomerId() + && $object->getProductId() && $object->getWebsiteId()) { + if ($row = $this->_getAlertRow($object)) { + $price = $object->getPrice(); + $object->addData($row); + if ($price) { + $object->setPrice($price); + } + $object->setStatus(0); + } + } + if (is_null($object->getAddDate())) { + $object->setAddDate(Mage::getModel('core/date')->gmtDate()); + } + return parent::_beforeSave($object); + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Price/Collection.php b/app/code/core/Mage/ProductAlert/Model/Resource/Price/Collection.php new file mode 100755 index 0000000000..95f121269e --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Price/Collection.php @@ -0,0 +1,98 @@ + + */ +class Mage_ProductAlert_Model_Resource_Price_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define price collection + * + */ + protected function _construct() + { + $this->_init('productalert/price'); + } + + /** + * Add customer filter + * + * @param mixed $customer + * @return Mage_ProductAlert_Model_Resource_Price_Collection + */ + public function addCustomerFilter($customer) + { + if (is_array($customer)) { + $condition = $this->getConnection()->quoteInto('customer_id IN(?)', $customer); + } elseif ($customer instanceof Mage_Customer_Model_Customer) { + $condition = $this->getConnection()->quoteInto('customer_id=?', $customer->getId()); + } else { + $condition = $this->getConnection()->quoteInto('customer_id=?', $customer); + } + $this->addFilter('customer_id', $condition, 'string'); + return $this; + } + + /** + * Add website filter + * + * @param mixed $website + * @return Mage_ProductAlert_Model_Resource_Price_Collection + */ + public function addWebsiteFilter($website) + { + if (is_null($website) || $website == 0) { + return $this; + } + if (is_array($website)) { + $condition = $this->getConnection()->quoteInto('website_id IN(?)', $website); + } elseif ($website instanceof Mage_Core_Model_Website) { + $condition = $this->getConnection()->quoteInto('website_id=?', $website->getId()); + } else { + $condition = $this->getConnection()->quoteInto('website_id=?', $website); + } + $this->addFilter('website_id', $condition, 'string'); + return $this; + } + + /** + * Set order by customer + * + * @param string $sort + * @return Mage_ProductAlert_Model_Resource_Price_Collection + */ + public function setCustomerOrder($sort = 'ASC') + { + $this->getSelect()->order('customer_id ' . $sort); + return $this; + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Price/Customer/Collection.php b/app/code/core/Mage/ProductAlert/Model/Resource/Price/Customer/Collection.php new file mode 100755 index 0000000000..af59ce42b8 --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Price/Customer/Collection.php @@ -0,0 +1,62 @@ + + */ +class Mage_ProductAlert_Model_Resource_Price_Customer_Collection + extends Mage_Customer_Model_Resource_Customer_Collection +{ + /** + * join productalert price data to customer collection + * + * @param int $productId + * @param int $websiteId + * @return Mage_ProductAlert_Model_Resource_Price_Customer_Collection + */ + public function join($productId, $websiteId) + { + $this->getSelect()->join( + array('alert' => $this->getTable('productalert/price')), + 'e.entity_id=alert.customer_id', + array('alert_price_id', 'price', 'add_date', 'last_send_date', 'send_count', 'status') + ); + + $this->getSelect()->where('alert.product_id=?', $productId); + if ($websiteId) { + $this->getSelect()->where('alert.website_id=?', $websiteId); + } + $this->_setIdFieldName('alert_price_id'); + $this->addAttributeToSelect('*'); + + return $this; + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php b/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php new file mode 100755 index 0000000000..fa2754ea6d --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Stock.php @@ -0,0 +1,67 @@ + + */ +class Mage_ProductAlert_Model_Resource_Stock extends Mage_ProductAlert_Model_Resource_Abstract +{ + /** + * Initialize connection + * + */ + protected function _construct() + { + $this->_init('productalert/stock', 'alert_stock_id'); + } + + /** + * Before save action + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (is_null($object->getId()) && $object->getCustomerId() + && $object->getProductId() && $object->getWebsiteId()) { + if ($row = $this->_getAlertRow($object)) { + $object->addData($row); + $object->setStatus(0); + } + } + if (is_null($object->getAddDate())) { + $object->setAddDate(Mage::getModel('core/date')->gmtDate()); + $object->setStatus(0); + } + return parent::_beforeSave($object); + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Collection.php b/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Collection.php new file mode 100755 index 0000000000..dac383f1aa --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Collection.php @@ -0,0 +1,113 @@ + + */ +class Mage_ProductAlert_Model_Resource_Stock_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define stock collection + * + */ + protected function _construct() + { + $this->_init('productalert/stock'); + } + + /** + * Add customer filter + * + * @param mixed $customer + * @return Mage_ProductAlert_Model_Resource_Stock_Collection + */ + public function addCustomerFilter($customer) + { + $adapter = $this->getConnection(); + if (is_array($customer)) { + $condition = $adapter->quoteInto('customer_id IN(?)', $customer); + } elseif ($customer instanceof Mage_Customer_Model_Customer) { + $condition = $adapter->quoteInto('customer_id=?', $customer->getId()); + } else { + $condition = $adapter->quoteInto('customer_id=?', $customer); + } + $this->addFilter('customer_id', $condition, 'string'); + return $this; + } + + /** + * Add website filter + * + * @param mixed $website + * @return Mage_ProductAlert_Model_Resource_Stock_Collection + */ + public function addWebsiteFilter($website) + { + $adapter = $this->getConnection(); + if (is_null($website) || $website == 0) { + return $this; + } + if (is_array($website)) { + $condition = $adapter->quoteInto('website_id IN(?)', $website); + } elseif ($website instanceof Mage_Core_Model_Website) { + $condition = $adapter->quoteInto('website_id=?', $website->getId()); + } else { + $condition = $adapter->quoteInto('website_id=?', $website); + } + $this->addFilter('website_id', $condition, 'string'); + return $this; + } + + /** + * Add status filter + * + * @param int $status + * @return Mage_ProductAlert_Model_Resource_Stock_Collection + */ + public function addStatusFilter($status) + { + $condition = $this->getConnection()->quoteInto('status=?', $status); + $this->addFilter('status', $condition, 'string'); + return $this; + } + + /** + * Set order by customer + * + * @param string $sort + * @return Mage_ProductAlert_Model_Resource_Stock_Collection + */ + public function setCustomerOrder($sort = 'ASC') + { + $this->getSelect()->order('customer_id ' . $sort); + return $this; + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Customer/Collection.php b/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Customer/Collection.php new file mode 100755 index 0000000000..c36e0c603d --- /dev/null +++ b/app/code/core/Mage/ProductAlert/Model/Resource/Stock/Customer/Collection.php @@ -0,0 +1,62 @@ + + */ +class Mage_ProductAlert_Model_Resource_Stock_Customer_Collection + extends Mage_Customer_Model_Resource_Customer_Collection +{ + /** + * join productalert stock data to customer collection + * + * @param int $productId + * @param int $websiteId + * @return Mage_ProductAlert_Model_Resource_Stock_Customer_Collection + */ + public function join($productId, $websiteId) + { + $this->getSelect()->join( + array('alert' => $this->getTable('productalert/stock')), + 'alert.customer_id=e.entity_id', + array('alert_stock_id', 'add_date', 'send_date', 'send_count', 'status') + ); + + $this->getSelect()->where('alert.product_id=?', $productId); + if ($websiteId) { + $this->getSelect()->where('alert.website_id=?', $websiteId); + } + $this->_setIdFieldName('alert_stock_id'); + $this->addAttributeToSelect('*'); + + return $this; + } +} diff --git a/app/code/core/Mage/ProductAlert/Model/Stock.php b/app/code/core/Mage/ProductAlert/Model/Stock.php index 9a64a3b697..1bc45028d3 100644 --- a/app/code/core/Mage/ProductAlert/Model/Stock.php +++ b/app/code/core/Mage/ProductAlert/Model/Stock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,25 @@ /** * ProductAlert for back in stock model * - * @category Mage - * @package Mage_ProductAlert + * @method Mage_ProductAlert_Model_Resource_Stock _getResource() + * @method Mage_ProductAlert_Model_Resource_Stock getResource() + * @method int getCustomerId() + * @method Mage_ProductAlert_Model_Stock setCustomerId(int $value) + * @method int getProductId() + * @method Mage_ProductAlert_Model_Stock setProductId(int $value) + * @method int getWebsiteId() + * @method Mage_ProductAlert_Model_Stock setWebsiteId(int $value) + * @method string getAddDate() + * @method Mage_ProductAlert_Model_Stock setAddDate(string $value) + * @method string getSendDate() + * @method Mage_ProductAlert_Model_Stock setSendDate(string $value) + * @method int getSendCount() + * @method Mage_ProductAlert_Model_Stock setSendCount(int $value) + * @method int getStatus() + * @method Mage_ProductAlert_Model_Stock setStatus(int $value) + * + * @category Mage + * @package Mage_ProductAlert * @author Magento Core Team */ class Mage_ProductAlert_Model_Stock extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/ProductAlert/controllers/AddController.php b/app/code/core/Mage/ProductAlert/controllers/AddController.php index e2bbc8cf4f..14b792e26d 100644 --- a/app/code/core/Mage/ProductAlert/controllers/AddController.php +++ b/app/code/core/Mage/ProductAlert/controllers/AddController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php b/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php index bf86ace58c..255633be8b 100644 --- a/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php +++ b/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/etc/config.xml b/app/code/core/Mage/ProductAlert/etc/config.xml index 87b96d11b6..eaaeceec29 100644 --- a/app/code/core/Mage/ProductAlert/etc/config.xml +++ b/app/code/core/Mage/ProductAlert/etc/config.xml @@ -21,25 +21,25 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.2 + 1.6.0.0 - Mage_ProductAlert_Model - productalert_mysql4 + productalert_resource - - Mage_ProductAlert_Model_Mysql4 + + Mage_ProductAlert_Model_Resource + productalert_mysql4 product_alert_price
      @@ -48,7 +48,7 @@ product_alert_stock
      -
      +
      @@ -85,10 +85,8 @@ html -
      - @@ -100,7 +98,6 @@ - @@ -128,7 +125,6 @@ - @@ -139,13 +135,12 @@ general - + catalog_productalert_cron_error_email_template general - diff --git a/app/code/core/Mage/ProductAlert/etc/system.xml b/app/code/core/Mage/ProductAlert/etc/system.xml index c61b71b9a1..098581a49c 100644 --- a/app/code/core/Mage/ProductAlert/etc/system.xml +++ b/app/code/core/Mage/ProductAlert/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/ProductAlert/sql/productalert_setup/install-1.6.0.0.php b/app/code/core/Mage/ProductAlert/sql/productalert_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..162bb999a0 --- /dev/null +++ b/app/code/core/Mage/ProductAlert/sql/productalert_setup/install-1.6.0.0.php @@ -0,0 +1,161 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); +/** + * Create table 'productalert/price' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('productalert/price')) + ->addColumn('alert_price_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product alert price id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product id') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price amount') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website id') + ->addColumn('add_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Product alert add date') + ->addColumn('last_send_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Product alert last send date') + ->addColumn('send_count', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product alert send count') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product alert status') + ->addIndex($installer->getIdxName('productalert/price', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('productalert/price', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('productalert/price', array('website_id')), + array('website_id')) + ->addForeignKey($installer->getFkName('productalert/price', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('productalert/price', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('productalert/price', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Product Alert Price'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'productalert/stock' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('productalert/stock')) + ->addColumn('alert_stock_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Product alert stock id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website id') + ->addColumn('add_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Product alert add date') + ->addColumn('send_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Product alert send date') + ->addColumn('send_count', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Send Count') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product alert status') + ->addIndex($installer->getIdxName('productalert/stock', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('productalert/stock', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('productalert/stock', array('website_id')), + array('website_id')) + ->addForeignKey($installer->getFkName('productalert/stock', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('productalert/stock', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('productalert/stock', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Product Alert Stock'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); + diff --git a/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-install-0.7.0.php index c6ff144a03..8bd0001d78 100644 --- a/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-0.7.1-0.7.2.php index b523687166..0da7010f76 100644 --- a/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_ProductAlert - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..14c05fd2ba --- /dev/null +++ b/app/code/core/Mage/ProductAlert/sql/productalert_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,321 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_WEBSITE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/price'), + 'FK_PRODUCT_ALERT_PRICE_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('productalert/stock'), + 'FK_PRODUCT_ALERT_STOCK_WEBSITE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('productalert/price') => array( + 'columns' => array( + 'alert_price_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product alert price id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price amount' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website id' + ), + 'add_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Product alert add date' + ), + 'last_send_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Product alert last send date' + ), + 'send_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product alert send count' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product alert status' + ) + ), + 'comment' => 'Product Alert Price' + ), + $installer->getTable('productalert/stock') => array( + 'columns' => array( + 'alert_stock_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Product alert stock id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website id' + ), + 'add_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Product alert add date' + ), + 'send_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Product alert send date' + ), + 'send_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Send Count' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product alert status' + ) + ), + 'comment' => 'Product Alert Stock' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('productalert/price'), + $installer->getIdxName('productalert/price', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('productalert/price'), + $installer->getIdxName('productalert/price', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('productalert/price'), + $installer->getIdxName('productalert/price', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('productalert/stock'), + $installer->getIdxName('productalert/stock', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('productalert/stock'), + $installer->getIdxName('productalert/stock', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('productalert/stock'), + $installer->getIdxName('productalert/stock', array('website_id')), + array('website_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/price', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('productalert/price'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/price', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('productalert/price'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/price', 'website_id', 'core/website', 'website_id'), + $installer->getTable('productalert/price'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/stock', 'website_id', 'core/website', 'website_id'), + $installer->getTable('productalert/stock'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/stock', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('productalert/stock'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('productalert/stock', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('productalert/stock'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Rating/Block/Entity/Detailed.php b/app/code/core/Mage/Rating/Block/Entity/Detailed.php index efa109ecc9..933a88034b 100644 --- a/app/code/core/Mage/Rating/Block/Entity/Detailed.php +++ b/app/code/core/Mage/Rating/Block/Entity/Detailed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -42,13 +42,13 @@ public function __construct() protected function _toHtml() { $entityId = Mage::app()->getRequest()->getParam('id'); - if( intval($entityId) <= 0 ) { + if (intval($entityId) <= 0) { return ''; } $reviewsCount = Mage::getModel('review/review') ->getTotalReviews($entityId, true); - if( $reviewsCount == 0 ) { + if ($reviewsCount == 0) { #return Mage::helper('rating')->__('Be the first to review this product'); $this->setTemplate('rating/empty.phtml'); return parent::_toHtml(); diff --git a/app/code/core/Mage/Rating/Helper/Data.php b/app/code/core/Mage/Rating/Helper/Data.php index 2ff7708ec8..a71b6c2756 100644 --- a/app/code/core/Mage/Rating/Helper/Data.php +++ b/app/code/core/Mage/Rating/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating.php index d94ac54dd6..a5ad39b2ea 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating.php @@ -20,324 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating model * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ - -class Mage_Rating_Model_Mysql4_Rating extends Mage_Core_Model_Mysql4_Abstract +class Mage_Rating_Model_Mysql4_Rating extends Mage_Rating_Model_Resource_Rating { - public function _construct() - { - $this->_init('rating/rating', 'rating_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'rating_code', - 'title' => /* Mage::helper('rating')->__('Rating with the same title')*/ '' - )); - return $this; - } - - protected function _getLoadSelect($field, $value, $object) - { - $read = $this->_getReadAdapter(); - - $select = $read->select() - ->from(array('main'=>$this->getMainTable()), array('rating_id', 'entity_id', 'position')) - ->joinLeft(array('title'=>$this->getTable('rating_title')), - 'main.rating_id=title.rating_id AND title.store_id = '. (int) Mage::getSingleton('core/store')->getId(), - array('IF(title.value IS NULL, main.rating_code, title.value) AS rating_code')) - ->where('main.'.$field.'=?', $value); - return $select; - } - - protected function _afterLoad(Mage_Core_Model_Abstract $object) { - parent::_afterLoad($object); - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('rating_title')) - ->where('rating_id=?', $object->getId()); - - $data = $this->_getReadAdapter()->fetchAll($select); - $storeCodes = array(); - foreach ($data as $row) { - $storeCodes[$row['store_id']] = $row['value']; - } - if(sizeof($storeCodes)>0) { - $object->setRatingCodes($storeCodes); - } - - $storesSelect = $this->_getReadAdapter()->select() - ->from($this->getTable('rating_store')) - ->where('rating_id=?', $object->getId()); - - $stores = $this->_getReadAdapter()->fetchAll($storesSelect); - - $putStores = array(); - foreach ($stores as $store) { - $putStores[] = $store['store_id']; - } - - $object->setStores($putStores); - - return $this; - } - - protected function _afterSave(Mage_Core_Model_Abstract $object) { - parent::_afterSave($object); - - if($object->hasRatingCodes()) { - try { - $this->_getWriteAdapter()->beginTransaction(); - $condition = $this->_getWriteAdapter()->quoteInto('rating_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('rating_title'), $condition); - if ($ratingCodes = $object->getRatingCodes()) { - foreach ($ratingCodes as $storeId=>$value) { - if(trim($value)=='') { - continue; - } - $data = new Varien_Object(); - $data->setRatingId($object->getId()) - ->setStoreId($storeId) - ->setValue($value); - $this->_getWriteAdapter()->insert($this->getTable('rating_title'), $data->getData()); - } - } - $this->_getWriteAdapter()->commit(); - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - } - } - - if($object->hasStores()) { - try { - $condition = $this->_getWriteAdapter()->quoteInto('rating_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->getTable('rating_store'), $condition); - foreach ($object->getStores() as $storeId) { - $storeInsert = new Varien_Object(); - $storeInsert->setStoreId($storeId); - $storeInsert->setRatingId($object->getId()); - $this->_getWriteAdapter()->insert($this->getTable('rating_store'), $storeInsert->getData()); - } - } - catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - } - } - - return $this; - } - - /** - * Perform actions after object delete - * Prepare rating data for reaggregate all data for reviews - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Rating_Model_Mysql4_Rating - */ - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - parent::_afterDelete($object); - $data = $this->_getEntitySummaryData($object); - $summary = array(); - foreach ($data as $row) { - $clone = clone $object; - $clone->addData( $row ); - $summary[$clone->getStoreId()][$clone->getEntityPkValue()] = $clone; - } - Mage::getResourceModel('review/review_summary')->reAggregate($summary); - return $this; - } - - /** - * Return array of rating summary - * - * @param Mage_Rating_Model_Rating $object - * @param boolean $onlyForCurrentStore - * @return array - */ - public function getEntitySummary($object, $onlyForCurrentStore = true) - { - $data = $this->_getEntitySummaryData($object); - - if($onlyForCurrentStore) { - foreach ($data as $row) { - if($row['store_id']==Mage::app()->getStore()->getId()) { - $object->addData( $row ); - } - } - return $object; - } - - $result = array(); - - //$stores = Mage::app()->getStore()->getResourceCollection()->load(); - $stores = Mage::getModel('core/store')->getResourceCollection()->load(); - - foreach ($data as $row) { - $clone = clone $object; - $clone->addData( $row ); - $result[$clone->getStoreId()] = $clone; - } - - $usedStoresId = array_keys($result); - - foreach ($stores as $store) { - if (!in_array($store->getId(), $usedStoresId)) { - $clone = clone $object; - $clone->setCount(0); - $clone->setSum(0); - $clone->setStoreId($store->getId()); - $result[$store->getId()] = $clone; - } - } - - return array_values($result); - } - - /** - * Return data of rating summary - * - * @param Mage_Rating_Model_Rating $object - * @return array - */ - protected function _getEntitySummaryData($object) - { - $read = $this->_getReadAdapter(); - $sql = "SELECT - {$this->getTable('rating_vote')}.entity_pk_value as entity_pk_value, - SUM({$this->getTable('rating_vote')}.percent) as sum, - COUNT(*) as count, - {$this->getTable('review/review_store')}.store_id - FROM - {$this->getTable('rating_vote')} - INNER JOIN - {$this->getTable('review/review')} - ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review')}.review_id - LEFT JOIN - {$this->getTable('review/review_store')} - ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review_store')}.review_id - INNER JOIN - {$this->getTable('rating/rating_store')} AS rst - ON rst.rating_id = {$this->getTable('rating_vote')}.rating_id AND rst.store_id = {$this->getTable('review/review_store')}.store_id - INNER JOIN - {$this->getTable('review/review_status')} AS review_status - ON {$this->getTable('review/review')}.status_id = review_status.status_id - WHERE "; - if ($object->getEntityPkValue()) { - $sql .= "{$read->quoteInto($this->getTable('rating_vote').'.entity_pk_value=?', $object->getEntityPkValue())} AND "; - } - $sql .= "review_status.status_code = 'approved' - GROUP BY - {$this->getTable('rating_vote')}.entity_pk_value, {$this->getTable('review/review_store')}.store_id"; - - return $read->fetchAll($sql); - } - - public function getReviewSummary($object, $onlyForCurrentStore = true) - { - $read = $this->_getReadAdapter(); - $sql = "SELECT - SUM({$this->getTable('rating_vote')}.percent) as sum, - COUNT(*) as count, - {$this->getTable('review/review_store')}.store_id - FROM - {$this->getTable('rating_vote')} - LEFT JOIN - {$this->getTable('review/review_store')} - ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review_store')}.review_id - INNER JOIN - {$this->getTable('rating/rating_store')} AS rst - ON rst.rating_id = {$this->getTable('rating_vote')}.rating_id AND rst.store_id = {$this->getTable('review/review_store')}.store_id - WHERE - {$read->quoteInto($this->getTable('rating_vote').'.review_id=?', $object->getReviewId())} - GROUP BY - {$this->getTable('rating_vote')}.review_id, {$this->getTable('review/review_store')}.store_id"; - - $data = $read->fetchAll($sql); - - if($onlyForCurrentStore) { - foreach ($data as $row) { - if($row['store_id']==Mage::app()->getStore()->getId()) { - $object->addData( $row ); - } - } - return $object; - } - - $result = array(); - - $stores = Mage::app()->getStore()->getResourceCollection()->load(); - - foreach ($data as $row) { - $clone = clone $object; - $clone->addData( $row ); - $result[$clone->getStoreId()] = $clone; - } - - $usedStoresId = array_keys($result); - - foreach ($stores as $store) { - if (!in_array($store->getId(), $usedStoresId)) { - $clone = clone $object; - $clone->setCount(0); - $clone->setSum(0); - $clone->setStoreId($store->getId()); - $result[$store->getId()] = $clone; - - } - } - - return array_values($result); - } - - /** - * Get rating entity type id by code - * - * @param string $entityCode - * @return int - */ - public function getEntityIdByCode($entityCode) - { - $select = $this->_getReadAdapter()->select() - ->from( $this->getTable('rating_entity'), array('entity_id')) - ->where('entity_code = ?', $entityCode); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Delete ratings by product id - * - * @param int $productId - * @return Mage_Rating_Model_Mysql4_Rating - */ - public function deleteAggregatedRatingsByProductId($productId) - { - $entityId = $this->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE); - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('rating/rating'), array('rating_id')) - ->where('entity_id = ?', $entityId); - $ratings = $this->_getReadAdapter()->fetchCol($select); - - $this->_getWriteAdapter()->delete($this->getTable('rating/rating_vote_aggregated'), array( - 'entity_pk_value=?' => $productId, - 'rating_id IN(?)' => $ratings - )); - return $this; - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Collection.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Collection.php index dda67fc903..653d5a537f 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Collection.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Collection.php @@ -20,177 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating collection resource model * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ -class Mage_Rating_Model_Mysql4_Rating_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Rating_Model_Mysql4_Rating_Collection extends Mage_Rating_Model_Resource_Rating_Collection { - /** - * @var bool - */ - protected $_isStoreJoined = false; - - public function _construct() - { - $this->_init('rating/rating'); - } - - - - /** - * add entity filter - * - * @param int|string $entity - * @return Varien_Data_Collection_Db - */ - public function addEntityFilter($entity) - { - $this->_select->join($this->getTable('rating_entity'), - 'main_table.entity_id='.$this->getTable('rating_entity').'.entity_id'); - - if (is_numeric($entity)) { - $this->addFilter('entity', - $this->getConnection()->quoteInto($this->getTable('rating_entity').'.entity_id=?', $entity), - 'string'); - } - elseif (is_string($entity)) { - $this->addFilter('entity', - $this->getConnection()->quoteInto($this->getTable('rating_entity').'.entity_code=?', $entity), - 'string'); - } - return $this; - } - - /** - * set order by position field - * - * @param string $dir - * @return Varien_Data_Collection_Db - */ - public function setPositionOrder($dir='ASC') - { - $this->setOrder('main_table.position', $dir); - return $this; - } - - public function setStoreFilter($storeId) - { - if(!is_array($storeId)) { - $storeId = array($storeId === null ? -1 : $storeId); - } - if (empty($storeId)) { - return $this; - } - if (!$this->_isStoreJoined) { - $this->getSelect()->join(array('store'=>$this->getTable('rating_store')), 'main_table.rating_id = store.rating_id') - ->group('main_table.rating_id'); - $this->_isStoreJoined = true; - } - $this->getSelect()->where($this->getConnection()->quoteInto('store.store_id IN(?)', $storeId)); - $this->setPositionOrder(); - return $this; - } - - /** - * add options to ratings in collection - * - * @return Varien_Data_Collection_Db - */ - public function addOptionToItems() - { - $arrRatingId = $this->getColumnValues('rating_id'); - - if (!empty($arrRatingId)) { - $collection = Mage::getResourceModel('rating/rating_option_collection') - ->addRatingFilter($arrRatingId) - ->setPositionOrder() - ->load(); - - foreach ($this as $rating) { - $rating->setOptions($collection->getItemsByColumnValue('rating_id', $rating->getId())); - } - } - - return $this; - } - - public function addEntitySummaryToItem($entityPkValue, $storeId) - { - $arrRatingId = $this->getColumnValues('rating_id'); - - if( count($arrRatingId) == 0 ) { - return; - } - - $sql = "SELECT - {$this->getTable('rating_vote')}.rating_id as rating_id, - SUM({$this->getTable('rating_vote')}.percent) as sum, - COUNT(*) as count - FROM - {$this->getTable('rating_vote')} - INNER JOIN - {$this->getTable('review/review_store')} - ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review_store')}.review_id AND {$this->getTable('review/review_store')}.store_id = ". (int) $storeId . " - INNER JOIN - {$this->getTable('rating/rating_store')} AS rst - ON rst.rating_id = {$this->getTable('rating_vote')}.rating_id AND rst.store_id = ". (int) $storeId . " - INNER JOIN - {$this->getTable('review/review')} ON {$this->getTable('review/review_store')}.review_id={$this->getTable('review/review')}.review_id AND {$this->getTable('review/review')}.status_id=1 - WHERE - {$this->getConnection()->quoteInto($this->getTable('rating_vote').'.rating_id IN (?)', $arrRatingId)} - AND {$this->getConnection()->quoteInto($this->getTable('rating_vote').'.entity_pk_value=?', $entityPkValue)} - GROUP BY - {$this->getTable('rating_vote')}.rating_id"; - - $data = $this->getConnection()->fetchAll($sql); - - foreach ($data as $item) { - $rating = $this->getItemById($item['rating_id']); - if ($rating && $item['count']>0) { - $rating->setSummary($item['sum']/$item['count']); - } - } - return $this; - } - - public function addRatingPerStoreName($storeId) { - $this->getSelect()->joinLeft(array('title'=>$this->getTable('rating_title')), - 'main_table.rating_id=title.rating_id AND title.store_id = '. (int) $storeId, - array('IF(title.value IS NULL, main_table.rating_code, title.value) AS rating_code')); - return $this; - } - - public function addStoresToCollection() - { - if (!$this->_isCollectionLoaded) { - return $this; - } - $ratingIds = array(); - foreach ($this as $item) { - $ratingIds[] = $item->getId(); - $item->setStores(array()); - } - if (!$ratingIds) { - return $this; - } - - $this->_select = $this->getConnection() - ->select() - ->from($this->getTable('rating_store')) - ->where('rating_id IN(?)', $ratingIds); - foreach ($this->getConnection()->fetchAll($this->_select) as $row) { - $item = $this->getItemById($row['rating_id']); - $item->setStores(array_merge($item->getStores(), array($row['store_id']))); - } - - return $this; - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Entity.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Entity.php index 86910af27b..7f145acef6 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Entity.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Entity.php @@ -20,31 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating entity resource * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ - -class Mage_Rating_Model_Mysql4_Rating_Entity extends Mage_Core_Model_Mysql4_Abstract +class Mage_Rating_Model_Mysql4_Rating_Entity extends Mage_Rating_Model_Resource_Rating_Entity { - function _construct() - { - $this->_init('rating/rating_entity', 'entity_id'); - } - - public function getIdByCode($entityCode) - { - $read = $this->_getReadAdapter(); - $select = $read->select(); - $select->from($this->getTable('rating_entity'), $this->getIdFieldName()) - ->where('entity_code = ?', $entityCode); - return $read->fetchOne($select); - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option.php index 5225297872..54ecb8616b 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option.php @@ -20,184 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating option resource model * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ -class Mage_Rating_Model_Mysql4_Rating_Option +class Mage_Rating_Model_Mysql4_Rating_Option extends Mage_Rating_Model_Resource_Rating_Option { - protected $_reviewTable; - protected $_ratingOptionTable; - protected $_ratingVoteTable; - protected $_aggregateTable; - protected $_reviewStoreTable; - protected $_ratingStoreTable; - - protected $_read; - protected $_write; - - protected $_optionData; - protected $_optionId; - - public function __construct() - { - $this->_reviewTable = Mage::getSingleton('core/resource')->getTableName('review/review'); - $this->_ratingOptionTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_option'); - $this->_ratingVoteTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_vote'); - $this->_aggregateTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_vote_aggregated'); - $this->_reviewStoreTable = Mage::getSingleton('core/resource')->getTableName('review/review_store'); - $this->_ratingStoreTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_store'); - - $this->_read = Mage::getSingleton('core/resource')->getConnection('rating_read'); - $this->_write = Mage::getSingleton('core/resource')->getConnection('rating_write'); - } - - public function save($object) - { - if( $object->getId() ) { - $condition = $this->_write->quoteInto('option_id = ?', $object->getId()); - $object->unsetData('option_id'); - $this->_write->update($this->_ratingOptionTable, $object->getData(), $condition); - } else { - $this->_write->insert($this->_ratingOptionTable, $object->getData()); - } - return $object; - } - - public function delete($object) - { - $condition = $this->_write->quoteInto('option_id = ?', $object->getId()); - $this->_write->delete($this->_ratingOptionTable, $condition); - } - - public function addVote($option) - { - $optionData = $this->load($option->getId()); - $data = array( - 'option_id' => $option->getId(), - 'review_id' => $option->getReviewId(), - 'percent' => (($optionData['value'] / 5) * 100), - 'value' => $optionData['value'] - ); - - if( !$option->getDoUpdate() ) { - $data['remote_ip'] = Mage::helper('core/http')->getRemoteAddr(); - $data['remote_ip_long'] = Mage::helper('core/http')->getRemoteAddr(true); - $data['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId(); - $data['entity_pk_value'] = $option->getEntityPkValue(); - $data['rating_id'] = $option->getRatingId(); - } - - $this->_write->beginTransaction(); - try { - if( $option->getDoUpdate() ) { - $condition = "vote_id = '{$option->getVoteId()}' AND review_id = '{$option->getReviewId()}'"; - $this->_write->update($this->_ratingVoteTable, $data, $condition); - $this->aggregate($option); - } else { - $this->_write->insert($this->_ratingVoteTable, $data); - $option->setVoteId($this->_write->lastInsertId()); - $this->aggregate($option); - } - $this->_write->commit(); - } - catch (Exception $e){ - $this->_write->rollback(); - throw new Exception($e->getMessage()); - } - return $this; - } - - public function aggregate($option) - { - $optionData = $this->load($option->getId()); - $vote = Mage::getModel('rating/rating_option_vote')->load($option->getVoteId()); - $this->aggregateEntityByRatingId($vote->getRatingId(), $vote->getEntityPkValue()); - } - - public function aggregateEntityByRatingId($ratingId, $entityPkValue) - { - $select = $this->_read->select() - ->from($this->_aggregateTable) - ->where('rating_id = ?', $ratingId) - ->where('entity_pk_value = ?', $entityPkValue); - - $data = $this->_read->fetchAll($select); - - $oldData = array(); - foreach($data as $row) { - $oldData[$row['store_id']] = $row['primary_id']; - } - - $select = $this->_read->select() - ->from(array('vote'=>$this->_ratingVoteTable), - array('COUNT(vote.vote_id) AS vote_count', - 'SUM(vote.value) AS vote_value_sum', - 'COUNT(CASE WHEN review.status_id=1 THEN vote.vote_id ELSE NULL END) AS app_vote_count', - 'SUM(CASE WHEN review.status_id=1 THEN vote.value ELSE 0 END) AS app_vote_value_sum', - )) - ->join(array('review'=>$this->_reviewTable), 'vote.review_id=review.review_id', array()) - ->joinLeft(array('store'=>$this->_reviewStoreTable), 'vote.review_id=store.review_id', 'store_id') - ->join(array('rstore'=>$this->_ratingStoreTable), 'vote.rating_id=rstore.rating_id AND rstore.store_id=store.store_id', array()) - ->where('vote.rating_id = ?', $ratingId) - ->where('vote.entity_pk_value = ?', $entityPkValue) - ->group('vote.rating_id') - ->group('vote.entity_pk_value') - ->group('store.store_id'); - - $perStoreInfo = $this->_read->fetchAll($select); - - $usedStores = array(); - foreach($perStoreInfo as $row) { - $saveData = new Varien_Object(array( - 'rating_id' => $ratingId, - 'entity_pk_value' => $entityPkValue, - 'vote_count' => $row['vote_count'], - 'vote_value_sum' => $row['vote_value_sum'], - 'percent' => (($row['vote_value_sum']/$row['vote_count'])/5) * 100, - 'percent_approved' => ($row['app_vote_count'] ? ((($row['app_vote_value_sum']/$row['app_vote_count'])/5) * 100) : 0), - 'store_id' => $row['store_id'], - )); - - if(isset($oldData[$row['store_id']])) { - $condition = $this->_write->quoteInto("primary_id = ?", $oldData[$row['store_id']]); - $this->_write->update($this->_aggregateTable, $saveData->getData(), $condition); - } else { - $this->_write->insert($this->_aggregateTable, $saveData->getData()); - } - - $usedStores[] = $row['store_id']; - } - - $toDelete = array_diff(array_keys($oldData), $usedStores); - - foreach ($toDelete as $storeId) { - $condition = $this->_write->quoteInto("primary_id = ?", $oldData[$storeId]); - $this->_write->delete($this->_aggregateTable, $condition); - } - } - - public function load($optionId) - { - if( !$this->_optionData || $this->_optionId != $optionId ) { - $select = $this->_read->select(); - $select->from($this->_ratingOptionTable) - ->where('option_id = ?', $optionId); - - $data = $this->_read->fetchRow($select); - - $this->_optionData = $data; - $this->_optionId = $optionId; - return $data; - } - - return $this->_optionData; - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Collection.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Collection.php index 4634175a4f..06a7e852d4 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Collection.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Collection.php @@ -20,59 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating option collection * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ -class Mage_Rating_Model_Mysql4_Rating_Option_Collection extends Varien_Data_Collection_Db +class Mage_Rating_Model_Mysql4_Rating_Option_Collection extends Mage_Rating_Model_Resource_Rating_Option_Collection { - protected $_ratingOptionTable; - protected $_ratingVoteTable; - - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('rating_read')); - $this->_ratingOptionTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_option'); - $this->_ratingVoteTable = Mage::getSingleton('core/resource')->getTableName('rating/rating_vote'); - - $this->_select->from($this->_ratingOptionTable); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('rating/rating_option')); - } - - /** - * add rating filter - * - * @param int|array $rating - * @return Varien_Data_Collection_Db - */ - public function addRatingFilter($rating) - { - if (is_numeric($rating)) { - $this->addFilter('rating_id', $rating); - } - elseif (is_array($rating)) { - $this->addFilter('rating_id', $this->_getConditionSql('rating_id', array('in'=>$rating)), 'string'); - } - return $this; - } - - /** - * set order by position field - * - * @param string $dir - * @return Varien_Data_Collection_Db - */ - public function setPositionOrder($dir='ASC') - { - $this->setOrder($this->_ratingOptionTable.'.position', $dir); - return $this; - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote.php index 46fd340bd4..0e8b560f1e 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote.php @@ -20,22 +20,18 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating vote resource model * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ - -class Mage_Rating_Model_Mysql4_Rating_Option_Vote extends Mage_Core_Model_Mysql4_Abstract +class Mage_Rating_Model_Mysql4_Rating_Option_Vote extends Mage_Rating_Model_Resource_Rating_Option_Vote { - function _construct() - { - $this->_init('rating/rating_option_vote', 'vote_id'); - } } diff --git a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote/Collection.php b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote/Collection.php index d8739d7cd1..2496d2b4a6 100644 --- a/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote/Collection.php +++ b/app/code/core/Mage/Rating/Model/Mysql4/Rating/Option/Vote/Collection.php @@ -20,89 +20,19 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Rating votes collection * - * @category Mage - * @package Mage_Rating + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ - -class Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection + extends Mage_Rating_Model_Resource_Rating_Option_Vote_Collection { - public function _construct() - { - $this->_init('rating/rating_option_vote'); - } - - public function setReviewFilter($reviewId) - { - $this->_select->where("main_table.review_id = ?", $reviewId); - return $this; - } - - public function setEntityPkFilter($entityId) - { - $this->_select->where("entity_pk_value = ?", $entityId); - return $this; - } - - public function setStoreFilter($storeId) - { - $this->_select->join(array('rstore'=>$this->getTable('review/review_store')), 'main_table.review_id=rstore.review_id AND rstore.store_id=' . (int)$storeId, array()); - return $this; - } - - public function addRatingInfo($storeId=null) - { - $this->_select->join($this->getTable('rating/rating'), "{$this->getTable('rating/rating')}.rating_id = main_table.rating_id", "{$this->getTable('rating/rating')}.*") - ->joinLeft(array('title'=>$this->getTable('rating/rating_title')), - "main_table.rating_id=title.rating_id AND title.store_id = ". (int) Mage::app()->getStore()->getId(), - array("IF(title.value IS NULL, {$this->getTable('rating/rating')}.rating_code, title.value) AS rating_code")); - - if($storeId == null) { - $storeId = Mage::app()->getStore()->getId(); - } - - if(is_array($storeId)) { - $condition = $this->getConnection()->quoteInto('store.store_id IN(?)', $storeId); - } else { - $condition = $this->getConnection()->quoteInto('store.store_id = ?', $storeId); - } - - $this->_select->join(array('store'=>$this->getTable('rating_store')), 'main_table.rating_id = store.rating_id AND '. $condition); - $this->_select->group('main_table.vote_id'); - - return $this; - } - - public function addOptionInfo() - { - $this->_select->join($this->getTable('rating/rating_option'), "main_table.option_id = {$this->getTable('rating/rating_option')}.option_id", "{$this->getTable('rating/rating_option')}.*"); - return $this; - } - - public function addRatingOptions() - { - if( !$this->getSize() ) { - return $this; - } - foreach( $this->getItems() as $item ) { - $options = Mage::getModel('rating/rating_option') - ->getResourceCollection() - ->addRatingFilter($item->getRatingId()) - ->load(); - - if( $item->getRatingId() ) { - $item->setRatingOptions($options); - } else { - return; - } - } - return $this; - } } diff --git a/app/code/core/Mage/Rating/Model/Observer.php b/app/code/core/Mage/Rating/Model/Observer.php index 8376607137..b010005995 100644 --- a/app/code/core/Mage/Rating/Model/Observer.php +++ b/app/code/core/Mage/Rating/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/Model/Rating.php b/app/code/core/Mage/Rating/Model/Rating.php index 2b174d1774..520b0310eb 100644 --- a/app/code/core/Mage/Rating/Model/Rating.php +++ b/app/code/core/Mage/Rating/Model/Rating.php @@ -20,13 +20,22 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Rating model * + * @method Mage_Rating_Model_Resource_Rating getResource() + * @method Mage_Rating_Model_Resource_Rating _getResource() + * @method array getRatingCodes() + * @method Mage_Rating_Model_Rating setRatingCodes(array $value) + * @method array getStores() + * @method Mage_Rating_Model_Rating setStores(array $value) + * @method string getRatingCode() + * @method Mage_Rating_Model_Rating getRatingCode(string $value) + * * @category Mage * @package Mage_Rating * @author Magento Core Team @@ -41,7 +50,12 @@ class Mage_Rating_Model_Rating extends Mage_Core_Model_Abstract const ENTITY_PRODUCT_REVIEW_CODE = 'product_review'; const ENTITY_REVIEW_CODE = 'review'; - public function __construct() + /** + * Define resource model + * + * @return void + */ + protected function _construct() { $this->_init('rating/rating'); } diff --git a/app/code/core/Mage/Rating/Model/Rating/Entity.php b/app/code/core/Mage/Rating/Model/Rating/Entity.php index 0bccab681e..381d7d19e1 100644 --- a/app/code/core/Mage/Rating/Model/Rating/Entity.php +++ b/app/code/core/Mage/Rating/Model/Rating/Entity.php @@ -20,15 +20,20 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Ratings entity model * - * @category Mage - * @package Mage_Rating + * @method Mage_Rating_Model_Resource_Rating_Entity _getResource() + * @method Mage_Rating_Model_Resource_Rating_Entity getResource() + * @method string getEntityCode() + * @method Mage_Rating_Model_Rating_Entity setEntityCode(string $value) + * + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ diff --git a/app/code/core/Mage/Rating/Model/Rating/Option.php b/app/code/core/Mage/Rating/Model/Rating/Option.php index ed2bf2b9cf..5c075dc0b4 100644 --- a/app/code/core/Mage/Rating/Model/Rating/Option.php +++ b/app/code/core/Mage/Rating/Model/Rating/Option.php @@ -20,50 +20,33 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Rating option model * - * @category Mage - * @package Mage_Rating + * @method Mage_Rating_Model_Resource_Rating_Option _getResource() + * @method Mage_Rating_Model_Resource_Rating_Option getResource() + * @method int getRatingId() + * @method Mage_Rating_Model_Rating_Option setRatingId(int $value) + * @method string getCode() + * @method Mage_Rating_Model_Rating_Option setCode(string $value) + * @method int getValue() + * @method Mage_Rating_Model_Rating_Option setValue(int $value) + * @method int getPosition() + * @method Mage_Rating_Model_Rating_Option setPosition(int $value) + * + * @category Mage + * @package Mage_Rating * @author Magento Core Team */ -class Mage_Rating_Model_Rating_Option extends Varien_Object +class Mage_Rating_Model_Rating_Option extends Mage_Core_Model_Abstract { - public function __construct() - { - parent::__construct(); - } - - public function getResource() - { - return Mage::getResourceModel('rating/rating_option'); - } - - public function getResourceCollection() - { - return Mage::getResourceModel('rating/rating_option_collection'); - } - - public function load($optionId) - { - $this->setData($this->getResource()->load($optionId)); - return $this; - } - - public function save() + protected function _construct() { - $this->getResource()->save($this); - return $this; - } - - public function delete() - { - $this->getResource()->delete($this); - return $this; + $this->_init('rating/rating_option'); } public function addVote() @@ -78,13 +61,8 @@ public function setId($id) return $this; } - public function getId() - { - return $this->getOptionId(); - } - - public function getCollection() - { - return Mage::getResourceModel('rating/rating_option_collection'); - } +// public function getId() +// { +// return $this->getOptionId(); +// } } diff --git a/app/code/core/Mage/Rating/Model/Rating/Option/Vote.php b/app/code/core/Mage/Rating/Model/Rating/Option/Vote.php index e99c1c2f75..1a499407c3 100644 --- a/app/code/core/Mage/Rating/Model/Rating/Option/Vote.php +++ b/app/code/core/Mage/Rating/Model/Rating/Option/Vote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating.php b/app/code/core/Mage/Rating/Model/Resource/Rating.php new file mode 100755 index 0000000000..a088700181 --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating.php @@ -0,0 +1,442 @@ + + */ +class Mage_Rating_Model_Resource_Rating extends Mage_Core_Model_Resource_Db_Abstract +{ + const RATING_STATUS_APPROVED = 'Approved'; + + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('rating/rating', 'rating_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Rating_Model_Resource_Rating + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => 'rating_code', + 'title' => /* Mage::helper('rating')->__('Rating with the same title')*/ '' + )); + return $this; + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Rating_Model_Rating $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $adapter = $this->_getReadAdapter(); + + $table = $this->getMainTable(); + $storeId = (int)Mage::app()->getStore()->getId(); + $select = parent::_getLoadSelect($field, $value, $object); + $codeExpr = $adapter->getIfNullSql('title.value', "{$table}.rating_code"); + + $select->joinLeft( + array('title' => $this->getTable('rating/rating_title')), + $adapter->quoteInto("{$table}.rating_id = title.rating_id AND title.store_id = ?", $storeId), + array('rating_code' => $codeExpr)); + + return $select; + } + + /** + * Actions after load + * + * @param Mage_Rating_Model_Rating $object + * @return Mage_Rating_Model_Resource_Rating + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + parent::_afterLoad($object); + + if (!$object->getId()) { + return $this; + } + + $adapter = $this->_getReadAdapter(); + $bind = array(':rating_id' => (int)$object->getId()); + // load rating titles + $select = $adapter->select() + ->from($this->getTable('rating/rating_title'), array('store_id', 'value')) + ->where('rating_id=:rating_id'); + + $result = $adapter->fetchPairs($select, $bind); + if ($result) { + $object->setRatingCodes($result); + } + + // load rating available in stores + $select = $adapter->select() + ->from($this->getTable('rating/rating_store'), 'store_id') + ->where('rating_id=:rating_id'); + $result = $adapter->fetchCol($select, $bind); + $object->setStores($result); + + return $this; + } + + /** + * Actions after save + * + * @param Mage_Rating_Model_Rating $object + * @return Mage_Rating_Model_Resource_Rating + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + parent::_afterSave($object); + + $adapter = $this->_getWriteAdapter(); + $ratingId = (int)$object->getId(); + + if ($object->hasRatingCodes()) { + $ratingTitleTable = $this->getTable('rating/rating_title'); + $adapter->beginTransaction(); + try { + $select = $adapter->select() + ->from($ratingTitleTable, array('store_id', 'value')) + ->where('rating_id = :rating_id'); + $old = $adapter->fetchPairs($select, array(':rating_id' => $ratingId)); + $new = $object->getRatingCodes(); + + $insert = array_diff_assoc($new, $old); + $delete = array_diff_assoc($old, $new); + + if ($insert) { + $data = array(); + foreach ($insert as $storeId => $title) { + //remove record if title is empty + if (empty($title)) { + $delete[$storeId] = $title; + continue; + } + $data[] = array( + 'rating_id' => $ratingId, + 'store_id' => (int)$storeId, + 'value' => $title + ); + } + if (!empty($data)) { + $adapter->insertMultiple($ratingTitleTable, $data); + } + } + if ($old && $delete) { + $where = array( + 'rating_id = ?' => $ratingId, + 'store_id IN(?)' => array_keys($delete) + ); + $adapter->delete($ratingTitleTable, $where); + } + $adapter->commit(); + } catch (Exception $e) { + Mage::logException($e); + $adapter->rollBack(); + } + } + + if ($object->hasStores()) { + $ratingStoreTable = $this->getTable('rating/rating_store'); + $adapter->beginTransaction(); + try { + $select = $adapter->select() + ->from($ratingStoreTable, array('store_id')) + ->where('rating_id = :rating_id'); + $old = $adapter->fetchCol($select, array(':rating_id' => $ratingId)); + $new = $object->getStores(); + + $insert = array_diff($new, $old); + $delete = array_diff($old, $new); + + if ($delete) { + $where = array( + 'rating_id = ?' => $ratingId, + 'store_id IN(?)' => $delete + ); + $adapter->delete($ratingStoreTable, $where); + } + + if ($insert) { + $data = array(); + foreach ($insert as $storeId) { + $data[] = array( + 'rating_id' => $ratingId, + 'store_id' => (int)$storeId, + ); + } + $adapter->insertMultiple($ratingStoreTable, $data); + } + + $adapter->commit(); + } catch (Exception $e) { + Mage::logException($e); + $adapter->rollBack(); + } + } + + return $this; + } + + /** + * Perform actions after object delete + * Prepare rating data for reaggregate all data for reviews + * + * @param Mage_Rating_Model_Rating $object + * @return Mage_Rating_Model_Resource_Rating + */ + protected function _afterDelete(Mage_Core_Model_Abstract $object) + { + parent::_afterDelete($object); + if (!Mage::helper('rating')->isModuleEnabled('Mage_Review')) { + return $this; + } + $data = $this->_getEntitySummaryData($object); + $summary = array(); + foreach ($data as $row) { + $clone = clone $object; + $clone->addData($row); + $summary[$clone->getStoreId()][$clone->getEntityPkValue()] = $clone; + } + Mage::getResourceModel('review/review_summary')->reAggregate($summary); + return $this; + } + + /** + * Return array of rating summary + * + * @param Mage_Rating_Model_Rating $object + * @param boolean $onlyForCurrentStore + * @return array + */ + public function getEntitySummary($object, $onlyForCurrentStore = true) + { + $data = $this->_getEntitySummaryData($object); + + if ($onlyForCurrentStore) { + foreach ($data as $row) { + if ($row['store_id']==Mage::app()->getStore()->getId()) { + $object->addData($row); + } + } + return $object; + } + + $result = array(); + + //$stores = Mage::app()->getStore()->getResourceCollection()->load(); + $stores = Mage::getModel('core/store')->getResourceCollection()->load(); + + foreach ($data as $row) { + $clone = clone $object; + $clone->addData($row); + $result[$clone->getStoreId()] = $clone; + } + + $usedStoresId = array_keys($result); + + foreach ($stores as $store) { + if (!in_array($store->getId(), $usedStoresId)) { + $clone = clone $object; + $clone->setCount(0); + $clone->setSum(0); + $clone->setStoreId($store->getId()); + $result[$store->getId()] = $clone; + } + } + + return array_values($result); + } + + /** + * Return data of rating summary + * + * @param Mage_Rating_Model_Rating $object + * @return array + */ + protected function _getEntitySummaryData($object) + { + $adapter = $this->_getReadAdapter(); + + $sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})"); + $countColumn = new Zend_Db_Expr("COUNT(*)"); + + $select = $adapter->select() + ->from(array('rating_vote' => $this->getTable('rating/rating_option_vote')), + array( + 'entity_pk_value' => 'rating_vote.entity_pk_value', + 'sum' => $sumColumn, + 'count' => $countColumn)) + ->join(array('review' => $this->getTable('review/review')), + 'rating_vote.review_id=review.review_id', + array()) + ->joinLeft(array('review_store' => $this->getTable('review/review_store')), + 'rating_vote.review_id=review_store.review_id', + array('review_store.store_id')) + ->join(array('rating_store' => $this->getTable('rating/rating_store')), + 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', + array()) + ->join(array('review_status' => $this->getTable('review/review_status')), + 'review.status_id = review_status.status_id', + array()) + ->where('review_status.status_code = :status_code') + ->group('rating_vote.entity_pk_value') + ->group('review_store.store_id'); + $bind = array(':status_code' => self::RATING_STATUS_APPROVED); + + $entityPkValue = $object->getEntityPkValue(); + if ($entityPkValue) { + $select->where('rating_vote.entity_pk_value = :pk_value'); + $bind[':pk_value'] = $entityPkValue; + } + + return $adapter->fetchAll($select, $bind); + } + + /** + * Review summary + * + * @param Mage_Rating_Model_Rating $object + * @param boolean $onlyForCurrentStore + * @return array + */ + public function getReviewSummary($object, $onlyForCurrentStore = true) + { + $adapter = $this->_getReadAdapter(); + + $sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})"); + $countColumn = new Zend_Db_Expr('COUNT(*)'); + $select = $adapter->select() + ->from(array('rating_vote' => $this->getTable('rating/rating_option_vote')), + array( + 'sum' => $sumColumn, + 'count' => $countColumn + )) + ->joinLeft(array('review_store' => $this->getTable('review/review_store')), + 'rating_vote.review_id = review_store.review_id', + array('review_store.store_id')) + ->join(array('rating_store' => $this->getTable('rating/rating_store')), + 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', + array()) + ->where('rating_vote.review_id = :review_id') + ->group('rating_vote.review_id') + ->group('review_store.store_id'); + + $data = $adapter->fetchAll($select, array(':review_id' => $object->getReviewId())); + + if ($onlyForCurrentStore) { + foreach ($data as $row) { + if ($row['store_id'] == Mage::app()->getStore()->getId()) { + $object->addData($row); + } + } + return $object; + } + + $result = array(); + + $stores = Mage::app()->getStore()->getResourceCollection()->load(); + + foreach ($data as $row) { + $clone = clone $object; + $clone->addData($row); + $result[$clone->getStoreId()] = $clone; + } + + $usedStoresId = array_keys($result); + + foreach ($stores as $store) { + if (!in_array($store->getId(), $usedStoresId)) { + $clone = clone $object; + $clone->setCount(0); + $clone->setSum(0); + $clone->setStoreId($store->getId()); + $result[$store->getId()] = $clone; + + } + } + + return array_values($result); + } + + /** + * Get rating entity type id by code + * + * @param string $entityCode + * @return int + */ + public function getEntityIdByCode($entityCode) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('rating/rating_entity'), array('entity_id')) + ->where('entity_code = :entity_code'); + + return $this->_getReadAdapter()->fetchOne($select, array(':entity_code' => $entityCode)); + } + + /** + * Delete ratings by product id + * + * @param int $productId + * @return Mage_Rating_Model_Resource_Rating + */ + public function deleteAggregatedRatingsByProductId($productId) + { + $entityId = $this->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE); + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), 'rating_id') + ->where('entity_id = :entity_id'); + $ratingIds = $adapter->fetchCol($select, array(':entity_id' => $entityId)); + + if ($ratingIds) { + $where = array( + 'entity_pk_value = ?' => (int) $productId, + 'rating_id IN(?)' => $ratingIds + ); + $adapter->delete($this->getTable('rating/rating_vote_aggregated'), $where); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php new file mode 100755 index 0000000000..8d5f31f5af --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Collection.php @@ -0,0 +1,260 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * @var bool + */ + protected $_isStoreJoined = false; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('rating/rating'); + } + + /** + * Add entity filter + * + * @param int|string $entity + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addEntityFilter($entity) + { + $adapter = $this->getConnection(); + + $this->getSelect() + ->join($this->getTable('rating_entity'), + 'main_table.entity_id=' . $this->getTable('rating_entity') . '.entity_id', + array('entity_code')); + + if (is_numeric($entity)) { + $this->addFilter('entity', + $adapter->quoteInto($this->getTable('rating_entity') . '.entity_id=?', $entity), + 'string'); + } elseif (is_string($entity)) { + $this->addFilter('entity', + $adapter->quoteInto($this->getTable('rating_entity') . '.entity_code=?', $entity), + 'string'); + } + return $this; + } + + /** + * set order by position field + * + * @param string $dir + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function setPositionOrder($dir='ASC') + { + $this->setOrder('main_table.position', $dir); + return $this; + } + + /** + * Set store filter + * + * @param int_type $storeId + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function setStoreFilter($storeId) + { + $adapter = $this->getConnection(); + if (!is_array($storeId)) { + $storeId = array($storeId === null ? -1 : $storeId); + } + if (empty($storeId)) { + return $this; + } + if (!$this->_isStoreJoined) { + $this->getSelect() + ->distinct(true) + ->join( + array('store'=>$this->getTable('rating_store')), + 'main_table.rating_id = store.rating_id', + array()) + // ->group('main_table.rating_id') + ; + $this->_isStoreJoined = true; + } + $inCond = $adapter->prepareSqlCondition('store.store_id', array( + 'in' => $storeId + )); + $this->getSelect() + ->where($inCond); + $this->setPositionOrder(); + return $this; + } + + /** + * Add options to ratings in collection + * + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addOptionToItems() + { + $arrRatingId = $this->getColumnValues('rating_id'); + + if (!empty($arrRatingId)) { + $collection = Mage::getResourceModel('rating/rating_option_collection') + ->addRatingFilter($arrRatingId) + ->setPositionOrder() + ->load(); + + foreach ($this as $rating) { + $rating->setOptions($collection->getItemsByColumnValue('rating_id', $rating->getId())); + } + } + + return $this; + } + + /** + * Add entity summary to item + * + * @param int $entityPkValue + * @param int $storeId + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addEntitySummaryToItem($entityPkValue, $storeId) + { + $arrRatingId = $this->getColumnValues('rating_id'); + if (count($arrRatingId) == 0) { + return $this; + } + + $adapter = $this->getConnection(); + + $inCond = $adapter->prepareSqlCondition('rating_option_vote.rating_id', array( + 'in' => $arrRatingId + )); + $sumCond = new Zend_Db_Expr("SUM(rating_option_vote.{$adapter->quoteIdentifier('percent')})"); + $countCond = new Zend_Db_Expr('COUNT(*)'); + $select = $adapter->select() + ->from(array('rating_option_vote' => $this->getTable('rating/rating_option_vote')), + array( + 'rating_id' => 'rating_option_vote.rating_id', + 'sum' => $sumCond, + 'count' => $countCond + )) + ->join( + array('review_store' => $this->getTable('review/review_store')), + 'rating_option_vote.review_id=review_store.review_id AND review_store.store_id = :store_id', + array()) + ->join( + array('rst' => $this->getTable('rating/rating_store')), + 'rst.rating_id = rating_option_vote.rating_id AND rst.store_id = :rst_store_id', + array()) + ->join(array('review' => $this->getTable('review/review')), + 'review_store.review_id=review.review_id AND review.status_id=1', + array()) + ->where($inCond) + ->where('rating_option_vote.entity_pk_value=:pk_value') + ->group('rating_option_vote.rating_id'); + $bind = array( + ':store_id' => (int)$storeId, + ':rst_store_id' => (int)$storeId, + ':pk_value' => $entityPkValue + ); + $data = $this->getConnection()->fetchAll($select, $bind); + + foreach ($data as $item) { + $rating = $this->getItemById($item['rating_id']); + if ($rating && $item['count']>0) { + $rating->setSummary($item['sum']/$item['count']); + } + } + return $this; + } + + /** + * Add rating store name + * + * @param int $storeId + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addRatingPerStoreName($storeId) + { + $adapter = $this->getConnection(); + $ratingCodeCond = $adapter->getIfNullSql('title.value', 'main_table.rating_code'); + $this->getSelect() + ->joinLeft(array('title' => $this->getTable('rating_title')), + $adapter->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?', (int) $storeId), + array('rating_code' => $ratingCodeCond)); + return $this; + } + + /** + * Add stores to collection + * + * @return Mage_Rating_Model_Resource_Rating_Collection + */ + public function addStoresToCollection() + { + if (!$this->_isCollectionLoaded) { + return $this; + } + $ratingIds = array(); + foreach ($this as $item) { + $ratingIds[] = $item->getId(); + $item->setStores(array()); + } + if (!$ratingIds) { + return $this; + } + $adapter = $this->getConnection(); + + $inCond = $adapter->prepareSqlCondition('rating_id', array( + 'in' => $ratingIds + )); + + $this->_select = $adapter + ->select() + ->from($this->getTable('rating_store')) + ->where($inCond); + + $data = $adapter->fetchAll($this->_select); + if (is_array($data) && count($data) > 0) { + foreach ($data as $row) { + $item = $this->getItemById($row['rating_id']); + $item->setStores(array_merge($item->getStores(), array($row['store_id']))); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Entity.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Entity.php new file mode 100755 index 0000000000..ffe5aca8f3 --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Entity.php @@ -0,0 +1,61 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Entity extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Rating entity resource initialization + * + */ + protected function _construct() + { + $this->_init('rating/rating_entity', 'entity_id'); + } + + /** + * Return entity_id by entityCode + * + * @param string $entityCode + * @return int + */ + public function getIdByCode($entityCode) + { + $adapter = $this->_getReadAdapter(); + + $select = $adapter->select() + ->from($this->getTable('rating_entity'), $this->getIdFieldName()) + ->where('entity_code = :entity_code'); + return $adapter->fetchOne($select, array(':entity_code' => $entityCode)); + } +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php new file mode 100755 index 0000000000..57c2e7565a --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php @@ -0,0 +1,267 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Review table + * + * @var string + */ + protected $_reviewTable; + + /** + * Rating option table + * + * @var string + */ + protected $_ratingOptionTable; + + /** + * Rating vote table + * + * @var string + */ + protected $_ratingVoteTable; + + /** + * Aggregate table + * + * @var string + */ + protected $_aggregateTable; + + /** + * Review store table + * + * @var string + */ + protected $_reviewStoreTable; + + /** + * Rating store table + * + * @var string + */ + protected $_ratingStoreTable; + + /** + * Option data + * + * @var array + */ + protected $_optionData; + + /** + * Option id + * + * @var int + */ + protected $_optionId; + + /** + * Resource initialization. Define other tables name + * + */ + protected function _construct() + { + $this->_init('rating/rating_option', 'option_id'); + + $this->_reviewTable = $this->getTable('review/review'); + $this->_ratingOptionTable = $this->getTable('rating/rating_option'); + $this->_ratingVoteTable = $this->getTable('rating/rating_option_vote'); + $this->_aggregateTable = $this->getTable('rating/rating_vote_aggregated'); + $this->_reviewStoreTable = $this->getTable('review/review_store'); + $this->_ratingStoreTable = $this->getTable('rating/rating_store'); + } + + /** + * Add vote + * + * @param Mage_Rating_Model_Rating_Option $option + * @return Mage_Rating_Model_Resource_Rating_Option + */ + public function addVote($option) + { + $adapter = $this->_getWriteAdapter(); + $optionData = $this->loadDataById($option->getId()); + $data = array( + 'option_id' => $option->getId(), + 'review_id' => $option->getReviewId(), + 'percent' => (($optionData['value'] / 5) * 100), + 'value' => $optionData['value'] + ); + + if (!$option->getDoUpdate()) { + $data['remote_ip'] = Mage::helper('core/http')->getRemoteAddr(); + $data['remote_ip_long'] = Mage::helper('core/http')->getRemoteAddr(true); + $data['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId(); + $data['entity_pk_value'] = $option->getEntityPkValue(); + $data['rating_id'] = $option->getRatingId(); + } + + $adapter->beginTransaction(); + try { + if ($option->getDoUpdate()) { + $condition = array( + 'vote_id = ?' => $option->getVoteId(), + 'review_id = ?' => $option->getReviewId() + ); + $adapter->update($this->_ratingVoteTable, $data, $condition); + $this->aggregate($option); + } else { + $adapter->insert($this->_ratingVoteTable, $data); + $option->setVoteId($adapter->lastInsertId($this->_ratingVoteTable)); + $this->aggregate($option); + } + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollback(); + throw new Exception($e->getMessage()); + } + return $this; + } + + /** + * Aggregate options + * + * @param Mage_Rating_Model_Rating_Option $option + */ + public function aggregate($option) + { + $vote = Mage::getModel('rating/rating_option_vote')->load($option->getVoteId()); + $this->aggregateEntityByRatingId($vote->getRatingId(), $vote->getEntityPkValue()); + } + + /** + * Aggregate entity by rating id + * + * @param int $ratingId + * @param int $entityPkValue + */ + public function aggregateEntityByRatingId($ratingId, $entityPkValue) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + $select = $readAdapter->select() + ->from($this->_aggregateTable, array('store_id', 'primary_id')) + ->where('rating_id = :rating_id') + ->where('entity_pk_value = :pk_value'); + $bind = array(':rating_id' => $ratingId, ':pk_value' => $entityPkValue); + $oldData = $readAdapter->fetchPairs($select, $bind); + + $appVoteCountCond = $readAdapter->getCheckSql('review.status_id=1', 'vote.vote_id', 'NULL'); + $appVoteValueSumCond = $readAdapter->getCheckSql('review.status_id=1', 'vote.value', '0'); + + $select = $readAdapter->select() + ->from(array('vote'=>$this->_ratingVoteTable), + array( + 'vote_count' => new Zend_Db_Expr('COUNT(vote.vote_id)'), + 'vote_value_sum' => new Zend_Db_Expr('SUM(vote.value)'), + 'app_vote_count' => new Zend_Db_Expr("COUNT({$appVoteCountCond})"), + 'app_vote_value_sum' => new Zend_Db_Expr("SUM({$appVoteValueSumCond})") )) + ->join(array('review' =>$this->_reviewTable), + 'vote.review_id=review.review_id', + array()) + ->joinLeft(array('store'=>$this->_reviewStoreTable), + 'vote.review_id=store.review_id', 'store_id') + ->join(array('rstore' =>$this->_ratingStoreTable), + 'vote.rating_id=rstore.rating_id AND rstore.store_id=store.store_id', + array()) + ->where('vote.rating_id = :rating_id') + ->where('vote.entity_pk_value = :pk_value') + ->group(array( + 'vote.rating_id', + 'vote.entity_pk_value', + 'store.store_id' + )); + + $perStoreInfo = $readAdapter->fetchAll($select, $bind); + + $usedStores = array(); + foreach ($perStoreInfo as $row) { + $saveData = array( + 'rating_id' => $ratingId, + 'entity_pk_value' => $entityPkValue, + 'vote_count' => $row['vote_count'], + 'vote_value_sum' => $row['vote_value_sum'], + 'percent' => (($row['vote_value_sum']/$row['vote_count'])/5) * 100, + 'percent_approved' => ($row['app_vote_count'] ? ((($row['app_vote_value_sum']/$row['app_vote_count'])/5) * 100) : 0), + 'store_id' => $row['store_id'], + ); + + if (isset($oldData[$row['store_id']])) { + $condition = array('primary_id = ?' => $oldData[$row['store_id']]); + $writeAdapter->update($this->_aggregateTable, $saveData, $condition); + } else { + $writeAdapter->insert($this->_aggregateTable, $saveData); + } + + $usedStores[] = $row['store_id']; + } + + $toDelete = array_diff(array_keys($oldData), $usedStores); + + foreach ($toDelete as $storeId) { + $condition = array('primary_id = ?' => $oldData[$storeId]); + $writeAdapter->delete($this->_aggregateTable, $condition); + } + } + + /** + * Load object data by optionId + * Method renamed from 'load'. + * + * @param int $optionId + * @return array + */ + public function loadDataById($optionId) + { + if (!$this->_optionData || $this->_optionId != $optionId) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select(); + $select->from($this->_ratingOptionTable) + ->where('option_id = :option_id'); + + $data = $adapter->fetchRow($select, array(':option_id' => $optionId)); + + $this->_optionData = $data; + $this->_optionId = $optionId; + return $data; + } + + return $this->_optionData; + } + +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Collection.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Collection.php new file mode 100755 index 0000000000..5bff514f5f --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Collection.php @@ -0,0 +1,90 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Rating options table + * + * @var string + * @deprecated since 1.5.0.0 + */ + protected $_ratingOptionTable; + + /** + * Rating votes table + * + * @var string + */ + protected $_ratingVoteTable; + + /** + * Define model + * + */ + protected function _construct() + { + $this->_init('rating/rating_option'); + $this->_ratingOptionTable = $this->getTable('rating/rating_option'); + $this->_ratingVoteTable = $this->getTable('rating/rating_option_vote'); + } + + /** + * Add rating filter + * + * @param int|array $rating + * @return Mage_Rating_Model_Resource_Rating_Option_Collection + */ + public function addRatingFilter($rating) + { + if (is_numeric($rating)) { + $this->addFilter('rating_id', $rating); + } elseif (is_array($rating)) { + $this->addFilter('rating_id', $this->_getConditionSql('rating_id', array('in'=>$rating)), 'string'); + } + return $this; + } + + /** + * Set order by position field + * + * @param string $dir + * @return Mage_Rating_Model_Resource_Rating_Option_Collection + */ + public function setPositionOrder($dir='ASC') + { + $this->setOrder('main_table.position', $dir); + return $this; + } +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote.php new file mode 100755 index 0000000000..43f80451ee --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote.php @@ -0,0 +1,44 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Option_Vote extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('rating/rating_option_vote', 'vote_id'); + } +} diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php new file mode 100755 index 0000000000..dd8e4f5e2b --- /dev/null +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option/Vote/Collection.php @@ -0,0 +1,169 @@ + + */ +class Mage_Rating_Model_Resource_Rating_Option_Vote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Define model + * + */ + protected function _construct() + { + $this->_init('rating/rating_option_vote'); + } + + /** + * Set review filter + * + * @param int $reviewId + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function setReviewFilter($reviewId) + { + $this->getSelect() + ->where("main_table.review_id = ?", $reviewId); + return $this; + } + + /** + * Set EntityPk filter + * + * @param int $entityId + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function setEntityPkFilter($entityId) + { + $this->getSelect() + ->where("entity_pk_value = ?", $entityId); + return $this; + } + + /** + * Set store filter + * + * @param int $storeId + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function setStoreFilter($storeId) + { + $this->getSelect() + ->join(array('rstore'=>$this->getTable('review/review_store')), + $this->getConnection()->quoteInto( + 'main_table.review_id=rstore.review_id AND rstore.store_id=?', + (int)$storeId), + array()); + return $this; + } + + /** + * Add rating info to select + * + * @param int $storeId + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function addRatingInfo($storeId=null) + { + $adapter=$this->getConnection(); + $ratingCodeCond = $adapter->getIfNullSql('title.value', 'rating.rating_code'); + $this->getSelect() + ->join( + array('rating' => $this->getTable('rating/rating')), + 'rating.rating_id = main_table.rating_id', + array('rating_code')) + ->joinLeft( + array('title' => $this->getTable('rating/rating_title')), + $adapter->quoteInto('main_table.rating_id=title.rating_id AND title.store_id = ?', + (int)Mage::app()->getStore()->getId()), + array('rating_code' => $ratingCodeCond)); + + if ($storeId == null) { + $storeId = Mage::app()->getStore()->getId(); + } + + if (is_array($storeId)) { + $condition = $adapter->prepareSqlCondition('store.store_id', array( + 'in' => $storeId + )); + } else { + $condition = $adapter->quoteInto('store.store_id = ?', $storeId); + } + + $this->getSelect() + ->join( + array('store' => $this->getTable('rating_store')), + 'main_table.rating_id = store.rating_id AND ' . $condition) +// ->group('main_table.vote_id') + ; + + $adapter->fetchAll($this->getSelect()); + return $this; + } + + /** + * Add option info to select + * + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function addOptionInfo() + { + $this->getSelect() + ->join(array('rating_option' => $this->getTable('rating/rating_option')), + 'main_table.option_id = rating_option.option_id'); + return $this; + } + + /** + * Add rating options + * + * @return Mage_Rating_Model_Resource_Rating_Option_Vote_Collection + */ + public function addRatingOptions() + { + if (!$this->getSize()) { + return $this; + } + foreach ($this->getItems() as $item) { + $options = Mage::getModel('rating/rating_option') + ->getResourceCollection() + ->addRatingFilter($item->getRatingId()) + ->load(); + + if ($item->getRatingId()) { + $item->setRatingOptions($options); + } else { + return; + } + } + return $this; + } +} diff --git a/app/code/core/Mage/Rating/data/rating_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Rating/data/rating_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..bfdbd50f34 --- /dev/null +++ b/app/code/core/Mage/Rating/data/rating_setup/data-install-1.6.0.0.php @@ -0,0 +1,83 @@ + + */ + +/* @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; + +$data = array( + Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE => array( + array( + 'rating_code' => 'Quality', + 'position' => 0 + ), + array( + 'rating_code' => 'Value', + 'position' => 0 + ), + array( + 'rating_code' => 'Price', + 'position' => 0 + ), + ), + Mage_Rating_Model_Rating::ENTITY_PRODUCT_REVIEW_CODE => array( + ), + Mage_Rating_Model_Rating::ENTITY_REVIEW_CODE => array( + ), +); + +foreach ($data as $entityCode => $ratings) { + //Fill table rating/rating_entity + $installer->getConnection() + ->insert($installer->getTable('rating_entity'), array('entity_code' => $entityCode)); + $entityId = $installer->getConnection()->lastInsertId($installer->getTable('rating_entity')); + + foreach ($ratings as $bind) { + //Fill table rating/rating + $bind['entity_id'] = $entityId; + $installer->getConnection()->insert($installer->getTable('rating'), $bind); + + //Fill table rating/rating_option + $ratingId = $installer->getConnection()->lastInsertId($installer->getTable('rating')); + $optionData = array(); + for ($i = 1; $i <= 5; $i ++) { + $optionData[] = array( + 'rating_id' => $ratingId, + 'code' => (string)$i, + 'value' => $i, + 'position' => $i + ); + } + $installer->getConnection()->insertMultiple($installer->getTable('rating_option'), $optionData); + } +} diff --git a/app/code/core/Mage/Rating/etc/adminhtml.xml b/app/code/core/Mage/Rating/etc/adminhtml.xml index a6001b36e1..9ae6bf1de8 100644 --- a/app/code/core/Mage/Rating/etc/adminhtml.xml +++ b/app/code/core/Mage/Rating/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Rating/etc/config.xml b/app/code/core/Mage/Rating/etc/config.xml index e048957c6e..4300598b3c 100644 --- a/app/code/core/Mage/Rating/etc/config.xml +++ b/app/code/core/Mage/Rating/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.2 + 1.6.0.0 Mage_Rating_Model - rating_mysql4 + rating_resource - - Mage_Rating_Model_Mysql4 + + Mage_Rating_Model_Resource + rating_mysql4 rating
      @@ -55,9 +56,6 @@ rating_option
      - - rating_option_vote
      -
      rating_option_vote
      @@ -65,7 +63,7 @@ rating_option_vote_aggregated
      -
      +
      @@ -75,9 +73,9 @@ - - Mage_Rating_Block - + + Mage_Rating_Block +
      @@ -91,7 +89,6 @@ - diff --git a/app/code/core/Mage/Rating/sql/rating_setup/install-1.6.0.0.php b/app/code/core/Mage/Rating/sql/rating_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..a20da03968 --- /dev/null +++ b/app/code/core/Mage/Rating/sql/rating_setup/install-1.6.0.0.php @@ -0,0 +1,309 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); + +/** + * Create table 'rating/rating_entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_entity')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('entity_code', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false + ), 'Entity Code') + ->addIndex($installer->getIdxName('rating/rating_entity', array('entity_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('entity_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Rating entities'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating')) + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rating Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Entity Id') + ->addColumn('rating_code', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false + ), 'Rating Code') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Rating Position On Frontend') + ->addIndex($installer->getIdxName('rating/rating', array('rating_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('rating_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('rating/rating', array('entity_id')), + array('entity_id')) + ->addForeignKey($installer->getFkName('rating/rating', 'entity_id', 'rating/rating_entity', 'entity_id'), + 'entity_id', $installer->getTable('rating/rating_entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Ratings'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rating Option Id') + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Rating Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false + ), 'Rating Option Code') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Rating Option Value') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Ration option position on frontend') + ->addIndex($installer->getIdxName('rating/rating_option', array('rating_id')), + array('rating_id')) + ->addForeignKey($installer->getFkName('rating/rating_option', 'rating_id', 'rating/rating', 'rating_id'), + 'rating_id', $installer->getTable('rating/rating'), 'rating_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Rating options'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating_option_vote' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_option_vote')) + ->addColumn('vote_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Vote id') + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Vote option id') + ->addColumn('remote_ip', Varien_Db_Ddl_Table::TYPE_TEXT, 16, array( + 'nullable' => false + ), 'Customer IP') + ->addColumn('remote_ip_long', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'nullable' => false, + 'default' => 0 + ), 'Customer IP converted to long integer format') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => 0 + ), 'Customer Id') + ->addColumn('entity_pk_value', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Product id') + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Rating id') + ->addColumn('review_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + ), 'Review id') + ->addColumn('percent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => 0 + ), 'Percent amount') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => 0 + ), 'Vote option value') + ->addIndex($installer->getIdxName('rating/rating_option_vote', array('option_id')), + array('option_id')) + ->addForeignKey($installer->getFkName('rating/rating_option_vote', 'option_id', 'rating/rating_option', 'option_id'), + 'option_id', $installer->getTable('rating/rating_option'), 'option_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Rating option values'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating_vote_aggregated' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_vote_aggregated')) + ->addColumn('primary_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Vote aggregation id') + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Rating id') + ->addColumn('entity_pk_value', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Product id') + ->addColumn('vote_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Vote dty') + ->addColumn('vote_value_sum', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'General vote sum') + ->addColumn('percent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => 0 + ), 'Vote percent') + ->addColumn('percent_approved', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'default' => '0', + ), 'Vote percent approved by admin') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Store Id') + ->addIndex($installer->getIdxName('rating/rating_vote_aggregated', array('rating_id')), + array('rating_id')) + ->addIndex($installer->getIdxName('rating/rating_vote_aggregated', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('rating/rating_vote_aggregated', 'rating_id', 'rating/rating', 'rating_id'), + 'rating_id', $installer->getTable('rating/rating'), 'rating_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('rating/rating_vote_aggregated', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Rating vote aggregated'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_store')) + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'primary' => true, + ), 'Rating id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'primary' => true + ), 'Store id') + ->addIndex($installer->getIdxName('rating/rating_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('rating/rating_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('rating/rating_store', 'rating_id', 'rating/rating', 'rating_id'), + 'rating_id', $installer->getTable('rating/rating'), 'rating_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Rating Store'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'rating/rating_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('rating/rating_title')) + ->addColumn('rating_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'primary' => true, + ), 'Rating Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'primary' => true + ), 'Store Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false + ), 'Rating Label') + ->addIndex($installer->getIdxName('rating/rating_title', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('rating/rating_title', 'rating_id', 'rating/rating', 'rating_id'), + 'rating_id', $installer->getTable('rating/rating'), 'rating_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('rating/rating_title', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Rating Title'); +$installer->getConnection()->createTable($table); + +/** + * Review/Rating module upgrade. + * Create FK for 'rating/rating_option_vote' + */ +$table = $installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_option_vote', 'review_id', 'review/review', 'review_id'), + $installer->getTable('rating/rating_option_vote'), 'review_id', + $installer->getTable('review/review'), 'review_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-install-0.7.0.php index b834dcef3f..5efeb8aea3 100644 --- a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.0-0.7.1.php index 3d8f69b225..b817ca2e84 100644 --- a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.1-0.7.2.php index 9e41058742..8c4af4c9fe 100644 --- a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rating - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..34e2fdb421 --- /dev/null +++ b/app/code/core/Mage/Rating/sql/rating_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,568 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating'), + 'FK_RATING_ENTITY_KEY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_option'), + 'FK_RATING_OPTION_RATING' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_option_vote'), + 'FK_RATING_OPTION_REVIEW_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_option_vote'), + 'FK_RATING_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_vote_aggregated'), + 'FK_RATING_OPTION_VALUE_AGGREGATE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_vote_aggregated'), + 'FK_RATING_OPTION_VOTE_AGGREGATED_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_store'), + 'FK_RATING_STORE_RATING' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_store'), + 'FK_RATING_STORE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_title'), + 'FK_RATING_TITLE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('rating/rating_title'), + 'FK_RATING_TITLE_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating'), + 'FK_RATING_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_entity'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_option'), + 'FK_RATING_OPTION_RATING' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_option_vote'), + 'FK_RATING_OPTION_VALUE_OPTION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_option_vote'), + 'FK_RATING_OPTION_REVIEW_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_vote_aggregated'), + 'FK_RATING_OPTION_VALUE_AGGREGATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_vote_aggregated'), + 'FK_RATING_OPTION_VOTE_AGGREGATED_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_store'), + 'FK_RATING_STORE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('rating/rating_title'), + 'FK_RATING_TITLE_STORE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('rating/rating') => array( + 'columns' => array( + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rating Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Id' + ), + 'rating_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Rating Code' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rating Position On Frontend' + ) + ), + 'comment' => 'Ratings' + ), + $installer->getTable('rating/rating_store') => array( + 'columns' => array( + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Rating id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store id' + ) + ), + 'comment' => 'Rating Store' + ), + $installer->getTable('rating/rating_title') => array( + 'columns' => array( + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Rating Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Rating Label' + ) + ), + 'comment' => 'Rating Title' + ), + $installer->getTable('rating/rating_entity') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'entity_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Entity Code' + ) + ), + 'comment' => 'Rating entities' + ), + $installer->getTable('rating/rating_option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rating Option Id' + ), + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rating Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Rating Option Code' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rating Option Value' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Ration option position on frontend' + ) + ), + 'comment' => 'Rating options' + ), + $installer->getTable('rating/rating_option_vote') => array( + 'columns' => array( + 'vote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Vote id' + ), + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Vote option id' + ), + 'remote_ip' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 16, + 'nullable' => false, + 'comment' => 'Customer IP' + ), + 'remote_ip_long' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer IP converted to long integer format' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer Id' + ), + 'entity_pk_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rating id' + ), + 'review_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'comment' => 'Review id' + ), + 'percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Percent amount' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Vote option value' + ) + ), + 'comment' => 'Rating option values' + ), + $installer->getTable('rating/rating_vote_aggregated') => array( + 'columns' => array( + 'primary_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Vote aggregation id' + ), + 'rating_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rating id' + ), + 'entity_pk_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'vote_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Vote dty' + ), + 'vote_value_sum' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'General vote sum' + ), + 'percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Vote percent' + ), + 'percent_approved' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'default' => '0', + 'comment' => 'Vote percent approved by admin' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Rating vote aggregated' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating'), + $installer->getIdxName( + 'rating/rating', + array('rating_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('rating_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating'), + $installer->getIdxName('rating/rating', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_entity'), + $installer->getIdxName( + 'rating/rating_entity', + array('entity_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('entity_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_option'), + $installer->getIdxName('rating/rating_option', array('rating_id')), + array('rating_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_option_vote'), + $installer->getIdxName('rating/rating_option_vote', array('option_id')), + array('option_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_vote_aggregated'), + $installer->getIdxName('rating/rating_vote_aggregated', array('rating_id')), + array('rating_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_vote_aggregated'), + $installer->getIdxName('rating/rating_vote_aggregated', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_store'), + $installer->getIdxName('rating/rating_store', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('rating/rating_title'), + $installer->getIdxName('rating/rating_title', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating', 'entity_id', 'rating/rating_entity', 'entity_id'), + $installer->getTable('rating/rating'), + 'entity_id', + $installer->getTable('rating/rating_entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_option', 'rating_id', 'rating/rating', 'rating_id'), + $installer->getTable('rating/rating_option'), + 'rating_id', + $installer->getTable('rating/rating'), + 'rating_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_option_vote', 'review_id', 'review/review', 'review_id'), + $installer->getTable('rating/rating_option_vote'), + 'review_id', + $installer->getTable('review/review'), + 'review_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_option_vote', 'option_id', 'rating/rating_option', 'option_id'), + $installer->getTable('rating/rating_option_vote'), + 'option_id', + $installer->getTable('rating/rating_option'), + 'option_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_vote_aggregated', 'rating_id', 'rating/rating', 'rating_id'), + $installer->getTable('rating/rating_vote_aggregated'), + 'rating_id', + $installer->getTable('rating/rating'), + 'rating_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_vote_aggregated', 'store_id', 'core/store', 'store_id'), + $installer->getTable('rating/rating_vote_aggregated'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('rating/rating_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_store', 'rating_id', 'rating/rating', 'rating_id'), + $installer->getTable('rating/rating_store'), + 'rating_id', + $installer->getTable('rating/rating'), + 'rating_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_title', 'rating_id', 'rating/rating', 'rating_id'), + $installer->getTable('rating/rating_title'), + 'rating_id', + $installer->getTable('rating/rating'), + 'rating_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('rating/rating_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('rating/rating_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Reports/Block/Product/Abstract.php b/app/code/core/Mage/Reports/Block/Product/Abstract.php index 6256af0ac3..0e5527f20a 100644 --- a/app/code/core/Mage/Reports/Block/Product/Abstract.php +++ b/app/code/core/Mage/Reports/Block/Product/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -99,7 +99,7 @@ protected function _getModel() /** * Retrieve Index Product Collection * - * @return Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract */ public function getItemsCollection() { diff --git a/app/code/core/Mage/Reports/Block/Product/Compared.php b/app/code/core/Mage/Reports/Block/Product/Compared.php index 51f540b49f..2730e72642 100644 --- a/app/code/core/Mage/Reports/Block/Product/Compared.php +++ b/app/code/core/Mage/Reports/Block/Product/Compared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Block/Product/Viewed.php b/app/code/core/Mage/Reports/Block/Product/Viewed.php index 13b7e7dae6..aa911d66bf 100644 --- a/app/code/core/Mage/Reports/Block/Product/Viewed.php +++ b/app/code/core/Mage/Reports/Block/Product/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Block/Product/Widget/Compared.php b/app/code/core/Mage/Reports/Block/Product/Widget/Compared.php index a38ad80520..da3f1b0a98 100644 --- a/app/code/core/Mage/Reports/Block/Product/Widget/Compared.php +++ b/app/code/core/Mage/Reports/Block/Product/Widget/Compared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Block/Product/Widget/Viewed.php b/app/code/core/Mage/Reports/Block/Product/Widget/Viewed.php index dae845198d..c8dd21f4c1 100644 --- a/app/code/core/Mage/Reports/Block/Product/Widget/Viewed.php +++ b/app/code/core/Mage/Reports/Block/Product/Widget/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Exception.php b/app/code/core/Mage/Reports/Exception.php index ac2e6372bd..bea573e35a 100644 --- a/app/code/core/Mage/Reports/Exception.php +++ b/app/code/core/Mage/Reports/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Helper/Data.php b/app/code/core/Mage/Reports/Helper/Data.php index 89f1f3c09f..354cdbe186 100644 --- a/app/code/core/Mage/Reports/Helper/Data.php +++ b/app/code/core/Mage/Reports/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Config.php b/app/code/core/Mage/Reports/Model/Config.php index 2e285edf5e..64d8993a4a 100644 --- a/app/code/core/Mage/Reports/Model/Config.php +++ b/app/code/core/Mage/Reports/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Event.php b/app/code/core/Mage/Reports/Model/Event.php index 3a1ad681e6..8be3e59bb8 100644 --- a/app/code/core/Mage/Reports/Model/Event.php +++ b/app/code/core/Mage/Reports/Model/Event.php @@ -20,16 +20,31 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Events model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @method Mage_Reports_Model_Resource_Event _getResource() + * @method Mage_Reports_Model_Resource_Event getResource() + * @method string getLoggedAt() + * @method Mage_Reports_Model_Event setLoggedAt(string $value) + * @method int getEventTypeId() + * @method Mage_Reports_Model_Event setEventTypeId(int $value) + * @method int getObjectId() + * @method Mage_Reports_Model_Event setObjectId(int $value) + * @method int getSubjectId() + * @method Mage_Reports_Model_Event setSubjectId(int $value) + * @method int getSubtype() + * @method Mage_Reports_Model_Event setSubtype(int $value) + * @method int getStoreId() + * @method Mage_Reports_Model_Event setStoreId(int $value) + * + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ class Mage_Reports_Model_Event extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Reports/Model/Event/Observer.php b/app/code/core/Mage/Reports/Model/Event/Observer.php index 636abbe802..98d546329b 100644 --- a/app/code/core/Mage/Reports/Model/Event/Observer.php +++ b/app/code/core/Mage/Reports/Model/Event/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Event/Type.php b/app/code/core/Mage/Reports/Model/Event/Type.php index a9493156c3..180ae1ed5e 100644 --- a/app/code/core/Mage/Reports/Model/Event/Type.php +++ b/app/code/core/Mage/Reports/Model/Event/Type.php @@ -20,15 +20,22 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Event type model * - * @category Mage - * @package Mage_Reports + * @method Mage_Reports_Model_Resource_Event_Type _getResource() + * @method Mage_Reports_Model_Resource_Event_Type getResource() + * @method string getEventName() + * @method Mage_Reports_Model_Event_Type setEventName(string $value) + * @method int getCustomerLogin() + * @method Mage_Reports_Model_Event_Type setCustomerLogin(int $value) + * + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ diff --git a/app/code/core/Mage/Reports/Model/Flag.php b/app/code/core/Mage/Reports/Model/Flag.php index 3a883692f0..fe2fad95f9 100644 --- a/app/code/core/Mage/Reports/Model/Flag.php +++ b/app/code/core/Mage/Reports/Model/Flag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Grouped/Collection.php b/app/code/core/Mage/Reports/Model/Grouped/Collection.php index ba045f0b6f..5503174b1d 100644 --- a/app/code/core/Mage/Reports/Model/Grouped/Collection.php +++ b/app/code/core/Mage/Reports/Model/Grouped/Collection.php @@ -20,24 +20,25 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Reports_Model_Grouped_Collection extends Varien_Data_Collection +class Mage_Reports_Model_Grouped_Collection + extends Varien_Data_Collection //Mage_Core_Model_Resource_Db_Collection_Abstract { /** - * Enter description here... + * Column name for group by clause * - * @var unknown_type + * @var string */ protected $_columnGroupBy = null; /** - * Enter description here... + * Collection resource * - * @var unknown_type + * @var Mage_Core_Model_Resource_Db_Collection_Abstract */ - protected $_resourceCollection = array(); + protected $_resourceCollection = null; /** * Set column to group by @@ -47,7 +48,7 @@ class Mage_Reports_Model_Grouped_Collection extends Varien_Data_Collection */ public function setColumnGroupBy($column) { - $this->_columnGroupBy = $column; + $this->_columnGroupBy = (string)$column; return $this; } @@ -55,7 +56,7 @@ public function setColumnGroupBy($column) * Load collection * * @param boolean $printQuery - * @param boolean$logQuery + * @param boolean $logQuery * @return Mage_Reports_Model_Grouped_Collection */ public function load($printQuery = false, $logQuery = false) @@ -67,7 +68,7 @@ public function load($printQuery = false, $logQuery = false) parent::load($printQuery, $logQuery); $this->_setIsLoaded(); - if (!is_null($this->_columnGroupBy)) { + if ($this->_columnGroupBy !== null) { $this->_mergeWithEmptyData(); $this->_groupResourceData(); } @@ -78,7 +79,7 @@ public function load($printQuery = false, $logQuery = false) /** * Setter for resource collection * - * @param unknown_type $collection + * @param Varien_Data_Collection_Db $collection * @return Mage_Reports_Model_Grouped_Collection */ public function setResourceCollection($collection) diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Accounts/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Accounts/Collection.php index f00ec187bd..28857c74cb 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Accounts/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Accounts/Collection.php @@ -20,48 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * New Accounts Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Accounts_Collection extends Mage_Reports_Model_Mysql4_Customer_Collection +class Mage_Reports_Model_Mysql4_Accounts_Collection extends Mage_Reports_Model_Resource_Accounts_Collection { - - protected function _joinFields($from = '', $to = '') - { - $this->addAttributeToFilter('created_at' , array("from" => $from, "to" => $to, "datetime" => true)) - ->addExpressionAttributeToSelect("accounts", "COUNT({{entity_id}})", array("entity_id")) - ->getSelect()->group('("*")'); - - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->_joinFields($from, $to); - return $this; - } - - /** - * Set store filter to collection - * - * @param array $setStoreIds - * @return Mage_Reports_Model_Mysql4_Accounts_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); - } - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Coupons/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Coupons/Collection.php index c459b86ba5..fe6c78cb21 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Coupons/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Coupons/Collection.php @@ -20,89 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Coupons Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Coupons_Collection extends Mage_Sales_Model_Entity_Order_Collection +class Mage_Reports_Model_Mysql4_Coupons_Collection extends Mage_Reports_Model_Resource_Coupons_Collection { - - protected $_from = ''; - protected $_to = ''; - - public function setDateRange($from, $to) - { - $this->_from = $from; - $this->_to = $to; - $this->_reset(); - return $this; - } - - public function setStoreIds($storeIds) - { - $this->joinFields($this->_from, $this->_to, $storeIds); - return $this; - } - - public function joinFields($from, $to, $storeIds = array()) - { - $this->groupByAttribute('coupon_code') - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)) - ->addAttributeToFilter('coupon_code', array('neq' => '')) - ->getselect()->columns(array('uses' => 'COUNT(e.entity_id)')) - ->having('uses > 0') - ->order('uses desc'); - //die($this->getSelect()); - $storeIds = array_values($storeIds); - if (count($storeIds) >= 1 && $storeIds[0] != '') { - $this->addAttributeToFilter('store_id', array('in' => $storeIds)); - $this->addExpressionAttributeToSelect( - 'subtotal', - 'SUM({{base_subtotal}})', - array('base_subtotal')) - ->addExpressionAttributeToSelect( - 'discount', - 'SUM({{base_discount_amount}})', - array('base_discount_amount')) - ->addExpressionAttributeToSelect( - 'total', - 'SUM({{base_subtotal}}-{{base_discount_amount}})', - array('base_subtotal', 'base_discount_amount')); - } else { - $this->addExpressionAttributeToSelect( - 'subtotal', - 'SUM({{base_subtotal}}*{{base_to_global_rate}})', - array('base_subtotal', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'discount', - 'SUM({{base_discount_amount}}*{{base_to_global_rate}})', - array('base_discount_amount', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'total', - 'SUM(({{base_subtotal}}-{{base_discount_amount}})*{{base_to_global_rate}})', - array('base_subtotal', 'base_discount_amount', 'base_to_global_rate')); - } - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(DISTINCT main_table.rule_id)"); - $sql = $countSelect->__toString(); - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Collection.php index b84bd1d3df..c7806247d5 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Collection.php @@ -20,205 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Customer_Collection extends Mage_Customer_Model_Entity_Customer_Collection +class Mage_Reports_Model_Mysql4_Customer_Collection extends Mage_Reports_Model_Resource_Customer_Collection { - /** - * Add order statistics flag - * - * @var boolean - */ - protected $_addOrderStatistics = false; - /** - * Add order statistics is filter flag - * - * @var boolean - */ - protected $_addOrderStatisticsIsFilter = false; - - protected $_customerIdTableName; - protected $_customerIdFieldName; - protected $_orderEntityTableName; - protected $_orderEntityFieldName; - - public function addCartInfo() - { - foreach ($this->getItems() as $item) - { - $quote = Mage::getModel('sales/quote')->loadByCustomer($item->getId()); - - if (is_object($quote)) - { - $totals = $quote->getTotals(); - $item->setTotal($totals['subtotal']->getValue()); - $quote_items = Mage::getResourceModel('sales/quote_item_collection')->setQuoteFilter($quote->getId()); - $quote_items->load(); - $item->setItems($quote_items->count()); - } else { - $item->remove(); - } - - } - return $this; - } - - public function addCustomerName() - { - $this->addNameToSelect(); - return $this; - } - - /** - * Order for each customer - * - * @param string $from - * @param string $to - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - public function joinOrders($from = '', $to = '') - { - if ($from != '' && $to != '') { - $dateFilter = " and orders.created_at BETWEEN '{$from}' AND '{$to}'"; - } else { - $dateFilter = ''; - } - - $this->getSelect() - ->joinLeft(array('orders'=>$this->getTable('sales/order')), - "orders.customer_id=e.entity_id".$dateFilter, - array()); - - return $this; - } - - /** - * Add orders count - * - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - public function addOrdersCount() - { - - $this->getSelect() - ->columns(array("orders_count" => "COUNT(orders.entity_id)")) - ->where('orders.state <> ?', Mage_Sales_Model_Order::STATE_CANCELED) - ->group("e.entity_id"); - - return $this; - } - - /** - * Order summary info for each customer - * such as orders_count, orders_avg_amount, orders_total_amount - * - * @param int $storeId - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - public function addSumAvgTotals($storeId = 0) - { - /** - * calculate average and total amount - */ - $expr = ($storeId == 0) - ? "(orders.base_subtotal-IFNULL(orders.base_subtotal_canceled,0)-IFNULL(orders.base_subtotal_refunded,0))*orders.base_to_global_rate" - : "{orders.base_subtotal-IFNULL(orders.base_subtotal_canceled,0)-IFNULL(orders.base_subtotal_refunded,0)"; - - $this->getSelect() - ->columns(array("orders_avg_amount" => "AVG({$expr})")) - ->columns(array("orders_sum_amount" => "SUM({$expr})")); - - return $this; - } - - public function orderByTotalAmount($dir = 'desc') - { - $this->getSelect() - ->order("orders_sum_amount {$dir}"); - return $this; - } - - /** - * Add order statistics - * - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - public function addOrdersStatistics($isFilter = false) - { - $this->_addOrderStatistics = true; - $this->_addOrderStatisticsIsFilter = $isFilter; - return $this; - } - - /** - * Add orders statistics to collection items - * - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - protected function _addOrdersStatistics() - { - $customerIds = $this->getColumnValues($this->getResource()->getIdFieldName()); - - if ($this->_addOrderStatistics && !empty($customerIds)) { - $totalExpr = ($this->_addOrderStatisticsIsFilter) - ? '(orders.base_subtotal-IFNULL(orders.base_subtotal_canceled,0)-IFNULL(orders.base_subtotal_refunded,0))*orders.base_to_global_rate' - : 'orders.base_subtotal-IFNULL(orders.base_subtotal_canceled,0)-IFNULL(orders.base_subtotal_refunded,0)'; - $select = $this->getConnection()->select(); - $select->from(array('orders'=>$this->getTable('sales/order')), array( - 'orders_avg_amount' => "AVG({$totalExpr})", - 'orders_sum_amount' => "SUM({$totalExpr})", - 'orders_count' => 'COUNT(orders.entity_id)', - 'customer_id' - ))->where('orders.state <> ?', Mage_Sales_Model_Order::STATE_CANCELED) - ->where('orders.customer_id IN(?)', $customerIds) - ->group('orders.customer_id'); - - foreach ($this->getConnection()->fetchAll($select) as $ordersInfo) { - $this->getItemById($ordersInfo['customer_id'])->addData($ordersInfo); - } - } - - return $this; - } - - /** - * Collection after load operations like adding orders statistics - * - * @return Mage_Reports_Model_Mysql4_Customer_Collection - */ - protected function _afterLoad() - { - $this->_addOrdersStatistics(); - return $this; - } - - public function orderByCustomerRegistration($dir = 'desc') - { - $this->addAttributeToSort('entity_id', $dir); - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(DISTINCT e.entity_id)"); - - return $countSelect; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Orders/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Orders/Collection.php index fec272e53f..c584ca8062 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Orders/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Orders/Collection.php @@ -20,53 +20,19 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers by orders Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Customer_Orders_Collection extends Mage_Reports_Model_Mysql4_Order_Collection +class Mage_Reports_Model_Mysql4_Customer_Orders_Collection + extends Mage_Reports_Model_Resource_Customer_Orders_Collection { - protected function _joinFields($from = '', $to = '') - { - $this->joinCustomerName() - ->groupByCustomer() - ->addOrdersCount() - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)); - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->_joinFields($from, $to); - return $this; - } - - /** - * Set store filter to collection - * - * @param array $setStoreIds - * @return Mage_Reports_Model_Mysql4_Customer_Orders_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); - $this->addSumAvgTotals(1) - ->orderByOrdersCount(); - } else { - $this->addSumAvgTotals() - ->orderByOrdersCount(); - } - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Totals/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Totals/Collection.php index a2b7a92a33..f51372e0ea 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Customer/Totals/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Customer/Totals/Collection.php @@ -20,52 +20,19 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Customers by totals Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Customer_Totals_Collection extends Mage_Reports_Model_Mysql4_Order_Collection +class Mage_Reports_Model_Mysql4_Customer_Totals_Collection + extends Mage_Reports_Model_Resource_Customer_Totals_Collection { - protected function _joinFields($from = '', $to = '') - { - $this->joinCustomerName() - ->groupByCustomer() - ->addOrdersCount() - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)); - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->_joinFields($from, $to); - return $this; - } - - /** - * Set store filter collection - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Customer_Totals_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); - $this->addSumAvgTotals(1) - ->orderByTotalAmount(); - } else { - $this->addSumAvgTotals() - ->orderByTotalAmount(); - } - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Entity/Summary/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Mysql4/Entity/Summary/Collection/Abstract.php index 167f2d191a..86b678faff 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Entity/Summary/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Entity/Summary/Collection/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,104 +28,11 @@ /** * Reports summary collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Entity_Summary_Collection_Abstract extends Varien_Data_Collection +class Mage_Reports_Model_Mysql4_Entity_Summary_Collection_Abstract + extends Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract { - /** - * Entity collection for summaries - * - * @var Mage_Entity_Model_Entity_Collection_Abstract - */ - protected $_entityCollection; - - /** - * Loads and calculates summaries - * - * @param boolean $printQuery - * @param boolean $logQuery - * @return Varien_Data_Collection - */ - /*public function load($printQuery=false, $logQuery=false) - { - return $this; - }*/ - - /** - * Filters the summaries by some period - * - * @param string $periodType - * @param string|int|null $customStart - * @param string|int|null $customEnd - * @return Varien_Data_Collection - */ - public function setSelectPeriod($periodType, $customStart=null, $customEnd=null) - { - switch ($periodType) { - case "24h": - $customStart = time()-24*60*60; - $customEnd = time(); - break; - - case "7d": - $customStart = time()-7*24*60*60; - $customEnd = time(); - break; - - case "30d": - $customStart = time()-30*24*60*60; - $customEnd = time(); - break; - - case "1y": - $customStart = time()-365*24*60*60; - $customEnd = time(); - break; - - default: - if(is_string($customStart)) { - $customStart = strtotime($customStart); - } - if(is_string($customEnd)) { - $customEnd = strtotime($customEnd); - } - break; - - } - - - return $this; - } - - - public function setDatePeriod($period) - { - - } - - public function setStoreFilter($storeId) - { - return $this; - } - - /** - * Return collection for summaries - * - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function getCollection() - { - if (empty($this->_entityCollection)) { - $this->_initCollection(); - } - return $this->_entityCollection; - } - - protected function _initCollection() - { - return $this; - } - } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Event.php b/app/code/core/Mage/Reports/Model/Mysql4/Event.php index bcd4be4395..5702f02bc5 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Event.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Event.php @@ -20,160 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report events resource model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Event extends Mage_Core_Model_Mysql4_Abstract +class Mage_Reports_Model_Mysql4_Event extends Mage_Reports_Model_Resource_Event { - /** - * Initialize connection - * - */ - protected function _construct() - { - $this->_init('reports/event', 'event_id'); - } - - /** - * Update customer type after customer login - * - * @param Mage_Reports_Model_Event $model - * @param int $visitorId - * @param int $customerId - * @param array $types - * @return Mage_Reports_Model_Mysql4_Event - */ - public function updateCustomerType(Mage_Reports_Model_Event $model, $visitorId, $customerId, $types = array()) - { - if ($types) { - $this->_getWriteAdapter()->update($this->getMainTable(), - array('subject_id' => $customerId, 'subtype' => 0), - array( - $this->_getWriteAdapter()->quoteInto('subject_id=?', $visitorId), - $this->_getWriteAdapter()->quoteInto('subtype=?', 1), - $this->_getWriteAdapter()->quoteInto('event_type_id IN(?)', $types) - ) - ); - } - return $this; - } - - /** - * Add events log to a collection - * The collection id field is used without corellation, so it must be unique. - * DESC ordering by event will be added to the collection - * - * @param Varien_Data_Collection_Db $collection - * @param int $eventTypeId - * @param int $eventSubjectId - * @param int $subtype - * @param array $skipIds - */ - public function applyLogToCollection(Varien_Data_Collection_Db $collection, $eventTypeId, $eventSubjectId, $subtype, $skipIds = array()) - { - $idFieldName = $collection->getResource()->getIdFieldName(); - - $derivedSelect = $this->getReadConnection()->select() - ->from($this->getTable('reports/event'), array('event_id' => new Zend_Db_Expr('MAX(event_id)'), 'object_id')) - ->where('event_type_id=?', (int)$eventTypeId) - ->where('subject_id=?', (int)$eventSubjectId) - ->where('subtype=?', (int)$subtype) - ->where('store_id IN(?)', $this->getCurrentStoreIds()) - ->group('object_id') - ; - if ($skipIds) { - if (!is_array($skipIds)) { - $skipIds = array((int)$skipIds); - } - $derivedSelect->where('object_id NOT IN(?)', $skipIds); - } - - $collection->getSelect() - ->joinInner(array('evt' => new Zend_Db_Expr("({$derivedSelect})")), "`{$idFieldName}`=evt.object_id", array()) - ->order('evt.event_id DESC'); - } - - /** - * Obtain all current store ids, depending on configuration - * - * @param array $predefinedStoreIds - * @return array - */ - public function getCurrentStoreIds(array $predefinedStoreIds = null) - { - $stores = array(); - // get all or specified stores - if (Mage::app()->getStore()->getId() == 0) { - if (null !== $predefinedStoreIds) { - $stores = $predefinedStoreIds; - } - else { - foreach (Mage::app()->getStores() as $store) { - $stores[] = $store->getId(); - } - } - } - // get all stores, required by configuration in current store scope - else { - switch (Mage::getStoreConfig('catalog/recently_products/scope')) { - case 'website': - $resourceStore = Mage::app()->getStore()->getWebsite()->getStores(); - break; - case 'group': - $resourceStore = Mage::app()->getStore()->getGroup()->getStores(); - break; - default: - $resourceStore = array(Mage::app()->getStore()); - break; - } - - foreach ($resourceStore as $store) { - $stores[] = $store->getId(); - } - } - foreach ($stores as $key => $store) { - $stores[$key] = (int)$store; - } - return $stores; - } - - /** - * Clean report event table - * - * @param Mage_Reports_Model_Event $object - * @return Mage_Reports_Model_Mysql4_Event - */ - public function clean(Mage_Reports_Model_Event $object) - { - while (true) { - $select = $this->_getReadAdapter()->select() - ->from(array('event_table' => $this->getMainTable()), array('event_id')) - ->joinLeft( - array('visitor_table' => $this->getTable('log/visitor')), - 'event_table.subject_id = visitor_table.visitor_id', - array()) - ->where('visitor_table.visitor_id IS NULL') - ->where('event_table.subtype=?', 1) - ->limit(1000); - $eventIds = $this->_getReadAdapter()->fetchCol($select); - - if (!$eventIds) { - break; - } - - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto('event_id IN(?)', $eventIds) - ); - } - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Event/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Event/Collection.php index f308fda973..3098303d6f 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Event/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Event/Collection.php @@ -20,72 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report event collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Event_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Reports_Model_Mysql4_Event_Collection extends Mage_Reports_Model_Resource_Event_Collection { - /** - * Store Ids - * - * @var array - */ - protected $_storeIds; - - protected function _construct() - { - $this->_init('reports/event'); - } - - /** - * Add store ids filter - * - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Event_Collection - */ - public function addStoreFilter(array $storeIds) - { - $this->_storeIds = $storeIds; - return $this; - } - - /** - * Add recently filter - * - * @param int $typeId - * @param int $subjectId - * @param int $subtype - * @param int|array $ignore - * @param int $limit - * @return Mage_Reports_Model_Mysql4_Event_Collection - */ - public function addRecentlyFiler($typeId, $subjectId, $subtype = 0, $ignore = null, $limit = 15) - { - $stores = $this->getResource()->getCurrentStoreIds($this->_storeIds); - $this->_select - ->where('event_type_id=?', $typeId) - ->where('subject_id=?', $subjectId) - ->where('subtype=?', $subtype) - ->where('store_id IN(?)', $stores); - if ($ignore) { - if (is_array($ignore)) { - $this->_select->where('object_id NOT IN(?)', $ignore); - } - else { - $this->_select->where('object_id<>?', $ignore); - } - } - $this->_select->group('object_id') - ->limit($limit); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Event/Type.php b/app/code/core/Mage/Reports/Model/Mysql4/Event/Type.php index d3eca23569..b1fa5619d5 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Event/Type.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Event/Type.php @@ -20,22 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report event type resource model * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Event_Type extends Mage_Core_Model_Mysql4_Abstract +class Mage_Reports_Model_Mysql4_Event_Type extends Mage_Reports_Model_Resource_Event_Type { - protected function _construct() - { - $this->_init('reports/event_type', 'event_type_id'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Event/Type/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Event/Type/Collection.php index 5ad7f05819..6c9a3039ba 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Event/Type/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Event/Type/Collection.php @@ -20,27 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report event types collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Event_Type_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Reports_Model_Mysql4_Event_Type_Collection extends Mage_Reports_Model_Resource_Event_Type_Collection { - protected function _construct() - { - $this->_init('reports/event_type'); - } - - public function toOptionArray() - { - return parent::_toOptionArray('event_type_id', 'event_name'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Invoiced/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Invoiced/Collection.php index e94ebd34ae..94a9c5722e 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Invoiced/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Invoiced/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,80 +28,10 @@ /** * Reports invoiced collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Invoiced_Collection extends Mage_Sales_Model_Entity_Order_Collection +class Mage_Reports_Model_Mysql4_Invoiced_Collection extends Mage_Reports_Model_Resource_Invoiced_Collection { - - public function setDateRange($from, $to) - { - $this->_reset() - ->addAttributeToSelect('*') - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) - ->addExpressionAttributeToSelect('orders', - 'COUNT({{base_total_invoiced}})', - array('base_total_invoiced')) - ->addExpressionAttributeToSelect('orders_invoiced', - 'SUM(IF({{base_total_invoiced}} > 0, 1, 0))', - array('base_total_invoiced')) - ->addAttributeToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)) - ->getSelect()->group('("*")')->having('orders > 0'); - - return $this; - } - - /** - * Set store filter collection - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Invoiced_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)) - ->addExpressionAttributeToSelect( - 'invoiced', - 'SUM({{base_total_invoiced}})', - array('base_total_invoiced')) - ->addExpressionAttributeToSelect( - 'invoiced_captured', - 'SUM({{base_total_paid}})', - array('base_total_paid')) - ->addExpressionAttributeToSelect( - 'invoiced_not_captured', - 'SUM({{base_total_invoiced}}-{{base_total_paid}})', - array('base_total_invoiced', 'base_total_paid')); - } else { - $this->addExpressionAttributeToSelect( - 'invoiced', - 'SUM({{base_total_invoiced}}*{{base_to_global_rate}})', - array('base_total_invoiced', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'invoiced_captured', - 'SUM({{base_total_paid}}*{{base_to_global_rate}})', - array('base_total_paid', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'invoiced_not_captured', - 'SUM(({{base_total_invoiced}}-{{base_total_paid}})*{{base_to_global_rate}})', - array('base_total_invoiced', 'base_to_global_rate', 'base_total_paid')); - } - - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(*)"); - $sql = $countSelect->__toString(); - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Order/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Order/Collection.php index e305b2a272..c2c115908f 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Order/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,610 +28,10 @@ /** * Reports orders collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Order_Collection extends Mage_Sales_Model_Mysql4_Order_Collection +class Mage_Reports_Model_Mysql4_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection { - protected $_isLive = false; - - /** - * Check range for live mode - * - * @param $range - * @return boolean - */ - public function checkIsLive($range) - { - $this->_isLive = !Mage::getStoreConfig('sales/dashboard/use_aggregated_data'); - return $this; - } - - /** - * Retrieve is live flag for rep - * - * @return boolean - */ - public function isLive() - { - return $this->_isLive; - } - - /** - * Prepare report summary - * - * @param string $range - * @param mixed $customStart - * @param mixed $customEnd - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function prepareSummary($range, $customStart, $customEnd, $isFilter=0) - { - $this->checkIsLive($range); - if ($this->_isLive) { - $this->_prepareSummaryLive($range, $customStart, $customEnd, $isFilter); - } else { - $this->_prepareSummaryAggregated($range, $customStart, $customEnd, $isFilter); - } - - return $this; - } - - /** - * Prepare report summary from live data - * - * @param string $range - * @param mixed $customStart - * @param mixed $customEnd - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilter=0) - { - $this->setMainTable('sales/order'); - if ($isFilter==0) { - $this->getSelect()->columns(array( - 'revenue' => 'SUM(main_table.base_grand_total*main_table.base_to_global_rate)' - )); - } else{ - $this->getSelect()->columns(array( - 'revenue' => 'SUM(main_table.base_grand_total)' - )); - } - - $this->getSelect()->columns(array( - 'quantity' => 'COUNT(main_table.entity_id)', - 'range' => $this->_getRangeExpressionForAttribute($range, 'created_at'), - ))->order('range', 'asc') - ->group('range'); - - $this->addFieldToFilter('created_at', $this->getDateRange($range, $customStart, $customEnd)) - ->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); - return $this; - } - - /** - * Prepare report summary from aggregated data - * - * @param string $range - * @param mixed $customStart - * @param mixed $customEnd - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - protected function _prepareSummaryAggregated($range, $customStart, $customEnd) - { - $this->setMainTable('sales/order_aggregated_created'); - $this->getSelect()->columns(array( - 'revenue' => 'SUM(main_table.total_revenue_amount)', - 'quantity' => 'SUM(main_table.orders_count)', - 'range' => $this->_getRangeExpressionForAttribute($range, 'main_table.period'), - ))->order('range', 'asc') - ->group('range'); - - $this->getSelect()->where( - $this->_getConditionSql('main_table.period', $this->getDateRange($range, $customStart, $customEnd)) - ); - - $statuses = Mage::getSingleton('sales/config') - ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); - - if (empty($statuses)) { - $statuses = array(0); - } - - $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses); - return $this; - } - - protected function _getRangeExpression($range) - { - // dont need of this offset bc we are format date in block - //$timeZoneOffset = Mage::getModel('core/date')->getGmtOffset(); - - switch ($range) - { - case '24h': - $expression = 'DATE_FORMAT({{attribute}}, \'%Y-%m-%d %H:00\')'; - - break; - case '7d': - case '1m': - $expression = 'DATE_FORMAT({{attribute}}, \'%Y-%m-%d\')'; - break; - case '1y': - case '2y': - case 'custom': - default: - $expression = 'DATE_FORMAT({{attribute}}, \'%Y-%m\')'; - break; - } - - return $expression; - } - - /** - * Retriev range exression adapteted for attribute - * - * @param string $range - * @param unknown_type $attribute - */ - protected function _getRangeExpressionForAttribute($range, $attribute) - { - $expression = $this->_getRangeExpression($range); - return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), $expression); - } - - public function getDateRange($range, $customStart, $customEnd, $returnObjects = false) - { - $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); - $dateStart = clone $dateEnd; - - // go to the end of a day - $dateEnd->setHour(23); - $dateEnd->setMinute(59); - $dateEnd->setSecond(59); - - $dateStart->setHour(0); - $dateStart->setMinute(0); - $dateStart->setSecond(0); - - switch ($range) - { - case '24h': - $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); - $dateEnd->addHour(1); - $dateStart = clone $dateEnd; - $dateStart->subDay(1); - break; - - case '7d': - // substract 6 days we need to include - // only today and not hte last one from range - $dateStart->subDay(6); - break; - - case '1m': - $dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start')); - break; - - case 'custom': - $dateStart = $customStart ? $customStart : $dateEnd; - $dateEnd = $customEnd ? $customEnd : $dateEnd; - break; - - case '1y': - case '2y': - $startMonthDay = explode(',', Mage::getStoreConfig('reports/dashboard/ytd_start')); - $startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1; - $startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1; - $dateStart->setMonth($startMonth); - $dateStart->setDay($startDay); - if ($range == '2y') { - $dateStart->subYear(1); - } - break; - } - - if ($returnObjects) { - return array($dateStart, $dateEnd); - } else { - return array('from'=>$dateStart, 'to'=>$dateEnd, 'datetime'=>true); - } - } - - public function addItemCountExpr() - { -// $orderItemEntityTypeId = Mage::getResourceSingleton('sales/order_item')->getTypeId(); -// $this->getSelect()->join( -// array('items'=>Mage::getResourceSingleton('sales/order_item')->getEntityTable()), -// 'items.parent_id=e.entity_id and items.entity_type_id='.$orderItemEntityTypeId, -// array('items_count'=>new Zend_Db_Expr('COUNT(items.entity_id)')) -// ) -// ->group('e.entity_id'); - $this->getSelect()->columns(array('items_count'=>'total_item_count'), 'main_table'); - return $this; - } - - /** - * Calculate totals report - * - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function calculateTotals($isFilter = 0) - { - if ($this->isLive()) { - $this->_calculateTotalsLive($isFilter); - } else { - $this->_calculateTotalsAggregated($isFilter); - } - - return $this; - } - - /** - * Calculate totals live report - * - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - protected function _calculateTotalsLive($isFilter = 0) - { - $this->setMainTable('sales/order'); - $this->removeAllFieldsFromSelect(); - - if ($isFilter == 0) { - $this->getSelect()->columns(array( - 'revenue' => 'SUM((main_table.base_subtotal-IFNULL(main_table.base_subtotal_refunded,0)-IFNULL(main_table.base_subtotal_canceled,0)-ABS(IFNULL(main_table.base_discount_amount,0))+IFNULL(main_table.base_discount_refunded,0))*main_table.base_to_global_rate)', - 'tax' => 'SUM((main_table.base_tax_amount-IFNULL(main_table.base_tax_refunded,0)-IFNULL(main_table.base_tax_canceled,0))*main_table.base_to_global_rate)', - 'shipping' => 'SUM((main_table.base_shipping_amount-IFNULL(main_table.base_shipping_refunded,0)-IFNULL(main_table.base_shipping_canceled,0))*main_table.base_to_global_rate)', - )); - } else { - $this->getSelect()->columns(array( - 'revenue' => 'SUM((main_table.base_subtotal-IFNULL(main_table.base_subtotal_refunded,0)-IFNULL(main_table.base_subtotal_canceled,0)-ABS(IFNULL(main_table.base_discount_amount,0))+IFNULL(main_table.base_discount_refunded,0)))', - 'tax' => 'SUM((main_table.base_tax_amount-IFNULL(main_table.base_tax_refunded,0)-IFNULL(main_table.base_tax_canceled,0)))', - 'shipping' => 'SUM((main_table.base_shipping_amount-IFNULL(main_table.base_shipping_refunded,0)-IFNULL(main_table.base_shipping_canceled,0)))', - )); - } - - $this->getSelect()->columns(array( - 'quantity' => 'COUNT(main_table.entity_id)', - )); - - $this->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); - - return $this; - } - - /** - * Calculate totals agregated report - * - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - protected function _calculateTotalsAggregated($isFilter = 0) - { - $this->setMainTable('sales/order_aggregated_created'); - $this->removeAllFieldsFromSelect(); - - $this->getSelect()->columns(array( - 'revenue' => 'SUM(main_table.total_revenue_amount)', - 'tax' => 'SUM(main_table.total_tax_amount_actual)', - 'shipping' => 'SUM(main_table.total_shipping_amount_actual)', - 'quantity' => 'SUM(orders_count)', - )); - - $statuses = Mage::getSingleton('sales/config') - ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); - - if (empty($statuses)) { - $statuses = array(0); - } - - $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses); - - return $this; - } - - /** - * Calculate lifitime sales - * - * @param int $isFilter - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function calculateSales($isFilter = 0) - { - $statuses = Mage::getSingleton('sales/config') - ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); - - if (empty($statuses)) { - $statuses = array(0); - } - - if (Mage::getStoreConfig('sales/dashboard/use_aggregated_data')) { - $this->setMainTable('sales/order_aggregated_created'); - $this->removeAllFieldsFromSelect(); - - $this->getSelect()->columns(array( - 'lifetime' => 'SUM(main_table.total_revenue_amount)', - 'average' => "IF(SUM(main_table.orders_count) > 0, SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count), 0)" - )); - - if (!$isFilter) { - $this->addFieldToFilter('store_id', - array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId()) - ); - } - $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses); - } else { - $this->setMainTable('sales/order'); - $this->removeAllFieldsFromSelect(); - $expr = 'IFNULL(main_table.base_subtotal, 0) - IFNULL(main_table.base_subtotal_refunded, 0)' - . ' - IFNULL(main_table.base_subtotal_canceled, 0) - ABS(IFNULL(main_table.base_discount_amount, 0))' - . ' + IFNULL(main_table.base_discount_refunded, 0)'; - - $this->getSelect()->columns(array( - 'lifetime' => "SUM({$expr})", - 'average' => "AVG({$expr})" - )); - $this->getSelect()->where('main_table.status NOT IN(?)', $statuses) - ->where('main_table.state NOT IN(?)', array(Mage_Sales_Model_Order::STATE_NEW, Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)); - } - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->addFieldToFilter('created_at', array('from' => $from, 'to' => $to)) - ->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)) - ->getSelect() - ->columns(array('orders'=>'COUNT(DISTINCT(main_table.entity_id))')) - ->group('("*")'); - - /** - * getting qty count for each order - */ - -// $orderItem = Mage::getResourceSingleton('sales/order_item'); -// /* @var $orderItem Mage_Sales_Model_Entity_Quote */ -// $attr = $orderItem->getAttribute('parent_id'); -// /* @var $attr Mage_Eav_Model_Entity_Attribute_Abstract */ -// $attrId = $attr->getAttributeId(); -// $tableName = $attr->getBackend()->getTable(); -// -// $this->getSelect() -// ->joinLeft(array("order_items" => $tableName), -// "order_items.parent_id = e.entity_id and order_items.entity_type_id=".$orderItem->getTypeId(), array()); -// -// $attr = $orderItem->getAttribute('qty_ordered'); -// /* @var $attr Mage_Eav_Model_Entity_Attribute_Abstract */ -// $attrId = $attr->getAttributeId(); -// $tableName = $attr->getBackend()->getTable(); -// $fieldName = $attr->getBackend()->isStatic() ? 'qty_ordered' : 'value'; -// -// $this->getSelect() -// ->joinLeft(array("order_items2" => $tableName), -// "order_items2.entity_id = `order_items`.entity_id and order_items2.attribute_id = {$attrId}", array()) -// ->columns(array("items" => "sum(order_items2.{$fieldName})")); - - $this->getSelect()->columns(array("items" => 'SUM(' . $this->getConnection()->quoteIdentifier('main_table.total_qty_ordered') . ')')); - - return $this; - } - - /** - * Set store filter collection - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->getSelect()->columns(array( - 'subtotal' => 'SUM(main_table.base_subtotal)', - 'tax' => 'SUM(main_table.base_tax_amount)', - 'shipping' => 'SUM(main_table.base_shipping_amount)', - 'discount' => 'SUM(main_table.base_discount_amount)', - 'total' => 'SUM(main_table.base_grand_total)', - 'invoiced' => 'SUM(main_table.base_total_paid)', - 'refunded' => 'SUM(main_table.base_total_refunded)', - 'profit' => 'SUM(IFNULL(main_table.base_subtotal_invoiced, 0)) + SUM(IFNULL(main_table.base_discount_refunded, 0)) - SUM(IFNULL(main_table.base_subtotal_refunded, 0)) - SUM(IFNULL(main_table.base_discount_invoiced, 0)) - SUM(IFNULL(main_table.base_total_invoiced_cost, 0))', - )); - } else { - $this->getSelect()->columns(array( - 'subtotal' => 'SUM(main_table.base_subtotal * main_table.base_to_global_rate)', - 'tax' => 'SUM(main_table.base_tax_amount * main_table.base_to_global_rate)', - 'shipping' => 'SUM(main_table.base_shipping_amount * main_table.base_to_global_rate)', - 'discount' => 'SUM(main_table.base_discount_amount * main_table.base_to_global_rate)', - 'total' => 'SUM(main_table.base_grand_total * main_table.base_to_global_rate)', - 'invoiced' => 'SUM(main_table.base_total_paid * main_table.base_to_global_rate)', - 'refunded' => 'SUM(main_table.base_total_refunded * main_table.base_to_global_rate)', - 'profit' => 'SUM(IFNULL(main_table.base_subtotal_invoiced, 0)* main_table.base_to_global_rate) + SUM(IFNULL(main_table.base_discount_refunded, 0)* main_table.base_to_global_rate) - SUM(IFNULL(main_table.base_subtotal_refunded, 0)* main_table.base_to_global_rate) - SUM(IFNULL(main_table.base_discount_invoiced, 0)* main_table.base_to_global_rate) - SUM(IFNULL(main_table.base_total_invoiced_cost, 0)* main_table.base_to_global_rate)', - )); - } - - return $this; - } - - /** - * Add group By customer attribute - * - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function groupByCustomer() - { - $this->getSelect()->group('main_table.customer_id'); - - return $this; - } - - /** - * Join Customer Name (concat) - * - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function joinCustomerName($alias = 'name') - { - $this->getSelect()->columns(array($alias => 'CONCAT(main_table.customer_firstname," ", main_table.customer_lastname)')); - return $this; - } - - /** - * Add Order count field to select - * - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function addOrdersCount() - { - $this->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); - $this->getSelect() - ->columns(array("orders_count" => "COUNT(main_table.entity_id)")); - - return $this; - } - - /** - * Add revenue - * - * @param boolean $convertCurrency - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function addRevenueToSelect($convertCurrency = false) - { - if ($convertCurrency) { - $this->getSelect()->columns(array( - 'revenue' => '(main_table.base_grand_total * main_table.base_to_global_rate)' - )); - } else { - $this->getSelect()->columns(array( - 'revenue' => 'base_grand_total' - )); - } - - return $this; - } - - /** - * Add summary average totals - * - * @param int $storeId - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function addSumAvgTotals($storeId = 0) - { - /** - * calculate average and total amount - */ - $expr = ($storeId == 0) - ? '(main_table.base_subtotal - - IFNULL(main_table.base_subtotal_refunded, 0) - - IFNULL(main_table.base_subtotal_canceled, 0) - - ABS(main_table.base_discount_amount) - - IFNULL(main_table.base_discount_canceled, 0) - ) * main_table.base_to_global_rate' - : 'main_table.base_subtotal - - IFNULL(main_table.base_subtotal_canceled, 0) - - IFNULL(main_table.base_subtotal_refunded, 0) - - ABS(main_table.base_discount_amount) - - IFNULL(main_table.base_discount_canceled, 0)'; - - $this->getSelect() - ->columns(array("orders_avg_amount" => "AVG({$expr})")) - ->columns(array("orders_sum_amount" => "SUM({$expr})")); - - return $this; - } - - /** - * Sort order by total amount - * - * @param string $dir - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function orderByTotalAmount($dir = 'desc') - { - $this->getSelect() - ->order("orders_sum_amount {$dir}"); - return $this; - } - - public function orderByOrdersCount($dir = 'desc') - { - $this->getSelect() - ->order("orders_count {$dir}"); - return $this; - } - - public function orderByCustomerRegistration($dir = 'desc') - { - $this->setOrder('customer_id', $dir); - return $this; - } - - /** - * Sort order by order created_at date - * @param string $dir - */ - public function orderByCreatedAt($dir = 'desc') - { - $this->setOrder('created_at', $dir); - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(DISTINCT main_table.entity_id)"); - - $sql = $countSelect->__toString(); - - return $sql; - } - - /** - * Initialize initial fields to select - * - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - protected function _initInitialFieldsToSelect() - { - // No fields should be initialized - return $this; - } - - /** - * Add period filter by created_at attribute - * - * @param string $period - * @return Mage_Reports_Model_Mysql4_Order_Collection - */ - public function addCreateAtPeriodFilter($period) - { - list($from, $to) = $this->getDateRange($period, 0, 0, true); - - $this->checkIsLive($period); - - if ($this->isLive()) { - $fieldToFilter = 'created_at'; - } else { - $fieldToFilter = 'period'; - } - - $this->addFieldToFilter($fieldToFilter, array( - 'from' => $from->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), - 'to' => $to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT) - )); - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php index c3b961798e..146ecc62ba 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Collection.php @@ -20,300 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Products Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Collection extends Mage_Reports_Model_Resource_Product_Collection { - const SELECT_COUNT_SQL_TYPE_CART = 1; - - protected $_productEntityId; - protected $_productEntityTableName; - protected $_productEntityTypeId; - protected $_selectCountSqlType = 0; - - /** - * Set Type for COUNT SQL Select - * - * @param int $type - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function setSelectCountSqlType($type) - { - $this->_selectCountSqlType = $type; - return $this; - } - - public function setProductEntityId($value) - { - $this->_productEntityId = $value; - return $this; - } - - public function getProductEntityId() - { - return $this->_productEntityId; - } - - public function setProductEntityTableName($value) - { - $this->_productEntityTableName = $value; - return $this; - } - - public function getProductEntityTableName() - { - return $this->_productEntityTableName; - } - - public function setProductEntityTypeId($value) - { - $this->_productEntityTypeId = $value; - return $this; - } - - public function getProductEntityTypeId() - { - return $this->_productEntityTypeId; - } - - public function __construct() - { - $product = Mage::getResourceSingleton('catalog/product'); - /* @var $product Mage_Catalog_Model_Entity_Product */ - $this->setProductEntityId($product->getEntityIdField()); - $this->setProductEntityTableName($product->getEntityTable()); - $this->setProductEntityTypeId($product->getTypeId()); - - parent::__construct(); - } - - protected function _joinFields() - { - $this->_totals = new Varien_Object(); - - $this->addAttributeToSelect('entity_id') - ->addAttributeToSelect('name') - ->addAttributeToSelect('price'); - /*$this->getSelect()->columns(array( - 'viewed' => 'CONCAT("","")', - 'added' => 'CONCAT("","")', - 'purchased' => 'CONCAT("","")', - 'fulfilled' => 'CONCAT("","")', - 'revenue' => 'CONCAT("","")', - ));*/ - } - - public function getSelectCountSql() - { - if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) { - $countSelect = clone $this->getSelect(); - $countSelect->reset() - ->from( - array('quote_item_table' => $this->getTable('sales/quote_item')), - 'COUNT(DISTINCT quote_item_table.product_id)' - ) - ->join( - array('quote_table' => $this->getTable('sales/quote')), - 'quote_table.entity_id = quote_item_table.quote_id AND quote_table.is_active = 1', - array() - ); - return $countSelect->__toString(); - } - - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(DISTINCT e.entity_id)"); - $sql = $countSelect->__toString(); - return $sql; - } - - public function addCartsCount() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(); - - $countSelect->from(array("quote_items" => $this->getTable('sales/quote_item')), "count(*)") - ->join(array('quotes' => $this->getTable('sales/quote')), - 'quotes.entity_id = quote_items.quote_id AND quotes.is_active = 1', - array()) - ->where("quote_items.product_id = e.entity_id"); - - $this->getSelect() - ->columns(array("carts" => "({$countSelect})")) - ->group("e.{$this->getProductEntityId()}") - ->having('carts > 0'); - - return $this; - } - - public function addOrdersCount($from = '', $to = '') - { - $this->getSelect() - ->joinLeft(array("order_items" => $this->getTable('sales/order_item')), - "order_items.product_id = e.{$this->getProductEntityId()}", array()) - ->columns(array("orders" => "count(`order_items2`.item_id)")) - ->group("e.{$this->getProductEntityId()}"); - - if ($from != '' && $to != '') { - $dateFilter = " and order_items2.created_at BETWEEN '{$from}' AND '{$to}'"; - } else { - $dateFilter = ''; - } - - $this->getSelect() - ->joinLeft(array("order_items2" => $this->getTable('sales/order_item')), - "order_items2.item_id = order_items.item_id".$dateFilter, array()); - - return $this; - } - - public function addOrderedQty($from = '', $to = '') - { - $qtyOrderedTableName = $this->getTable('sales/order_item'); - $qtyOrderedFieldName = 'qty_ordered'; - - $productIdFieldName = 'product_id'; - - $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes(); - $productTypes = $this->getConnection()->quoteInto(' AND (e.type_id NOT IN (?))', $compositeTypeIds); - - if ($from != '' && $to != '') { - $dateFilter = " AND `order`.created_at BETWEEN '{$from}' AND '{$to}'"; - } else { - $dateFilter = ""; - } - - $this->getSelect()->reset()->from( - array('order_items' => $qtyOrderedTableName), - array( - 'ordered_qty' => "SUM(order_items.{$qtyOrderedFieldName})", - 'order_items_name' => 'order_items.name' - ) - ); - - $_joinCondition = $this->getConnection()->quoteInto( - 'order.entity_id = order_items.order_id AND order.state<>?', Mage_Sales_Model_Order::STATE_CANCELED - ); - $_joinCondition .= $dateFilter; - $this->getSelect()->joinInner( - array('order' => $this->getTable('sales/order')), - $_joinCondition, - array() - ); - - - $this->getSelect() - ->joinLeft(array('e' => $this->getProductEntityTableName()), - "e.entity_id = order_items.{$productIdFieldName} - AND e.entity_type_id = {$this->getProductEntityTypeId()}{$productTypes}", - array( - 'entity_id' => 'order_items.product_id', - 'entity_type_id' => 'e.entity_type_id', - 'attribute_set_id' => 'e.attribute_set_id', - 'type_id' => 'e.type_id', - 'sku' => 'e.sku', - 'has_options' => 'e.has_options', - 'required_options' => 'e.required_options', - 'created_at' => 'e.created_at', - 'updated_at' => 'e.updated_at' - ) - ) - ->group('order_items.product_id') - ->having('ordered_qty > 0'); - - return $this; - } - - public function setOrder($attribute, $dir='desc') - { - switch ($attribute) - { - case 'carts': - case 'orders': - case 'ordered_qty': - $this->getSelect()->order($attribute . ' ' . $dir); - break; - default: - parent::setOrder($attribute, $dir); - } - - return $this; - } - - public function addViewsCount($from = '', $to = '') - { - /** - * Getting event type id for catalog_product_view event - */ - foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) { - if ($eventType->getEventName() == 'catalog_product_view') { - $productViewEvent = $eventType->getId(); - break; - } - } - - $this->getSelect()->reset() - ->from( - array('_table_views' => $this->getTable('reports/event')), - array('views' => 'COUNT(_table_views.event_id)')) - ->join(array('e' => $this->getProductEntityTableName()), - "e.entity_id = _table_views.object_id AND e.entity_type_id = {$this->getProductEntityTypeId()}") - ->where('_table_views.event_type_id = ?', $productViewEvent) - ->group('e.entity_id') - ->order('views desc') - ->having('views > 0'); - - if ($from != '' && $to != '') { - $this->getSelect() - ->where('logged_at >= ?', $from) - ->where('logged_at <= ?', $to); - } - - return $this; - } - - /** - * Add store restrictions to product collection - * - * @param array $storeIds - * @param array $websiteIds - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function addStoreRestrictions($storeIds, $websiteIds) - { - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - if (!is_array($websiteIds)) { - $websiteIds = array($websiteIds); - } - - $filters = $this->_productLimitationFilters; - if ($filters['store_id']) { - if (!in_array($filters['store_id'], $storeIds)) { - $this->addStoreFilter($filters['store_id']); - } else { - $this->addStoreFilter($this->getStoreId()); - } - } else { - $this->addWebsiteFilter($websiteIds); - } - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Downloads/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Downloads/Collection.php index 294b75062a..c6813e80ee 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Downloads/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Downloads/Collection.php @@ -20,82 +20,19 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Product Downloads Report collection * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Product_Downloads_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Downloads_Collection + extends Mage_Reports_Model_Resource_Product_Downloads_Collection { - protected $_idFieldName = 'link_id'; - - /** - * Add downloads summary grouping by product - * - * @return Mage_Reports_Model_Mysql4_Product_Downloads_Collection - */ - public function addSummary() - { - $this->getSelect() - ->joinInner( - array('d' => $this->getTable('downloadable/link_purchased_item')), - 'e.entity_id=d.product_id', - array( - 'purchases' => new Zend_Db_Expr('SUM(d.number_of_downloads_bought)'), - 'downloads' => new Zend_Db_Expr('SUM(d.number_of_downloads_used)') - ) - ) - ->joinInner( - array('l' => $this->getTable('downloadable/link_title')), - 'd.link_id=l.link_id', - array('l.link_id') - ) - ->joinLeft( - array('l_store' => $this->getTable('downloadable/link_title')), - $this->getConnection()->quoteInto('l.link_id=l_store.link_id AND l_store.store_id=?',$this->getStoreId()), - array('link_title' => 'IFNULL(l_store.title, l.title)') - ) - ->where('d.number_of_downloads_bought>0 OR d.number_of_downloads_used>0') - ->group('d.link_id'); - - return $this; - } - - /** - * Add sorting - * - * @return Mage_Reports_Model_Mysql4_Product_Downloads_Collection - */ - public function setOrder($attribute, $dir='desc') - { - if ($attribute == 'purchases' || $attribute == 'downloads' || $attribute == 'link_title') { - $this->getSelect()->order($attribute . ' ' . $dir); - } else { - parent::setOrder($attribute, $dir); - } - return $this; - } - - /** - * Add filtering - * - * @return Mage_Reports_Model_Mysql4_Product_Downloads_Collection - */ - public function addFieldToFilter($field, $condition=null) - { - if ($field == 'link_title') { - $conditionSql = $this->_getConditionSql('l.title', $condition); - $this->getSelect()->where($conditionSql); - } else { - parent::addFieldToFilter($field, $condition); - } - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Abstract.php index 044c3e0f4e..c7bd644200 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,158 +28,10 @@ /** * Reports Product Index Abstract Resource Model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -abstract class Mage_Reports_Model_Mysql4_Product_Index_Abstract extends Mage_Core_Model_Mysql4_Abstract +class Mage_Reports_Model_Mysql4_Product_Index_Abstract extends Mage_Reports_Model_Resource_Product_Index_Abstract { - /** - * Fields List for update in forsedSave - * - * @var array - */ - protected $_fieldsForUpdate = array('store_id', 'added_at'); - - /** - * Update Customer from visitor (Customer loggin) - * - * @param Mage_Reports_Model_Product_Index_Abstract $object - * @return Mage_Reports_Model_Mysql4_Product_Index_Abstract - */ - public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstract $object) - { - /** - * Do nothing if customer not logged in - */ - if (!$object->getCustomerId()) { - return $this; - } - - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('visitor_id=?', $object->getVisitorId()); - $rowSet = $select->query()->fetchAll(); - foreach ($rowSet as $row) { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where('customer_id=?', $object->getCustomerId()) - ->where('product_id=?', $row['product_id']); - $idx = $this->_getWriteAdapter()->fetchRow($select); - - if ($idx) { - $this->_getWriteAdapter()->delete($this->getMainTable(), - $this->_getWriteAdapter()->quoteInto('index_id=?', $row['index_id']) - ); - $this->_getWriteAdapter()->update($this->getMainTable(), array( - 'visitor_id' => $object->getVisitorId(), - 'store_id' => $object->getStoreId(), - 'added_at' => now(), - ), $this->_getWriteAdapter()->quoteInto('index_id=?', $idx['index_id'])); - } - else { - $this->_getWriteAdapter()->update($this->getMainTable(), array( - 'customer_id' => $object->getCustomerId(), - 'store_id' => $object->getStoreId(), - 'added_at' => now() - ), $this->_getWriteAdapter()->quoteInto('index_id=?', $row['index_id'])); - } - } - - return $this; - } - - /** - * Purge visitor data by customer (logout) - * - * @param Mage_Reports_Model_Product_Index_Abstract $object - * @return Mage_Reports_Model_Mysql4_Product_Index_Abstract - */ - public function purgeVisitorByCustomer(Mage_Reports_Model_Product_Index_Abstract $object) - { - if (!$object->getCustomerId()) { - return $this; - } - - $where = $this->_getWriteAdapter()->quoteInto('customer_id=?', $object->getCustomerId()); - $bind = array( - 'visitor_id' => null, - ); - - $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); - - return $this; - } - - /** - * Save Product Index data (forsed save) - * - * @param Mage_Reports_Model_Product_Index_Abstract $object - * @return Mage_Reports_Model_Mysql4_Product_Index_Abstract - */ - public function save(Mage_Core_Model_Abstract $object) - { - return $this->forsedSave($object); - } - - /** - * Clean index (visitor) - * - * @return Mage_Reports_Model_Mysql4_Product_Index_Abstract - */ - public function clean() - { - while (true) { - $select = $this->_getReadAdapter()->select() - ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName())) - ->joinLeft( - array('visitor_table' => $this->getTable('log/visitor')), - 'main_table.visitor_id = visitor_table.visitor_id', - array()) - ->where('main_table.visitor_id > 0') - ->where('visitor_table.visitor_id IS NULL') - ->limit(100); - $indexIds = $this->_getReadAdapter()->fetchCol($select); - - if (!$indexIds) { - break; - } - - $this->_getWriteAdapter()->delete( - $this->getMainTable(), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $indexIds) - ); - } - return $this; - } - - /** - * Add information about product ids to visitor/customer - * - * @param $object - * @param $productIds - */ - public function registerIds($object, $productIds) - { - $row = array( - 'visitor_id' => $object->getVisitorId(), - 'customer_id' => $object->getCustomerId(), - 'store_id' => $object->getStoreId(), - ); - $addedAt = new Zend_Date(); - $data = array(); - foreach ($productIds as $productId) { - $productId = (int) $productId; - if ($productId) { - $row['product_id'] = $productId; - $row['added_at'] = $addedAt->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); - $data[] = $row; - } - $addedAt->subSecond(1); - } - if (!empty($data)) { - $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), $data, array_keys($row)); - } - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Collection/Abstract.php index e0db893750..096d056da1 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Collection/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,115 +28,11 @@ /** * Reports Product Index Abstract Product Resource Collection * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -abstract class Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract + extends Mage_Reports_Model_Resource_Product_Index_Collection_Abstract { - /** - * Retrieve Product Index table name - * - * @return string - */ - abstract protected function _getTableName(); - - /** - * Join index table - */ - protected function _joinIdxTable() - { - if (!$this->getFlag('is_idx_table_joined')) { - $this->joinTable( - array('idx_table' => $this->_getTableName()), - 'product_id=entity_id', - array( - 'product_id' => 'product_id', - 'item_store_id' => 'store_id', - 'added_at' => 'added_at' - ), - $this->_getWhereCondition() - ); - $this->setFlag('is_idx_table_joined', true); - } - return $this; - } - - /** - * Add Viewed Products Index to Collection - * - * @return Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract - */ - public function addIndexFilter() - { - $this->_joinIdxTable(); - $this->_productLimitationFilters['store_table'] = 'idx_table'; - $this->setFlag('url_data_object', true); - $this->setFlag('do_not_use_category_id', true); - return $this; - } - - /** - * Add filter by product ids - * @param array $ids - */ - public function addFilterByIds($ids) - { - if (empty($ids)) { - $this->getSelect()->where('0'); - } else { - $this->getSelect()->where('e.entity_id IN(?)', $ids); - } - return $this; - } - - /** - * Retrieve Where Condition to Index table - * - * @return array - */ - protected function _getWhereCondition() - { - $condition = array(); - - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $condition['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId(); - } - else { - $condition['visitor_id'] = Mage::getSingleton('log/visitor')->getId(); - } - - return $condition; - } - - /** - * Add order by "added at" - * - * @param string $dir - * @return Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract - */ - public function setAddedAtOrder($dir = 'desc') - { - if ($this->getFlag('is_idx_table_joined')) { - $this->getSelect()->order('added_at '.$dir); - } - return $this; - } - - /** - * Add exclude Product Ids - * - * @param int|array $productIds - * @return Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract - */ - public function excludeProductIds($productIds) - { - if (empty($productIds)) { - return $this; - } - $this->_joinIdxTable(); - $this->getSelect()->where('idx_table.product_id NOT IN(?)', $productIds); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared.php index c527399cc1..274e46158e 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,18 +28,10 @@ /** * Reports Compared Product Index Resource Model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Index_Compared extends Mage_Reports_Model_Mysql4_Product_Index_Abstract +class Mage_Reports_Model_Mysql4_Product_Index_Compared extends Mage_Reports_Model_Resource_Product_Index_Compared { - /** - * Initialize connection and main resource table - * - */ - protected function _construct() - { - $this->_init('reports/compared_product_index', 'index_id'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared/Collection.php index 93fd653f2d..1f6926bb2e 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Compared/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,19 +28,11 @@ /** * Reports Compared Product Index Resource Collection * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Index_Compared_Collection extends Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract +class Mage_Reports_Model_Mysql4_Product_Index_Compared_Collection + extends Mage_Reports_Model_Resource_Product_Index_Compared_Collection { - /** - * Retrieve Product Index table name - * - * @return string - */ - protected function _getTableName() - { - return $this->getTable('reports/compared_product_index'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed.php index 073e70eb43..4e75191fb3 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,18 +28,10 @@ /** * Reports Viewed Product Index Resource Model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Index_Viewed extends Mage_Reports_Model_Mysql4_Product_Index_Abstract +class Mage_Reports_Model_Mysql4_Product_Index_Viewed extends Mage_Reports_Model_Resource_Product_Index_Viewed { - /** - * Initialize connection and main resource table - * - */ - protected function _construct() - { - $this->_init('reports/viewed_product_index', 'index_id'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed/Collection.php index fc6cc21b53..d036c35421 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Index/Viewed/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,19 +28,11 @@ /** * Reports Viewed Product Index Resource Collection * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Index_Viewed_Collection extends Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract +class Mage_Reports_Model_Mysql4_Product_Index_Viewed_Collection + extends Mage_Reports_Model_Resource_Product_Index_Viewed_Collection { - /** - * Retrieve Product Index table name - * - * @return string - */ - protected function _getTableName() - { - return $this->getTable('reports/viewed_product_index'); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Lowstock/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Lowstock/Collection.php index 27c54501e8..588fba0acd 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Lowstock/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Lowstock/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -29,209 +29,10 @@ * Product Low Stock Report Collection * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Lowstock_Collection extends Mage_Reports_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Lowstock_Collection + extends Mage_Reports_Model_Resource_Product_Lowstock_Collection { - /** - * CatalogInventory Stock Item Resource instance - * - * @var Mage_CatalogInventory_Model_Mysql4_Stock_Item - */ - protected $_inventoryItemResource = null; - - /** - * Flag about is joined CatalogInventory Stock Item - * - * @var bool - */ - protected $_inventoryItemJoined = false; - - /** - * Alias for CatalogInventory Stock Item Table - * - * @var string - */ - protected $_inventoryItemTableAlias = 'lowstock_inventory_item'; - - /** - * Retrieve CatalogInventory Stock Item Resource instance - * - * @return Mage_CatalogInventory_Model_Mysql4_Stock_Item - */ - protected function _getInventoryItemResource() - { - if (is_null($this->_inventoryItemResource)) { - $this->_inventoryItemResource = Mage::getResourceSingleton('cataloginventory/stock_item'); - } - return $this->_inventoryItemResource; - } - - /** - * Retrieve CatalogInventory Stock Item Table - * - * @return string - */ - protected function _getInventoryItemTable() - { - return $this->_getInventoryItemResource()->getMainTable(); - } - - /** - * Retrieve CatalogInventory Stock Item Table Id field name - * - * @return string - */ - protected function _getInventoryItemIdField() - { - return $this->_getInventoryItemResource()->getIdFieldName(); - } - - /** - * Retrieve alias for CatalogInventory Stock Item Table - * - * @return string - */ - protected function _getInventoryItemTableAlias() - { - return $this->_inventoryItemTableAlias; - } - - /** - * Add catalog inventory stock item field to select - * - * @param string $field - * @param string $alias - * @return Mage_Reports_Model_Mysql4_Product_Lowstock_Collection - */ - protected function _addInventoryItemFieldToSelect($field, $alias = null) - { - if (empty($alias)) { - $alias = $field; - } - - if (isset($this->_joinFields[$alias])) { - return $this; - } - - $this->_joinFields[$alias] = array( - 'table' => $this->_getInventoryItemTableAlias(), - 'field' => $field - ); - - $this->getSelect()->columns(array($alias => $field), $this->_getInventoryItemTableAlias()); - return $this; - } - - /** - * Retrieve catalog inventory stock item field correlation name - * - * @param string $field - * @return string - */ - protected function _getInventoryItemField($field) - { - return sprintf('%s.%s', $this->_getInventoryItemTableAlias(), $field); - } - - /** - * Join catalog inventory stock item table for further stock_item values filters - * - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function joinInventoryItem($fields = array()) - { - if (!$this->_inventoryItemJoined) { - $this->getSelect()->join( - array($this->_getInventoryItemTableAlias() => $this->_getInventoryItemTable()), - sprintf('`e`.`%s`=`%s`.`product_id`', - $this->getEntity()->getEntityIdField(), - $this->_getInventoryItemTableAlias() - ), - array() - ); - $this->_inventoryItemJoined = true; - } - - if (!is_array($fields)) { - if (empty($fields)) { - $fields = array(); - } else { - $fields = array($fields); - } - } - - foreach ($fields as $alias => $field) { - if (!is_string($alias)) { - $alias = null; - } - $this->_addInventoryItemFieldToSelect($field, $alias); - } - - return $this; - } - - /** - * Add filter by product type(s) - * - * @param array|string $typeFilter - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function filterByProductType($typeFilter) - { - if (!is_string($typeFilter) && !is_array($typeFilter)) { - Mage::throwException( - Mage::helper('catalog')->__('Wrong product type filter specified') - ); - } - $this->addAttributeToFilter('type_id', $typeFilter); - return $this; - } - - /** - * Add filter by product types from config - * Only types witch has QTY parameter - * - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function filterByIsQtyProductTypes() - { - $this->filterByProductType( - array_keys(array_filter(Mage::helper('cataloginventory')->getIsQtyTypeIds())) - ); - return $this; - } - - /** - * Add Use Manage Stock Condition to collection - * - * @param int|null $storeId - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function useManageStockFilter($storeId = null) - { - $this->joinInventoryItem(); - $this->getSelect()->where(sprintf('IF(%s,%d,%s)=1', - $this->_getInventoryItemField('use_config_manage_stock'), - (int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK,$storeId), - $this->_getInventoryItemIdField('manage_stock'))); - return $this; - } - - /** - * Add Notify Stock Qty Condition to collection - * - * @param int $storeId - * @return Mage_Reports_Model_Mysql4_Product_Collection - */ - public function useNotifyStockQtyFilter($storeId = null) - { - $this->joinInventoryItem(array('qty')); - $this->getSelect()->where(sprintf('qty < IF(%s,%d,%s)', - $this->_getInventoryItemField('use_config_notify_stock_qty'), - (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY,$storeId), - $this->_getInventoryItemField('notify_stock_qty'))); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Ordered/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Ordered/Collection.php index 3966c1d18f..2a6a8cee49 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Ordered/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Ordered/Collection.php @@ -20,38 +20,19 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Products Ordered (Bestsellers) Report collection * - * @deprecated after 1.4.0.1 + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Ordered_Collection extends Mage_Reports_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Ordered_Collection + extends Mage_Reports_Model_Resource_Product_Ordered_Collection { - protected function _joinFields($from = '', $to = '') - { - $this->addAttributeToSelect('*') - ->addOrderedQty($from, $to) - ->setOrder('ordered_qty', 'desc'); - - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->_joinFields($from, $to); - return $this; - } - - public function setStoreIds($storeIds) - { - $storeId = array_pop($storeIds); - $this->setStoreId($storeId); - $this->addStoreFilter($storeId); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Sold/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Sold/Collection.php index 356cec5764..d778acb4a7 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Sold/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Sold/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,64 +28,10 @@ /** * Report Sold Products collection * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Product_Sold_Collection extends Mage_Reports_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Sold_Collection extends Mage_Reports_Model_Resource_Product_Sold_Collection { - /** - * Set Date range to collection - * - * @param int $from - * @param int $to - * @return Mage_Reports_Model_Mysql4_Product_Sold_Collection - */ - public function setDateRange($from, $to) - { - $this->_reset() - ->addAttributeToSelect('*') - ->addOrderedQty($from, $to) - ->setOrder('ordered_qty', 'desc'); - - return $this; - } - - /** - * Set store filter to collection - * - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Product_Sold_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->getSelect()->where('order_items.store_id IN (?)', (array)$storeIds); - } - return $this; - } - - /** - * Add website product limitation - * - * @return Mage_Reports_Model_Mysql4_Product_Sold_Collection - */ - protected function _productLimitationJoinWebsite() - { - $filters = $this->_productLimitationFilters; - $conditions = array( - 'product_website.product_id=e.entity_id' - ); - if (isset($filters['website_ids'])) { - $conditions[] = $this->getConnection() - ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']); - - $subQuery = $this->getConnection()->select() - ->from(array('product_website' => $this->getTable('catalog/product_website')), array('product_website.product_id')) - ->where(join(' AND ', $conditions)); - $this->getSelect()->where('e.entity_id IN( '.$subQuery.' )'); - } - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Product/Viewed/Collection.php index 75acb1af3c..8fa10a375c 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Product/Viewed/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Product/Viewed/Collection.php @@ -20,39 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Products Most Viewed Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Product_Viewed_Collection extends Mage_Reports_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Product_Viewed_Collection extends Mage_Reports_Model_Resource_Product_Viewed_Collection { - protected function _joinFields($from = '', $to = '') - { - $this->addAttributeToSelect('*') - ->addViewsCount($from, $to); - return $this; - } - - public function setDateRange($from, $to) - { - $this->_reset() - ->_joinFields($from, $to); - return $this; - } - - public function setStoreIds($storeIds) - { - $storeId = array_pop($storeIds); - $this->setStoreId($storeId); - $this->addStoreFilter($storeId); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Quote/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Quote/Collection.php index 1cbb5de142..8e2c9f7f90 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Quote/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Quote/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,203 +28,10 @@ /** * Reports quote collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Quote_Collection extends Mage_Sales_Model_Mysql4_Quote_Collection +class Mage_Reports_Model_Mysql4_Quote_Collection extends Mage_Reports_Model_Resource_Quote_Collection { - /** - * Type of total quantity calculation of Products in Carts report - */ - const SELECT_COUNT_SQL_TYPE_CART = 1; - - /** - * Type of total quantity calculation - * @var int - */ - protected $_selectCountSqlType = 0; - - protected $_joinedFields = array(); - - protected $_map = array('fields' => array('store_id' => 'main_table.store_id')); - - /** - * Set type for COUNT SQL select - * - * @param int $type - * @return Mage_Reports_Model_Mysql4_Quote_Collection - */ - public function setSelectCountSqlType($type) - { - $this->_selectCountSqlType = $type; - return $this; - } - - public function prepareForAbandonedReport($storeIds, $filter = null) - { - $this->addFieldToFilter('items_count', array('neq' => '0')) - ->addFieldToFilter('main_table.is_active', '1') - ->addSubtotal($storeIds, $filter) - ->addCustomerData($filter) - ->setOrder('updated_at'); - if (is_array($storeIds)) { - $this->addFieldToFilter('store_id', array('in' => $storeIds)); - } - return $this; - } - - /** - * Prepare select query for products in carts report - * - * @return Mage_Reports_Model_Mysql4_Quote_Collection - */ - public function prepareForProductsInCarts() - { - $productEntity = Mage::getResourceSingleton('catalog/product_collection'); - $productAttrName = $productEntity->getAttribute('name'); - $productAttrNameId = (int) $productAttrName->getAttributeId(); - $productAttrNameTable = $productAttrName->getBackend()->getTable(); - $productAttrPrice = $productEntity->getAttribute('price'); - $productAttrPriceId = (int) $productAttrPrice->getAttributeId(); - $productAttrPriceTable = $productAttrPrice->getBackend()->getTable(); - - $ordersSubSelect = clone $this->getSelect(); - $ordersSubSelect->reset() - ->from(array('order_items' => $this->getTable('sales/order_item')), new Zend_Db_Expr('COUNT(1)')) - ->where('order_items.product_id = e.entity_id'); - - $this->getSelect() - ->useStraightJoin(true) - ->reset(Zend_Db_Select::COLUMNS) - ->joinInner(array('quote_items' => $this->getTable('sales/quote_item')), 'quote_items.quote_id = main_table.entity_id', null) - ->joinInner(array('e' => $this->getTable('catalog/product')), 'e.entity_id = quote_items.product_id', null) - ->joinInner(array('product_name' => $productAttrNameTable), - "product_name.entity_id = e.entity_id and product_name.attribute_id = {$productAttrNameId}", - array('name'=>'product_name.value')) - ->joinInner(array('product_price' => $productAttrPriceTable), - "product_price.entity_id = e.entity_id and product_price.attribute_id = {$productAttrPriceId}", - array('price'=>'product_price.value')) - ->columns('e.*') - ->columns(array('carts' => new Zend_Db_Expr('count(quote_items.item_id)'))) - ->columns("({$ordersSubSelect}) AS orders") - ->where('main_table.is_active = ?', 1) - ->group('quote_items.product_id'); - - return $this; - } - - /** - * Add store ids to filter - * - * @param array $storeIds - * @return Mage_Reports_Model_Mysql4_Quote_Collection - */ - public function addStoreFilter($storeIds) - { - $this->addFieldToFilter('store_id', array('in' => $storeIds)); - return $this; - } - - public function addCustomerData($filter = null) - { - $customerEntity = Mage::getResourceSingleton('customer/customer'); - $attrFirstname = $customerEntity->getAttribute('firstname'); - $attrFirstnameId = (int) $attrFirstname->getAttributeId(); - $attrFirstnameTableName = $attrFirstname->getBackend()->getTable(); - - $attrLastname = $customerEntity->getAttribute('lastname'); - $attrLastnameId = (int) $attrLastname->getAttributeId(); - $attrLastnameTableName = $attrLastname->getBackend()->getTable(); - - $attrEmail = $customerEntity->getAttribute('email'); - $attrEmailTableName = $attrEmail->getBackend()->getTable(); - - $this->getSelect() - ->joinInner( - array('cust_email'=>$attrEmailTableName), - 'cust_email.entity_id=main_table.customer_id', - array('email'=>'cust_email.email') - ) - ->joinInner( - array('cust_fname'=>$attrFirstnameTableName), - 'cust_fname.entity_id=main_table.customer_id and cust_fname.attribute_id=' . $attrFirstnameId, - array('firstname'=>'cust_fname.value') - ) - ->joinInner( - array('cust_lname'=>$attrLastnameTableName), - 'cust_lname.entity_id=main_table.customer_id and cust_lname.attribute_id=' . $attrLastnameId, - array( - 'lastname'=>'cust_lname.value', - 'customer_name' => new Zend_Db_Expr('CONCAT(cust_fname.value, " ", cust_lname.value)') - ) - ); - - $this->_joinedFields['customer_name'] = 'CONCAT(cust_fname.value, " ", cust_lname.value)'; - $this->_joinedFields['email'] = 'cust_email.email'; - - if ($filter) { - if (isset($filter['customer_name'])) { - $this->getSelect()->where( - $this->_joinedFields['customer_name'] . ' LIKE ?', - "%{$filter['customer_name']}%" - ); - } - if (isset($filter['email'])) { - $this->getSelect()->where( - $this->_joinedFields['email'] . ' LIKE ?', - "%{$filter['email']}%" - ); - } - } - - return $this; - } - - public function addSubtotal($storeIds = '', $filter = null) - { - if (is_array($storeIds)) { - $this->getSelect()->columns(array("subtotal" => "(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)")); - $this->_joinedFields['subtotal'] = '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'; - } else { - $this->getSelect()->columns(array("subtotal" => "main_table.base_subtotal_with_discount")); - $this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount'; - } - - if ($filter && is_array($filter) && isset($filter['subtotal'])) { - if (isset($filter['subtotal']['from'])) { - $this->getSelect()->where( - $this->_joinedFields['subtotal'] . ' >= ?', - $filter['subtotal']['from'], Zend_Db::FLOAT_TYPE - ); - } - if (isset($filter['subtotal']['to'])) { - $this->getSelect()->where( - $this->_joinedFields['subtotal'] . ' <= ?', - $filter['subtotal']['to'], Zend_Db::FLOAT_TYPE - ); - } - } - - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - - if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) { - $countSelect->columns("count(DISTINCT e.entity_id)"); - } else { - $countSelect->columns("count(DISTINCT main_table.entity_id)"); - } - $sql = $countSelect->__toString(); - - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Refunded/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Refunded/Collection.php index 1e81e9d2b7..69381ecd83 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Refunded/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Refunded/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,79 +28,10 @@ /** * Reports refunded collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Refunded_Collection extends Mage_Sales_Model_Entity_Order_Collection +class Mage_Reports_Model_Mysql4_Refunded_Collection extends Mage_Reports_Model_Resource_Refunded_Collection { - - public function setDateRange($from, $to) - { - $this->_reset() - ->addAttributeToSelect('*') - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) - ->addExpressionAttributeToSelect('orders', 'COUNT({{total_refunded}})', array('total_refunded')); - - $this->getSelect() - ->where('base_total_refunded>0') - ->group('("*")') - ->having('orders > 0'); - - return $this; - } - - /** - * Set store filter to collection - * - * @param array $setStoreIds - * @return Mage_Reports_Model_Mysql4_Refunded_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)) - ->addExpressionAttributeToSelect( - 'refunded', - 'SUM({{base_total_refunded}})', - array('base_total_refunded')) - ->addExpressionAttributeToSelect( - 'online_refunded', - 'SUM({{base_total_online_refunded}})', - array('base_total_online_refunded')) - ->addExpressionAttributeToSelect( - 'offline_refunded', - 'SUM({{base_total_offline_refunded}})', - array('base_total_offline_refunded')); - } else { - $this->addExpressionAttributeToSelect( - 'refunded', - 'SUM({{base_total_refunded}}*{{base_to_global_rate}})', - array('base_total_refunded', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'online_refunded', - 'SUM({{base_total_online_refunded}}*{{base_to_global_rate}})', - array('base_total_online_refunded', 'base_to_global_rate')) - ->addExpressionAttributeToSelect( - 'offline_refunded', - 'SUM({{base_total_offline_refunded}}*{{base_to_global_rate}})', - array('base_total_offline_refunded', 'base_to_global_rate')); - } - - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(*)"); - $sql = $countSelect->__toString(); - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Report/Abstract.php b/app/code/core/Mage/Reports/Model/Mysql4/Report/Abstract.php index 386a932ca7..c73bd373bf 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Report/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Report/Abstract.php @@ -20,333 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Abstract report aggregate resource model * - * + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ -abstract class Mage_Reports_Model_Mysql4_Report_Abstract extends Mage_Core_Model_Mysql4_Abstract +class Mage_Reports_Model_Mysql4_Report_Abstract extends Mage_Reports_Model_Resource_Report_Abstract { - /** - * Flag object - * - * @var Mage_Reports_Model_Flag - */ - protected $_flag = null; - - /** - * Retrive flag object - * - * @return Mage_Reports_Model_Flag - */ - protected function _getFlag() - { - if ($this->_flag === null) { - $this->_flag = Mage::getModel('reports/flag'); - } - return $this->_flag; - } - - /** - * Saves flag - * - * @param string $code - * @param mixed $value - * @return Mage_Reports_Model_Mysql4_Report_Abstract - */ - protected function _setFlagData($code, $value = null) - { - $this->_getFlag() - ->setReportFlagCode($code) - ->unsetData() - ->loadSelf(); - - if ($value !== null) { - $this->_getFlag()->setFlagData($value); - } - - // touch last_update - $this->_getFlag()->setLastUpdate($this->formatDate(time())); - - $this->_getFlag()->save(); - - return $this; - } - - /** - * Retrieve flag data - * - * @param string $code - * @return mixed - */ - protected function _getFlagData($code) - { - $this->_getFlag() - ->setReportFlagCode($code) - ->unsetData() - ->loadSelf(); - - return $this->_getFlag()->getFlagData(); - } - - /** - * Trancate table - * - * @param string $table - * @return Mage_Reports_Model_Mysql4_Report_Abstract - */ - protected function _truncateTable($table) - { - $this->_getWriteAdapter()->query('TRUNCATE TABLE ' . $this->_getWriteAdapter()->quoteIdentifier($table)); - return $this; - } - - /** - * Clear report table by specified date range. - * If specified source table parameters, - * condition will be generated by source table subselect. - * - * @param string $table - * @param string|null $from - * @param string|null $to - * @param Zend_Db_Select|string|null $subSelect - * @param string|null $sourceWhereColumn - * @param string|null $sourceAdditionalWhere - * @param boolean $doNotUseTrancate - * @return Mage_Reports_Model_Mysql4_Report_Abstract - */ - protected function _clearTableByDateRange($table, $from = null, $to = null, $subSelect = null, $doNotUseTruncate = false) - { - if ($from === null && $to === null && !$doNotUseTruncate) { - $this->_truncateTable($table); - return $this; - } - - if ($subSelect !== null) { - $deleteCondition = $this->_makeConditionFromDateRangeSelect($subSelect, 'period'); - } else { - $condition = array(); - if ($from !== null) { - $dt = new Zend_Date($from); - $dt = $this->formatDate($dt->getDate()); - $condition[] = $this->_getWriteAdapter()->quoteInto('period >= ?', $dt); - } - - if ($to !== null) { - $dt = new Zend_Date($to); - $dt = $this->formatDate($dt->getDate()); - $condition[] = $this->_getWriteAdapter()->quoteInto('period <= ?', $dt); - } - $deleteCondition = implode(' AND ', $condition); - } - - $this->_getWriteAdapter()->delete($table, $deleteCondition); - return $this; - } - - /** - * Generate table date range select - * - * @param string $table - * @param string $column - * @param string $whereColumn - * @param string|null $from - * @param string|null $to - * @param array $additionalWhere - * @return Varien_Db_Select - */ - protected function _getTableDateRangeSelect($table, $column, $whereColumn, $from = null, $to = null, - $additionalWhere = array(), $alias = 'date_range_table') - { - $select = $this->_getWriteAdapter()->select() - ->from( - array($alias => $table), - 'DATE('. $this->_getWriteAdapter()->quoteIdentifier($alias . '.' . $column) . ')' - ) - ->distinct(true); - - if ($from !== null) { - $select->where($alias . '.' . $whereColumn . ' >= ?', $from); - } - - if ($to !== null) { - $select->where($alias . '.' . $whereColumn . ' <= ?', $to); - } - - if (!empty($additionalWhere)) { - foreach ($additionalWhere as $condition) { - if (is_array($condition) && count($condition) == 2) { - $condition = $this->_getWriteAdapter()->quoteInto($condition[0], $condition[1]); - } elseif (is_array($condition)) { // Invalid condition - continue; - } - $condition = str_replace('{{table}}', $this->_getWriteAdapter()->quoteIdentifier($alias), $condition); - $select->where($condition); - } - } - - return $select; - } - - /** - * Make condition for using in where section - * from select statement with single date column - * - * @param string|Zend_Db_Select Query string or instance retrieved from _getTableDateRangeSelect or _getTableDateRangeRelatedSelect - * @param string Name of period column - * @result string|false - */ - protected function _makeConditionFromDateRangeSelect($select, $periodColumn) - { - static $selectResultCache = array(); - $cacheKey = (string)$select; - - if (!array_key_exists($cacheKey, $selectResultCache)) { - try { - $selectResult = array(); - $query = $this->_getReadAdapter()->query($select); - while ($date = $query->fetchColumn()) { - $selectResult[] = $date; - } - } catch (Exception $e) { - $selectResult = false; - } - $selectResultCache[$cacheKey] = $selectResult; - } else { - $selectResult = $selectResultCache[$cacheKey]; - } - - if ($selectResult === false) { - return false; - } - - $whereCondition = array(); - foreach ($selectResult as $date) { - $whereCondition[] = "{$periodColumn} BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'"; - } - $whereCondition = implode(' OR ', $whereCondition); - if ($whereCondition == '') { - $whereCondition = '1<>1'; // FALSE condition! - } - - return $whereCondition; - } - - /** - * Generate table date range select - * - * @param string $table - * @param string $relatedTable - * @param array $joinCondition - * @param string $column - * @param string $whereColumn - * @param string|null $from - * @param string|null $to - * @param array $additionalWhere - * @return Varien_Db_Select - */ - protected function _getTableDateRangeRelatedSelect($table, $relatedTable, $joinCondition, $column, $whereColumn, $from = null, $to = null, - $additionalWhere = array(), $alias = 'date_range_table', $relatedAlias = 'related_date_range_table') - { - $joinConditionSql = ''; - - foreach ($joinCondition as $fkField => $pkField) { - if ($joinConditionSql) { - $joinConditionSql .= ' AND '; - } - - $joinConditionSql .= $this->_getWriteAdapter()->quoteIdentifier($alias . '.' . $fkField) - . ' = ' . $this->_getWriteAdapter()->quoteIdentifier($relatedAlias . '.' . $pkField); - } - - $select = $this->_getWriteAdapter()->select() - ->from( - array($alias => $table), - 'DATE('. $this->_getWriteAdapter()->quoteIdentifier($alias . '.' . $column) . ')' - ) - ->joinInner( - array($relatedAlias => $relatedTable), - $joinConditionSql, - array() - ) - ->distinct(true); - - if ($from !== null) { - $select->where($relatedAlias . '.' . $whereColumn . ' >= ?', $from); - } - - if ($to !== null) { - $select->where($relatedAlias . '.' . $whereColumn . ' <= ?', $to); - } - - if (!empty($additionalWhere)) { - foreach ($additionalWhere as $condition) { - if (is_array($condition) && count($condition) == 2) { - $condition = $this->_getWriteAdapter()->quoteInto($condition[0], $condition[1]); - } elseif (is_array($condition)) { // Invalid condition - continue; - } - $condition = str_replace( - array('{{table}}', '{{related_table}}'), - array( - $this->_getWriteAdapter()->quoteIdentifier($alias), - $this->_getWriteAdapter()->quoteIdentifier($relatedAlias) - ), - $condition - ); - $select->where($condition); - } - } - - return $select; - } - - /** - * Check range dates and transforms it to strings - * - * @param mixed $from - * @param mixed $to - * @return Mage_Reports_Model_Mysql4_Report_Abstract - */ - protected function _checkDates(&$from, &$to) - { - if ($from !== null) { - $from = $this->formatDate($from); - } - - if ($to !== null) { - $to = $this->formatDate($to); - } - - return $this; - } - - /** - * Retrieve store timezone offset from UTC in the form acceptable by SQL's CONVERT_TZ() - * - * @return string - */ - protected function _getStoreTimezoneUtcOffset($store = null) - { - return Mage::app()->getLocale()->storeDate($store)->toString(Zend_Date::GMT_DIFF_SEP); - } - - /** - * Retrieve date in UTC timezone - * - * @return Zend_Date|null - */ - protected function _dateToUtc($date) - { - if ($date === null) { - return null; - } - $dateUtc = new Zend_Date($date); - $dateUtc->setTimezone('Etc/UTC'); - return $dateUtc; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Report/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Report/Collection.php index 502163a6aa..7122da7bc3 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Report/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Report/Collection.php @@ -20,182 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Reviews collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Report_Collection +class Mage_Reports_Model_Mysql4_Report_Collection extends Mage_Reports_Model_Resource_Report_Collection { - - protected $_from; - protected $_to; - protected $_period; - - protected $_model; - - protected $_intervals; - - protected $_pageSize; - - protected $_storeIds; - - protected function _construct() - { - - } - - public function setPeriod($period) - { - $this->_period = $period; - } - - public function setInterval($from, $to) - { - $this->_from = $from; - $this->_to = $to; - } - - public function getIntervals() - { - if (!$this->_intervals) { - $this->_intervals = array(); - if (!$this->_from && !$this->_to){ - return $this->_intervals; - } - $dateStart = new Zend_Date($this->_from); - $dateEnd = new Zend_Date($this->_to); - - - $t = array(); - $firstInterval = true; - while ($dateStart->compare($dateEnd) <= 0) { - - switch ($this->_period) { - case 'day' : - $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat()); - $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss'); - $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59'); - $dateStart->addDay(1); - break; - case 'month': - $t['title'] = $dateStart->toString('MM/yyyy'); - $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') - : $dateStart->toString('yyyy-MM-01 00:00:00'); - - $lastInterval = ($dateStart->compareMonth($dateEnd->getMonth()) == 0); - - $t['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay()) - ->toString('yyyy-MM-dd 23:59:59') - : $dateStart->toString('yyyy-MM-'.date('t', $dateStart->getTimestamp()).' 23:59:59'); - - $dateStart->addMonth(1); - - if ($dateStart->compareMonth($dateEnd->getMonth()) == 0) { - $dateStart->setDay(1); - } - - $firstInterval = false; - break; - case 'year': - $t['title'] = $dateStart->toString('yyyy'); - $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') - : $dateStart->toString('yyyy-01-01 00:00:00'); - - $lastInterval = ($dateStart->compareYear($dateEnd->getYear()) == 0); - - $t['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth()) - ->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') - : $dateStart->toString('yyyy-12-31 23:59:59'); - $dateStart->addYear(1); - - if ($dateStart->compareYear($dateEnd->getYear()) == 0) { - $dateStart->setMonth(1)->setDay(1); - } - - $firstInterval = false; - break; - } - $this->_intervals[$t['title']] = $t; - } - } - return $this->_intervals; - } - - /** - * Return date periods - * - * @return array - */ - - public function getPeriods() - { - return array( - 'day'=>Mage::helper('reports')->__('Day'), - 'month'=>Mage::helper('reports')->__('Month'), - 'year'=>Mage::helper('reports')->__('Year') - ); - } - - public function setStoreIds($storeIds) - { - $this->_storeIds = $storeIds; - } - - public function getStoreIds() - { - return $this->_storeIds; - } - - public function getSize() - { - return count($this->getIntervals()); - } - - public function setPageSize($size) - { - $this->_pageSize = $size; - return $this; - } - - public function getPageSize() - { - return $this->_pageSize; - } - - public function initReport($modelClass) - { - //$this->_modelArray = array(); - //foreach ($this->getIntervals() as $key=>$interval) { - $this->_model = Mage::getModel('reports/report') - ->setPageSize($this->getPageSize()) - ->setStoreIds($this->getStoreIds()) - ->initCollection($modelClass); - //->setPeriodTitle($interval['title']); - //->setStartDate($interval['start']) - //->setEndDate($interval['end']); - //} - } - - public function getReportFull($from, $to) - { - return $this->_model->getReportFull($this->timeShift($from), $this->timeShift($to)); - } - - public function getReport($from, $to) - { - return $this->_model->getReport($this->timeShift($from), $this->timeShift($to)); - } - - public function timeShift($datetime) - { - return Mage::app()->getLocale()->utcDate(null, $datetime, true, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Review/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Review/Collection.php index 23e020d05c..02294f7aa2 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Review/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Review/Collection.php @@ -20,70 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Reviews collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Review_Collection extends Mage_Review_Model_Mysql4_Review_Collection +class Mage_Reports_Model_Mysql4_Review_Collection extends Mage_Reports_Model_Resource_Review_Collection { - protected function _construct() - { - $this->_init('review/review'); - } - - public function addProductFilter($productId) - { - $this->_select - ->where('main_table.entity_pk_value = ?', $productId); - - return $this; - } - - public function resetSelect() - { - parent::resetSelect(); - $this->_joinFields(); - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->_select; - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $sql = $countSelect->__toString(); - - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(main_table.review_id) from ', $sql); - - return $sql; - } - - public function setOrder($attribute, $dir='desc') - { - $fields = array( - 'nickname', - 'title', - 'detail', - 'created_at' - ); - - if (in_array($attribute, $fields)) { - $this->_select->order($attribute . ' ' . $dir); - } else { - parent::setOrder($attribute, $dir); - } - - return $this; - } - } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Review/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Review/Customer/Collection.php index 2b1d73406b..6766d1982a 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Review/Customer/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Review/Customer/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,65 +28,11 @@ /** * Report Customers Review collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Review_Customer_Collection extends Mage_Review_Model_Mysql4_Review_Collection +class Mage_Reports_Model_Mysql4_Review_Customer_Collection + extends Mage_Reports_Model_Resource_Review_Customer_Collection { - public function joinCustomers() - { - $customer = Mage::getResourceSingleton('customer/customer'); - //TODO: add full name logic - $firstnameAttr = $customer->getAttribute('firstname'); - $firstnameAttrId = $firstnameAttr->getAttributeId(); - $firstnameTable = $firstnameAttr->getBackend()->getTable(); - - if ($firstnameAttr->getBackend()->isStatic()) { - $firstnameField = 'firstname'; - $attrCondition = ''; - } else { - $firstnameField = 'value'; - $attrCondition = ' AND _table_customer_firstname.attribute_id = '.$firstnameAttrId; - } - - $this->getSelect()->joinInner(array('_table_customer_firstname' => $firstnameTable), - '_table_customer_firstname.entity_id=detail.customer_id'.$attrCondition, array()); - - $lastnameAttr = $customer->getAttribute('lastname'); - $lastnameAttrId = $lastnameAttr->getAttributeId(); - $lastnameTable = $lastnameAttr->getBackend()->getTable(); - - if ($lastnameAttr->getBackend()->isStatic()) { - $lastnameField = 'lastname'; - $attrCondition = ''; - } else { - $lastnameField = 'value'; - $attrCondition = ' AND _table_customer_lastname.attribute_id = '.$lastnameAttrId; - } - - $this->getSelect()->joinInner(array('_table_customer_lastname' => $lastnameTable), - '_table_customer_lastname.entity_id=detail.customer_id'.$attrCondition, array()) - ->columns(array( - 'customer_name' => "CONCAT(_table_customer_firstname.{$firstnameField}, ' ', _table_customer_lastname.{$lastnameField})", - 'review_cnt' => "COUNT(main_table.review_id)")) - ->group('detail.customer_id'); - - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->_select; - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $sql = $countSelect->__toString(); - - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(DISTINCT `detail`.`customer_id`) from ', $sql); - - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Review/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Review/Product/Collection.php index 64001c727c..2ffe875d64 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Review/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Review/Product/Collection.php @@ -20,52 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Products Review collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Review_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Review_Product_Collection extends Mage_Reports_Model_Resource_Review_Product_Collection { - public function joinReview() - { - $this->addAttributeToSelect('name'); - $this->getSelect()->join( - array('r' => $this->getTable('review/review')), - 'e.entity_id=r.entity_pk_value', - array( - 'review_cnt' => 'COUNT(DISTINCT r.review_id)', - 'last_created' => 'MAX(r.created_at)', - ) - ); - - $this->getSelect()->joinLeft( - array('table_rating' => $this->getTable('rating_option_vote_aggregated')), - 'e.entity_id=table_rating.entity_pk_value AND table_rating.store_id>0', - array( - 'avg_rating' => 'SUM(table_rating.percent)/COUNT(table_rating.rating_id)', - 'avg_rating_approved' => 'SUM(table_rating.percent_approved)/COUNT(table_rating.rating_id)' - ) - ); - $this->getSelect()->group('e.entity_id'); - - return $this; - } - - public function addAttributeToSort($attribute, $dir='asc') - { - if (in_array($attribute, array('review_cnt', 'last_created', 'avg_rating', 'avg_rating_approved'))) { - $this->getSelect()->order($attribute.' '.$dir); - return $this; - } - - return parent::addAttributeToSort($attribute, $dir); - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Shipping/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Shipping/Collection.php index 91f527d0a4..87ec891a9c 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Shipping/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Shipping/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,46 +28,10 @@ /** * Reports orders collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Shipping_Collection extends Mage_Sales_Model_Entity_Order_Collection +class Mage_Reports_Model_Mysql4_Shipping_Collection extends Mage_Reports_Model_Resource_Shipping_Collection { - - public function setDateRange($from, $to) - { - $this->_reset() - ->addAttributeToSelect('*') - ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) - ->addExpressionAttributeToSelect('orders', 'COUNT(DISTINCT({{entity_id}}))', array('entity_id')) - ->addAttributeToSelect('shipping_description') - ->groupByAttribute('shipping_description') - ->getSelect()->order('orders desc'); - - $this->getSelect()->where("`_table_shipping_description`.`value` <> ''"); - return $this; - } - - /** - * Set store filter to collection - * - * @param array $setStoreIds - * @return Mage_Reports_Model_Mysql4_Shipping_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); - $this->addExpressionAttributeToSelect('total', - 'SUM({{base_shipping_amount}})', - array('base_shipping_amount')); - } else { - $this->addExpressionAttributeToSelect('total', - 'SUM({{base_shipping_amount}}*{{base_to_global_rate}})', - array('base_shipping_amount', 'base_to_global_rate')); - } - - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Shopcart/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Shopcart/Product/Collection.php index 298bb36af1..6f02e3d22b 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Shopcart/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Shopcart/Product/Collection.php @@ -20,33 +20,21 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Shopingcart Products Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team * * @deprecated after 1.5.0.1 */ - -class Mage_Reports_Model_Mysql4_Shopcart_Product_Collection extends Mage_Reports_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Shopcart_Product_Collection + extends Mage_Reports_Model_Resource_Shopcart_Product_Collection { - protected function _joinFields() - { - parent::_joinFields(); - $this->addAttributeToSelect('price') - ->addCartsCount() - ->addOrdersCount(); - } - - public function setDateRange($from, $to) - { - $this->resetSelect(); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Collection.php index 536422863e..7d7354a55b 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Collection.php @@ -20,50 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Products Tags collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Tag_Collection extends Mage_Tag_Model_Mysql4_Popular_Collection +class Mage_Reports_Model_Mysql4_Tag_Collection extends Mage_Reports_Model_Resource_Tag_Collection { - - /** - * Add group by tag - * - * @deprecated after 1.4.0.1 - * @return Mage_Reports_Model_Mysql4_Tag_Collection - */ - public function addGroupByTag() - { - return $this; - } - - /** - * Add tag popularity to select by specified store ids - * - * @param int|array $storeIds - * @return Mage_Reports_Model_Mysql4_Tag_Collection - */ - public function addPopularity($storeIds) - { - $select = $this->getSelect() - ->joinLeft( - array('tr'=>$this->getTable('tag/relation')), - 'main_table.tag_id = tr.tag_id', - array( - 'popularity' => 'COUNT(tr.tag_id)' - ) - ); - if (!empty($storeIds)) { - $select->where('tr.store_id IN(?)', $storeIds); - } - $select->group('main_table.tag_id'); - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Customer/Collection.php index c631342b1e..ebc3b7687d 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Customer/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Customer/Collection.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Customers Tags collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Tag_Customer_Collection extends Mage_Tag_Model_Mysql4_Customer_Collection +class Mage_Reports_Model_Mysql4_Tag_Customer_Collection extends Mage_Reports_Model_Resource_Tag_Customer_Collection { - - public function addTagedCount() - { - $this->getSelect() - ->columns(array('taged' => 'count(tr.tag_relation_id)')); - //->order('taged desc'); - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $sql = $countSelect->__toString(); - - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(DISTINCT tr.customer_id) from ', $sql); - - return $sql; - } - - public function setOrder($attribute, $dir='desc') - { - switch( $attribute ) { - case 'taged': - $this->getSelect()->order($attribute . ' ' . $dir); - break; - - default: - parent::setOrder($attribute, $dir); - } - return $this; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Product/Collection.php index 9e913af9cd..7ee00a93b4 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Tag/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Tag/Product/Collection.php @@ -20,94 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report Products Tags collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Tag_Product_Collection extends Mage_Tag_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Tag_Product_Collection extends Mage_Reports_Model_Resource_Tag_Product_Collection { - public function addUniqueTagedCount() - { - $this->getSelect() - ->columns(array('utaged' => 'count(DISTINCT(relation.tag_id))')); - //->order('taged desc'); - return $this; - } - - public function addAllTagedCount() - { - $this->getSelect() - ->columns(array('taged' => 'count(relation.tag_id)')); - //->order('taged desc'); - return $this; - } - - public function addTagedCount() - { - $this->getSelect() - ->columns(array('taged' => 'count(relation.tag_relation_id)')); - //->order('taged desc'); - return $this; - } - - public function addGroupByProduct() - { - $this->getSelect() - ->group('relation.product_id'); - $this->setJoinFlag('distinct'); - return $this; - } - - public function addGroupByTag() - { - $this->getSelect() - ->group('relation.tag_id'); - $this->setJoinFlag('distinct'); - $this->setJoinFlag('group_tag'); - return $this; - } - - public function addProductFilter($customerId) - { - $this->getSelect() - ->where('relation.product_id = ?', $customerId); - $this->_customerFilterId = $customerId; - return $this; - } - - - - public function setOrder($attribute, $dir='desc') - { - if ($attribute == 'utaged' || $attribute == 'taged' || $attribute == 'tag_name') { - $this->getSelect()->order($attribute . ' ' . $dir); - } else { - parent::setOrder($attribute, $dir); - } - - return $this; - } - - - protected function _joinFields() - { - $tagTable = Mage::getSingleton('core/resource')->getTableName('tag/tag'); - $tagRelationTable = Mage::getSingleton('core/resource')->getTableName('tag/relation'); - $this->addAttributeToSelect('name'); - $this->getSelect() - ->join(array('relation' => $tagRelationTable), "relation.product_id = e.entity_id") - ->join(array('t' => $tagTable), "t.tag_id =relation.tag_id", array( - 'tag_id', 'status', 'tag_name' => 'name' - )); - - - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Tax/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Tax/Collection.php index 49e6b63c12..7becd9567c 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Tax/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Tax/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,66 +28,10 @@ /** * Reports tax collection * - * @deprecated 1.7 - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ -class Mage_Reports_Model_Mysql4_Tax_Collection extends Mage_Sales_Model_Entity_Order_Collection +class Mage_Reports_Model_Mysql4_Tax_Collection extends Mage_Reports_Model_Resource_Tax_Collection { - public function _construct() - { - parent::_construct(); - $this->setRowIdFieldName('tax_id'); - } - - public function setDateRange($from, $to) - { - $this->_reset(); - - $this->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) - ->addExpressionAttributeToSelect('orders', 'COUNT(DISTINCT({{entity_id}}))', array('entity_id')) - ->getSelect() - ->join(array('tax_table' => $this->getTable('sales/order_tax')), 'e.entity_id = tax_table.order_id') - ->group('tax_table.code') - ->order(array('process', 'priority')); - - return $this; - } - - /** - * Set store filter to collection - * - * @param array $setStoreIds - * @return Mage_Reports_Model_Mysql4_Tax_Collection - */ - public function setStoreIds($storeIds) - { - if ($storeIds) { - $this->getSelect() - ->where('e.store_id in (?)', (array)$storeIds) - ->columns(array('tax'=>'SUM(tax_table.base_real_amount)')); - } else { - $this->addExpressionAttributeToSelect( - 'tax', - 'SUM(tax_table.base_real_amount*{{base_to_global_rate}})', - array('base_to_global_rate')); - } - - return $this; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::HAVING); - $countSelect->columns("count(DISTINCT e.entity_id)"); - $sql = $countSelect->__toString(); - return $sql; - } } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Collection.php index c9be47ac75..851191120e 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Collection.php @@ -20,65 +20,18 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Wishlist Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Wishlist_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Reports_Model_Mysql4_Wishlist_Collection extends Mage_Reports_Model_Resource_Wishlist_Collection { - protected $wishlistTable; - - public function setWishlistTable($value) - { - $this->_wishlistTable = $value; - return $this; - } - - public function getWishlistTable() - { - return $this->_wishlistTable; - } - - protected function _construct() - { - $this->_init('wishlist/wishlist'); - - $this->setWishlistTable(Mage::getSingleton('core/resource')->getTableName('wishlist/wishlist')); - } - - public function getWishlistCustomerCount() - { - $collection = Mage::getResourceModel('customer/customer_collection'); - $collection->load(); - - $customers = $collection->count(); - - $collection = Mage::getResourceModel('customer/customer_collection'); - $collection->getSelect()->from(array('wt' => $this->getWishlistTable())) - ->where('wt.customer_id=e.entity_id') - ->group('wt.wishlist_id'); - $collection->load(); - $count = $collection->count(); - return array(($count*100)/$customers, $count); - } - - public function getSharedCount() - { - $collection = Mage::getResourceModel('customer/customer_collection'); - $collection->getSelect()->from(array('wt' => $this->getWishlistTable())) - ->where('wt.customer_id=e.entity_id') - ->where('wt.shared=1') - ->group('wt.wishlist_id'); - $collection->load(); - return $collection->count(); - } - } diff --git a/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Product/Collection.php b/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Product/Collection.php index fe486f34f5..3a4c832f4f 100644 --- a/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Mysql4/Wishlist/Product/Collection.php @@ -20,73 +20,19 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Wishlist Report collection * - * @category Mage - * @package Mage_Reports + * @category Mage + * @package Mage_Reports * @author Magento Core Team */ - -class Mage_Reports_Model_Mysql4_Wishlist_Product_Collection extends Mage_Wishlist_Model_Mysql4_Product_Collection +class Mage_Reports_Model_Mysql4_Wishlist_Product_Collection + extends Mage_Reports_Model_Resource_Wishlist_Product_Collection { - protected function _construct() - { - $this->_init('wishlist/wishlist'); - } - - public function addWishlistCount() - { - $wishlistItemTable = Mage::getSingleton('core/resource')->getTableName('wishlist/item'); - - $this->getSelect() - ->from(array('wi' => $wishlistItemTable), 'count(wishlist_item_id) as wishlists') - ->where('wi.product_id=e.entity_id') - ->group('wi.product_id'); - - $this->getEntity()->setStore(0); - return $this; - } - - public function getCustomerCount() - { - $this->getSelect()->reset(); - $this->getSelect()->from("wishlist", array("count(wishlist_id) as wishlist_cnt")) - ->group("wishlist.customer_id"); - return $this;//->getItems()->; - } - - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::GROUP); - - $sql = $countSelect->__toString(); - - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(*) from ', $sql); - - return $sql; - } - - public function setOrder($attribute, $dir='desc') - { - switch ($attribute) - { - case 'wishlists': - $this->getSelect()->order($attribute . ' ' . $dir); - break; - default: - parent::setOrder($attribute, $dir); - } - - return $this; - } - } diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php index 6da922b9e9..b49319e93d 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Compared.php b/app/code/core/Mage/Reports/Model/Product/Index/Compared.php index 9d2a82cbac..029421ab95 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Compared.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Compared.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,19 @@ /** * Catalog Compared Product Index Model * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @method Mage_Reports_Model_Resource_Product_Index_Compared _getResource() + * @method Mage_Reports_Model_Resource_Product_Index_Compared getResource() + * @method Mage_Reports_Model_Product_Index_Compared setVisitorId(int $value) + * @method Mage_Reports_Model_Product_Index_Compared setCustomerId(int $value) + * @method int getProductId() + * @method Mage_Reports_Model_Product_Index_Compared setProductId(int $value) + * @method Mage_Reports_Model_Product_Index_Compared setStoreId(int $value) + * @method string getAddedAt() + * @method Mage_Reports_Model_Product_Index_Compared setAddedAt(string $value) + * + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ class Mage_Reports_Model_Product_Index_Compared extends Mage_Reports_Model_Product_Index_Abstract { diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Viewed.php b/app/code/core/Mage/Reports/Model/Product/Index/Viewed.php index 96ac496cf2..65cd1e3428 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Viewed.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Viewed.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,19 @@ /** * Catalog Viewed Product Index * - * @category Mage - * @package Mage_Reports - * @author Magento Core Team + * @method Mage_Reports_Model_Resource_Product_Index_Viewed _getResource() + * @method Mage_Reports_Model_Resource_Product_Index_Viewed getResource() + * @method Mage_Reports_Model_Product_Index_Viewed setVisitorId(int $value) + * @method Mage_Reports_Model_Product_Index_Viewed setCustomerId(int $value) + * @method int getProductId() + * @method Mage_Reports_Model_Product_Index_Viewed setProductId(int $value) + * @method Mage_Reports_Model_Product_Index_Viewed setStoreId(int $value) + * @method string getAddedAt() + * @method Mage_Reports_Model_Product_Index_Viewed setAddedAt(string $value) + * + * @category Mage + * @package Mage_Reports + * @author Magento Core Team */ class Mage_Reports_Model_Product_Index_Viewed extends Mage_Reports_Model_Product_Index_Abstract { diff --git a/app/code/core/Mage/Reports/Model/Report.php b/app/code/core/Mage/Reports/Model/Report.php index a155719771..8644f53730 100644 --- a/app/code/core/Mage/Reports/Model/Report.php +++ b/app/code/core/Mage/Reports/Model/Report.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Resource/Accounts/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Accounts/Collection.php new file mode 100755 index 0000000000..143c50fbc6 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Accounts/Collection.php @@ -0,0 +1,84 @@ + + */ +class Mage_Reports_Model_Resource_Accounts_Collection extends Mage_Reports_Model_Resource_Customer_Collection +{ + + /** + * Join created_at and accounts fields + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Accounts_Collection + */ + protected function _joinFields($from = '', $to = '') + { + + $this->getSelect()->reset(Zend_Db_Select::COLUMNS); + $this->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)) + ->addExpressionAttributeToSelect('accounts', 'COUNT({{entity_id}})', array('entity_id')); + + $this->getSelect()->having("{$this->_joinFields['accounts']['field']} > ?", 0); + + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Accounts_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->_joinFields($from, $to); + return $this; + } + + /** + * Set store ids to final result + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Accounts_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); + } + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Coupons/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Coupons/Collection.php new file mode 100755 index 0000000000..81bc3b6401 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Coupons/Collection.php @@ -0,0 +1,144 @@ + + */ +class Mage_Reports_Model_Resource_Coupons_Collection extends Mage_Sales_Model_Entity_Order_Collection +{ + /** + * From value + * + * @var string + */ + protected $_from = ''; + + /** + * To value + * + * @var string + */ + protected $_to = ''; + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Coupons_Collection + */ + public function setDateRange($from, $to) + { + $this->_from = $from; + $this->_to = $to; + $this->_reset(); + return $this; + } + + /** + * Set store ids + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Coupons_Collection + */ + public function setStoreIds($storeIds) + { + $this->joinFields($this->_from, $this->_to, $storeIds); + return $this; + } + + /** + * Join fields + * + * @param string $from + * @param string $to + * @param array $storeIds + */ + public function joinFields($from, $to, $storeIds = array()) + { + $this->groupByAttribute('coupon_code') + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)) + ->addAttributeToFilter('coupon_code', array('neq' => '')) + ->getSelect()->columns(array('uses' => 'COUNT(e.entity_id)')) + ->having('uses > ?', 0) + ->order('uses ' . self::SORT_ORDER_DESC); + + $storeIds = array_values($storeIds); + if (count($storeIds) >= 1 && $storeIds[0] != '') { + $this->addAttributeToFilter('store_id', array('in' => $storeIds)); + $this->addExpressionAttributeToSelect( + 'subtotal', + 'SUM({{base_subtotal}})', + array('base_subtotal')) + ->addExpressionAttributeToSelect( + 'discount', + 'SUM({{base_discount_amount}})', + array('base_discount_amount')) + ->addExpressionAttributeToSelect( + 'total', + 'SUM({{base_subtotal}}-{{base_discount_amount}})', + array('base_subtotal', 'base_discount_amount')); + } else { + $this->addExpressionAttributeToSelect( + 'subtotal', + 'SUM({{base_subtotal}}*{{base_to_global_rate}})', + array('base_subtotal', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'discount', + 'SUM({{base_discount_amount}}*{{base_to_global_rate}})', + array('base_discount_amount', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'total', + 'SUM(({{base_subtotal}}-{{base_discount_amount}})*{{base_to_global_rate}})', + array('base_subtotal', 'base_discount_amount', 'base_to_global_rate')); + } + + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns('COUNT(DISTINCT main_table.rule_id)'); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Customer/Collection.php new file mode 100755 index 0000000000..a1015277c0 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Customer/Collection.php @@ -0,0 +1,287 @@ + + */ +class Mage_Reports_Model_Resource_Customer_Collection extends Mage_Customer_Model_Resource_Customer_Collection +{ + /** + * Add order statistics flag + * + * @var boolean + */ + protected $_addOrderStatistics = false; + + /** + * Add order statistics is filter flag + * + * @var boolean + */ + protected $_addOrderStatisticsIsFilter = false; + + /** + * Customer id table name + * + * @var string + */ + protected $_customerIdTableName; + + /** + * Customer id field name + * + * @var string + */ + protected $_customerIdFieldName; + + /** + * Order entity table name + * + * @var string + */ + protected $_orderEntityTableName; + + /** + * Order entity field name + * + * @var string + */ + protected $_orderEntityFieldName; + + /** + * Add cart info to collection + * + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function addCartInfo() + { + foreach ($this->getItems() as $item) { + $quote = Mage::getModel('sales/quote')->loadByCustomer($item->getId()); + + if ($quote instanceof Mage_Sales_Model_Quote) { + $totals = $quote->getTotals(); + $item->setTotal($totals['subtotal']->getValue()); + $quoteItems = Mage::getResourceModel('sales/quote_item_collection')->setQuoteFilter($quote->getId()); + $quoteItems->load(); + $item->setItems($quoteItems->count()); + } else { + $item->remove(); + } + + } + return $this; + } + + /** + * Add customer name to results + * + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function addCustomerName() + { + $this->addNameToSelect(); + return $this; + } + + /** + * Order for each customer + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function joinOrders($from = '', $to = '') + { + if ($from != '' && $to != '') { + $dateFilter = " AND orders.created_at BETWEEN '{$from}' AND '{$to}'"; + } else { + $dateFilter = ''; + } + + $this->getSelect() + ->joinLeft(array('orders' => $this->getTable('sales/order')), + "orders.customer_id = e.entity_id".$dateFilter, + array()); + + return $this; + } + + /** + * Add orders count + * + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function addOrdersCount() + { + $this->getSelect() + ->columns(array("orders_count" => "COUNT(orders.entity_id)")) + ->where('orders.state <> ?', Mage_Sales_Model_Order::STATE_CANCELED) + ->group("e.entity_id"); + + return $this; + } + + /** + * Order summary info for each customer + * such as orders_count, orders_avg_amount, orders_total_amount + * + * @param int $storeId + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function addSumAvgTotals($storeId = 0) + { + $adapter = $this->getConnection(); + $baseSubtotalRefunded = $adapter->getIfNullSql('orders.base_subtotal_refunded', 0); + $baseSubtotalCanceled = $adapter->getIfNullSql('orders.base_subtotal_canceled', 0); + + /** + * calculate average and total amount + */ + $expr = ($storeId == 0) + ? "(orders.base_subtotal - {$baseSubtotalCanceled} - {$baseSubtotalRefunded}) * orders.base_to_global_rate" + : "orders.base_subtotal - {$baseSubtotalCanceled} - {$baseSubtotalRefunded}"; + + $this->getSelect() + ->columns(array("orders_avg_amount" => "AVG({$expr})")) + ->columns(array("orders_sum_amount" => "SUM({$expr})")); + + return $this; + } + + /** + * Order by total amount + * + * @param string $dir + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function orderByTotalAmount($dir = self::SORT_ORDER_DESC) + { + $this->getSelect() + ->order("orders_sum_amount {$dir}"); + return $this; + } + + /** + * Add order statistics + * + * @param boolean $isFilter + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function addOrdersStatistics($isFilter = false) + { + $this->_addOrderStatistics = true; + $this->_addOrderStatisticsIsFilter = (bool)$isFilter; + return $this; + } + + /** + * Add orders statistics to collection items + * + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + protected function _addOrdersStatistics() + { + $customerIds = $this->getColumnValues($this->getResource()->getIdFieldName()); + + if ($this->_addOrderStatistics && !empty($customerIds)) { + $adapter = $this->getConnection(); + $baseSubtotalRefunded = $adapter->getIfNullSql('orders.base_subtotal_refunded', 0); + $baseSubtotalCanceled = $adapter->getIfNullSql('orders.base_subtotal_canceled', 0); + + $totalExpr = ($this->_addOrderStatisticsIsFilter) + ? "(orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded})*orders.base_to_global_rate" + : "orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded}"; + + $select = $this->getConnection()->select(); + $select->from(array('orders'=>$this->getTable('sales/order')), array( + 'orders_avg_amount' => "AVG({$totalExpr})", + 'orders_sum_amount' => "SUM({$totalExpr})", + 'orders_count' => 'COUNT(orders.entity_id)', + 'customer_id' + ))->where('orders.state <> ?', Mage_Sales_Model_Order::STATE_CANCELED) + ->where('orders.customer_id IN(?)', $customerIds) + ->group('orders.customer_id'); + + /* + * Analytic functions usage + */ + $select = Mage::getResourceHelper('core')->getQueryUsingAnalyticFunction($select); + + foreach ($this->getConnection()->fetchAll($select) as $ordersInfo) { + $this->getItemById($ordersInfo['customer_id'])->addData($ordersInfo); + } + } + + return $this; + } + + /** + * Collection after load operations like adding orders statistics + * + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + protected function _afterLoad() + { + $this->_addOrdersStatistics(); + return $this; + } + + /** + * Order by customer registration + * + * @param string $dir + * @return Mage_Reports_Model_Resource_Customer_Collection + */ + public function orderByCustomerRegistration($dir = self::SORT_ORDER_DESC) + { + $this->addAttributeToSort('entity_id', $dir); + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns("count(DISTINCT e.entity_id)"); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Customer/Orders/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Customer/Orders/Collection.php new file mode 100755 index 0000000000..c5c42ceb88 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Customer/Orders/Collection.php @@ -0,0 +1,91 @@ + + */ +class Mage_Reports_Model_Resource_Customer_Orders_Collection extends Mage_Reports_Model_Resource_Order_Collection +{ + protected function _construct() + { + parent::_construct(); + $this->_useAnalyticFunction = true; + } + /** + * Join fields + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Customer_Orders_Collection + */ + protected function _joinFields($from = '', $to = '') + { + $this->joinCustomerName() + ->groupByCustomer() + ->addOrdersCount() + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)); + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Customer_Orders_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->_joinFields($from, $to); + return $this; + } + + /** + * Set store filter to collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Customer_Orders_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); + $this->addSumAvgTotals(1) + ->orderByOrdersCount(); + } else { + $this->addSumAvgTotals() + ->orderByOrdersCount(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Customer/Totals/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Customer/Totals/Collection.php new file mode 100755 index 0000000000..d7c9045eb9 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Customer/Totals/Collection.php @@ -0,0 +1,91 @@ + + */ +class Mage_Reports_Model_Resource_Customer_Totals_Collection extends Mage_Reports_Model_Resource_Order_Collection +{ + protected function _construct() + { + parent::_construct(); + $this->_useAnalyticFunction = true; + } + /** + * Join fields + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Customer_Totals_Collection + */ + protected function _joinFields($from = '', $to = '') + { + $this->joinCustomerName() + ->groupByCustomer() + ->addOrdersCount() + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to, 'datetime' => true)); + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Customer_Totals_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->_joinFields($from, $to); + return $this; + } + + /** + * Set store filter collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Customer_Totals_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); + $this->addSumAvgTotals(1) + ->orderByTotalAmount(); + } else { + $this->addSumAvgTotals() + ->orderByTotalAmount(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php new file mode 100755 index 0000000000..9bdd82060e --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php @@ -0,0 +1,134 @@ + + */ +class Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract extends Varien_Data_Collection +{ + /** + * Entity collection for summaries + * + * @var Mage_Entity_Model_Entity_Collection_Abstract + */ + protected $_entityCollection; + + /** + * Filters the summaries by some period + * + * @param string $periodType + * @param string|int|null $customStart + * @param string|int|null $customEnd + * @return Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract + */ + public function setSelectPeriod($periodType, $customStart = null, $customEnd = null) + { + switch ($periodType) { + case "24h": + $customStart = Varien_Date::toTimestamp(true) - 86400; + $customEnd = Varien_Date::toTimestamp(true); + break; + + case "7d": + $customStart = Varien_Date::toTimestamp(true) - 604800; + $customEnd = Varien_Date::toTimestamp(true); + break; + + case "30d": + $customStart = Varien_Date::toTimestamp(true) - 2592000; + $customEnd = Varien_Date::toTimestamp(true); + break; + + case "1y": + $customStart = Varien_Date::toTimestamp(true) - 31536000; + $customEnd = Varien_Date::toTimestamp(true); + break; + + default: + if (is_string($customStart)) { + $customStart = strtotime($customStart); + } + if (is_string($customEnd)) { + $customEnd = strtotime($customEnd); + } + break; + + } + + + return $this; + } + + /** + * Set date period + * + * @param int $period + * @return Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract + */ + public function setDatePeriod($period) + { + return $this; + } + + /** + * Set store filter + * + * @param int $storeId + * @return Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract + */ + public function setStoreFilter($storeId) + { + return $this; + } + + /** + * Return collection for summaries + * + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + public function getCollection() + { + if (empty($this->_entityCollection)) { + $this->_initCollection(); + } + return $this->_entityCollection; + } + + /** + * Init collection + * + * @return Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract + */ + protected function _initCollection() + { + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Event.php b/app/code/core/Mage/Reports/Model/Resource/Event.php new file mode 100755 index 0000000000..74426167c2 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Event.php @@ -0,0 +1,187 @@ + + */ +class Mage_Reports_Model_Resource_Event extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize main table and identifier field. + * Set main entity table name and primary key field name. + * + * @return void + */ + protected function _construct() + { + $this->_init('reports/event', 'event_id'); + } + + /** + * Update customer type after customer login + * + * @param Mage_Reports_Model_Event $model + * @param int $visitorId + * @param int $customerId + * @param array $types + * @return Mage_Reports_Model_Resource_Event + */ + public function updateCustomerType(Mage_Reports_Model_Event $model, $visitorId, $customerId, $types = array()) + { + if ($types) { + $this->_getWriteAdapter()->update($this->getMainTable(), + array('subject_id' => (int)$customerId, 'subtype' => 0), + array( + 'subject_id = ?' => (int)$visitorId, + 'subtype = ?' => 1, + 'event_type_id IN(?)' => $types + ) + ); + } + return $this; + } + + /** + * Add events log to a collection + * The collection id field is used without corellation, so it must be unique. + * DESC ordering by event will be added to the collection + * + * @param Varien_Data_Collection_Db $collection + * @param int $eventTypeId + * @param int $eventSubjectId + * @param int $subtype + * @param array $skipIds + * @return Mage_Reports_Model_Resource_Event + */ + public function applyLogToCollection(Varien_Data_Collection_Db $collection, $eventTypeId, $eventSubjectId, $subtype, + $skipIds = array()) + { + $idFieldName = $collection->getResource()->getIdFieldName(); + + $derivedSelect = $this->getReadConnection()->select() + ->from( + $this->getTable('reports/event'), + array('event_id' => new Zend_Db_Expr('MAX(event_id)'), 'object_id')) + ->where('event_type_id = ?', (int)$eventTypeId) + ->where('subject_id = ?', (int)$eventSubjectId) + ->where('subtype = ?', (int)$subtype) + ->where('store_id IN(?)', $this->getCurrentStoreIds()) + ->group('object_id'); + + if ($skipIds) { + if (!is_array($skipIds)) { + $skipIds = array((int)$skipIds); + } + $derivedSelect->where('object_id NOT IN(?)', $skipIds); + } + + $collection->getSelect() + ->joinInner( + array('evt' => new Zend_Db_Expr("({$derivedSelect})")), + "{$idFieldName} = evt.object_id", + array()) + ->order('evt.event_id ' . Varien_Db_Select::SQL_DESC); + + return $this; + } + + /** + * Obtain all current store ids, depending on configuration + * + * @param array $predefinedStoreIds + * @return array + */ + public function getCurrentStoreIds(array $predefinedStoreIds = null) + { + $stores = array(); + // get all or specified stores + if (Mage::app()->getStore()->getId() == 0) { + if (null !== $predefinedStoreIds) { + $stores = $predefinedStoreIds; + } else { + foreach (Mage::app()->getStores() as $store) { + $stores[] = $store->getId(); + } + } + } else { // get all stores, required by configuration in current store scope + switch (Mage::getStoreConfig('catalog/recently_products/scope')) { + case 'website': + $resourceStore = Mage::app()->getStore()->getWebsite()->getStores(); + break; + case 'group': + $resourceStore = Mage::app()->getStore()->getGroup()->getStores(); + break; + default: + $resourceStore = array(Mage::app()->getStore()); + break; + } + + foreach ($resourceStore as $store) { + $stores[] = $store->getId(); + } + } + foreach ($stores as $key => $store) { + $stores[$key] = (int)$store; + } + + return $stores; + } + + /** + * Clean report event table + * + * @param Mage_Reports_Model_Event $object + * @return Mage_Reports_Model_Resource_Event + */ + public function clean(Mage_Reports_Model_Event $object) + { + while (true) { + $select = $this->_getReadAdapter()->select() + ->from(array('event_table' => $this->getMainTable()), array('event_id')) + ->joinLeft( + array('visitor_table' => $this->getTable('log/visitor')), + 'event_table.subject_id = visitor_table.visitor_id', + array()) + ->where('visitor_table.visitor_id IS NULL') + ->where('event_table.subtype = ?', 1) + ->limit(1000); + $eventIds = $this->_getReadAdapter()->fetchCol($select); + + if (!$eventIds) { + break; + } + + $this->_getWriteAdapter()->delete($this->getMainTable(), array('event_id IN(?)' => $eventIds)); + } + return $this; + } +} + diff --git a/app/code/core/Mage/Reports/Model/Resource/Event/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Event/Collection.php new file mode 100755 index 0000000000..febaa2c234 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Event/Collection.php @@ -0,0 +1,102 @@ + + */ +class Mage_Reports_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Store Ids + * + * @var array + */ + protected $_storeIds; + + /** + * Use analytic function flag + * If true - allows to prepare final select with analytic function + * + * @var bool + */ + protected $_useAnalyticFunction = true; + + /** + * Resource initializations + * + */ + protected function _construct() + { + $this->_init('reports/event'); + } + + /** + * Add store ids filter + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Event_Collection + */ + public function addStoreFilter(array $storeIds) + { + $this->_storeIds = $storeIds; + return $this; + } + + /** + * Add recently filter + * + * @param int $typeId + * @param int $subjectId + * @param int $subtype + * @param int|array $ignore + * @param int $limit + * @return Mage_Reports_Model_Resource_Event_Collection + */ + public function addRecentlyFiler($typeId, $subjectId, $subtype = 0, $ignore = null, $limit = 15) + { + $stores = $this->getResource()->getCurrentStoreIds($this->_storeIds); + $select = $this->getSelect(); + $select->where('event_type_id = ?', $typeId) + ->where('subject_id = ?', $subjectId) + ->where('subtype = ?', $subtype) + ->where('store_id IN(?)', $stores); + if ($ignore) { + if (is_array($ignore)) { + $select->where('object_id NOT IN(?)', $ignore); + } else { + $select->where('object_id <> ?', $ignore); + } + } + $select->group('object_id') + ->limit($limit); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Event/Type.php b/app/code/core/Mage/Reports/Model/Resource/Event/Type.php new file mode 100755 index 0000000000..93647dea9a --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Event/Type.php @@ -0,0 +1,45 @@ + + */ +class Mage_Reports_Model_Resource_Event_Type extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Main table initialization + * + */ + protected function _construct() + { + $this->_init('reports/event_type', 'event_type_id'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Event/Type/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Event/Type/Collection.php new file mode 100755 index 0000000000..53ebbd2a25 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Event/Type/Collection.php @@ -0,0 +1,55 @@ + + */ +class Mage_Reports_Model_Resource_Event_Type_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('reports/event_type'); + } + + /** + * Return option array + * + * @return array + */ + public function toOptionArray() + { + return parent::_toOptionArray('event_type_id', 'event_name'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..15a0d85bdc --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,51 @@ + + */ +class Mage_Reports_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Mysql4 +{ + + /** + * Merge Index data + * + * @param string $mainTable + * @param array $data + * @return string + */ + public function mergeVisitorProductIndex($mainTable, $data, $matchFields) + { + $result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, array_keys($data)); + return $result; + } + +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Invoiced/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Invoiced/Collection.php new file mode 100755 index 0000000000..b1e9e82ba4 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Invoiced/Collection.php @@ -0,0 +1,126 @@ + + */ +class Mage_Reports_Model_Resource_Invoiced_Collection extends Mage_Sales_Model_Entity_Order_Collection +{ + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Invoiced_Collection + */ + public function setDateRange($from, $to) + { + $orderInvoicedExpr = $this->getConnection()->getCheckSql('{{base_total_invoiced}} > 0', 1, 0); + $this->_reset() + ->addAttributeToSelect('*') + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) + ->addExpressionAttributeToSelect('orders', + 'COUNT({{base_total_invoiced}})', + array('base_total_invoiced')) + ->addExpressionAttributeToSelect('orders_invoiced', + "SUM({$orderInvoicedExpr})", + array('base_total_invoiced')) + ->addAttributeToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)) + ->getSelect() + ->group('entity_id') + ->having('orders > ?', 0); + /* + * Allow Analytic Functions Usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Set store filter collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Invoiced_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)) + ->addExpressionAttributeToSelect( + 'invoiced', + 'SUM({{base_total_invoiced}})', + array('base_total_invoiced')) + ->addExpressionAttributeToSelect( + 'invoiced_captured', + 'SUM({{base_total_paid}})', + array('base_total_paid')) + ->addExpressionAttributeToSelect( + 'invoiced_not_captured', + 'SUM({{base_total_invoiced}}-{{base_total_paid}})', + array('base_total_invoiced', 'base_total_paid')); + } else { + $this->addExpressionAttributeToSelect( + 'invoiced', + 'SUM({{base_total_invoiced}}*{{base_to_global_rate}})', + array('base_total_invoiced', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'invoiced_captured', + 'SUM({{base_total_paid}}*{{base_to_global_rate}})', + array('base_total_paid', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'invoiced_not_captured', + 'SUM(({{base_total_invoiced}}-{{base_total_paid}})*{{base_to_global_rate}})', + array('base_total_invoiced', 'base_to_global_rate', 'base_total_paid')); + } + + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns("COUNT(*)"); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php new file mode 100755 index 0000000000..37d6f1cae6 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -0,0 +1,719 @@ + + */ +class Mage_Reports_Model_Resource_Order_Collection extends Mage_Sales_Model_Resource_Order_Collection +{ + /** + * Is live + * + * @var boolean + */ + protected $_isLive = false; + + /** + * Check range for live mode + * + * @param unknown_type $range + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function checkIsLive($range) + { + $this->_isLive = (bool)!Mage::getStoreConfig('sales/dashboard/use_aggregated_data'); + return $this; + } + + /** + * Retrieve is live flag for rep + * + * @return boolean + */ + public function isLive() + { + return $this->_isLive; + } + + /** + * Prepare report summary + * + * @param string $range + * @param mixed $customStart + * @param mixed $customEnd + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function prepareSummary($range, $customStart, $customEnd, $isFilter = 0) + { + $this->checkIsLive($range); + if ($this->_isLive) { + $this->_prepareSummaryLive($range, $customStart, $customEnd, $isFilter); + } else { + $this->_prepareSummaryAggregated($range, $customStart, $customEnd, $isFilter); + } + + return $this; + } + + /** + * Prepare report summary from live data + * + * @param string $range + * @param mixed $customStart + * @param mixed $customEnd + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilter = 0) + { + $this->setMainTable('sales/order'); + /** + * Reset all columns, because result will group only by 'created_at' field + */ + $this->getSelect()->reset(Zend_Db_Select::COLUMNS); + if ($isFilter == 0) { + $this->getSelect()->columns(array( + 'revenue' => 'SUM(main_table.base_grand_total * main_table.base_to_global_rate)' + )); + } else { + $this->getSelect()->columns(array( + 'revenue' => 'SUM(main_table.base_grand_total)' + )); + } + + $rangeCreatedAt = $this->_getRangeExpressionForAttribute($range, 'created_at'); + $rangeCreatedAt2 = str_replace($this->getConnection()->quoteIdentifier('created_at'), + 'MIN(created_at)', $rangeCreatedAt); + + $this->getSelect() + ->columns(array( + 'quantity' => 'COUNT(main_table.entity_id)', + 'range' => $rangeCreatedAt2, + )) + ->order('range') + ->group($rangeCreatedAt); + + $this->addFieldToFilter('created_at', $this->getDateRange($range, $customStart, $customEnd)) + ->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); + + return $this; + } + + /** + * Prepare report summary from aggregated data + * + * @param string $range + * @param mixed $customStart + * @param mixed $customEnd + * @return Mage_Reports_Model_Resource_Order_Collection + */ + protected function _prepareSummaryAggregated($range, $customStart, $customEnd) + { + + $this->setMainTable('sales/order_aggregated_created'); + /** + * Reset all columns, because result will group only by 'created_at' field + */ + $this->getSelect()->reset(Zend_Db_Select::COLUMNS); + $rangePeriod = $this->_getRangeExpressionForAttribute($range, 'main_table.period'); + + $tableName = $this->getConnection()->quoteIdentifier('main_table.period'); + $rangePeriod2 = str_replace($tableName, "MIN($tableName)", $rangePeriod); + + $this->getSelect()->columns(array( + 'revenue' => 'SUM(main_table.total_revenue_amount)', + 'quantity' => 'SUM(main_table.orders_count)', + 'range' => $rangePeriod2, + )) + ->order('range') + ->group($rangePeriod); + + $this->getSelect()->where( + $this->_getConditionSql('main_table.period', $this->getDateRange($range, $customStart, $customEnd)) + ); + + $statuses = Mage::getSingleton('sales/config') + ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); + + if (empty($statuses)) { + $statuses = array(0); + } + $this->addFieldToFilter('main_table.order_status', array('nin' => $statuses)); + + return $this; + } + + /** + * Get range expression + * + * @param unknown_type $range + * @return unknown + */ + protected function _getRangeExpression($range) + { + // dont need of this offset bc we are format date in block + //$timeZoneOffset = Mage::getModel('core/date')->getGmtOffset(); + + switch ($range) + { + case '24h': + $expression = $this->getConnection()->getConcatSql(array( + $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d %H:'), + $this->getConnection()->quote('00') + )); + break; + case '7d': + case '1m': + $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d'); + break; + case '1y': + case '2y': + case 'custom': + default: + $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m'); + break; + } + + return $expression; + } + + /** + * Retriev range exression adapteted for attribute + * + * @param string $range + * @param unknown_type $attribute + * @return unknown + */ + protected function _getRangeExpressionForAttribute($range, $attribute) + { + $expression = $this->_getRangeExpression($range); + return str_replace('{{attribute}}', $this->getConnection()->quoteIdentifier($attribute), $expression); + } + + /** + * Get Date range + * + * @param string $range + * @param string $customStart + * @param string $customEnd + * @param boolean $returnObjects + * @return unknown + */ + public function getDateRange($range, $customStart, $customEnd, $returnObjects = false) + { + $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); + $dateStart = clone $dateEnd; + + // go to the end of a day + $dateEnd->setHour(23); + $dateEnd->setMinute(59); + $dateEnd->setSecond(59); + + $dateStart->setHour(0); + $dateStart->setMinute(0); + $dateStart->setSecond(0); + + switch ($range) + { + case '24h': + $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); + $dateEnd->addHour(1); + $dateStart = clone $dateEnd; + $dateStart->subDay(1); + break; + + case '7d': + // substract 6 days we need to include + // only today and not hte last one from range + $dateStart->subDay(6); + break; + + case '1m': + $dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start')); + break; + + case 'custom': + $dateStart = $customStart ? $customStart : $dateEnd; + $dateEnd = $customEnd ? $customEnd : $dateEnd; + break; + + case '1y': + case '2y': + $startMonthDay = explode(',', Mage::getStoreConfig('reports/dashboard/ytd_start')); + $startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1; + $startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1; + $dateStart->setMonth($startMonth); + $dateStart->setDay($startDay); + if ($range == '2y') { + $dateStart->subYear(1); + } + break; + } + + if ($returnObjects) { + return array($dateStart, $dateEnd); + } else { + return array('from' => $dateStart, 'to' => $dateEnd, 'datetime' => true); + } + } + + /** + * Add item count expression + * + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function addItemCountExpr() + { + $this->getSelect()->columns(array('items_count' => 'total_item_count'), 'main_table'); + return $this; + } + + /** + * Calculate totals report + * + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function calculateTotals($isFilter = 0) + { + if ($this->isLive()) { + $this->_calculateTotalsLive($isFilter); + } else { + $this->_calculateTotalsAggregated($isFilter); + } + + return $this; + } + + /** + * Calculate totals live report + * + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + protected function _calculateTotalsLive($isFilter = 0) + { + $this->setMainTable('sales/order'); + $this->removeAllFieldsFromSelect(); + + $adapter = $this->getConnection(); + + $baseSubtotalRefunded = $adapter->getIfNullSql('main_table.base_subtotal_refunded', 0); + $baseSubtotalCanceled = $adapter->getIfNullSql('main_table.base_subtotal_canceled', 0); + $baseDiscountAmount = $adapter->getIfNullSql('main_table.base_discount_amount', 0); + $baseDiscountRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0); + $baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0); + $baseTaxCanceled = $adapter->getIfNullSql('main_table.base_tax_canceled', 0); + $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0); + $baseShippingCanceled = $adapter->getIfNullSql('main_table.base_shipping_canceled', 0); + + if ($isFilter == 0) { + $sumArgument = 'main_table.base_to_global_rate'; + $revenueArgument = "(main_table.base_subtotal - ({$baseSubtotalRefunded}) - ({$baseSubtotalCanceled})" + . " - ABS({$baseDiscountAmount}) + ({$baseDiscountRefunded})) * ({$sumArgument})"; + $taxArgument = "(main_table.base_tax_amount-({$baseTaxRefunded}) - ({$baseTaxCanceled})) * ({$sumArgument})"; + $shippingArgument = "(main_table.base_shipping_amount - ({$baseShippingRefunded}) - " + . " ({$baseShippingCanceled})) * ({$sumArgument})"; + } else { + $revenueArgument = "(main_table.base_subtotal - {$baseSubtotalRefunded} - {$baseSubtotalCanceled}" + . " - ABS({$baseDiscountAmount}) + {$baseDiscountRefunded})"; + $taxArgument = "(main_table.base_tax_amount - {$baseTaxRefunded} - {$baseTaxCanceled})"; + $shippingArgument= "(main_table.base_shipping_amount - {$baseShippingRefunded} - {$baseShippingCanceled})"; + } + + $this->getSelect()->columns(array( + 'revenue' => "SUM({$revenueArgument})", + 'tax' => "SUM({$taxArgument})", + 'shipping' => "SUM({$shippingArgument})", + 'quantity' => 'COUNT(main_table.entity_id)' + )); + + $this->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); + + return $this; + } + + /** + * Calculate totals aggregated report + * + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + protected function _calculateTotalsAggregated($isFilter = 0) + { + $this->setMainTable('sales/order_aggregated_created'); + $this->removeAllFieldsFromSelect(); + + $this->getSelect()->columns(array( + 'revenue' => 'SUM(main_table.total_revenue_amount)', + 'tax' => 'SUM(main_table.total_tax_amount_actual)', + 'shipping' => 'SUM(main_table.total_shipping_amount_actual)', + 'quantity' => 'SUM(orders_count)', + )); + + $statuses = Mage::getSingleton('sales/config') + ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); + + if (empty($statuses)) { + $statuses = array(0); + } + + $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses); + + return $this; + } + + /** + * Calculate lifitime sales + * + * @param int $isFilter + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function calculateSales($isFilter = 0) + { + $statuses = Mage::getSingleton('sales/config') + ->getOrderStatusesForState(Mage_Sales_Model_Order::STATE_CANCELED); + + if (empty($statuses)) { + $statuses = array(0); + } + $adapter = $this->getConnection(); + + if (Mage::getStoreConfig('sales/dashboard/use_aggregated_data')) { + $this->setMainTable('sales/order_aggregated_created'); + $this->removeAllFieldsFromSelect(); + $averageExpr = $adapter->getCheckSql( + 'SUM(main_table.orders_count) > 0', + 'SUM(main_table.total_revenue_amount)/SUM(main_table.orders_count)', + 0); + $this->getSelect()->columns(array( + 'lifetime' => 'SUM(main_table.total_revenue_amount)', + 'average' => $averageExpr + )); + + if (!$isFilter) { + $this->addFieldToFilter('store_id', + array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId()) + ); + } + $this->getSelect()->where('main_table.order_status NOT IN(?)', $statuses); + } else { + $this->setMainTable('sales/order'); + $this->removeAllFieldsFromSelect(); + + $baseSubtotal = $adapter->getIfNullSql('main_table.base_subtotal', 0); + $baseSubtotalRefunded = $adapter->getIfNullSql('main_table.base_subtotal_refunded', 0); + $baseSubtotalCanceled = $adapter->getIfNullSql('main_table.base_subtotal_canceled', 0); + $baseDiscountRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0); + $expr = "{$baseSubtotal} - {$baseSubtotalRefunded} - {$baseSubtotalCanceled} " + . " - ABS({$baseSubtotalCanceled}) + {$baseDiscountRefunded}"; + + + $this->getSelect() + ->columns(array( + 'lifetime' => "SUM({$expr})", + 'average' => "AVG({$expr})" + )) + ->where('main_table.status NOT IN(?)', $statuses) + ->where( + 'main_table.state NOT IN(?)', + array(Mage_Sales_Model_Order::STATE_NEW, Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) + ); + } + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->addFieldToFilter('created_at', array('from' => $from, 'to' => $to)) + ->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)) + ->getSelect() + ->columns(array('orders' => 'COUNT(DISTINCT(main_table.entity_id))')) + ->group('entity_id'); + + $this->getSelect()->columns(array("items" => 'SUM(main_table.total_qty_ordered)')); + + return $this; + } + + /** + * Set store filter collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function setStoreIds($storeIds) + { + $adapter = $this->getConnection(); + $baseSubtotalInvoiced = $adapter->getIfNullSql('main_table.base_subtotal_invoiced', 0); + $baseDiscountRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0); + $baseSubtotalRefunded = $adapter->getIfNullSql('main_table.base_subtotal_refunded', 0); + $baseDiscountInvoiced = $adapter->getIfNullSql('main_table.base_discount_invoiced', 0); + $baseTotalInvocedCost = $adapter->getIfNullSql('main_table.base_total_invoiced_cost', 0); + if ($storeIds) { + $this->getSelect()->columns(array( + 'subtotal' => 'SUM(main_table.base_subtotal)', + 'tax' => 'SUM(main_table.base_tax_amount)', + 'shipping' => 'SUM(main_table.base_shipping_amount)', + 'discount' => 'SUM(main_table.base_discount_amount)', + 'total' => 'SUM(main_table.base_grand_total)', + 'invoiced' => 'SUM(main_table.base_total_paid)', + 'refunded' => 'SUM(main_table.base_total_refunded)', + 'profit' => "SUM($baseSubtotalInvoiced) " + . "+ SUM({$baseDiscountRefunded}) - SUM({$baseSubtotalRefunded}) " + . "- SUM({$baseDiscountInvoiced}) - SUM({$baseTotalInvocedCost})" + )); + } else { + $this->getSelect()->columns(array( + 'subtotal' => 'SUM(main_table.base_subtotal * main_table.base_to_global_rate)', + 'tax' => 'SUM(main_table.base_tax_amount * main_table.base_to_global_rate)', + 'shipping' => 'SUM(main_table.base_shipping_amount * main_table.base_to_global_rate)', + 'discount' => 'SUM(main_table.base_discount_amount * main_table.base_to_global_rate)', + 'total' => 'SUM(main_table.base_grand_total * main_table.base_to_global_rate)', + 'invoiced' => 'SUM(main_table.base_total_paid * main_table.base_to_global_rate)', + 'refunded' => 'SUM(main_table.base_total_refunded * main_table.base_to_global_rate)', + 'profit' => "SUM({$baseSubtotalInvoiced} * main_table.base_to_global_rate) " + . "+ SUM({$baseDiscountRefunded} * main_table.base_to_global_rate) " + . "- SUM({$baseSubtotalRefunded} * main_table.base_to_global_rate) " + . "- SUM({$baseDiscountInvoiced} * main_table.base_to_global_rate) " + . "- SUM({$baseTotalInvocedCost} * main_table.base_to_global_rate)" + )); + } + + return $this; + } + + /** + * Add group By customer attribute + * + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function groupByCustomer() + { + $this->getSelect()->group('main_table.customer_id'); + + /* + * Allow Analytic functions usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Join Customer Name (concat) + * + * @param string $alias + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function joinCustomerName($alias = 'name') + { + $fields = array('main_table.customer_firstname', 'main_table.customer_lastname'); + $fieldConcat = $this->getConnection()->getConcatSql($fields, ' '); + $this->getSelect()->columns(array($alias => $fieldConcat)); + return $this; + } + + /** + * Add Order count field to select + * + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function addOrdersCount() + { + $this->addFieldToFilter('state', array('neq' => Mage_Sales_Model_Order::STATE_CANCELED)); + $this->getSelect() + ->columns(array('orders_count' => 'COUNT(main_table.entity_id)')); + + return $this; + } + + /** + * Add revenue + * + * @param boolean $convertCurrency + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function addRevenueToSelect($convertCurrency = false) + { + if ($convertCurrency) { + $this->getSelect()->columns(array( + 'revenue' => '(main_table.base_grand_total * main_table.base_to_global_rate)' + )); + } else { + $this->getSelect()->columns(array( + 'revenue' => 'base_grand_total' + )); + } + + return $this; + } + + /** + * Add summary average totals + * + * @param int $storeId + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function addSumAvgTotals($storeId = 0) + { + $adapter = $this->getConnection(); + $baseSubtotalRefunded = $adapter->getIfNullSql('main_table.base_subtotal_refunded', 0); + $baseSubtotalCanceled = $adapter->getIfNullSql('main_table.base_subtotal_canceled', 0); + $baseDiscountCanceled = $adapter->getIfNullSql('main_table.base_discount_canceled', 0); + + /** + * calculate average and total amount + */ + $expr = ($storeId == 0) + ? "(main_table.base_subtotal - {$baseSubtotalRefunded} - {$baseSubtotalCanceled} - ABS(main_table.base_discount_amount) - {$baseDiscountCanceled}) * main_table.base_to_global_rate" + : "main_table.base_subtotal - {$baseSubtotalCanceled} - {$baseSubtotalRefunded} - ABS(main_table.base_discount_amount) - {$baseDiscountCanceled}"; + + $this->getSelect() + ->columns(array('orders_avg_amount' => "AVG({$expr})")) + ->columns(array('orders_sum_amount' => "SUM({$expr})")); + + return $this; + } + + /** + * Sort order by total amount + * + * @param string $dir + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function orderByTotalAmount($dir = self::SORT_ORDER_DESC) + { + $this->getSelect()->order('orders_sum_amount ' . $dir); + return $this; + } + + /** + * Order by orders count + * + * @param unknown_type $dir + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function orderByOrdersCount($dir = self::SORT_ORDER_DESC) + { + $this->getSelect()->order('orders_count ' . $dir); + return $this; + } + + /** + * Order by customer registration + * + * @param unknown_type $dir + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function orderByCustomerRegistration($dir = self::SORT_ORDER_DESC) + { + $this->setOrder('customer_id', $dir); + return $this; + } + + /** + * Sort order by order created_at date + * + * @param string $dir + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function orderByCreatedAt($dir = self::SORT_ORDER_DESC) + { + $this->setOrder('created_at', $dir); + return $this; + } + + /** + * Get select count sql + * + * @return unknown + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns("COUNT(DISTINCT main_table.entity_id)"); + + return $countSelect; + } + + /** + * Initialize initial fields to select + * + * @return Mage_Reports_Model_Resource_Order_Collection + */ + protected function _initInitialFieldsToSelect() + { + // No fields should be initialized + return $this; + } + + /** + * Add period filter by created_at attribute + * + * @param string $period + * @return Mage_Reports_Model_Resource_Order_Collection + */ + public function addCreateAtPeriodFilter($period) + { + list($from, $to) = $this->getDateRange($period, 0, 0, true); + + $this->checkIsLive($period); + + if ($this->isLive()) { + $fieldToFilter = 'created_at'; + } else { + $fieldToFilter = 'period'; + } + + $this->addFieldToFilter($fieldToFilter, array( + 'from' => $from->toString(Varien_Date::DATETIME_INTERNAL_FORMAT), + 'to' => $to->toString(Varien_Date::DATETIME_INTERNAL_FORMAT) + )); + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Collection.php new file mode 100755 index 0000000000..17c30f07f2 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Collection.php @@ -0,0 +1,433 @@ + + */ +class Mage_Reports_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + const SELECT_COUNT_SQL_TYPE_CART = 1; + + /** + * Product entity identifier + * + * @var int + */ + protected $_productEntityId; + + /** + * Product entity table name + * + * @var string + */ + protected $_productEntityTableName; + + /** + * Product entity type identifier + * + * @var int + */ + protected $_productEntityTypeId; + + /** + * select count + * + * @var int + */ + protected $_selectCountSqlType = 0; + + /** + * Init main class options + * + */ + public function __construct() + { + $product = Mage::getResourceSingleton('catalog/product'); + /* @var $product Mage_Catalog_Model_Entity_Product */ + $this->setProductEntityId($product->getEntityIdField()); + $this->setProductEntityTableName($product->getEntityTable()); + $this->setProductEntityTypeId($product->getTypeId()); + + parent::__construct(); + } + /** + * Set Type for COUNT SQL Select + * + * @param int $type + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function setSelectCountSqlType($type) + { + $this->_selectCountSqlType = $type; + return $this; + } + + /** + * Set product entity id + * + * @param int $value + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function setProductEntityId($entityId) + { + $this->_productEntityId = (int)$entityId; + return $this; + } + + /** + * Get product entity id + * + * @return int + */ + public function getProductEntityId() + { + return $this->_productEntityId; + } + + /** + * Set product entity table name + * + * @param string $value + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function setProductEntityTableName($value) + { + $this->_productEntityTableName = $value; + return $this; + } + + /** + * Get product entity table name + * + * @return string + */ + public function getProductEntityTableName() + { + return $this->_productEntityTableName; + } + + /** + * Set product entity type id + * + * @param int $value + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function setProductEntityTypeId($value) + { + $this->_productEntityTypeId = $value; + return $this; + } + + /** + * Get product entity tyoe id + * + * @return int + */ + public function getProductEntityTypeId() + { + return $this->_productEntityTypeId; + } + + /** + * Join fields + * + * @return Mage_Reports_Model_Resource_Product_Collection + */ + protected function _joinFields() + { + $this->_totals = new Varien_Object(); + + $this->addAttributeToSelect('entity_id') + ->addAttributeToSelect('name') + ->addAttributeToSelect('price'); + + return $this; + } + + /** + * Get select count sql + * + * @return unknown + */ + public function getSelectCountSql() + { + if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) { + $countSelect = clone $this->getSelect(); + $countSelect->reset() + ->from( + array('quote_item_table' => $this->getTable('sales/quote_item')), + array('COUNT(DISTINCT quote_item_table.product_id)')) + ->join( + array('quote_table' => $this->getTable('sales/quote')), + 'quote_table.entity_id = quote_item_table.quote_id AND quote_table.is_active = 1', + array() + ); + return $countSelect; + } + + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns("count(DISTINCT e.entity_id)"); + + return $countSelect; + } + + /** + * Add carts count + * + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function addCartsCount() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(); + + $countSelect->from(array('quote_items' => $this->getTable('sales/quote_item')), 'COUNT(*)') + ->join(array('quotes' => $this->getTable('sales/quote')), + 'quotes.entity_id = quote_items.quote_id AND quotes.is_active = 1', + array()) + ->where("quote_items.product_id = e.entity_id"); + + $this->getSelect() + ->columns(array("carts" => "({$countSelect})")) + ->group("e.{$this->getProductEntityId()}") + ->having('carts > ?', 0); + + return $this; + } + + /** + * Add orders count + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function addOrdersCount($from = '', $to = '') + { + $orderItemTableName = $this->getTable('sales/order_item'); + $productFieldName = sprintf('e.%s', $this->getProductEntityId()); + + $this->getSelect() + ->joinLeft( + array('order_items' => $orderItemTableName), + "order_items.product_id = {$productFieldName}", + array()) + ->columns(array('orders' => 'COUNT(order_items2.item_id)')) + ->group($productFieldName); + + $dateFilter = array('order_items2.item_id = order_items.item_id'); + if ($from != '' && $to != '') { + $dateFilter[] = $this->_prepareBetweenSql('order_items2.created_at', $from, $to); + } + + $this->getSelect() + ->joinLeft( + array('order_items2' => $orderItemTableName), + implode(' AND ', $dateFilter), + array() + ); + + return $this; + } + + /** + * Add ordered qty's + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function addOrderedQty($from = '', $to = '') + { + $adapter = $this->getConnection(); + $compositeTypeIds = Mage::getSingleton('catalog/product_type')->getCompositeTypes(); + $orderTableAliasName = $adapter->quoteIdentifier('order'); + + $orderJoinCondition = array( + $orderTableAliasName . '.entity_id = order_items.order_id', + $adapter->quoteInto("{$orderTableAliasName}.state <> ?", Mage_Sales_Model_Order::STATE_CANCELED), + + ); + + $productJoinCondition = array( + $adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds), + 'e.entity_id = order_items.product_id', + $adapter->quoteInto('e.entity_type_id = ?', $this->getProductEntityTypeId()) + ); + + if ($from != '' && $to != '') { + $fieldName = $orderTableAliasName . '.created_at'; + $orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to); + } + + $this->getSelect()->reset() + ->from( + array('order_items' => $this->getTable('sales/order_item')), + array( + 'ordered_qty' => 'SUM(order_items.qty_ordered)', + 'order_items_name' => 'order_items.name' + )) + ->joinInner( + array('order' => $this->getTable('sales/order')), + implode(' AND ', $orderJoinCondition), + array()) + ->joinLeft( + array('e' => $this->getProductEntityTableName()), + implode(' AND ', $productJoinCondition), + array( + 'entity_id' => 'order_items.product_id', + 'entity_type_id' => 'e.entity_type_id', + 'attribute_set_id' => 'e.attribute_set_id', + 'type_id' => 'e.type_id', + 'sku' => 'e.sku', + 'has_options' => 'e.has_options', + 'required_options' => 'e.required_options', + 'created_at' => 'e.created_at', + 'updated_at' => 'e.updated_at' + )) + ->group('order_items.product_id') + ->having('SUM(order_items.qty_ordered) > ?', 0); + return $this; + } + + /** + * Set order + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if (in_array($attribute, array('carts', 'orders', 'ordered_qty'))) { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + + return $this; + } + + /** + * Add views count + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function addViewsCount($from = '', $to = '') + { + /** + * Getting event type id for catalog_product_view event + */ + foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType) { + if ($eventType->getEventName() == 'catalog_product_view') { + $productViewEvent = (int)$eventType->getId(); + break; + } + } + + $this->getSelect()->reset() + ->from( + array('report_table_views' => $this->getTable('reports/event')), + array('views' => 'COUNT(report_table_views.event_id)')) + ->join(array('e' => $this->getProductEntityTableName()), + $this->getConnection()->quoteInto( + "e.entity_id = report_table_views.object_id AND e.entity_type_id = ?", + $this->getProductEntityTypeId())) + ->where('report_table_views.event_type_id = ?', $productViewEvent) + ->group('e.entity_id') + ->order('views ' . self::SORT_ORDER_DESC) + ->having('COUNT(report_table_views.event_id) > ?', 0); + + if ($from != '' && $to != '') { + $this->getSelect() + ->where('logged_at >= ?', $from) + ->where('logged_at <= ?', $to); + } + + $this->_useAnalyticFunction = true; + return $this; + } + + /** + * Prepare between sql + * + * @param string $fieldName Field name with table suffix ('created_at' or 'main_table.created_at') + * @param string $from + * @param string $to + * @return string Formatted sql string + */ + protected function _prepareBetweenSql($fieldName, $from, $to) + { + return sprintf('(%s BETWEEN %s AND %s)', + $fieldName, + $this->getConnection()->quote($from), + $this->getConnection()->quote($to) + ); + } + + /** + * Add store restrictions to product collection + * + * @param array $storeIds + * @param array $websiteIds + * @return Mage_Reports_Model_Resource_Product_Collection + */ + public function addStoreRestrictions($storeIds, $websiteIds) + { + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + if (!is_array($websiteIds)) { + $websiteIds = array($websiteIds); + } + + $filters = $this->_productLimitationFilters; + if (isset($filters['store_id'])) { + if (!in_array($filters['store_id'], $storeIds)) { + $this->addStoreFilter($filters['store_id']); + } else { + $this->addStoreFilter($this->getStoreId()); + } + } else { + $this->addWebsiteFilter($websiteIds); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Downloads/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Downloads/Collection.php new file mode 100755 index 0000000000..bd01f3bff3 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Downloads/Collection.php @@ -0,0 +1,123 @@ + + */ +class Mage_Reports_Model_Resource_Product_Downloads_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Identifier field name + * + * @var string + */ + protected $_idFieldName = 'link_id'; + + protected function _construct() + { + parent::_construct(); + + + } + /** + * Add downloads summary grouping by product + * + * @return Mage_Reports_Model_Resource_Product_Downloads_Collection + */ + public function addSummary() + { + $adapter = $this->getConnection(); + $linkExpr = $adapter->getIfNullSql('l_store.title', 'l.title'); + + $this->getSelect() + ->joinInner( + array('d' => $this->getTable('downloadable/link_purchased_item')), + 'e.entity_id = d.product_id', + array( + 'purchases' => new Zend_Db_Expr('SUM(d.number_of_downloads_bought)'), + 'downloads' => new Zend_Db_Expr('SUM(d.number_of_downloads_used)'), + )) + ->joinInner( + array('l' => $this->getTable('downloadable/link_title')), + 'd.link_id = l.link_id', + array('l.link_id')) + ->joinLeft( + array('l_store' => $this->getTable('downloadable/link_title')), + $adapter->quoteInto('l.link_id = l_store.link_id AND l_store.store_id = ?', (int)$this->getStoreId()), + array('link_title' => $linkExpr)) + ->where(implode(' OR ', array( + $adapter->quoteInto('d.number_of_downloads_bought > ?', 0), + $adapter->quoteInto('d.number_of_downloads_used > ?', 0), + ))) + ->group('d.link_id'); + /** + * Allow to use analytic function + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Add sorting + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Product_Downloads_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if ($attribute == 'purchases' || $attribute == 'downloads' || $attribute == 'link_title') { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + return $this; + } + + /** + * Add filtering + * + * @param string $field + * @param string $condition + * @return Mage_Reports_Model_Resource_Product_Downloads_Collection + */ + public function addFieldToFilter($field, $condition = null) + { + if ($field == 'link_title') { + $conditionSql = $this->_getConditionSql('l.title', $condition); + $this->getSelect()->where($conditionSql); + } else { + parent::addFieldToFilter($field, $condition); + } + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php new file mode 100755 index 0000000000..5207f4326c --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Abstract.php @@ -0,0 +1,228 @@ + + */ +abstract class Mage_Reports_Model_Resource_Product_Index_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Fields List for update in forsedSave + * + * @var array + */ + protected $_fieldsForUpdate = array('store_id', 'added_at'); + + /** + * Update Customer from visitor (Customer logged in) + * + * @param Mage_Reports_Model_Product_Index_Abstract $object + * @return Mage_Reports_Model_Resource_Product_Index_Abstract + */ + public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstract $object) + { + /** + * Do nothing if customer not logged in + */ + if (!$object->getCustomerId() || !$object->getVisitorId()) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('visitor_id = ?', $object->getVisitorId()); + + $rowSet = $select->query()->fetchAll(); + foreach ($rowSet as $row) { + + /* We need to determine if there are rows with known + customer for current product. + */ + + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('customer_id = ?', $object->getCustomerId()) + ->where('product_id = ?', $row['product_id']); + $idx = $adapter->fetchRow($select); + + if ($idx) { + /* If we are here it means that we have two rows: one with known customer, but second just visitor is set + * One row should be updated with customer_id, second should be deleted + * + */ + $adapter->delete($this->getMainTable(), array('index_id = ?' => $row['index_id'])); + $where = array('index_id = ?' => $idx['index_id']); + $data = array( + 'visitor_id' => $object->getVisitorId(), + 'store_id' => $object->getStoreId(), + 'added_at' => Varien_Date::now(), + ); + } else { + $where = array('index_id = ?' => $row['index_id']); + $data = array( + 'customer_id' => $object->getCustomerId(), + 'store_id' => $object->getStoreId(), + 'added_at' => Varien_Date::now() + ); + } + + $adapter->update($this->getMainTable(), $data, $where); + + } + return $this; + } + + /** + * Purge visitor data by customer (logout) + * + * @param Mage_Reports_Model_Product_Index_Abstract $object + * @return Mage_Reports_Model_Resource_Product_Index_Abstract + */ + public function purgeVisitorByCustomer(Mage_Reports_Model_Product_Index_Abstract $object) + { + /** + * Do nothing if customer not logged in + */ + if (!$object->getCustomerId()) { + return $this; + } + + $bind = array('visitor_id' => null); + $where = array('customer_id = ?' => (int)$object->getCustomerId()); + $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); + + return $this; + } + + /** + * Save Product Index data (forced save) + * + * @param Mage_Reports_Model_Product_Index_Abstract $object + * @return Mage_Reports_Model_Resource_Product_Index_Abstract + */ + public function save(Mage_Core_Model_Abstract $object) + { + if ($object->isDeleted()) { + return $this->delete($object); + } + + $this->_serializeFields($object); + $this->_beforeSave($object); + $this->_checkUnique($object); + + $data = $this->_prepareDataForSave($object); + unset($data[$this->getIdFieldName()]); + + $matchFields = array('product_id', 'store_id'); + + Mage::getResourceHelper('reports')->mergeVisitorProductIndex( + $this->getMainTable(), + $data, + $matchFields + ); + + + $this->unserializeFields($object); + $this->_afterSave($object); + + return $this; + } + + + /** + * Clean index (visitor) + * + * @return Mage_Reports_Model_Resource_Product_Index_Abstract + */ + public function clean() + { + while (true) { + $select = $this->_getReadAdapter()->select() + ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName())) + ->joinLeft( + array('visitor_table' => $this->getTable('log/visitor')), + 'main_table.visitor_id = visitor_table.visitor_id', + array()) + ->where('main_table.visitor_id > ?', 0) + ->where('visitor_table.visitor_id IS NULL') + ->limit(100); + $indexIds = $this->_getReadAdapter()->fetchCol($select); + + if (!$indexIds) { + break; + } + + $this->_getWriteAdapter()->delete( + $this->getMainTable(), + $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $indexIds) + ); + } + return $this; + } + + /** + * Add information about product ids to visitor/customer + * + * + * @param Mage_Reports_Model_Product_Index_Abstract $object + * @param array $productIds + * @return Mage_Reports_Model_Resource_Product_Index_Abstract + */ + public function registerIds(Varien_Object $object, $productIds) + { + $row = array( + 'visitor_id' => $object->getVisitorId(), + 'customer_id' => $object->getCustomerId(), + 'store_id' => $object->getStoreId(), + ); + $addedAt = Varien_Date::toTimestamp(true); + $data = array(); + foreach ($productIds as $productId) { + $productId = (int) $productId; + if ($productId) { + $row['product_id'] = $productId; + $row['added_at'] = Varien_Date::formatDate($addedAt); + $data[] = $row; + } + $addedAt -= ($addedAt > 0) ? 1 : 0; + } + + $matchFields = array('product_id', 'store_id'); + foreach ($data as $row) { + Mage::getResourceHelper('reports')->mergeVisitorProductIndex( + $this->getMainTable(), + $row, + $matchFields + ); + } + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php new file mode 100755 index 0000000000..d692cad91a --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php @@ -0,0 +1,145 @@ + + */ +abstract class Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Retrieve Product Index table name + * + */ + abstract protected function _getTableName() +; + + /** + * Join index table + * + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + */ + protected function _joinIdxTable() + { + if (!$this->getFlag('is_idx_table_joined')) { + $this->joinTable( + array('idx_table' => $this->_getTableName()), + 'product_id=entity_id', + array( + 'product_id' => 'product_id', + 'item_store_id' => 'store_id', + 'added_at' => 'added_at' + ), + $this->_getWhereCondition() + ); + $this->setFlag('is_idx_table_joined', true); + } + return $this; + } + + /** + * Add Viewed Products Index to Collection + * + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + */ + public function addIndexFilter() + { + $this->_joinIdxTable(); + $this->_productLimitationFilters['store_table'] = 'idx_table'; + $this->setFlag('url_data_object', true); + $this->setFlag('do_not_use_category_id', true); + return $this; + } + + /** + * Add filter by product ids + * + * @param array $ids + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + */ + public function addFilterByIds($ids) + { + if (empty($ids)) { + $this->getSelect()->where('1=0'); + } else { + $this->getSelect()->where('e.entity_id IN(?)', $ids); + } + return $this; + } + + /** + * Retrieve Where Condition to Index table + * + * @return array + */ + protected function _getWhereCondition() + { + $condition = array(); + + if (Mage::getSingleton('customer/session')->isLoggedIn()) { + $condition['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId(); + } else { + $condition['visitor_id'] = Mage::getSingleton('log/visitor')->getId(); + } + + return $condition; + } + + /** + * Add order by "added at" + * + * @param string $dir + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + */ + public function setAddedAtOrder($dir = self::SORT_ORDER_DESC) + { + if ($this->getFlag('is_idx_table_joined')) { + $this->getSelect()->order('added_at ' . $dir); + } + return $this; + } + + /** + * Add exclude Product Ids + * + * @param int|array $productIds + * @return Mage_Reports_Model_Resource_Product_Index_Collection_Abstract + */ + public function excludeProductIds($productIds) + { + if (empty($productIds)) { + return $this; + } + $this->_joinIdxTable(); + $this->getSelect()->where('idx_table.product_id NOT IN(?)', $productIds); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared.php new file mode 100755 index 0000000000..3fb5f01430 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared.php @@ -0,0 +1,45 @@ + + */ +class Mage_Reports_Model_Resource_Product_Index_Compared extends Mage_Reports_Model_Resource_Product_Index_Abstract +{ + /** + * Initialize connection and main resource table + * + */ + protected function _construct() + { + $this->_init('reports/compared_product_index', 'index_id'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared/Collection.php new file mode 100755 index 0000000000..e6ee0b6b30 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Compared/Collection.php @@ -0,0 +1,47 @@ + + */ +class Mage_Reports_Model_Resource_Product_Index_Compared_Collection + extends Mage_Reports_Model_Resource_Product_Index_Collection_Abstract +{ + /** + * Retrieve Product Index table name + * + * @return string + */ + protected function _getTableName() + { + return $this->getTable('reports/compared_product_index'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed.php new file mode 100755 index 0000000000..06fcc6c7d4 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed.php @@ -0,0 +1,45 @@ + + */ +class Mage_Reports_Model_Resource_Product_Index_Viewed extends Mage_Reports_Model_Resource_Product_Index_Abstract +{ + /** + * Initialize connection and main resource table + * + */ + protected function _construct() + { + $this->_init('reports/viewed_product_index', 'index_id'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed/Collection.php new file mode 100755 index 0000000000..3864e72307 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Viewed/Collection.php @@ -0,0 +1,47 @@ + + */ +class Mage_Reports_Model_Resource_Product_Index_Viewed_Collection + extends Mage_Reports_Model_Resource_Product_Index_Collection_Abstract +{ + /** + * Retrieve Product Index table name + * + * @return string + */ + protected function _getTableName() + { + return $this->getTable('reports/viewed_product_index'); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Lowstock/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Lowstock/Collection.php new file mode 100755 index 0000000000..c4429719b2 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Lowstock/Collection.php @@ -0,0 +1,242 @@ + + */ +class Mage_Reports_Model_Resource_Product_Lowstock_Collection extends Mage_Reports_Model_Resource_Product_Collection +{ + /** + * CatalogInventory Stock Item Resource instance + * + * @var Mage_CatalogInventory_Model_Resource_Stock_Item + */ + protected $_inventoryItemResource = null; + + /** + * Flag about is joined CatalogInventory Stock Item + * + * @var bool + */ + protected $_inventoryItemJoined = false; + + /** + * Alias for CatalogInventory Stock Item Table + * + * @var string + */ + protected $_inventoryItemTableAlias = 'lowstock_inventory_item'; + + /** + * Retrieve CatalogInventory Stock Item Resource instance + * + * @return Mage_CatalogInventory_Model_Resource_Stock_Item + */ + protected function _getInventoryItemResource() + { + if ($this->_inventoryItemResource === null) { + $this->_inventoryItemResource = Mage::getResourceSingleton('cataloginventory/stock_item'); + } + return $this->_inventoryItemResource; + } + + /** + * Retrieve CatalogInventory Stock Item Table + * + * @return string + */ + protected function _getInventoryItemTable() + { + return $this->_getInventoryItemResource()->getMainTable(); + } + + /** + * Retrieve CatalogInventory Stock Item Table Id field name + * + * @return string + */ + protected function _getInventoryItemIdField() + { + return $this->_getInventoryItemResource()->getIdFieldName(); + } + + /** + * Retrieve alias for CatalogInventory Stock Item Table + * + * @return string + */ + protected function _getInventoryItemTableAlias() + { + return $this->_inventoryItemTableAlias; + } + + /** + * Add catalog inventory stock item field to select + * + * @param string $field + * @param string $alias + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + protected function _addInventoryItemFieldToSelect($field, $alias = null) + { + if (empty($alias)) { + $alias = $field; + } + + if (isset($this->_joinFields[$alias])) { + return $this; + } + + $this->_joinFields[$alias] = array( + 'table' => $this->_getInventoryItemTableAlias(), + 'field' => $field + ); + + $this->getSelect()->columns(array($alias => $field), $this->_getInventoryItemTableAlias()); + return $this; + } + + /** + * Retrieve catalog inventory stock item field correlation name + * + * @param string $field + * @return string + */ + protected function _getInventoryItemField($field) + { + return sprintf('%s.%s', $this->_getInventoryItemTableAlias(), $field); + } + + /** + * Join catalog inventory stock item table for further stock_item values filters + * + * @param unknown_type $fields + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + public function joinInventoryItem($fields = array()) + { + if (!$this->_inventoryItemJoined) { + $this->getSelect()->join( + array($this->_getInventoryItemTableAlias() => $this->_getInventoryItemTable()), + sprintf('e.%s = %s.product_id', + $this->getEntity()->getEntityIdField(), + $this->_getInventoryItemTableAlias() + ), + array() + ); + $this->_inventoryItemJoined = true; + } + + if (!is_array($fields)) { + if (empty($fields)) { + $fields = array(); + } else { + $fields = array($fields); + } + } + + foreach ($fields as $alias => $field) { + if (!is_string($alias)) { + $alias = null; + } + $this->_addInventoryItemFieldToSelect($field, $alias); + } + + return $this; + } + + /** + * Add filter by product type(s) + * + * @param array|string $typeFilter + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + public function filterByProductType($typeFilter) + { + if (!is_string($typeFilter) && !is_array($typeFilter)) { + Mage::throwException( + Mage::helper('catalog')->__('Wrong product type filter specified') + ); + } + $this->addAttributeToFilter('type_id', $typeFilter); + return $this; + } + + /** + * Add filter by product types from config + * Only types witch has QTY parameter + * + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + public function filterByIsQtyProductTypes() + { + $this->filterByProductType( + array_keys(array_filter(Mage::helper('cataloginventory')->getIsQtyTypeIds())) + ); + return $this; + } + + /** + * Add Use Manage Stock Condition to collection + * + * @param int|null $storeId + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + public function useManageStockFilter($storeId = null) + { + $this->joinInventoryItem(); + $manageStockExpr = $this->getConnection()->getCheckSql( + $this->_getInventoryItemField('use_config_manage_stock') . ' = 1', + (int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId), + $this->_getInventoryItemField('manage_stock') + ); + $this->getSelect()->where($manageStockExpr . ' = ?', 1); + return $this; + } + + /** + * Add Notify Stock Qty Condition to collection + * + * @param int $storeId + * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection + */ + public function useNotifyStockQtyFilter($storeId = null) + { + $this->joinInventoryItem(array('qty')); + $notifyStockExpr = $this->getConnection()->getCheckSql( + $this->_getInventoryItemField('use_config_notify_stock_qty') . ' = 1', + (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY, $storeId), + $this->_getInventoryItemField('notify_stock_qty') + ); + $this->getSelect()->where('qty < ?', $notifyStockExpr); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Ordered/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Ordered/Collection.php new file mode 100755 index 0000000000..840fec7365 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Ordered/Collection.php @@ -0,0 +1,80 @@ + + */ +class Mage_Reports_Model_Resource_Product_Ordered_Collection extends Mage_Reports_Model_Resource_Product_Collection +{ + /** + * Join fields + * + * @param int $from + * @param int $to + * @return Mage_Reports_Model_Resource_Product_Ordered_Collection + */ + protected function _joinFields($from = '', $to = '') + { + $this->addAttributeToSelect('*') + ->addOrderedQty($from, $to) + ->setOrder('ordered_qty', self::SORT_ORDER_DESC); + + return $this; + } + + /** + * Enter description here ... + * + * @param int $from + * @param int $to + * @return Mage_Reports_Model_Resource_Product_Ordered_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->_joinFields($from, $to); + return $this; + } + + /** + * Set store ids + * + * @param array s$storeIds + * @return Mage_Reports_Model_Resource_Product_Ordered_Collection + */ + public function setStoreIds($storeIds) + { + $storeId = array_pop($storeIds); + $this->setStoreId($storeId); + $this->addStoreFilter($storeId); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Sold/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Sold/Collection.php new file mode 100755 index 0000000000..b30b0bccd1 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Sold/Collection.php @@ -0,0 +1,91 @@ + + */ +class Mage_Reports_Model_Resource_Product_Sold_Collection extends Mage_Reports_Model_Resource_Product_Collection +{ + /** + * Set Date range to collection + * + * @param int $from + * @param int $to + * @return Mage_Reports_Model_Resource_Product_Sold_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->addAttributeToSelect('*') + ->addOrderedQty($from, $to) + ->setOrder('ordered_qty', self::SORT_ORDER_DESC); + + return $this; + } + + /** + * Set store filter to collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Product_Sold_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->getSelect()->where('order_items.store_id IN (?)', (array)$storeIds); + } + return $this; + } + + /** + * Add website product limitation + * + * @return Mage_Reports_Model_Resource_Product_Sold_Collection + */ + protected function _productLimitationJoinWebsite() + { + $filters = $this->_productLimitationFilters; + $conditions = array('product_website.product_id=e.entity_id'); + if (isset($filters['website_ids'])) { + $conditions[] = $this->getConnection() + ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']); + + $subQuery = $this->getConnection()->select() + ->from(array('product_website' => $this->getTable('catalog/product_website')), + array('product_website.product_id') + ) + ->where(join(' AND ', $conditions)); + $this->getSelect()->where('e.entity_id IN( '.$subQuery.' )'); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Viewed/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Product/Viewed/Collection.php new file mode 100755 index 0000000000..4f228527c3 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Viewed/Collection.php @@ -0,0 +1,78 @@ + + */ +class Mage_Reports_Model_Resource_Product_Viewed_Collection extends Mage_Reports_Model_Resource_Product_Collection +{ + /** + * Join fields + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Product_Viewed_Collection + */ + protected function _joinFields($from = '', $to = '') + { + $this->addAttributeToSelect('*') + ->addViewsCount($from, $to); + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Product_Viewed_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->_joinFields($from, $to); + return $this; + } + + /** + * Set store ids + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Product_Viewed_Collection + */ + public function setStoreIds($storeIds) + { + $storeId = array_pop($storeIds); + $this->setStoreId($storeId); + $this->addStoreFilter($storeId); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Quote/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Quote/Collection.php new file mode 100755 index 0000000000..4f435d4213 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Quote/Collection.php @@ -0,0 +1,295 @@ + + */ +class Mage_Reports_Model_Resource_Quote_Collection extends Mage_Sales_Model_Resource_Quote_Collection +{ + + const SELECT_COUNT_SQL_TYPE_CART = 1; + + protected $_selectCountSqlType = 0; + + /** + * Join fields + * + * @var array + */ + protected $_joinedFields = array(); + + /** + * Map + * + * @var array + */ + protected $_map = array('fields' => array('store_id' => 'main_table.store_id')); + + /** + * Set type for COUNT SQL select + * + * @param int $type + * @return Mage_Reports_Model_Mysql4_Quote_Collection + */ + public function setSelectCountSqlType($type) + { + $this->_selectCountSqlType = $type; + return $this; + } + + protected function _construct() + { + parent::_construct(); + /** + * Allow to use analytic function + */ + $this->_useAnalyticFunction = true; + } + + + /** + * Prepare for abandoned report + * + * @param array $storeIds + * @param string $filter + * @return Mage_Reports_Model_Resource_Quote_Collection + */ + public function prepareForAbandonedReport($storeIds, $filter = null) + { + $this->addFieldToFilter('items_count', array('neq' => '0')) + ->addFieldToFilter('main_table.is_active', '1') + ->addSubtotal($storeIds, $filter) + ->addCustomerData($filter) + ->setOrder('updated_at'); + if (is_array($storeIds)) { + $this->addFieldToFilter('store_id', array('in' => $storeIds)); + } + + + return $this; + } + + /** + * Prepare select query for products in carts report + * + * @return Mage_Reports_Model_Resource_Quote_Collection + */ + public function prepareForProductsInCarts() + { + $productEntity = Mage::getResourceSingleton('catalog/product_collection'); + $productAttrName = $productEntity->getAttribute('name'); + $productAttrNameId = (int) $productAttrName->getAttributeId(); + $productAttrNameTable = $productAttrName->getBackend()->getTable(); + $productAttrPrice = $productEntity->getAttribute('price'); + $productAttrPriceId = (int) $productAttrPrice->getAttributeId(); + $productAttrPriceTable = $productAttrPrice->getBackend()->getTable(); + + $ordersSubSelect = clone $this->getSelect(); + $ordersSubSelect->reset() + ->from( + array('oi' => $this->getTable('sales/order_item')), + array( + 'orders' => new Zend_Db_Expr('COUNT(1)'), + 'product_id')) + ->group('oi.product_id'); + + $this->getSelect() + ->useStraightJoin(true) + ->reset(Zend_Db_Select::COLUMNS) + ->joinInner( + array('quote_items' => $this->getTable('sales/quote_item')), + 'quote_items.quote_id = main_table.entity_id', + null) + ->joinInner( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = quote_items.product_id', + null) + ->joinInner( + array('product_name' => $productAttrNameTable), + "product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}", + array('name'=>'product_name.value')) + ->joinInner( + array('product_price' => $productAttrPriceTable), + "product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}", + array('price'=>'product_price.value')) + ->joinLeft( + array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))), + 'order_items.product_id = e.entity_id', + array() + ) + ->columns('e.*') + ->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)'))) + ->columns('order_items.orders') + ->where('main_table.is_active = ?', 1) + ->group('quote_items.product_id'); + + return $this; + } + + /** + * Add store ids to filter + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Quote_Collection + */ + public function addStoreFilter($storeIds) + { + $this->addFieldToFilter('store_id', array('in' => $storeIds)); + return $this; + } + + /** + * Add customer data + * + * @param unknown_type $filter + * @return Mage_Reports_Model_Resource_Quote_Collection + */ + public function addCustomerData($filter = null) + { + $customerEntity = Mage::getResourceSingleton('customer/customer'); + $attrFirstname = $customerEntity->getAttribute('firstname'); + $attrFirstnameId = (int) $attrFirstname->getAttributeId(); + $attrFirstnameTableName = $attrFirstname->getBackend()->getTable(); + + $attrLastname = $customerEntity->getAttribute('lastname'); + $attrLastnameId = (int) $attrLastname->getAttributeId(); + $attrLastnameTableName = $attrLastname->getBackend()->getTable(); + + $attrEmail = $customerEntity->getAttribute('email'); + $attrEmailTableName = $attrEmail->getBackend()->getTable(); + + $adapter = $this->getSelect()->getAdapter(); + $customerName = $adapter->getConcatSql(array('cust_fname.value', 'cust_lname.value'), ' '); + $this->getSelect() + ->joinInner( + array('cust_email' => $attrEmailTableName), + 'cust_email.entity_id = main_table.customer_id', + array('email' => 'cust_email.email') + ) + ->joinInner( + array('cust_fname' => $attrFirstnameTableName), + implode(' AND ', array( + 'cust_fname.entity_id = main_table.customer_id', + $adapter->quoteInto('cust_fname.attribute_id = ?', (int)$attrFirstnameId), + )), + array('firstname' => 'cust_fname.value') + ) + ->joinInner( + array('cust_lname' => $attrLastnameTableName), + implode(' AND ', array( + 'cust_lname.entity_id = main_table.customer_id', + $adapter->quoteInto('cust_lname.attribute_id = ?', (int)$attrLastnameId) + )), + array( + 'lastname' => 'cust_lname.value', + 'customer_name' => $customerName + ) + ); + + $this->_joinedFields['customer_name'] = $customerName; + $this->_joinedFields['email'] = 'cust_email.email'; + + if ($filter) { + if (isset($filter['customer_name'])) { + $likeExpr = '%' . $filter['customer_name'] . '%'; + $this->getSelect()->where($this->_joinedFields['customer_name'] . ' LIKE ?', $likeExpr); + } + if (isset($filter['email'])) { + $likeExpr = '%' . $filter['email'] . '%'; + $this->getSelect()->where($this->_joinedFields['email'] . ' LIKE ?', $likeExpr); + } + } + + return $this; + } + + /** + * Add subtotals + * + * @param array $storeIds + * @param array $filter + * @return Mage_Reports_Model_Resource_Quote_Collection + */ + public function addSubtotal($storeIds = '', $filter = null) + { + if (is_array($storeIds)) { + $this->getSelect()->columns(array( + 'subtotal' => '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)' + )); + $this->_joinedFields['subtotal'] = + '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'; + } else { + $this->getSelect()->columns(array('subtotal' => 'main_table.base_subtotal_with_discount')); + $this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount'; + } + + if ($filter && is_array($filter) && isset($filter['subtotal'])) { + if (isset($filter['subtotal']['from'])) { + $this->getSelect()->where( + $this->_joinedFields['subtotal'] . ' >= ?', + $filter['subtotal']['from'], Zend_Db::FLOAT_TYPE + ); + } + if (isset($filter['subtotal']['to'])) { + $this->getSelect()->where( + $this->_joinedFields['subtotal'] . ' <= ?', + $filter['subtotal']['to'], Zend_Db::FLOAT_TYPE + ); + } + } + + return $this; + } + + /** + * Get select count sql + * + * @return unknown + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->resetJoinLeft(); + + if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) { + $countSelect->columns("COUNT(DISTINCT e.entity_id)"); + } else { + $countSelect->columns("COUNT(DISTINCT main_table.entity_id)"); + } + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Refunded/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Refunded/Collection.php new file mode 100755 index 0000000000..6b42ff46b1 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Refunded/Collection.php @@ -0,0 +1,117 @@ + + */ +class Mage_Reports_Model_Resource_Refunded_Collection extends Mage_Sales_Model_Entity_Order_Collection +{ + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Refunded_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->addAttributeToSelect('*') + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) + ->addExpressionAttributeToSelect('orders', 'COUNT({{total_refunded}})', array('total_refunded')); + + $this->getSelect() + ->where('base_total_refunded > ?', 0) + ->group('("*")') + ->having('orders > ?', 0); + + return $this; + } + + /** + * Set store filter to collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Refunded_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)) + ->addExpressionAttributeToSelect( + 'refunded', + 'SUM({{base_total_refunded}})', + array('base_total_refunded')) + ->addExpressionAttributeToSelect( + 'online_refunded', + 'SUM({{base_total_online_refunded}})', + array('base_total_online_refunded')) + ->addExpressionAttributeToSelect( + 'offline_refunded', + 'SUM({{base_total_offline_refunded}})', + array('base_total_offline_refunded')); + } else { + $this->addExpressionAttributeToSelect( + 'refunded', + 'SUM({{base_total_refunded}}*{{base_to_global_rate}})', + array('base_total_refunded', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'online_refunded', + 'SUM({{base_total_online_refunded}}*{{base_to_global_rate}})', + array('base_total_online_refunded', 'base_to_global_rate')) + ->addExpressionAttributeToSelect( + 'offline_refunded', + 'SUM({{base_total_offline_refunded}}*{{base_to_global_rate}})', + array('base_total_offline_refunded', 'base_to_global_rate')); + } + + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns('COUNT(*)'); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php new file mode 100755 index 0000000000..521eb7b915 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php @@ -0,0 +1,359 @@ + + */ +abstract class Mage_Reports_Model_Resource_Report_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Flag object + * + * @var Mage_Reports_Model_Flag + */ + protected $_flag = null; + + /** + * Retrive flag object + * + * @return Mage_Reports_Model_Flag + */ + protected function _getFlag() + { + if ($this->_flag === null) { + $this->_flag = Mage::getModel('reports/flag'); + } + return $this->_flag; + } + + /** + * Saves flag + * + * @param string $code + * @param mixed $value + * @return Mage_Reports_Model_Resource_Report_Abstract + */ + protected function _setFlagData($code, $value = null) + { + $this->_getFlag() + ->setReportFlagCode($code) + ->unsetData() + ->loadSelf(); + + if ($value !== null) { + $this->_getFlag()->setFlagData($value); + } + + $time = Varien_Date::toTimestamp(true); + // touch last_update + $this->_getFlag()->setLastUpdate($this->formatDate($time)); + + $this->_getFlag()->save(); + + return $this; + } + + /** + * Retrieve flag data + * + * @param string $code + * @return mixed + */ + protected function _getFlagData($code) + { + $this->_getFlag() + ->setReportFlagCode($code) + ->unsetData() + ->loadSelf(); + + return $this->_getFlag()->getFlagData(); + } + + /** + * Trancate table + * + * @param string $table + * @return Mage_Reports_Model_Resource_Report_Abstract + */ + protected function _truncateTable($table) + { + $this->_getWriteAdapter()->truncateTable($table); + return $this; + } + + /** + * Clear report table by specified date range. + * If specified source table parameters, + * condition will be generated by source table subselect. + * + * @param string $table + * @param string|null $from + * @param string|null $to + * @param Zend_Db_Select|string|null $subSelect + * @param unknown_type $doNotUseTruncate + * @return Mage_Reports_Model_Resource_Report_Abstract + */ + protected function _clearTableByDateRange($table, $from = null, $to = null, $subSelect = null, + $doNotUseTruncate = false) + { + if ($from === null && $to === null && !$doNotUseTruncate) { + $this->_truncateTable($table); + return $this; + } + + if ($subSelect !== null) { + $deleteCondition = $this->_makeConditionFromDateRangeSelect($subSelect, 'period'); + } else { + $condition = array(); + if ($from !== null) { + $condition[] = $this->_getWriteAdapter()->quoteInto('period >= ?', $from); + } + + if ($to !== null) { + $condition[] = $this->_getWriteAdapter()->quoteInto('period <= ?', $to); + } + $deleteCondition = implode(' AND ', $condition); + } + $this->_getWriteAdapter()->delete($table, $deleteCondition); + return $this; + } + + /** + * Generate table date range select + * + * @param string $table + * @param string $column + * @param string $whereColumn + * @param string|null $from + * @param string|null $to + * @param array $additionalWhere + * @param unknown_type $alias + * @return Varien_Db_Select + */ + protected function _getTableDateRangeSelect($table, $column, $whereColumn, $from = null, $to = null, + $additionalWhere = array(), $alias = 'date_range_table') + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from( + array($alias => $table), + $adapter->getDatePartSql($adapter->quoteIdentifier($alias . '.' . $column)) + ) + ->distinct(true); + + if ($from !== null) { + $select->where($alias . '.' . $whereColumn . ' >= ?', $from); + } + + if ($to !== null) { + $select->where($alias . '.' . $whereColumn . ' <= ?', $to); + } + + if (!empty($additionalWhere)) { + foreach ($additionalWhere as $condition) { + if (is_array($condition) && count($condition) == 2) { + $condition = $adapter->quoteInto($condition[0], $condition[1]); + } elseif (is_array($condition)) { // Invalid condition + continue; + } + $condition = str_replace('{{table}}', $adapter->quoteIdentifier($alias), $condition); + $select->where($condition); + } + } + + return $select; + } + + /** + * Make condition for using in where section + * from select statement with single date column + * + * @result string|false + * + * @param Varien_Db_Select $select + * @param string $periodColumn + * @return unknown + */ + protected function _makeConditionFromDateRangeSelect($select, $periodColumn) + { + static $selectResultCache = array(); + $cacheKey = (string)$select; + + if (!array_key_exists($cacheKey, $selectResultCache)) { + try { + $selectResult = array(); + $query = $this->_getReadAdapter()->query($select); + while ($date = $query->fetchColumn()) { + $selectResult[] = $date; + } + } catch (Exception $e) { + $selectResult = false; + } + $selectResultCache[$cacheKey] = $selectResult; + } else { + $selectResult = $selectResultCache[$cacheKey]; + } + if ($selectResult === false) { + return false; + } + + $whereCondition = array(); + $adapter = $this->_getReadAdapter(); + foreach ($selectResult as $date) { + $date = substr($date, 0, 10); // to fix differences in oracle + $whereCondition[] = sprintf("%s BETWEEN '%s' AND '%s'", + $periodColumn, "{$date} 00:00:00", "{$date} 23:59:59"); + } + $whereCondition = implode(' OR ', $whereCondition); + if ($whereCondition == '') { + $whereCondition = '1=0'; // FALSE condition! + } + + return $whereCondition; + } + + /** + * Generate table date range select + * + * @param string $table + * @param string $relatedTable + * @param array $joinCondition + * @param string $column + * @param string $whereColumn + * @param string|null $from + * @param string|null $to + * @param array $additionalWhere + * @param unknown_type $alias + * @param unknown_type $relatedAlias + * @return Varien_Db_Select + */ + protected function _getTableDateRangeRelatedSelect($table, $relatedTable, $joinCondition, $column, $whereColumn, + $from = null, $to = null, $additionalWhere = array(), $alias = 'date_range_table', + $relatedAlias = 'related_date_range_table') + { + $adapter = $this->_getReadAdapter(); + $joinConditionSql = array(); + + foreach ($joinCondition as $fkField => $pkField) { + $joinConditionSql[] = sprintf('%s.%s = %s.%s', $alias, $fkField, $relatedAlias, $pkField); + } + + $select = $adapter->select() + ->from( + array($alias => $table), + $adapter->getDatePartSql( + $adapter->quoteIdentifier($alias . '.' . $column) + ) + ) + ->joinInner( + array($relatedAlias => $relatedTable), + implode(' AND ', $joinConditionSql), + array() + ) + ->distinct(true); + + if ($from !== null) { + $select->where($relatedAlias . '.' . $whereColumn . ' >= ?', $from); + } + + if ($to !== null) { + $select->where($relatedAlias . '.' . $whereColumn . ' <= ?', $to); + } + + if (!empty($additionalWhere)) { + foreach ($additionalWhere as $condition) { + if (is_array($condition) && count($condition) == 2) { + $condition = $adapter->quoteInto($condition[0], $condition[1]); + } elseif (is_array($condition)) { // Invalid condition + continue; + } + $condition = str_replace( + array('{{table}}', '{{related_table}}'), + array( + $adapter->quoteIdentifier($alias), + $adapter->quoteIdentifier($relatedAlias) + ), + $condition + ); + $select->where($condition); + } + } + + return $select; + } + + /** + * Check range dates and transforms it to strings + * + * @param mixed $from + * @param mixed $to + * @return Mage_Reports_Model_Resource_Report_Abstract + */ + protected function _checkDates(&$from, &$to) + { + if ($from !== null) { + $from = $this->formatDate($from); + } + + if ($to !== null) { + $to = $this->formatDate($to); + } + + return $this; + } + + /** + * Retrieve store timezone offset from UTC in the form acceptable by SQL's CONVERT_TZ() + * + * @param unknown_type $store + * @return string + */ + protected function _getStoreTimezoneUtcOffset($store = null) + { + return Mage::app()->getLocale()->storeDate($store)->toString(Zend_Date::GMT_DIFF_SEP); + } + + /** + * Retrieve date in UTC timezone + * + * @param unknown_type $date + * @return Zend_Date|null + */ + protected function _dateToUtc($date) + { + if ($date === null) { + return null; + } + $dateUtc = new Zend_Date($date); + $dateUtc->setTimezone('Etc/UTC'); + return $dateUtc; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php new file mode 100755 index 0000000000..93c6382670 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php @@ -0,0 +1,313 @@ + + */ +class Mage_Reports_Model_Resource_Report_Collection +{ + /** + * From value + * + * @var string + */ + protected $_from; + + /** + * To value + * + * @var string + */ + protected $_to; + + /** + * Report period + * + * @var int + */ + protected $_period; + + /** + * Model object + * + * @var string + */ + protected $_model; + + /** + * Intervals + * + * @var int + */ + protected $_intervals; + + /** + * Page size + * + * @var int + */ + protected $_pageSize; + + /** + * Array of store ids + * + * @var array + */ + protected $_storeIds; + + /** + * Resource initialization + * + */ + protected function _construct() + { + + } + + /** + * Set period + * + * @param int $period + * @return Mage_Reports_Model_Resource_Report_Collection + */ + public function setPeriod($period) + { + $this->_period = $period; + return $this; + } + + /** + * Set interval + * + * @param int $from + * @param int $to + * @return Mage_Reports_Model_Resource_Report_Collection + */ + public function setInterval($from, $to) + { + $this->_from = $from; + $this->_to = $to; + + return $this; + } + + /** + * Get intervals + * + * @return unknown + */ + public function getIntervals() + { + if (!$this->_intervals) { + $this->_intervals = array(); + if (!$this->_from && !$this->_to) { + return $this->_intervals; + } + $dateStart = new Zend_Date($this->_from); + $dateEnd = new Zend_Date($this->_to); + + + $t = array(); + $firstInterval = true; + while ($dateStart->compare($dateEnd) <= 0) { + + switch ($this->_period) { + case 'day': + $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat()); + $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss'); + $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59'); + $dateStart->addDay(1); + break; + case 'month': + $t['title'] = $dateStart->toString('MM/yyyy'); + $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') + : $dateStart->toString('yyyy-MM-01 00:00:00'); + + $lastInterval = ($dateStart->compareMonth($dateEnd->getMonth()) == 0); + + $t['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay()) + ->toString('yyyy-MM-dd 23:59:59') + : $dateStart->toString('yyyy-MM-'.date('t', $dateStart->getTimestamp()).' 23:59:59'); + + $dateStart->addMonth(1); + + if ($dateStart->compareMonth($dateEnd->getMonth()) == 0) { + $dateStart->setDay(1); + } + + $firstInterval = false; + break; + case 'year': + $t['title'] = $dateStart->toString('yyyy'); + $t['start'] = ($firstInterval) ? $dateStart->toString('yyyy-MM-dd 00:00:00') + : $dateStart->toString('yyyy-01-01 00:00:00'); + + $lastInterval = ($dateStart->compareYear($dateEnd->getYear()) == 0); + + $t['end'] = ($lastInterval) ? $dateStart->setMonth($dateEnd->getMonth()) + ->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') + : $dateStart->toString('yyyy-12-31 23:59:59'); + $dateStart->addYear(1); + + if ($dateStart->compareYear($dateEnd->getYear()) == 0) { + $dateStart->setMonth(1)->setDay(1); + } + + $firstInterval = false; + break; + } + $this->_intervals[$t['title']] = $t; + } + } + return $this->_intervals; + } + + /** + * Return date periods + * + * @return array + */ + public function getPeriods() + { + return array( + 'day' => Mage::helper('reports')->__('Day'), + 'month' => Mage::helper('reports')->__('Month'), + 'year' => Mage::helper('reports')->__('Year') + ); + } + + /** + * Set store ids + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Report_Collection + */ + public function setStoreIds($storeIds) + { + $this->_storeIds = $storeIds; + return $this; + } + + /** + * Get store ids + * + * @return arrays + */ + public function getStoreIds() + { + return $this->_storeIds; + } + + /** + * Get size + * + * @return int + */ + public function getSize() + { + return count($this->getIntervals()); + } + + /** + * Set page size + * + * @param int $size + * @return Mage_Reports_Model_Resource_Report_Collection + */ + public function setPageSize($size) + { + $this->_pageSize = $size; + return $this; + } + + /** + * Get page size + * + * @return int + */ + public function getPageSize() + { + return $this->_pageSize; + } + + /** + * Init report + * + * @param string $modelClass + * @return Mage_Reports_Model_Resource_Report_Collection + */ + public function initReport($modelClass) + { + $this->_model = Mage::getModel('reports/report') + ->setPageSize($this->getPageSize()) + ->setStoreIds($this->getStoreIds()) + ->initCollection($modelClass); + + return $this; + } + + /** + * get report full + * + * @param int $from + * @param int $to + * @return unknown + */ + public function getReportFull($from, $to) + { + return $this->_model->getReportFull($this->timeShift($from), $this->timeShift($to)); + } + + /** + * Get report + * + * @param int $from + * @param int $to + * @return Varien_Object + */ + public function getReport($from, $to) + { + return $this->_model->getReport($this->timeShift($from), $this->timeShift($to)); + } + + /** + * Retreive time shift + * + * @param string $datetime + * @return string + */ + public function timeShift($datetime) + { + return Mage::app()->getLocale() + ->utcDate(null, $datetime, true, Varien_Date::DATETIME_INTERNAL_FORMAT) + ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Review/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Review/Collection.php new file mode 100755 index 0000000000..6463db8ee7 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Review/Collection.php @@ -0,0 +1,105 @@ + + */ +class Mage_Reports_Model_Resource_Review_Collection extends Mage_Review_Model_Resource_Review_Collection +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('review/review'); + } + + /** + * add product filter + * + * @param unknown_type $productId + * @return Mage_Reports_Model_Resource_Review_Collection + */ + public function addProductFilter($productId) + { + $this->addFieldToFilter('entity_pk_value', array('eq' => (int)$productId)); + + return $this; + } + + /** + * Reset select + * + * @return Mage_Reports_Model_Resource_Review_Collection + */ + public function resetSelect() + { + parent::resetSelect(); + $this->_joinFields(); + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->_select; + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->columns("COUNT(main_table.review_id)"); + + return $countSelect; + } + + /** + * Set order + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Review_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if (in_array($attribute, array('nickname', 'title', 'detail', 'created_at'))) { + $this->_select->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + + return $this; + } +} 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 new file mode 100755 index 0000000000..590424d09b --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Review/Customer/Collection.php @@ -0,0 +1,120 @@ + + */ +class Mage_Reports_Model_Resource_Review_Customer_Collection extends Mage_Review_Model_Resource_Review_Collection +{ + /** + * Join customers + * + * @return Mage_Reports_Model_Resource_Review_Customer_Collection + */ + public function joinCustomers() + { + /** + * Allow to use analytic function to result select + */ + $this->_useAnalyticFunction = true; + + /** @var $adapter Varien_Db_Adapter_Interface */ + $adapter = $this->getConnection(); + /** @var $customer Mage_Customer_Model_Resource_Customer */ + $customer = Mage::getResourceSingleton('customer/customer'); + /** @var $firstnameAttr Mage_Eav_Model_Entity_Attribute */ + $firstnameAttr = $customer->getAttribute('firstname'); + /** @var $lastnameAttr Mage_Eav_Model_Entity_Attribute */ + $lastnameAttr = $customer->getAttribute('lastname'); + + $firstnameCondition = array('table_customer_firstname.entity_id = detail.customer_id'); + + if ($firstnameAttr->getBackend()->isStatic()) { + $firstnameField = 'firstname'; + } else { + $firstnameField = 'value'; + $firstnameCondition[] = $adapter->quoteInto('table_customer_firstname.attribute_id = ?', + (int)$firstnameAttr->getAttributeId()); + } + + $this->getSelect()->joinInner( + array('table_customer_firstname' => $firstnameAttr->getBackend()->getTable()), + implode(' AND ', $firstnameCondition), + array()); + + + $lastnameCondition = array('table_customer_lastname.entity_id = detail.customer_id'); + if ($lastnameAttr->getBackend()->isStatic()) { + $lastnameField = 'lastname'; + } else { + $lastnameField = 'value'; + $lastnameCondition[] = $adapter->quoteInto('table_customer_lastname.attribute_id = ?', + (int)$lastnameAttr->getAttributeId()); + } + + //Prepare fullname field result + $customerFullname = $adapter->getConcatSql(array( + "table_customer_firstname.{$firstnameField}", + "table_customer_lastname.{$lastnameField}" + ), ' '); + $this->getSelect()->reset(Zend_Db_Select::COLUMNS) + ->joinInner( + array('table_customer_lastname' => $lastnameAttr->getBackend()->getTable()), + implode(' AND ', $lastnameCondition), + array()) + ->columns(array( + 'customer_name' => $customerFullname, + 'review_cnt' => 'COUNT(main_table.review_id)')) + ->group('detail.customer_id'); + + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->_select; + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + + $countSelect->columns(new Zend_Db_Expr('COUNT(DISTINCT detail.customer_id)')); + + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php new file mode 100755 index 0000000000..6043b418a1 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php @@ -0,0 +1,109 @@ + + */ +class Mage_Reports_Model_Resource_Review_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + protected function _construct() + { + parent::_construct(); + $this->_useAnalyticFunction = true; + } + /** + * Join review table to result + * + * @return Mage_Reports_Model_Resource_Review_Product_Collection + */ + public function joinReview() + { + $helper = Mage::getResourceHelper('core'); + + $subSelect = clone $this->getSelect(); + $subSelect->reset() + ->from(array('rev' => $this->getTable('review/review')), 'COUNT(DISTINCT rev.review_id)') + ->where('e.entity_id = rev.entity_pk_value'); + + $this->addAttributeToSelect('name'); + + $this->getSelect() + ->join( + array('r' => $this->getTable('review/review')), + 'e.entity_id = r.entity_pk_value', + array( + 'review_cnt' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)), + 'last_created' => 'MAX(r.created_at)',)) + ->group('e.entity_id'); + + $joinCondition = array( + 'e.entity_id = table_rating.entity_pk_value', + $this->getConnection()->quoteInto('table_rating.store_id > ?', 0) + ); + + /** + * @var $groupByCondition array of group by fields + */ + $groupByCondition = $this->getSelect()->getPart(Zend_Db_Select::GROUP); + $percentField = $this->getConnection()->quoteIdentifier('table_rating.percent'); + $sumPercentField = $helper->prepareColumn("SUM({$percentField})", $groupByCondition); + $sumPercentApproved = $helper->prepareColumn('SUM(table_rating.percent_approved)', $groupByCondition); + $countRatingId = $helper->prepareColumn('COUNT(table_rating.rating_id)', $groupByCondition); + + $this->getSelect() + ->joinLeft( + array('table_rating' => $this->getTable('rating/rating_vote_aggregated')), + implode(' AND ', $joinCondition), + array( + 'avg_rating' => sprintf('%s/%s', $sumPercentField, $countRatingId), + 'avg_rating_approved' => sprintf('%s/%s', $sumPercentApproved, $countRatingId), + )); +//ECHO $this->getSelect();dd(); + return $this; + } + + /** + * Add attribute to sort + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Review_Product_Collection + */ + public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) + { + if (in_array($attribute, array('review_cnt', 'last_created', 'avg_rating', 'avg_rating_approved'))) { + $this->getSelect()->order($attribute.' '.$dir); + return $this; + } + + return parent::addAttributeToSort($attribute, $dir); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Shipping/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Shipping/Collection.php new file mode 100755 index 0000000000..1d3de4ca6d --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Shipping/Collection.php @@ -0,0 +1,79 @@ + + */ +class Mage_Reports_Model_Resource_Shipping_Collection extends Mage_Sales_Model_Entity_Order_Collection +{ + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Shipping_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset() + ->addAttributeToSelect('*') + ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) + ->addExpressionAttributeToSelect('orders', 'COUNT(DISTINCT({{entity_id}}))', array('entity_id')) + ->addAttributeToSelect('shipping_description') + ->groupByAttribute('shipping_description') + ->getSelect()->order('orders ' . self::SORT_ORDER_DESC); + + $this->getSelect()->where("table_shipping_description.value <> ''"); + return $this; + } + + /** + * Set store filter to collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Shipping_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds)); + $this->addExpressionAttributeToSelect('total', + 'SUM({{base_shipping_amount}})', + array('base_shipping_amount')); + } else { + $this->addExpressionAttributeToSelect('total', + 'SUM({{base_shipping_amount}}*{{base_to_global_rate}})', + array('base_shipping_amount', 'base_to_global_rate')); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Shopcart/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Shopcart/Product/Collection.php new file mode 100755 index 0000000000..b07208dc89 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Shopcart/Product/Collection.php @@ -0,0 +1,64 @@ + + */ +class Mage_Reports_Model_Resource_Shopcart_Product_Collection extends Mage_Reports_Model_Resource_Product_Collection +{ + /** + * Join fields + * + * @return Mage_Reports_Model_Resource_Shopcart_Product_Collection + */ + protected function _joinFields() + { + parent::_joinFields(); + $this->addAttributeToSelect('price') + ->addCartsCount() + ->addOrdersCount(); + + return $this; + } + + /** + * Set date range + * + * @param string $from + * @param strin $to + * @return Mage_Reports_Model_Resource_Shopcart_Product_Collection + */ + public function setDateRange($from, $to) + { + $this->getSelect()->reset(); + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Tag/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Tag/Collection.php new file mode 100755 index 0000000000..7be1b75693 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Tag/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Reports_Model_Resource_Tag_Collection extends Mage_Tag_Model_Resource_Popular_Collection +{ + /** + * Add group by tag + * + * @deprecated after 1.4.0.1 + * + * @return Mage_Reports_Model_Resource_Tag_Collection + */ + public function addGroupByTag() + { + return $this; + } + + /** + * Add tag popularity to select by specified store ids + * + * @param int|array $storeIds + * @return Mage_Reports_Model_Resource_Tag_Collection + */ + public function addPopularity($storeIds) + { + $select = $this->getSelect() + ->joinLeft( + array('tr' => $this->getTable('tag/relation')), + 'main_table.tag_id = tr.tag_id', + array('popularity' => 'COUNT(tr.tag_id)') + ); + if (!empty($storeIds)) { + $select->where('tr.store_id IN(?)', $storeIds); + } + $select->group('main_table.tag_id'); + + /** + * Allow to use analytic function + */ + $this->_useAnalyticFunction = true; + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Tag/Customer/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Tag/Customer/Collection.php new file mode 100755 index 0000000000..9c9ede3b60 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Tag/Customer/Collection.php @@ -0,0 +1,88 @@ + + */ +class Mage_Reports_Model_Resource_Tag_Customer_Collection extends Mage_Tag_Model_Resource_Customer_Collection +{ + protected function _construct() + { + parent::_construct(); + $this->_useAnalyticFunction = true; + } + /** + * Add target count + * + * @return Mage_Reports_Model_Resource_Tag_Customer_Collection + */ + public function addTagedCount() + { + $this->getSelect() + ->columns(array('taged' => 'COUNT(tr.tag_relation_id)')); + return $this; + } + + /** + * get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->columns("COUNT(DISTINCT tr.customer_id)"); + + return $countSelect; + } + + /** + * Set order + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Tag_Customer_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if (in_array($attribute, array('taged'))) { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Tag/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Tag/Product/Collection.php new file mode 100755 index 0000000000..10755d0478 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Tag/Product/Collection.php @@ -0,0 +1,168 @@ + + */ +class Mage_Reports_Model_Resource_Tag_Product_Collection extends Mage_Tag_Model_Resource_Product_Collection +{ + protected function _construct() + { + parent::_construct(); + /** + * Allow to use analytic function + */ + $this->_useAnalyticFunction = true; + } + /** + * Add unique target count to result + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addUniqueTagedCount() + { + $select = clone $this->getSelect(); + + $select->reset() + ->from(array('rel' => $this->getTable('tag/relation')), 'COUNT(DISTINCT rel.tag_id)') + ->where('rel.product_id = e.entity_id'); + + $this->getSelect() + ->columns(array('utaged' => new Zend_Db_Expr(sprintf('(%s)', $select)))); + return $this; + } + + /** + * Add all target count to result + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addAllTagedCount() + { + $this->getSelect() + ->columns(array('taged' => 'COUNT(relation.tag_id)')); + return $this; + } + + /** + * Add target count to result + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addTagedCount() + { + $this->getSelect() + ->columns(array('taged' => 'COUNT(relation.tag_relation_id)')); + + return $this; + } + + /** + * Add group by product to result + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addGroupByProduct() + { + $this->getSelect() + ->group('relation.product_id'); + $this->setJoinFlag('distinct'); + return $this; + } + + /** + * Add group by tag to result + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addGroupByTag() + { + $this->getSelect() + ->group('relation.tag_id'); + $this->setJoinFlag('distinct'); + $this->setJoinFlag('group_tag'); + return $this; + } + + /** + * Add product filter + * + * @param int $customerId + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function addProductFilter($customerId) + { + $this->getSelect() + ->where('relation.product_id = ?', (int)$customerId); + $this->_customerFilterId = (int)$customerId; + return $this; + } + + /** + * Set order + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if ($attribute == 'utaged' || $attribute == 'taged' || $attribute == 'tag_name') { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + + return $this; + } + + /** + * Join fields + * + * @return Mage_Reports_Model_Resource_Tag_Product_Collection + */ + protected function _joinFields() + { + $this->addAttributeToSelect('name'); + $this->getSelect() + ->join( + array('relation' => $this->getTable('tag/relation')), + 'relation.product_id = e.entity_id', + array()) + ->join( + array('t' => $this->getTable('tag/tag')), + 't.tag_id = relation.tag_id', + array('tag_id', 'status', 'tag_name' => 'name') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Tax/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Tax/Collection.php new file mode 100755 index 0000000000..4523c5b7c2 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Tax/Collection.php @@ -0,0 +1,114 @@ + + */ +class Mage_Reports_Model_Resource_Tax_Collection extends Mage_Sales_Model_Entity_Order_Collection +{ + /** + * Set row identifier field name + * + */ + public function _construct() + { + parent::_construct(); + $this->setRowIdFieldName('tax_id'); + } + + /** + * Set date range + * + * @param string $from + * @param string $to + * @return Mage_Reports_Model_Resource_Tax_Collection + */ + public function setDateRange($from, $to) + { + $this->_reset(); + + $this->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to)) + ->addExpressionAttributeToSelect('orders', 'COUNT(DISTINCT({{entity_id}}))', array('entity_id')) + ->getSelect() + ->join( + array('tax_table' => $this->getTable('sales/order_tax')), + 'e.entity_id = tax_table.order_id') + ->group('tax_table.code') + ->order(array('process', 'priority')); + /* + * Allow Analytic Functions Usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Set store filter to collection + * + * @param array $storeIds + * @return Mage_Reports_Model_Resource_Tax_Collection + */ + public function setStoreIds($storeIds) + { + if ($storeIds) { + $this->getSelect() + ->where('e.store_id IN(?)', (array)$storeIds) + ->columns(array('tax' => 'SUM(tax_table.base_real_amount)')); + } else { + $this->addExpressionAttributeToSelect( + 'tax', + 'SUM(tax_table.base_real_amount*{{base_to_global_rate}})', + array('base_to_global_rate') + ); + } + + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::HAVING); + $countSelect->columns("COUNT(DISTINCT e.entity_id)"); + return $countSelect; + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Wishlist/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Wishlist/Collection.php new file mode 100755 index 0000000000..fccac19ade --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Wishlist/Collection.php @@ -0,0 +1,121 @@ + + */ +class Mage_Reports_Model_Resource_Wishlist_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Wishlist table name + * + * @var string + */ + protected $_wishlistTable; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('wishlist/wishlist'); + $this->setWishlistTable($this->getTable('wishlist/wishlist')); + } + /** + * Set wishlist table name + * + * @param string $value + * @return Mage_Reports_Model_Resource_Wishlist_Collection + */ + public function setWishlistTable($value) + { + $this->_wishlistTable = $value; + return $this; + } + + /** + * retrieve wishlist table name + * + * @return string + */ + public function getWishlistTable() + { + return $this->_wishlistTable; + } + + /** + * Retrieve wishlist customer count + * + * @return array + */ + public function getWishlistCustomerCount() + { + /** @var $collection Mage_Customer_Model_Resource_Customer_Collection */ + $collection = Mage::getResourceModel('customer/customer_collection'); + + $customersSelect = $collection->getSelectCountSql(); + + $countSelect = clone $customersSelect; + $countSelect->joinLeft( + array('wt' => $this->getWishlistTable()), + 'wt.customer_id = e.entity_id', + array() + ) + ->group('wt.wishlist_id'); + $count = $collection->count(); + $resultSelect = $this->getConnection()->select() + ->union(array($customersSelect, $count), Zend_Db_Select::SQL_UNION_ALL); + list($customers, $count) = $this->getConnection()->fetchCol($resultSelect); + + return array(($count*100)/$customers, $count); + } + + /** + * Get shared items collection count + * + * @return int + */ + public function getSharedCount() + { + /** @var $collection Mage_Customer_Model_Resource_Customer_Collection */ + $collection = Mage::getResourceModel('customer/customer_collection'); + $countSelect = $collection->getSelectCountSql(); + $countSelect->joinLeft( + array('wt' => $this->getWishlistTable()), + 'wt.customer_id=e.entity_id', + array() + ) + ->where('wt.shared=1') + ->group('wt.wishlist_id'); + return $countSelect->getAdapter()->fetchOne($countSelect); + } +} diff --git a/app/code/core/Mage/Reports/Model/Resource/Wishlist/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Wishlist/Product/Collection.php new file mode 100755 index 0000000000..1b446d7037 --- /dev/null +++ b/app/code/core/Mage/Reports/Model/Resource/Wishlist/Product/Collection.php @@ -0,0 +1,126 @@ + + */ +class Mage_Reports_Model_Resource_Wishlist_Product_Collection extends Mage_Wishlist_Model_Resource_Product_Collection +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('wishlist/wishlist'); + } + + /** + * Add wishlist count + * + * @return Mage_Reports_Model_Resource_Wishlist_Product_Collection + */ + public function addWishlistCount() + { + $wishlistItemTable = $this->getTable('wishlist/item'); + $this->getSelect() + ->join( + array('wi' => $wishlistItemTable), + 'wi.product_id = e.entity_id', + array('wishlists' => new Zend_Db_Expr('COUNT(wi.wishlist_item_id)'))) + ->where('wi.product_id = e.entity_id') + ->group('wi.product_id'); + /* + * Allow Analytic Functions Usage + */ + $this->_useAnalyticFunction = true; + + $this->getEntity()->setStore(0); + return $this; + } + + /** + * add customer count to result + * + * @return Mage_Reports_Model_Resource_Wishlist_Product_Collection + */ + public function getCustomerCount() + { + $this->getSelect()->reset(); + + $this->getSelect() + ->from( + array('wishlist' => $this->getTable('wishlist/wishlist')), + array( + 'wishlist_cnt' => new Zend_Db_Expr('COUNT(wishlist.wishlist_id)'), + 'wishlist.customer_id' + )) + ->group('wishlist.customer_id'); + return $this; + } + + /** + * Get select count sql + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->columns("COUNT(*)"); + + return $countSelect; + } + + /** + * Set order to result + * + * @param string $attribute + * @param string $dir + * @return Mage_Reports_Model_Resource_Wishlist_Product_Collection + */ + public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) + { + if ($attribute == 'wishlists') { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + + return $this; + } +} + diff --git a/app/code/core/Mage/Reports/Model/Session.php b/app/code/core/Mage/Reports/Model/Session.php index 7d249a045e..6f948c7e04 100644 --- a/app/code/core/Mage/Reports/Model/Session.php +++ b/app/code/core/Mage/Reports/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Test.php b/app/code/core/Mage/Reports/Model/Test.php index 650c116aa6..3a45fad58c 100644 --- a/app/code/core/Mage/Reports/Model/Test.php +++ b/app/code/core/Mage/Reports/Model/Test.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/Model/Totals.php b/app/code/core/Mage/Reports/Model/Totals.php index 4576291e13..0610f6a108 100644 --- a/app/code/core/Mage/Reports/Model/Totals.php +++ b/app/code/core/Mage/Reports/Model/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/data/reports_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Reports/data/reports_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..b67be244a6 --- /dev/null +++ b/app/code/core/Mage/Reports/data/reports_setup/data-install-1.6.0.0.php @@ -0,0 +1,109 @@ +startSetup(); +/* + * Report Event Types default data + */ +$eventTypeData = array( + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_PRODUCT_VIEW, + 'event_name' => 'catalog_product_view' + ), + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_PRODUCT_SEND, + 'event_name' => 'sendfriend_product' + ), + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_PRODUCT_COMPARE, + 'event_name' => 'catalog_product_compare_add_product' + ), + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_PRODUCT_TO_CART, + 'event_name' => 'checkout_cart_add_product' + ), + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_PRODUCT_TO_WISHLIST, + 'event_name' => 'wishlist_add_product' + ), + array( + 'event_type_id' => Mage_Reports_Model_Event::EVENT_WISHLIST_SHARE, + 'event_name' => 'wishlist_share' + ) +); + +foreach ($eventTypeData as $row) { + $installer->getConnection()->insertForce($installer->getTable('reports/event_type'), $row); +} + +/** + * Prepare database after data upgrade + */ +$installer->endSetup(); + +/** + * Cms Page with 'home' identifier page modification for report pages + */ +/** @var $cms Mage_Cms_Model_Page */ +$cms = Mage::getModel('cms/page')->load('home', 'identifier'); + +$reportLayoutUpdate = ''; + +/* + * Merge and save old layout update data with report layout data + */ +$cms->setLayoutUpdateXml($cms->getLayoutUpdateXml() . $reportLayoutUpdate)->save(); diff --git a/app/code/core/Mage/Reports/etc/adminhtml.xml b/app/code/core/Mage/Reports/etc/adminhtml.xml index fd5f4414d6..5f87b73fc2 100644 --- a/app/code/core/Mage/Reports/etc/adminhtml.xml +++ b/app/code/core/Mage/Reports/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -33,6 +33,7 @@ Sales + 10 Orders @@ -62,6 +63,7 @@ Shopping Cart + 20 Products in carts @@ -79,6 +81,7 @@ Products + 30 Bestsellers @@ -104,6 +107,7 @@ Customers + 40 New Accounts @@ -119,60 +123,11 @@ - - - Reviews - - - Customers Reviews - adminhtml/report_review/customer - - - Products Reviews - adminhtml/report_review/product - - - - - Tags - - - Customers - adminhtml/report_tag/customer - - - Products - adminhtml/report_tag/product - - - - Popular - adminhtml/report_tag/popular - - - Search Terms + 60 adminhtml/report/search - 65535 Refresh Statistics diff --git a/app/code/core/Mage/Reports/etc/config.xml b/app/code/core/Mage/Reports/etc/config.xml index db979b1fa2..5956512fb8 100644 --- a/app/code/core/Mage/Reports/etc/config.xml +++ b/app/code/core/Mage/Reports/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.10 + 1.6.0.0 Mage_Reports_Model - reports_mysql4 + reports_resource - - Mage_Reports_Model_Mysql4 + + Mage_Reports_Model_Resource + reports_mysql4 report_event
      @@ -53,9 +54,8 @@ report_viewed_product_index
      -
      +
      - @@ -74,7 +74,6 @@
      - @@ -186,7 +185,6 @@
      - diff --git a/app/code/core/Mage/Reports/etc/system.xml b/app/code/core/Mage/Reports/etc/system.xml index d47fe620de..ab98a74082 100644 --- a/app/code/core/Mage/Reports/etc/system.xml +++ b/app/code/core/Mage/Reports/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Reports/etc/widget.xml b/app/code/core/Mage/Reports/etc/widget.xml index 77ef3d3744..c9a712ec4d 100644 --- a/app/code/core/Mage/Reports/etc/widget.xml +++ b/app/code/core/Mage/Reports/etc/widget.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Reports/sql/reports_setup/install-1.6.0.0.php b/app/code/core/Mage/Reports/sql/reports_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..953477e477 --- /dev/null +++ b/app/code/core/Mage/Reports/sql/reports_setup/install-1.6.0.0.php @@ -0,0 +1,226 @@ +startSetup(); +/** + * Create table 'reports/event_type' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('reports/event_type')) + ->addColumn('event_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Event Type Id') + ->addColumn('event_name', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => false, + ), 'Event Name') + ->addColumn('customer_login', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Login') + ->setComment('Reports Event Type Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'reports/event' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('reports/event')) + ->addColumn('event_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Event Id') + ->addColumn('logged_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Logged At') + ->addColumn('event_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Event Type Id') + ->addColumn('object_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Object Id') + ->addColumn('subject_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Subject Id') + ->addColumn('subtype', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Subtype') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addIndex($installer->getIdxName('reports/event', array('event_type_id')), + array('event_type_id')) + ->addIndex($installer->getIdxName('reports/event', array('subject_id')), + array('subject_id')) + ->addIndex($installer->getIdxName('reports/event', array('object_id')), + array('object_id')) + ->addIndex($installer->getIdxName('reports/event', array('subtype')), + array('subtype')) + ->addIndex($installer->getIdxName('reports/event', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('reports/event', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/event', 'event_type_id', 'reports/event_type', 'event_type_id'), + 'event_type_id', $installer->getTable('reports/event_type'), 'event_type_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Reports Event Table'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'reports/compared_product_index'. + * MySQL table differs by having unique keys on (customer/visitor, product) columns and is created + * in separate install. + */ +$tableName = $installer->getTable('reports/compared_product_index'); +if (!$installer->tableExists($tableName)) { + $table = $installer->getConnection() + ->newTable($tableName) + ->addColumn('index_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Index Id') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Visitor Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Added At') + ->addIndex($installer->getIdxName('reports/compared_product_index', array('visitor_id', 'product_id')), + array('visitor_id', 'product_id')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('customer_id', 'product_id')), + array('customer_id', 'product_id')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Reports Compared Product Index Table'); + $installer->getConnection()->createTable($table); +} + + +/** + * Create table 'reports/viewed_product_index'. + * MySQL table differs by having unique keys on (customer/visitor, product) columns and is created + * in separate install. + */ +$tableName = $installer->getTable('reports/viewed_product_index'); +if (!$installer->tableExists($tableName)) { + $table = $installer->getConnection() + ->newTable($tableName) + ->addColumn('index_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Index Id') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Visitor Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Added At') + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('visitor_id', 'product_id')), + array('visitor_id', 'product_id')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('customer_id', 'product_id')), + array('customer_id', 'product_id')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Reports Viewed Product Index Table'); + $installer->getConnection()->createTable($table); +} + +/* + * Prepare database for tables install + */ +$installer->endSetup(); + diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-0.7.1.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-0.7.1.php index cbef439bb4..ab3d6ed026 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-0.7.1.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.5.0.0.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.5.0.0.php new file mode 100644 index 0000000000..703c290555 --- /dev/null +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.5.0.0.php @@ -0,0 +1,82 @@ +getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName( + 'reports/viewed_product_index', + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ); + $installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName( + 'reports/viewed_product_index', + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ); + + /** + * Unique indexes for reports/compared_product_index + */ + $installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName( + 'reports/compared_product_index', + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ); + $installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName( + 'reports/compared_product_index', + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ); +} diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.6.0.0.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.6.0.0.php new file mode 100644 index 0000000000..204a21b588 --- /dev/null +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-install-1.6.0.0.php @@ -0,0 +1,135 @@ +getConnection() + ->newTable($installer->getTable('reports/compared_product_index')) + ->addColumn('index_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Index Id') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Visitor Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Added At') + ->addIndex($installer->getIdxName('reports/compared_product_index', array('visitor_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('visitor_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('customer_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('customer_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('reports/compared_product_index', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/compared_product_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Reports Compared Product Index Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'reports/viewed_product_index' + * In MySQL version this table comes with unique keys to implement insertOnDuplicate(), so that + * only one record is added when customer/visitor views same product again. + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('reports/viewed_product_index')) + ->addColumn('index_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Index Id') + ->addColumn('visitor_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Visitor Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Added At') + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('visitor_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('visitor_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('customer_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('customer_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('added_at')), + array('added_at')) + ->addIndex($installer->getIdxName('reports/viewed_product_index', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('reports/viewed_product_index', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Reports Viewed Product Index Table'); +$installer->getConnection()->createTable($table); + +$installFile = dirname(__FILE__) . DS . 'install-1.6.0.0.php'; +if (file_exists($installFile)) { + include $installFile; +} diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.0-0.7.1.php index a416001427..bbe64feded 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.1-0.7.2.php index 3d37a212f1..89cc8923a2 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.2-0.7.3.php index ac7b0f7fec..ce5e45026d 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.3-0.7.4.php index 32a65e597e..5fdfd6cca9 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.4-0.7.5.php index c0e0cec3ef..f409473b20 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.5-0.7.7.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.5-0.7.7.php index 055d4e4cb1..fc19ffe6cb 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.5-0.7.7.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.5-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.7-0.7.8.php index c144809754..9f826be269 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.8-0.7.9.php index 06020ac719..2ad6950c58 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.9-0.7.10.php index ffd603799a..04eff8fbc7 100644 --- a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Reports - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..9cde61ffd6 --- /dev/null +++ b/app/code/core/Mage/Reports/sql/reports_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,503 @@ +startSetup(); + +/** + * Drop foreign keys + */ + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/compared_product_index'), + 'FK_REPORT_COMPARED_PRODUCT_INDEX_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/compared_product_index'), + 'FK_REPORT_COMPARED_PRODUCT_INDEX_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/compared_product_index'), + 'FK_REPORT_COMPARED_PRODUCT_INDEX_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/event'), + 'FK_REPORT_EVENT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/event'), + 'FK_REPORT_EVENT_TYPE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/viewed_product_index'), + 'FK_REPORT_VIEWED_PRODUCT_INDEX_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/viewed_product_index'), + 'FK_REPORT_VIEWED_PRODUCT_INDEX_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('reports/viewed_product_index'), + 'FK_REPORT_VIEWED_PRODUCT_INDEX_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('reports/compared_product_index'), + 'UNQ_BY_VISITOR' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/compared_product_index'), + 'UNQ_BY_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/compared_product_index'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/compared_product_index'), + 'IDX_SORT_ADDED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/compared_product_index'), + 'PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/event'), + 'IDX_EVENT_TYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/event'), + 'IDX_SUBJECT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/event'), + 'IDX_OBJECT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/event'), + 'IDX_SUBTYPE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/event'), + 'FK_REPORT_EVENT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/viewed_product_index'), + 'UNQ_BY_VISITOR' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/viewed_product_index'), + 'UNQ_BY_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/viewed_product_index'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/viewed_product_index'), + 'IDX_SORT_ADDED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('reports/viewed_product_index'), + 'PRODUCT_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('reports/event') => array( + 'columns' => array( + 'event_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Event Id' + ), + 'logged_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Logged At' + ), + 'event_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Event Type Id' + ), + 'object_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Object Id' + ), + 'subject_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Subject Id' + ), + 'subtype' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Subtype' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Reports Event Table' + ), + $installer->getTable('reports/event_type') => array( + 'columns' => array( + 'event_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Event Type Id' + ), + 'event_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'nullable' => false, + 'comment' => 'Event Name' + ), + 'customer_login' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Login' + ) + ), + 'comment' => 'Reports Event Type Table' + ), + $installer->getTable('reports/compared_product_index') => array( + 'columns' => array( + 'index_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Index Id' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Visitor Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'added_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Added At' + ) + ), + 'comment' => 'Reports Compared Product Index Table' + ), + $installer->getTable('reports/viewed_product_index') => array( + 'columns' => array( + 'index_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Index Id' + ), + 'visitor_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Visitor Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'added_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Added At' + ) + ), + 'comment' => 'Reports Viewed Product Index Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName( + 'reports/compared_product_index', + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName( + 'reports/compared_product_index', + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName('reports/compared_product_index', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName('reports/compared_product_index', array('added_at')), + array('added_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/compared_product_index'), + $installer->getIdxName('reports/compared_product_index', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/event'), + $installer->getIdxName('reports/event', array('event_type_id')), + array('event_type_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/event'), + $installer->getIdxName('reports/event', array('subject_id')), + array('subject_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/event'), + $installer->getIdxName('reports/event', array('object_id')), + array('object_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/event'), + $installer->getIdxName('reports/event', array('subtype')), + array('subtype') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/event'), + $installer->getIdxName('reports/event', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName( + 'reports/viewed_product_index', + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('visitor_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName( + 'reports/viewed_product_index', + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('customer_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName('reports/viewed_product_index', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName('reports/viewed_product_index', array('added_at')), + array('added_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('reports/viewed_product_index'), + $installer->getIdxName('reports/viewed_product_index', array('product_id')), + array('product_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/compared_product_index', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('reports/compared_product_index'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/compared_product_index', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('reports/compared_product_index'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/compared_product_index', 'store_id', 'core/store', 'store_id'), + $installer->getTable('reports/compared_product_index'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/event', 'store_id', 'core/store', 'store_id'), + $installer->getTable('reports/event'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/event', 'event_type_id', 'reports/event_type', 'event_type_id'), + $installer->getTable('reports/event'), + 'event_type_id', + $installer->getTable('reports/event_type'), + 'event_type_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/viewed_product_index', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('reports/viewed_product_index'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/viewed_product_index', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('reports/viewed_product_index'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('reports/viewed_product_index', 'store_id', 'core/store', 'store_id'), + $installer->getTable('reports/viewed_product_index'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Review/Block/Customer/List.php b/app/code/core/Mage/Review/Block/Customer/List.php index e4d09226ba..7f62c936cb 100644 --- a/app/code/core/Mage/Review/Block/Customer/List.php +++ b/app/code/core/Mage/Review/Block/Customer/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/Customer/Recent.php b/app/code/core/Mage/Review/Block/Customer/Recent.php index 45661ab167..cf848ea6dc 100644 --- a/app/code/core/Mage/Review/Block/Customer/Recent.php +++ b/app/code/core/Mage/Review/Block/Customer/Recent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/Customer/View.php b/app/code/core/Mage/Review/Block/Customer/View.php index 59f2a14b2f..205ebe8c3e 100644 --- a/app/code/core/Mage/Review/Block/Customer/View.php +++ b/app/code/core/Mage/Review/Block/Customer/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/Form.php b/app/code/core/Mage/Review/Block/Form.php index 26ec8fc70e..2736d4a6d8 100644 --- a/app/code/core/Mage/Review/Block/Form.php +++ b/app/code/core/Mage/Review/Block/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/Helper.php b/app/code/core/Mage/Review/Block/Helper.php index 57eed9f2ce..e5377dc2f2 100644 --- a/app/code/core/Mage/Review/Block/Helper.php +++ b/app/code/core/Mage/Review/Block/Helper.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/Product/View.php b/app/code/core/Mage/Review/Block/Product/View.php index 79d6b15968..9107c64283 100644 --- a/app/code/core/Mage/Review/Block/Product/View.php +++ b/app/code/core/Mage/Review/Block/Product/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -74,7 +74,7 @@ public function getReviewsCollection() if (null === $this->_reviewsCollection) { $this->_reviewsCollection = Mage::getModel('review/review')->getCollection() ->addStoreFilter(Mage::app()->getStore()->getId()) - ->addStatusFilter('approved') + ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) ->addEntityFilter('product', $this->getProduct()->getId()) ->setDateOrder(); } diff --git a/app/code/core/Mage/Review/Block/Product/View/List.php b/app/code/core/Mage/Review/Block/Product/View/List.php index 82829a24b1..b0e83ba17c 100644 --- a/app/code/core/Mage/Review/Block/Product/View/List.php +++ b/app/code/core/Mage/Review/Block/Product/View/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Block/View.php b/app/code/core/Mage/Review/Block/View.php index 83fadec2c0..3aae055ff2 100644 --- a/app/code/core/Mage/Review/Block/View.php +++ b/app/code/core/Mage/Review/Block/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Helper/Data.php b/app/code/core/Mage/Review/Helper/Data.php index 31d257e29d..30d0077042 100644 --- a/app/code/core/Mage/Review/Helper/Data.php +++ b/app/code/core/Mage/Review/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review.php b/app/code/core/Mage/Review/Model/Mysql4/Review.php index 5a1b402b27..ce7fac32e7 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review resource model * @@ -31,319 +32,6 @@ * @package Mage_Review * @author Magento Core Team */ -class Mage_Review_Model_Mysql4_Review extends Mage_Core_Model_Mysql4_Abstract +class Mage_Review_Model_Mysql4_Review extends Mage_Review_Model_Resource_Review { - protected $_reviewTable; - protected $_reviewDetailTable; - protected $_reviewStatusTable; - protected $_reviewEntityTable; - protected $_reviewStoreTable; - private $_deleteCache = array(); - - protected function _construct() - { - $this->_init('review/review', 'review_id'); - $this->_reviewTable = $this->getTable('review/review'); - $this->_reviewDetailTable = $this->getTable('review/review_detail'); - $this->_reviewStatusTable = $this->getTable('review/review_status'); - $this->_reviewEntityTable = $this->getTable('review/review_entity'); - $this->_reviewStoreTable = $this->getTable('review/review_store'); - $this->_aggregateTable = $this->getTable('review/review_aggregate'); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $select->join($this->_reviewDetailTable, $this->getMainTable().".review_id = {$this->_reviewDetailTable}.review_id"); - return $select; - } - - /** - * Perform actions before object save - * - * @param Varien_Object $object - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getId()) { - $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate()); - } - if ($object->hasData('stores') && is_array($object->getStores())) { - $stores = $object->getStores(); - $stores[] = 0; - $object->setStores($stores); - } elseif ($object->hasData('stores')) { - $object->setStores(array($object->getStores(), 0)); - } - return $this; - } - - /** - * Perform actions after object save - * - * @param Varien_Object $object - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - /** - * save detale - */ - $detail = array( - 'title' => $object->getTitle(), - 'detail' => $object->getDetail(), - 'nickname' => $object->getNickname(), - ); - $select = $this->_getWriteAdapter()->select() - ->from($this->_reviewDetailTable, 'detail_id') - ->where('review_id=?', $object->getId()); - $detailId = $this->_getWriteAdapter()->fetchOne($select); - - if ($detailId) { - $this->_getWriteAdapter()->update($this->_reviewDetailTable, - $detail, - 'detail_id='.$detailId - ); - } - else { - $detail['store_id'] = $object->getStoreId(); - $detail['customer_id']= $object->getCustomerId(); - $detail['review_id'] = $object->getId(); - $this->_getWriteAdapter()->insert($this->_reviewDetailTable, $detail); - } - - - /** - * save stores - */ - $stores = $object->getStores(); - if(!empty($stores)) { - $condition = $this->_getWriteAdapter()->quoteInto('review_id = ?', $object->getId()); - $this->_getWriteAdapter()->delete($this->_reviewStoreTable, $condition); - - $insertedStoreIds = array(); - foreach ($stores as $storeId) { - if (in_array($storeId, $insertedStoreIds)) { - continue; - } - - $insertedStoreIds[] = $storeId; - $storeInsert = array( - 'store_id' => $storeId, - 'review_id'=> $object->getId() - ); - $this->_getWriteAdapter()->insert($this->_reviewStoreTable, $storeInsert); - } - } - - // reaggregate ratings, that depend on this review - $this->_aggregateRatings( - $this->_loadVotedRatingIds($object->getId()), - $object->getEntityPkValue() - ); - - return $this; - } - - /** - * Perform actions after object load - * - * @param Varien_Object $object - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->_reviewStoreTable, array('store_id')) - ->where('review_id=?', $object->getId()); - $stores = $this->_getReadAdapter()->fetchCol($select); - if (empty($stores) && Mage::app()->isSingleStoreMode()) { - $object->setStores(array(Mage::app()->getStore(true)->getId())); - } else { - $object->setStores($stores); - } - return $this; - } - - protected function _beforeDelete(Mage_Core_Model_Abstract $object) - { - // prepare rating ids, that depend on review - $this->_deleteCache = array( - 'ratingIds' => $this->_loadVotedRatingIds($object->getId()), - 'entityPkValue' => $object->getEntityPkValue() - ); - return $this; - } - - /** - * Perform actions after object delete - * - * @param Varien_Object $object - */ - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - $this->aggregate($object); - - // reaggregate ratings, that depended on this review - $this->_aggregateRatings( - $this->_deleteCache['ratingIds'], - $this->_deleteCache['entityPkValue'] - ); - $this->_deleteCache = array(); - - return $this; - } - - public function getTotalReviews($entityPkValue, $approvedOnly=false, $storeId=0) - { - $select = $this->_getReadAdapter()->select() - ->from($this->_reviewTable, "COUNT(*)") - ->where("{$this->_reviewTable}.entity_pk_value = ?", $entityPkValue); - - if($storeId > 0) { - $select->join(array('store'=>$this->_reviewStoreTable), - $this->_reviewTable.'.review_id=store.review_id AND store.store_id=' . (int)$storeId, array()); - } - if( $approvedOnly ) { - $select->where("{$this->_reviewTable}.status_id = ?", 1); - } - return $this->_getReadAdapter()->fetchOne($select); - } - - public function aggregate($object) - { - if( !$object->getEntityPkValue() && $object->getId() ) { - $object->load($object->getReviewId()); - } - - $ratingModel = Mage::getModel('rating/rating'); - $ratingSummaries= $ratingModel->getEntitySummary($object->getEntityPkValue(), false); - - $nonDelete = array(); - foreach($ratingSummaries as $ratingSummaryObject) { - if( $ratingSummaryObject->getCount() ) { - $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount()); - } else { - $ratingSummary = $ratingSummaryObject->getSum(); - } - - $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId()); - $select = $this->_getReadAdapter()->select() - ->from($this->_aggregateTable) - ->where("{$this->_aggregateTable}.entity_pk_value = ?", $object->getEntityPkValue()) - ->where("{$this->_aggregateTable}.entity_type = ?", $object->getEntityId()) - ->where("{$this->_aggregateTable}.store_id = ?", $ratingSummaryObject->getStoreId()); - - $oldData = $this->_getReadAdapter()->fetchRow($select); - - $data = new Varien_Object(); - - $data->setReviewsCount($reviewsCount) - ->setEntityPkValue($object->getEntityPkValue()) - ->setEntityType($object->getEntityId()) - ->setRatingSummary( ($ratingSummary > 0) ? $ratingSummary : 0 ) - ->setStoreId($ratingSummaryObject->getStoreId()); - - $this->_getWriteAdapter()->beginTransaction(); - try { - if( $oldData['primary_id'] > 0 ) { - $condition = $this->_getWriteAdapter()->quoteInto("{$this->_aggregateTable}.primary_id = ?", $oldData['primary_id']); - $this->_getWriteAdapter()->update($this->_aggregateTable, $data->getData(), $condition); - } else { - $this->_getWriteAdapter()->insert($this->_aggregateTable, $data->getData()); - } - $this->_getWriteAdapter()->commit(); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - } - } - } - - /** - * Get rating IDs from review votes - * - * @param int $reviewId - * @return array - */ - protected function _loadVotedRatingIds($reviewId) - { - if (empty($reviewId)) { - return array(); - } - $select = $this->_getReadAdapter()->select() - ->from(array('v' => $this->getTable('rating/rating_option_vote')), 'r.rating_id') - ->joinInner(array('r' => $this->getTable('rating/rating')), 'v.rating_id=r.rating_id') - ->where('v.review_id=?', $reviewId - ); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Aggregate this review's ratings. - * Useful, when changing the review. - * - * @param array $ratingIds - * @param int $entityPkValue - * @return Mage_Review_Model_Mysql4_Review - */ - protected function _aggregateRatings($ratingIds, $entityPkValue) - { - if ($ratingIds && !is_array($ratingIds)) { - $ratingIds = array((int)$ratingIds); - } - if ($ratingIds && $entityPkValue - && ($resource = Mage::getResourceSingleton('rating/rating_option')) - ) { - foreach ($ratingIds as $ratingId) { - $resource->aggregateEntityByRatingId( - $ratingId, $entityPkValue - ); - } - } - return $this; - } - - public function reAggregateReview($reviewId, $entityPkValue) - { - $this->_aggregateRatings($this->_loadVotedRatingIds($reviewId), $entityPkValue); - } - - /** - * Get review entity type id by code - * - * @param string $entityCode - * @return int|bool - */ - public function getEntityIdByCode($entityCode) - { - $select = $this->_getReadAdapter()->select() - ->from($this->_reviewEntityTable, array('entity_id')) - ->where('entity_code = ?', $entityCode); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Delete reviews by product id. - * Better to call this method in transaction, because operation performed on two separated tables - * - * @param int $productId - * @return Mage_Review_Model_Mysql4_Review - */ - public function deleteReviewsByProductId($productId) - { - $this->_getWriteAdapter()->delete($this->_reviewTable, array( - 'entity_pk_value=?' => $productId, - 'entity_id=?' => $this->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE) - )); - $this->_getWriteAdapter()->delete($this->getTable('review/review_aggregate'), array( - 'entity_pk_value=?' => $productId, - 'entity_type=?' => $this->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE) - )); - return $this; - } } diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review/Collection.php b/app/code/core/Mage/Review/Model/Mysql4/Review/Collection.php index fcdfb2d3d0..3f4f29db1c 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review/Collection.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review/Collection.php @@ -20,205 +20,18 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review collection resource model * - * @category Mage - * @package Mage_Review + * @category Mage + * @package Mage_Review * @author Magento Core Team */ -class Mage_Review_Model_Mysql4_Review_Collection extends Varien_Data_Collection_Db +class Mage_Review_Model_Mysql4_Review_Collection extends Mage_Review_Model_Resource_Review_Collection { - protected $_reviewTable; - protected $_reviewDetailTable; - protected $_reviewStatusTable; - protected $_reviewEntityTable; - protected $_reviewStoreTable; - protected $_addStoreDataFlag = false; - - public function __construct() - { - $resources = Mage::getSingleton('core/resource'); - - parent::__construct($resources->getConnection('review_read')); - - $this->_reviewTable = $resources->getTableName('review/review'); - $this->_reviewDetailTable = $resources->getTableName('review/review_detail'); - $this->_reviewStatusTable = $resources->getTableName('review/review_status'); - $this->_reviewEntityTable = $resources->getTableName('review/review_entity'); - $this->_reviewStoreTable = $resources->getTableName('review/review_store'); - - $this->_select->from(array('main_table'=>$this->_reviewTable)) - ->join(array('detail'=>$this->_reviewDetailTable), 'main_table.review_id=detail.review_id'); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('review/review')); - } - - public function addCustomerFilter($customerId) - { - $this->addFilter('customer', - $this->getConnection()->quoteInto('detail.customer_id=?', $customerId), - 'string'); - return $this; - } - - /** - * Add store filter - * - * @param int|array $storeId - * @return Varien_Data_Collection_Db - */ - public function addStoreFilter($storeId) - { - $this->getSelect()->join(array('store'=>$this->_reviewStoreTable), 'main_table.review_id=store.review_id', array()); - $this->getSelect()->where('store.store_id IN (?)', $storeId); - return $this; - } - - /** - * Add stores data - * - * @param int $storeId - * @return Varien_Data_Collection_Db - */ - public function addStoreData() - { - $this->_addStoreDataFlag = true; - return $this; - } - - /** - * Add entity filter - * - * @param int|string $entity - * @param int $pkValue - * @return Varien_Data_Collection_Db - */ - public function addEntityFilter($entity, $pkValue) - { - if (is_numeric($entity)) { - $this->addFilter('entity', - $this->getConnection()->quoteInto('main_table.entity_id=?', $entity), - 'string'); - } - elseif (is_string($entity)) { - $this->_select->join($this->_reviewEntityTable, - 'main_table.entity_id='.$this->_reviewEntityTable.'.entity_id'); - - $this->addFilter('entity', - $this->getConnection()->quoteInto($this->_reviewEntityTable.'.entity_code=?', $entity), - 'string'); - } - - $this->addFilter('entity_pk_value', - $this->getConnection()->quoteInto('main_table.entity_pk_value=?', $pkValue), - 'string'); - - return $this; - } - - public function addEntityInfo($entityName) - { - - return $this; - } - - /** - * Add status filter - * - * @param int|string $status - * @return Varien_Data_Collection_Db - */ - public function addStatusFilter($status) - { - if (is_numeric($status)) { - $this->addFilter('status', - $this->getConnection()->quoteInto('main_table.status_id=?', $status), - 'string'); - } - elseif (is_string($status)) { - $this->_select->join($this->_reviewStatusTable, - 'main_table.status_id='.$this->_reviewStatusTable.'.status_id'); - - $this->addFilter('status', - $this->getConnection()->quoteInto($this->_reviewStatusTable.'.status_code=?', $status), - 'string'); - } - return $this; - } - - public function setDateOrder($dir='DESC') - { - $this->setOrder('main_table.created_at', $dir); - return $this; - } - - public function addRateVotes() - { - foreach( $this->getItems() as $item ) { - $votesCollection = Mage::getModel('rating/rating_option_vote') - ->getResourceCollection() - ->setReviewFilter($item->getId()) - ->setStoreFilter(Mage::app()->getStore()->getId()) - ->addRatingInfo(Mage::app()->getStore()->getId()) - ->load(); - $item->setRatingVotes( $votesCollection ); - } - - return $this; - } - - public function addReviewsTotalCount() - { - $this->_select->joinLeft(array('r' => $this->_reviewTable), 'main_table.entity_pk_value = r.entity_pk_value', 'COUNT(r.review_id) as total_reviews'); - $this->_select->group('main_table.review_id'); - - return $this; - } - - public function load($printQuery=false, $logQuery=false) - { - if ($this->isLoaded()) { - return $this; - } - Mage::dispatchEvent('review_review_collection_load_before', array('collection' => $this)); - parent::load($printQuery, $logQuery); - if($this->_addStoreDataFlag) { - $this->_addStoreData(); - } - - - - return $this; - } - - protected function _addStoreData() - { - $reviewsIds = $this->getColumnValues('review_id'); - $storesToReviews = array(); - if (count($reviewsIds)>0) { - $select = $this->getConnection()->select() - ->from($this->_reviewStoreTable) - ->where('review_id IN(?)', $reviewsIds); - $result = $this->getConnection()->fetchAll($select); - foreach ($result as $row) { - if (!isset($storesToReviews[$row['review_id']])) { - $storesToReviews[$row['review_id']] = array(); - } - $storesToReviews[$row['review_id']][] = $row['store_id']; - } - } - - foreach ($this as $item) { - if(isset($storesToReviews[$item->getId()])) { - $item->setStores($storesToReviews[$item->getId()]); - } else { - $item->setStores(array()); - } - } - } } diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review/Product/Collection.php b/app/code/core/Mage/Review/Model/Mysql4/Review/Product/Collection.php index 77e3b71cbc..c32b02d624 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review/Product/Collection.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review/Product/Collection.php @@ -20,351 +20,18 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review Product Collection * - * @category Mage - * @package Mage_Review + * @category Mage + * @package Mage_Review * @author Magento Core Team */ - -class Mage_Review_Model_Mysql4_Review_Product_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Review_Model_Mysql4_Review_Product_Collection extends Mage_Review_Model_Resource_Review_Product_Collection { - protected $_entitiesAlias = array(); - protected $_reviewStoreTable; - protected $_addStoreDataFlag = false; - protected $_storesIds = array(); - - protected function _construct() - { - $this->_init('catalog/product'); - $this->setRowIdFieldName('review_id'); - $this->_reviewStoreTable = Mage::getSingleton('core/resource')->getTableName('review/review_store'); - $this->_initTables(); - } - - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinFields(); - return $this; - } - - /** - * Adds store filter into array - * - * @param mixed $storeId - * @return Mage_Review_Model_Mysql4_Review_Product_Collection - */ - public function addStoreFilter($storeId = null) - { - if (is_null($storeId)) { - $storeId = $this->getStoreId(); - } - - parent::addStoreFilter($storeId); - - if (!is_array($storeId)) { - $storeId = array($storeId); - } - - if (!empty($this->_storesIds)) { - $this->_storesIds = array_intersect($this->_storesIds, $storeId); - } else { - $this->_storesIds = $storeId; - } - - return $this; - } - - /** - * Adds specific store id into array - * - * @param array $storeId - * @return Mage_Review_Model_Mysql4_Review_Product_Collection - */ - public function setStoreFilter($storeId) - { - if (is_array($storeId) && isset($storeId['eq'])) { - $storeId = array_shift($storeId); - } - - if (!is_array($storeId)){ - $storeId = array($storeId); - } - - if (!empty($this->_storesIds)){ - $this->_storesIds = array_intersect($this->_storesIds, $storeId); - } else { - $this->_storesIds = $storeId; - } - - return $this; - } - - /** - * Applies all store filters in one place to prevent multiple joins in select - * - * @param null|Zend_Db_Select $select - * @return Mage_Review_Model_Mysql4_Review_Product_Collection - */ - protected function _applyStoresFilterToSelect(Zend_Db_Select $select = null) - { - $storesIds = $this->_storesIds; - - if (is_null($select)){ - $select = $this->getSelect(); - } - - if (is_array($storesIds) && !empty($storesIds)) { - $select->join( - array('store'=>$this->_reviewStoreTable), - $this->getConnection()->quoteInto('rt.review_id=store.review_id AND store.store_id IN(?)', $storesIds), - array()) - ->distinct(true) - ; - } else { - $select->join(array('store'=>$this->_reviewStoreTable), - 'rt.review_id=store.review_id AND store.store_id=' . (int)$storesIds, array()); - } - - return $this; - } - - /** - * Add stores data - * - * @param int $storeId - * @return Varien_Data_Collection_Db - */ - public function addStoreData() - { - $this->_addStoreDataFlag = true; - return $this; - } - public function addCustomerFilter($customerId) - { - $this->getSelect() - ->where('rdt.customer_id = ?', $customerId); - return $this; - } - - public function addEntityFilter($entityId) - { - $this->getSelect() - ->where('rt.entity_pk_value = ?', $entityId); - return $this; - } - - public function addStatusFilter($status) - { - $this->getSelect() - ->where('rt.status_id = ?', $status); - return $this; - } - - public function setDateOrder($dir='DESC') - { - $this->setOrder('rt.created_at', $dir); - return $this; - } - - public function addReviewSummary() - { - foreach( $this->getItems() as $item ) { - $model = Mage::getModel('rating/rating'); - $model->getReviewSummary($item->getReviewId()); - $item->addData($model->getData()); - } - return $this; - } - - public function addRateVotes() - { - foreach( $this->getItems() as $item ) { - $votesCollection = Mage::getModel('rating/rating_option_vote') - ->getResourceCollection() - ->setEntityPkFilter($item->getEntityId()) - ->setStoreFilter(Mage::app()->getStore()->getId()) - ->load(); - $item->setRatingVotes( $votesCollection ); - } - return $this; - } - - protected function _joinFields() - { - $reviewTable = Mage::getSingleton('core/resource')->getTableName('review/review'); - $reviewDetailTable = Mage::getSingleton('core/resource')->getTableName('review/review_detail'); - - $this->addAttributeToSelect('name') - ->addAttributeToSelect('sku'); - - $this->getSelect() - ->join(array('rt' => $reviewTable), - 'rt.entity_pk_value = e.entity_id', - array('review_id', 'created_at', 'entity_pk_value', 'status_id')) - ->join(array('rdt' => $reviewDetailTable), 'rdt.review_id = rt.review_id'); - return $this; - } - - /** - * Retrive all ids for collection - * - * @return array - */ - public function getAllIds($limit=null, $offset=null) - { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns('rt.review_id'); - return $this->getConnection()->fetchCol($idsSelect); - } - - - /** - * Render SQL for retrieve product count - * - * @return string - */ - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $sql = $countSelect->__toString(); - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select count(e.entity_id) from ', $sql); - - return $sql; - } - - public function setOrder($attribute, $dir='desc') - { - switch( $attribute ) { - case 'rt.review_id': - case 'rt.created_at': - case 'rt.status_id': - case 'rdt.title': - case 'rdt.nickname': - case 'rdt.detail': - $this->getSelect()->order($attribute . ' ' . $dir); - break; - case 'stores': - // No way to sort - break; - case 'type': - $this->getSelect()->order('rdt.customer_id ' . $dir); - break; - default: - parent::setOrder($attribute, $dir); - } - return $this; - } - - public function addAttributeToFilter($attribute, $condition=null, $joinType='inner') - { - switch( $attribute ) { - case 'rt.review_id': - case 'rt.created_at': - case 'rt.status_id': - case 'rdt.title': - case 'rdt.nickname': - case 'rdt.detail': - $conditionSql = $this->_getConditionSql($attribute, $condition); - $this->getSelect()->where($conditionSql); - return $this; - break; - case 'stores': - $this->setStoreFilter($condition); - return $this; - break; - case 'type': - if($condition == 1) { - $this->getSelect() - ->where('rdt.customer_id IS NULL AND rdt.store_id = ?', Mage_Core_Model_App::ADMIN_STORE_ID); - } elseif ($condition == 2) { - $this->getSelect()->where('rdt.customer_id > 0'); - } else { - $this->getSelect() - ->where('rdt.customer_id IS NULL AND rdt.store_id <> ?', Mage_Core_Model_App::ADMIN_STORE_ID); - } - - return $this; - break; - - default: - parent::addAttributeToFilter($attribute, $condition, $joinType); - } - - return $this; - } - - public function getColumnValues($colName) - { - $col = array(); - foreach ($this->getItems() as $item) { - $col[] = $item->getData($colName); - } - return $col; - } - - protected function _afterLoad() - { - parent::_afterLoad(); - if ($this->_addStoreDataFlag) { - $this->_addStoreData(); - } - return $this; - } - - protected function _addStoreData() - { - $reviewsIds = $this->getColumnValues('review_id'); - $storesToReviews = array(); - if (count($reviewsIds)>0) { - $select = $this->getConnection()->select() - ->from($this->_reviewStoreTable) - ->where('review_id IN(?)', $reviewsIds) - ->where('store_id > ?', 0); - $result = $this->getConnection()->fetchAll($select); - foreach ($result as $row) { - if (!isset($storesToReviews[$row['review_id']])) { - $storesToReviews[$row['review_id']] = array(); - } - $storesToReviews[$row['review_id']][] = $row['store_id']; - } - } - - foreach ($this as $item) { - if(isset($storesToReviews[$item->getReviewId()])) { - $item->setData('stores',$storesToReviews[$item->getReviewId()]); - } else { - $item->setData('stores', array()); - } - - } - } - - /** - * Redeclare parent method for store filters applying - * - * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection - */ - protected function _beforeLoad() - { - parent::_beforeLoad(); - $this->_applyStoresFilterToSelect(); - - return $this; - } - } +} diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review/Status/Collection.php b/app/code/core/Mage/Review/Model/Mysql4/Review/Status/Collection.php index 71c6c566b1..8b194da200 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review/Status/Collection.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review/Status/Collection.php @@ -20,34 +20,18 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review sttuses collection * - * @category Mage - * @package Mage_Review + * @category Mage + * @package Mage_Review * @author Magento Core Team */ - -class Mage_Review_Model_Mysql4_Review_Status_Collection extends Varien_Data_Collection_Db +class Mage_Review_Model_Mysql4_Review_Status_Collection extends Mage_Review_Model_Resource_Review_Status_Collection { - protected $_reviewStatusTable; - - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('review_read')); - - $this->_setIdFieldName('status_id'); - $this->_reviewStatusTable = Mage::getSingleton('core/resource')->getTableName('review/review_status'); - - $this->_select->from($this->_reviewStatusTable); - } - - public function toOptionArray() - { - return parent::_toOptionArray('status_id', 'status_code'); - } } diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review/Summary.php b/app/code/core/Mage/Review/Model/Mysql4/Review/Summary.php index 4c4ef27b80..ae142ee4eb 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review/Summary.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review/Summary.php @@ -20,60 +20,18 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review summary resource model * - * @category Mage - * @package Mage_Review + * @category Mage + * @package Mage_Review * @author Magento Core Team */ - -class Mage_Review_Model_Mysql4_Review_Summary extends Mage_Core_Model_Mysql4_Abstract +class Mage_Review_Model_Mysql4_Review_Summary extends Mage_Review_Model_Resource_Review_Summary { - protected function _construct() - { - $this->_init('review/review_aggregate', 'entity_pk_value'); - } - - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - $select->where('store_id = ?', (int)$object->getStoreId()); - return $select; - } - - /** - * Reaggregate all data by rating summary - * - * @param array $summary - * @return Mage_Review_Model_Mysql4_Review_Summary - */ - public function reAggregate($summary) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->group(array('entity_pk_value', 'store_id')); - foreach ($this->_getWriteAdapter()->fetchAll($select) as $row) { - if (isset($summary[$row['store_id']]) && isset($summary[$row['store_id']][$row['entity_pk_value']])) { - $summaryItem = $summary[$row['store_id']][$row['entity_pk_value']]; - if ($summaryItem->getCount()) { - $ratingSummary = round($summaryItem->getSum() / $summaryItem->getCount()); - } else { - $ratingSummary = $summaryItem->getSum(); - } - } else { - $ratingSummary = 0; - } - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('rating_summary' => $ratingSummary), - $this->_getWriteAdapter()->quoteInto('primary_id = ?', $row['primary_id']) - ); - } - return $this; - } } diff --git a/app/code/core/Mage/Review/Model/Mysql4/Review/Summary/Collection.php b/app/code/core/Mage/Review/Model/Mysql4/Review/Summary/Collection.php index 5883fa90b1..e84060df60 100644 --- a/app/code/core/Mage/Review/Model/Mysql4/Review/Summary/Collection.php +++ b/app/code/core/Mage/Review/Model/Mysql4/Review/Summary/Collection.php @@ -20,44 +20,18 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Review summery collection * - * @category Mage - * @package Mage_Review + * @category Mage + * @package Mage_Review * @author Magento Core Team */ -class Mage_Review_Model_Mysql4_Review_Summary_Collection extends Varien_Data_Collection_Db +class Mage_Review_Model_Mysql4_Review_Summary_Collection extends Mage_Review_Model_Resource_Review_Summary_Collection { - protected $_summaryTable; - - public function __construct() - { - $resources = Mage::getSingleton('core/resource'); - $this->_setIdFieldName('primary_id'); - - parent::__construct($resources->getConnection('review_read')); - $this->_summaryTable = $resources->getTableName('review/review_aggregate'); - - $this->_select->from($this->_summaryTable); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('review/review_summary')); - } - - public function addEntityFilter($entityId, $entityType=1) - { - $this->_select->where('entity_pk_value IN(?)', $entityId) - ->where('entity_type = ?', $entityType); - return $this; - } - - public function addStoreFilter($storeId) - { - $this->_select->where('store_id = ?', $storeId); - return $this; - } } diff --git a/app/code/core/Mage/Review/Model/Observer.php b/app/code/core/Mage/Review/Model/Observer.php index e5f5830b7d..f4a54ec8f8 100644 --- a/app/code/core/Mage/Review/Model/Observer.php +++ b/app/code/core/Mage/Review/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -61,6 +61,24 @@ public function processProductAfterDeleteEvent(Varien_Event_Observer $observer) if ($eventProduct && $eventProduct->getId()) { Mage::getResourceSingleton('review/review')->deleteReviewsByProductId($eventProduct->getId()); } + + return $this; + } + + /** + * Append review summary before rendering html + * + * @param Varien_Event_Observer $observer + * @return Mage_Review_Model_Observer + */ + public function catalogBlockProductCollectionBeforeToHtml(Varien_Event_Observer $observer) + { + $productCollection = $observer->getEvent()->getCollection(); + if ($productCollection instanceof Varien_Data_Collection) { + $productCollection->load(); + Mage::getModel('review/review')->appendSummary($productCollection); + } + return $this; } } diff --git a/app/code/core/Mage/Review/Model/Resource/Review.php b/app/code/core/Mage/Review/Model/Resource/Review.php new file mode 100755 index 0000000000..d39b8b782b --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review.php @@ -0,0 +1,441 @@ + + */ +class Mage_Review_Model_Resource_Review extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Review table + * + * @var string + */ + protected $_reviewTable; + + /** + * Review Detail table + * + * @var string + */ + protected $_reviewDetailTable; + + /** + * Review status table + * + * @var string + */ + protected $_reviewStatusTable; + + /** + * Review entity table + * + * @var string + */ + protected $_reviewEntityTable; + + /** + * Review store table + * + * @var string + */ + protected $_reviewStoreTable; + + /** + * Review aggregate table + * + * @var string + */ + protected $_aggregateTable; + + /** + * Cache of deleted rating data + * + * @var array + */ + private $_deleteCache = array(); + + /** + * Define main table. Define other tables name + * + */ + protected function _construct() + { + $this->_init('review/review', 'review_id'); + $this->_reviewTable = $this->getTable('review/review'); + $this->_reviewDetailTable = $this->getTable('review/review_detail'); + $this->_reviewStatusTable = $this->getTable('review/review_status'); + $this->_reviewEntityTable = $this->getTable('review/review_entity'); + $this->_reviewStoreTable = $this->getTable('review/review_store'); + $this->_aggregateTable = $this->getTable('review/review_aggregate'); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param unknown_type $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $select->join( + $this->_reviewDetailTable, + $this->getMainTable().".review_id = {$this->_reviewDetailTable}.review_id" + ); + return $select; + } + + /** + * Perform actions before object save + * + * @param Varien_Object $object + * @return Mage_Review_Model_Resource_Review + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getId()) { + $object->setCreatedAt(Mage::getSingleton('core/date')->gmtDate()); + } + if ($object->hasData('stores') && is_array($object->getStores())) { + $stores = $object->getStores(); + $stores[] = 0; + $object->setStores($stores); + } elseif ($object->hasData('stores')) { + $object->setStores(array($object->getStores(), 0)); + } + return $this; + } + + /** + * Perform actions after object save + * + * @param Varien_Object $object + * @return Mage_Review_Model_Resource_Review + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getWriteAdapter(); + /** + * save detail + */ + $detail = array( + 'title' => $object->getTitle(), + 'detail' => $object->getDetail(), + 'nickname' => $object->getNickname(), + ); + $select = $adapter->select() + ->from($this->_reviewDetailTable, 'detail_id') + ->where('review_id = :review_id'); + $detailId = $adapter->fetchOne($select, array(':review_id' => $object->getId())); + + if ($detailId) { + $condition = array("detail_id = ?" => $detailId); + $adapter->update($this->_reviewDetailTable, $detail, $condition); + } else { + $detail['store_id'] = $object->getStoreId(); + $detail['customer_id']= $object->getCustomerId(); + $detail['review_id'] = $object->getId(); + $adapter->insert($this->_reviewDetailTable, $detail); + } + + + /** + * save stores + */ + $stores = $object->getStores(); + if (!empty($stores)) { + $condition = array('review_id = ?' => $object->getId()); + $adapter->delete($this->_reviewStoreTable, $condition); + + $insertedStoreIds = array(); + foreach ($stores as $storeId) { + if (in_array($storeId, $insertedStoreIds)) { + continue; + } + + $insertedStoreIds[] = $storeId; + $storeInsert = array( + 'store_id' => $storeId, + 'review_id'=> $object->getId() + ); + $adapter->insert($this->_reviewStoreTable, $storeInsert); + } + } + + // reaggregate ratings, that depend on this review + $this->_aggregateRatings( + $this->_loadVotedRatingIds($object->getId()), + $object->getEntityPkValue() + ); + + return $this; + } + + /** + * Perform actions after object load + * + * @param Varien_Object $object + * @return Mage_Review_Model_Resource_Review + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->_reviewStoreTable, array('store_id')) + ->where('review_id = :review_id'); + $stores = $adapter->fetchCol($select, array(':review_id' => $object->getId())); + if (empty($stores) && Mage::app()->isSingleStoreMode()) { + $object->setStores(array(Mage::app()->getStore(true)->getId())); + } else { + $object->setStores($stores); + } + return $this; + } + + /** + * Action before delete + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Review_Model_Resource_Review + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $object) + { + // prepare rating ids, that depend on review + $this->_deleteCache = array( + 'ratingIds' => $this->_loadVotedRatingIds($object->getId()), + 'entityPkValue' => $object->getEntityPkValue() + ); + return $this; + } + + /** + * Perform actions after object delete + * + * @param Varien_Object $object + * @return Mage_Review_Model_Resource_Review + */ + protected function _afterDelete(Mage_Core_Model_Abstract $object) + { + $this->aggregate($object); + + // reaggregate ratings, that depended on this review + $this->_aggregateRatings( + $this->_deleteCache['ratingIds'], + $this->_deleteCache['entityPkValue'] + ); + $this->_deleteCache = array(); + + return $this; + } + + /** + * Retrieves total reviews + * + * @param int $entityPkValue + * @param bool $approvedOnly + * @param int $storeId + * @return int + */ + public function getTotalReviews($entityPkValue, $approvedOnly = false, $storeId = 0) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->_reviewTable, + array( + 'review_count' => new Zend_Db_Expr('COUNT(*)') + )) + ->where("{$this->_reviewTable}.entity_pk_value = :pk_value"); + $bind = array(':pk_value' => $entityPkValue); + if ($storeId > 0) { + $select->join(array('store'=>$this->_reviewStoreTable), + $this->_reviewTable.'.review_id=store.review_id AND store.store_id = :store_id', + array()); + $bind[':store_id'] = (int)$storeId; + } + if ($approvedOnly) { + $select->where("{$this->_reviewTable}.status_id = :status_id"); + $bind[':status_id'] = 1; + } + return $adapter->fetchOne($select, $bind); + } + + /** + * Aggregate + * + * @param Mage_Core_Model_Abstract $object + */ + public function aggregate($object) + { + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + if (!$object->getEntityPkValue() && $object->getId()) { + $object->load($object->getReviewId()); + } + + $ratingModel = Mage::getModel('rating/rating'); + $ratingSummaries= $ratingModel->getEntitySummary($object->getEntityPkValue(), false); + + foreach ($ratingSummaries as $ratingSummaryObject) { + if ($ratingSummaryObject->getCount()) { + $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount()); + } else { + $ratingSummary = $ratingSummaryObject->getSum(); + } + + $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId()); + $select = $readAdapter->select() + ->from($this->_aggregateTable) + ->where('entity_pk_value = :pk_value') + ->where('entity_type = :entity_type') + ->where('store_id = :store_id'); + $bind = array( + ':pk_value' => $object->getEntityPkValue(), + ':entity_type' => $object->getEntityId(), + ':store_id' =>$ratingSummaryObject->getStoreId() + ); + $oldData = $readAdapter->fetchRow($select, $bind); + + $data = new Varien_Object(); + + $data->setReviewsCount($reviewsCount) + ->setEntityPkValue($object->getEntityPkValue()) + ->setEntityType($object->getEntityId()) + ->setRatingSummary(($ratingSummary > 0) ? $ratingSummary : 0) + ->setStoreId($ratingSummaryObject->getStoreId()); + + $writeAdapter->beginTransaction(); + try { + if ($oldData['primary_id'] > 0) { + $condition = array("{$this->_aggregateTable}.primary_id = ?" => $oldData['primary_id']); + $writeAdapter->update($this->_aggregateTable, $data->getData(), $condition); + } else { + $writeAdapter->insert($this->_aggregateTable, $data->getData()); + } + $writeAdapter->commit(); + } catch (Exception $e) { + $writeAdapter->rollBack(); + } + } + } + + /** + * Get rating IDs from review votes + * + * @param int $reviewId + * @return array + */ + protected function _loadVotedRatingIds($reviewId) + { + $adapter = $this->_getReadAdapter(); + if (empty($reviewId)) { + return array(); + } + $select = $adapter->select() + ->from(array('v' => $this->getTable('rating/rating_option_vote')), 'r.rating_id') + ->joinInner(array('r' => $this->getTable('rating/rating')), 'v.rating_id=r.rating_id') + ->where('v.review_id = :revire_id'); + return $adapter->fetchCol($select, array(':revire_id' => $reviewId)); + } + + /** + * Aggregate this review's ratings. + * Useful, when changing the review. + * + * @param array $ratingIds + * @param int $entityPkValue + * @return Mage_Review_Model_Resource_Review + */ + protected function _aggregateRatings($ratingIds, $entityPkValue) + { + if ($ratingIds && !is_array($ratingIds)) { + $ratingIds = array((int)$ratingIds); + } + if ($ratingIds && $entityPkValue + && ($resource = Mage::getResourceSingleton('rating/rating_option')) + ) { + foreach ($ratingIds as $ratingId) { + $resource->aggregateEntityByRatingId( + $ratingId, $entityPkValue + ); + } + } + return $this; + } + + /** + * Reaggregate this review's ratings. + * + * @param int $reviewId + * @param int $entityPkValue + */ + public function reAggregateReview($reviewId, $entityPkValue) + { + $this->_aggregateRatings($this->_loadVotedRatingIds($reviewId), $entityPkValue); + } + + /** + * Get review entity type id by code + * + * @param string $entityCode + * @return int|bool + */ + public function getEntityIdByCode($entityCode) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->_reviewEntityTable, array('entity_id')) + ->where('entity_code = :entity_code'); + return $adapter->fetchOne($select, array(':entity_code' => $entityCode)); + } + + /** + * Delete reviews by product id. + * Better to call this method in transaction, because operation performed on two separated tables + * + * @param int $productId + * @return Mage_Review_Model_Resource_Review + */ + public function deleteReviewsByProductId($productId) + { + $this->_getWriteAdapter()->delete($this->_reviewTable, array( + 'entity_pk_value=?' => $productId, + 'entity_id=?' => $this->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE) + )); + $this->_getWriteAdapter()->delete($this->getTable('review/review_aggregate'), array( + 'entity_pk_value=?' => $productId, + 'entity_type=?' => $this->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE) + )); + return $this; + } +} diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Collection.php b/app/code/core/Mage/Review/Model/Resource/Review/Collection.php new file mode 100755 index 0000000000..1189620c6f --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Collection.php @@ -0,0 +1,309 @@ + + */ +class Mage_Review_Model_Resource_Review_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Review table + * + * @var string + */ + protected $_reviewTable; + + /** + * Review detail table + * + * @var string + */ + protected $_reviewDetailTable; + + /** + * Review status table + * + * @var string + */ + protected $_reviewStatusTable; + + /** + * Review entity table + * + * @var string + */ + protected $_reviewEntityTable; + + /** + * Review store table + * + * @var string + */ + protected $_reviewStoreTable; + + /** + * Add store data flag + * @var bool + */ + protected $_addStoreDataFlag = false; + + /** + * Define module + * + */ + protected function _construct() + { + $this->_init('review/review'); + $this->_reviewTable = $this->getTable('review/review'); + $this->_reviewDetailTable = $this->getTable('review/review_detail'); + $this->_reviewStatusTable = $this->getTable('review/review_status'); + $this->_reviewEntityTable = $this->getTable('review/review_entity'); + $this->_reviewStoreTable = $this->getTable('review/review_store'); + + } + + /** + * init select + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->getSelect() + ->join(array('detail' => $this->_reviewDetailTable), + 'main_table.review_id = detail.review_id', + array('detail_id', 'title', 'detail', 'nickname', 'customer_id')); + return $this; + } + + /** + * Enter description here ... + * + * @param unknown_type $customerId + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addCustomerFilter($customerId) + { + $this->addFilter('customer', + $this->getConnection()->quoteInto('detail.customer_id=?', $customerId), + 'string'); + return $this; + } + + /** + * Add store filter + * + * @param int|array $storeId + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addStoreFilter($storeId) + { + $inCond = $this->getConnection()->prepareSqlCondition('store.store_id', array('in' => $storeId)); + $this->getSelect()->join(array('store'=>$this->_reviewStoreTable), + 'main_table.review_id=store.review_id', + array()); + $this->getSelect()->where($inCond); + return $this; + } + + /** + * Add stores data + * + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addStoreData() + { + $this->_addStoreDataFlag = true; + return $this; + } + + /** + * Add entity filter + * + * @param int|string $entity + * @param int $pkValue + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addEntityFilter($entity, $pkValue) + { + if (is_numeric($entity)) { + $this->addFilter('entity', + $this->getConnection()->quoteInto('main_table.entity_id=?', $entity), + 'string'); + } elseif (is_string($entity)) { + $this->_select->join($this->_reviewEntityTable, + 'main_table.entity_id='.$this->_reviewEntityTable.'.entity_id', + array('entity_code')); + + $this->addFilter('entity', + $this->getConnection()->quoteInto($this->_reviewEntityTable.'.entity_code=?', $entity), + 'string'); + } + + $this->addFilter('entity_pk_value', + $this->getConnection()->quoteInto('main_table.entity_pk_value=?', $pkValue), + 'string'); + + return $this; + } + + /** + * Add status filter + * + * @param int|string $status + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addStatusFilter($status) + { + if (is_numeric($status)) { + $this->addFilter('status', + $this->getConnection()->quoteInto('main_table.status_id=?', $status), + 'string'); + } elseif (is_string($status)) { + $this->_select->join($this->_reviewStatusTable, + 'main_table.status_id='.$this->_reviewStatusTable.'.status_id', + array('status_code')); + + $this->addFilter('status', + $this->getConnection()->quoteInto($this->_reviewStatusTable.'.status_code=?', $status), + 'string'); + } + return $this; + } + + /** + * Set date order + * + * @param string $dir + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function setDateOrder($dir = 'DESC') + { + $this->setOrder('main_table.created_at', $dir); + return $this; + } + + /** + * Add rate votes + * + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addRateVotes() + { + foreach ($this->getItems() as $item) { + $votesCollection = Mage::getModel('rating/rating_option_vote') + ->getResourceCollection() + ->setReviewFilter($item->getId()) + ->setStoreFilter(Mage::app()->getStore()->getId()) + ->addRatingInfo(Mage::app()->getStore()->getId()) + ->load(); + $item->setRatingVotes($votesCollection); + } + + return $this; + } + + /** + * Add reviews total count + * + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function addReviewsTotalCount() + { + $this->_select->joinLeft( + array('r' => $this->_reviewTable), + 'main_table.entity_pk_value = r.entity_pk_value', + array('total_reviews' => new Zend_Db_Expr('COUNT(r.review_id)')) + ) + ->group('main_table.review_id'); + + /* + * Allow analytic functions usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Load data + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Review_Model_Resource_Review_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + Mage::dispatchEvent('review_review_collection_load_before', array('collection' => $this)); + parent::load($printQuery, $logQuery); + if ($this->_addStoreDataFlag) { + $this->_addStoreData(); + } + return $this; + } + + /** + * Add store data + * + */ + protected function _addStoreData() + { + $adapter = $this->getConnection(); + + $reviewsIds = $this->getColumnValues('review_id'); + $storesToReviews = array(); + if (count($reviewsIds)>0) { + $inCond = $adapter->prepareSqlCondition('review_id', array('in' => $reviewsIds)); + $select = $adapter->select() + ->from($this->_reviewStoreTable) + ->where($inCond); + $result = $adapter->fetchAll($select); + foreach ($result as $row) { + if (!isset($storesToReviews[$row['review_id']])) { + $storesToReviews[$row['review_id']] = array(); + } + $storesToReviews[$row['review_id']][] = $row['store_id']; + } + } + + foreach ($this as $item) { + if (isset($storesToReviews[$item->getId()])) { + $item->setStores($storesToReviews[$item->getId()]); + } else { + $item->setStores(array()); + } + } + } +} 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 new file mode 100755 index 0000000000..2db2de2b02 --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Product/Collection.php @@ -0,0 +1,481 @@ + + */ +class Mage_Review_Model_Resource_Review_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Entities alias + * + * @var array + */ + protected $_entitiesAlias = array(); + + /** + * Review store table + * + * @var string + */ + protected $_reviewStoreTable; + + /** + * Add store data flag + * + * @var boolean + */ + protected $_addStoreDataFlag = false; + + + /** + * Filter by stores for the collection + * + * @var array + */ + protected $_storesIds = array(); + + /** + * Define module + * + */ + protected function _construct() + { + $this->_init('catalog/product'); + $this->setRowIdFieldName('review_id'); + $this->_reviewStoreTable = Mage::getSingleton('core/resource')->getTableName('review/review_store'); + $this->_initTables(); + } + + /** + * init select + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinFields(); + return $this; + } + + /** + * Adds store filter into array + * + * @param mixed $storeId + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addStoreFilter($storeId = null) + { + if (is_null($storeId)) { + $storeId = $this->getStoreId(); + } + + parent::addStoreFilter($storeId); + + if (!is_array($storeId)) { + $storeId = array($storeId); + } + + if (!empty($this->_storesIds)) { + $this->_storesIds = array_intersect($this->_storesIds, $storeId); + } else { + $this->_storesIds = $storeId; + } + + return $this; + } + + /** + * Adds specific store id into array + * + * @param array $storeId + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function setStoreFilter($storeId) + { + if (is_array($storeId) && isset($storeId['eq'])) { + $storeId = array_shift($storeId); + } + + if (!is_array($storeId)){ + $storeId = array($storeId); + } + + if (!empty($this->_storesIds)){ + $this->_storesIds = array_intersect($this->_storesIds, $storeId); + } else { + $this->_storesIds = $storeId; + } + + return $this; + } + + /** + * Applies all store filters in one place to prevent multiple joins in select + * + * @param null|Zend_Db_Select $select + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _applyStoresFilterToSelect(Zend_Db_Select $select = null) + { + $adapter = $this->getConnection(); + $storesIds = $this->_storesIds; + if (is_null($select)){ + $select = $this->getSelect(); + } + + if (is_array($storesIds) && (count($storesIds) == 1)) { + $storesIds = array_shift($storesIds); + } + + if (is_array($storesIds) && !empty($storesIds)) { + $inCond = $adapter->prepareSqlCondition('store.store_id', array('in' => $storesIds)); + $select->join(array('store' => $this->_reviewStoreTable), + 'rt.review_id=store.review_id AND ' . $inCond, + array()) + ->distinct(true); + } else { + $select->join(array('store' => $this->_reviewStoreTable), + $adapter->quoteInto('rt.review_id=store.review_id AND store.store_id = ?', (int)$storesIds), + array()); + } + + return $this; + } + + /** + * Add stores data + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addStoreData() + { + $this->_addStoreDataFlag = true; + return $this; + } + + /** + * Add customer filter + * + * @param int $customerId + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addCustomerFilter($customerId) + { + $this->getSelect() + ->where('rdt.customer_id = ?', $customerId); + return $this; + } + + /** + * Add entity filter + * + * @param int $entityId + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addEntityFilter($entityId) + { + $this->getSelect() + ->where('rt.entity_pk_value = ?', $entityId); + return $this; + } + + /** + * Add status filter + * + * @param mixed $status + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addStatusFilter($status) + { + $this->getSelect() + ->where('rt.status_id = ?', $status); + return $this; + } + + /** + * Set date order + * + * @param string $dir + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function setDateOrder($dir = 'DESC') + { + $this->setOrder('rt.created_at', $dir); + return $this; + } + + /** + * Add review summary + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addReviewSummary() + { + foreach ($this->getItems() as $item) { + $model = Mage::getModel('rating/rating'); + $model->getReviewSummary($item->getReviewId()); + $item->addData($model->getData()); + } + return $this; + } + + /** + * Add rote votes + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addRateVotes() + { + foreach ($this->getItems() as $item) { + $votesCollection = Mage::getModel('rating/rating_option_vote') + ->getResourceCollection() + ->setEntityPkFilter($item->getEntityId()) + ->setStoreFilter(Mage::app()->getStore()->getId()) + ->load(); + $item->setRatingVotes($votesCollection); + } + return $this; + } + + /** + * join fields to entity + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _joinFields() + { + $reviewTable = Mage::getSingleton('core/resource')->getTableName('review/review'); + $reviewDetailTable = Mage::getSingleton('core/resource')->getTableName('review/review_detail'); + + $this->addAttributeToSelect('name') + ->addAttributeToSelect('sku'); + + $this->getSelect() + ->join(array('rt' => $reviewTable), + 'rt.entity_pk_value = e.entity_id', + array('rt.review_id', 'review_created_at'=> 'rt.created_at', 'rt.entity_pk_value', 'rt.status_id')) + ->join(array('rdt' => $reviewDetailTable), + 'rdt.review_id = rt.review_id', + array('rdt.title','rdt.nickname', 'rdt.detail', 'rdt.customer_id', 'rdt.store_id')); + return $this; + } + + /** + * Retrive all ids for collection + * + * @param unknown_type $limit + * @param unknown_type $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + $idsSelect = clone $this->getSelect(); + $idsSelect->reset(Zend_Db_Select::ORDER); + $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $idsSelect->reset(Zend_Db_Select::COLUMNS); + $idsSelect->columns('rt.review_id'); + return $this->getConnection()->fetchCol($idsSelect); + } + + /** + * Render SQL for retrieve product count + * + * @return string + */ + public function getSelectCountSql() + { + $select = parent::getSelectCountSql(); + + $select->reset(Zend_Db_Select::HAVING); + + return $select; + } + + /** + * Set order to attribute + * + * @param string $attribute + * @param string $dir + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function setOrder($attribute, $dir = 'DESC') + { + switch($attribute) { + case 'rt.review_id': + case 'rt.created_at': + case 'rt.status_id': + case 'rdt.title': + case 'rdt.nickname': + case 'rdt.detail': + $this->getSelect()->order($attribute . ' ' . $dir); + break; + case 'stores': + // No way to sort + break; + case 'type': + $this->getSelect()->order('rdt.customer_id ' . $dir); + break; + default: + parent::setOrder($attribute, $dir); + } + return $this; + } + + /** + * Add attribute to filter + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|string $attribute + * @param array $condition + * @param string $joinType + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner') + { + switch($attribute) { + case 'rt.review_id': + case 'rt.created_at': + case 'rt.status_id': + case 'rdt.title': + case 'rdt.nickname': + case 'rdt.detail': + $conditionSql = $this->_getConditionSql($attribute, $condition); + $this->getSelect()->where($conditionSql); + break; + case 'stores': + $this->setStoreFilter($condition); + break; + case 'type': + if ($condition == 1) { + $conditionParts = array( + $this->_getConditionSql('rdt.customer_id', array('is' => 'NULL')), + $this->_getConditionSql('rdt.store_id', array('eq' => Mage_Core_Model_App::ADMIN_STORE_ID)) + ); + $conditionSql = implode(' AND ', $conditionParts); + } elseif ($condition == 2) { + $conditionSql = $this->_getConditionSql('rdt.customer_id', array('gt' => 0)); + } else { + $conditionParts = array( + $this->_getConditionSql('rdt.customer_id', array('is' => 'NULL')), + $this->_getConditionSql('rdt.store_id', array('neq' => Mage_Core_Model_App::ADMIN_STORE_ID)) + ); + $conditionSql = implode(' AND ', $conditionParts); + } + $this->getSelect()->where($conditionSql); + break; + + default: + parent::addAttributeToFilter($attribute, $condition, $joinType); + break; + } + return $this; + } + + /** + * Retrieves column values + * + * @param string $colName + * @return array + */ + public function getColumnValues($colName) + { + $col = array(); + foreach ($this->getItems() as $item) { + $col[] = $item->getData($colName); + } + return $col; + } + + /** + * Action after load + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + if ($this->_addStoreDataFlag) { + $this->_addStoreData(); + } + return $this; + } + + /** + * Add store data + * + */ + protected function _addStoreData() + { + $adapter = $this->getConnection(); + //$this->_getConditionSql('rdt.customer_id', array('null' => null)); + $reviewsIds = $this->getColumnValues('review_id'); + $storesToReviews = array(); + if (count($reviewsIds)>0) { + $reviewIdCondition = $this->_getConditionSql('review_id', array('in' => $reviewsIds)); + $storeIdCondition = $this->_getConditionSql('store_id', array('gt' => 0)); + $select = $adapter->select() + ->from($this->_reviewStoreTable) + ->where($reviewIdCondition) + ->where($storeIdCondition); + $result = $adapter->fetchAll($select); + foreach ($result as $row) { + if (!isset($storesToReviews[$row['review_id']])) { + $storesToReviews[$row['review_id']] = array(); + } + $storesToReviews[$row['review_id']][] = $row['store_id']; + } + } + + foreach ($this as $item) { + if (isset($storesToReviews[$item->getReviewId()])) { + $item->setData('stores', $storesToReviews[$item->getReviewId()]); + } else { + $item->setData('stores', array()); + } + + } + } + + /** + * Redeclare parent method for store filters applying + * + * @return Mage_Review_Model_Resource_Review_Product_Collection + */ + protected function _beforeLoad() + { + parent::_beforeLoad(); + $this->_applyStoresFilterToSelect(); + + return $this; + } +} diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Status.php b/app/code/core/Mage/Review/Model/Resource/Review/Status.php new file mode 100644 index 0000000000..3cf5396c8a --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Status.php @@ -0,0 +1,46 @@ + + */ +class Mage_Review_Model_Resource_Review_Status extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Resource status model initialization + * + */ + protected function _construct() + { + $this->_init('review/review_status', 'status_id'); + } +} diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Status/Collection.php b/app/code/core/Mage/Review/Model/Resource/Review/Status/Collection.php new file mode 100755 index 0000000000..ce6a449349 --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Status/Collection.php @@ -0,0 +1,62 @@ + + */ +class Mage_Review_Model_Resource_Review_Status_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Review status table + * + * @var string + */ + protected $_reviewStatusTable; + + /** + * Collection model initialization + * + */ + protected function _construct() + { + $this->_init('review/review_status'); + } + + /** + * Convert items array to array for select options + * + * @return array + */ + public function toOptionArray() + { + return parent::_toOptionArray('status_id', 'status_code'); + } +} diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Summary.php b/app/code/core/Mage/Review/Model/Resource/Review/Summary.php new file mode 100755 index 0000000000..f5c11b9548 --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Summary.php @@ -0,0 +1,97 @@ + + */ +class Mage_Review_Model_Resource_Review_Summary extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define module + * + */ + protected function _construct() + { + $this->_init('review/review_aggregate', 'entity_pk_value'); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return unknown + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $select->where('store_id = ?', (int)$object->getStoreId()); + return $select; + } + + /** + * Reaggregate all data by rating summary + * + * @param array $summary + * @return Mage_Review_Model_Resource_Review_Summary + */ + public function reAggregate($summary) + { + $adapter = $this->_getWriteAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), + array( + 'primary_id' => new Zend_Db_Expr('MAX(primary_id)'), + 'store_id', + 'entity_pk_value' + )) + ->group(array('entity_pk_value', 'store_id')); + foreach ($adapter->fetchAll($select) as $row) { + if (isset($summary[$row['store_id']]) && isset($summary[$row['store_id']][$row['entity_pk_value']])) { + $summaryItem = $summary[$row['store_id']][$row['entity_pk_value']]; + if ($summaryItem->getCount()) { + $ratingSummary = round($summaryItem->getSum() / $summaryItem->getCount()); + } else { + $ratingSummary = $summaryItem->getSum(); + } + } else { + $ratingSummary = 0; + } + $adapter->update( + $this->getMainTable(), + array('rating_summary' => $ratingSummary), + $adapter->quoteInto('primary_id = ?', $row['primary_id']) + ); + } + return $this; + } +} diff --git a/app/code/core/Mage/Review/Model/Resource/Review/Summary/Collection.php b/app/code/core/Mage/Review/Model/Resource/Review/Summary/Collection.php new file mode 100755 index 0000000000..2b4dd5c8b8 --- /dev/null +++ b/app/code/core/Mage/Review/Model/Resource/Review/Summary/Collection.php @@ -0,0 +1,86 @@ + + */ +class Mage_Review_Model_Resource_Review_Summary_Collection extends Varien_Data_Collection_Db +{ + /** + * Enter description here ... + * + * @var unknown + */ + protected $_summaryTable; + + /** + * Enter description here ... + * + */ + public function __construct() + { + $resources = Mage::getSingleton('core/resource'); + $this->_setIdFieldName('primary_id'); + + parent::__construct($resources->getConnection('review_read')); + $this->_summaryTable = $resources->getTableName('review/review_aggregate'); + + $this->_select->from($this->_summaryTable); + + $this->setItemObjectClass(Mage::getConfig()->getModelClassName('review/review_summary')); + } + + /** + * Add entity filter + * + * @param unknown_type $entityId + * @param unknown_type $entityType + * @return Mage_Review_Model_Resource_Review_Summary_Collection + */ + public function addEntityFilter($entityId, $entityType = 1) + { + $this->_select->where('entity_pk_value IN(?)', $entityId) + ->where('entity_type = ?', $entityType); + return $this; + } + + /** + * Add store filter + * + * @param int $storeId + * @return Mage_Review_Model_Resource_Review_Summary_Collection + */ + public function addStoreFilter($storeId) + { + $this->_select->where('store_id = ?', $storeId); + return $this; + } +} diff --git a/app/code/core/Mage/Review/Model/Review.php b/app/code/core/Mage/Review/Model/Review.php index 127288934c..132343bcee 100644 --- a/app/code/core/Mage/Review/Model/Review.php +++ b/app/code/core/Mage/Review/Model/Review.php @@ -20,15 +20,25 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Review model * - * @category Mage - * @package Mage_Review + * @method Mage_Review_Model_Resource_Review _getResource() + * @method Mage_Review_Model_Resource_Review getResource() + * @method string getCreatedAt() + * @method Mage_Review_Model_Review setCreatedAt(string $value) + * @method Mage_Review_Model_Review setEntityId(int $value) + * @method int getEntityPkValue() + * @method Mage_Review_Model_Review setEntityPkValue(int $value) + * @method int getStatusId() + * @method Mage_Review_Model_Review setStatusId(int $value) + * + * @category Mage + * @package Mage_Review * @author Magento Core Team */ class Mage_Review_Model_Review extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Simple.php b/app/code/core/Mage/Review/Model/Review/Status.php similarity index 75% rename from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Simple.php rename to app/code/core/Mage/Review/Model/Review/Status.php index 280f6764b6..85981b5dda 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Composite/Fieldset/Simple.php +++ b/app/code/core/Mage/Review/Model/Review/Status.php @@ -19,19 +19,25 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Review + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Adminhtml block for fieldset of simple product + * Review status * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Review * @author Magento Core Team */ -class Mage_Adminhtml_Block_Catalog_Product_Composite_Fieldset_Simple extends Mage_Adminhtml_Block_Catalog_Product_Composite_Configure + +class Mage_Review_Model_Review_Status extends Mage_Core_Model_Abstract { + public function __construct() + { + $this->_init('review/review_status'); + } + } diff --git a/app/code/core/Mage/Review/Model/Review/Summary.php b/app/code/core/Mage/Review/Model/Review/Summary.php index 9e6d9c6062..fa463b9c3a 100644 --- a/app/code/core/Mage/Review/Model/Review/Summary.php +++ b/app/code/core/Mage/Review/Model/Review/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/Model/Session.php b/app/code/core/Mage/Review/Model/Session.php index 36fa438a9a..0225f8b769 100644 --- a/app/code/core/Mage/Review/Model/Session.php +++ b/app/code/core/Mage/Review/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/controllers/CustomerController.php b/app/code/core/Mage/Review/controllers/CustomerController.php index c506d637bb..f4594d0a6a 100644 --- a/app/code/core/Mage/Review/controllers/CustomerController.php +++ b/app/code/core/Mage/Review/controllers/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/controllers/ProductController.php b/app/code/core/Mage/Review/controllers/ProductController.php index 9cbdd43383..4cf922e378 100644 --- a/app/code/core/Mage/Review/controllers/ProductController.php +++ b/app/code/core/Mage/Review/controllers/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -296,4 +296,3 @@ protected function _initProductLayout($product) $this->generateLayoutXml()->generateLayoutBlocks(); } } - diff --git a/app/code/core/Mage/Review/data/review_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Review/data/review_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..5aad520c99 --- /dev/null +++ b/app/code/core/Mage/Review/data/review_setup/data-install-1.6.0.0.php @@ -0,0 +1,61 @@ + + */ + +/* @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; + +//Fill table review/review_entity +$reviewEntityCodes = array( + Mage_Review_Model_Review::ENTITY_PRODUCT_CODE, + Mage_Review_Model_Review::ENTITY_CUSTOMER_CODE, + Mage_Review_Model_Review::ENTITY_CATEGORY_CODE, +); +foreach ($reviewEntityCodes as $entityCode) { + $installer->getConnection() + ->insert($installer->getTable('review/review_entity'), array('entity_code' => $entityCode)); +} + +//Fill table review/review_entity +$reviewStatuses = array( + Mage_Review_Model_Review::STATUS_APPROVED => 'Approved', + Mage_Review_Model_Review::STATUS_PENDING => 'Pending', + Mage_Review_Model_Review::STATUS_NOT_APPROVED => 'Not Approved' +); +foreach ($reviewStatuses as $k => $v) { + $bind = array( + 'status_id' => $k, + 'status_code' => $v + ); + $installer->getConnection()->insertForce($installer->getTable('review/review_status'), $bind); +} diff --git a/app/code/core/Mage/Review/etc/adminhtml.xml b/app/code/core/Mage/Review/etc/adminhtml.xml index 2eca506a2c..b7447d7c37 100644 --- a/app/code/core/Mage/Review/etc/adminhtml.xml +++ b/app/code/core/Mage/Review/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -54,6 +54,24 @@ + + + + Reviews + 55 + + + Customers Reviews + adminhtml/report_review/customer + + + Products Reviews + adminhtml/report_review/product + + + + + diff --git a/app/code/core/Mage/Review/etc/config.xml b/app/code/core/Mage/Review/etc/config.xml index 0d7a606035..cdfa691a9f 100644 --- a/app/code/core/Mage/Review/etc/config.xml +++ b/app/code/core/Mage/Review/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.6 + 1.6.0.0 Mage_Review_Model - review_mysql4 + review_resource - - Mage_Review_Model_Mysql4 + + Mage_Review_Model_Resource + review_mysql4 review
      @@ -59,7 +60,7 @@ review_store
      -
      +
      @@ -69,9 +70,9 @@ - - Mage_Review_Block - + + Mage_Review_Block +
      @@ -141,6 +142,15 @@ + + + + model + review/observer + catalogBlockProductCollectionBeforeToHtml + + + /review/customer/ diff --git a/app/code/core/Mage/Review/etc/system.xml b/app/code/core/Mage/Review/etc/system.xml index ed64ba17ed..b24512aaa4 100644 --- a/app/code/core/Mage/Review/etc/system.xml +++ b/app/code/core/Mage/Review/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Review/sql/review_setup/install-1.6.0.0.php b/app/code/core/Mage/Review/sql/review_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..b0318f6a14 --- /dev/null +++ b/app/code/core/Mage/Review/sql/review_setup/install-1.6.0.0.php @@ -0,0 +1,231 @@ + + */ +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); +/** + * Create table 'review/review_entity' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review_entity')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Review entity id') + ->addColumn('entity_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false + ), 'Review entity code') + ->setComment('Review entities'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'review/review_status' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review_status')) + ->addColumn('status_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Status id') + ->addColumn('status_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Status code') + ->setComment('Review statuses'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'review/review' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review')) + ->addColumn('review_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Review id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Review create date') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity id') + ->addColumn('entity_pk_value', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product id') + ->addColumn('status_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Status code') + ->addIndex($installer->getIdxName('review/review', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('review/review', array('status_id')), + array('status_id')) + ->addIndex($installer->getIdxName('review/review', array('entity_pk_value')), + array('entity_pk_value')) + ->addForeignKey($installer->getFkName('review/review', 'entity_id', 'review/review_entity', 'entity_id'), + 'entity_id', $installer->getTable('review/review_entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('review/review', 'status_id', 'review/review_status', 'status_id'), + 'status_id', $installer->getTable('review/review_status'), 'status_id', + Varien_Db_Ddl_Table::ACTION_NO_ACTION, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Review base information'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'review/review_detail' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review_detail')) + ->addColumn('detail_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Review detail id') + ->addColumn('review_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Review id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Store id') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Title') + ->addColumn('detail', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Detail description') + ->addColumn('nickname', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array( + 'nullable' => false, + ), 'User nickname') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addIndex($installer->getIdxName('review/review_detail', array('review_id')), + array('review_id')) + ->addIndex($installer->getIdxName('review/review_detail', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('review/review_detail', array('customer_id')), + array('customer_id')) + ->addForeignKey($installer->getFkName('review/review_detail', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('review/review_detail', 'review_id', 'review/review', 'review_id'), + 'review_id', $installer->getTable('review/review'), 'review_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('review/review_detail', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Review detail information'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'review/review_aggregate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review_aggregate')) + ->addColumn('primary_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Summary review entity id') + ->addColumn('entity_pk_value', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Product id') + ->addColumn('entity_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Entity type id') + ->addColumn('reviews_count', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Qty of reviews') + ->addColumn('rating_summary', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Summarized rating') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store id') + ->addIndex($installer->getIdxName('review/review_aggregate', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('review/review_aggregate', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Review aggregates'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'review/review_store' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('review/review_store')) + ->addColumn('review_id', Varien_Db_Ddl_Table::TYPE_BIGINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Review Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store Id') + ->addIndex($installer->getIdxName('review/review_store', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('review/review_store', 'review_id', 'review/review', 'review_id'), + 'review_id', $installer->getTable('review/review'), 'review_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('review/review_store', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Review Store'); +$installer->getConnection()->createTable($table); + +$this->endSetup(); diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-install-0.7.0.php index f6e839d4ed..188f545ce2 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.0-0.7.1.php index 2ab751176a..091ba60457 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.1-0.7.2.php index 69d585a7fc..713627a3ec 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.2-0.7.3.php index 43854b0a80..f082f758aa 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.3-0.7.4.php index 1a6f63b0ea..aa23b24f17 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.4-0.7.5.php index 5685706908..63e22af4be 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.5-0.7.6.php index e8fd8bf2cb..7c49ba08f1 100644 --- a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Review - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..d637ea23bb --- /dev/null +++ b/app/code/core/Mage/Review/sql/review_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,446 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review'), + 'FK_REVIEW_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review'), + 'FK_REVIEW_STATUS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_REVIEW' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_aggregate'), + 'FK_REVIEW_ENTITY_SUMMARY_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_store'), + 'FK_REVIEW_STORE_REVIEW' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_store'), + 'FK_REVIEW_STORE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('review/review_store'), + 'REVIEW_STORE_IBFK_1' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('review/review'), + 'FK_REVIEW_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review'), + 'FK_REVIEW_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review'), + 'FK_REVIEW_PARENT_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_REVIEW' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review_detail'), + 'FK_REVIEW_DETAIL_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review_store'), + 'FK_REVIEW_STORE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('review/review_aggregate'), + 'FK_REVIEW_ENTITY_SUMMARY_STORE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('review/review') => array( + 'columns' => array( + 'review_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Review id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Review create date' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity id' + ), + 'entity_pk_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'status_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Status code' + ) + ), + 'comment' => 'Review base information' + ), + $installer->getTable('review/review_detail') => array( + 'columns' => array( + 'detail_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Review detail id' + ), + 'review_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Review id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Store id' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Title' + ), + 'detail' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Detail description' + ), + 'nickname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'nullable' => false, + 'comment' => 'User nickname' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ) + ), + 'comment' => 'Review detail information' + ), + $installer->getTable('review/review_status') => array( + 'columns' => array( + 'status_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Status id' + ), + 'status_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Status code' + ) + ), + 'comment' => 'Review statuses' + ), + $installer->getTable('review/review_entity') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Review entity id' + ), + 'entity_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Review entity code' + ) + ), + 'comment' => 'Review entities' + ), + $installer->getTable('review/review_aggregate') => array( + 'columns' => array( + 'primary_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Summary review entity id' + ), + 'entity_pk_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product id' + ), + 'entity_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity type id' + ), + 'reviews_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Qty of reviews' + ), + 'rating_summary' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Summarized rating' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store id' + ) + ), + 'comment' => 'Review aggregates' + ), + $installer->getTable('review/review_store') => array( + 'columns' => array( + 'review_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Review Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ) + ), + 'comment' => 'Review Store' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('review/review'), + $installer->getIdxName('review/review', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review'), + $installer->getIdxName('review/review', array('status_id')), + array('status_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review'), + $installer->getIdxName('review/review', array('entity_pk_value')), + array('entity_pk_value') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review_detail'), + $installer->getIdxName('review/review_detail', array('review_id')), + array('review_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review_detail'), + $installer->getIdxName('review/review_detail', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review_detail'), + $installer->getIdxName('review/review_detail', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review_aggregate'), + $installer->getIdxName('review/review_aggregate', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('review/review_store'), + $installer->getIdxName('review/review_store', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review', 'entity_id', 'review/review_entity', 'entity_id'), + $installer->getTable('review/review'), + 'entity_id', + $installer->getTable('review/review_entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review', 'status_id', 'review/review_status', 'status_id'), + $installer->getTable('review/review'), + 'status_id', + $installer->getTable('review/review_status'), + 'status_id', + Varien_Db_Ddl_Table::ACTION_NO_ACTION, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_detail', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('review/review_detail'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_detail', 'review_id', 'review/review', 'review_id'), + $installer->getTable('review/review_detail'), + 'review_id', + $installer->getTable('review/review'), + 'review_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_detail', 'store_id', 'core/store', 'store_id'), + $installer->getTable('review/review_detail'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_aggregate', 'store_id', 'core/store', 'store_id'), + $installer->getTable('review/review_aggregate'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_store', 'review_id', 'review/review', 'review_id'), + $installer->getTable('review/review_store'), + 'review_id', + $installer->getTable('review/review'), + 'review_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('review/review_store', 'store_id', 'core/store', 'store_id'), + $installer->getTable('review/review_store'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Rss/Block/Abstract.php b/app/code/core/Mage/Rss/Block/Abstract.php index 18a1ab5f19..f271f73289 100644 --- a/app/code/core/Mage/Rss/Block/Abstract.php +++ b/app/code/core/Mage/Rss/Block/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Rss_Block_Abstract extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php index c687b90bc0..fe91a51392 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Abstract.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Rss_Block_Catalog_Abstract extends Mage_Rss_Block_Abstract diff --git a/app/code/core/Mage/Rss/Block/Catalog/Category.php b/app/code/core/Mage/Rss/Block/Catalog/Category.php index 8715abcf77..d281d7b171 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Category.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Catalog/New.php b/app/code/core/Mage/Rss/Block/Catalog/New.php index d50ed7c478..0c799322a8 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/New.php +++ b/app/code/core/Mage/Rss/Block/Catalog/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php b/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php index 206bc6bbfe..8776fddb16 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php +++ b/app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -66,14 +66,16 @@ protected function _toHtml() $_configManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); $stockItemWhere = "({{table}}.low_stock_date is not null) " - . " and ({{table}}.low_stock_date>'0000-00-00') " - . " and IF({{table}}.use_config_manage_stock=1," . $_configManageStock . ",{{table}}.manage_stock) = 1"; - + . " AND ( ({{table}}.use_config_manage_stock=1 AND ".$_configManageStock."=1)" + . " OR ({{table}}.use_config_manage_stock=0 AND {{table}}.manage_stock=1) )"; + $product = Mage::getModel('catalog/product'); $collection = $product->getCollection() ->addAttributeToSelect('name', true) ->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'), $stockItemWhere, 'inner') + ->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'), + $stockItemWhere, 'inner') ->setOrder('low_stock_date') ; $collection->addAttributeToFilter('status', array('in' => Mage::getSingleton('catalog/product_status')->getVisibleStatusIds())); diff --git a/app/code/core/Mage/Rss/Block/Catalog/Review.php b/app/code/core/Mage/Rss/Block/Catalog/Review.php index e9b861b9d0..8086d87e58 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Review.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Review.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php index aebe2510f3..931af4a163 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -66,6 +66,7 @@ protected function _toHtml() $now = date('Y-m-d'); $_saleRule = Mage::getModel('salesrule/rule'); + $collection = $_saleRule->getResourceCollection() ->addFieldToFilter('from_date', array('date'=>true, 'to' => $now)) ->addFieldToFilter('website_ids',array('finset' => $websiteId)) @@ -73,6 +74,7 @@ protected function _toHtml() ->addFieldToFilter('is_rss',1) ->addFieldToFilter('is_active',1) ->setOrder('from_date','desc'); + $collection->getSelect()->where('to_date is null or to_date>=?', $now); $collection->load(); diff --git a/app/code/core/Mage/Rss/Block/Catalog/Special.php b/app/code/core/Mage/Rss/Block/Catalog/Special.php index 9511db1b36..25e83c951a 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Special.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Special.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Catalog/Tag.php b/app/code/core/Mage/Rss/Block/Catalog/Tag.php index 5246221cf0..e3a0516351 100644 --- a/app/code/core/Mage/Rss/Block/Catalog/Tag.php +++ b/app/code/core/Mage/Rss/Block/Catalog/Tag.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -68,8 +68,12 @@ protected function _toHtml() $product = Mage::getModel('catalog/product'); - Mage::getSingleton('core/resource_iterator') - ->walk($_collection->getSelect(), array(array($this, 'addTaggedItemXml')), array('rssObj'=> $rssObj, 'product'=>$product)); + Mage::getSingleton('core/resource_iterator')->walk( + Mage::getResourceHelper('core')->getQueryUsingAnalyticFunction($_collection->getSelect()), + array(array($this, 'addTaggedItemXml')), + array('rssObj'=> $rssObj, 'product'=>$product), + $_collection->getSelect()->getAdapter() + ); return $rssObj->createRssXml(); } diff --git a/app/code/core/Mage/Rss/Block/List.php b/app/code/core/Mage/Rss/Block/List.php index 07ccb9a1d8..9f642649a8 100644 --- a/app/code/core/Mage/Rss/Block/List.php +++ b/app/code/core/Mage/Rss/Block/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Order/Details.php b/app/code/core/Mage/Rss/Block/Order/Details.php index 1fbaf0a379..b83fbd74e2 100644 --- a/app/code/core/Mage/Rss/Block/Order/Details.php +++ b/app/code/core/Mage/Rss/Block/Order/Details.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Rss_Block_Order_Details extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/Rss/Block/Order/New.php b/app/code/core/Mage/Rss/Block/Order/New.php index 47241b8889..bd9579ed37 100644 --- a/app/code/core/Mage/Rss/Block/Order/New.php +++ b/app/code/core/Mage/Rss/Block/Order/New.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Order/Status.php b/app/code/core/Mage/Rss/Block/Order/Status.php index 67cb5b7c02..87812bdb58 100644 --- a/app/code/core/Mage/Rss/Block/Order/Status.php +++ b/app/code/core/Mage/Rss/Block/Order/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Block/Wishlist.php b/app/code/core/Mage/Rss/Block/Wishlist.php index a27b2ed377..36a8871004 100644 --- a/app/code/core/Mage/Rss/Block/Wishlist.php +++ b/app/code/core/Mage/Rss/Block/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Helper/Catalog.php b/app/code/core/Mage/Rss/Helper/Catalog.php index 31eb1c502d..e6d5ab6ec0 100644 --- a/app/code/core/Mage/Rss/Helper/Catalog.php +++ b/app/code/core/Mage/Rss/Helper/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Helper/Data.php b/app/code/core/Mage/Rss/Helper/Data.php index 881f804e77..98369c9aea 100644 --- a/app/code/core/Mage/Rss/Helper/Data.php +++ b/app/code/core/Mage/Rss/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Helper/Order.php b/app/code/core/Mage/Rss/Helper/Order.php index e911c6525c..9989e44363 100644 --- a/app/code/core/Mage/Rss/Helper/Order.php +++ b/app/code/core/Mage/Rss/Helper/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Model/Mysql4/Order.php b/app/code/core/Mage/Rss/Model/Mysql4/Order.php index b19fb33138..f8d8d8f18e 100644 --- a/app/code/core/Mage/Rss/Model/Mysql4/Order.php +++ b/app/code/core/Mage/Rss/Model/Mysql4/Order.php @@ -20,142 +20,18 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Order Rss Resource Model * - * @category Mage - * @package Mage_Rss + * @category Mage + * @package Mage_Rss * @author Magento Core Team */ -class Mage_Rss_Model_Mysql4_Order +class Mage_Rss_Model_Mysql4_Order extends Mage_Rss_Model_Resource_Order { - /** - * @var array - * @deprecated after 1.4.1.0 - */ - protected $_entityTypeIdsToTypes = array(); - - /** - * @var array - * @deprecated after 1.4.1.0 - */ - protected $_entityIdsToIncrementIds = array(); - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getEntityTypeIdsToTypes() - { - return $this->_entityTypeIdsToTypes; - } - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getEntityIdsToIncrementIds() - { - return $this->_entityIdsToIncrementIds; - } - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getAllOrderEntityTypeIds() - { - return array(); - } - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getAllOrderEntityIds($orderId, $orderEntityTypes) - { - return array(); - } - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getAllEntityIds($entityIds = array()) - { - return array(); - } - - /** - * @return array - * @deprecated after 1.4.1.0 - */ - public function getAllEntityTypeCommentIds() - { - return array(); - } - - /** - * Retrieve core resource model - * - * @return Mage_Core_Model_Resource - */ - public function getCoreResource() - { - return Mage::getSingleton('core/resource'); - } - - /** - * Retrieve order comments - * - * @param int $orderId - * @return array - */ - public function getAllCommentCollection($orderId) - { - $res = $this->getCoreResource(); - $read = $res->getConnection('core_read'); - - $fields = array( - 'notified' => 'is_customer_notified', - 'comment', - 'created_at', - ); - $commentSelects = array(); - foreach (array('invoice', 'shipment', 'creditmemo') as $entityTypeCode) { - $mainTable = $res->getTableName('sales/' . $entityTypeCode); - $slaveTable = $res->getTableName('sales/' . $entityTypeCode . '_comment'); - $select = $read->select() - ->from(array('main' => $mainTable), array( - 'entity_id' => 'order_id', - 'entity_type_code' => new Zend_Db_Expr("'$entityTypeCode'") - )) - ->join(array('slave' => $slaveTable), 'main.entity_id = slave.parent_id', $fields) - ->where('main.order_id = ?', $orderId); - $commentSelects[] = '(' . $select . ')'; - } - $select = $read->select() - ->from($res->getTableName('sales/order_status_history'), array( - 'entity_id' => 'parent_id', - 'entity_type_code' => new Zend_Db_Expr("'order'") - ) + $fields) - ->where('parent_id = ?', $orderId) - ->where('is_visible_on_front > 0'); - $commentSelects[] = '(' . $select . ')'; - - $commentSelect = $read->select() - ->union($commentSelects) - ->order('created_at desc'); - - $select = $read->select() - ->from(array('order' => $res->getTableName('sales/order')), array('increment_id')) - ->join(array('t' => $commentSelect), 't.entity_id = order.entity_id'); - - return $read->fetchAll($select); - } - } diff --git a/app/code/core/Mage/Rss/Model/Observer.php b/app/code/core/Mage/Rss/Model/Observer.php index 78cb75f553..60c5493b70 100644 --- a/app/code/core/Mage/Rss/Model/Observer.php +++ b/app/code/core/Mage/Rss/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Model/Resource/Order.php b/app/code/core/Mage/Rss/Model/Resource/Order.php new file mode 100755 index 0000000000..298c3cf23b --- /dev/null +++ b/app/code/core/Mage/Rss/Model/Resource/Order.php @@ -0,0 +1,188 @@ + + */ +class Mage_Rss_Model_Resource_Order +{ + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @var array + */ + protected $_entityTypeIdsToTypes = array(); + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @var array + */ + protected $_entityIdsToIncrementIds = array(); + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @return array + */ + public function getEntityTypeIdsToTypes() + { + return $this->_entityTypeIdsToTypes; + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @return array + */ + public function getEntityIdsToIncrementIds() + { + return $this->_entityIdsToIncrementIds; + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @return array + */ + public function getAllOrderEntityTypeIds() + { + return array(); + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @param unknown_type $orderId + * @param unknown_type $orderEntityTypes + * @return array + */ + public function getAllOrderEntityIds($orderId, $orderEntityTypes) + { + return array(); + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @param unknown_type $entityIds + * @return array + */ + public function getAllEntityIds($entityIds = array()) + { + return array(); + } + + /** + * Enter description here ... + * + * @deprecated after 1.4.1.0 + * + * @return array + */ + public function getAllEntityTypeCommentIds() + { + return array(); + } + + /** + * Retrieve core resource model + * + * @return Mage_Core_Model_Resource + */ + public function getCoreResource() + { + return Mage::getSingleton('core/resource'); + } + + /** + * Retrieve order comments + * + * @param int $orderId + * @return array + */ + public function getAllCommentCollection($orderId) + { + $res = $this->getCoreResource(); + $read = $res->getConnection('core_read'); + + $fields = array( + 'notified' => 'is_customer_notified', + 'comment', + 'created_at', + ); + $commentSelects = array(); + foreach (array('invoice', 'shipment', 'creditmemo') as $entityTypeCode) { + $mainTable = $res->getTableName('sales/' . $entityTypeCode); + $slaveTable = $res->getTableName('sales/' . $entityTypeCode . '_comment'); + $select = $read->select() + ->from(array('main' => $mainTable), array( + 'entity_id' => 'order_id', + 'entity_type_code' => new Zend_Db_Expr("'$entityTypeCode'") + )) + ->join(array('slave' => $slaveTable), 'main.entity_id = slave.parent_id', $fields) + ->where('main.order_id = ?', $orderId); + $commentSelects[] = '(' . $select . ')'; + } + $select = $read->select() + ->from($res->getTableName('sales/order_status_history'), array( + 'entity_id' => 'parent_id', + 'entity_type_code' => new Zend_Db_Expr("'order'") + ) + $fields) + ->where('parent_id = ?', $orderId) + ->where('is_visible_on_front > 0'); + $commentSelects[] = '(' . $select . ')'; + + $commentSelect = $read->select() + ->union($commentSelects, Zend_Db_Select::SQL_UNION_ALL); + + $select = $read->select() + ->from(array('orders' => $res->getTableName('sales/order')), array('increment_id')) + ->join(array('t' => $commentSelect),'t.entity_id = orders.entity_id') + ->order('orders.created_at desc'); + + return $read->fetchAll($select); + } +} diff --git a/app/code/core/Mage/Rss/Model/Rss.php b/app/code/core/Mage/Rss/Model/Rss.php index 56db6d1b39..0b0ffb60ee 100644 --- a/app/code/core/Mage/Rss/Model/Rss.php +++ b/app/code/core/Mage/Rss/Model/Rss.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Model/Session.php b/app/code/core/Mage/Rss/Model/Session.php index 7e287bcd54..ee64e5af7b 100644 --- a/app/code/core/Mage/Rss/Model/Session.php +++ b/app/code/core/Mage/Rss/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/Model/System/Config/Backend/Links.php b/app/code/core/Mage/Rss/Model/System/Config/Backend/Links.php index 697bdf47ec..83166bbdff 100644 --- a/app/code/core/Mage/Rss/Model/System/Config/Backend/Links.php +++ b/app/code/core/Mage/Rss/Model/System/Config/Backend/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/controllers/CatalogController.php b/app/code/core/Mage/Rss/controllers/CatalogController.php index 845e67c970..15a2c1f4c1 100644 --- a/app/code/core/Mage/Rss/controllers/CatalogController.php +++ b/app/code/core/Mage/Rss/controllers/CatalogController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/controllers/IndexController.php b/app/code/core/Mage/Rss/controllers/IndexController.php index d678018b92..99e43024bd 100644 --- a/app/code/core/Mage/Rss/controllers/IndexController.php +++ b/app/code/core/Mage/Rss/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/controllers/OrderController.php b/app/code/core/Mage/Rss/controllers/OrderController.php index 1cb6bc291f..c16b49b56c 100644 --- a/app/code/core/Mage/Rss/controllers/OrderController.php +++ b/app/code/core/Mage/Rss/controllers/OrderController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rss/etc/adminhtml.xml b/app/code/core/Mage/Rss/etc/adminhtml.xml index 83add6828a..14eef386b7 100644 --- a/app/code/core/Mage/Rss/etc/adminhtml.xml +++ b/app/code/core/Mage/Rss/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Rss/etc/config.xml b/app/code/core/Mage/Rss/etc/config.xml index a8d89e7227..7f7b4f7719 100644 --- a/app/code/core/Mage/Rss/etc/config.xml +++ b/app/code/core/Mage/Rss/etc/config.xml @@ -21,43 +21,36 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.8.0 + 1.6.0.0 Mage_Rss_Model - rss_mysql4 + rss_resource - - Mage_Rss_Model_Mysql4 - + + Mage_Rss_Model_Resource + rss_mysql4 + - Mage_Rss_Block + + Mage_Rss_Block + - - + - diff --git a/app/code/core/Mage/Rss/etc/system.xml b/app/code/core/Mage/Rss/etc/system.xml index cf6de6d336..41df19397b 100644 --- a/app/code/core/Mage/Rss/etc/system.xml +++ b/app/code/core/Mage/Rss/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Rss - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Rule/Block/Actions.php b/app/code/core/Mage/Rule/Block/Actions.php index 4ab4b7e13f..ea0a56ad62 100644 --- a/app/code/core/Mage/Rule/Block/Actions.php +++ b/app/code/core/Mage/Rule/Block/Actions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Block/Conditions.php b/app/code/core/Mage/Rule/Block/Conditions.php index c0171808f9..678e1ef62d 100644 --- a/app/code/core/Mage/Rule/Block/Conditions.php +++ b/app/code/core/Mage/Rule/Block/Conditions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Block/Editable.php b/app/code/core/Mage/Rule/Block/Editable.php index 5b6894b115..4a33bad404 100644 --- a/app/code/core/Mage/Rule/Block/Editable.php +++ b/app/code/core/Mage/Rule/Block/Editable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Block/Newchild.php b/app/code/core/Mage/Rule/Block/Newchild.php index ec72445205..cf77582f78 100644 --- a/app/code/core/Mage/Rule/Block/Newchild.php +++ b/app/code/core/Mage/Rule/Block/Newchild.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Block/Rule.php b/app/code/core/Mage/Rule/Block/Rule.php index c2aaed1f69..4b8abbe987 100644 --- a/app/code/core/Mage/Rule/Block/Rule.php +++ b/app/code/core/Mage/Rule/Block/Rule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Helper/Data.php b/app/code/core/Mage/Rule/Helper/Data.php index 942c7e8a6e..3f1ff71ddd 100644 --- a/app/code/core/Mage/Rule/Helper/Data.php +++ b/app/code/core/Mage/Rule/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Action/Abstract.php b/app/code/core/Mage/Rule/Model/Action/Abstract.php index 307b272da7..6646a95e5e 100644 --- a/app/code/core/Mage/Rule/Model/Action/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Action/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Action/Collection.php b/app/code/core/Mage/Rule/Model/Action/Collection.php index 48bff70de2..5090e71786 100644 --- a/app/code/core/Mage/Rule/Model/Action/Collection.php +++ b/app/code/core/Mage/Rule/Model/Action/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Action/Interface.php b/app/code/core/Mage/Rule/Model/Action/Interface.php index 082a938471..6710f98f0b 100644 --- a/app/code/core/Mage/Rule/Model/Action/Interface.php +++ b/app/code/core/Mage/Rule/Model/Action/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index d6667b6240..35e8bb8294 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -217,9 +217,9 @@ public function getOperatorSelectOptions() } $opt = array(); $operatorByType = $this->getOperatorByInputType(); - foreach ($this->getOperatorOption() as $k=>$v) { + foreach ($this->getOperatorOption() as $k => $v) { if (!$operatorByType || in_array($k, $operatorByType[$type])) { - $opt[] = array('value'=>$k, 'label'=>$v); + $opt[] = array('value' => $k, 'label' => $v); } } return $opt; @@ -242,9 +242,12 @@ public function loadValueOptions() public function getValueSelectOptions() { - $opt = array(); - foreach ($this->getValueOption() as $k=>$v) { - $opt[] = array('value'=>$k, 'label'=>$v); + $valueOption = $opt = array(); + if ($this->hasValueOption()) { + $valueOption = (array) $this->getValueOption(); + } + foreach ($valueOption as $k => $v) { + $opt[] = array('value' => $k, 'label' => $v); } return $opt; } @@ -254,7 +257,7 @@ public function getValueParsed() $value = $this->getData('value'); $op = $this->getOperator(); - if (($op === '{}' || $op === '!{}' || $op==='()' || $op==='!()') && is_scalar($value)) { + if (($op === '{}' || $op === '!{}' || $op === '()' || $op === '!()') && is_scalar($value)) { $value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY); $this->setValue($value); } @@ -278,7 +281,7 @@ public function getValue() public function getValueName() { $value = $this->getValue(); - if (is_null($value) || ''===$value) { + if (is_null($value) || '' === $value) { return '...'; } @@ -298,7 +301,7 @@ public function getValueName() } } } - if ($o['value']==$value) { + if ($o['value'] == $value) { return $o['label']; } } @@ -341,11 +344,11 @@ public function asHtmlRecursive() public function getTypeElement() { - return $this->getForm()->addField($this->getPrefix().'__'.$this->getId().'__type', 'hidden', array( - 'name'=>'rule['.$this->getPrefix().']['.$this->getId().'][type]', - 'value'=>$this->getType(), - 'no_span'=>true, - 'class' => 'hidden', + return $this->getForm()->addField($this->getPrefix() . '__' . $this->getId() . '__type', 'hidden', array( + 'name' => 'rule[' . $this->getPrefix() . '][' . $this->getId() . '][type]', + 'value' => $this->getType(), + 'no_span' => true, + 'class' => 'hidden', )); } @@ -357,7 +360,7 @@ public function getTypeElementHtml() public function getAttributeElement() { if (is_null($this->getAttribute())) { - foreach ($this->getAttributeOption() as $k=>$v) { + foreach ($this->getAttributeOption() as $k => $v) { $this->setAttribute($k); break; } @@ -457,14 +460,14 @@ public function getValueElementHtml() public function getAddLinkHtml() { $src = Mage::getDesign()->getSkinUrl('images/rule_component_add.gif'); - $html = ''; + $html = ''; return $html; } public function getRemoveLinkHtml() { $src = Mage::getDesign()->getSkinUrl('images/rule_component_remove.gif'); - $html = ' '; + $html = ' '; return $html; } @@ -473,20 +476,20 @@ public function getChooserContainerHtml() $url = $this->getValueElementChooserUrl(); $html = ''; if ($url) { - $html = '
      '; + $html = '
      '; } return $html; } - public function asString($format='') + public function asString($format = '') { - $str = $this->getAttributeName().' '.$this->getOperatorName().' '.$this->getValueName(); + $str = $this->getAttributeName() . ' ' . $this->getOperatorName() . ' ' . $this->getValueName(); return $str; } public function asStringRecursive($level=0) { - $str = str_pad('', $level*3, ' ', STR_PAD_LEFT).$this->asString(); + $str = str_pad('', $level * 3, ' ', STR_PAD_LEFT) . $this->asString(); return $str; } @@ -547,7 +550,7 @@ public function validateAttribute($validatedValue) if (is_array($validatedValue) || is_null($validatedValue)) { $result = false; } else { - $result = $validatedValue<=$value; + $result = $validatedValue <= $value; } break; @@ -555,7 +558,7 @@ public function validateAttribute($validatedValue) if (is_array($validatedValue) || is_null($validatedValue)) { $result = false; } else { - $result = $validatedValue>=$value; + $result = $validatedValue >= $value; } break; @@ -578,7 +581,7 @@ public function validateAttribute($validatedValue) if (is_array($validatedValue)) { $result = false; } else { - $result = stripos((string)$validatedValue, (string)$value)!==false; + $result = stripos((string)$validatedValue, (string)$value) !== false; } } break; @@ -592,7 +595,7 @@ public function validateAttribute($validatedValue) break; } - if ('!='==$op || '>'==$op || '<'==$op || '!{}'==$op || '!()'==$op) { + if ('!=' == $op || '>' == $op || '<' == $op || '!{}' == $op || '!()' == $op) { $result = !$result; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Combine.php b/app/code/core/Mage/Rule/Model/Condition/Combine.php index 17302b8e4e..ffab00c731 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Combine.php +++ b/app/code/core/Mage/Rule/Model/Condition/Combine.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Condition/Interface.php b/app/code/core/Mage/Rule/Model/Condition/Interface.php index 7db329cd75..d73bd79c1a 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Interface.php +++ b/app/code/core/Mage/Rule/Model/Condition/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Environment.php b/app/code/core/Mage/Rule/Model/Environment.php index 63b01c4e6a..fffd91e5c7 100644 --- a/app/code/core/Mage/Rule/Model/Environment.php +++ b/app/code/core/Mage/Rule/Model/Environment.php @@ -20,12 +20,12 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Rule_Model_Environment extends Varien_Object +class Mage_Rule_Model_Environment extends Varien_Object { /** * Collect application environment for rules filtering @@ -38,7 +38,7 @@ public function collect() $this->setNow(time()); Mage::dispatchEvent('rule_environment_collect', array('env'=>$this)); - + return $this; } } diff --git a/app/code/core/Mage/Rule/Model/Mysql4/Rule.php b/app/code/core/Mage/Rule/Model/Mysql4/Rule.php index 3ad530ca65..dadaf8e2c2 100644 --- a/app/code/core/Mage/Rule/Model/Mysql4/Rule.php +++ b/app/code/core/Mage/Rule/Model/Mysql4/Rule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,14 +28,10 @@ /** * Quote rule mysql4 resource model * - * @category Mage - * @package Mage_Rule + * @category Mage + * @package Mage_Rule * @author Magento Core Team */ -class Mage_Rule_Model_Mysql4_Rule extends Mage_Core_Model_Mysql4_Abstract +class Mage_Rule_Model_Mysql4_Rule extends Mage_Rule_Model_Resource_Rule { - protected function _construct() - { - $this->_init('rule/rule', 'rule_id'); - } } diff --git a/app/code/core/Mage/Rule/Model/Mysql4/Rule/Collection.php b/app/code/core/Mage/Rule/Model/Mysql4/Rule/Collection.php index f3a9e56e64..7345e30ac0 100644 --- a/app/code/core/Mage/Rule/Model/Mysql4/Rule/Collection.php +++ b/app/code/core/Mage/Rule/Model/Mysql4/Rule/Collection.php @@ -20,130 +20,18 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Abstract rules collection to be extended * - * @category Mage - * @package Mage_Rule + * @category Mage + * @package Mage_Rule * @author Magento Core Team */ -class Mage_Rule_Model_Mysql4_Rule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Rule_Model_Mysql4_Rule_Collection extends Mage_Rule_Model_Resource_Rule_Collection { - /** - * Quote rule environment - * - * @var Mage_Rule_Model_Environment - */ - protected $_env; - - protected function _construct() - { - $this->_init('rule/rule'); - } - - /** - * Initialize resource collection variables - * - * Example: - */ - /* - public function __construct() - { - parent::__construct(Mage::getSingleton('core/resource')->getConnection('sales_read')); - - $ruleTable = Mage::getSingleton('core/resource')->getTableName('sales/quote_rule'); - $this->_select->from($ruleTable)->order('sort_order'); - - $this->setItemObjectClass(Mage::getConfig()->getModelClassName('sales/quote_rule')); - } - */ - - /** - * Set environment for all rules in collection - * - * @param Mage_Rule_Model_Environment $env - * @return Mage_Rule_Model_Mysql4_Rule_Collection - */ - public function setEnv(Mage_Rule_Model_Environment $env=null) - { - $this->_env = $env; - return $this; - } - - /** - * Retrieve environment for the rules in collection - * - * @return Mage_Rule_Model_Mysql4_Rule_Collection - */ - public function getEnv() - { - if (!$this->_env) { - $this->_env = Mage::getModel('core/rule_environment'); - $this->_env->collect(); - } - return $this->_env; - } - - /** - * Overload default addItem method to set environment for the rules - * - * @param Mage_Rule_Model_Abstract $rule - * @return Mage_Rule_Model_Mysql4_Rule_Collection - */ - public function addItem(Varien_Object $rule) - { - $rule->setEnv($this->getEnv())->setIsCollectionValidated(true); - parent::addItem($rule); - return $this; - } - - /** - * Set filter for the collection based on the environment - * - * @return Mage_Rule_Model_Mysql4_Rule_Collection - */ - public function setActiveFilter() - { - $e = $this->getEnv()->getData(); - - $this->_select->where("is_active=1"); - - if (!empty($e['now'])) { - if (!is_numeric($e['now'])) { - $e['now'] = strtotime($e['now']); - } - $now = date("Y-m-d H:i:s", $e['now']); - } else { - $now = date("Y-m-d H:i:s"); - } - $this->_select->where("start_at<='$now' and expire_at>='$now'"); - - return $this; - } - - /** - * Process the quote with all the rules in collection - * - * @return Mage_Rule_Model_Mysql4_Rule_Collection - */ - public function process() - { - $rules = $this->getItems(); - foreach ($rules as $rule) { - $rule->process(); - if ($rule->getStopProcessingRules()) { - break; - } - } - return $this; - } - - protected function _afterLoad() - { - $this->walk('afterLoad'); - } } diff --git a/app/code/core/Mage/Rule/Model/Renderer/Actions.php b/app/code/core/Mage/Rule/Model/Renderer/Actions.php index cd5338404e..33d429a917 100644 --- a/app/code/core/Mage/Rule/Model/Renderer/Actions.php +++ b/app/code/core/Mage/Rule/Model/Renderer/Actions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Renderer/Conditions.php b/app/code/core/Mage/Rule/Model/Renderer/Conditions.php index fedb4eede9..6eea670f1f 100644 --- a/app/code/core/Mage/Rule/Model/Renderer/Conditions.php +++ b/app/code/core/Mage/Rule/Model/Renderer/Conditions.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Rule/Model/Resource/Rule.php b/app/code/core/Mage/Rule/Model/Resource/Rule.php new file mode 100755 index 0000000000..65334ce89a --- /dev/null +++ b/app/code/core/Mage/Rule/Model/Resource/Rule.php @@ -0,0 +1,45 @@ + + */ +class Mage_Rule_Model_Resource_Rule extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('rule/rule', 'rule_id'); + } +} diff --git a/app/code/core/Mage/Rule/Model/Resource/Rule/Collection.php b/app/code/core/Mage/Rule/Model/Resource/Rule/Collection.php new file mode 100755 index 0000000000..f1560b694e --- /dev/null +++ b/app/code/core/Mage/Rule/Model/Resource/Rule/Collection.php @@ -0,0 +1,143 @@ + + */ +class Mage_Rule_Model_Resource_Rule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Quote rule environment + * + * @var Mage_Rule_Model_Environment + */ + protected $_env; + + /** + * Define resource model and model + * + */ + protected function _construct() + { + $this->_init('rule/rule'); + } + + /** + * Set environment for all rules in collection + * + * @param Mage_Rule_Model_Environment $env + * @return Mage_Rule_Model_Resource_Rule_Collection + */ + public function setEnv(Mage_Rule_Model_Environment $env = null) + { + $this->_env = $env; + return $this; + } + + /** + * Retrieve environment for the rules in collection + * + * @return Mage_Rule_Model_Resource_Rule_Collection + */ + public function getEnv() + { + if (!$this->_env) { + $this->_env = Mage::getModel('core/rule_environment'); + $this->_env->collect(); + } + return $this->_env; + } + + /** + * Overload default addItem method to set environment for the rules + * + * @param Mage_Rule_Model_Abstract $rule + * @return Mage_Rule_Model_Resource_Rule_Collection + */ + public function addItem(Varien_Object $rule) + { + $rule->setEnv($this->getEnv())->setIsCollectionValidated(true); + parent::addItem($rule); + return $this; + } + + /** + * Set filter for the collection based on the environment + * + * @return Mage_Rule_Model_Resource_Rule_Collection + */ + public function setActiveFilter() + { + $e = $this->getEnv()->getData(); + + $this->addFieldToFilter('is_active', 1); + + if (!empty($e['now'])) { + if (!is_numeric($e['now'])) { + $e['now'] = strtotime($e['now']); + } + $now = date("Y-m-d H:i:s", $e['now']); + } else { + $now = date("Y-m-d H:i:s"); + } + + $this->addFieldToFilter('start_at', array('to'=>$now)); + $this->addFieldToFilter('expire_at', array('from'=>$now)); + + return $this; + } + + /** + * Process the quote with all the rules in collection + * + * @return Mage_Rule_Model_Resource_Rule_Collection + */ + public function process() + { + $rules = $this->getItems(); + foreach ($rules as $rule) { + $rule->process(); + if ($rule->getStopProcessingRules()) { + break; + } + } + return $this; + } + + /** + * Walk across collection after load + * + */ + protected function _afterLoad() + { + $this->walk('afterLoad'); + } +} diff --git a/app/code/core/Mage/Rule/Model/Rule.php b/app/code/core/Mage/Rule/Model/Rule.php index 196adb95ea..c3671a3040 100644 --- a/app/code/core/Mage/Rule/Model/Rule.php +++ b/app/code/core/Mage/Rule/Model/Rule.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -90,12 +90,19 @@ public function getConditions() return $this->_conditions; } + /** + * @return Mage_Rule_Model_Action_Collection + */ public function getActionsInstance() { return Mage::getModel('rule/action_collection'); } - public function _resetActions($actions=null) + /** + * @param Mage_Rule_Model_Action_Collection $actions + * @return Mage_Rule_Model_Rule + */ + public function _resetActions($actions = null) { if (is_null($actions)) { $actions = $this->getActionsInstance(); @@ -354,7 +361,7 @@ public function setIsReadonly($value) */ public function validateData(Varien_Object $object) { - if($object->getData('from_date') && $object->getData('to_date')){ + if ($object->getData('from_date') && $object->getData('to_date')) { $dateStart = new Zend_Date($object->getData('from_date'), Varien_Date::DATE_INTERNAL_FORMAT); $dateEnd = new Zend_Date($object->getData('to_date'), Varien_Date::DATE_INTERNAL_FORMAT); diff --git a/app/code/core/Mage/Rule/etc/config.xml b/app/code/core/Mage/Rule/etc/config.xml index 50a4cf90dc..8676009cf1 100644 --- a/app/code/core/Mage/Rule/etc/config.xml +++ b/app/code/core/Mage/Rule/etc/config.xml @@ -21,30 +21,31 @@ * * @category Mage * @package Mage_Rule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 Mage_Rule_Model - rule_mysql4 + rule_resource - - Mage_Rule_Model_Mysql4 - + + Mage_Rule_Model_Resource + rule_mysql4 + - - Mage_Rule_Block - + + Mage_Rule_Block + @@ -58,7 +59,6 @@
      - diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement.php index abfbed0a5e..3547b264d0 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/Grid.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/Grid.php index bbdf909875..ec9db4ee53 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/Grid.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -100,13 +100,15 @@ protected function _prepareColumns() $this->addColumn('customer_firstname', array( 'header' => Mage::helper('sales')->__('Customer Name'), 'index' => 'customer_firstname', - 'type' => 'text' + 'type' => 'text', + 'escape' => true )); $this->addColumn('customer_lastname', array( 'header' => Mage::helper('sales')->__('Customer Last Name'), 'index' => 'customer_lastname', - 'type' => 'text' + 'type' => 'text', + 'escape' => true )); $this->addColumn('method_code', array( diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php index b75759d4c1..f767e67f51 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Form.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Form.php index d4769a7fcc..d62bedd231 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Form.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Info.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Info.php index c0a45fb8b9..97a0adeb1d 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Info.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Orders.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Orders.php index 4e4242f1a3..5ae0e99a3b 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Orders.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tab/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tabs.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tabs.php index 5ff26c1ee6..e85b2d8670 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tabs.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php index ee345d39ce..57e80d86e6 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Recurring/Profile.php b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Recurring/Profile.php index 130baf7861..3baa754df9 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Recurring/Profile.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Recurring/Profile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile.php index 4233672c82..0c3d7ff7ca 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Edit/Form.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Edit/Form.php index 0ee7aa7306..b43c95fcb4 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Edit/Form.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Grid.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Grid.php index 67f0d0d786..5804b69a18 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Grid.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View.php index fc7f2d510b..1f511bcbbf 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Getawayinfo.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Getawayinfo.php index dbfabaf4c3..6251d4e375 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Getawayinfo.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Getawayinfo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Info.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Info.php index a686c91e4e..94c50a0e33 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Info.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Items.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Items.php index 93405c766b..55b2ff2e68 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Items.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Info.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Info.php index dbc87df038..9741f9d486 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Info.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php index 11c49f39b5..d56f5bf89e 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form.php b/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form.php index c6421f695f..1b8e600007 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form/Order.php b/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form/Order.php index 878a5359b2..8d3e91e459 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form/Order.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Report/Filter/Form/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php b/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php index 91ef3ea528..f5a77406c0 100644 --- a/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php +++ b/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Billing/Agreements.php b/app/code/core/Mage/Sales/Block/Billing/Agreements.php index a985628d38..07b27b35eb 100644 --- a/app/code/core/Mage/Sales/Block/Billing/Agreements.php +++ b/app/code/core/Mage/Sales/Block/Billing/Agreements.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Items/Abstract.php b/app/code/core/Mage/Sales/Block/Items/Abstract.php index 1e02223e0b..cfa69e03eb 100644 --- a/app/code/core/Mage/Sales/Block/Items/Abstract.php +++ b/app/code/core/Mage/Sales/Block/Items/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Comments.php b/app/code/core/Mage/Sales/Block/Order/Comments.php index 5c68b3fd20..0b702f2665 100644 --- a/app/code/core/Mage/Sales/Block/Order/Comments.php +++ b/app/code/core/Mage/Sales/Block/Order/Comments.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Sales_Block_Order_Comments extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php index ad933e9f29..69f424587c 100644 --- a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Creditmemo/Items.php b/app/code/core/Mage/Sales/Block/Order/Creditmemo/Items.php index f3065ac3e3..3ae64dafd5 100644 --- a/app/code/core/Mage/Sales/Block/Order/Creditmemo/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Creditmemo/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Creditmemo/Totals.php b/app/code/core/Mage/Sales/Block/Order/Creditmemo/Totals.php index 73d6135873..63786743d2 100644 --- a/app/code/core/Mage/Sales/Block/Order/Creditmemo/Totals.php +++ b/app/code/core/Mage/Sales/Block/Order/Creditmemo/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Sales_Block_Order_Creditmemo_Totals extends Mage_Sales_Block_Order_Totals diff --git a/app/code/core/Mage/Sales/Block/Order/Details.php b/app/code/core/Mage/Sales/Block/Order/Details.php index 669fede4da..8a0c227175 100644 --- a/app/code/core/Mage/Sales/Block/Order/Details.php +++ b/app/code/core/Mage/Sales/Block/Order/Details.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Creditmemo/Items.php b/app/code/core/Mage/Sales/Block/Order/Email/Creditmemo/Items.php index d78f5752c2..b73c865c6a 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Creditmemo/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Creditmemo/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Invoice/Items.php b/app/code/core/Mage/Sales/Block/Order/Email/Invoice/Items.php index 6d697c2397..06dce45691 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Invoice/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Invoice/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Items.php b/app/code/core/Mage/Sales/Block/Order/Email/Items.php index 5357f963a7..9b7e8f0b00 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Items/Default.php b/app/code/core/Mage/Sales/Block/Order/Email/Items/Default.php index 3bd692afad..5ac17d2743 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Items/Default.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Items/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Default.php b/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Default.php index 5c5ac25e49..41eaf71763 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Default.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Grouped.php b/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Grouped.php index 8635012893..f428016dc6 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Grouped.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Items/Order/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Email/Shipment/Items.php b/app/code/core/Mage/Sales/Block/Order/Email/Shipment/Items.php index 0fa2675512..9250f29f6b 100644 --- a/app/code/core/Mage/Sales/Block/Order/Email/Shipment/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Email/Shipment/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/History.php b/app/code/core/Mage/Sales/Block/Order/History.php index e19f716076..45da66ea55 100644 --- a/app/code/core/Mage/Sales/Block/Order/History.php +++ b/app/code/core/Mage/Sales/Block/Order/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Info.php b/app/code/core/Mage/Sales/Block/Order/Info.php index a93c518f2e..da07c5eb8f 100644 --- a/app/code/core/Mage/Sales/Block/Order/Info.php +++ b/app/code/core/Mage/Sales/Block/Order/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Invoice.php b/app/code/core/Mage/Sales/Block/Order/Invoice.php index de5e03d832..5055504a5c 100644 --- a/app/code/core/Mage/Sales/Block/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Block/Order/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Invoice/Items.php b/app/code/core/Mage/Sales/Block/Order/Invoice/Items.php index 006e5926b4..9788ff9732 100644 --- a/app/code/core/Mage/Sales/Block/Order/Invoice/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Invoice/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Invoice/Totals.php b/app/code/core/Mage/Sales/Block/Order/Invoice/Totals.php index bc196bdc7c..9ce722c101 100644 --- a/app/code/core/Mage/Sales/Block/Order/Invoice/Totals.php +++ b/app/code/core/Mage/Sales/Block/Order/Invoice/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Sales_Block_Order_Invoice_Totals extends Mage_Sales_Block_Order_Totals diff --git a/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php b/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php index c7ca136b3d..e9306fe472 100644 --- a/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php +++ b/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Grouped.php b/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Grouped.php index a2716e91e7..479141996c 100644 --- a/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Grouped.php +++ b/app/code/core/Mage/Sales/Block/Order/Item/Renderer/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Items.php b/app/code/core/Mage/Sales/Block/Order/Items.php index c4060b3f8b..688e756e33 100644 --- a/app/code/core/Mage/Sales/Block/Order/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Print.php b/app/code/core/Mage/Sales/Block/Order/Print.php index 1a687963ab..6def8989a2 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print.php +++ b/app/code/core/Mage/Sales/Block/Order/Print.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php b/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php index 27249cbd2c..70c0da09be 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php b/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php index df7209d017..9055e7acaf 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php b/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php index 2b6340793d..4af55735d7 100644 --- a/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php +++ b/app/code/core/Mage/Sales/Block/Order/Print/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Recent.php b/app/code/core/Mage/Sales/Block/Order/Recent.php index e6377bd7e2..651e9d3938 100644 --- a/app/code/core/Mage/Sales/Block/Order/Recent.php +++ b/app/code/core/Mage/Sales/Block/Order/Recent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Shipment.php b/app/code/core/Mage/Sales/Block/Order/Shipment.php index 87a36347cd..e7c253f4f2 100644 --- a/app/code/core/Mage/Sales/Block/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Block/Order/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Shipment/Items.php b/app/code/core/Mage/Sales/Block/Order/Shipment/Items.php index 0c0d5f136e..207c107b62 100644 --- a/app/code/core/Mage/Sales/Block/Order/Shipment/Items.php +++ b/app/code/core/Mage/Sales/Block/Order/Shipment/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Tax.php b/app/code/core/Mage/Sales/Block/Order/Tax.php index e3998c0a3b..b35ec8bc4b 100644 --- a/app/code/core/Mage/Sales/Block/Order/Tax.php +++ b/app/code/core/Mage/Sales/Block/Order/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Order/Totals.php b/app/code/core/Mage/Sales/Block/Order/Totals.php index 6556cefb5a..9517876a95 100644 --- a/app/code/core/Mage/Sales/Block/Order/Totals.php +++ b/app/code/core/Mage/Sales/Block/Order/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Sales_Block_Order_Totals extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/Sales/Block/Order/View.php b/app/code/core/Mage/Sales/Block/Order/View.php index cff4a2a7fe..122d1cf0ad 100644 --- a/app/code/core/Mage/Sales/Block/Order/View.php +++ b/app/code/core/Mage/Sales/Block/Order/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Payment/Form/Billing/Agreement.php b/app/code/core/Mage/Sales/Block/Payment/Form/Billing/Agreement.php index ea4081669e..d31c3c9e7c 100644 --- a/app/code/core/Mage/Sales/Block/Payment/Form/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Payment/Form/Billing/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Payment/Info/Billing/Agreement.php b/app/code/core/Mage/Sales/Block/Payment/Info/Billing/Agreement.php index 5a5332b174..7c352ccfbf 100644 --- a/app/code/core/Mage/Sales/Block/Payment/Info/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Payment/Info/Billing/Agreement.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Recurring/Profile/View.php b/app/code/core/Mage/Sales/Block/Recurring/Profile/View.php index 85363f975a..5c3da9007a 100644 --- a/app/code/core/Mage/Sales/Block/Recurring/Profile/View.php +++ b/app/code/core/Mage/Sales/Block/Recurring/Profile/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Block/Recurring/Profiles.php b/app/code/core/Mage/Sales/Block/Recurring/Profiles.php index 8cf67b2882..5977fc60aa 100644 --- a/app/code/core/Mage/Sales/Block/Recurring/Profiles.php +++ b/app/code/core/Mage/Sales/Block/Recurring/Profiles.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -41,7 +41,7 @@ class Mage_Sales_Block_Recurring_Profiles extends Mage_Core_Block_Template */ public function prepareProfilesGrid() { - $this->_prepareProfiles(array('profile_id', 'reference_id', 'state', 'created_at', 'updated_at', 'method_code')); + $this->_prepareProfiles(array('reference_id', 'state', 'created_at', 'updated_at', 'method_code')); $pager = $this->getLayout()->createBlock('page/html_pager') ->setCollection($this->_profiles)->setIsOutputRequired(false); diff --git a/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php b/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php index 34b4bb4d42..7ee48867a8 100644 --- a/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php +++ b/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Exception.php b/app/code/core/Mage/Sales/Exception.php index 7ee5505a15..f59927a937 100644 --- a/app/code/core/Mage/Sales/Exception.php +++ b/app/code/core/Mage/Sales/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Helper/Data.php b/app/code/core/Mage/Sales/Helper/Data.php index 2157cd680e..4008f84422 100644 --- a/app/code/core/Mage/Sales/Helper/Data.php +++ b/app/code/core/Mage/Sales/Helper/Data.php @@ -20,19 +20,31 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Sales module base helper * + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ class Mage_Sales_Helper_Data extends Mage_Core_Helper_Data { + /** + * Maximum available number + */ const MAXIMUM_AVAILABLE_NUMBER = 99999999; + /** + * Check quote amount + * + * @param Mage_Sales_Model_Quote $quote + * @param decimal $amount + * @return Mage_Sales_Helper_Data + */ public function checkQuoteAmount(Mage_Sales_Model_Quote $quote, $amount) { if (!$quote->getHasError() && ($amount>=self::MAXIMUM_AVAILABLE_NUMBER)) { @@ -44,49 +56,113 @@ public function checkQuoteAmount(Mage_Sales_Model_Quote $quote, $amount) return $this; } + /** + * Check allow to send new order confirmation email + * + * @param mixed $store + * @return bool + */ public function canSendNewOrderConfirmationEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, $store); } + /** + * Check allow to send new order email + * + * @param mixed $store + * @return bool + */ public function canSendNewOrderEmail($store = null) { return $this->canSendNewOrderConfirmationEmail($store); } + /** + * Check allow to send order comment email + * + * @param mixed $store + * @return bool + */ public function canSendOrderCommentEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order::XML_PATH_UPDATE_EMAIL_ENABLED, $store); } + /** + * Check allow to send new shipment email + * + * @param mixed $store + * @return bool + */ public function canSendNewShipmentEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Shipment::XML_PATH_EMAIL_ENABLED, $store); } + /** + * Check allow to send shipment comment email + * + * @param mixed $store + * @return bool + */ public function canSendShipmentCommentEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Shipment::XML_PATH_UPDATE_EMAIL_ENABLED, $store); } + /** + * Check allow to send new invoice email + * + * @param mixed $store + * @return bool + */ public function canSendNewInvoiceEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Invoice::XML_PATH_EMAIL_ENABLED, $store); } + /** + * Check allow to send invoice comment email + * + * @param mixed $store + * @return bool + */ public function canSendInvoiceCommentEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Invoice::XML_PATH_UPDATE_EMAIL_ENABLED, $store); } + /** + * Check allow to send new creditmemo email + * + * @param mixed $store + * @return bool + */ public function canSendNewCreditmemoEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Creditmemo::XML_PATH_EMAIL_ENABLED, $store); } + /** + * Check allow to send creditmemo comment email + * + * @param mixed $store + * @return bool + */ public function canSendCreditmemoCommentEmail($store = null) { return Mage::getStoreConfigFlag(Mage_Sales_Model_Order_Creditmemo::XML_PATH_UPDATE_EMAIL_ENABLED, $store); } + /** + * Get old field map + * + * @param string $entityId + * @return array + */ + public function getOldFieldMap($entityId) + { + return (array)Mage::getConfig()->getNode('global/sales/old_fields_map/' . $entityId); + } } diff --git a/app/code/core/Mage/Sales/Helper/Reorder.php b/app/code/core/Mage/Sales/Helper/Reorder.php index 195c9c1ad3..e6eea9542b 100644 --- a/app/code/core/Mage/Sales/Helper/Reorder.php +++ b/app/code/core/Mage/Sales/Helper/Reorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Abstract.php b/app/code/core/Mage/Sales/Model/Abstract.php index 1d862c9f06..c98cda0f12 100644 --- a/app/code/core/Mage/Sales/Model/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -61,7 +61,7 @@ protected function _afterSave() public function getCreatedAtDate() { return Mage::app()->getLocale()->date( - $this->_getResource()->mktime(($this->getCreatedAt())), + Varien_Date::toTimestamp($this->getCreatedAt()), null, null, true @@ -77,7 +77,7 @@ public function getCreatedAtStoreDate() { return Mage::app()->getLocale()->storeDate( $this->getStore(), - $this->_getResource()->mktime(($this->getCreatedAt())), + Varien_Date::toTimestamp($this->getCreatedAt()), true ); } diff --git a/app/code/core/Mage/Sales/Model/Api/Resource.php b/app/code/core/Mage/Sales/Model/Api/Resource.php index 81aaa6f5a1..d04b5b9cfa 100644 --- a/app/code/core/Mage/Sales/Model/Api/Resource.php +++ b/app/code/core/Mage/Sales/Model/Api/Resource.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Billing/Agreement.php b/app/code/core/Mage/Sales/Model/Billing/Agreement.php index 49dc751e46..0801c53eb2 100644 --- a/app/code/core/Mage/Sales/Model/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Model/Billing/Agreement.php @@ -20,14 +20,35 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Billing Agreement abstract model * - * @author Magento Core Team + * @method Mage_Sales_Model_Resource_Billing_Agreement _getResource() + * @method Mage_Sales_Model_Resource_Billing_Agreement getResource() + * @method int getCustomerId() + * @method Mage_Sales_Model_Billing_Agreement setCustomerId(int $value) + * @method string getMethodCode() + * @method Mage_Sales_Model_Billing_Agreement setMethodCode(string $value) + * @method string getReferenceId() + * @method Mage_Sales_Model_Billing_Agreement setReferenceId(string $value) + * @method string getStatus() + * @method Mage_Sales_Model_Billing_Agreement setStatus(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Billing_Agreement setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Billing_Agreement setUpdatedAt(string $value) + * @method int getStoreId() + * @method Mage_Sales_Model_Billing_Agreement setStoreId(int $value) + * @method string getAgreementLabel() + * @method Mage_Sales_Model_Billing_Agreement setAgreementLabel(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Billing_Agreement extends Mage_Payment_Model_Billing_AgreementAbstract { @@ -58,7 +79,7 @@ protected function _construct() protected function _beforeSave() { $date = Mage::getModel('core/date')->gmtDate(); - if ($this->isObjectNew()) { + if ($this->isObjectNew() && !$this->getCreatedAt()) { $this->setCreatedAt($date); } else { $this->setUpdatedAt($date); diff --git a/app/code/core/Mage/Sales/Model/Config.php b/app/code/core/Mage/Sales/Model/Config.php index 6cdd4ebb2e..74c06b1cfd 100644 --- a/app/code/core/Mage/Sales/Model/Config.php +++ b/app/code/core/Mage/Sales/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Convert/Order.php b/app/code/core/Mage/Sales/Model/Convert/Order.php index c779b6d435..4e20955602 100644 --- a/app/code/core/Mage/Sales/Model/Convert/Order.php +++ b/app/code/core/Mage/Sales/Model/Convert/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Convert/Quote.php b/app/code/core/Mage/Sales/Model/Convert/Quote.php index df5c48800f..e44df96448 100644 --- a/app/code/core/Mage/Sales/Model/Convert/Quote.php +++ b/app/code/core/Mage/Sales/Model/Convert/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Email/Template.php b/app/code/core/Mage/Sales/Model/Email/Template.php index d6c7a2adc1..b870d36059 100644 --- a/app/code/core/Mage/Sales/Model/Email/Template.php +++ b/app/code/core/Mage/Sales/Model/Email/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order.php b/app/code/core/Mage/Sales/Model/Entity/Order.php index 473801d126..c0bf2d909c 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Address.php b/app/code/core/Mage/Sales/Model/Entity/Order/Address.php index 3afc66eff4..6a3092711d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Address.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Address/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Address/Collection.php index 51fba37664..f63e3ae024 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Address/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Address/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Billing.php b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Billing.php index 06e78104dc..2d07c0c72b 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Billing.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Billing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Child.php index e08c11d32f..549c4bf9e8 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Child.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Parent.php index 9e1bd0cce5..ca6a846992 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Parent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Shipping.php b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Shipping.php index cfb30c778e..6919fe0ff3 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Attribute/Backend/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Collection.php index 8a904d47ab..168d235f0d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo.php index 98e8b400d2..b7a0ef1682 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Child.php index eac63093e2..4e8a405e70 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Child.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Parent.php index c1a719bc7b..5820fbcae9 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Attribute/Backend/Parent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Collection.php index 91a1923697..a3a908979f 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment.php index 57a9b966e9..cab166bdbc 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment/Collection.php index 20e900206d..b972890bc5 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Comment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item.php index f3a5fea111..afd7f9ec57 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item/Collection.php index 997a10c529..b8360429e5 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Creditmemo/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice.php index 13b4164e83..a5eac6c5ba 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Child.php index d90023eaa9..386c2df43d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Child.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Item.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Item.php index ccd06d650d..b2e15306aa 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Order.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Order.php index 41921539b5..8017c58250 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Order.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Parent.php index a14e0a70b3..8a1c1a4707 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Attribute/Backend/Parent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Collection.php index 93c9088f48..7dab1b3bba 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment.php index 97087a375e..3c47768525 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment/Collection.php index bbdabb5464..28a171af1b 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Comment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item.php index a218843105..d76114bb80 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item/Collection.php index cf9e9b4983..dbb4464e5d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Invoice/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Item.php b/app/code/core/Mage/Sales/Model/Entity/Order/Item.php index 6bbb24550e..75ea6c55d5 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Item/Collection.php index 3d7c955725..0d5b39e2a9 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Payment.php b/app/code/core/Mage/Sales/Model/Entity/Order/Payment.php index f514b95c3c..cd515614d2 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Payment/Collection.php index 6d502808ad..3213cf757d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Payment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Payment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment.php index 81ff1d2c06..6398bd21e1 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Child.php index b9b160f023..5c17d5e20c 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Child.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Parent.php index 8b2c30963d..43042077fc 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Attribute/Backend/Parent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Collection.php index c134ad5c38..1b73827eb1 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment.php index 65822dfbc9..09dd76a790 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment/Collection.php index ef4545c6b0..d31aef060c 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Comment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item.php index b502878b99..c11ab0b060 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item/Collection.php index cb36541015..d1fba08b77 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track.php index 266aeb4960..3d574cf559 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track/Collection.php index b0fd2781df..254381c8d4 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Shipment/Track/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Status/History.php b/app/code/core/Mage/Sales/Model/Entity/Order/Status/History.php index 99be971ec3..28988d95e1 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Status/History.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Status/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Order/Status/History/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Order/Status/History/Collection.php index 31c03482c0..f063eebf40 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Order/Status/History/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Order/Status/History/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote.php b/app/code/core/Mage/Sales/Model/Entity/Quote.php index 4d27196852..e6d71a665a 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address.php index ff7cf04bb5..6ccb03ac2e 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend.php index cb4d5c4072..c7bee1d6dd 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Child.php index bb1ff1b7c6..d5ec90fb86 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Child.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Parent.php index 0ccfb111a8..a8c040d622 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Parent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Region.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Region.php index e637e41f5b..218c56cb8b 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Region.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Backend/Region.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend.php index dcaf28017e..8e29bef39f 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Custbalance.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Custbalance.php index aa3eeb410f..57f51cb485 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Custbalance.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Custbalance.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Discount.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Discount.php index 49d2c6102f..6b237bcc9a 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Discount.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Grand.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Grand.php index 173f439a14..cce73141e6 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Grand.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Grand.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Shipping.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Shipping.php index c9c4f18d5a..70dff763f0 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Subtotal.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Subtotal.php index 963cc00ad9..192ef7c7f6 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Tax.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Tax.php index c2935a5ab0..d060e87c56 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Tax.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Collection.php index 74817259d2..757666e97b 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item.php index 75ff998f4c..a317a48c2f 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item/Collection.php index b19ec27ae0..1c11778542 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate.php index 106a273fd6..fc7dc5dec8 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate/Collection.php index 4a1841fb3b..8d41bbd82d 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Address/Rate/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Collection.php index 693eebe5c3..fef6aded77 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Item.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Item.php index 1f3709f7e8..21139a9e1b 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Item/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Item/Collection.php index 01c39d2a59..c8590a3a39 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Payment.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Payment.php index 7db2fb92ad..4d6cd959dc 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Payment.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Quote/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Quote/Payment/Collection.php index 7d223d2682..1e7672abfd 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Quote/Payment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Quote/Payment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Sale/Collection.php b/app/code/core/Mage/Sales/Model/Entity/Sale/Collection.php index 92bac622d1..eb8e794fbe 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Sale/Collection.php +++ b/app/code/core/Mage/Sales/Model/Entity/Sale/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Entity/Setup.php b/app/code/core/Mage/Sales/Model/Entity/Setup.php index 192168cec3..7f27347a06 100644 --- a/app/code/core/Mage/Sales/Model/Entity/Setup.php +++ b/app/code/core/Mage/Sales/Model/Entity/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ class Mage_Sales_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup public function getDefaultEntities() { return array( - 'quote'=>array( + 'quote' => array( 'entity_model' => 'sales/quote', 'table' => 'sales/quote', 'attributes' => array( diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Abstract.php index 5371b3baf3..3b01bf77fe 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Abstract.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales mysql4 abstract resource model * @@ -31,21 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -abstract class Mage_Sales_Model_Mysql4_Abstract extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Abstract extends Mage_Sales_Model_Resource_Abstract { - /** - * Prepare data for save - * - * @param Mage_Core_Model_Abstract $object - * @return array - */ - protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getId() || $object->isObjectNew()) { - $object->setCreatedAt(now()); - } - $object->setUpdatedAt(now()); - $data = parent::_prepareDataForSave($object); - return $data; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement.php b/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement.php index dbe7703e21..7c585ba98e 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement.php @@ -20,40 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Billing agreement resource model * - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Billing_Agreement extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Billing_Agreement extends Mage_Sales_Model_Resource_Billing_Agreement { - /** - * Resource initialization - */ - protected function _construct() - { - $this->_init('sales/billing_agreement', 'agreement_id'); - } - - /** - * Add order relation to billing agreement - * - * @param int $agreementId - * @param int $orderId - * @return Mage_Sales_Model_Mysql4_Billing_Agreement - */ - public function addOrderRelation($agreementId, $orderId) - { - $this->_getWriteAdapter()->insert( - $this->getTable('sales/billing_agreement_order'), array( - 'agreement_id' => $agreementId, - 'order_id' => $orderId - ) - ); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement/Collection.php index 66e190294e..d7d2f06a16 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Billing/Agreement/Collection.php @@ -20,54 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Billing agreements resource collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Billing_Agreement_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Billing_Agreement_Collection + extends Mage_Sales_Model_Resource_Billing_Agreement_Collection { - /** - * Collection initialization - * - */ - protected function _construct() - { - $this->_init('sales/billing_agreement'); - } - - /** - * Add cutomer details(email, firstname, lastname) to select - * - * @return Mage_Sales_Model_Mysql4_Billing_Agreement_Collection - */ - public function addCustomerDetails() - { - $select = $this->getSelect()->joinInner( - array('ce' => $this->getTable('customer/entity')), - 'ce.entity_id = main_table.customer_id', - array('customer_email' => 'email') - ); - - $customer = Mage::getResourceSingleton('customer/customer'); - - $attr = $customer->getAttribute('firstname'); - $select->joinLeft(array('firstname' => $attr->getBackend()->getTable()), - 'firstname.entity_id = main_table.customer_id' - . ' AND firstname.entity_type_id = ' . $customer->getTypeId() - . ' AND firstname.attribute_id = ' . $attr->getAttributeId(), - array('customer_firstname' => 'value')); - $attr = $customer->getAttribute('lastname'); - $select->joinLeft(array('lastname' => $attr->getBackend()->getTable()), - 'lastname.entity_id = main_table.customer_id' - . ' AND lastname.entity_type_id = ' . $customer->getTypeId() - . ' AND lastname.attribute_id = ' . $attr->getAttributeId(), - array('customer_lastname' => 'value')); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Collection/Abstract.php index 8f11b1a116..fe24364a80 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Collection/Abstract.php @@ -20,133 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales abstract collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -abstract class Mage_Sales_Model_Mysql4_Collection_Abstract extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Collection_Abstract extends Mage_Sales_Model_Resource_Collection_Abstract { - /** - * Check if $attribute is Mage_Eav_Model_Entity_Attribute and convert to string field name - * - * @param string|Mage_Eav_Model_Entity_Attribute $attribute - * @return string - */ - protected function _attributeToField($attribute) - { - $field = false; - if (is_string($attribute)) { - $field = $attribute; - } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute) { - $field = $attribute->getAttributeCode(); - } - if (!$field) { - Mage::throwException(Mage::helper('sales')->__('Cannot determine the field name.')); - } - return $field; - } - - /** - * Add attribute to select result set. - * Backward compatibility with EAV collection - * - * @param string $attribute - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - public function addAttributeToSelect($attribute) - { - $this->addFieldToSelect($this->_attributeToField($attribute)); - return $this; - } - - /** - * Specify collection select filter by attribute value - * Backward compatibility with EAV collection - * - * @param string|Mage_Eav_Model_Entity_Attribute $attribute - * @param array|integer|string|null $condition - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - public function addAttributeToFilter($attribute, $condition = null) - { - $this->addFieldToFilter($this->_attributeToField($attribute), $condition); - return $this; - } - - /** - * Specify collection select filter by attribute value - * Backward compatibility with EAV collection - * - * @param string $attribute - * @param string $dir - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - public function addAttributeToSort($attribute, $dir='asc') - { - $this->addOrder($this->_attributeToField($attribute), $dir); - return $this; - } - - /** - * Set collection page start and records to show - * Backward compatibility with EAV collection - * - * @param integer $pageNum - * @param integer $pageSize - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function setPage($pageNum, $pageSize) - { - $this->setCurPage($pageNum) - ->setPageSize($pageSize); - return $this; - } - - /** - * Create all ids retrieving select with limitation - * Backward compatibility with EAV collection - * - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - protected function _getAllIdsSelect($limit=null, $offset=null) - { - $idsSelect = clone $this->getSelect(); - $idsSelect->reset(Zend_Db_Select::ORDER); - $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $idsSelect->reset(Zend_Db_Select::COLUMNS); - $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table'); - $idsSelect->limit($limit, $offset); - return $idsSelect; - } - - /** - * Retrive all ids for collection - * Backward compatibility with EAV collection - * - * @param int $limit - * @param int $offset - * @return array - */ - public function getAllIds($limit=null, $offset=null) - { - return $this->getConnection()->fetchCol( - $this->_getAllIdsSelect($limit, $offset), - $this->_bindParams - ); - } - - - /** - * Backward compatibility with EAV collection - * @todo implement join functionality if necessary - */ - public function joinAttribute($alias, $attribute, $bind, $filter=null, $joinType='inner', $storeId=null) - { - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Order.php index cc593a1393..dfc0c78908 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order.php @@ -20,87 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order extends Mage_Sales_Model_Resource_Order { - protected $_eventPrefix = 'sales_order_resource'; - protected $_eventObject = 'resource'; - protected $_grid = true; - protected $_useIncrementId = true; - protected $_entityCodeForIncrementId = 'order'; - - protected function _construct() - { - $this->_init('sales/order', 'entity_id'); - } - - /** - * Init virtual grid records for entity - * - * @return Mage_Sales_Model_Mysql4_Order - */ - protected function _initVirtualGridColumns() - { - parent::_initVirtualGridColumns(); - $this->addVirtualGridColumn( - 'billing_name', - 'sales/order_address', - array('billing_address_id' => 'entity_id'), - 'CONCAT(IFNULL({{table}}.firstname, ""), " ", IFNULL({{table}}.lastname, ""))' - ) - ->addVirtualGridColumn( - 'shipping_name', - 'sales/order_address', - array('shipping_address_id' => 'entity_id'), - 'CONCAT(IFNULL({{table}}.firstname, ""), " ", IFNULL({{table}}.lastname, ""))' - ); - - return $this; - } - - /** - * Count existent products of order items by specified product types - * - * @param int $orderId - * @param array $productTypeIds - * @param bool $isProductTypeIn - * @return array - */ - public function aggregateProductsByTypes($orderId, $productTypeIds = array(), $isProductTypeIn = false) - { - $select = $this->getReadConnection()->select() - ->from(array('o' => $this->getTable('sales/order_item')), new Zend_Db_Expr('o.product_type, COUNT(*)')) - ->joinInner(array('p' => $this->getTable('catalog/product')), 'o.product_id=p.entity_id', array()) - ->where('o.order_id=?', $orderId) - ->group('(1)') - ; - if ($productTypeIds) { - $select->where($this->getReadConnection()->quoteInto( - sprintf('(o.product_type %s (?))', ($isProductTypeIn ? 'IN' : 'NOT IN')), - $productTypeIds - )); - } - return $this->getReadConnection()->fetchPairs($select); - } - - /** - * Retrieve order_increment_id by order_id - * - * @param int $orderId - * @return string - */ - public function getIncrementId($orderId) - { - $select = $this->getReadConnection()->select() - ->from($this->getMainTable(), array("increment_id")) - ->where('entity_id = ?', $orderId); - return $this->getReadConnection()->fetchOne($select); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php index 890e04486b..7db651ec4c 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php @@ -20,403 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales resource abstract * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -abstract class Mage_Sales_Model_Mysql4_Order_Abstract extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Order_Abstract extends Mage_Sales_Model_Resource_Order_Abstract { - /** - * Is grid available - * - * @var boolean - */ - protected $_grid = false; - - /** - * Use additional is object new check for this resource - * - * @var boolean - */ - protected $_useIsObjectNew = true; - - /** - * Flag for using of increment id - * - * @var boolean - */ - protected $_useIncrementId = false; - - /** - * Entity code for increment id (Eav entity code) - * - * @var string - */ - protected $_entityTypeForIncrementId = ''; - - /** - * Grid virtual columns - * - * @var array|null - */ - protected $_virtualGridColumns = null; - - /** - * Grid columns - * - * @var array|null - */ - protected $_gridColumns = null; - - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_resource'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'resource'; - - /** - * Add new virtual grid column - * - * @param string $alias - * @param string $table - * @param array $joinCondition - * @param string $column - * @return Mage_Sales_Model_Mysql4_Abstract - */ - public function addVirtualGridColumn($alias, $table, $joinCondition, $column) - { - $table = $this->getTable($table); - - if (!in_array($alias, $this->getGridColumns())) { - Mage::throwException( - Mage::helper('sales')->__('Please specify a valid grid column alias name that exists in grid table.') - ); - } - - $this->_virtualGridColumns[$alias] = array( - $table, $joinCondition, $column - ); - - return $this; - } - - /** - * Retrieve virtual grid columns - * - * @return array - */ - public function getVirtualGridColumns() - { - if ($this->_virtualGridColumns === null) { - $this->_initVirtualGridColumns(); - } - - return $this->_virtualGridColumns; - } - - /** - * Init virtual grid records for entity - * - * @return Mage_Sales_Model_Mysql4_Abstract - */ - protected function _initVirtualGridColumns() - { - $this->_virtualGridColumns = array(); - if ($this->_eventPrefix && $this->_eventObject) { - Mage::dispatchEvent($this->_eventPrefix . '_init_virtual_grid_columns', array( - $this->_eventObject => $this - )); - } - return $this; - } - - /** - * Update records in grid table - * - * @param array|int $ids - * @return Mage_Sales_Model_Mysql4_Abstract - */ - public function updateGridRecords($ids) - { - if ($this->_grid) { - if (!is_array($ids)) { - $ids = array($ids); - } - - if ($this->_eventPrefix && $this->_eventObject) { - $proxy = new Varien_Object(); - $proxy->setIds($ids) - ->setData($this->_eventObject, $this); - - Mage::dispatchEvent($this->_eventPrefix . '_update_grid_records', array('proxy' => $proxy)); - $ids = $proxy->getIds(); - } - - if (empty($ids)) { // If nothing to update - return $this; - } - $columnsToSelect = array(); - - $select = $this->getUpdateGridRecordsSelect($ids, $columnsToSelect); - - $this->_getWriteAdapter()->query($select->insertFromSelect($this->getGridTable(), $columnsToSelect, true)); - } - - return $this; - } - - /** - * Retrieve update grid records select - * - * @param array $ids - * @param array|null $gridColumns - * @param boolean $asJoin - * @return Varien_Db_Select - */ - public function getUpdateGridRecordsSelect($ids, &$flatColumnsToSelect, $gridColumns = null) - { - $flatColumns = array_keys( - $this->_getReadAdapter()->describeTable( - $this->getMainTable() - ) - ); - - if ($gridColumns === null) { - $gridColumns = $this->getGridColumns(); - } - - $flatColumnsToSelect = array_intersect($flatColumns, $gridColumns); - - $select = $this->_getWriteAdapter()->select() - ->from(array('main_table' => $this->getMainTable()), $flatColumnsToSelect) - ->where('main_table.' . $this->getIdFieldName() . ' IN(?)', $ids); - - $this->joinVirtualGridColumnsToSelect('main_table', $select, $flatColumnsToSelect); - - return $select; - } - - /** - * Join virtual grid columns to select - * - * @param string $mainTable - * @param Zend_Db_Select $select - * @return Mage_Sales_Model_Mysql4_Abstract - */ - public function joinVirtualGridColumnsToSelect($mainTableAlias, Zend_Db_Select $select, &$columnsToSelect) - { - foreach ($this->getVirtualGridColumns() as $alias => $expression) { - list($table, $joinCondition, $column) = $expression; - $tableAlias = '_table_' . $alias; - - $joinConditionExpr = array(); - foreach ($joinCondition as $fkField=>$pkField) { - $pkField = $this->_getWriteAdapter()->quoteIdentifier( - $tableAlias . '.' . $pkField - ); - $fkField = $this->_getWriteAdapter()->quoteIdentifier( - $mainTableAlias . '.' . $fkField - ); - $joinConditionExpr[] = $fkField . '=' . $pkField; - } - - $select->joinLeft( - array($tableAlias=> $table), - implode(' AND ', $joinConditionExpr), - array($alias => str_replace('{{table}}', $tableAlias, $column)) - ); - - $columnsToSelect[] = $alias; - } - - return $this; - } - - /** - * Retrieve list of grid columns - * - * @return array - */ - public function getGridColumns() - { - if ($this->_gridColumns === null) { - if ($this->_grid) { - $this->_gridColumns = array_keys( - $this->_getReadAdapter()->describeTable($this->getGridTable()) - ); - } else { - $this->_gridColumns = array(); - } - } - - return $this->_gridColumns; - } - - /** - * Retrieve grid table - * - * @return string - */ - public function getGridTable() - { - if ($this->_grid) { - return $this->getMainTable() . '_grid'; - } - return false; - } - - /** - * Before save object attribute - * - * @param Mage_Core_Model_Abstract $object - * @param string $attribute - * @return Mage_Sales_Model_Mysql4_Abstract - */ - protected function _beforeSaveAttribute(Mage_Core_Model_Abstract $object, $attribute) - { - if ($this->_eventObject && $this->_eventPrefix) { - Mage::dispatchEvent($this->_eventPrefix . '_save_attribute_before', array( - $this->_eventObject => $this, - 'object' => $object, - 'attribute' => $attribute - )); - } - return $this; - } - - /** - * After save object attribute - * - * @param Mage_Core_Model_Abstract $object - * @param string $attribute - * @return Mage_Sales_Model_Mysql4_Abstract - */ - protected function _afterSaveAttribute(Mage_Core_Model_Abstract $object, $attribute) - { - if ($this->_eventObject && $this->_eventPrefix) { - Mage::dispatchEvent($this->_eventPrefix . '_save_attribute_after', array( - $this->_eventObject => $this, - 'object' => $object, - 'attribute' => $attribute - )); - } - return $this; - } - - /** - * Perform actions after object save - * - * @param Mage_Core_Model_Abstract $object - * @param string $attribute - * @return Mage_Sales_Model_Mysql4_Abstract - */ - public function saveAttribute(Mage_Core_Model_Abstract $object, $attribute) - { - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { - $attribute = $attribute->getAttributeCode(); - } - - if (is_string($attribute)) { - $attribute = array($attribute); - } - - if (is_array($attribute) && !empty($attribute)) { - $this->beginTransaction(); - try { - $this->_beforeSaveAttribute($object, $attribute); - $data = new Varien_Object(); - foreach ($attribute as $code) { - $data->setData($code, $object->getData($code)); - } - - $updateArray = $this->_prepareDataForTable($data, $this->getMainTable()); - $this->_postSaveFieldsUpdate($object, $updateArray); - if (!$object->getForceUpdateGridRecords() && - count(array_intersect($this->getGridColumns(), $attribute)) > 0) { - $this->updateGridRecords($object->getId()); - } - $this->_afterSaveAttribute($object, $attribute); - $this->commit(); - } catch (Exception $e) { - $this->rollBack(); - throw $e; - } - } - - return $this; - } - - /** - * Perform actions before object save - * - * @param Varien_Object $object - * @return Mage_Sales_Model_Mysql4_Abstract - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if ($this->_useIncrementId && !$object->getIncrementId()) { - /* @var $entityType Mage_Eav_Model_Entity_Type */ - $entityType = Mage::getModel('eav/entity_type')->loadByCode($this->_entityTypeForIncrementId); - $object->setIncrementId($entityType->fetchNewIncrementId($object->getStoreId())); - } - parent::_beforeSave($object); - return $this; - } - - /** - * Update field in table if model have been already saved - * - * @param Mage_Core_Model_Abstract $object - * @param array $data - * @return Mage_Sales_Model_Mysql4_Abstract - */ - protected function _postSaveFieldsUpdate($object, $data) - { - if ($object->getId() && !empty($data)) { - $table = $this->getMainTable(); - $this->_getWriteAdapter()->update($table, $data, $this->getIdFieldName() . '=' . (int) $object->getId()); - $object->addData($data); - } - - return $this; - } - - /** - * Set main resource table - * - * @param string $table - * @return Mage_Sales_Model_Mysql4_Abstract - */ - public function setMainTable($table) - { - $this->_mainTable = $table; - return $this; - } - - /** - * Save object data - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function save(Mage_Core_Model_Abstract $object) - { - if (!$object->getForceObjectSave()) { - parent::save($object); - } - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Address.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Address.php index b9631ac111..8cba5bcd93 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Address.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Address.php @@ -20,51 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order address resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Address extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Address extends Mage_Sales_Model_Resource_Order_Address { - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_address_resource'; - - /** - * Resource initialization - */ - protected function _construct() - { - $this->_init('sales/order_address', 'entity_id'); - } - - /** - * Return configuration for all attributes - * - * @return array - */ - public function getAllAttributes() - { - $attributes = array( - 'city' => Mage::helper('sales')->__('City'), - 'company' => Mage::helper('sales')->__('Company'), - 'country_id' => Mage::helper('sales')->__('Country'), - 'email' => Mage::helper('sales')->__('Email'), - 'firstname' => Mage::helper('sales')->__('First Name'), - 'lastname' => Mage::helper('sales')->__('Last Name'), - 'region_id' => Mage::helper('sales')->__('State/Province'), - 'street' => Mage::helper('sales')->__('Street Address'), - 'telephone' => Mage::helper('sales')->__('Telephone'), - 'postcode' => Mage::helper('sales')->__('Zip/Postal Code') - ); - asort($attributes); - return $attributes; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Address/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Address/Collection.php index 54400c2168..86f3d579f2 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Address/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Address/Collection.php @@ -20,37 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order payment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Address_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Address_Collection extends Mage_Sales_Model_Resource_Order_Address_Collection { - protected $_eventPrefix = 'sales_order_address_collection'; - protected $_eventObject = 'order_address_collection'; - - protected function _construct() - { - $this->_init('sales/order_address'); - } - - /** - * Redeclare after load method for dispatch event - * - * @return Mage_Sales_Model_Mysql4_Order_Address_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - Mage::dispatchEvent($this->_eventPrefix.'_load_after', array( - $this->_eventObject => $this - )); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Billing.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Billing.php index 3addc7f8c6..d10bcc3ad5 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Billing.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Billing.php @@ -20,42 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Order billing address backend * - * @deprecated after 1.4, no more EAV for sales - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Billing extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Billing + extends Mage_Sales_Model_Resource_Order_Attribute_Backend_Billing { - - public function beforeSave($object) - { - $billingAddressId = $object->getBillingAddressId(); - if (is_null($billingAddressId)) { - $object->unsetBillingAddressId(); - } - } - - public function afterSave($object) - { - $billingAddressId = false; - foreach ($object->getAddressesCollection() as $address) { - if ('billing' == $address->getAddressType()) { - $billingAddressId = $address->getId(); - } - } - if ($billingAddressId) { - $object->setBillingAddressId($billingAddressId); - $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode()); - } - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Child.php index 407eca0d88..25321dfe6c 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Child.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Child - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Attribute_Backend_Child { - public function beforeSave($object) - { - if ($object->getOrder()) { - $object->setParentId($object->getOrder()->getId()); - } - parent::beforeSave($object); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Parent.php index 50bbd8fcf4..8f3219bc35 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Parent.php @@ -20,35 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Parent - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Attribute_Backend_Parent { - public function afterSave($object) - { - parent::afterSave($object); - - foreach ($object->getAddressesCollection() as $item) { - $item->save(); - } - foreach ($object->getItemsCollection() as $item) { - $item->save(); - } - foreach ($object->getPaymentsCollection() as $item) { - $item->save(); - } - foreach ($object->getStatusHistoryCollection() as $item) { - $item->save(); - } - foreach ($object->getRelatedObjects() as $object) { - $object->save(); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Shipping.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Shipping.php index ee619ad3be..ec0cfaf789 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Attribute/Backend/Shipping.php @@ -20,40 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Order shipping address backend - * @deprecated after 1.4, no more EAV for sales - * @category Mage - * @package Mage_Sales + * + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Shipping extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +class Mage_Sales_Model_Mysql4_Order_Attribute_Backend_Shipping + extends Mage_Sales_Model_Resource_Order_Attribute_Backend_Shipping { - - public function beforeSave($object) - { - $shippingAddressId = $object->getShippingAddressId(); - if (is_null($shippingAddressId)) { - $object->unsetShippingAddressId(); - } - } - - public function afterSave($object) - { - $shippingAddressId = false; - foreach ($object->getAddressesCollection() as $address) { - if ('shipping' == $address->getAddressType()) { - $shippingAddressId = $address->getId(); - } - } - if ($shippingAddressId) { - $object->setShippingAddressId($shippingAddressId); - $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode()); - } - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection.php index 74d0c9bc04..a3f3483aa4 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection.php @@ -20,201 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Collection extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Collection extends Mage_Sales_Model_Resource_Order_Collection { - protected $_eventPrefix = 'sales_order_collection'; - protected $_eventObject = 'order_collection'; - - protected function _construct() - { - $this->_init('sales/order'); - $this - ->addFilterToMap('entity_id', 'main_table.entity_id') - ->addFilterToMap('customer_id', 'main_table.customer_id') - ->addFilterToMap('quote_address_id', 'main_table.quote_address_id'); - } - - /** - * Add items count expr to collection select, backward capability with eav structure - * - * @return Mage_Sales_Model_Mysql4_Order_Collection - */ - public function addItemCountExpr() - { - if (is_null($this->_fieldsToSelect)) { // If we select all fields from table, - // we need to add column alias - $this->getSelect()->columns(array('items_count'=>'total_item_count')); - } else { - $this->addFieldToSelect('total_item_count', 'items_count'); - } - return $this; - } - - /** - * Minimize usual count select - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - /* @var $countSelect Varien_Db_Select */ - $countSelect = parent::getSelectCountSql(); - - $countSelect->resetJoinLeft(); - return $countSelect; - } - - /** - * Reset left join - * - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - protected function _getAllIdsSelect($limit = null, $offset = null) - { - $idsSelect = parent::_getAllIdsSelect($limit, $offset); - $idsSelect->resetJoinLeft(); - return $idsSelect; - } - - - - /** - * Join table sales_flat_order_address to select for billing and shipping order addresses. - * Create corillation map - * - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - protected function _addAddressFields() - { - $billingAliasName = 'billing_o_a'; - $shippingAliasName = 'shipping_o_a'; - $joinTable = $this->getTable('sales/order_address'); - - $this - ->addFilterToMap('billing_firstname', $billingAliasName . '.firstname') - ->addFilterToMap('billing_lastname', $billingAliasName . '.lastname') - ->addFilterToMap('billing_telephone', $billingAliasName . '.telephone') - ->addFilterToMap('billing_postcode', $billingAliasName . '.postcode') - - ->addFilterToMap('shipping_firstname', $shippingAliasName . '.firstname') - ->addFilterToMap('shipping_lastname', $shippingAliasName . '.lastname') - ->addFilterToMap('shipping_telephone', $shippingAliasName . '.telephone') - ->addFilterToMap('shipping_postcode', $shippingAliasName . '.postcode'); - - $this - ->getSelect() - ->joinLeft( - array($billingAliasName => $joinTable), - "(main_table.entity_id = $billingAliasName.parent_id AND $billingAliasName.address_type = 'billing')", - array( - $billingAliasName . '.firstname', - $billingAliasName . '.lastname', - $billingAliasName . '.telephone', - $billingAliasName . '.postcode' - ) - ) - ->joinLeft( - array($shippingAliasName => $joinTable), - "(main_table.entity_id = $shippingAliasName.parent_id AND $shippingAliasName.address_type = 'shipping')", - array( - $shippingAliasName . '.firstname', - $shippingAliasName . '.lastname', - $shippingAliasName . '.telephone', - $shippingAliasName . '.postcode' - ) - ); - - return $this; - } - - /** - * Add addresses information to select - * - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - public function addAddressFields() - { - return $this->_addAddressFields(); - } - - /** - * Add field search filter to collection as OR condition - * - * @see self::_getConditionSql for $condition - * @param string $field - * @param null|string|array $condition - * @return Mage_Eav_Model_Entity_Collection_Abstract - */ - public function addFieldToSearchFilter($field, $condition = null) - { - $field = $this->_getMappedField($field); - $this->_select->orWhere($this->_getConditionSql($field, $condition)); - return $this; - } - - /** - * Specify collection select filter by attribute value - * - * @param array|string|Mage_Eav_Model_Entity_Attribute $attribute - * @param array|integer|string|null $condition - * @return Mage_Sales_Model_Mysql4_Collection_Abstract - */ - public function addAttributeToSearchFilter($attributes, $condition = null) - { - if (is_array($attributes) && !empty($attributes)){ - $this->_addAddressFields(); - - $toFilterData = array(); - foreach ($attributes as $attribute) { - $this->addFieldToSearchFilter($this->_attributeToField($attribute['attribute']), $attribute); - } - } - else { - $this->addAttributeToFilter($attributes, $condition); - } - - return $this; - } - - /** - * Add filter by specified billing agreements - * - * @param int|array $agreements - * @return Mage_Sales_Model_Mysql4_Order_Collection - */ - public function addBillingAgreementsFilter($agreements) - { - $agreements = (is_array($agreements)) ? $agreements : array($agreements); - $this->getSelect()->joinInner( - array('sbao' => $this->getTable('sales/billing_agreement_order')), - 'main_table.entity_id = sbao.order_id', - array() - )->where('sbao.agreement_id IN(?)', $agreements); - return $this; - } - - /** - * Add filter by specified recurring profile id(s) - * - * @param array|int $ids - * @return Mage_Sales_Model_Mysql4_Order_Collection - */ - public function addRecurringProfilesFilter($ids) - { - $ids = (is_array($ids)) ? $ids : array($ids); - $this->getSelect()->joinInner( - array('srpo' => $this->getTable('sales/recurring_profile_order')), - 'main_table.entity_id = srpo.order_id', - array() - )->where('srpo.profile_id IN(?)', $ids); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection/Abstract.php index fd1ff79fc6..b66dba0e2f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Collection/Abstract.php @@ -20,80 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -abstract class Mage_Sales_Model_Mysql4_Order_Collection_Abstract extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Collection_Abstract extends Mage_Sales_Model_Resource_Order_Collection_Abstract { - /** - * Order object - * - * @var Mage_Sales_Model_Order - */ - protected $_salesOrder = null; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'parent_id'; - - /** - * Set sales order model as parent collection object - * - * @param Mage_Sales_Model_Order $order - * @return Mage_Sales_Model_Mysql4_Order_Collection_Abstract - */ - public function setSalesOrder($order) - { - $this->_salesOrder = $order; - if ($this->_eventPrefix && $this->_eventObject) { - Mage::dispatchEvent($this->_eventPrefix . '_set_sales_order', array( - 'collection' => $this, - $this->_eventObject => $this, - 'order' => $order - )); - } - - return $this; - } - - /** - * Retrieve sales order as parent collection object - * - * @return Mage_Sales_Model_Order|null - */ - public function getSalesOrder() - { - return $this->_salesOrder; - } - - /** - * Add order filter - * - * @param int|Mage_Sales_Model_Order $order - * @return Mage_Sales_Model_Mysql4_Order_Collection_Abstract - */ - public function setOrderFilter($order) - { - if ($order instanceof Mage_Sales_Model_Order) { - $this->setSalesOrder($order); - $orderId = $order->getId(); - if ($orderId) { - $this->addFieldToFilter($this->_orderField, $orderId); - } else { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - } - } else { - $this->addFieldToFilter($this->_orderField, $order); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Comment/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Comment/Collection/Abstract.php index fd780398af..a432dfc270 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Comment/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Comment/Collection/Abstract.php @@ -20,49 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order abstract comments collection, used as parent for: invoice, shipment, creditmemo * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -abstract class Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract + extends Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract { - /** - * Set filter on comments by their parent item - * - * @param Mage_Core_Model_Abstract|int $parent - * @return Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract - */ - public function setParentFilter($parent) - { - if ($parent instanceof Mage_Core_Model_Abstract) { - $parent = $parent->getId(); - } - return $this->addFieldToFilter('parent_id', $parent); - } - - /** - * Adds filter to get only 'visible on front' comments - * - * @param int $flag - * @return Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract - */ - public function addVisibleOnFrontFilter($flag = 1) - { - return $this->addFieldToFilter('is_visible_on_front', $flag); - } - - /** - * Set created_at sort order - * - * @param string $direction - * @return Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract - */ - public function setCreatedAtOrder($direction='desc') - { - return $this->setOrder('created_at', $direction); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo.php index 1e57bec195..8d1d630bce 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo extends Mage_Sales_Model_Resource_Order_Creditmemo { - protected $_eventPrefix = 'sales_order_creditmemo_resource'; - protected $_grid = true; - protected $_useIncrementId = true; - protected $_entityTypeForIncrementId = 'creditmemo'; - - protected function _construct() - { - $this->_init('sales/creditmemo', 'entity_id'); - } - - /** - * Init virtual grid records for entity - * - * @return Mage_Sales_Model_Mysql4_Order_Creditmemo - */ - protected function _initVirtualGridColumns() - { - parent::_initVirtualGridColumns(); - $this->addVirtualGridColumn( - 'billing_name', - 'sales/order_address', - array('billing_address_id' => 'entity_id'), - 'CONCAT(IFNULL({{table}}.firstname, ""), " ", IFNULL({{table}}.lastname, ""))' - ) - ->addVirtualGridColumn( - 'order_increment_id', - 'sales/order', - array('order_id' => 'entity_id'), - 'increment_id' - ) - ->addVirtualGridColumn( - 'order_created_at', - 'sales/order', - array('order_id' => 'entity_id'), - 'created_at' - ) - ; - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Child.php index e974ed5784..083a01da02 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Child.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Creditmemo_Attribute_Backend_Child - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Creditmemo_Attribute_Backend_Child { - public function beforeSave($object) - { - if ($object->getCreditmemo()) { - $object->setParentId($object->getCreditmemo()->getId()); - } - return parent::beforeSave($object); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Parent.php index 14c24fc088..a61a633e41 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Attribute/Backend/Parent.php @@ -20,31 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Creditmemo_Attribute_Backend_Parent - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Creditmemo_Attribute_Backend_Parent { - public function afterSave($object) - { - parent::afterSave($object); - - /** - * Save creditmemo items - */ - foreach ($object->getAllItems() as $item) { - $item->save(); - } - - foreach($object->getCommentsCollection() as $comment) { - $comment->save(); - } - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Collection.php index 12f33c1e60..fd31752016 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Collection.php @@ -20,38 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Collection extends Mage_Sales_Model_Resource_Order_Creditmemo_Collection { - protected $_eventPrefix = 'sales_order_creditmemo_collection'; - protected $_eventObject = 'order_creditmemo_collection'; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - - protected function _construct() - { - $this->_init('sales/order_creditmemo'); - } - - /** - * Used to emulate after load functionality for each item without loading them - * - */ - protected function _afterLoad() - { - $this->walk('afterLoad'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment.php index 1eec74f0c2..a2e4327ca7 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo comment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Comment extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Comment extends Mage_Sales_Model_Resource_Order_Creditmemo_Comment { - protected $_eventPrefix = 'sales_order_creditmemo_comment_resource'; - - protected function _construct() - { - $this->_init('sales/creditmemo_comment', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment/Collection.php index 89933e70a1..b467cb2568 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Comment/Collection.php @@ -20,45 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo comments collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Comment_Collection extends Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Creditmemo_Comment_Collection { - /* - * @var string - */ - protected $_eventPrefix = 'sales_order_creditmemo_comment_collection'; - - /* - * @var string - */ - protected $_eventObject = 'order_creditmemo_comment_collection'; - - /* - * Inits creditmemo comment collection - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->_init('sales/order_creditmemo_comment'); - } - - /** - * Set creditmemo filter - * - * @param int $creditmemoId - * @return Mage_Sales_Model_Mysql4_Order_Creditmemo_Comment_Collection - */ - public function setCreditmemoFilter($creditmemoId) - { - return $this->setParentFilter($creditmemoId); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Grid/Collection.php index 6bc6f69016..903ebd1f61 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Grid/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Grid/Collection.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo grid collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Grid_Collection extends Mage_Sales_Model_Mysql4_Order_Creditmemo_Collection +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Grid_Collection + extends Mage_Sales_Model_Resource_Order_Creditmemo_Grid_Collection { - protected $_eventPrefix = 'sales_order_creditmemo_grid_collection'; - protected $_eventObject = 'order_creditmemo_grid_collection'; - - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales/creditmemo_grid'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item.php index 0c62cbb694..c78360d0b0 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo item resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Item extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Item extends Mage_Sales_Model_Resource_Order_Creditmemo_Item { - protected $_eventPrefix = 'sales_order_creditmemo_item_resource'; - - protected function _construct() - { - $this->_init('sales/creditmemo_item', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item/Collection.php index b3996c2a04..344354b019 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Creditmemo/Item/Collection.php @@ -20,33 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order creditmemo items collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Creditmemo_Item_Collection extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Creditmemo_Item_Collection + extends Mage_Sales_Model_Resource_Order_Creditmemo_Item_Collection { - protected $_eventPrefix = 'sales_order_creditmemo_item_collection'; - protected $_eventObject = 'order_creditmemo_item_collection'; - - protected function _construct() - { - $this->_init('sales/order_creditmemo_item'); - } - - /** - * Set creditmemo filter - * - * @param int $creditmemoId - * @return Mage_Sales_Model_Mysql4_Order_Creditmemo_Item_Collection - */ - public function setCreditmemoFilter($creditmemoId) - { - $this->addFieldToFilter('parent_id', $creditmemoId); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php index 5a84cd7839..54c3d84edb 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php @@ -20,73 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order grid collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Grid_Collection extends Mage_Sales_Model_Mysql4_Order_Collection +class Mage_Sales_Model_Mysql4_Order_Grid_Collection extends Mage_Sales_Model_Resource_Order_Grid_Collection { - protected $_eventPrefix = 'sales_order_grid_collection'; - protected $_eventObject = 'order_grid_collection'; - - /** - * Customer mode flag - * - * @var bool - */ - protected $_customerModeFlag = false; - - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales/order_grid'); - } - - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - - $unionSelect = clone $this->getSelect(); - - $unionSelect->reset(Zend_Db_Select::ORDER); - $unionSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $unionSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $countSelect = clone $this->getSelect(); - $countSelect->reset(); - $countSelect->from(array('a' => $unionSelect), 'COUNT(*)'); - - return $countSelect; - } - - /** - * Set customer mode flag value - * - * @param bool $value - * @return Mage_Sales_Model_Mysql4_Order_Grid_Collection - */ - public function setIsCustomerMode($value) - { - $this->_customerModeFlag = (bool)$value; - return $this; - } - - /** - * Get customer mode flag value - * - * @return bool - */ - public function getIsCustomerMode() - { - return $this->_customerModeFlag; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice.php index 2b6c44ef8c..159655f283 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice extends Mage_Sales_Model_Resource_Order_Invoice { - protected $_eventPrefix = 'sales_order_invoice_resource'; - protected $_grid = true; - protected $_useIncrementId = true; - protected $_entityTypeForIncrementId = 'invoice'; - - protected function _construct() - { - $this->_init('sales/invoice', 'entity_id'); - } - - /** - * Init virtual grid records for entity - * - * @return Mage_Sales_Model_Mysql4_Order_Invoice - */ - protected function _initVirtualGridColumns() - { - parent::_initVirtualGridColumns(); - $this->addVirtualGridColumn( - 'billing_name', - 'sales/order_address', - array('billing_address_id' => 'entity_id'), - 'CONCAT(IFNULL({{table}}.firstname, ""), " ", IFNULL({{table}}.lastname, ""))' - ) - ->addVirtualGridColumn( - 'order_increment_id', - 'sales/order', - array('order_id' => 'entity_id'), - 'increment_id' - ) - ->addVirtualGridColumn( - 'order_created_at', - 'sales/order', - array('order_id' => 'entity_id'), - 'created_at' - ) - ; - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Child.php index 7efe927102..b995cd5ec9 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Child.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Invoice_Attribute_Backend_Child - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Child { - public function beforeSave($object) - { - if ($object->getInvoice()) { - $object->setParentId($object->getInvoice()->getId()); - } - return parent::beforeSave($object); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Item.php index 5a042eacc9..413084d606 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Item.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Invoice_Attribute_Backend_Item - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Item { - public function afterSave($object) - { - if ($object->getOrderItem()) { - $object->getOrderItem()->save(); - } - return parent::beforeSave($object); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Order.php index 3600ae0d7a..9d865e9d17 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Order.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Invoice_Attribute_Backend_Order - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Order { - public function beforeSave($object) - { - if ($object->getOrder()) { - $object->setOrderId($object->getOrder()->getId()); - $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId()); - } - return parent::beforeSave($object); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Parent.php index 055025ce03..bde5ce00ad 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Attribute/Backend/Parent.php @@ -20,32 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Invoice_Attribute_Backend_Parent - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Parent { - public function afterSave($object) - { - parent::afterSave($object); - - /** - * Save invoice items - */ - foreach ($object->getAllItems() as $item) { - $item->setOrderItem($item->getOrderItem()); - $item->save(); - } - - foreach($object->getCommentsCollection() as $comment) { - $comment->save(); - } - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php index 65f7d8a3b1..bb7920242e 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php @@ -20,36 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice_Collection extends Mage_Sales_Model_Resource_Order_Invoice_Collection { - protected $_eventPrefix = 'sales_order_invoice_collection'; - protected $_eventObject = 'order_invoice_collection'; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - protected function _construct() - { - $this->_init('sales/order_invoice'); - } - /** - * Used to emulate after load functionality for each item without loading them - * - */ - protected function _afterLoad() - { - $this->walk('afterLoad'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment.php index 92737ea5ca..410f9bff39 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment.php @@ -20,22 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice comment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Comment extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice_Comment extends Mage_Sales_Model_Resource_Order_Invoice_Comment { - protected $_eventPrefix = 'sales_order_invoice_comment_resource'; - - - protected function _construct() - { - $this->_init('sales/invoice_comment', 'entity_id'); - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment/Collection.php index 76e32f0d33..f839e85d11 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Comment/Collection.php @@ -20,45 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice comment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Comment_Collection extends Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Invoice_Comment_Collection { - /* - * @var string - */ - protected $_eventPrefix = 'sales_order_invoice_comment_collection'; - - /* - * @var string - */ - protected $_eventObject = 'order_invoice_comment_collection'; - - /* - * Inits invoice comment collection - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->_init('sales/order_invoice_comment'); - } - - /** - * Set invoice filter - * - * @param int $invoiceId - * @return Mage_Sales_Model_Mysql4_Order_Invoice_Comment_Collection - */ - public function setInvoiceFilter($invoiceId) - { - return $this->setParentFilter($invoiceId); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Grid/Collection.php index 20004d4df7..09df19aa74 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Grid/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Grid/Collection.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice grid collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Grid_Collection extends Mage_Sales_Model_Mysql4_Order_Invoice_Collection +class Mage_Sales_Model_Mysql4_Order_Invoice_Grid_Collection + extends Mage_Sales_Model_Resource_Order_Invoice_Grid_Collection { - protected $_eventPrefix = 'sales_order_invoice_grid_collection'; - protected $_eventObject = 'order_invoice_grid_collection'; - - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales/invoice_grid'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item.php index 049a6aae79..660a478063 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice item resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Item extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice_Item extends Mage_Sales_Model_Resource_Order_Invoice_Item { - protected $_eventPrefix = 'sales_order_invoice_item_resource'; - - protected function _construct() - { - $this->_init('sales/invoice_item', 'entity_id'); - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item/Collection.php index aa737adf8b..6ada48f80c 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Item/Collection.php @@ -20,33 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order invoice item collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Invoice_Item_Collection extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Invoice_Item_Collection + extends Mage_Sales_Model_Resource_Order_Invoice_Item_Collection { - protected $_eventPrefix = 'sales_order_invoice_item_collection'; - protected $_eventObject = 'order_invoice_item_collection'; - - protected function _construct() - { - $this->_init('sales/order_invoice_item'); - } - - /** - * Set invoice filter - * - * @param int $invoiceId - * @return Mage_Sales_Model_Mysql4_Order_Invoice_Item_Collection - */ - public function setInvoiceFilter($invoiceId) - { - $this->addFieldToFilter('parent_id', $invoiceId); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Item.php index 5a6a973e0b..302a3e06e9 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Item.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order item resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Item extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Item extends Mage_Sales_Model_Resource_Order_Item { - protected $_eventPrefix = 'sales_order_item_resource'; - - protected function _construct() - { - $this->_init('sales/order_item', 'item_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Item/Collection.php index 081c073682..3ba443d9f8 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Item/Collection.php @@ -20,105 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order payment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Item_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Item_Collection extends Mage_Sales_Model_Resource_Order_Item_Collection { - protected $_eventPrefix = 'sales_order_item_collection'; - protected $_eventObject = 'order_item_collection'; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - protected function _construct() - { - $this->_init('sales/order_item'); - } - - /** - * Assign parent items on after collection load - * - * @return Mage_Sales_Model_Mysql4_Order_Item_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - /** - * Assign parent items - */ - foreach ($this as $item) { - if ($item->getParentItemId()) { - $item->setParentItem($this->getItemById($item->getParentItemId())); - } - } - return $this; - } - - /** - * Set random items order - * - * @return Mage_Sales_Model_Mysql4_Order_Item_Collection - */ - public function setRandomOrder() - { - $this->setOrder('RAND()'); - return $this; - } - - /** - * Set filter by item id - * - * @param mixed $item - * @return Mage_Sales_Model_Mysql4_Order_Item_Collection - */ - public function addIdFilter($item) - { - if (is_array($item)) { - $this->addFieldToFilter('item_id', array('in'=>$item)); - } elseif ($item instanceof Mage_Sales_Model_Order_Item) { - $this->addFieldToFilter('item_id', $item->getId()); - } else { - $this->addFieldToFilter('item_id', $item); - } - return $this; - } - - /** - * Filter collection by specified product types - * - * @param array $typeIds - * @return Mage_Sales_Model_Mysql4_Order_Item_Collection - */ - public function filterByTypes($typeIds) - { - $this->addFieldToFilter('product_type', array('in' => $typeIds)); - return $this; - } - - /** - * Filter collection by parent_item_id - * - * @param int $parentId - * @return Mage_Sales_Model_Mysql4_Order_Item_Collection - */ - public function filterByParent($parentId = null) - { - if (empty($parentId)) { - $this->addFieldToFilter('parent_item_id', array('null' => true)); - } - else { - $this->addFieldToFilter('parent_item_id', $parentId); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment.php index f17f9f7e6a..146a50e419 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment.php @@ -20,29 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order payment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Payment extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Payment extends Mage_Sales_Model_Resource_Order_Payment { - /** - * Serializeable field: additional_information - * - * @var array - */ - protected $_serializableFields = array( - 'additional_information' => array(null, array()) - ); - - protected $_eventPrefix = 'sales_order_payment_resource'; - - protected function _construct() - { - $this->_init('sales/order_payment', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Collection.php index 0b38d331bb..127533df30 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Collection.php @@ -20,35 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order payment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Payment_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Payment_Collection extends Mage_Sales_Model_Resource_Order_Payment_Collection { - protected $_eventPrefix = 'sales_order_payment_collection'; - protected $_eventObject = 'order_payment_collection'; - - protected function _construct() - { - $this->_init('sales/order_payment'); - } - - /** - * Unserialize additional_information in each item - * - * @return Mage_Sales_Model_Mysql4_Order_Payment_Collection - */ - protected function _afterLoad() - { - foreach ($this->_items as $item) { - $this->getResource()->unserializeFields($item); - } - return parent::_afterLoad(); - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction.php index a523b90e25..b2067d4e61 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction.php @@ -20,167 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales transaction resource model + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Payment_Transaction extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Payment_Transaction extends Mage_Sales_Model_Resource_Order_Payment_Transaction { - /** - * Serializeable field: additional_information - * - * @var array - */ - protected $_serializableFields = array( - 'additional_information' => array(null, array()) - ); - - /** - * Initialize main table and the primary key field name - */ - protected function _construct() - { - $this->_init('sales/payment_transaction', 'transaction_id'); - } - - /** - * Update transactions in database using provided transaction as parent for them - * have to repeat the business logic to avoid accidental injection of wrong transactions - * @param Mage_Sales_Model_Order_Payment_Transaction $transaction - */ - public function injectAsParent(Mage_Sales_Model_Order_Payment_Transaction $transaction) - { - $txnId = $transaction->getTxnId(); - if ($txnId && Mage_Sales_Model_Order_Payment_Transaction::TYPE_PAYMENT === $transaction->getTxnType() - && $id = $transaction->getId()) { - $adapter = $this->_getWriteAdapter(); - - // verify such transaction exists, determine payment and order id - $verificationRow = $adapter->fetchRow( - $adapter->select()->from($this->getMainTable(), array('payment_id', 'order_id')) - ->where("{$this->getIdFieldName()} = ?", (int)$id) - ); - if (!$verificationRow) { - return; - } - list($paymentId, $orderId) = array_values($verificationRow); - - // inject - $adapter->update($this->getMainTable(), array('parent_id' => $id), - sprintf('%s <> %d AND parent_id IS NULL AND payment_id = %d AND order_id = %d AND parent_txn_id = %s', - $this->getIdFieldName(), $id, - (int)$paymentId, (int)$orderId, - $adapter->quote($txnId) - )); - } - } - - /** - * Load the tansaction object by specified txn_id - * @param Mage_Sales_Model_Order_Payment_Transaction $transaction - * @param int $orderId - * @param int $paymentId - * @param string $txnId - */ - public function loadObjectByTxnId(Mage_Sales_Model_Order_Payment_Transaction $transaction, $orderId, $paymentId, $txnId) - { - $select = $this->_getLoadByUniqueKeySelect($orderId, $paymentId, $txnId); - $data = $this->_getWriteAdapter()->fetchRow($select); - $transaction->setData($data); - $this->unserializeFields($transaction); - $this->_afterLoad($transaction); - } - - /** - * Retrieve order website id - * - * @param int $orderId - * @return string - */ - public function getOrderWebsiteId($orderId) - { - $select = $this->_getReadAdapter()->select() - ->from(array('so' => $this->getTable('sales/order')), 'cs.website_id') - ->joinInner(array('cs' => $this->getTable('core/store')), 'cs.store_id = so.store_id') - ->where('so.entity_id = ?', $orderId); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Lookup for parent_id in already saved transactions of this payment by the order_id - * Also serialize additional information, if any - * - * @param Mage_Sales_Model_Order_Payment_Transaction $transaction - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction - * @throws Mage_Core_Exception - */ - protected function _beforeSave(Mage_Core_Model_Abstract $transaction) - { - $parentTxnId = $transaction->getData('parent_txn_id'); - $txnId = $transaction->getData('txn_id'); - $orderId = $transaction->getData('order_id'); - $paymentId = $transaction->getData('payment_id'); - $idFieldName = $this->getIdFieldName(); - - if ($parentTxnId) { - if (!$txnId || !$orderId || !$paymentId) { - Mage::throwException(Mage::helper('sales')->__('Not enough valid data to save the parent transaction ID.')); - } - $parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName); - if ($parentId) { - $transaction->setData('parent_id', $parentId); - } - } - - // make sure unique key won't cause trouble - if ($transaction->isFailsafe()) { - $autoincrementId = (int)$this->_lookupByTxnId($orderId, $paymentId, $txnId, $idFieldName); - if ($autoincrementId) { - $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false); - } - } - - return parent::_beforeSave($transaction); - } - - /** - * Load cell/row by specified unique key parts - * @param int $orderId - * @param int $paymentId - * @param string $txnId - * @param mixed (array|string|object) $columns - * @param bool $isRow - * @param string $txnType - * @return mixed (array|string) - */ - private function _lookupByTxnId($orderId, $paymentId, $txnId, $columns, $isRow = false, $txnType = null) - { - $select = $this->_getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $columns); - if ($txnType) { - $select->where('txn_type = ?', $txnType); - } - if ($isRow) { - return $this->_getWriteAdapter()->fetchRow($select); - } - return $this->_getWriteAdapter()->fetchOne($select); - } - - /** - * Get select object for loading transaction by the unique key of order_id, payment_id, txn_id - * @param int $orderId - * @param int $paymentId - * @param string $txnId - * @param string|array|Zend_Db_Expr $columns - */ - private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $columns = '*') - { - return $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), $columns) - ->where('order_id = ?', $orderId) - ->where('payment_id = ?', $paymentId) - ->where('txn_id = ?', $txnId); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction/Collection.php index 5e8a00ee76..a5a4f6ee37 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Payment/Transaction/Collection.php @@ -20,222 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Payment transactions collection + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection + extends Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection { - /** - * Order ID filter - * - * @var int - */ - protected $_orderId = null; - - /** - * Columns of order info that should be selected - * - * @var array - */ - protected $_addOrderInformation = array(); - - /** - * Columns of payment info that should be selected - * - * @var array - */ - protected $_addPaymentInformation = array(); - - /** - * Order Store ids - * - * @var array - */ - protected $_storeIds = array(); - - /** - * Payment ID filter - * @var int - */ - protected $_paymentId = null; - - /** - * Parent ID filter - * @var int - */ - protected $_parentId = null; - - /** - * Filter by transaction type - * @var array - */ - protected $_txnTypes = null; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - /** - * Initialize collection items factory class - */ - protected function _construct() - { - $this->_init('sales/order_payment_transaction'); - return parent::_construct(); - } - - /** - * Join order information - * - * @param array $keys - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addOrderInformation(array $keys) - { - $this->_addOrderInformation = array_merge($this->_addOrderInformation, $keys); - $this->addFilterToMap('created_at', 'main_table.created_at'); - return $this; - } - - /** - * Join payment information - * - * @param array $keys - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addPaymentInformation(array $keys) - { - $this->_addPaymentInformation = array_merge($this->_addPaymentInformation, $keys); - return $this; - } - - /** - * Order ID filter setter - * - * @param int $orderId - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addOrderIdFilter($orderId) - { - $this->_orderId = (int)$orderId; - return $this; - } - - /** - * Payment ID filter setter - * Can take either the integer id or the payment instance - * @param Mage_Sales_Model_Order_Payment|int $payment - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addPaymentIdFilter($payment) - { - $id = $payment; - if (is_object($payment)) { - $id = $payment->getId(); - } - $this->_paymentId = (int)$id; - return $this; - } - - /** - * Parent ID filter setter - * @param int $parentId - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addParentIdFilter($parentId) - { - $this->_parentId = (int)$parentId; - return $this; - } - - /** - * Transaction type filter setter - * @param array|string $txnType - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addTxnTypeFilter($txnType) - { - if (!is_array($txnType)) { - $txnType = array($txnType); - } - $this->_txnTypes = $txnType; - return $this; - } - - /** - * Add filter by store ids - * - * @param int|array $storeIds - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - public function addStoreFilter($storeIds) - { - $storeIds = (is_array($storeIds)) ? $storeIds : array($storeIds); - $this->_storeIds = array_merge($this->_storeIds, $storeIds); - return $this; - } - - /** - * Prepare filters - */ - protected function _beforeLoad() - { - parent::_beforeLoad(); - - if ($this->isLoaded()) { - return $this; - } - - // filters - if ($this->_paymentId) { - $this->getSelect()->where('main_table.payment_id = ?', $this->_paymentId); - } - if ($this->_parentId) { - $this->getSelect()->where('main_table.parent_id = ?', $this->_parentId); - } - if ($this->_txnTypes) { - $this->getSelect()->where('main_table.txn_type IN(?)', $this->_txnTypes); - } - if ($this->_orderId) { - $this->getSelect()->where('main_table.order_id = ?', $this->_orderId); - } - if ($this->_addPaymentInformation) { - $this->getSelect()->joinInner( - array('sop' => $this->getTable('sales/order_payment')), - 'main_table.payment_id = sop.entity_id', - $this->_addPaymentInformation - ); - } - if ($this->_storeIds) { - $this->getSelect()->where('so.store_id IN(?)', $this->_storeIds); - $this->addOrderInformation(array('store_id')); - } - if($this->_addOrderInformation) { - $this->getSelect()->joinInner( - array('so' => $this->getTable('sales/order')), - 'main_table.order_id = so.entity_id', - $this->_addOrderInformation - ); - } - return $this; - } - - /** - * Unserialize additional_information in each item - * @return Mage_Sales_Model_Mysql4_Order_Payment_Transaction_Collection - */ - protected function _afterLoad() - { - foreach ($this->_items as $item) { - $this->getResource()->unserializeFields($item); - } - return parent::_afterLoad(); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment.php index 14c9979623..23245beb9d 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment.php @@ -20,54 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment extends Mage_Sales_Model_Resource_Order_Shipment { - protected $_eventPrefix = 'sales_order_shipment_resource'; - protected $_grid = true; - protected $_useIncrementId = true; - protected $_entityTypeForIncrementId = 'shipment'; - - protected function _construct() - { - $this->_init('sales/shipment', 'entity_id'); - } - - /** - * Init virtual grid records for entity - * - * @return Mage_Sales_Model_Mysql4_Order_Shipment - */ - protected function _initVirtualGridColumns() - { - parent::_initVirtualGridColumns(); - $this->addVirtualGridColumn( - 'shipping_name', - 'sales/order_address', - array('shipping_address_id' => 'entity_id'), - 'CONCAT(IFNULL({{table}}.firstname, ""), " ", IFNULL({{table}}.lastname, ""))' - ) - ->addVirtualGridColumn( - 'order_increment_id', - 'sales/order', - array('order_id' => 'entity_id'), - 'increment_id' - ) - ->addVirtualGridColumn( - 'order_created_at', - 'sales/order', - array('order_id' => 'entity_id'), - 'created_at' - ) - ; - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Child.php index 1ac53ffa0b..196381ce18 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Child.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Shipment_Attribute_Backend_Child - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Child { - public function beforeSave($object) - { - if ($object->getShipment()) { - $object->setParentId($object->getShipment()->getId()); - } - return parent::beforeSave($object); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Parent.php index 57e1abff15..e541bc9f3a 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Attribute/Backend/Parent.php @@ -20,37 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, no more EAV for sales + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Mysql4_Order_Shipment_Attribute_Backend_Parent - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Parent { - public function afterSave($object) - { - parent::afterSave($object); - - /** - * Save Shipment items - */ - foreach ($object->getAllItems() as $item) { - $item->save(); - } - - /** - * Save Shipment tracks - */ - foreach ($object->getAllTracks() as $track) { - $track->save(); - } - - foreach($object->getCommentsCollection() as $comment) { - $comment->save(); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Collection.php index f4e955a03e..8122e265f1 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Collection.php @@ -20,36 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Collection extends Mage_Sales_Model_Resource_Order_Shipment_Collection { - protected $_eventPrefix = 'sales_order_shipment_collection'; - protected $_eventObject = 'order_shipment_collection'; - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - protected function _construct() - { - $this->_init('sales/order_shipment'); - } - - /** - * Used to emulate after load functionality for each item without loading them - * - */ - protected function _afterLoad() - { - $this->walk('afterLoad'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment.php index 54160f6900..a6a448e1ad 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment comment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Comment extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Comment extends Mage_Sales_Model_Resource_Order_Shipment_Comment { - protected $_eventPrefix = 'sales_order_shipment_comment_resource'; - - protected function _construct() - { - $this->_init('sales/shipment_comment', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment/Collection.php index abe6b71177..440fd68330 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Comment/Collection.php @@ -20,45 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment comments collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Comment_Collection extends Mage_Sales_Model_Mysql4_Order_Comment_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Shipment_Comment_Collection { - /* - * @var string - */ - protected $_eventPrefix = 'sales_order_shipment_comment_collection'; - - /* - * @var string - */ - protected $_eventObject = 'order_shipment_comment_collection'; - - /* - * Inits shipment comment collection - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->_init('sales/order_shipment_comment'); - } - - /** - * Set shipment filter - * - * @param int $shipmentId - * @return Mage_Sales_Model_Mysql4_Order_Shipment_Comment_Collection - */ - public function setShipmentFilter($shipmentId) - { - return $this->setParentFilter($shipmentId); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Grid/Collection.php index db6523482a..963b37365a 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Grid/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Grid/Collection.php @@ -20,24 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Grid_Collection extends Mage_Sales_Model_Mysql4_Order_Shipment_Collection +class Mage_Sales_Model_Mysql4_Order_Shipment_Grid_Collection + extends Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection { - protected $_eventPrefix = 'sales_order_shipment_grid_collection'; - protected $_eventObject = 'order_shipment_grid_collection'; - - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales/shipment_grid'); - } - - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item.php index d0ac67f879..5db6b6685b 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment item resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Item extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Item extends Mage_Sales_Model_Resource_Order_Shipment_Item { - protected $_eventPrefix = 'sales_order_shipment_item_resource'; - - protected function _construct() - { - $this->_init('sales/shipment_item', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item/Collection.php index 67858362b5..20909f8a23 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Item/Collection.php @@ -20,33 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment items collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Item_Collection extends Mage_Sales_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Item_Collection + extends Mage_Sales_Model_Resource_Order_Shipment_Item_Collection { - protected $_eventPrefix = 'sales_order_shipment_item_collection'; - protected $_eventObject = 'order_shipment_item_collection'; - - protected function _construct() - { - $this->_init('sales/order_shipment_item'); - } - - /** - * Set shipment filter - * - * @param int $shipmentId - * @return Mage_Sales_Model_Mysql4_Order_Shipment_Item_Collection - */ - public function setShipmentFilter($shipmentId) - { - $this->addFieldToFilter('parent_id', $shipmentId); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track.php index 1c93eba23f..bdbf6b160a 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment comment resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Track extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Track extends Mage_Sales_Model_Resource_Order_Shipment_Track { - protected $_eventPrefix = 'sales_order_shipment_track_resource'; - - protected function _construct() - { - $this->_init('sales/shipment_track', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track/Collection.php index 479bf3e542..220e005bd5 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Shipment/Track/Collection.php @@ -20,41 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order shipment tracks collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Shipment_Track_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Shipment_Track_Collection + extends Mage_Sales_Model_Resource_Order_Shipment_Track_Collection { - protected $_eventPrefix = 'sales_order_shipment_track_collection'; - protected $_eventObject = 'order_shipment_track_collection'; - - /** - * Order field for setOrderFilter - * - * @var string - */ - protected $_orderField = 'order_id'; - - protected function _construct() - { - $this->_init('sales/order_shipment_track'); - } - - /** - * Set shipment filter - * - * @param int $shipmentId - * @return Mage_Sales_Model_Mysql4_Order_Shipment_Track_Collection - */ - public function setShipmentFilter($shipmentId) - { - $this->addFieldToFilter('parent_id', $shipmentId); - return $this; - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status.php index ea31a265c0..7b69fe3f97 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status.php @@ -20,184 +20,13 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order status resource model */ -class Mage_Sales_Model_Mysql4_Order_Status extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Order_Status extends Mage_Sales_Model_Resource_Order_Status { - /** - * Status labels table - * - * @var string - */ - protected $_labelsTable; - - /** - * Status state table - * - * @var string - */ - protected $_stateTable; - - /** - * Internal constructor - */ - protected function _construct() - { - $this->_init('sales/order_status', 'status'); - $this->_isPkAutoIncrement = false; - $this->_labelsTable = $this->getTable('sales/order_status_label'); - $this->_stateTable = $this->getTable('sales/order_status_state'); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - if ($field == 'default_state') { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable()) - ->join(array('state_table'=>$this->_stateTable), $this->getMainTable().'.status=state_table.status', 'status') - ->where('state_table.state=?', $value) - ->order('state_table.is_default DESC') - ->limit(1); - } else { - $select = parent::_getLoadSelect($field, $value, $object); - } - return $select; - } - - /** - * Store labels getter - * - * @param Mage_Core_Model_Abstract $status - * @return array - */ - public function getStoreLabels(Mage_Core_Model_Abstract $status) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->_labelsTable, array('store_id', 'label')) - ->where('status=?', $status->getStatus()); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Save status labels per store - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Sales_Model_Mysql4_Order_Status - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if ($object->hasStoreLabels()) { - $labels = $object->getStoreLabels(); - $this->_getWriteAdapter()->delete( - $this->_labelsTable, - array('status = ?' => $object->getStatus()) - ); - $data = array(); - foreach ($labels as $storeId => $label) { - if (empty($label)) { - continue; - } - $data[] = array( - 'status' => $object->getStatus(), - 'store_id' => $storeId, - 'label' => $label - ); - } - if (!empty($data)) { - $this->_getWriteAdapter()->insertMultiple($this->_labelsTable, $data); - } - } - return parent::_afterSave($object); - } - - /** - * Assign order status to order state - * - * @param string $status - * @param string $state - * @param bool $isDefault - * @return Mage_Sales_Model_Mysql4_Order_Status - */ - public function assignState($status, $state, $isDefault) - { - if ($isDefault) { - $this->_getWriteAdapter()->update( - $this->_stateTable, - array('is_default' => 0), - array('state=?' => $state) - ); - } - $this->_getWriteAdapter()->insertOnDuplicate( - $this->_stateTable, - array( - 'status' => $status, - 'state' => $state, - 'is_default'=> (int) $isDefault - ) - ); - return $this; - } - - /** - * Unassign order status from order state - * - * @param string $status - * @param string $state - * @return Mage_Sales_Model_Mysql4_Order_Status - */ - public function unassignState($status, $state) - { - $select = $this->_getWriteAdapter()->select() - ->from($this->_stateTable, 'count(*)') - ->where('state=?', $state); - if ($this->_getWriteAdapter()->fetchOne($select) == 1) { - throw new Mage_Core_Exception( - Mage::helper('sales')->__('Last status can\'t be unassigned from state.') - ); - } - $select = $this->_getWriteAdapter()->select() - ->from($this->_stateTable, 'is_default') - ->where('state=?', $state) - ->where('status=?', $status) - ->limit(1); - $isDefault = $this->_getWriteAdapter()->fetchOne($select); - $this->_getWriteAdapter()->delete( - $this->_stateTable, - array( - 'state=?' => $state, - 'status=?' => $status - ) - ); - - if ($isDefault) { - $select = $this->_getWriteAdapter()->select() - ->from($this->_stateTable, 'status') - ->where('state=?', $state) - ->limit(1); - $defaultStatus = $this->_getWriteAdapter()->fetchOne($select); - if ($defaultStatus) { - $this->_getWriteAdapter()->update( - $this->_stateTable, - array('is_default'=>1), - array( - 'state=?' => $state, - 'status=?' => $defaultStatus - ) - ); - } - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/Collection.php index a115a782d9..6730e36ed0 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/Collection.php @@ -20,81 +20,13 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Flat sales order status history collection */ -class Mage_Sales_Model_Mysql4_Order_Status_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Status_Collection extends Mage_Sales_Model_Resource_Order_Status_Collection { - /** - * Internal constructor - */ - protected function _construct() - { - $this->_init('sales/order_status'); - } - - /** - * Get collection data as options array - * - * @return array - */ - public function toOptionArray() - { - return $this->_toOptionArray('status', 'label'); - } - - /** - * Get collection data as options hash - * - * @return array - */ - public function toOptionHash() - { - return $this->_toOptionHash('status', 'label'); - } - - /** - * Join order states table - */ - public function joinStates() - { - if (!$this->getFlag('states_joined')) { - $this->_idFieldName = 'status_state'; - $this->getSelect()->joinLeft( - array('state_table' => $this->getTable('sales/order_status_state')), - 'main_table.status=state_table.status', - array('state', 'is_default') - ); - $this->setFlag('states_joined', true); - } - return $this; - } - - /** - * add state code filter to collection - * - * @param string $state - */ - public function addStateFilter($state) - { - $this->joinStates(); - $this->getSelect()->where('state_table.state=?', $state); - return $this; - } - - /** - * Define label order - * - * @param string $dir - * @return Mage_Sales_Model_Mysql4_Order_Status_Collection - */ - public function orderByLabel($dir = 'ASC') - { - $this->getSelect()->order('main_table.label '.$dir); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History.php index 386714a8f6..41383d9086 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History.php @@ -20,20 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order status history resource * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Status_History extends Mage_Sales_Model_Mysql4_Order_Abstract +class Mage_Sales_Model_Mysql4_Order_Status_History extends Mage_Sales_Model_Resource_Order_Status_History { - protected $_eventPrefix = 'sales_order_status_history_resource'; - - protected function _construct() - { - $this->_init('sales/order_status_history', 'entity_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History/Collection.php index 39b0a1c9e0..c2d0037b72 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Status/History/Collection.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Flat sales order status history collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Status_History_Collection extends Mage_Sales_Model_Mysql4_Order_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Status_History_Collection + extends Mage_Sales_Model_Resource_Order_Status_History_Collection { - protected $_eventPrefix = 'sales_order_status_history_collection'; - protected $_eventObject = 'order_status_history_collection'; - - protected function _construct() - { - $this->_init('sales/order_status_history'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax.php index d00fa328f9..278be0989b 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax.php @@ -20,17 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @deprecated after 1.4, moved to tax module + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Tax extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Order_Tax extends Mage_Sales_Model_Resource_Order_Tax { - protected function _construct() - { - $this->_init('sales/order_tax', 'tax_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax/Collection.php index bdffb1d8d1..8489891ff2 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Order/Tax/Collection.php @@ -20,30 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order Tax Collection - * - * @deprecated after 1.4 - moved to Tax module - * @author Magento Core Team + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Order_Tax_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Order_Tax_Collection extends Mage_Sales_Model_Resource_Order_Tax_Collection { - protected function _construct() - { - $this->_init('sales/order_tax', 'sales/order_tax'); - } - - public function loadByOrder($order) - { - $orderId = $order->getId(); - $this->getSelect() - ->where('main_table.order_id = ?', $orderId) - ->order('process'); - return $this->load(); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote.php index 2f2dbb0996..a622cdcdab 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote mysql4 resource model * @@ -31,182 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote extends Mage_Sales_Model_Resource_Quote { - /** - * Initialize table nad PK name - */ - protected function _construct() - { - $this->_init('sales/quote', 'entity_id'); - } - - /** - * Retrieve select object for load object data - * - * @param string $field - * @param mixed $value - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - if ($storeIds = $object->getSharedStoreIds()) { - $select->where('store_id IN (?)', $storeIds); - } - else { - /** - * For empty result - */ - $select->where('store_id<0'); - } - return $select; - } - - /** - * Load quote data by customer identifier - * - * @param Mage_Sales_Model_Quote $quote - * @param int $customerId - */ - public function loadByCustomerId($quote, $customerId) - { - $read = $this->_getReadAdapter(); - if ($read) { - $select = $this->_getLoadSelect('customer_id', $customerId, $quote) - ->where('is_active=1') - ->order('updated_at desc') - ->limit(1); - - $data = $read->fetchRow($select); - - if ($data) { - $quote->setData($data); - } - } - - $this->_afterLoad($quote); - return $this; - } - - /** - * Load only active quote - * - * @param Mage_Sales_Model_Quote $quote - * @param int $quoteId - */ - public function loadActive($quote, $quoteId) - { - $read = $this->_getReadAdapter(); - if ($read) { - $select = $this->_getLoadSelect('entity_id', $quoteId, $quote) - ->where('is_active=1'); - - $data = $read->fetchRow($select); - - if ($data) { - $quote->setData($data); - } - } - - $this->_afterLoad($quote); - return $this; - } - - /** - * Load quote data by identifier without store - * - * @param Mage_Sales_Model_Quote $quote - * @param int $quoteId - * @return Mage_Sales_Model_Mysql4_Quote - */ - public function loadByIdWithoutStore($quote, $quoteId) - { - $read = $this->_getReadAdapter(); - if ($read) { - $select = parent::_getLoadSelect('entity_id', $quoteId, $quote); - - $data = $read->fetchRow($select); - - if ($data) { - $quote->setData($data); - } - } - - $this->_afterLoad($quote); - return $this; - } - - public function getReservedOrderId($quote) - { - return Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($quote->getStoreId()); - } - - public function isOrderIncrementIdUsed($orderIncrementId) { - if ($this->_getReadAdapter()) { - $select = $this->_getReadAdapter()->select(); - $select->from($this->getTable('sales/order'), 'entity_id') - ->where('increment_id = ?', $orderIncrementId); - $entity_id = $this->_getReadAdapter()->fetchOne($select); - if ($entity_id > 0) { - return true; - } else { - return false; - } - } - return false; - } - - /** - * Mark quotes - that depend on catalog price rules - to be recollected on demand - * - */ - public function markQuotesRecollectOnCatalogRules() - { - $this->_getWriteAdapter()->query(" - UPDATE {$this->getTable('sales/quote')} SET trigger_recollect = 1 - WHERE entity_id IN ( - SELECT DISTINCT quote_id - FROM {$this->getTable('sales/quote_item')} - WHERE product_id IN (SELECT DISTINCT product_id FROM {$this->getTable('catalogrule/rule_product_price')}) - )" - ); - } - - /** - * Substract product from all quotes quantities - * - * @param Mage_Catalog_Model_Product $product - */ - public function substractProductFromQuotes($product) - { - if ($product->getId()) { - $this->_getWriteAdapter()->query( - 'update ' . $this->getTable('sales/quote_item') . - ' as qi, ' . $this->getTable('sales/quote') . - ' as q set q.items_qty = q.items_qty - qi.qty, q.items_count = q.items_count - 1 ' . - ' where qi.product_id = "' . $product->getId() . '" and q.entity_id = qi.quote_id and qi.parent_item_id is null' - ); - } - } - - /** - * Mark recollect contain product(s) quotes - * - * @param array|int $productIds - * @return Mage_Sales_Model_Mysql4_Quote - */ - public function markQuotesRecollect($productIds) - { - $this->_getWriteAdapter()->query(" - UPDATE `{$this->getTable('sales/quote')}` SET `trigger_recollect` = 1 - WHERE `entity_id` IN ( - SELECT DISTINCT `quote_id` - FROM `{$this->getTable('sales/quote_item')}` - WHERE `product_id` IN (?) - )", $productIds - ); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address.php index 2ab67cba25..5f6daf7ef5 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote address mysql4 resource model * @@ -31,10 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Address extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address extends Mage_Sales_Model_Resource_Quote_Address { - protected function _construct() - { - $this->_init('sales/quote_address', 'address_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend.php index 83f73e3757..74157feda9 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend.php @@ -20,16 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Backend - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend { - public function collectTotals(Mage_Sales_Model_Quote_Address $address) - { - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Child.php index 31fa37aa8b..cf2c1f1253 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Child.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Child.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Backend_Child - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Child { - public function beforeSave($object) - { - if ($object->getAddress()) { - $object->setParentId($object->getAddress()->getId()) - ->setStoreId($object->getAddress()->getStoreId()); - } - parent::beforeSave($object); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Parent.php index 50dab671bc..4e312958f1 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Parent.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Parent.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Backend_Parent - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Parent { - public function afterSave($object) - { - parent::afterSave($object); - - $object->getItemsCollection()->save(); - $object->getShippingRatesCollection()->save(); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Region.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Region.php index aac91327ab..16d907cd67 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Region.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Backend/Region.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Backend_Region - extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Region { - public function beforeSave($object) - { - if (is_numeric($object->getRegion())) { - $region = Mage::getModel('directory/region')->load((int)$object->getRegion()); - if ($region) { - $object->setRegionId($region->getId()); - $object->setRegion($region->getCode()); - } - } - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend.php index d64eb77cd1..2c760092da 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend.php @@ -20,18 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend - extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $arr = array(); - - return $arr; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Custbalance.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Custbalance.php index d62bf0ba58..47a3866a4e 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Custbalance.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Custbalance.php @@ -20,24 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Custbalance - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Custbalance { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $custbalance = $address->getCustbalanceAmount(); - if ($custbalance!=0) { - $address->addTotal(array( - 'code'=>'custbalance', - 'title'=>Mage::helper('sales')->__('Store Credit'), - 'value'=>-$custbalance - )); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Discount.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Discount.php index e5f7cb7354..484836631c 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Discount.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Discount.php @@ -20,29 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Discount - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Discount { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $amount = $address->getDiscountAmount(); - if ($amount!=0) { - $title = Mage::helper('sales')->__('Discount'); - if ($address->getQuote()->getCouponCode()) { - $title .= ' ('.$address->getQuote()->getCouponCode().')'; - } - $address->addTotal(array( - 'code'=>'discount', - 'title'=>$title, - 'value'=>-$amount - )); - } - return $this; - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Grand.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Grand.php index dd1a261be1..20c90def76 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Grand.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Grand.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Grand - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Grand { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $address->addTotal(array( - 'code'=>'grand_total', - 'title'=>Mage::helper('sales')->__('Grand Total'), - 'value'=>$address->getGrandTotal(), - 'area'=>'footer', - )); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Shipping.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Shipping.php index 19f4aadc4e..206144f5f5 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Shipping.php @@ -20,29 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Shipping - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Shipping { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $amount = $address->getShippingAmount(); - if ($amount != 0) { - $title = Mage::helper('sales')->__('Shipping & Handling'); - if ($address->getShippingDescription()) { - $title .= ' (' . $address->getShippingDescription() . ')'; - } - $address->addTotal(array( - 'code' => 'shipping', - 'title' => $title, - 'value' => $address->getShippingAmount() - )); - } - return $this; - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Subtotal.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Subtotal.php index 7501151d2e..1f044434f6 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Subtotal.php @@ -20,22 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Subtotal - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Subtotal { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $address->addTotal(array( - 'code'=>'subtotal', - 'title'=>Mage::helper('sales')->__('Subtotal'), - 'value'=>$address->getSubtotal() - )); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Tax.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Tax.php index b8acad768a..a66a920d47 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Tax.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Attribute/Frontend/Tax.php @@ -20,24 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend_Tax - extends Mage_Sales_Model_Mysql4_Quote_Address_Attribute_Frontend + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Tax { - public function fetchTotals(Mage_Sales_Model_Quote_Address $address) - { - $amount = $address->getTaxAmount(); - if ($amount!=0) { - $address->addTotal(array( - 'code'=>'tax', - 'title'=>Mage::helper('sales')->__('Tax'), - 'value'=>$amount - )); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Collection.php index a79ef8feb2..24b8813f8f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,43 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Quote_Address_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address_Collection extends Mage_Sales_Model_Resource_Quote_Address_Collection { - protected $_eventPrefix = 'sales_quote_address_collection'; - protected $_eventObject = 'quote_address_collection'; - - protected function _construct() - { - $this->_init('sales/quote_address'); - } - - /** - * Setting filter on quote_id field but if quote_id is 0 - * we should exclude loading junk data from DB - * - * @param int $quoteId - * @return Mage_Sales_Model_Mysql4_Quote_Address_Collection - */ - public function setQuoteFilter($quoteId) - { - $this->addFieldToFilter('quote_id', $quoteId ? $quoteId : array('null' => 1)); - return $this; - } - - /** - * Redeclare after load method for dispatch event - * - * @return Mage_Sales_Model_Mysql4_Quote_Address_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - Mage::dispatchEvent($this->_eventPrefix.'_load_after', array( - $this->_eventObject => $this - )); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item.php index 08dfdcecce..660ff5686d 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote address item mysql4 resource model * @@ -31,10 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Address_Item extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address_Item extends Mage_Sales_Model_Resource_Quote_Address_Item { - protected function _construct() - { - $this->_init('sales/quote_address_item', 'address_item_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item/Collection.php index f9788b8d8d..b80a4e07d2 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,42 +28,11 @@ /** * Quote addresses collection * - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Quote_Address_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address_Item_Collection + extends Mage_Sales_Model_Resource_Quote_Address_Item_Collection { - protected function _construct() - { - $this->_init('sales/quote_address_item'); - } - - protected function _afterLoad() - { - parent::_afterLoad(); - /** - * Assign parent items - */ - foreach ($this as $item) { - if ($item->getParentItemId()) { - $item->setParentItem($this->getItemById($item->getParentItemId())); - } - } - - return $this; - } - - public function setAddressFilter($addressId) - { - if ($addressId) { - $this->addFieldToFilter('quote_address_id', $addressId); - } else { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - } - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate.php index e1fa9c405d..e2ba1b893f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote address shipping rate mysql4 resource model * @@ -31,10 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Address_Rate extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address_Rate extends Mage_Sales_Model_Resource_Quote_Address_Rate { - protected function _construct() - { - $this->_init('sales/quote_address_shipping_rate', 'rate_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate/Collection.php index 5751e8d0e6..051f75c1c6 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Address/Rate/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,61 +32,7 @@ * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection + extends Mage_Sales_Model_Resource_Quote_Address_Rate_Collection { - /** - * Whether to load fixed items only - * - * @var bool - */ - protected $_allowFixedOnly = false; - - protected function _construct() - { - $this->_init('sales/quote_address_rate'); - } - - /** - * Set filter by address id - * - * @param int $addressId - * @return Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection - */ - public function setAddressFilter($addressId) - { - if ($addressId) { - $this->addFieldToFilter('address_id', $addressId); - } else { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - } - return $this; - } - - /** - * Setter for loading fixed items only - * - * @param bool $value - * @return Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection - */ - public function setFixedOnlyFilter($value) - { - $this->_allowFixedOnly = (bool)$value; - return $this; - } - - /** - * Don't add item to the collection if only fixed are allowed and its carrier is not fixed - * - * @param Mage_Sales_Model_Quote_Address_Rate $rate - * @return Mage_Sales_Model_Mysql4_Quote_Address_Rate_Collection; - */ - public function addItem(Varien_Object $rate) - { - if ($this->_allowFixedOnly && (!$rate->getCarrierInstance() || !$rate->getCarrierInstance()->isFixed())) { - return $this; - } - return parent::addItem($rate); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Collection.php index e139a03f87..1b302b3986 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Collection.php @@ -20,21 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quotes collection * - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Collection extends Mage_Sales_Model_Resource_Quote_Collection { - protected function _construct() - { - $this->_init('sales/quote'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item.php index 10d9376821..d7a5098157 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote mysql4 resource model * @@ -31,10 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Item extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Item extends Mage_Sales_Model_Resource_Quote_Item { - protected function _construct() - { - $this->_init('sales/quote_item', 'item_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php index 246d78c399..39a18856c2 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,208 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Item_Collection extends Mage_Sales_Model_Resource_Quote_Item_Collection { - /** - * Collection quote instance - * - * @var Mage_Sales_Model_Quote - */ - protected $_quote; - - /** - * Product Ids array - * - * @var array - */ - protected $_productIds = array(); - - /** - * Initialize resource model - * - */ - protected function _construct() - { - $this->_init('sales/quote_item'); - } - - /** - * Retrieve store Id (From Quote) - * - * @return int - */ - public function getStoreId() - { - return $this->_quote->getStoreId(); - } - - /** - * Set Quote object to Collection - * - * @param Mage_Sales_Model_Quote $quote - * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection - */ - public function setQuote($quote) - { - $this->_quote = $quote; - $quoteId = $quote->getId(); - if ($quoteId) { - $this->addFieldToFilter('quote_id', $quote->getId()); - } else { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - } - return $this; - } - - /** - * Reset the collection and inner join it to quotes table - * - * Optionally can select items with specified product id only - * - * @param string $quotesTableName - * @param int $productId - * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection - */ - public function resetJoinQuotes($quotesTableName, $productId = null) - { - $this->getSelect() - ->reset() - ->from(array('qi' => $this->getResource()->getMainTable()), array('item_id', 'qty', 'quote_id')); - $this->getSelect() - ->joinInner(array('q' => $quotesTableName), 'qi.quote_id=q.entity_id', array('store_id', 'items_qty', 'items_count')); - if ($productId) { - $this->getSelect()->where('qi.product_id=?', $productId); - } - return $this; - } - - /** - * After load processing - * - * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - /** - * Assign parent items - */ - foreach ($this as $item) { - if ($item->getParentItemId()) { - $item->setParentItem($this->getItemById($item->getParentItemId())); - } - if ($this->_quote) { - $item->setQuote($this->_quote); - } - } - - /** - * Assign options and products - */ - $this->_assignOptions(); - $this->_assignProducts(); - $this->resetItemsDataChanged(); - - return $this; - } - - /** - * Add options to items - * - * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection - */ - protected function _assignOptions() - { - $itemIds = array_keys($this->_items); - $optionCollection = Mage::getModel('sales/quote_item_option')->getCollection() - ->addItemFilter($itemIds); - foreach ($this as $item) { - $item->setOptions($optionCollection->getOptionsByItem($item)); - } - $productIds = $optionCollection->getProductIds(); - $this->_productIds = array_merge($this->_productIds, $productIds); - - return $this; - } - - /** - * Add products to items and item options - * - * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection - */ - protected function _assignProducts() - { - Varien_Profiler::start('QUOTE:'.__METHOD__); - $productIds = array(); - foreach ($this as $item) { - $productIds[] = $item->getProductId(); - } - $this->_productIds = array_merge($this->_productIds, $productIds); - - $productCollection = Mage::getModel('catalog/product')->getCollection() - ->setStoreId($this->getStoreId()) - ->addIdFilter($this->_productIds) - ->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes()) - ->addOptionsToResult() - ->addStoreFilter() - ->addUrlRewrite() - ->addTierPriceData(); - - Mage::dispatchEvent('prepare_catalog_product_collection_prices', array( - 'collection' => $productCollection, - 'store_id' => $this->getStoreId(), - )); - Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array( - 'product_collection' => $productCollection - )); - - $recollectQuote = false; - foreach ($this as $item) { - $product = $productCollection->getItemById($item->getProductId()); - if ($product) { - $product->setCustomOptions(array()); - $qtyOptions = array(); - $optionProductIds = array(); - foreach ($item->getOptions() as $option) { - /** - * Call type specified logic for product associated with quote item - */ - $product->getTypeInstance(true)->assignProductToOption( - $productCollection->getItemById($option->getProductId()), - $option, - $product - ); - - if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) { - $optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId(); - } - } - - if ($optionProductIds) { - foreach ($optionProductIds as $optionProductId) { - $qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId); - if ($qtyOption) { - $qtyOptions[$optionProductId] = $qtyOption; - } - } - } - $item->setQtyOptions($qtyOptions); - - $item->setProduct($product); - } else { - $item->isDeleted(true); - $recollectQuote = true; - } - $item->checkData(); - } - - if ($recollectQuote && $this->_quote) { - $this->_quote->collectTotals(); - } - Varien_Profiler::stop('QUOTE:'.__METHOD__); - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option.php index 22ac34b7a8..0964a6dd51 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Item option mysql4 resource model * @@ -31,10 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Item_Option extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Item_Option extends Mage_Sales_Model_Resource_Quote_Item_Option { - protected function _construct() - { - $this->_init('sales/quote_item_option', 'option_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option/Collection.php index 94d799061a..f9f85e352b 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Option/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Item option collection * @@ -31,144 +32,7 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Item_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Item_Option_Collection + extends Mage_Sales_Model_Resource_Quote_Item_Option_Collection { - /** - * Array of option ids grouped by item id - * - * @var array - */ - protected $_optionsByItem = array(); - - /** - * Array of option ids grouped by product id - * - * @var array - */ - protected $_optionsByProduct = array(); - - /** - * Define resource model for collection - * - * @return void - */ - protected function _construct() - { - $this->_init('sales/quote_item_option'); - } - - /** - * Fill array of options by item and product - * - * @return Mage_Sales_Model_Mysql4_Quote_Item_Option_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - foreach ($this as $option) { - $optionId = $option->getId(); - $itemId = $option->getItemId(); - $productId = $option->getProductId(); - if (isset($this->_optionsByItem[$itemId])) { - $this->_optionsByItem[$itemId][] = $optionId; - } else { - $this->_optionsByItem[$itemId] = array($optionId); - } - if (isset($this->_optionsByProduct[$productId])) { - $this->_optionsByProduct[$productId][] = $optionId; - } else { - $this->_optionsByProduct[$productId] = array($optionId); - } - } - - return $this; - } - - /** - * Apply quote item(s) filter to collection - * - * @param int | array $item - * @return Mage_Sales_Model_Mysql4_Quote_Item_Option_Collection - */ - public function addItemFilter($item) - { - if (empty($item)) { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - //$this->addFieldToFilter('item_id', ''); - } else if (is_array($item)) { - $this->addFieldToFilter('item_id', array('in'=>$item)); - } else if ($item instanceof Mage_Sales_Model_Quote_Item) { - $this->addFieldToFilter('item_id', $item->getId()); - } else { - $this->addFieldToFilter('item_id', $item); - } - - return $this; - } - - /** - * Get array of all product ids - * - * @return array - */ - public function getProductIds() - { - $this->load(); - - return array_keys($this->_optionsByProduct); - } - - /** - * Get all option for item - * - * @param mixed $item - * @return array - */ - public function getOptionsByItem($item) - { - if ($item instanceof Mage_Sales_Model_Quote_Item) { - $itemId = $item->getId(); - } else { - $itemId = $item; - } - - $this->load(); - - $options = array(); - if (isset($this->_optionsByItem[$itemId])) { - foreach ($this->_optionsByItem[$itemId] as $optionId) { - $options[] = $this->_items[$optionId]; - } - } - - return $options; - } - - /** - * Get all option for item - * - * @param mixed $item - * @return array - */ - public function getOptionsByProduct($product) - { - if ($product instanceof Mage_Catalog_Model_Product) { - $productId = $product->getId(); - } else { - $productId = $product; - } - - $this->load(); - - $options = array(); - if (isset($this->_optionsByProduct[$productId])) { - foreach ($this->_optionsByProduct[$productId] as $optionId) { - $options[] = $this->_items[$optionId]; - } - } - - return $options; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment.php index 4c78313e75..622458b05f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Quote payment mysql4 resource model * @@ -31,19 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Quote_Payment extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Quote_Payment extends Mage_Sales_Model_Resource_Quote_Payment { - /** - * Serializeable field: additional_information - * - * @var array - */ - protected $_serializableFields = array( - 'additional_information' => array(null, array()) - ); - - protected function _construct() - { - $this->_init('sales/quote_payment', 'payment_id'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment/Collection.php index f6dd14ad5c..45f525164a 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Payment/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,29 +32,6 @@ * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Quote_Payment_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Quote_Payment_Collection extends Mage_Sales_Model_Resource_Quote_Payment_Collection { - protected function _construct() - { - $this->_init('sales/quote_payment'); - } - - public function setQuoteFilter($quoteId) - { - $this->addFieldToFilter('quote_id', $quoteId); - return $this; - } - - /** - * Unserialize additional_information in each item - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - protected function _afterLoad() - { - foreach ($this->_items as $item) { - $this->getResource()->unserializeFields($item); - } - return parent::_afterLoad(); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile.php b/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile.php index 90c37e3d39..29ff751117 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile.php @@ -20,64 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Recurring payment profiles resource model + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Recurring_Profile extends Mage_Sales_Model_Mysql4_Abstract +class Mage_Sales_Model_Mysql4_Recurring_Profile extends Mage_Sales_Model_Resource_Recurring_Profile { - /** - * Initialize main table and column - */ - protected function _construct() - { - $this->_init('sales/recurring_profile', 'profile_id'); - - $this->_serializableFields = array( - 'profile_vendor_info' => array(null, array()), - 'additional_info' => array(null, array()), - - 'order_info' => array(null, array()), - 'order_item_info' => array(null, array()), - 'billing_address_info' => array(null, array()), - 'shipping_address_info' => array(null, array()) - ); - } - - /** - * Return recurring profile child Orders Ids - * - * @param Mage_Sales_Model_Recurring_Profile - * @return array - */ - public function getChildOrderIds($object) - { - $select = $this->_getReadAdapter()->select() - ->from( - array('main_table' => $this->getTable('sales/recurring_profile_order')), - array('order_id')) - ->where('profile_id=?', $object->getId()); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Add order relation to recurring profile - * - * @param int $recurringProfileId - * @param int $orderId - * @return Mage_Sales_Model_Mysql4_Recurring_Profile - */ - public function addOrderRelation($recurringProfileId, $orderId) - { - $this->_getWriteAdapter()->insert( - $this->getTable('sales/recurring_profile_order'), array( - 'profile_id' => $recurringProfileId, - 'order_id' => $orderId - ) - ); - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile/Collection.php index 4c55a3073e..9217cb7775 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Recurring/Profile/Collection.php @@ -20,21 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Recurring profile collection * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Recurring_Profile_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sales_Model_Mysql4_Recurring_Profile_Collection + extends Mage_Sales_Model_Resource_Recurring_Profile_Collection { - protected $_eventPrefix = 'sales_recurring_profile_collection'; - protected $_eventObject = 'recurring_profile_collection'; - - protected function _construct() - { - $this->_init('sales/recurring_profile'); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report.php b/app/code/core/Mage/Sales/Model/Mysql4/Report.php index 334bc67cd3..6af0b31716 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report.php @@ -20,25 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Report extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - {} - /** - * Set main table and idField - * - * @param string $table - * @param string $field - * @return Mage_Sales_Model_Mysql4_Report - */ - public function init($table, $field = 'id') - { - $this->_init($table, $field); - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Report extends Mage_Sales_Model_Resource_Report +{ } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Abstract.php index 5e94279086..34858bb550 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Abstract.php @@ -20,19 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Order report resource model * - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -abstract class Mage_Sales_Model_Mysql4_Report_Abstract extends Mage_Reports_Model_Mysql4_Report_Abstract +class Mage_Sales_Model_Mysql4_Report_Abstract extends Mage_Sales_Model_Resource_Report_Abstract { - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers.php index 78e81e2ff9..2806f0d7a3 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers.php @@ -20,234 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Bestsellers report resource model * - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Report_Bestsellers extends Mage_Sales_Model_Mysql4_Report_Abstract +class Mage_Sales_Model_Mysql4_Report_Bestsellers extends Mage_Sales_Model_Resource_Report_Bestsellers { - const AGGREGATION_DAILY = 'daily'; - const AGGREGATION_MONTHLY = 'monthly'; - const AGGREGATION_YEARLY = 'yearly'; - - protected function _construct() - { - $this->_init('sales/bestsellers_aggregated_' . self::AGGREGATION_DAILY, 'id'); - } - - /** - * Aggregate Orders data by order created at - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Order - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - //$this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect( - $this->getTable('sales/order'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(source_table.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'source_table.store_id', - 'product_id' => 'order_item.product_id', - 'product_name' => 'IFNULL(product_name.value, product_default_name.value)', - 'product_price' => 'IFNULL(product_price.value, product_default_price.value) * IFNULL(source_table.base_to_global_rate, 0)', - 'qty_ordered' => 'SUM(order_item.qty_ordered)', - ); - - $select = $this->_getWriteAdapter()->select(); - - $select->from(array('source_table' => $this->getTable('sales/order')), $columns) - ->joinInner( - array('order_item' => $this->getTable('sales/order_item')), - 'order_item.order_id = source_table.entity_id', - array() - ) - ->where('source_table.state <> ?', Mage_Sales_Model_Order::STATE_CANCELED); - - - /** @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product $product */ - $product = Mage::getResourceSingleton('catalog/product'); - - $productTypes = array( - Mage_Catalog_Model_Product_Type::TYPE_GROUPED, - Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, - Mage_Catalog_Model_Product_Type::TYPE_BUNDLE, - ); - $select->joinInner( - array('product' => $this->getTable('catalog/product')), - 'product.entity_id = order_item.product_id' - . ' AND product.entity_type_id = ' . $product->getTypeId() - . " AND product.type_id NOT IN('" . implode("', '", $productTypes) . "')", - array() - ); - - // join product attributes Name & Price - $attr = $product->getAttribute('name'); - $select->joinLeft(array('product_name' => $attr->getBackend()->getTable()), - 'product_name.entity_id = product.entity_id' - . ' AND product_name.store_id = source_table.store_id' - . ' AND product_name.entity_type_id = ' . $product->getTypeId() - . ' AND product_name.attribute_id = ' . $attr->getAttributeId(), - array()) - ->joinLeft(array('product_default_name' => $attr->getBackend()->getTable()), - 'product_default_name.entity_id = product.entity_id' - . ' AND product_default_name.store_id = 0' - . ' AND product_default_name.entity_type_id = ' . $product->getTypeId() - . ' AND product_default_name.attribute_id = ' . $attr->getAttributeId(), - array()); - - $attr = $product->getAttribute('price'); - $select->joinLeft(array('product_price' => $attr->getBackend()->getTable()), - 'product_price.entity_id = product.entity_id' - . ' AND product_price.store_id = source_table.store_id' - . ' AND product_price.entity_type_id = ' . $product->getTypeId() - . ' AND product_price.attribute_id = ' . $attr->getAttributeId(), - array()) - ->joinLeft(array('product_default_price' => $attr->getBackend()->getTable()), - 'product_default_price.entity_id = product.entity_id' - . ' AND product_default_price.store_id = 0' - . ' AND product_default_price.entity_type_id = ' . $product->getTypeId() - . ' AND product_default_price.attribute_id = ' . $attr->getAttributeId(), - array()); - - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); - } - - $select->group(new Zend_Db_Expr('1,2,3')); - - $select->useStraightJoin(); // important! - $sql = $select->insertFromSelect($this->getMainTable(), array_keys($columns)); - $this->_getWriteAdapter()->query($sql); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'product_id' => 'product_id', - 'product_name' => 'product_name', - 'product_price' => 'product_price', - 'qty_ordered' => 'SUM(qty_ordered)', - ); - - $select->reset(); - $select->from($this->getMainTable(), $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'product_id' - )); - - $sql = $select->insertFromSelect($this->getMainTable(), array_keys($columns)); - $this->_getWriteAdapter()->query($sql); - - - // update rating - $this->_updateRatingPos(self::AGGREGATION_DAILY); - $this->_updateRatingPos(self::AGGREGATION_MONTHLY); - $this->_updateRatingPos(self::AGGREGATION_YEARLY); - - - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_BESTSELLERS_FLAG_CODE); - } catch (Exception $e) { - //$this->_getWriteAdapter()->rollBack(); - throw $e; - } - - //$this->_getWriteAdapter()->commit(); - return $this; - } - - /** - * Update rating position - * - * @param string $aggregation One of Mage_Sales_Model_Mysql4_Report_Bestsellers::AGGREGATION_XXX constants - * @return Mage_Sales_Model_Mysql4_Report_Bestsellers - */ - protected function _updateRatingPos($aggregation) - { - $aggregationTable = $this->getTable('sales/bestsellers_aggregated_' . $aggregation); - - $periodSubSelect = $this->_getWriteAdapter()->select(); - $ratingSubSelect = $this->_getWriteAdapter()->select(); - $ratingSelect = $this->_getWriteAdapter()->select(); - - $periodCol = 't.period'; - if ($aggregation == self::AGGREGATION_MONTHLY) { - $periodCol = "DATE_FORMAT(t.period, '%Y-%m-01')"; - } else if ($aggregation == self::AGGREGATION_YEARLY) { - $periodCol = "DATE_FORMAT(t.period, '%Y-01-01')"; - } - - $columns = array( - 'period' => 't.period', - 'store_id' => 't.store_id', - 'product_id' => 't.product_id', - 'product_name' => 't.product_name', - 'product_price' => 't.product_price', - ); - - if ($aggregation == self::AGGREGATION_DAILY) { - $columns['id'] = 't.id'; // to speed-up insert on duplicate key update - } - - $cols = array_keys($columns); - $cols[] = new Zend_Db_Expr('SUM(t.`qty_ordered`) AS `total_qty_ordered`'); - $periodSubSelect->from(array('t' => $this->getMainTable()), $cols) - ->group(array('t.store_id', $periodCol, 't.product_id')) - ->order(array('t.store_id', $periodCol, 'total_qty_ordered DESC')); - - $cols = $columns; - $cols['qty_ordered'] = 't.total_qty_ordered'; - $cols['rating_pos'] = new Zend_Db_Expr("(@pos := IF(t.`store_id` <> @prevStoreId OR {$periodCol} <> @prevPeriod, 1, @pos+1))"); - $cols['prevStoreId'] = new Zend_Db_Expr('(@prevStoreId := t.`store_id`)'); - $cols['prevPeriod'] = new Zend_Db_Expr("(@prevPeriod := {$periodCol})"); - $ratingSubSelect->from($periodSubSelect, $cols); - - $cols = $columns; - $cols['period'] = $periodCol; // important! - $cols['qty_ordered'] = 't.qty_ordered'; - $cols['rating_pos'] = 't.rating_pos'; - $ratingSelect->from($ratingSubSelect, $cols); - - $sql = $ratingSelect->insertFromSelect($aggregationTable, array_keys($cols)); - - $this->_getWriteAdapter()->query("SET @pos = 0, @prevStoreId = -1, @prevPeriod = '0000-00-00'"); - $this->_getWriteAdapter()->query($sql); - - return $this; - } } - diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers/Collection.php index aaff553852..7b5f9251bc 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers/Collection.php @@ -20,319 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report bestsellers collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Bestsellers_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Bestsellers_Collection + extends Mage_Sales_Model_Resource_Report_Bestsellers_Collection { - /** - * @var int - */ - protected $_ratingLimit = 5; - - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/bestsellers_aggregated_daily'); - $this->setConnection($this->getResource()->getReadConnection()); - // overwrite default behaviour - $this->_applyFilters = false; - } - - protected function _getSelectedColumns() - { - if (!$this->_selectedColumns) { - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } else { - $this->_selectedColumns = array( - 'period' => 'period', - 'qty_ordered' => 'qty_ordered', - 'product_id' => 'product_id', - 'product_name' => 'product_name', - 'product_price' => 'product_price', - ); - if ('year' == $this->_period) { - $this->_selectedColumns['period'] = 'YEAR(period)'; - } else if ('month' == $this->_period) { - $this->_selectedColumns['period'] = "DATE_FORMAT(period, '%Y-%m')"; - } - } - } - return $this->_selectedColumns; - } - - /** - * Make select object for date boundary - * - * @param mixed $from - * @param mixed $to - * @return Zend_Db_Select - */ - protected function _makeBoundarySelect($from, $to) - { - $cols = $this->_getSelectedColumns(); - $cols['qty_ordered'] = 'SUM(qty_ordered)'; - $sel = $this->getConnection()->select() - ->from($this->getResource()->getMainTable(), $cols) - ->where('period >= ?', $from) - ->where('period <= ?', $to) - ->group('product_id') - ->order('qty_ordered DESC') - ->limit($this->_ratingLimit); - $this->_applyStoresFilterToSelect($sel); - return $sel; - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Order_Collection - */ - protected function _initSelect() - { - $select = $this->getSelect(); - - // if grouping by product, not by period - if (!$this->_period) { - $cols = $this->_getSelectedColumns(); - $cols['qty_ordered'] = 'SUM(qty_ordered)'; - if ($this->_from || $this->_to) { - $select->from($this->getTable('sales/bestsellers_aggregated_daily'), $cols); - } else { - $select->from($this->getTable('sales/bestsellers_aggregated_yearly'), $cols); - } - $select - ->group('product_id') - ->order('qty_ordered DESC') - ->limit($this->_ratingLimit); - - return $this; - } - - - if ('year' == $this->_period) { - $select->from($this->getTable('sales/bestsellers_aggregated_yearly'), $this->_getSelectedColumns()); - } else if ('month' == $this->_period) { - $select->from($this->getTable('sales/bestsellers_aggregated_monthly'), $this->_getSelectedColumns()); - } else { - $select->from($this->getTable('sales/bestsellers_aggregated_daily'), $this->_getSelectedColumns()); - } - if (!$this->isTotals()) { - $select->group(array('period', 'product_id')); - } - $select->where('rating_pos <= ?', $this->_ratingLimit); - - return $this; - } - - /** - * Get SQL for get record count - * - * @return Varien_Db_Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - return $this->getConnection()->select()->from($this->getSelect(), 'COUNT(*)'); - } - - /** - * Set ids for store restrictions - * - * @param array $storeIds - * @return Mage_Sales_Model_Mysql4_Report_Bestsellers_Collection - */ - public function addStoreRestrictions($storeIds) - { - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - $currentStoreIds = $this->_storesIds; - if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID - && $currentStoreIds != array(Mage_Core_Model_App::ADMIN_STORE_ID)) { - if (!is_array($currentStoreIds)) { - $currentStoreIds = array($currentStoreIds); - } - $this->_storesIds = array_intersect($currentStoreIds, $storeIds); - } else { - $this->_storesIds = $storeIds; - } - - return $this; - } - - /** - * Redeclare parent method for applying filters after parent method - * but before adding unions and calculating totals - * - * @return Mage_Sales_Model_Mysql4_Report_Bestsellers_Collection - */ - protected function _beforeLoad() - { - parent::_beforeLoad(); - - $this->_applyStoresFilter(); - $this->_applyDateRangeFilter(); - - if ($this->_period) { - // - $selectUnions = array(); - - // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; - $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); - $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); - if ('year' == $this->_period) { - - if ($periodFrom) { - // not the first day of the year - if ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the year - $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // first day of the next year - $this->_from = $periodFrom->getDate() - ->addYear(1) - ->setMonth(1) - ->setDay(1) - ->toString($dtFormat); - } - } - } - - if ($periodTo) { - // not the last day of the year - if ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31) { - $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); // first day of the year - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // last day of the previous year - $this->_to = $periodTo->getDate() - ->subYear(1) - ->setMonth(12) - ->setDay(31) - ->toString($dtFormat); - } - } - } - - if ($periodFrom && $periodTo) { - // the same year - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - $this->getSelect()->where('1<>1'); - } - } - - } - else if ('month' == $this->_period) { - - if ($periodFrom) { - // not the first day of the month - if ($periodFrom->toValue(Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the month - $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // first day of the next month - $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); - } - } - } - - if ($periodTo) { - // not the last day of the month - if ($periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { - $dtFrom = $periodTo->getDate()->setDay(1); // first day of the month - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // last day of the previous month - $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); - } - } - } - - if ($periodFrom && $periodTo) { - if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) - // the same month - && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH) - ) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - $this->getSelect()->where('1<>1'); - } - } - - } - - // add unions to select - if ($selectUnions) { - $unionParts = array(); - $cloneSelect = clone $this->getSelect(); - $unionParts[] = '(' . $cloneSelect . ')'; - foreach ($selectUnions as $union) { - $unionParts[] = '(' . $union . ')'; - } - $this->getSelect()->reset()->union($unionParts, Zend_Db_Select::SQL_UNION_ALL); - } - - if ($this->isTotals()) { - // calculate total - $cloneSelect = clone $this->getSelect(); - $this->getSelect()->reset()->from($cloneSelect, $this->getAggregatedColumns()); - } else { - // add sorting - $this->getSelect()->order(array('period ASC', 'qty_ordered DESC')); - } - } - - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Collection/Abstract.php index 66a1ac52c3..054dc5c507 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Collection/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Collection/Abstract.php @@ -20,230 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Report_Collection_Abstract extends Mage_Core_Model_Mysql4_Collection_Abstract -{ - protected $_from = null; - protected $_to = null; - protected $_orderStatus = null; - protected $_period = null; - protected $_storesIds = 0; - protected $_applyFilters = true; - protected $_isTotals = false; - protected $_isSubTotals = false; - protected $_aggregatedColumns = array(); - - /** - * Set array of columns that should be aggregated - * - * @param array $columns - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function setAggregatedColumns(array $columns) - { - $this->_aggregatedColumns = $columns; - return $this; - } - - /** - * Retrieve array of columns that should be aggregated - * - * @return array - */ - public function getAggregatedColumns() - { - return $this->_aggregatedColumns; - } - - /** - * Set date range - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function setDateRange($from = null, $to = null) - { - $this->_from = $from; - $this->_to = $to; - return $this; - } - - /** - * Set period - * - * @param string $period - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function setPeriod($period) - { - $this->_period = $period; - return $this; - } - - /** - * Apply date range filter - * - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - protected function _applyDateRangeFilter() - { - if (!is_null($this->_from)) { - $this->getSelect()->where('period >= ?', $this->_from); - } - if (!is_null($this->_to)) { - $this->getSelect()->where('period <= ?', $this->_to); - } - return $this; - } - - /** - * Set store ids - * - * @param mixed $storeIds (null, int|string, array, array may contain null) - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function addStoreFilter($storeIds) - { - $this->_storesIds = $storeIds; - return $this; - } - - /** - * Apply stores filter to select object - * - * @param Zend_Db_Select $select - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - protected function _applyStoresFilterToSelect(Zend_Db_Select $select) - { - $nullCheck = false; - $storeIds = $this->_storesIds; - - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - - $storeIds = array_unique($storeIds); - - if ($index = array_search(null, $storeIds)) { - unset($storeIds[$index]); - $nullCheck = true; - } - - $storeIds[0] = ($storeIds[0] == '') ? 0 : $storeIds[0]; - - if ($nullCheck) { - $select->where('store_id IN(?) OR store_id IS NULL', $storeIds); - } else { - $select->where('store_id IN(?)', $storeIds); - } - return $this; - } - - /** - * Apply stores filter - * - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - protected function _applyStoresFilter() - { - return $this->_applyStoresFilterToSelect($this->getSelect()); - } - - /** - * Set status filter - * - * @param string|array $state - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function addOrderStatusFilter($orderStatus) - { - $this->_orderStatus = $orderStatus; - return $this; - } - - /** - * Apply order status filter - * - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - protected function _applyOrderStatusFilter() - { - if (is_null($this->_orderStatus)) { - return $this; - } - $orderStatus = $this->_orderStatus; - if (!is_array($orderStatus)) { - $orderStatus = array($orderStatus); - } - $this->getSelect()->where('order_status IN(?)', $orderStatus); - return $this; - } - - /** - * Set apply filters flag - * - * @param boolean $flag - * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function setApplyFilters($flag) - { - $this->_applyFilters = $flag; - return $this; - } - - /** - * Getter/Setter for isTotals - * - * @param null|boolean $flag - * @return boolean|Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function isTotals($flag = null) - { - if (is_null($flag)) { - return $this->_isTotals; - } - $this->_isTotals = $flag; - return $this; - } - - /** - * Getter/Setter for isSubTotals - * - * @param null|boolean $flag - * @return boolean|Mage_Sales_Model_Mysql4_Report_Collection_Abstract - */ - public function isSubTotals($flag = null) - { - if (is_null($flag)) { - return $this->_isSubTotals; - } - $this->_isSubTotals = $flag; - return $this; - } - - /** - * Load data - * Redeclare parent load method just for adding method _beforeLoad - * - * @return Varien_Data_Collection_Db - */ - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - $this->_initSelect(); - if ($this->_applyFilters) { - $this->_applyDateRangeFilter(); - $this->_applyStoresFilter(); - $this->_applyOrderStatusFilter(); - } - return parent::load($printQuery, $logQuery); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Report_Collection_Abstract extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced.php index 04dd1c087e..2a66513c1f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced.php @@ -20,229 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Report_Invoiced extends Mage_Sales_Model_Mysql4_Report_Abstract -{ - protected function _construct() - { - $this->_setResource('sales'); - } - - /** - * Aggregate Invoiced data - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Invoiced - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $this->_aggregateByOrderCreatedAt($from, $to); - $this->_aggregateByInvoiceCreatedAt($from, $to); - - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_INVOICE_FLAG_CODE); - return $this; - } - - /** - * Aggregate Invoiced data by invoice created_at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Invoiced - */ - protected function _aggregateByInvoiceCreatedAt($from, $to) - { - $table = $this->getTable('sales/invoiced_aggregated'); - $sourceTable = $this->getTable('sales/invoice'); - $orderTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeRelatedSelect( - $sourceTable, $orderTable, array('order_id'=>'entity_id'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(source_table.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'order_table.store_id', - 'order_status' => 'order_table.status', - 'orders_count' => 'COUNT(order_table.entity_id)', - 'orders_invoiced' => 'COUNT(order_table.entity_id)', - 'invoiced' => 'SUM(order_table.base_total_invoiced * order_table.base_to_global_rate)', - 'invoiced_captured' => 'SUM(order_table.base_total_paid * order_table.base_to_global_rate)', - 'invoiced_not_captured' => 'SUM((order_table.base_total_invoiced - order_table.base_total_paid) * order_table.base_to_global_rate)' - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from(array('source_table' => $sourceTable), $columns) - ->joinInner( - array('order_table' => $orderTable), - $this->_getWriteAdapter()->quoteInto( - 'source_table.order_id = order_table.entity_id AND order_table.state <> ?', - Mage_Sales_Model_Order::STATE_CANCELED), - array() - ); - - $filterSubSelect = $this->_getWriteAdapter()->select(); - $filterSubSelect->from(array('filter_source_table' => $sourceTable), 'MAX(filter_source_table.entity_id)') - ->where('filter_source_table.order_id = source_table.order_id'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); - } - - $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); - unset($filterSubSelect); - - $select->group(array( - 'period', - 'store_id', - 'order_status' - )); - - $select->having('orders_count > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'orders_count' => 'SUM(orders_count)', - 'orders_invoiced' => 'SUM(orders_invoiced)', - 'invoiced' => 'SUM(invoiced)', - 'invoiced_captured' => 'SUM(invoiced_captured)', - 'invoiced_not_captured' => 'SUM(invoiced_not_captured)' - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } - - /** - * Aggregate Invoiced data by order created_at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Invoiced - */ - protected function _aggregateByOrderCreatedAt($from, $to) - { - $table = $this->getTable('sales/invoiced_aggregated_order'); - $sourceTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - 'period' => "DATE(CONVERT_TZ(created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'store_id', - 'order_status' => 'status', - 'orders_count' => 'COUNT(`base_total_invoiced`)', - 'orders_invoiced' => 'SUM(IF(`base_total_invoiced` > 0, 1, 0))', - 'invoiced' => 'SUM(`base_total_invoiced` * `base_to_global_rate`)', - 'invoiced_captured' => 'SUM(`base_total_paid` * `base_to_global_rate`)', - 'invoiced_not_captured' => 'SUM((`base_total_invoiced` - `base_total_paid`) * `base_to_global_rate`)' - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from($sourceTable, $columns) - ->where('state <> ?', Mage_Sales_Model_Order::STATE_CANCELED); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); - } - - $select->group(array( - 'period', - 'store_id', - 'order_status' - )); - - $select->having('orders_count > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'orders_count' => 'SUM(orders_count)', - 'orders_invoiced' => 'SUM(orders_invoiced)', - 'invoiced' => 'SUM(invoiced)', - 'invoiced_captured' => 'SUM(invoiced_captured)', - 'invoiced_not_captured' => 'SUM(invoiced_not_captured)' - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } - +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Report_Invoiced extends Mage_Sales_Model_Resource_Report_Invoiced +{ } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Invoiced.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Invoiced.php index fea9c2662d..1376a21ff3 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Invoiced.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Invoiced.php @@ -20,29 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report invoiced collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Invoiced extends Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Order +class Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Invoiced + extends Mage_Sales_Model_Resource_Report_Invoiced_Collection_Invoiced { - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/invoiced_aggregated'); - $this->setConnection($this->getResource()->getReadConnection()); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Order.php index 654e188f32..9844ffbf9d 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Invoiced/Collection/Order.php @@ -20,75 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report invoiced collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Order extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Order + extends Mage_Sales_Model_Resource_Report_Invoiced_Collection_Order { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/invoiced_aggregated_order'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'orders_count' => 'SUM(orders_count)', - 'orders_invoiced' => 'SUM(orders_invoiced)', - 'invoiced' => 'SUM(invoiced)', - 'invoiced_captured' => 'SUM(invoiced_captured)', - 'invoiced_not_captured' => 'SUM(invoiced_not_captured)' - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - return $this->_selectedColumns; - - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Invoiced_Collection_Order - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); - if (!$this->isTotals()) { - $this->getSelect()->group($this->_periodFormat); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order.php index 2d789efa05..32f4e288f7 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order.php @@ -20,141 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Order entity resource model * - * @category Mage - * @package Mage_Sales + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Sales_Model_Mysql4_Report_Order extends Mage_Sales_Model_Mysql4_Report_Abstract +class Mage_Sales_Model_Mysql4_Report_Order extends Mage_Sales_Model_Resource_Report_Order { - protected function _construct() - { - $this->_init('sales/order_aggregated_created', 'id'); - } - - /** - * Aggregate Orders data by order created at - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Order - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect( - $this->getTable('sales/order'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(o.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'o.store_id', - 'order_status' => 'o.status', - 'orders_count' => 'COUNT(o.entity_id)', - 'total_qty_ordered' => 'SUM(oi.total_qty_ordered)', - 'total_qty_invoiced' => 'SUM(oi.total_qty_invoiced)', - 'total_income_amount' => 'SUM((o.base_grand_total - IFNULL(o.base_total_canceled, 0)) * o.base_to_global_rate)', - 'total_revenue_amount' => 'SUM((o.base_total_paid - IFNULL(o.base_total_refunded, 0)) * o.base_to_global_rate)', - 'total_profit_amount' => 'SUM((o.base_total_paid - IFNULL(o.base_total_refunded, 0) - IFNULL(o.base_tax_invoiced, 0) - IFNULL(o.base_shipping_invoiced, 0) - IFNULL(o.base_total_invoiced_cost, 0)) * o.base_to_global_rate)', - 'total_invoiced_amount' => 'SUM(o.base_total_invoiced * o.base_to_global_rate)', - 'total_canceled_amount' => 'SUM(o.base_total_canceled * o.base_to_global_rate)', - 'total_paid_amount' => 'SUM(o.base_total_paid * o.base_to_global_rate)', - 'total_refunded_amount' => 'SUM(o.base_total_refunded * o.base_to_global_rate)', - 'total_tax_amount' => 'SUM((o.base_tax_amount - IFNULL(o.base_tax_canceled, 0)) * o.base_to_global_rate)', - 'total_tax_amount_actual' => 'SUM((o.base_tax_invoiced - IFNULL(o.base_tax_refunded, 0)) * o.base_to_global_rate)', - 'total_shipping_amount' => 'SUM((o.base_shipping_amount - IFNULL(o.base_shipping_canceled, 0)) * o.base_to_global_rate)', - 'total_shipping_amount_actual' => 'SUM((o.base_shipping_invoiced - IFNULL(o.base_shipping_refunded, 0)) * o.base_to_global_rate)', - 'total_discount_amount' => 'SUM((ABS(o.base_discount_amount) - IFNULL(o.base_discount_canceled, 0)) * o.base_to_global_rate)', - 'total_discount_amount_actual' => 'SUM((o.base_discount_invoiced - IFNULL(o.base_discount_refunded, 0)) * o.base_to_global_rate)', - ); - - $select = $this->_getWriteAdapter()->select(); - $selectOrderItem = $this->_getWriteAdapter()->select(); - - $cols = array( - 'order_id' => 'order_id', - 'total_qty_ordered' => 'SUM(qty_ordered - IFNULL(qty_canceled, 0))', - 'total_qty_invoiced' => 'SUM(qty_invoiced)', - ); - $selectOrderItem->from($this->getTable('sales/order_item'), $cols) - ->where('parent_item_id IS NULL') - ->group('order_id'); - if ($subSelect !== null) { - //$selectOrderItem->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); - } - - $select->from(array('o' => $this->getTable('sales/order')), $columns) - ->join(array('oi' => $selectOrderItem), 'oi.order_id = o.entity_id', array()) - ->where('o.state NOT IN (?)', array( - Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, - Mage_Sales_Model_Order::STATE_NEW - )); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'o.created_at')); - } - - $select->group(array( - 'period', - 'store_id', - 'order_status', - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); - - // setup all columns to select SUM() except period, store_id and order_status - foreach ($columns as $k => $v) { - $columns[$k] = 'SUM(' . $k . ')'; - } - $columns['period'] = 'period'; - $columns['store_id'] = new Zend_Db_Expr('0'); - $columns['order_status'] = 'order_status'; - - $select->reset(); - $select->from($this->getMainTable(), $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); - - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } } - diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Collection.php index f8d0716f82..ceb259ad5d 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Collection.php @@ -20,83 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report order collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Order_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Order_Collection extends Mage_Sales_Model_Resource_Report_Order_Collection { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order_aggregated_created'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'orders_count' => 'SUM(orders_count)', - 'total_qty_ordered' => 'SUM(total_qty_ordered)', - 'total_qty_invoiced' => 'SUM(total_qty_invoiced)', - 'total_income_amount' => 'SUM(total_income_amount)', - 'total_revenue_amount' => 'SUM(total_revenue_amount)', - 'total_profit_amount' => 'SUM(total_profit_amount)', - 'total_invoiced_amount' => 'SUM(total_invoiced_amount)', - 'total_canceled_amount' => 'SUM(total_canceled_amount)', - 'total_paid_amount' => 'SUM(total_paid_amount)', - 'total_refunded_amount' => 'SUM(total_refunded_amount)', - 'total_tax_amount' => 'SUM(total_tax_amount)', - 'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)', - 'total_shipping_amount' => 'SUM(total_shipping_amount)', - 'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)', - 'total_discount_amount' => 'SUM(total_discount_amount)', - 'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)', - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Order_Collection - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns()); - if (!$this->isTotals()) { - $this->getSelect()->group($this->_periodFormat); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Updatedat/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Updatedat/Collection.php index 6f300b276d..cb9ffda157 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Updatedat/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Order/Updatedat/Collection.php @@ -20,188 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Report order updated_at collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection + extends Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection { - - protected $_periodFormat; - protected $_inited = false; - protected $_selectedColumns = array( - 'orders_count' => 'COUNT(e.entity_id)', - 'total_qty_ordered' => 'IFNULL(SUM(oi.total_qty_ordered), 0)', - 'total_qty_invoiced' => 'IFNULL(SUM(oi.total_qty_invoiced), 0)', - 'total_income_amount' => 'IFNULL(SUM((e.base_grand_total - IFNULL(e.base_total_canceled, 0)) * e.base_to_global_rate), 0)', - 'total_revenue_amount' => 'IFNULL(SUM((e.base_total_paid - IFNULL(e.base_total_refunded, 0)) * e.base_to_global_rate), 0)', - 'total_profit_amount' => 'IFNULL(SUM((e.base_total_paid - IFNULL(e.base_total_refunded, 0) - IFNULL(e.base_tax_invoiced, 0) - IFNULL(e.base_shipping_invoiced, 0) - IFNULL(e.base_total_invoiced_cost, 0)) * e.base_to_global_rate), 0)', - 'total_invoiced_amount' => 'IFNULL(SUM(e.base_total_invoiced * e.base_to_global_rate), 0)', - 'total_canceled_amount' => 'IFNULL(SUM(e.base_total_canceled * e.base_to_global_rate), 0)', - 'total_paid_amount' => 'IFNULL(SUM(e.base_total_paid * e.base_to_global_rate), 0)', - 'total_refunded_amount' => 'IFNULL(SUM(e.base_total_refunded * e.base_to_global_rate), 0)', - 'total_tax_amount' => 'IFNULL(SUM((e.base_tax_amount - IFNULL(e.base_tax_canceled, 0)) * e.base_to_global_rate), 0)', - 'total_tax_amount_actual' => 'IFNULL(SUM((e.base_tax_invoiced - IFNULL(e.base_tax_refunded, 0)) * e.base_to_global_rate), 0)', - 'total_shipping_amount' => 'IFNULL(SUM((e.base_shipping_amount - IFNULL(e.base_shipping_canceled, 0)) * e.base_to_global_rate), 0)', - 'total_shipping_amount_actual' => 'IFNULL(SUM((e.base_shipping_invoiced - IFNULL(e.base_shipping_refunded, 0)) * e.base_to_global_rate), 0)', - 'total_discount_amount' => 'IFNULL(SUM((ABS(e.base_discount_amount) - IFNULL(e.base_discount_canceled, 0)) * e.base_to_global_rate), 0)', - 'total_discount_amount_actual' => 'IFNULL(SUM((e.base_discount_invoiced - IFNULL(e.base_discount_refunded, 0)) * e.base_to_global_rate), 0)', - ); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order', 'entity_id'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - /** - * Apply stores filter - * - * @return Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection - */ - protected function _applyStoresFilter() - { - $nullCheck = false; - $storeIds = $this->_storesIds; - - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - - $storeIds = array_unique($storeIds); - - if ($index = array_search(null, $storeIds)) { - unset($storeIds[$index]); - $nullCheck = true; - } - - if ($nullCheck) { - $this->getSelect()->where('store_id IN(?) OR store_id IS NULL', $storeIds); - } elseif ($storeIds[0] != '') { - $this->getSelect()->where('store_id IN(?)', $storeIds); - } - - return $this; - } - - /** - * Apply order status filter - * - * @return Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection - */ - protected function _applyOrderStatusFilter() - { - if (is_null($this->_orderStatus)) { - return $this; - } - $orderStatus = $this->_orderStatus; - if (!is_array($orderStatus)) { - $orderStatus = array($orderStatus); - } - $this->getSelect()->where('status IN(?)', $orderStatus); - return $this; - } - - /** - * Retrieve array of columns to select - * - * @return array - */ - protected function _getSelectedColumns() - { - if (!$this->isTotals()) { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(e.updated_at, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM e.updated_at)'; - } else { - $this->_periodFormat = 'DATE(e.updated_at)'; - } - $this->_selectedColumns += array('period' => $this->_periodFormat); - } - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection - */ - protected function _initSelect() - { - if ($this->_inited) { - return $this; - } - - $columns = $this->_getSelectedColumns(); - - $mainTable = $this->getResource()->getMainTable(); - - $selectOrderItem = $this->getConnection()->select() - ->from($this->getTable('sales/order_item'), array( - 'order_id' => 'order_id', - 'total_qty_ordered' => 'SUM(qty_ordered - IFNULL(qty_canceled, 0))', - 'total_qty_invoiced' => 'SUM(qty_invoiced)', - )) - ->where('parent_item_id IS NULL') - ->group('order_id'); - - $select = $this->getSelect() - ->from(array('e' => $mainTable), $columns) - ->join(array('oi' => $selectOrderItem), 'oi.order_id = e.entity_id', array()) - ->where('e.state NOT IN (?)', array( - Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, - Mage_Sales_Model_Order::STATE_NEW - )); - - $this->_applyStoresFilter(); - $this->_applyOrderStatusFilter(); - - if ($this->_to !== null) { - $select->where('DATE(e.updated_at) <= DATE(?)', $this->_to); - } - - if ($this->_from !== null) { - $select->where('DATE(e.updated_at) >= DATE(?)', $this->_from); - } - - if (!$this->isTotals()) { - $select->group($this->_periodFormat); - } - - $this->_inited = true; - return $this; - } - - /** - * Load - * - * @param boolean $printQuery - * @param boolean $logQuery - * @return Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - $this->_initSelect(); - $this->setApplyFilters(false); - return parent::load($printQuery, $logQuery); - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded.php index c8cd430df6..757cc6c41f 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded.php @@ -20,224 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Report_Refunded extends Mage_Sales_Model_Mysql4_Report_Abstract -{ - protected function _construct() - { - $this->_setResource('sales'); - } - - /** - * Aggregate Refunded data - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Refunded - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $this->_aggregateByOrderCreatedAt($from, $to); - $this->_aggregateByRefundCreatedAt($from, $to); - - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_REFUNDED_FLAG_CODE); - return $this; - } - - /** - * Aggregate refunded data by order created at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Refunded - */ - protected function _aggregateByOrderCreatedAt($from, $to) - { - $table = $this->getTable('sales/refunded_aggregated_order'); - $sourceTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'store_id', - 'order_status' => 'status', - 'orders_count' => 'COUNT(`total_refunded`)', - 'refunded' => 'SUM(`base_total_refunded` * `base_to_global_rate`)', - 'online_refunded' => 'SUM(`base_total_online_refunded` * `base_to_global_rate`)', - 'offline_refunded' => 'SUM(`base_total_offline_refunded` * `base_to_global_rate`)' - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from($sourceTable, $columns) - ->where('state <> ?', Mage_Sales_Model_Order::STATE_CANCELED) - ->where('base_total_refunded > 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); - } - - $select->group(array( - 'period', - 'store_id', - 'order_status' - )); - - $select->having('orders_count > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'orders_count' => 'SUM(orders_count)', - 'refunded' => 'SUM(refunded)', - 'online_refunded' => 'SUM(online_refunded)', - 'offline_refunded' => 'SUM(offline_refunded)' - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } - - /** - * Aggregate refunded data by creaditmemo created at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Refunded - */ - protected function _aggregateByRefundCreatedAt($from, $to) - { - $table = $this->getTable('sales/refunded_aggregated'); - $sourceTable = $this->getTable('sales/creditmemo'); - $orderTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeRelatedSelect( - $sourceTable, $orderTable, array('order_id'=>'entity_id'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(source_table.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'order_table.store_id', - 'order_status' => 'order_table.status', - 'orders_count' => 'COUNT(order_table.`entity_id`)', - 'refunded' => 'SUM(order_table.`base_total_refunded` * order_table.`base_to_global_rate`)', - 'online_refunded' => 'SUM(order_table.`base_total_online_refunded` * order_table.`base_to_global_rate`)', - 'offline_refunded' => 'SUM(order_table.`base_total_offline_refunded` * order_table.`base_to_global_rate`)' - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from(array('source_table' => $sourceTable), $columns) - ->joinInner( - array('order_table' => $orderTable), - $this->_getWriteAdapter()->quoteInto( - 'source_table.order_id = order_table.entity_id AND order_table.state <> ? AND order_table.base_total_refunded > 0', - Mage_Sales_Model_Order::STATE_CANCELED), - array() - ); - - $filterSubSelect = $this->_getWriteAdapter()->select(); - $filterSubSelect->from(array('filter_source_table' => $sourceTable), 'MAX(filter_source_table.entity_id)') - ->where('filter_source_table.order_id = source_table.order_id'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); - } - - $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); - unset($filterSubSelect); - - $select->group(array( - 'period', - 'store_id', - 'order_status' - )); - - $select->having('orders_count > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'orders_count' => 'SUM(orders_count)', - 'refunded' => 'SUM(refunded)', - 'online_refunded' => 'SUM(online_refunded)', - 'offline_refunded' => 'SUM(offline_refunded)' - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - $this->_getWriteAdapter()->commit(); - return $this; - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Report_Refunded extends Mage_Sales_Model_Resource_Report_Refunded +{ } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Order.php index 6efcd69fed..032d0e9180 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Order.php @@ -20,74 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report refunded collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Order extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Order + extends Mage_Sales_Model_Resource_Report_Refunded_Collection_Order { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/refunded_aggregated_order'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'orders_count' => 'SUM(orders_count)', - 'refunded' => 'SUM(refunded)', - 'online_refunded' => 'SUM(online_refunded)', - 'offline_refunded' => 'SUM(offline_refunded)' - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - return $this->_selectedColumns; - - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Order - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); - if (!$this->isTotals()) { - $this->getSelect()->group($this->_periodFormat); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Refunded.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Refunded.php index 48f94bd58e..c76a854142 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Refunded.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Refunded/Collection/Refunded.php @@ -20,23 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report refunded collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Refunded extends Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Order +class Mage_Sales_Model_Mysql4_Report_Refunded_Collection_Refunded + extends Mage_Sales_Model_Resource_Report_Refunded_Collection_Refunded { - public function __construct() - { - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/refunded_aggregated'); - $this->setConnection($this->getResource()->getReadConnection()); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping.php index 91bb16a547..2f41d639ce 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping.php @@ -20,231 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Report_Shipping extends Mage_Sales_Model_Mysql4_Report_Abstract -{ - protected function _construct() - { - $this->_setResource('sales'); - } - - /** - * Aggregate Shipping data - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Shipping - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $this->_aggregateByOrderCreatedAt($from, $to); - $this->_aggregateByShippingCreatedAt($from, $to); - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_SHIPPING_FLAG_CODE); - return $this; - } - - /** - * Aggregate shipping report by order create_at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Shipping - */ - protected function _aggregateByOrderCreatedAt($from, $to) - { - $table = $this->getTable('sales/shipping_aggregated_order'); - $sourceTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'store_id', - 'order_status' => 'status', - 'shipping_description' => 'shipping_description', - 'orders_count' => 'COUNT(entity_id)', - 'total_shipping' => 'SUM((`base_shipping_amount` - IFNULL(`base_shipping_canceled`, 0)) * `base_to_global_rate`)', - 'total_shipping_actual' => 'SUM((`base_shipping_invoiced` - IFNULL(`base_shipping_refunded`, 0)) * `base_to_global_rate`)', - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from($sourceTable, $columns) - ->where('state NOT IN (?)', array( - Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, - Mage_Sales_Model_Order::STATE_NEW - )) - ->where('is_virtual = 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); - } - - $select->group(array( - 'period', - 'store_id', - 'order_status', - 'shipping_description' - )); - - $select->having('orders_count > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'shipping_description' => 'shipping_description', - 'orders_count' => 'SUM(orders_count)', - 'total_shipping' => 'SUM(total_shipping)', - 'total_shipping_actual' => 'SUM(total_shipping_actual)', - ); - - $select - ->from($table, $columns) - ->where("store_id <> 0"); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status', - 'shipping_description' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } - - /** - * Aggregate shipping report by shipment create_at as period - * - * @param mixed $from - * @param mixed $to - * @return Mage_Sales_Model_Mysql4_Report_Shipping - */ - protected function _aggregateByShippingCreatedAt($from, $to) - { - $table = $this->getTable('sales/shipping_aggregated'); - $sourceTable = $this->getTable('sales/invoice'); - $orderTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeRelatedSelect( - $sourceTable, $orderTable, array('order_id'=>'entity_id'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(source_table.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'order_table.store_id', - 'order_status' => 'order_table.status', - 'shipping_description' => 'order_table.shipping_description', - 'orders_count' => 'COUNT(order_table.entity_id)', - 'total_shipping' => 'SUM((order_table.`base_shipping_amount` - IFNULL(order_table.`base_shipping_canceled`, 0)) * order_table.`base_to_global_rate`)', - 'total_shipping_actual' => 'SUM((order_table.`base_shipping_invoiced` - IFNULL(order_table.`base_shipping_refunded`, 0)) * order_table.`base_to_global_rate`)', - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from(array('source_table' => $sourceTable), $columns) - ->joinInner( - array('order_table' => $orderTable), - $this->_getWriteAdapter()->quoteInto( - 'source_table.order_id = order_table.entity_id AND order_table.state <> ?', - Mage_Sales_Model_Order::STATE_CANCELED), - array() - ) - ->useStraightJoin(); - - $filterSubSelect = $this->_getWriteAdapter()->select(); - $filterSubSelect->from(array('filter_source_table' => $sourceTable), 'MIN(filter_source_table.entity_id)') - ->where('filter_source_table.order_id = source_table.order_id'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); - } - - $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); - unset($filterSubSelect); - - $select->group(array( - 'period', - 'store_id', - 'order_status', - 'shipping_description' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'shipping_description' => 'shipping_description', - 'orders_count' => 'SUM(orders_count)', - 'total_shipping' => 'SUM(total_shipping)', - 'total_shipping_actual' => 'SUM(total_shipping_actual)', - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status', - 'shipping_description' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Report_Shipping extends Mage_Sales_Model_Resource_Report_Shipping +{ } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Order.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Order.php index d4d893a22f..91b5a109af 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Order.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Order.php @@ -20,86 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report shipping collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Shipping_Collection_Order extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Sales_Model_Mysql4_Report_Shipping_Collection_Order + extends Mage_Sales_Model_Resource_Report_Shipping_Collection_Order { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/shipping_aggregated_order'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'shipping_description' => 'shipping_description', - 'orders_count' => 'sum(orders_count)', - 'total_shipping' => 'sum(total_shipping)', - 'total_shipping_actual' => 'sum(total_shipping_actual)', - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - if ($this->isSubTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat); - } - - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_Sales_Model_Mysql4_Report_Shipping_Collection - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); - - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->getSelect()->group(array( - $this->_periodFormat, - 'shipping_description' - )); - } - if ($this->isSubTotals()) { - $this->getSelect()->group(array( - $this->_periodFormat - )); - } - return $this; - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Shipment.php b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Shipment.php index 23f3a99028..96f7e5f989 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Report/Shipping/Collection/Shipment.php @@ -20,28 +20,19 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report shipping collection * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ -class Mage_Sales_Model_Mysql4_Report_Shipping_Collection_Shipment extends Mage_Sales_Model_Mysql4_Report_Shipping_Collection_Order +class Mage_Sales_Model_Mysql4_Report_Shipping_Collection_Shipment + extends Mage_Sales_Model_Resource_Report_Shipping_Collection_Shipment { - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/shipping_aggregated'); - $this->setConnection($this->getResource()->getReadConnection()); - } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Sale/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Sale/Collection.php index b6e67dd106..7e6bc87993 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Sale/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Sale/Collection.php @@ -20,258 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Sale_Collection extends Varien_Object implements IteratorAggregate +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Sale_Collection extends Mage_Sales_Model_Resource_Sale_Collection { - - /** - * Read connection - * - * @var Zend_Db_Adapter_Abstract - */ - protected $_read; - - /** - * Loaded collection items - * - * @var array - */ - protected $_items = array(); - - /** - * Totals data - * - * @var array - */ - protected $_totals = array('lifetime' => 0, 'base_lifetime' => 0, 'base_avgsale' => 0, 'num_orders' => 0); - - /** - * Entity attribute - * - * @var Mage_Sales_Model_Mysql4_Order - */ - protected $_resource; - - /** - * Collection's Zend_Db_Select object - * - * @var Zend_Db_Select - */ - protected $_select; - - /** - * Customer model - * - * @var Mage_Customer_Model_Customer - */ - protected $_customer; - - /** - * Order state value - * - * @var null|string|array - */ - protected $_orderStateValue = null; - - /** - * Order state condition - * - * @var string - */ - protected $_orderStateCondition = null; - - /** - * Set sales order entity and establish read connection - * - */ - public function __construct() - { - $this->_resource = Mage::getResourceSingleton('sales/order'); - $this->_read = $this->_resource->getReadConnection(); - } - - /** - * Set filter by customer - * - * @param Mage_Customer_Model_Customer $customer - * @return Mage_Sales_Model_Mysql4_Sale_Collection - */ - public function setCustomerFilter(Mage_Customer_Model_Customer $customer) - { - $this->_customer = $customer; - return $this; - } - - /** - * Add filter by stores - * - * @param array $storeIds - * @return Mage_Sales_Model_Mysql4_Sale_Collection - */ - public function addStoreFilter($storeIds) - { - $this->getSelect()->where('store_id IN (?)', $storeIds); - return $this; - } - - /** - * Set filter by order state - * - * @param string|array $state - * @return Mage_Sales_Model_Mysql4_Sale_Collection - */ - public function setOrderStateFilter($state, $exclude = false) - { - $this->_orderStateCondition = ($exclude) ? 'NOT IN' : 'IN'; - $this->_orderStateValue = (!is_array($state)) ? array($state) : $state; - return $this; - } - - /** - * Load data - * - * @param boolean $printQuery - * @param boolean $logQuery - * @return Mage_Sales_Model_Mysql4_Sale_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - $this->_select = $this->_read->select(); - $this->getSelect() - ->from(array('sales' => $this->_resource->getMainTable()), - array( - 'store_id', - 'lifetime' => 'sum(sales.base_grand_total)', - 'base_lifetime' => 'sum(sales.base_grand_total * sales.base_to_global_rate)', - 'avgsale' => 'avg(sales.base_grand_total)', - 'base_avgsale' => 'avg(sales.base_grand_total * sales.base_to_global_rate)', - 'num_orders' => 'count(sales.base_grand_total)' - ) - ) - ->group('sales.store_id') - ; - if ($this->_customer instanceof Mage_Customer_Model_Customer) { - $this->getSelect() - ->where('sales.customer_id=?', $this->_customer->getId()); - } - - if (!is_null($this->_orderStateValue)) { - $this->getSelect()->where('state ' . $this->_orderStateCondition . ' (?)', $this->_orderStateValue); - } - - Mage::dispatchEvent('sales_sale_collection_query_before', array('collection' => $this)); - - $this->printLogQuery($printQuery, $logQuery); - try { - $values = $this->_read->fetchAll($this->getSelect()->__toString()); - } catch (Exception $e) { - $this->printLogQuery(true, true, $this->getSelect()->__toString()); - throw $e; - } - $stores = Mage::getResourceModel('core/store_collection')->setWithoutDefaultFilter()->load()->toOptionHash(); - if (! empty($values)) { - foreach ($values as $v) { - $obj = new Varien_Object($v); - $storeName = isset($stores[$obj->getStoreId()]) ? $stores[$obj->getStoreId()] : null; - - $this->_items[ $v['store_id'] ] = $obj; - $this->_items[ $v['store_id'] ]->setStoreName($storeName); - $this->_items[ $v['store_id'] ]->setWebsiteId(Mage::app()->getStore($obj->getStoreId())->getWebsiteId()); - $this->_items[ $v['store_id'] ]->setAvgNormalized($obj->getAvgsale() * $obj->getNumOrders()); - foreach ($this->_totals as $key => $value) { - $this->_totals[$key] += $obj->getData($key); - } - } - if ($this->_totals['num_orders']) { - $this->_totals['avgsale'] = $this->_totals['base_lifetime'] / $this->_totals['num_orders']; - } - } - - return $this; - } - - /** - * Print and/or log query - * - * @param boolean $printQuery - * @param boolean $logQuery - * @param mixed $sql - * @return Mage_Sales_Model_Mysql4_Sale_Collection - */ - public function printLogQuery($printQuery = false, $logQuery = false, $sql = null) { - if ($printQuery) { - echo is_null($sql) ? $this->getSelect()->__toString() : $sql; - } - - if ($logQuery){ - Mage::log(is_null($sql) ? $this->getSelect()->__toString() : $sql); - } - return $this; - } - - /** - * Get zend db select instance - * - * @return Zend_Db_Select - */ - public function getSelect() - { - return $this->_select; - } - - /** - * Retrieve attribute entity by specified parameter - * - * @param int|string|object $attr - * @return Mage_Eav_Model_Entity_Attribute_Abstract - */ - public function getAttribute($attr) - { - return $this->_entity->getAttribute($attr); - } - - /** - * Retrieve currently used entity - * - * @return Mage_Eav_Model_Entity_Abstract - */ - public function getEntity() - { - return $this->_entity; - } - - /** - * Retrieve Iterator instance of items array - * - * @return ArrayIterator - */ - public function getIterator() - { - return new ArrayIterator($this->_items); - } - - /** - * Retrieve array of items - * - * @return array - */ - public function getItems() - { - return $this->_items; - } - - /** - * Retrieve totals data converted into Varien_Object - * - * @return Varien_Object - */ - public function getTotals() - { - return new Varien_Object($this->_totals); - } - } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Setup.php b/app/code/core/Mage/Sales/Model/Mysql4/Setup.php index c7fa987753..68619eda1c 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Setup.php @@ -20,935 +20,18 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Sales_Model_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ +class Mage_Sales_Model_Mysql4_Setup extends Mage_Sales_Model_Resource_Setup { - /** - * List of entities converted from EAV to flat data structure - * @var $_flatEntityTables array - */ - protected $_flatEntityTables = array( - 'quote' => 'sales_flat_quote', - 'quote_item' => 'sales_flat_quote_item', - 'quote_address' => 'sales_flat_quote_address', - 'quote_address_item'=> 'sales_flat_quote_address_item', - 'quote_address_rate'=> 'sales_flat_quote_shipping_rate', - 'quote_payment' => 'sales_flat_quote_payment', - 'order' => 'sales_flat_order', - 'order_payment' => 'sales_flat_order_payment', - 'order_item' => 'sales_flat_order_item', - 'order_address' => 'sales_flat_order_address', - 'order_status_history' => 'sales_flat_order_status_history', - 'invoice' => 'sales_flat_invoice', - 'invoice_item' => 'sales_flat_invoice_item', - 'invoice_comment' => 'sales_flat_invoice_comment', - 'creditmemo' => 'sales_flat_creditmemo', - 'creditmemo_item' => 'sales_flat_creditmemo_item', - 'creditmemo_comment'=> 'sales_flat_creditmemo_comment', - 'shipment' => 'sales_flat_shipment', - 'shipment_item' => 'sales_flat_shipment_item', - 'shipment_track' => 'sales_flat_shipment_track', - 'shipment_comment' => 'sales_flat_shipment_comment', - ); - - /** - * List of entities used with separate grid table - * @var $_flatEntitiesGrid array - */ - protected $_flatEntitiesGrid = array( - 'order', - 'invoice', - 'shipment', - 'creditmemo' - ); - - /** - * Check if table exist for flat entity - * - * @param string $table - * @return bool - */ - protected function _flatTableExist($table) - { - return $this->getConnection()->fetchOne("show tables like '{$this->getTable($table)}'"); - } - - /** - * Add entity attribute. Overwrited for flat entities support - * - * @param int|string $entityTypeId - * @param string $code - * @param array $attr - */ - public function addAttribute($entityTypeId, $code, array $attr) - { - if (isset($this->_flatEntityTables[$entityTypeId]) && $this->_flatTableExist($this->_flatEntityTables[$entityTypeId])) { - $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr); - $this->_addGridAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr, $entityTypeId); - } - else { - parent::addAttribute($entityTypeId, $code, $attr); - } - return $this; - } - - /** - * Add attribute as separate column in the table - * - * @param string $table - * @param string $attribute - * @param array $attr - */ - protected function _addFlatAttribute($table, $attribute, $attr) - { - $tableInfo = $this->getConnection()->describeTable($this->getTable($table)); - if (isset($tableInfo[$attribute])) { - return $this; - } - $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); - $this->getConnection()->addColumn($this->getTable($table), $attribute, $columnDefinition); - return $this; - } - - /** - * Add attribute to grid table if necessary - * @param string $table - * @param string $attribute - * @param array $attr - * @param string $entityTypeId - */ - protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId) - { - if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) { - $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); - $this->getConnection()->addColumn($this->getTable($table . '_grid'), $attribute, $columnDefinition); - } - return $this; - } - - protected function _getAttributeColumnDefinition($code, $data) - { - $columnDefinition = ''; - $type = isset($data['type']) ? $data['type'] : 'varchar'; - $req = isset($data['required']) ? $data['required'] : false; - - switch ($type) { - case 'int': - $columnDefinition = 'int(10) unsigned'; - break; - case 'decimal': - $columnDefinition = 'decimal(12,4)'; - break; - case 'text': - $columnDefinition = 'text'; - break; - case 'date': - $columnDefinition = 'datetime'; - break; - default: - $columnDefinition = 'varchar(255)'; - break; - } - - if ($req) { - $columnDefinition.= ' NOT NULL'; - } - return $columnDefinition; - } - - - public function getDefaultEntities() - { - return array( - 'quote'=>array( - 'entity_model' => 'sales/quote', - 'table' => 'sales/quote', - 'attributes' => array( - 'entity_id' => array('type'=>'static'), - 'is_active' => array('type'=>'static'), - 'store_id' => array('type'=>'static'), - 'remote_ip' => array('type'=>'static'), - 'checkout_method' => array('type'=>'static'), - 'password_hash' => array('type'=>'static'), - 'orig_order_id' => array('type'=>'static'), - 'converted_at' => array('type'=>'static'), - 'reserved_order_id' => array('type'=>'static'), - - 'coupon_code' => array('type'=>'static'), - 'global_currency_code' => array('type'=>'static'), - 'base_currency_code' => array('type'=>'static'), - 'store_currency_code' => array('type'=>'static'), - 'quote_currency_code' => array('type'=>'static'), - 'store_to_base_rate' => array('type'=>'static'), - 'store_to_quote_rate' => array('type'=>'static'), - 'base_to_global_rate' => array('type'=>'static'), - 'base_to_quote_rate' => array('type'=>'static'), - - 'items_count'=> array('type'=>'static'), - 'items_qty'=> array('type'=>'static'), - - 'grand_total' => array('type'=>'static'), - 'base_grand_total' => array('type'=>'static'), - - 'applied_rule_ids' => array('type'=>'static'), - - 'is_virtual' => array('type'=>'static'), - 'is_multi_shipping' => array('type'=>'static'), - - 'customer_id' => array('type'=>'static'), - 'customer_tax_class_id' => array('type'=>'static'), - 'customer_group_id' => array('type'=>'static'), - 'customer_email' => array('type'=>'static'), - 'customer_prefix' => array('type'=>'static'), - 'customer_firstname'=> array('type'=>'static'), - 'customer_middlename'=>array('type'=>'static'), - 'customer_lastname' => array('type'=>'static'), - 'customer_suffix' => array('type'=>'static'), - 'customer_note' => array('type'=>'static'), - 'customer_note_notify' => array('type'=>'static'), - 'customer_is_guest' => array('type'=>'static'), - 'customer_taxvat' => array('type'=>'static'), - 'customer_dob' => array('type'=>'static'), - 'customer_gender' => array('type'=>'static'), - ), - ), - - 'quote_item' => array( - 'entity_model' => 'sales/quote_item', - 'table' => 'sales/quote_item', - 'attributes' => array( - 'product_id' => array('type'=>'static'), - 'super_product_id' => array('type'=>'static'), - 'parent_product_id' => array('type'=>'static'), - 'sku' => array('type'=>'static'), - 'name' => array('type'=>'static'), - 'description' => array('type'=>'static'), - - 'weight' => array('type'=>'static'), - 'free_shipping' => array('type'=>'static'), - 'qty' => array('type'=>'static'), - 'is_qty_decimal'=> array('type'=>'static'), - - 'price' => array('type'=>'static'), - 'custom_price' => array('type'=>'static'), - 'discount_percent' => array('type'=>'static'), - 'discount_amount' => array('type'=>'static'), - 'no_discount' => array('type'=>'static'), - 'tax_percent' => array('type'=>'static'), - 'tax_amount' => array('type'=>'static'), - 'row_total' => array('type'=>'static'), - 'row_total_with_discount' => array('type'=>'static'), - - 'base_price' => array('type'=>'static'), - 'base_discount_amount' => array('type'=>'static'), - 'base_tax_amount' => array('type'=>'static'), - 'base_row_total' => array('type'=>'static'), - - 'row_weight' => array('type'=>'static'), - 'applied_rule_ids' => array('type'=>'static'), - 'additional_data' => array('type'=>'static'), - ), - ), - - 'quote_address' => array( - 'entity_model' => 'sales/quote_address', - 'table' => 'sales/quote_address', - 'attributes' => array( - 'address_type' => array('type'=>'static'), - - 'customer_id' => array('type'=>'static'), - 'customer_address_id' => array('type'=>'static'), - 'save_in_address_book' => array('type'=>'static'), - 'email' => array('type'=>'static'), - 'prefix' => array('type'=>'static'), - 'firstname' => array('type'=>'static'), - 'middlename'=> array('type'=>'static'), - 'lastname' => array('type'=>'static'), - 'suffix' => array('type'=>'static'), - 'company' => array('type'=>'static'), - 'street' => array('type'=>'static'), - 'city' => array('type'=>'static'), - 'region' => array('type'=>'static'), - 'region_id' => array('type'=>'static'), - 'postcode' => array('type'=>'static'), - 'country_id'=> array('type'=>'static'), - 'telephone' => array('type'=>'static'), - 'fax' => array('type'=>'static'), - - 'same_as_billing' => array('type'=>'static'), - 'free_shipping' => array('type'=>'static'), - 'weight' => array('type'=>'static'), - 'collect_shipping_rates' => array('type'=>'static'), - - 'shipping_method' => array('type'=>'static'), - 'shipping_description' => array('type'=>'static'), - - 'subtotal' => array('type'=>'static'), - 'subtotal_with_discount' => array('type'=>'static'), - 'tax_amount' => array('type'=>'static'), - 'shipping_amount' => array('type'=>'static'), - 'shipping_tax_amount' => array('type'=>'static'), - 'discount_amount' => array('type'=>'static'), - 'grand_total' => array('type'=>'static'), - - 'base_subtotal' => array('type'=>'static'), - 'base_subtotal_with_discount' => array('type'=>'static'), - 'base_tax_amount' => array('type'=>'static'), - 'base_shipping_amount' => array('type'=>'static'), - 'base_shipping_tax_amount' => array('type'=>'static'), - 'base_discount_amount' => array('type'=>'static'), - 'base_grand_total' => array('type'=>'static'), - - 'customer_notes' => array('type'=>'static'), - 'applied_taxes' => array('type'=>'text'), - ), - ), - 'quote_address_item' => array( - 'entity_model' => 'sales/quote_address_item', - 'table' =>'sales/quote_entity', - 'attributes' => array( - 'quote_item_id' => array('type'=>'int'), - 'product_id' => array('type'=>'int'), - 'super_product_id' => array('type'=>'int'), - 'parent_product_id' => array('type'=>'int'), - 'sku' => array(), - 'image' => array(), - 'name' => array(), - 'description' => array('type'=>'text'), - - 'weight' => array('type'=>'decimal'), - 'free_shipping' => array('type'=>'int'), - 'qty' => array('type'=>'decimal'), - 'is_qty_decimal'=> array('type'=>'int'), - - 'price' => array('type'=>'decimal'), - 'discount_percent' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'no_discount' => array('type'=>'int'), - 'tax_percent' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'row_total' => array('type'=>'decimal'), - 'row_total_with_discount' => array('type'=>'decimal'), - - 'base_price' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_row_total' => array('type'=>'decimal'), - - 'row_weight' => array('type'=>'decimal'), - 'applied_rule_ids' => array(), - 'additional_data' => array('type'=>'text'), - ), - ), - 'quote_address_rate' => array( - 'entity_model' => 'sales/quote_address_rate', - 'table' => 'sales/quote_entity', - 'attributes' => array( - 'code' => array(), - 'carrier' => array(), - 'carrier_title' => array(), - 'method' => array(), - 'method_description' => array('type'=>'text'), - 'price' => array('type'=>'decimal'), - 'error_message' => array('type'=>'text'), - ), - ), - 'quote_payment' => array( - 'entity_model' => 'sales/quote_payment', - 'table' =>'sales/quote_entity', - 'attributes' => array( - 'method' => array(), - 'additional_data' => array('type'=>'text'), - 'po_number' => array(), - 'cc_type' => array(), - 'cc_number_enc' => array(), - 'cc_last4' => array(), - 'cc_owner' => array(), - 'cc_exp_month' => array('type'=>'int'), - 'cc_exp_year' => array('type'=>'int'), - 'cc_cid_enc' => array(), - 'cc_ss_issue' => array(), - 'cc_ss_start_month' => array('type'=>'int'), - 'cc_ss_start_year' => array('type'=>'int'), - ), - ), - - 'order' => array( - 'entity_model' => 'sales/order', - 'table'=>'sales/order', - 'increment_model'=>'eav/entity_increment_numeric', - 'increment_per_store'=>true, - 'backend_prefix'=>'sales_entity/order_attribute_backend', - 'attributes' => array( - 'entity_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_attribute_backend_parent' - ), - 'store_id' => array('type'=>'static'), - 'store_name' => array('type'=>'varchar'), - 'remote_ip' => array(), - - 'status' => array('type'=>'varchar'), - 'state' => array('type'=>'varchar'), - 'hold_before_status' => array('type'=>'varchar'), - 'hold_before_state' => array('type'=>'varchar'), - - 'relation_parent_id' => array('type'=>'varchar'), - 'relation_parent_real_id' => array('type'=>'varchar'), - 'relation_child_id' => array('type'=>'varchar'), - 'relation_child_real_id' => array('type'=>'varchar'), - 'original_increment_id' => array('type'=>'varchar'), - 'edit_increment' => array('type'=>'int'), - - 'ext_order_id' => array('type'=>'varchar'), - 'ext_customer_id' => array('type'=>'varchar'), - - 'quote_id' => array('type'=>'int'), - 'quote_address_id' => array('type'=>'int'), - 'billing_address_id' => array('type'=>'int', 'backend'=>'_billing'), - 'shipping_address_id' => array('type'=>'int', 'backend'=>'_shipping'), - - 'coupon_code' => array(), - 'applied_rule_ids' => array(), - - 'global_currency_code' => array(), - 'base_currency_code' => array(), - 'store_currency_code' => array(), - 'order_currency_code' => array(), - 'store_to_base_rate' => array('type'=>'decimal'), - 'store_to_order_rate' => array('type'=>'decimal'), - 'base_to_global_rate' => array('type'=>'decimal'), - 'base_to_order_rate' => array('type'=>'decimal'), - - 'is_virtual' => array('type'=>'int'), - - 'shipping_method' => array(), - 'shipping_description' => array(), - 'weight' => array('type'=>'decimal'), - - 'tax_amount' => array('type'=>'static'), - 'shipping_amount' => array('type'=>'static'), - 'shipping_tax_amount' => array('type'=>'static'), - 'discount_amount' => array('type'=>'static'), - - 'subtotal' => array('type'=>'static'), - 'grand_total' => array('type'=>'static'), - 'total_paid' => array('type'=>'static'), - 'total_due' => array('type'=>'decimal'), - 'total_refunded' => array('type'=>'static'), - 'total_qty_ordered' => array('type'=>'static'), - 'total_canceled' => array('type'=>'static'), - 'total_invoiced' => array('type'=>'static'), - 'total_online_refunded' => array('type'=>'static'), - 'total_offline_refunded'=> array('type'=>'static'), - 'adjustment_positive' => array('type'=>'decimal'), - 'adjustment_negative' => array('type'=>'decimal'), - - 'base_tax_amount' => array('type'=>'static'), - 'base_shipping_amount' => array('type'=>'static'), - 'base_shipping_tax_amount' => array('type'=>'static'), - 'base_discount_amount' => array('type'=>'static'), - - 'base_subtotal' => array('type'=>'static'), - 'base_grand_total' => array('type'=>'static'), - 'base_total_paid' => array('type'=>'static'), - 'base_total_due' => array('type'=>'decimal'), - 'base_total_refunded' => array('type'=>'static'), - 'base_total_qty_ordered' => array('type'=>'static'), - 'base_total_canceled' => array('type'=>'static'), - 'base_total_invoiced' => array('type'=>'static'), - 'base_total_online_refunded' => array('type'=>'static'), - 'base_total_offline_refunded'=> array('type'=>'static'), - 'base_adjustment_positive' => array('type'=>'decimal'), - 'base_adjustment_negative' => array('type'=>'decimal'), - - 'subtotal_refunded' => array('type'=>'static'), - 'subtotal_canceled' => array('type'=>'static'), - 'discount_refunded' => array('type'=>'static'), - 'discount_canceled' => array('type'=>'static'), - 'discount_invoiced' => array('type'=>'static'), - 'subtotal_invoiced' => array('type'=>'static'), - 'tax_refunded' => array('type'=>'static'), - 'tax_canceled' => array('type'=>'static'), - 'tax_invoiced' => array('type'=>'static'), - 'shipping_refunded' => array('type'=>'static'), - 'shipping_canceled' => array('type'=>'static'), - 'shipping_invoiced' => array('type'=>'static'), - 'base_subtotal_refunded' => array('type'=>'static'), - 'base_subtotal_canceled' => array('type'=>'static'), - 'base_discount_refunded' => array('type'=>'static'), - 'base_discount_canceled' => array('type'=>'static'), - 'base_discount_invoiced' => array('type'=>'static'), - 'base_subtotal_invoiced' => array('type'=>'static'), - 'base_tax_refunded' => array('type'=>'static'), - 'base_tax_canceled' => array('type'=>'static'), - 'base_tax_invoiced' => array('type'=>'static'), - 'base_shipping_refunded' => array('type'=>'static'), - 'base_shipping_canceled' => array('type'=>'static'), - 'base_shipping_invoiced' => array('type'=>'static'), - - 'protect_code' => array('type' => 'static'), - - 'customer_id' => array('type'=>'static', 'visible'=>false), - 'customer_group_id' => array('type'=>'int', 'visible'=>false), - 'customer_email' => array('type'=>'varchar', 'visible'=>false), - 'customer_prefix' => array('type'=>'varchar', 'visible'=>false), - 'customer_firstname'=> array('type'=>'varchar', 'visible'=>false), - 'customer_middlename' => array('type'=>'varchar', 'visible'=>false), - 'customer_lastname' => array('type'=>'varchar', 'visible'=>false), - 'customer_suffix' => array('type'=>'varchar', 'visible'=>false), - 'customer_note' => array('type'=>'text', 'visible'=>false), - 'customer_note_notify' => array('type'=>'int', 'visible'=>false), - 'customer_is_guest' => array('type'=>'int', 'visible'=>false), - 'email_sent' => array('type'=>'int', 'visible'=>false), - 'customer_taxvat' => array('type'=>'varchar', 'visible'=>false), - 'customer_dob' => array('type'=>'datetime', 'backend'=>'eav/entity_attribute_backend_datetime'), - 'customer_gender' => array('type'=>'int', 'visible'=>false), - ), - ), - 'order_address' => array( - 'entity_model' => 'sales/order_address', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array('type'=>'static', 'backend'=>'sales_entity/order_attribute_backend_child'), - 'quote_address_id' => array('type'=>'int'), - 'address_type' => array(), - 'customer_id' => array('type'=>'int'), - 'customer_address_id' => array('type'=>'int'), - 'email' => array(), - 'prefix' => array(), - 'firstname' => array(), - 'middlename'=> array(), - 'lastname' => array(), - 'suffix' => array(), - 'company' => array(), - 'street' => array(), - 'city' => array(), - 'region' => array(), - 'region_id' => array('type'=>'int'), - 'postcode' => array(), - 'country_id'=> array('type'=>'varchar'), - 'telephone' => array(), - 'fax' => array(), - - ), - ), - 'order_item' => array( - 'entity_model' => 'sales/order_item', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_attribute_backend_child' - ), - - 'quote_item_id' => array('type'=>'int'), - 'product_id' => array('type'=>'int'), - 'super_product_id' => array('type'=>'int'), - 'parent_product_id' => array('type'=>'int'), - 'is_virtual' => array('type'=>'int'), - 'sku' => array(), - 'name' => array(), - 'description' => array('type'=>'text'), - 'weight' => array('type'=>'decimal'), - - 'is_qty_decimal' => array('type'=>'int'), - 'qty_ordered' => array('type'=>'decimal'), - 'qty_backordered' => array('type'=>'decimal'), - 'qty_invoiced' => array('type'=>'decimal'), - 'qty_canceled' => array('type'=>'decimal'), - 'qty_shipped' => array('type'=>'decimal'), - 'qty_refunded' => array('type'=>'decimal'), - - 'original_price' => array('type'=>'decimal'), - 'price' => array('type'=>'decimal'), - 'cost' => array('type'=>'decimal'), - - 'discount_percent' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'discount_invoiced' => array('type'=>'decimal'), - - 'tax_percent' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'tax_invoiced' => array('type'=>'decimal'), - - 'row_total' => array('type'=>'decimal'), - 'row_weight' => array('type'=>'decimal'), - 'row_invoiced' => array('type'=>'decimal'), - 'invoiced_total' => array('type'=>'decimal'), - 'amount_refunded' => array('type'=>'decimal'), - - 'base_price' => array('type'=>'decimal'), - 'base_original_price' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_discount_invoiced' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_tax_invoiced' => array('type'=>'decimal'), - 'base_row_total' => array('type'=>'decimal'), - 'base_row_invoiced' => array('type'=>'decimal'), - 'base_invoiced_total' => array('type'=>'decimal'), - 'base_amount_refunded' => array('type'=>'decimal'), - - 'applied_rule_ids' => array(), - 'additional_data' => array('type'=>'text'), - ), - ), - 'order_payment' => array( - 'entity_model' => 'sales/order_payment', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_attribute_backend_child' - ), - 'quote_payment_id' => array('type'=>'int'), - 'method' => array(), - 'additional_data' => array('type'=>'text'), - 'last_trans_id' => array(), - 'po_number' => array(), - - 'cc_type' => array(), - 'cc_number_enc' => array(), - 'cc_last4' => array(), - 'cc_owner' => array(), - 'cc_exp_month' => array(), - 'cc_exp_year' => array(), - - 'cc_ss_issue' => array(), - 'cc_ss_start_month' => array(), - 'cc_ss_start_year' => array(), - - 'cc_status' => array(), - 'cc_status_description' => array(), - 'cc_trans_id' => array(), - 'cc_approval' => array(), - 'cc_avs_status' => array(), - 'cc_cid_status' => array(), - - 'cc_debug_request_body' => array(), - 'cc_debug_response_body'=> array(), - 'cc_debug_response_serialized' => array(), - - 'anet_trans_method' => array(), - 'echeck_routing_number' => array(), - 'echeck_bank_name' => array(), - 'echeck_account_type' => array(), - 'echeck_account_name' => array(), - 'echeck_type' => array(), - - 'amount_ordered' => array('type'=>'decimal'), - 'amount_authorized' => array('type'=>'decimal'), - 'amount_paid' => array('type'=>'decimal'), - 'amount_canceled' => array('type'=>'decimal'), - 'amount_refunded' => array('type'=>'decimal'), - 'shipping_amount' => array('type'=>'decimal'), - 'shipping_captured' => array('type'=>'decimal'), - 'shipping_refunded' => array('type'=>'decimal'), - - 'base_amount_ordered' => array('type'=>'decimal'), - 'base_amount_authorized' => array('type'=>'decimal'), - 'base_amount_paid' => array('type'=>'decimal'), - 'base_amount_paid_online' => array('type'=>'decimal'), - 'base_amount_canceled' => array('type'=>'decimal'), - 'base_amount_refunded' => array('type'=>'decimal'), - 'base_amount_refunded_online' => array('type'=>'decimal'), - 'base_shipping_amount' => array('type'=>'decimal'), - 'base_shipping_captured' => array('type'=>'decimal'), - 'base_shipping_refunded' => array('type'=>'decimal'), - ), - ), - - 'order_status_history' => array( - 'entity_model' => 'sales/order_status_history', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_attribute_backend_child' - ), - 'status' => array('type'=>'varchar'), - 'comment' => array('type'=>'text'), - 'is_customer_notified' => array('type'=>'int'), - ), - ), - - 'invoice' => array( - 'entity_model' => 'sales/order_invoice', - 'table' =>'sales/order_entity', - 'increment_model' =>'eav/entity_increment_numeric', - 'increment_per_store'=>true, - 'backend_prefix' =>'sales_entity/order_attribute_backend', - 'attributes' => array( - 'entity_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_invoice_attribute_backend_parent' - ), - - 'state' => array('type'=>'int'), - 'is_used_for_refund' => array('type'=>'int'), - 'transaction_id' => array(), - - - 'order_id' => array( - 'type'=>'int', - 'backend'=>'sales_entity/order_invoice_attribute_backend_order' - ), - - 'billing_address_id' => array('type'=>'int'), - 'shipping_address_id' => array('type'=>'int'), - - 'global_currency_code' => array(), - 'base_currency_code' => array(), - 'store_currency_code' => array(), - 'order_currency_code' => array(), - 'store_to_base_rate' => array('type'=>'decimal'), - 'store_to_order_rate' => array('type'=>'decimal'), - 'base_to_global_rate' => array('type'=>'decimal'), - 'base_to_order_rate' => array('type'=>'decimal'), - - 'subtotal' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'shipping_amount' => array('type'=>'decimal'), - 'grand_total' => array('type'=>'decimal'), - 'total_qty' => array('type'=>'decimal'), - - 'can_void_flag' => array('type'=>'int'), - - 'base_subtotal' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_shipping_amount' => array('type'=>'decimal'), - 'base_grand_total' => array('type'=>'decimal'), - 'email_sent' => array('type'=>'int'), - 'store_id' => array('type'=>'static'), - ), - ), - - 'invoice_item' => array( - 'entity_model' => 'sales/order_invoice_item', - //'table'=>'sales/invoice', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_invoice_attribute_backend_child' - ), - 'order_item_id' => array('type'=>'int'), - 'product_id' => array('type'=>'int'), - 'name' => array(), - 'description' => array('type'=>'text'), - 'sku' => array(), - 'qty' => array('type'=>'decimal'), - 'cost' => array('type'=>'decimal'), - 'price' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'row_total' => array('type'=>'decimal'), - - 'base_price' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_row_total' => array('type'=>'decimal'), - - 'additional_data' => array('type'=>'text'), - ), - ), - - 'invoice_comment' => array( - 'entity_model' => 'sales/order_invoice_comment', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_invoice_attribute_backend_child' - ), - 'comment' => array('type'=>'text'), - 'is_customer_notified' => array('type'=>'int'), - ), - ), - - - - 'shipment' => array( - 'entity_model' => 'sales/order_shipment', - //'table'=>'sales/shipment', - 'table'=>'sales/order_entity', - 'increment_model'=>'eav/entity_increment_numeric', - 'increment_per_store'=>true, - 'backend_prefix'=>'sales_entity/order_attribute_backend', - 'attributes' => array( - 'entity_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_shipment_attribute_backend_parent' - ), - - 'customer_id' => array('type'=>'int'), - 'order_id' => array('type'=>'int'), - 'shipment_status' => array('type'=>'int'), - 'billing_address_id' => array('type'=>'int'), - 'shipping_address_id' => array('type'=>'int'), - - 'total_qty' => array('type'=>'decimal'), - 'total_weight' => array('type'=>'decimal'), - 'email_sent' => array('type'=>'int'), - 'store_id' => array('type' => 'static'), - ), - ), - - 'shipment_item' => array( - 'entity_model' => 'sales/order_shipment_item', - //'table'=>'sales/shipment', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_shipment_attribute_backend_child' - ), - 'order_item_id' => array('type'=>'int'), - 'product_id' => array('type'=>'int'), - 'name' => array(), - 'description' => array('type'=>'text'), - 'sku' => array(), - 'qty' => array('type'=>'decimal'), - 'price' => array('type'=>'decimal'), - 'weight' => array('type'=>'decimal'), - 'row_total' => array('type'=>'decimal'), - - 'additional_data' => array('type'=>'text'), - ), - ), - - 'shipment_comment' => array( - 'entity_model' => 'sales/order_shipment_comment', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_shipment_attribute_backend_child' - ), - 'comment' => array('type'=>'text'), - 'is_customer_notified' => array('type'=>'int'), - ), - ), - - 'shipment_track' => array( - 'entity_model' => 'sales/order_shipment_track', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_shipment_attribute_backend_child' - ), - 'order_id' => array('type'=>'int'), - 'number' => array('type'=>'text'), - 'carrier_code' => array('type'=>'varchar'), - 'title' => array('type'=>'varchar'), - 'description' => array('type'=>'text'), - 'qty' => array('type'=>'decimal'), - 'weight' => array('type'=>'decimal'), - ), - ), - - 'creditmemo' => array( - 'entity_model' => 'sales/order_creditmemo', - //'table'=>'sales/creditmemo', - 'table'=>'sales/order_entity', - 'increment_model'=>'eav/entity_increment_numeric', - 'increment_per_store'=>true, - 'backend_prefix'=>'sales_entity/order_attribute_backend', - 'attributes' => array( - 'entity_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_creditmemo_attribute_backend_parent' - ), - 'state' => array('type'=>'int'), - 'invoice_id' => array('type'=>'int'), - 'transaction_id'=> array(), - - 'order_id' => array('type'=>'int'), - 'creditmemo_status' => array('type'=>'int'), - 'billing_address_id' => array('type'=>'int'), - 'shipping_address_id' => array('type'=>'int'), - - 'global_currency_code' => array(), - 'base_currency_code' => array(), - 'store_currency_code' => array(), - 'order_currency_code' => array(), - 'store_to_base_rate' => array('type'=>'decimal'), - 'store_to_order_rate' => array('type'=>'decimal'), - 'base_to_global_rate' => array('type'=>'decimal'), - 'base_to_order_rate' => array('type'=>'decimal'), - - 'subtotal' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'shipping_amount' => array('type'=>'decimal'), - 'adjustment' => array('type'=>'decimal'), - 'adjustment_positive' => array('type'=>'decimal'), - 'adjustment_negative' => array('type'=>'decimal'), - 'grand_total' => array('type'=>'decimal'), - - 'base_subtotal' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_shipping_amount' => array('type'=>'decimal'), - 'base_adjustment' => array('type'=>'decimal'), - 'base_adjustment_positive' => array('type'=>'decimal'), - 'base_adjustment_negative' => array('type'=>'decimal'), - 'base_grand_total' => array('type'=>'decimal'), - 'email_sent' => array('type' => 'int'), - 'store_id' => array('type' => 'static'), - ), - ), - - 'creditmemo_item' => array( - 'entity_model' => 'sales/order_creditmemo_item', - //'table'=>'sales/creditmemo', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_creditmemo_attribute_backend_child' - ), - 'order_item_id' => array('type'=>'int'), - 'product_id' => array('type'=>'int'), - 'name' => array(), - 'description' => array('type'=>'text'), - 'sku' => array(), - 'qty' => array('type'=>'decimal'), - 'cost' => array('type'=>'decimal'), - 'price' => array('type'=>'decimal'), - 'discount_amount' => array('type'=>'decimal'), - 'tax_amount' => array('type'=>'decimal'), - 'row_total' => array('type'=>'decimal'), - - 'base_price' => array('type'=>'decimal'), - 'base_discount_amount' => array('type'=>'decimal'), - 'base_tax_amount' => array('type'=>'decimal'), - 'base_row_total' => array('type'=>'decimal'), - - 'additional_data' => array('type'=>'text'), - ), - ), - - 'creditmemo_comment' => array( - 'entity_model' => 'sales/order_creditmemo_comment', - 'table'=>'sales/order_entity', - 'attributes' => array( - 'parent_id' => array( - 'type'=>'static', - 'backend'=>'sales_entity/order_creditmemo_attribute_backend_child' - ), - 'comment' => array('type'=>'text'), - 'is_customer_notified' => array('type'=>'int'), - ), - ), - - ); - } } diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 2cafb22a4c..579592d899 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order.php b/app/code/core/Mage/Sales/Model/Order.php index 588f39c60a..ee174145b8 100644 --- a/app/code/core/Mage/Sales/Model/Order.php +++ b/app/code/core/Mage/Sales/Model/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,10 +34,283 @@ * sales_order_delete_before * sales_order_delete_after * + * @method Mage_Sales_Model_Resource_Order _getResource() + * @method Mage_Sales_Model_Resource_Order getResource() + * @method string getState() + * @method string getStatus() + * @method Mage_Sales_Model_Order setStatus(string $value) + * @method string getCouponCode() + * @method Mage_Sales_Model_Order setCouponCode(string $value) + * @method string getProtectCode() + * @method Mage_Sales_Model_Order setProtectCode(string $value) + * @method string getShippingDescription() + * @method Mage_Sales_Model_Order setShippingDescription(string $value) + * @method int getIsVirtual() + * @method Mage_Sales_Model_Order setIsVirtual(int $value) + * @method int getStoreId() + * @method Mage_Sales_Model_Order setStoreId(int $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Order setCustomerId(int $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order setBaseDiscountAmount(float $value) + * @method float getBaseDiscountCanceled() + * @method Mage_Sales_Model_Order setBaseDiscountCanceled(float $value) + * @method float getBaseDiscountInvoiced() + * @method Mage_Sales_Model_Order setBaseDiscountInvoiced(float $value) + * @method float getBaseDiscountRefunded() + * @method Mage_Sales_Model_Order setBaseDiscountRefunded(float $value) + * @method float getBaseGrandTotal() + * @method Mage_Sales_Model_Order setBaseGrandTotal(float $value) + * @method float getBaseShippingAmount() + * @method Mage_Sales_Model_Order setBaseShippingAmount(float $value) + * @method float getBaseShippingCanceled() + * @method Mage_Sales_Model_Order setBaseShippingCanceled(float $value) + * @method float getBaseShippingInvoiced() + * @method Mage_Sales_Model_Order setBaseShippingInvoiced(float $value) + * @method float getBaseShippingRefunded() + * @method Mage_Sales_Model_Order setBaseShippingRefunded(float $value) + * @method float getBaseShippingTaxAmount() + * @method Mage_Sales_Model_Order setBaseShippingTaxAmount(float $value) + * @method float getBaseShippingTaxRefunded() + * @method Mage_Sales_Model_Order setBaseShippingTaxRefunded(float $value) + * @method float getBaseSubtotal() + * @method Mage_Sales_Model_Order setBaseSubtotal(float $value) + * @method float getBaseSubtotalCanceled() + * @method Mage_Sales_Model_Order setBaseSubtotalCanceled(float $value) + * @method float getBaseSubtotalInvoiced() + * @method Mage_Sales_Model_Order setBaseSubtotalInvoiced(float $value) + * @method float getBaseSubtotalRefunded() + * @method Mage_Sales_Model_Order setBaseSubtotalRefunded(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order setBaseTaxAmount(float $value) + * @method float getBaseTaxCanceled() + * @method Mage_Sales_Model_Order setBaseTaxCanceled(float $value) + * @method float getBaseTaxInvoiced() + * @method Mage_Sales_Model_Order setBaseTaxInvoiced(float $value) + * @method float getBaseTaxRefunded() + * @method Mage_Sales_Model_Order setBaseTaxRefunded(float $value) + * @method float getBaseToGlobalRate() + * @method Mage_Sales_Model_Order setBaseToGlobalRate(float $value) + * @method float getBaseToOrderRate() + * @method Mage_Sales_Model_Order setBaseToOrderRate(float $value) + * @method float getBaseTotalCanceled() + * @method Mage_Sales_Model_Order setBaseTotalCanceled(float $value) + * @method float getBaseTotalInvoiced() + * @method Mage_Sales_Model_Order setBaseTotalInvoiced(float $value) + * @method float getBaseTotalInvoicedCost() + * @method Mage_Sales_Model_Order setBaseTotalInvoicedCost(float $value) + * @method float getBaseTotalOfflineRefunded() + * @method Mage_Sales_Model_Order setBaseTotalOfflineRefunded(float $value) + * @method float getBaseTotalOnlineRefunded() + * @method Mage_Sales_Model_Order setBaseTotalOnlineRefunded(float $value) + * @method float getBaseTotalPaid() + * @method Mage_Sales_Model_Order setBaseTotalPaid(float $value) + * @method float getBaseTotalQtyOrdered() + * @method Mage_Sales_Model_Order setBaseTotalQtyOrdered(float $value) + * @method float getBaseTotalRefunded() + * @method Mage_Sales_Model_Order setBaseTotalRefunded(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order setDiscountAmount(float $value) + * @method float getDiscountCanceled() + * @method Mage_Sales_Model_Order setDiscountCanceled(float $value) + * @method float getDiscountInvoiced() + * @method Mage_Sales_Model_Order setDiscountInvoiced(float $value) + * @method float getDiscountRefunded() + * @method Mage_Sales_Model_Order setDiscountRefunded(float $value) + * @method float getGrandTotal() + * @method Mage_Sales_Model_Order setGrandTotal(float $value) + * @method float getShippingAmount() + * @method Mage_Sales_Model_Order setShippingAmount(float $value) + * @method float getShippingCanceled() + * @method Mage_Sales_Model_Order setShippingCanceled(float $value) + * @method float getShippingInvoiced() + * @method Mage_Sales_Model_Order setShippingInvoiced(float $value) + * @method float getShippingRefunded() + * @method Mage_Sales_Model_Order setShippingRefunded(float $value) + * @method float getShippingTaxAmount() + * @method Mage_Sales_Model_Order setShippingTaxAmount(float $value) + * @method float getShippingTaxRefunded() + * @method Mage_Sales_Model_Order setShippingTaxRefunded(float $value) + * @method float getStoreToBaseRate() + * @method Mage_Sales_Model_Order setStoreToBaseRate(float $value) + * @method float getStoreToOrderRate() + * @method Mage_Sales_Model_Order setStoreToOrderRate(float $value) + * @method float getSubtotal() + * @method Mage_Sales_Model_Order setSubtotal(float $value) + * @method float getSubtotalCanceled() + * @method Mage_Sales_Model_Order setSubtotalCanceled(float $value) + * @method float getSubtotalInvoiced() + * @method Mage_Sales_Model_Order setSubtotalInvoiced(float $value) + * @method float getSubtotalRefunded() + * @method Mage_Sales_Model_Order setSubtotalRefunded(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order setTaxAmount(float $value) + * @method float getTaxCanceled() + * @method Mage_Sales_Model_Order setTaxCanceled(float $value) + * @method float getTaxInvoiced() + * @method Mage_Sales_Model_Order setTaxInvoiced(float $value) + * @method float getTaxRefunded() + * @method Mage_Sales_Model_Order setTaxRefunded(float $value) + * @method float getTotalCanceled() + * @method Mage_Sales_Model_Order setTotalCanceled(float $value) + * @method float getTotalInvoiced() + * @method Mage_Sales_Model_Order setTotalInvoiced(float $value) + * @method float getTotalOfflineRefunded() + * @method Mage_Sales_Model_Order setTotalOfflineRefunded(float $value) + * @method float getTotalOnlineRefunded() + * @method Mage_Sales_Model_Order setTotalOnlineRefunded(float $value) + * @method float getTotalPaid() + * @method Mage_Sales_Model_Order setTotalPaid(float $value) + * @method float getTotalQtyOrdered() + * @method Mage_Sales_Model_Order setTotalQtyOrdered(float $value) + * @method float getTotalRefunded() + * @method Mage_Sales_Model_Order setTotalRefunded(float $value) + * @method int getCanShipPartially() + * @method Mage_Sales_Model_Order setCanShipPartially(int $value) + * @method int getCanShipPartiallyItem() + * @method Mage_Sales_Model_Order setCanShipPartiallyItem(int $value) + * @method int getCustomerIsGuest() + * @method Mage_Sales_Model_Order setCustomerIsGuest(int $value) + * @method int getCustomerNoteNotify() + * @method Mage_Sales_Model_Order setCustomerNoteNotify(int $value) + * @method int getBillingAddressId() + * @method Mage_Sales_Model_Order setBillingAddressId(int $value) + * @method int getCustomerGroupId() + * @method Mage_Sales_Model_Order setCustomerGroupId(int $value) + * @method int getEditIncrement() + * @method Mage_Sales_Model_Order setEditIncrement(int $value) + * @method int getEmailSent() + * @method Mage_Sales_Model_Order setEmailSent(int $value) + * @method int getForcedDoShipmentWithInvoice() + * @method Mage_Sales_Model_Order setForcedDoShipmentWithInvoice(int $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Order setGiftMessageId(int $value) + * @method int getPaymentAuthorizationExpiration() + * @method Mage_Sales_Model_Order setPaymentAuthorizationExpiration(int $value) + * @method int getPaypalIpnCustomerNotified() + * @method Mage_Sales_Model_Order setPaypalIpnCustomerNotified(int $value) + * @method int getQuoteAddressId() + * @method Mage_Sales_Model_Order setQuoteAddressId(int $value) + * @method int getQuoteId() + * @method Mage_Sales_Model_Order setQuoteId(int $value) + * @method int getShippingAddressId() + * @method Mage_Sales_Model_Order setShippingAddressId(int $value) + * @method float getAdjustmentNegative() + * @method Mage_Sales_Model_Order setAdjustmentNegative(float $value) + * @method float getAdjustmentPositive() + * @method Mage_Sales_Model_Order setAdjustmentPositive(float $value) + * @method float getBaseAdjustmentNegative() + * @method Mage_Sales_Model_Order setBaseAdjustmentNegative(float $value) + * @method float getBaseAdjustmentPositive() + * @method Mage_Sales_Model_Order setBaseAdjustmentPositive(float $value) + * @method float getBaseShippingDiscountAmount() + * @method Mage_Sales_Model_Order setBaseShippingDiscountAmount(float $value) + * @method float getBaseSubtotalInclTax() + * @method Mage_Sales_Model_Order setBaseSubtotalInclTax(float $value) + * @method Mage_Sales_Model_Order setBaseTotalDue(float $value) + * @method float getPaymentAuthorizationAmount() + * @method Mage_Sales_Model_Order setPaymentAuthorizationAmount(float $value) + * @method float getShippingDiscountAmount() + * @method Mage_Sales_Model_Order setShippingDiscountAmount(float $value) + * @method float getSubtotalInclTax() + * @method Mage_Sales_Model_Order setSubtotalInclTax(float $value) + * @method Mage_Sales_Model_Order setTotalDue(float $value) + * @method float getWeight() + * @method Mage_Sales_Model_Order setWeight(float $value) + * @method string getCustomerDob() + * @method Mage_Sales_Model_Order setCustomerDob(string $value) + * @method string getIncrementId() + * @method Mage_Sales_Model_Order setIncrementId(string $value) + * @method string getAppliedRuleIds() + * @method Mage_Sales_Model_Order setAppliedRuleIds(string $value) + * @method string getBaseCurrencyCode() + * @method Mage_Sales_Model_Order setBaseCurrencyCode(string $value) + * @method string getCustomerEmail() + * @method Mage_Sales_Model_Order setCustomerEmail(string $value) + * @method string getCustomerFirstname() + * @method Mage_Sales_Model_Order setCustomerFirstname(string $value) + * @method string getCustomerLastname() + * @method Mage_Sales_Model_Order setCustomerLastname(string $value) + * @method string getCustomerMiddlename() + * @method Mage_Sales_Model_Order setCustomerMiddlename(string $value) + * @method string getCustomerPrefix() + * @method Mage_Sales_Model_Order setCustomerPrefix(string $value) + * @method string getCustomerSuffix() + * @method Mage_Sales_Model_Order setCustomerSuffix(string $value) + * @method string getCustomerTaxvat() + * @method Mage_Sales_Model_Order setCustomerTaxvat(string $value) + * @method string getDiscountDescription() + * @method Mage_Sales_Model_Order setDiscountDescription(string $value) + * @method string getExtCustomerId() + * @method Mage_Sales_Model_Order setExtCustomerId(string $value) + * @method string getExtOrderId() + * @method Mage_Sales_Model_Order setExtOrderId(string $value) + * @method string getGlobalCurrencyCode() + * @method Mage_Sales_Model_Order setGlobalCurrencyCode(string $value) + * @method string getHoldBeforeState() + * @method Mage_Sales_Model_Order setHoldBeforeState(string $value) + * @method string getHoldBeforeStatus() + * @method Mage_Sales_Model_Order setHoldBeforeStatus(string $value) + * @method string getOrderCurrencyCode() + * @method Mage_Sales_Model_Order setOrderCurrencyCode(string $value) + * @method string getOriginalIncrementId() + * @method Mage_Sales_Model_Order setOriginalIncrementId(string $value) + * @method string getRelationChildId() + * @method Mage_Sales_Model_Order setRelationChildId(string $value) + * @method string getRelationChildRealId() + * @method Mage_Sales_Model_Order setRelationChildRealId(string $value) + * @method string getRelationParentId() + * @method Mage_Sales_Model_Order setRelationParentId(string $value) + * @method string getRelationParentRealId() + * @method Mage_Sales_Model_Order setRelationParentRealId(string $value) + * @method string getRemoteIp() + * @method Mage_Sales_Model_Order setRemoteIp(string $value) + * @method string getShippingMethod() + * @method Mage_Sales_Model_Order setShippingMethod(string $value) + * @method string getStoreCurrencyCode() + * @method Mage_Sales_Model_Order setStoreCurrencyCode(string $value) + * @method string getStoreName() + * @method Mage_Sales_Model_Order setStoreName(string $value) + * @method string getXForwardedFor() + * @method Mage_Sales_Model_Order setXForwardedFor(string $value) + * @method string getCustomerNote() + * @method Mage_Sales_Model_Order setCustomerNote(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order setUpdatedAt(string $value) + * @method int getTotalItemCount() + * @method Mage_Sales_Model_Order setTotalItemCount(int $value) + * @method int getCustomerGender() + * @method Mage_Sales_Model_Order setCustomerGender(int $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order setBaseHiddenTaxAmount(float $value) + * @method float getShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order setShippingHiddenTaxAmount(float $value) + * @method float getBaseShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order setBaseShippingHiddenTaxAmount(float $value) + * @method float getHiddenTaxInvoiced() + * @method Mage_Sales_Model_Order setHiddenTaxInvoiced(float $value) + * @method float getBaseHiddenTaxInvoiced() + * @method Mage_Sales_Model_Order setBaseHiddenTaxInvoiced(float $value) + * @method float getHiddenTaxRefunded() + * @method Mage_Sales_Model_Order setHiddenTaxRefunded(float $value) + * @method float getBaseHiddenTaxRefunded() + * @method Mage_Sales_Model_Order setBaseHiddenTaxRefunded(float $value) + * @method float getShippingInclTax() + * @method Mage_Sales_Model_Order setShippingInclTax(float $value) + * @method float getBaseShippingInclTax() + * @method Mage_Sales_Model_Order setBaseShippingInclTax(float $value) + * + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract { + const ENTITY = 'order'; /** * XML configuration paths */ @@ -129,6 +402,18 @@ protected function _construct() $this->_init('sales/order'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order'); + return $this; + } + /** * Clear order object data * diff --git a/app/code/core/Mage/Sales/Model/Order/Address.php b/app/code/core/Mage/Sales/Model/Order/Address.php index ccf75d53cc..c5ef65864b 100644 --- a/app/code/core/Mage/Sales/Model/Order/Address.php +++ b/app/code/core/Mage/Sales/Model/Order/Address.php @@ -20,11 +20,57 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Sales order address model + * + * @method Mage_Sales_Model_Resource_Order_Address _getResource() + * @method Mage_Sales_Model_Resource_Order_Address getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Address setParentId(int $value) + * @method int getCustomerAddressId() + * @method Mage_Sales_Model_Order_Address setCustomerAddressId(int $value) + * @method int getQuoteAddressId() + * @method Mage_Sales_Model_Order_Address setQuoteAddressId(int $value) + * @method Mage_Sales_Model_Order_Address setRegionId(int $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Order_Address setCustomerId(int $value) + * @method string getFax() + * @method Mage_Sales_Model_Order_Address setFax(string $value) + * @method Mage_Sales_Model_Order_Address setRegion(string $value) + * @method string getPostcode() + * @method Mage_Sales_Model_Order_Address setPostcode(string $value) + * @method string getLastname() + * @method Mage_Sales_Model_Order_Address setLastname(string $value) + * @method string getCity() + * @method Mage_Sales_Model_Order_Address setCity(string $value) + * @method string getEmail() + * @method Mage_Sales_Model_Order_Address setEmail(string $value) + * @method string getTelephone() + * @method Mage_Sales_Model_Order_Address setTelephone(string $value) + * @method string getCountryId() + * @method Mage_Sales_Model_Order_Address setCountryId(string $value) + * @method string getFirstname() + * @method Mage_Sales_Model_Order_Address setFirstname(string $value) + * @method string getAddressType() + * @method Mage_Sales_Model_Order_Address setAddressType(string $value) + * @method string getPrefix() + * @method Mage_Sales_Model_Order_Address setPrefix(string $value) + * @method string getMiddlename() + * @method Mage_Sales_Model_Order_Address setMiddlename(string $value) + * @method string getSuffix() + * @method Mage_Sales_Model_Order_Address setSuffix(string $value) + * @method string getCompany() + * @method Mage_Sales_Model_Order_Address setCompany(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Address extends Mage_Customer_Model_Address_Abstract { protected $_order; @@ -32,17 +78,41 @@ class Mage_Sales_Model_Order_Address extends Mage_Customer_Model_Address_Abstrac protected $_eventPrefix = 'sales_order_address'; protected $_eventObject = 'address'; + /** + * Initialize resource + */ protected function _construct() { $this->_init('sales/order_address'); } + /** + * Init mapping array of short fields to its full names + * + * @return Mage_Sales_Model_Order_Address + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_address'); + return $this; + } + + /** + * Set order + * + * @return Mage_Sales_Model_Order_Address + */ public function setOrder(Mage_Sales_Model_Order $order) { $this->_order = $order; return $this; } + /** + * Get order + * + * @return Mage_Sales_Model_Order + */ public function getOrder() { if (!$this->_order) { diff --git a/app/code/core/Mage/Sales/Model/Order/Api.php b/app/code/core/Mage/Sales/Model/Order/Api.php index 3afdf24f4c..3976695cd3 100644 --- a/app/code/core/Mage/Sales/Model/Order/Api.php +++ b/app/code/core/Mage/Sales/Model/Order/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Api/V2.php b/app/code/core/Mage/Sales/Model/Order/Api/V2.php index 39b40d5995..6dbecb538f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Api/V2.php +++ b/app/code/core/Mage/Sales/Model/Order/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Config.php b/app/code/core/Mage/Sales/Model/Order/Config.php index 27fd743832..a7be7851e5 100644 --- a/app/code/core/Mage/Sales/Model/Order/Config.php +++ b/app/code/core/Mage/Sales/Model/Order/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo.php index 46d8312b37..002aebea77 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo.php @@ -20,11 +20,112 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Order creditmemo model + * + * @method Mage_Sales_Model_Resource_Order_Creditmemo _getResource() + * @method Mage_Sales_Model_Resource_Order_Creditmemo getResource() + * @method int getStoreId() + * @method Mage_Sales_Model_Order_Creditmemo setStoreId(int $value) + * @method float getAdjustmentPositive() + * @method float getBaseShippingTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseShippingTaxAmount(float $value) + * @method float getStoreToOrderRate() + * @method Mage_Sales_Model_Order_Creditmemo setStoreToOrderRate(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseDiscountAmount(float $value) + * @method float getBaseToOrderRate() + * @method Mage_Sales_Model_Order_Creditmemo setBaseToOrderRate(float $value) + * @method float getGrandTotal() + * @method Mage_Sales_Model_Order_Creditmemo setGrandTotal(float $value) + * @method float getBaseAdjustmentNegative() + * @method Mage_Sales_Model_Order_Creditmemo setBaseAdjustmentNegative(float $value) + * @method float getBaseSubtotalInclTax() + * @method Mage_Sales_Model_Order_Creditmemo setBaseSubtotalInclTax(float $value) + * @method float getShippingAmount() + * @method float getSubtotalInclTax() + * @method Mage_Sales_Model_Order_Creditmemo setSubtotalInclTax(float $value) + * @method float getAdjustmentNegative() + * @method float getBaseShippingAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseShippingAmount(float $value) + * @method float getStoreToBaseRate() + * @method Mage_Sales_Model_Order_Creditmemo setStoreToBaseRate(float $value) + * @method float getBaseToGlobalRate() + * @method Mage_Sales_Model_Order_Creditmemo setBaseToGlobalRate(float $value) + * @method float getBaseAdjustment() + * @method Mage_Sales_Model_Order_Creditmemo setBaseAdjustment(float $value) + * @method float getBaseSubtotal() + * @method Mage_Sales_Model_Order_Creditmemo setBaseSubtotal(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order_Creditmemo setDiscountAmount(float $value) + * @method float getSubtotal() + * @method Mage_Sales_Model_Order_Creditmemo setSubtotal(float $value) + * @method float getAdjustment() + * @method Mage_Sales_Model_Order_Creditmemo setAdjustment(float $value) + * @method float getBaseGrandTotal() + * @method Mage_Sales_Model_Order_Creditmemo setBaseGrandTotal(float $value) + * @method float getBaseAdjustmentPositive() + * @method Mage_Sales_Model_Order_Creditmemo setBaseAdjustmentPositive(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseTaxAmount(float $value) + * @method float getShippingTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setShippingTaxAmount(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setTaxAmount(float $value) + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Creditmemo setOrderId(int $value) + * @method int getEmailSent() + * @method Mage_Sales_Model_Order_Creditmemo setEmailSent(int $value) + * @method int getCreditmemoStatus() + * @method Mage_Sales_Model_Order_Creditmemo setCreditmemoStatus(int $value) + * @method int getState() + * @method Mage_Sales_Model_Order_Creditmemo setState(int $value) + * @method int getShippingAddressId() + * @method Mage_Sales_Model_Order_Creditmemo setShippingAddressId(int $value) + * @method int getBillingAddressId() + * @method Mage_Sales_Model_Order_Creditmemo setBillingAddressId(int $value) + * @method int getInvoiceId() + * @method Mage_Sales_Model_Order_Creditmemo setInvoiceId(int $value) + * @method string getCybersourceToken() + * @method Mage_Sales_Model_Order_Creditmemo setCybersourceToken(string $value) + * @method string getStoreCurrencyCode() + * @method Mage_Sales_Model_Order_Creditmemo setStoreCurrencyCode(string $value) + * @method string getOrderCurrencyCode() + * @method Mage_Sales_Model_Order_Creditmemo setOrderCurrencyCode(string $value) + * @method string getBaseCurrencyCode() + * @method Mage_Sales_Model_Order_Creditmemo setBaseCurrencyCode(string $value) + * @method string getGlobalCurrencyCode() + * @method Mage_Sales_Model_Order_Creditmemo setGlobalCurrencyCode(string $value) + * @method string getTransactionId() + * @method Mage_Sales_Model_Order_Creditmemo setTransactionId(string $value) + * @method string getIncrementId() + * @method Mage_Sales_Model_Order_Creditmemo setIncrementId(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Creditmemo setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order_Creditmemo setUpdatedAt(string $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseHiddenTaxAmount(float $value) + * @method float getShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setShippingHiddenTaxAmount(float $value) + * @method float getBaseShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo setBaseShippingHiddenTaxAmount(float $value) + * @method float getShippingInclTax() + * @method Mage_Sales_Model_Order_Creditmemo setShippingInclTax(float $value) + * @method float getBaseShippingInclTax() + * @method Mage_Sales_Model_Order_Creditmemo setBaseShippingInclTax(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Creditmemo extends Mage_Sales_Model_Abstract { const STATE_OPEN = 1; @@ -65,6 +166,17 @@ protected function _construct() $this->_init('sales/order_creditmemo'); } + /** + * Init mapping array of short fields to its full names + * + * @return Mage_Sales_Model_Order_Creditmemo + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_creditmemo'); + return $this; + } + /** * Retrieve Creditmemo configuration model * diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Comment.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Comment.php index 3491cd9685..9a4ffe9596 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Comment.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Comment.php @@ -20,11 +20,31 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Creditmemo_Comment _getResource() + * @method Mage_Sales_Model_Resource_Order_Creditmemo_Comment getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Creditmemo_Comment setParentId(int $value) + * @method int getIsCustomerNotified() + * @method Mage_Sales_Model_Order_Creditmemo_Comment setIsCustomerNotified(int $value) + * @method int getIsVisibleOnFront() + * @method Mage_Sales_Model_Order_Creditmemo_Comment setIsVisibleOnFront(int $value) + * @method string getComment() + * @method Mage_Sales_Model_Order_Creditmemo_Comment setComment(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Creditmemo_Comment setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Creditmemo_Comment extends Mage_Sales_Model_Abstract { /** diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Config.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Config.php index 972349956b..59a036f7b6 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Config.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php index 3463643b64..a0bcd4cdd4 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Item.php @@ -20,10 +20,83 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Creditmemo_Item _getResource() + * @method Mage_Sales_Model_Resource_Order_Creditmemo_Item getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Creditmemo_Item setParentId(int $value) + * @method float getWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setWeeeTaxAppliedRowAmount(float $value) + * @method float getBasePrice() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBasePrice(float $value) + * @method float getBaseWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseWeeeTaxRowDisposition(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setTaxAmount(float $value) + * @method float getBaseWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseWeeeTaxAppliedAmount(float $value) + * @method float getWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Creditmemo_Item setWeeeTaxRowDisposition(float $value) + * @method float getBaseRowTotal() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseRowTotal(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setDiscountAmount(float $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Order_Creditmemo_Item setRowTotal(float $value) + * @method float getWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setWeeeTaxAppliedAmount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseDiscountAmount(float $value) + * @method float getBaseWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseWeeeTaxDisposition(float $value) + * @method float getPriceInclTax() + * @method Mage_Sales_Model_Order_Creditmemo_Item setPriceInclTax(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseTaxAmount(float $value) + * @method float getWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Creditmemo_Item setWeeeTaxDisposition(float $value) + * @method float getBasePriceInclTax() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBasePriceInclTax(float $value) + * @method float getQty() + * @method float getBaseCost() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseCost(float $value) + * @method float getBaseWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseWeeeTaxAppliedRowAmount(float $value) + * @method float getPrice() + * @method Mage_Sales_Model_Order_Creditmemo_Item setPrice(float $value) + * @method float getBaseRowTotalInclTax() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseRowTotalInclTax(float $value) + * @method float getRowTotalInclTax() + * @method Mage_Sales_Model_Order_Creditmemo_Item setRowTotalInclTax(float $value) + * @method int getProductId() + * @method Mage_Sales_Model_Order_Creditmemo_Item setProductId(int $value) + * @method int getOrderItemId() + * @method Mage_Sales_Model_Order_Creditmemo_Item setOrderItemId(int $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Order_Creditmemo_Item setAdditionalData(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Order_Creditmemo_Item setDescription(string $value) + * @method string getWeeeTaxApplied() + * @method Mage_Sales_Model_Order_Creditmemo_Item setWeeeTaxApplied(string $value) + * @method string getSku() + * @method Mage_Sales_Model_Order_Creditmemo_Item setSku(string $value) + * @method string getName() + * @method Mage_Sales_Model_Order_Creditmemo_Item setName(string $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Creditmemo_Item setBaseHiddenTaxAmount(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Creditmemo_Item extends Mage_Core_Model_Abstract { protected $_eventPrefix = 'sales_creditmemo_item'; @@ -51,6 +124,18 @@ public function setCreditmemo(Mage_Sales_Model_Order_Creditmemo $creditmemo) return $this; } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('creditmemo_item'); + return $this; + } + /** * Retrieve creditmemo instance * diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Abstract.php index d2251d545b..729331da1f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Cost.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Cost.php index 036272794d..a837336140 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Cost.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Cost.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Discount.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Discount.php index f789495624..ea2209cf81 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Discount.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Grand.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Grand.php index 58dbd1b0ef..539c97a712 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Grand.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Grand.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Shipping.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Shipping.php index 2f1d249e64..28a0b9a8c8 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Subtotal.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Subtotal.php index 43e3f839bf..d1c80ca878 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Tax.php b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Tax.php index ae50e1a5b6..ac3e75c34f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Tax.php +++ b/app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice.php b/app/code/core/Mage/Sales/Model/Order/Invoice.php index 6970badf41..a4dc704dff 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice.php @@ -20,11 +20,105 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Invoice _getResource() + * @method Mage_Sales_Model_Resource_Order_Invoice getResource() + * @method int getStoreId() + * @method Mage_Sales_Model_Order_Invoice setStoreId(int $value) + * @method float getBaseGrandTotal() + * @method Mage_Sales_Model_Order_Invoice setBaseGrandTotal(float $value) + * @method float getShippingTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setShippingTaxAmount(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setTaxAmount(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseTaxAmount(float $value) + * @method float getStoreToOrderRate() + * @method Mage_Sales_Model_Order_Invoice setStoreToOrderRate(float $value) + * @method float getBaseShippingTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseShippingTaxAmount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseDiscountAmount(float $value) + * @method float getBaseToOrderRate() + * @method Mage_Sales_Model_Order_Invoice setBaseToOrderRate(float $value) + * @method float getGrandTotal() + * @method Mage_Sales_Model_Order_Invoice setGrandTotal(float $value) + * @method float getShippingAmount() + * @method Mage_Sales_Model_Order_Invoice setShippingAmount(float $value) + * @method float getSubtotalInclTax() + * @method Mage_Sales_Model_Order_Invoice setSubtotalInclTax(float $value) + * @method float getBaseSubtotalInclTax() + * @method Mage_Sales_Model_Order_Invoice setBaseSubtotalInclTax(float $value) + * @method float getStoreToBaseRate() + * @method Mage_Sales_Model_Order_Invoice setStoreToBaseRate(float $value) + * @method float getBaseShippingAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseShippingAmount(float $value) + * @method float getTotalQty() + * @method Mage_Sales_Model_Order_Invoice setTotalQty(float $value) + * @method float getBaseToGlobalRate() + * @method Mage_Sales_Model_Order_Invoice setBaseToGlobalRate(float $value) + * @method float getSubtotal() + * @method Mage_Sales_Model_Order_Invoice setSubtotal(float $value) + * @method float getBaseSubtotal() + * @method Mage_Sales_Model_Order_Invoice setBaseSubtotal(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order_Invoice setDiscountAmount(float $value) + * @method int getBillingAddressId() + * @method Mage_Sales_Model_Order_Invoice setBillingAddressId(int $value) + * @method int getIsUsedForRefund() + * @method Mage_Sales_Model_Order_Invoice setIsUsedForRefund(int $value) + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Invoice setOrderId(int $value) + * @method int getEmailSent() + * @method Mage_Sales_Model_Order_Invoice setEmailSent(int $value) + * @method int getCanVoidFlag() + * @method Mage_Sales_Model_Order_Invoice setCanVoidFlag(int $value) + * @method int getState() + * @method Mage_Sales_Model_Order_Invoice setState(int $value) + * @method int getShippingAddressId() + * @method Mage_Sales_Model_Order_Invoice setShippingAddressId(int $value) + * @method string getCybersourceToken() + * @method Mage_Sales_Model_Order_Invoice setCybersourceToken(string $value) + * @method string getStoreCurrencyCode() + * @method Mage_Sales_Model_Order_Invoice setStoreCurrencyCode(string $value) + * @method string getTransactionId() + * @method Mage_Sales_Model_Order_Invoice setTransactionId(string $value) + * @method string getOrderCurrencyCode() + * @method Mage_Sales_Model_Order_Invoice setOrderCurrencyCode(string $value) + * @method string getBaseCurrencyCode() + * @method Mage_Sales_Model_Order_Invoice setBaseCurrencyCode(string $value) + * @method string getGlobalCurrencyCode() + * @method Mage_Sales_Model_Order_Invoice setGlobalCurrencyCode(string $value) + * @method string getIncrementId() + * @method Mage_Sales_Model_Order_Invoice setIncrementId(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Invoice setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order_Invoice setUpdatedAt(string $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseHiddenTaxAmount(float $value) + * @method float getShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setShippingHiddenTaxAmount(float $value) + * @method float getBaseShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice setBaseShippingHiddenTaxAmount(float $value) + * @method float getShippingInclTax() + * @method Mage_Sales_Model_Order_Invoice setShippingInclTax(float $value) + * @method float getBaseShippingInclTax() + * @method Mage_Sales_Model_Order_Invoice setBaseShippingInclTax(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Invoice extends Mage_Sales_Model_Abstract { /** @@ -87,6 +181,17 @@ protected function _construct() $this->_init('sales/order_invoice'); } + /** + * Init mapping array of short fields to its full names + * + * @return Mage_Sales_Model_Order_Invoice + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_invoice'); + return $this; + } + /** * Load invoice by increment id * diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Api.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Api.php index b7d80da7bd..103f201489 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Api.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Api/V2.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Api/V2.php index a060d8c404..bf7616e39f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Api/V2.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Comment.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Comment.php index 612ed8f28e..eee94262b9 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Comment.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Comment.php @@ -20,11 +20,31 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Invoice_Comment _getResource() + * @method Mage_Sales_Model_Resource_Order_Invoice_Comment getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Invoice_Comment setParentId(int $value) + * @method int getIsCustomerNotified() + * @method Mage_Sales_Model_Order_Invoice_Comment setIsCustomerNotified(int $value) + * @method int getIsVisibleOnFront() + * @method Mage_Sales_Model_Order_Invoice_Comment setIsVisibleOnFront(int $value) + * @method string getComment() + * @method Mage_Sales_Model_Order_Invoice_Comment setComment(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Invoice_Comment setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Invoice_Comment extends Mage_Sales_Model_Abstract { /** diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Config.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Config.php index bd0d06b8fe..1050ff63fd 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Config.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php index 4ee3fc19ac..aa23d32c67 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Item.php @@ -20,11 +20,84 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Invoice_Item _getResource() + * @method Mage_Sales_Model_Resource_Order_Invoice_Item getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Invoice_Item setParentId(int $value) + * @method float getBasePrice() + * @method Mage_Sales_Model_Order_Invoice_Item setBasePrice(float $value) + * @method float getBaseWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseWeeeTaxRowDisposition(float $value) + * @method float getWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setWeeeTaxAppliedRowAmount(float $value) + * @method float getBaseWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseWeeeTaxAppliedAmount(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setTaxAmount(float $value) + * @method float getBaseRowTotal() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseRowTotal(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setDiscountAmount(float $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Order_Invoice_Item setRowTotal(float $value) + * @method float getWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Invoice_Item setWeeeTaxRowDisposition(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseDiscountAmount(float $value) + * @method float getBaseWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseWeeeTaxDisposition(float $value) + * @method float getPriceInclTax() + * @method Mage_Sales_Model_Order_Invoice_Item setPriceInclTax(float $value) + * @method float getWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setWeeeTaxAppliedAmount(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseTaxAmount(float $value) + * @method float getBasePriceInclTax() + * @method Mage_Sales_Model_Order_Invoice_Item setBasePriceInclTax(float $value) + * @method float getQty() + * @method float getWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Invoice_Item setWeeeTaxDisposition(float $value) + * @method float getBaseCost() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseCost(float $value) + * @method float getBaseWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseWeeeTaxAppliedRowAmount(float $value) + * @method float getPrice() + * @method Mage_Sales_Model_Order_Invoice_Item setPrice(float $value) + * @method float getBaseRowTotalInclTax() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseRowTotalInclTax(float $value) + * @method float getRowTotalInclTax() + * @method Mage_Sales_Model_Order_Invoice_Item setRowTotalInclTax(float $value) + * @method int getProductId() + * @method Mage_Sales_Model_Order_Invoice_Item setProductId(int $value) + * @method int getOrderItemId() + * @method Mage_Sales_Model_Order_Invoice_Item setOrderItemId(int $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Order_Invoice_Item setAdditionalData(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Order_Invoice_Item setDescription(string $value) + * @method string getWeeeTaxApplied() + * @method Mage_Sales_Model_Order_Invoice_Item setWeeeTaxApplied(string $value) + * @method string getSku() + * @method Mage_Sales_Model_Order_Invoice_Item setSku(string $value) + * @method string getName() + * @method Mage_Sales_Model_Order_Invoice_Item setName(string $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Invoice_Item setBaseHiddenTaxAmount(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Invoice_Item extends Mage_Core_Model_Abstract { protected $_eventPrefix = 'sales_invoice_item'; @@ -41,6 +114,17 @@ function _construct() $this->_init('sales/order_invoice_item'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('invoice_item'); + return $this; + } /** * Declare invoice instance * diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Abstract.php index 4c762e78ca..dfca69d047 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Cost.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Cost.php index bf377cb2b0..230b1d8c40 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Cost.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Cost.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Discount.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Discount.php index ccf276e8de..4d6f531b3c 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Discount.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Grand.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Grand.php index 7fc9998f13..c8e754d82f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Grand.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Grand.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Shipping.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Shipping.php index c34f1bd885..371e58fac5 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Subtotal.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Subtotal.php index 786aea1377..455f93b399 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Tax.php b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Tax.php index 680b342dad..03e1c975b6 100644 --- a/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Tax.php +++ b/app/code/core/Mage/Sales/Model/Order/Invoice/Total/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Item.php b/app/code/core/Mage/Sales/Model/Order/Item.php index 44876973d7..5cb90c4bf7 100644 --- a/app/code/core/Mage/Sales/Model/Order/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Item.php @@ -20,13 +20,167 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order Item Model * + * @method Mage_Sales_Model_Resource_Order_Item _getResource() + * @method Mage_Sales_Model_Resource_Order_Item getResource() + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Item setOrderId(int $value) + * @method int getParentItemId() + * @method Mage_Sales_Model_Order_Item setParentItemId(int $value) + * @method int getQuoteItemId() + * @method Mage_Sales_Model_Order_Item setQuoteItemId(int $value) + * @method int getStoreId() + * @method Mage_Sales_Model_Order_Item setStoreId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Item setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order_Item setUpdatedAt(string $value) + * @method int getProductId() + * @method Mage_Sales_Model_Order_Item setProductId(int $value) + * @method string getProductType() + * @method Mage_Sales_Model_Order_Item setProductType(string $value) + * @method float getWeight() + * @method Mage_Sales_Model_Order_Item setWeight(float $value) + * @method int getIsVirtual() + * @method Mage_Sales_Model_Order_Item setIsVirtual(int $value) + * @method string getSku() + * @method Mage_Sales_Model_Order_Item setSku(string $value) + * @method string getName() + * @method Mage_Sales_Model_Order_Item setName(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Order_Item setDescription(string $value) + * @method string getAppliedRuleIds() + * @method Mage_Sales_Model_Order_Item setAppliedRuleIds(string $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Order_Item setAdditionalData(string $value) + * @method int getFreeShipping() + * @method Mage_Sales_Model_Order_Item setFreeShipping(int $value) + * @method int getIsQtyDecimal() + * @method Mage_Sales_Model_Order_Item setIsQtyDecimal(int $value) + * @method int getNoDiscount() + * @method Mage_Sales_Model_Order_Item setNoDiscount(int $value) + * @method float getQtyBackordered() + * @method Mage_Sales_Model_Order_Item setQtyBackordered(float $value) + * @method float getQtyCanceled() + * @method Mage_Sales_Model_Order_Item setQtyCanceled(float $value) + * @method float getQtyInvoiced() + * @method Mage_Sales_Model_Order_Item setQtyInvoiced(float $value) + * @method float getQtyOrdered() + * @method Mage_Sales_Model_Order_Item setQtyOrdered(float $value) + * @method float getQtyRefunded() + * @method Mage_Sales_Model_Order_Item setQtyRefunded(float $value) + * @method float getQtyShipped() + * @method Mage_Sales_Model_Order_Item setQtyShipped(float $value) + * @method float getBaseCost() + * @method Mage_Sales_Model_Order_Item setBaseCost(float $value) + * @method float getPrice() + * @method Mage_Sales_Model_Order_Item setPrice(float $value) + * @method float getBasePrice() + * @method Mage_Sales_Model_Order_Item setBasePrice(float $value) + * @method Mage_Sales_Model_Order_Item setOriginalPrice(float $value) + * @method float getBaseOriginalPrice() + * @method Mage_Sales_Model_Order_Item setBaseOriginalPrice(float $value) + * @method float getTaxPercent() + * @method Mage_Sales_Model_Order_Item setTaxPercent(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Order_Item setTaxAmount(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Order_Item setBaseTaxAmount(float $value) + * @method float getTaxInvoiced() + * @method Mage_Sales_Model_Order_Item setTaxInvoiced(float $value) + * @method float getBaseTaxInvoiced() + * @method Mage_Sales_Model_Order_Item setBaseTaxInvoiced(float $value) + * @method float getDiscountPercent() + * @method Mage_Sales_Model_Order_Item setDiscountPercent(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Order_Item setDiscountAmount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Order_Item setBaseDiscountAmount(float $value) + * @method float getDiscountInvoiced() + * @method Mage_Sales_Model_Order_Item setDiscountInvoiced(float $value) + * @method float getBaseDiscountInvoiced() + * @method Mage_Sales_Model_Order_Item setBaseDiscountInvoiced(float $value) + * @method float getAmountRefunded() + * @method Mage_Sales_Model_Order_Item setAmountRefunded(float $value) + * @method float getBaseAmountRefunded() + * @method Mage_Sales_Model_Order_Item setBaseAmountRefunded(float $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Order_Item setRowTotal(float $value) + * @method float getBaseRowTotal() + * @method Mage_Sales_Model_Order_Item setBaseRowTotal(float $value) + * @method float getRowInvoiced() + * @method Mage_Sales_Model_Order_Item setRowInvoiced(float $value) + * @method float getBaseRowInvoiced() + * @method Mage_Sales_Model_Order_Item setBaseRowInvoiced(float $value) + * @method float getRowWeight() + * @method Mage_Sales_Model_Order_Item setRowWeight(float $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Order_Item setGiftMessageId(int $value) + * @method int getGiftMessageAvailable() + * @method Mage_Sales_Model_Order_Item setGiftMessageAvailable(int $value) + * @method float getBaseTaxBeforeDiscount() + * @method Mage_Sales_Model_Order_Item setBaseTaxBeforeDiscount(float $value) + * @method float getTaxBeforeDiscount() + * @method Mage_Sales_Model_Order_Item setTaxBeforeDiscount(float $value) + * @method string getExtOrderItemId() + * @method Mage_Sales_Model_Order_Item setExtOrderItemId(string $value) + * @method string getWeeeTaxApplied() + * @method Mage_Sales_Model_Order_Item setWeeeTaxApplied(string $value) + * @method float getWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Item setWeeeTaxAppliedAmount(float $value) + * @method float getWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Item setWeeeTaxAppliedRowAmount(float $value) + * @method float getBaseWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxAppliedAmount(float $value) + * @method float getBaseWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxAppliedRowAmount(float $value) + * @method float getWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Item setWeeeTaxDisposition(float $value) + * @method float getWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Item setWeeeTaxRowDisposition(float $value) + * @method float getBaseWeeeTaxDisposition() + * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxDisposition(float $value) + * @method float getBaseWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxRowDisposition(float $value) + * @method int getLockedDoInvoice() + * @method Mage_Sales_Model_Order_Item setLockedDoInvoice(int $value) + * @method int getLockedDoShip() + * @method Mage_Sales_Model_Order_Item setLockedDoShip(int $value) + * @method float getPriceInclTax() + * @method Mage_Sales_Model_Order_Item setPriceInclTax(float $value) + * @method float getBasePriceInclTax() + * @method Mage_Sales_Model_Order_Item setBasePriceInclTax(float $value) + * @method float getRowTotalInclTax() + * @method Mage_Sales_Model_Order_Item setRowTotalInclTax(float $value) + * @method float getBaseRowTotalInclTax() + * @method Mage_Sales_Model_Order_Item setBaseRowTotalInclTax(float $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Item setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxAmount(float $value) + * @method float getHiddenTaxInvoiced() + * @method Mage_Sales_Model_Order_Item setHiddenTaxInvoiced(float $value) + * @method float getBaseHiddenTaxInvoiced() + * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxInvoiced(float $value) + * @method float getHiddenTaxRefunded() + * @method Mage_Sales_Model_Order_Item setHiddenTaxRefunded(float $value) + * @method float getBaseHiddenTaxRefunded() + * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxRefunded(float $value) + * @method int getIsNominal() + * @method Mage_Sales_Model_Order_Item setIsNominal(int $value) + * @method float getTaxCanceled() + * @method Mage_Sales_Model_Order_Item setTaxCanceled(float $value) + * @method float getHiddenTaxCanceled() + * @method Mage_Sales_Model_Order_Item setHiddenTaxCanceled(float $value) + * @method float getTaxRefunded() + * @method Mage_Sales_Model_Order_Item setTaxRefunded(float $value) + * * @category Mage * @package Mage_Sales * @author Magento Core Team @@ -67,6 +221,18 @@ protected function _construct() $this->_init('sales/order_item'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_item'); + return $this; + } + /** * Prepare data before save * diff --git a/app/code/core/Mage/Sales/Model/Order/Payment.php b/app/code/core/Mage/Sales/Model/Order/Payment.php index cfb72df328..b427cdb471 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment.php @@ -20,12 +20,137 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order payment information + * + * @method Mage_Sales_Model_Resource_Order_Payment _getResource() + * @method Mage_Sales_Model_Resource_Order_Payment getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Payment setParentId(int $value) + * @method float getBaseShippingCaptured() + * @method Mage_Sales_Model_Order_Payment setBaseShippingCaptured(float $value) + * @method float getShippingCaptured() + * @method Mage_Sales_Model_Order_Payment setShippingCaptured(float $value) + * @method float getAmountRefunded() + * @method Mage_Sales_Model_Order_Payment setAmountRefunded(float $value) + * @method float getBaseAmountPaid() + * @method Mage_Sales_Model_Order_Payment setBaseAmountPaid(float $value) + * @method float getAmountCanceled() + * @method Mage_Sales_Model_Order_Payment setAmountCanceled(float $value) + * @method float getBaseAmountAuthorized() + * @method Mage_Sales_Model_Order_Payment setBaseAmountAuthorized(float $value) + * @method float getBaseAmountPaidOnline() + * @method Mage_Sales_Model_Order_Payment setBaseAmountPaidOnline(float $value) + * @method float getBaseAmountRefundedOnline() + * @method Mage_Sales_Model_Order_Payment setBaseAmountRefundedOnline(float $value) + * @method float getBaseShippingAmount() + * @method Mage_Sales_Model_Order_Payment setBaseShippingAmount(float $value) + * @method float getShippingAmount() + * @method Mage_Sales_Model_Order_Payment setShippingAmount(float $value) + * @method float getAmountPaid() + * @method Mage_Sales_Model_Order_Payment setAmountPaid(float $value) + * @method float getAmountAuthorized() + * @method Mage_Sales_Model_Order_Payment setAmountAuthorized(float $value) + * @method float getBaseAmountOrdered() + * @method Mage_Sales_Model_Order_Payment setBaseAmountOrdered(float $value) + * @method float getBaseShippingRefunded() + * @method Mage_Sales_Model_Order_Payment setBaseShippingRefunded(float $value) + * @method float getShippingRefunded() + * @method Mage_Sales_Model_Order_Payment setShippingRefunded(float $value) + * @method float getBaseAmountRefunded() + * @method Mage_Sales_Model_Order_Payment setBaseAmountRefunded(float $value) + * @method float getAmountOrdered() + * @method Mage_Sales_Model_Order_Payment setAmountOrdered(float $value) + * @method float getBaseAmountCanceled() + * @method Mage_Sales_Model_Order_Payment setBaseAmountCanceled(float $value) + * @method int getIdealTransactionChecked() + * @method Mage_Sales_Model_Order_Payment setIdealTransactionChecked(int $value) + * @method int getQuotePaymentId() + * @method Mage_Sales_Model_Order_Payment setQuotePaymentId(int $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Order_Payment setAdditionalData(string $value) + * @method string getCcExpMonth() + * @method Mage_Sales_Model_Order_Payment setCcExpMonth(string $value) + * @method string getCcSsStartYear() + * @method Mage_Sales_Model_Order_Payment setCcSsStartYear(string $value) + * @method string getEcheckBankName() + * @method Mage_Sales_Model_Order_Payment setEcheckBankName(string $value) + * @method string getMethod() + * @method Mage_Sales_Model_Order_Payment setMethod(string $value) + * @method string getCcDebugRequestBody() + * @method Mage_Sales_Model_Order_Payment setCcDebugRequestBody(string $value) + * @method string getCcSecureVerify() + * @method Mage_Sales_Model_Order_Payment setCcSecureVerify(string $value) + * @method string getCybersourceToken() + * @method Mage_Sales_Model_Order_Payment setCybersourceToken(string $value) + * @method string getIdealIssuerTitle() + * @method Mage_Sales_Model_Order_Payment setIdealIssuerTitle(string $value) + * @method string getProtectionEligibility() + * @method Mage_Sales_Model_Order_Payment setProtectionEligibility(string $value) + * @method string getCcApproval() + * @method Mage_Sales_Model_Order_Payment setCcApproval(string $value) + * @method string getCcLast4() + * @method Mage_Sales_Model_Order_Payment setCcLast4(string $value) + * @method string getCcStatusDescription() + * @method Mage_Sales_Model_Order_Payment setCcStatusDescription(string $value) + * @method string getEcheckType() + * @method Mage_Sales_Model_Order_Payment setEcheckType(string $value) + * @method string getPayboxQuestionNumber() + * @method Mage_Sales_Model_Order_Payment setPayboxQuestionNumber(string $value) + * @method string getCcDebugResponseSerialized() + * @method Mage_Sales_Model_Order_Payment setCcDebugResponseSerialized(string $value) + * @method string getCcSsStartMonth() + * @method Mage_Sales_Model_Order_Payment setCcSsStartMonth(string $value) + * @method string getEcheckAccountType() + * @method Mage_Sales_Model_Order_Payment setEcheckAccountType(string $value) + * @method string getLastTransId() + * @method Mage_Sales_Model_Order_Payment setLastTransId(string $value) + * @method string getCcCidStatus() + * @method Mage_Sales_Model_Order_Payment setCcCidStatus(string $value) + * @method string getCcOwner() + * @method Mage_Sales_Model_Order_Payment setCcOwner(string $value) + * @method string getCcType() + * @method Mage_Sales_Model_Order_Payment setCcType(string $value) + * @method string getIdealIssuerId() + * @method Mage_Sales_Model_Order_Payment setIdealIssuerId(string $value) + * @method string getPoNumber() + * @method Mage_Sales_Model_Order_Payment setPoNumber(string $value) + * @method string getCcExpYear() + * @method Mage_Sales_Model_Order_Payment setCcExpYear(string $value) + * @method string getCcStatus() + * @method Mage_Sales_Model_Order_Payment setCcStatus(string $value) + * @method string getEcheckRoutingNumber() + * @method Mage_Sales_Model_Order_Payment setEcheckRoutingNumber(string $value) + * @method string getAccountStatus() + * @method Mage_Sales_Model_Order_Payment setAccountStatus(string $value) + * @method string getAnetTransMethod() + * @method Mage_Sales_Model_Order_Payment setAnetTransMethod(string $value) + * @method string getCcDebugResponseBody() + * @method Mage_Sales_Model_Order_Payment setCcDebugResponseBody(string $value) + * @method string getCcSsIssue() + * @method Mage_Sales_Model_Order_Payment setCcSsIssue(string $value) + * @method string getEcheckAccountName() + * @method Mage_Sales_Model_Order_Payment setEcheckAccountName(string $value) + * @method string getCcAvsStatus() + * @method Mage_Sales_Model_Order_Payment setCcAvsStatus(string $value) + * @method string getCcNumberEnc() + * @method Mage_Sales_Model_Order_Payment setCcNumberEnc(string $value) + * @method string getCcTransId() + * @method Mage_Sales_Model_Order_Payment setCcTransId(string $value) + * @method string getFlo2cashAccountId() + * @method Mage_Sales_Model_Order_Payment setFlo2cashAccountId(string $value) + * @method string getPayboxRequestNumber() + * @method Mage_Sales_Model_Order_Payment setPayboxRequestNumber(string $value) + * @method string getAddressStatus() + * @method Mage_Sales_Model_Order_Payment setAddressStatus(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Order_Payment extends Mage_Payment_Model_Info { @@ -258,16 +383,6 @@ public function capture($invoice) } $this->_isCaptureFinal($paidWorkaround); - if (!$this->getParentTransactionId()) { - $orderingTransaction = $this->_lookupTransaction( - false, - Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER - ); - if ($orderingTransaction) { - $this->setParentTransactionId($orderingTransaction->getTxnId()); - } - } - $this->_generateTransactionId( Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $this->getAuthorizationTransaction() @@ -861,6 +976,10 @@ protected function _order($amount) $status = true; $this->getMethodInstance()->setStore($order->getStoreId())->order($this, $amount); + if ($this->getSkipOrderProcessing()) { + return $this; + } + // similar logic of "payment review" order as in capturing if ($this->getIsTransactionPending()) { $message = Mage::helper('sales')->__('Ordering amount of %s is pending approval on gateway.', $this->_formatPrice($amount)); @@ -1258,7 +1377,8 @@ protected function _lookupTransaction($txnId, $txnType = false) $collection = Mage::getModel('sales/order_payment_transaction')->getCollection() ->setOrderFilter($this->getOrder()) ->addPaymentIdFilter($this->getId()) - ->addTxnTypeFilter($txnType); + ->addTxnTypeFilter($txnType) + ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC); foreach ($collection as $txn) { $txn->setOrderPaymentObject($this); $this->_transactionsLookup[$txn->getTxnId()] = $txn; @@ -1281,6 +1401,17 @@ protected function _lookupTransaction($txnId, $txnType = false) return $this->_transactionsLookup[$txnId]; } + /** + * Find one transaction by ID or type + * @param string $txnId + * @param string $txnType + * @return Mage_Sales_Model_Order_Payment_Transaction|false + */ + public function lookupTransaction($txnId, $txnType = false) + { + return $this->_lookupTransaction($txnId, $txnType); + } + /** * Lookup an authorization transaction using parent transaction id, if set * @return Mage_Sales_Model_Order_Payment_Transaction|false @@ -1389,7 +1520,25 @@ protected function _createBillingAgreement() */ public function setTransactionAdditionalInfo($key, $value) { - $this->_transactionAdditionalInfo[$key] = $value; + if (is_array($key)) { + $this->_transactionAdditionalInfo = $key; + } else { + $this->_transactionAdditionalInfo[$key] = $value; + } + } + + /** + * Additionnal transaction info getter + * + * @param sting $key + * @return mixed + */ + public function getTransactionAdditionalInfo($key = null) + { + if (is_null($key)) { + return $this->_transactionAdditionalInfo; + } + return isset($this->_transactionAdditionalInfo[$key]) ? $this->_transactionAdditionalInfo[$key] : null; } /** diff --git a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php index b95d13dd94..64afb5fa8a 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,25 @@ * Payment transaction model * Tracks transaction history, allows to build transactions hierarchy * By default transactions are saved as closed. + * + * @method Mage_Sales_Model_Resource_Order_Payment_Transaction _getResource() + * @method Mage_Sales_Model_Resource_Order_Payment_Transaction getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Payment_Transaction setParentId(int $value) + * @method Mage_Sales_Model_Order_Payment_Transaction setOrderId(int $value) + * @method int getPaymentId() + * @method Mage_Sales_Model_Order_Payment_Transaction setPaymentId(int $value) + * @method string getTxnId() + * @method string getParentTxnId() + * @method string getTxnType() + * @method int getIsClosed() + * @method Mage_Sales_Model_Order_Payment_Transaction setIsClosed(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Payment_Transaction setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Order_Payment_Transaction extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php index d7c4891a86..04f85c9a16 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -81,7 +81,9 @@ abstract public function getPdf(); */ public function widthForStringUsingFontSize($string, $font, $fontSize) { - $drawingString = '"libiconv"' == ICONV_IMPL ? iconv('UTF-8', 'UTF-16BE//IGNORE', $string) : @iconv('UTF-8', 'UTF-16BE', $string); + $drawingString = '"libiconv"' == ICONV_IMPL ? + iconv('UTF-8', 'UTF-16BE//IGNORE', $string) : + @iconv('UTF-8', 'UTF-16BE', $string); $characters = array(); for ($i = 0; $i < strlen($drawingString); $i++) { @@ -131,7 +133,7 @@ protected function insertLogo(&$page, $store = null) { $image = Mage::getStoreConfig('sales/identity/logo', $store); if ($image) { - $image = Mage::getStoreConfig('system/filesystem/media', $store) . '/sales/store/logo/' . $image; + $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image; if (is_file($image)) { $image = Zend_Pdf_Image::imageWithPath($image); $page->drawImage($image, 25, 800, 125, 825); @@ -355,7 +357,9 @@ protected function insertOrder(&$page, $obj, $putOrderId = true) } //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : ''); - $truncatedTitle = substr($track->getTitle(), 0, 45) . (strlen($track->getTitle()) > 45 ? '...' : ''); + $maxTitleLen = 45; + $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : ''; + $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle; //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8'); $page->drawText($truncatedTitle, 300, $yShipments , 'UTF-8'); $page->drawText($track->getNumber(), 395, $yShipments , 'UTF-8'); diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php index c1187a4e80..7f9e69fcc9 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php index 5e49add060..da5e56330d 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php index 75efae8832..f6b0aa972c 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php index 8f71c258a2..e984a11e13 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Grouped.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Grouped.php index b268d71197..82e3baaf29 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Grouped.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php index 6a12a84862..4bd3daef38 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Grouped.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Grouped.php index 408bf74571..c77cd27ceb 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Grouped.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php index 12483199df..8906af359e 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php index 62763e3c89..b506370f85 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php index b4db890861..7406bb5510 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment.php b/app/code/core/Mage/Sales/Model/Order/Shipment.php index c4115d296a..41f8e5c4e1 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment.php @@ -20,11 +20,45 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Sales order shipment model + * + * @method Mage_Sales_Model_Resource_Order_Shipment _getResource() + * @method Mage_Sales_Model_Resource_Order_Shipment getResource() + * @method int getStoreId() + * @method Mage_Sales_Model_Order_Shipment setStoreId(int $value) + * @method float getTotalWeight() + * @method Mage_Sales_Model_Order_Shipment setTotalWeight(float $value) + * @method float getTotalQty() + * @method Mage_Sales_Model_Order_Shipment setTotalQty(float $value) + * @method int getEmailSent() + * @method Mage_Sales_Model_Order_Shipment setEmailSent(int $value) + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Shipment setOrderId(int $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Order_Shipment setCustomerId(int $value) + * @method int getShippingAddressId() + * @method Mage_Sales_Model_Order_Shipment setShippingAddressId(int $value) + * @method int getBillingAddressId() + * @method Mage_Sales_Model_Order_Shipment setBillingAddressId(int $value) + * @method int getShipmentStatus() + * @method Mage_Sales_Model_Order_Shipment setShipmentStatus(int $value) + * @method string getIncrementId() + * @method Mage_Sales_Model_Order_Shipment setIncrementId(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Shipment setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order_Shipment setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Shipment extends Mage_Sales_Model_Abstract { const STATUS_NEW = 1; @@ -62,6 +96,17 @@ protected function _construct() $this->_init('sales/order_shipment'); } + /** + * Init mapping array of short fields to its full names + * + * @return Mage_Sales_Model_Order_Shipment + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_shipment'); + return $this; + } + /** * Load shipment by increment id * diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Api.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Api.php index 255ffb5ecc..8ec3dc3741 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Api.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Api.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Api/V2.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Api/V2.php index 0e47e8a4d5..3484fe235f 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Api/V2.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Api/V2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Comment.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Comment.php index 9e3a732a3f..d848dc01c4 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Comment.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Comment.php @@ -20,11 +20,31 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Shipment_Comment _getResource() + * @method Mage_Sales_Model_Resource_Order_Shipment_Comment getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Shipment_Comment setParentId(int $value) + * @method int getIsCustomerNotified() + * @method Mage_Sales_Model_Order_Shipment_Comment setIsCustomerNotified(int $value) + * @method int getIsVisibleOnFront() + * @method Mage_Sales_Model_Order_Shipment_Comment setIsVisibleOnFront(int $value) + * @method string getComment() + * @method Mage_Sales_Model_Order_Shipment_Comment setComment(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Shipment_Comment setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Shipment_Comment extends Mage_Sales_Model_Abstract { /** diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php index 2af3ab2234..3d5d82b1c8 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Item.php @@ -20,10 +20,41 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Shipment_Item _getResource() + * @method Mage_Sales_Model_Resource_Order_Shipment_Item getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Shipment_Item setParentId(int $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Order_Shipment_Item setRowTotal(float $value) + * @method float getPrice() + * @method Mage_Sales_Model_Order_Shipment_Item setPrice(float $value) + * @method float getWeight() + * @method Mage_Sales_Model_Order_Shipment_Item setWeight(float $value) + * @method float getQty() + * @method int getProductId() + * @method Mage_Sales_Model_Order_Shipment_Item setProductId(int $value) + * @method int getOrderItemId() + * @method Mage_Sales_Model_Order_Shipment_Item setOrderItemId(int $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Order_Shipment_Item setAdditionalData(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Order_Shipment_Item setDescription(string $value) + * @method string getName() + * @method Mage_Sales_Model_Order_Shipment_Item setName(string $value) + * @method string getSku() + * @method Mage_Sales_Model_Order_Shipment_Item setSku(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Shipment_Item extends Mage_Core_Model_Abstract { protected $_eventPrefix = 'sales_shipment_item'; diff --git a/app/code/core/Mage/Sales/Model/Order/Shipment/Track.php b/app/code/core/Mage/Sales/Model/Order/Shipment/Track.php index e5ddc08f7c..393c2ba446 100644 --- a/app/code/core/Mage/Sales/Model/Order/Shipment/Track.php +++ b/app/code/core/Mage/Sales/Model/Order/Shipment/Track.php @@ -20,10 +20,40 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Order_Shipment_Track _getResource() + * @method Mage_Sales_Model_Resource_Order_Shipment_Track getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Shipment_Track setParentId(int $value) + * @method float getWeight() + * @method Mage_Sales_Model_Order_Shipment_Track setWeight(float $value) + * @method float getQty() + * @method Mage_Sales_Model_Order_Shipment_Track setQty(float $value) + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Shipment_Track setOrderId(int $value) + * @method string getNumber() + * @method Mage_Sales_Model_Order_Shipment_Track setNumber(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Order_Shipment_Track setDescription(string $value) + * @method string getTitle() + * @method Mage_Sales_Model_Order_Shipment_Track setTitle(string $value) + * @method string getCarrierCode() + * @method Mage_Sales_Model_Order_Shipment_Track setCarrierCode(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Shipment_Track setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Order_Shipment_Track setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Order_Shipment_Track extends Mage_Sales_Model_Abstract { const CUSTOM_CARRIER_CODE = 'custom'; @@ -40,6 +70,29 @@ function _construct() $this->_init('sales/order_shipment_track'); } + /** + * Init mapping array of short fields to + * its full names + * + * @resturn Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = array( + 'number' => 'track_number' + ); + } + + /** + * Back compatibility with old versions. + * + * @return string + */ + public function getNumber() + { + return $this->getData('track_number'); + } + /** * Declare Shipment instance * @@ -90,8 +143,9 @@ public function getNumberDetail() { $carrierInstance = Mage::getSingleton('shipping/config')->getCarrierInstance($this->getCarrierCode()); if (!$carrierInstance) { + $custom = array(); $custom['title'] = $this->getTitle(); - $custom['number'] = $this->getNumber(); + $custom['number'] = $this->getTrackNumber(); return $custom; } else { $carrierInstance->setStore($this->getStore()); diff --git a/app/code/core/Mage/Sales/Model/Order/Status.php b/app/code/core/Mage/Sales/Model/Order/Status.php index d48cb94de0..29859db4a3 100644 --- a/app/code/core/Mage/Sales/Model/Order/Status.php +++ b/app/code/core/Mage/Sales/Model/Order/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Order/Status/History.php b/app/code/core/Mage/Sales/Model/Order/Status/History.php index 286bd9bbc3..29d0779c40 100644 --- a/app/code/core/Mage/Sales/Model/Order/Status/History.php +++ b/app/code/core/Mage/Sales/Model/Order/Status/History.php @@ -20,12 +20,30 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Order status history comments + * + * @method Mage_Sales_Model_Resource_Order_Status_History _getResource() + * @method Mage_Sales_Model_Resource_Order_Status_History getResource() + * @method int getParentId() + * @method Mage_Sales_Model_Order_Status_History setParentId(int $value) + * @method int getIsCustomerNotified() + * @method int getIsVisibleOnFront() + * @method Mage_Sales_Model_Order_Status_History setIsVisibleOnFront(int $value) + * @method string getComment() + * @method Mage_Sales_Model_Order_Status_History setComment(string $value) + * @method string getStatus() + * @method Mage_Sales_Model_Order_Status_History setStatus(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Order_Status_History setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Order_Status_History extends Mage_Sales_Model_Abstract { diff --git a/app/code/core/Mage/Sales/Model/Order/Tax.php b/app/code/core/Mage/Sales/Model/Order/Tax.php index 3e0b6aeb1b..f094ef695c 100644 --- a/app/code/core/Mage/Sales/Model/Order/Tax.php +++ b/app/code/core/Mage/Sales/Model/Order/Tax.php @@ -20,12 +20,40 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * @deprecated after 1.4, moved to tax module + * + * @method Mage_Sales_Model_Resource_Order_Tax _getResource() + * @method Mage_Sales_Model_Resource_Order_Tax getResource() + * @method int getOrderId() + * @method Mage_Sales_Model_Order_Tax setOrderId(int $value) + * @method string getCode() + * @method Mage_Sales_Model_Order_Tax setCode(string $value) + * @method string getTitle() + * @method Mage_Sales_Model_Order_Tax setTitle(string $value) + * @method float getPercent() + * @method Mage_Sales_Model_Order_Tax setPercent(float $value) + * @method float getAmount() + * @method Mage_Sales_Model_Order_Tax setAmount(float $value) + * @method int getPriority() + * @method Mage_Sales_Model_Order_Tax setPriority(int $value) + * @method int getPosition() + * @method Mage_Sales_Model_Order_Tax setPosition(int $value) + * @method float getBaseAmount() + * @method Mage_Sales_Model_Order_Tax setBaseAmount(float $value) + * @method int getProcess() + * @method Mage_Sales_Model_Order_Tax setProcess(int $value) + * @method float getBaseRealAmount() + * @method Mage_Sales_Model_Order_Tax setBaseRealAmount(float $value) + * @method int getHidden() + * @method Mage_Sales_Model_Order_Tax setHidden(int $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Order_Tax extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Sales/Model/Order/Total.php b/app/code/core/Mage/Sales/Model/Order/Total.php index 1a7e8f5321..a82ac34539 100644 --- a/app/code/core/Mage/Sales/Model/Order/Total.php +++ b/app/code/core/Mage/Sales/Model/Order/Total.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Payment/Method/Billing/AgreementAbstract.php b/app/code/core/Mage/Sales/Model/Payment/Method/Billing/AgreementAbstract.php index fc24e2cf93..e35b8dcf7f 100644 --- a/app/code/core/Mage/Sales/Model/Payment/Method/Billing/AgreementAbstract.php +++ b/app/code/core/Mage/Sales/Model/Payment/Method/Billing/AgreementAbstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote.php b/app/code/core/Mage/Sales/Model/Quote.php index 54414cc945..68da558e3f 100644 --- a/app/code/core/Mage/Sales/Model/Quote.php +++ b/app/code/core/Mage/Sales/Model/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,6 +34,104 @@ * sales_quote_delete_before * sales_quote_delete_after * + * @method Mage_Sales_Model_Resource_Quote _getResource() + * @method Mage_Sales_Model_Resource_Quote getResource() + * @method Mage_Sales_Model_Quote setStoreId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote setUpdatedAt(string $value) + * @method string getConvertedAt() + * @method Mage_Sales_Model_Quote setConvertedAt(string $value) + * @method int getIsActive() + * @method Mage_Sales_Model_Quote setIsActive(int $value) + * @method Mage_Sales_Model_Quote setIsVirtual(int $value) + * @method int getIsMultiShipping() + * @method Mage_Sales_Model_Quote setIsMultiShipping(int $value) + * @method int getItemsCount() + * @method Mage_Sales_Model_Quote setItemsCount(int $value) + * @method float getItemsQty() + * @method Mage_Sales_Model_Quote setItemsQty(float $value) + * @method int getOrigOrderId() + * @method Mage_Sales_Model_Quote setOrigOrderId(int $value) + * @method float getStoreToBaseRate() + * @method Mage_Sales_Model_Quote setStoreToBaseRate(float $value) + * @method float getStoreToQuoteRate() + * @method Mage_Sales_Model_Quote setStoreToQuoteRate(float $value) + * @method string getBaseCurrencyCode() + * @method Mage_Sales_Model_Quote setBaseCurrencyCode(string $value) + * @method string getStoreCurrencyCode() + * @method Mage_Sales_Model_Quote setStoreCurrencyCode(string $value) + * @method string getQuoteCurrencyCode() + * @method Mage_Sales_Model_Quote setQuoteCurrencyCode(string $value) + * @method float getGrandTotal() + * @method Mage_Sales_Model_Quote setGrandTotal(float $value) + * @method float getBaseGrandTotal() + * @method Mage_Sales_Model_Quote setBaseGrandTotal(float $value) + * @method Mage_Sales_Model_Quote setCheckoutMethod(string $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Quote setCustomerId(int $value) + * @method Mage_Sales_Model_Quote setCustomerTaxClassId(int $value) + * @method Mage_Sales_Model_Quote setCustomerGroupId(int $value) + * @method string getCustomerEmail() + * @method Mage_Sales_Model_Quote setCustomerEmail(string $value) + * @method string getCustomerPrefix() + * @method Mage_Sales_Model_Quote setCustomerPrefix(string $value) + * @method string getCustomerFirstname() + * @method Mage_Sales_Model_Quote setCustomerFirstname(string $value) + * @method string getCustomerMiddlename() + * @method Mage_Sales_Model_Quote setCustomerMiddlename(string $value) + * @method string getCustomerLastname() + * @method Mage_Sales_Model_Quote setCustomerLastname(string $value) + * @method string getCustomerSuffix() + * @method Mage_Sales_Model_Quote setCustomerSuffix(string $value) + * @method string getCustomerDob() + * @method Mage_Sales_Model_Quote setCustomerDob(string $value) + * @method string getCustomerNote() + * @method Mage_Sales_Model_Quote setCustomerNote(string $value) + * @method int getCustomerNoteNotify() + * @method Mage_Sales_Model_Quote setCustomerNoteNotify(int $value) + * @method int getCustomerIsGuest() + * @method Mage_Sales_Model_Quote setCustomerIsGuest(int $value) + * @method string getRemoteIp() + * @method Mage_Sales_Model_Quote setRemoteIp(string $value) + * @method string getAppliedRuleIds() + * @method Mage_Sales_Model_Quote setAppliedRuleIds(string $value) + * @method string getReservedOrderId() + * @method Mage_Sales_Model_Quote setReservedOrderId(string $value) + * @method string getPasswordHash() + * @method Mage_Sales_Model_Quote setPasswordHash(string $value) + * @method string getCouponCode() + * @method Mage_Sales_Model_Quote setCouponCode(string $value) + * @method string getGlobalCurrencyCode() + * @method Mage_Sales_Model_Quote setGlobalCurrencyCode(string $value) + * @method float getBaseToGlobalRate() + * @method Mage_Sales_Model_Quote setBaseToGlobalRate(float $value) + * @method float getBaseToQuoteRate() + * @method Mage_Sales_Model_Quote setBaseToQuoteRate(float $value) + * @method string getCustomerTaxvat() + * @method Mage_Sales_Model_Quote setCustomerTaxvat(string $value) + * @method string getCustomerGender() + * @method Mage_Sales_Model_Quote setCustomerGender(string $value) + * @method float getSubtotal() + * @method Mage_Sales_Model_Quote setSubtotal(float $value) + * @method float getBaseSubtotal() + * @method Mage_Sales_Model_Quote setBaseSubtotal(float $value) + * @method float getSubtotalWithDiscount() + * @method Mage_Sales_Model_Quote setSubtotalWithDiscount(float $value) + * @method float getBaseSubtotalWithDiscount() + * @method Mage_Sales_Model_Quote setBaseSubtotalWithDiscount(float $value) + * @method int getIsChanged() + * @method Mage_Sales_Model_Quote setIsChanged(int $value) + * @method int getTriggerRecollect() + * @method Mage_Sales_Model_Quote setTriggerRecollect(int $value) + * @method string getExtShippingInfo() + * @method Mage_Sales_Model_Quote setExtShippingInfo(string $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Quote setGiftMessageId(int $value) + * + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ class Mage_Sales_Model_Quote extends Mage_Core_Model_Abstract @@ -77,6 +175,18 @@ protected function _construct() $this->_init('sales/quote'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('quote'); + return $this; + } + /** * Get quote store identifier * diff --git a/app/code/core/Mage/Sales/Model/Quote/Address.php b/app/code/core/Mage/Sales/Model/Quote/Address.php index d0f6bbb678..d1099ac7fc 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,114 @@ /** * Sales Quote address model * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @method Mage_Sales_Model_Resource_Quote_Address _getResource() + * @method Mage_Sales_Model_Resource_Quote_Address getResource() + * @method int getQuoteId() + * @method Mage_Sales_Model_Quote_Address setQuoteId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote_Address setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote_Address setUpdatedAt(string $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Quote_Address setCustomerId(int $value) + * @method int getSaveInAddressBook() + * @method Mage_Sales_Model_Quote_Address setSaveInAddressBook(int $value) + * @method int getCustomerAddressId() + * @method Mage_Sales_Model_Quote_Address setCustomerAddressId(int $value) + * @method string getAddressType() + * @method Mage_Sales_Model_Quote_Address setAddressType(string $value) + * @method string getEmail() + * @method Mage_Sales_Model_Quote_Address setEmail(string $value) + * @method string getPrefix() + * @method Mage_Sales_Model_Quote_Address setPrefix(string $value) + * @method string getFirstname() + * @method Mage_Sales_Model_Quote_Address setFirstname(string $value) + * @method string getMiddlename() + * @method Mage_Sales_Model_Quote_Address setMiddlename(string $value) + * @method string getLastname() + * @method Mage_Sales_Model_Quote_Address setLastname(string $value) + * @method string getSuffix() + * @method Mage_Sales_Model_Quote_Address setSuffix(string $value) + * @method string getCompany() + * @method Mage_Sales_Model_Quote_Address setCompany(string $value) + * @method string getCity() + * @method Mage_Sales_Model_Quote_Address setCity(string $value) + * @method Mage_Sales_Model_Quote_Address setRegion(string $value) + * @method Mage_Sales_Model_Quote_Address setRegionId(int $value) + * @method string getPostcode() + * @method Mage_Sales_Model_Quote_Address setPostcode(string $value) + * @method string getCountryId() + * @method Mage_Sales_Model_Quote_Address setCountryId(string $value) + * @method string getTelephone() + * @method Mage_Sales_Model_Quote_Address setTelephone(string $value) + * @method string getFax() + * @method Mage_Sales_Model_Quote_Address setFax(string $value) + * @method int getSameAsBilling() + * @method Mage_Sales_Model_Quote_Address setSameAsBilling(int $value) + * @method int getFreeShipping() + * @method Mage_Sales_Model_Quote_Address setFreeShipping(int $value) + * @method int getCollectShippingRates() + * @method Mage_Sales_Model_Quote_Address setCollectShippingRates(int $value) + * @method string getShippingMethod() + * @method Mage_Sales_Model_Quote_Address setShippingMethod(string $value) + * @method string getShippingDescription() + * @method Mage_Sales_Model_Quote_Address setShippingDescription(string $value) + * @method float getWeight() + * @method Mage_Sales_Model_Quote_Address setWeight(float $value) + * @method float getSubtotal() + * @method Mage_Sales_Model_Quote_Address setSubtotal(float $value) + * @method float getBaseSubtotal() + * @method Mage_Sales_Model_Quote_Address setBaseSubtotal(float $value) + * @method Mage_Sales_Model_Quote_Address setSubtotalWithDiscount(float $value) + * @method Mage_Sales_Model_Quote_Address setBaseSubtotalWithDiscount(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Quote_Address setTaxAmount(float $value) + * @method float getBaseTaxAmount() + * @method Mage_Sales_Model_Quote_Address setBaseTaxAmount(float $value) + * @method float getShippingAmount() + * @method float getBaseShippingAmount() + * @method float getShippingTaxAmount() + * @method Mage_Sales_Model_Quote_Address setShippingTaxAmount(float $value) + * @method float getBaseShippingTaxAmount() + * @method Mage_Sales_Model_Quote_Address setBaseShippingTaxAmount(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Quote_Address setDiscountAmount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Quote_Address setBaseDiscountAmount(float $value) + * @method float getGrandTotal() + * @method Mage_Sales_Model_Quote_Address setGrandTotal(float $value) + * @method float getBaseGrandTotal() + * @method Mage_Sales_Model_Quote_Address setBaseGrandTotal(float $value) + * @method string getCustomerNotes() + * @method Mage_Sales_Model_Quote_Address setCustomerNotes(string $value) + * @method string getDiscountDescription() + * @method Mage_Sales_Model_Quote_Address setDiscountDescription(string $value) + * @method float getShippingDiscountAmount() + * @method Mage_Sales_Model_Quote_Address setShippingDiscountAmount(float $value) + * @method float getBaseShippingDiscountAmount() + * @method Mage_Sales_Model_Quote_Address setBaseShippingDiscountAmount(float $value) + * @method float getSubtotalInclTax() + * @method Mage_Sales_Model_Quote_Address setSubtotalInclTax(float $value) + * @method float getBaseSubtotalTotalInclTax() + * @method Mage_Sales_Model_Quote_Address setBaseSubtotalTotalInclTax(float $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Quote_Address setGiftMessageId(int $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address setBaseHiddenTaxAmount(float $value) + * @method float getShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address setShippingHiddenTaxAmount(float $value) + * @method float getBaseShippingHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address setBaseShippingHiddenTaxAmount(float $value) + * @method float getShippingInclTax() + * @method Mage_Sales_Model_Quote_Address setShippingInclTax(float $value) + * @method float getBaseShippingInclTax() + * @method Mage_Sales_Model_Quote_Address setBaseShippingInclTax(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Quote_Address extends Mage_Customer_Model_Address_Abstract { @@ -95,6 +200,17 @@ protected function _construct() $this->_init('sales/quote_address'); } + /** + * Init mapping array of short fields to its full names + * + * @return Mage_Sales_Model_Quote_Address + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('quote_address'); + return $this; + } + /** * Initialize quote identifier before save * diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Item.php b/app/code/core/Mage/Sales/Model/Quote/Address/Item.php index 2f0a770248..cb4f05ae1e 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Item.php @@ -20,11 +20,94 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Quote_Address_Item _getResource() + * @method Mage_Sales_Model_Resource_Quote_Address_Item getResource() + * @method int getParentItemId() + * @method Mage_Sales_Model_Quote_Address_Item setParentItemId(int $value) + * @method int getQuoteAddressId() + * @method Mage_Sales_Model_Quote_Address_Item setQuoteAddressId(int $value) + * @method int getQuoteItemId() + * @method Mage_Sales_Model_Quote_Address_Item setQuoteItemId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote_Address_Item setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote_Address_Item setUpdatedAt(string $value) + * @method string getAppliedRuleIds() + * @method Mage_Sales_Model_Quote_Address_Item setAppliedRuleIds(string $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Quote_Address_Item setAdditionalData(string $value) + * @method float getWeight() + * @method Mage_Sales_Model_Quote_Address_Item setWeight(float $value) + * @method Mage_Sales_Model_Quote_Address_Item setQty(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Quote_Address_Item setDiscountAmount(float $value) + * @method Mage_Sales_Model_Quote_Address_Item setTaxAmount(float $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Quote_Address_Item setRowTotal(float $value) + * @method float getBaseRowTotal() + * @method Mage_Sales_Model_Quote_Address_Item setBaseRowTotal(float $value) + * @method float getRowTotalWithDiscount() + * @method Mage_Sales_Model_Quote_Address_Item setRowTotalWithDiscount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Quote_Address_Item setBaseDiscountAmount(float $value) + * @method Mage_Sales_Model_Quote_Address_Item setBaseTaxAmount(float $value) + * @method float getRowWeight() + * @method Mage_Sales_Model_Quote_Address_Item setRowWeight(float $value) + * @method int getProductId() + * @method Mage_Sales_Model_Quote_Address_Item setProductId(int $value) + * @method int getSuperProductId() + * @method Mage_Sales_Model_Quote_Address_Item setSuperProductId(int $value) + * @method int getParentProductId() + * @method Mage_Sales_Model_Quote_Address_Item setParentProductId(int $value) + * @method string getSku() + * @method Mage_Sales_Model_Quote_Address_Item setSku(string $value) + * @method string getImage() + * @method Mage_Sales_Model_Quote_Address_Item setImage(string $value) + * @method string getName() + * @method Mage_Sales_Model_Quote_Address_Item setName(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Quote_Address_Item setDescription(string $value) + * @method int getFreeShipping() + * @method Mage_Sales_Model_Quote_Address_Item setFreeShipping(int $value) + * @method int getIsQtyDecimal() + * @method Mage_Sales_Model_Quote_Address_Item setIsQtyDecimal(int $value) + * @method float getDiscountPercent() + * @method Mage_Sales_Model_Quote_Address_Item setDiscountPercent(float $value) + * @method int getNoDiscount() + * @method Mage_Sales_Model_Quote_Address_Item setNoDiscount(int $value) + * @method float getTaxPercent() + * @method Mage_Sales_Model_Quote_Address_Item setTaxPercent(float $value) + * @method float getBasePrice() + * @method Mage_Sales_Model_Quote_Address_Item setBasePrice(float $value) + * @method float getBaseCost() + * @method Mage_Sales_Model_Quote_Address_Item setBaseCost(float $value) + * @method float getPriceInclTax() + * @method Mage_Sales_Model_Quote_Address_Item setPriceInclTax(float $value) + * @method float getBasePriceInclTax() + * @method Mage_Sales_Model_Quote_Address_Item setBasePriceInclTax(float $value) + * @method float getRowTotalInclTax() + * @method Mage_Sales_Model_Quote_Address_Item setRowTotalInclTax(float $value) + * @method float getBaseRowTotalInclTax() + * @method Mage_Sales_Model_Quote_Address_Item setBaseRowTotalInclTax(float $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Quote_Address_Item setGiftMessageId(int $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address_Item setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Address_Item setBaseHiddenTaxAmount(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Quote_Address_Item extends Mage_Sales_Model_Quote_Item_Abstract { /** diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Rate.php b/app/code/core/Mage/Sales/Model/Quote/Address/Rate.php index a2f1b38fbe..8d5f0340e4 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Rate.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Rate.php @@ -20,11 +20,43 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Sales_Model_Resource_Quote_Address_Rate _getResource() + * @method Mage_Sales_Model_Resource_Quote_Address_Rate getResource() + * @method int getAddressId() + * @method Mage_Sales_Model_Quote_Address_Rate setAddressId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote_Address_Rate setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote_Address_Rate setUpdatedAt(string $value) + * @method string getCarrier() + * @method Mage_Sales_Model_Quote_Address_Rate setCarrier(string $value) + * @method string getCarrierTitle() + * @method Mage_Sales_Model_Quote_Address_Rate setCarrierTitle(string $value) + * @method string getCode() + * @method Mage_Sales_Model_Quote_Address_Rate setCode(string $value) + * @method string getMethod() + * @method Mage_Sales_Model_Quote_Address_Rate setMethod(string $value) + * @method string getMethodDescription() + * @method Mage_Sales_Model_Quote_Address_Rate setMethodDescription(string $value) + * @method float getPrice() + * @method Mage_Sales_Model_Quote_Address_Rate setPrice(float $value) + * @method string getErrorMessage() + * @method Mage_Sales_Model_Quote_Address_Rate setErrorMessage(string $value) + * @method string getMethodTitle() + * @method Mage_Sales_Model_Quote_Address_Rate setMethodTitle(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team + */ class Mage_Sales_Model_Quote_Address_Rate extends Mage_Shipping_Model_Rate_Abstract { protected $_address; diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total.php index a813fbc23c..1d8696b1da 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Abstract.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Abstract.php index 162196700a..3761bd16e1 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Collector.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Collector.php index 6d93b867bb..c6e52ee60e 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Collector.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Collector.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Custbalance.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Custbalance.php index 3eb9debba2..aa62d63bac 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Custbalance.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Custbalance.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Discount.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Discount.php index 5447287803..3a2e77b197 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Discount.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Grand.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Grand.php index d9cea8aec1..f52e404111 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Grand.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Grand.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal.php index 464a84bde9..252818621e 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Collector.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Collector.php index c23aaae430..c96a0b3622 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Collector.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Collector.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Initial.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Initial.php index afc6ea1cbf..a5739429b4 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Initial.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Initial.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Trial.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Trial.php index 1f8184a314..12438d220e 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Trial.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Recurring/Trial.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/RecurringAbstract.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/RecurringAbstract.php index 77bb5e2a76..ac0c77b096 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/RecurringAbstract.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/RecurringAbstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Shipping.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Shipping.php index e4a82a6039..0434115440 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php index ec229e03b1..8b41e872a0 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php index 6fd92aae57..4329fe555a 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php index d3a143e957..5fbc890cbd 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php index ed40aaa7e3..1645cf7997 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php +++ b/app/code/core/Mage/Sales/Model/Quote/Address/Total/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Config.php b/app/code/core/Mage/Sales/Model/Quote/Config.php index 4da3e404fc..f1842a6b13 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Config.php +++ b/app/code/core/Mage/Sales/Model/Quote/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Item.php b/app/code/core/Mage/Sales/Model/Quote/Item.php index aefb7ac618..727d47cb23 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,108 @@ /** * Sales Quote Item Model * - * @category Mage - * @package Mage_Sales - * @author Magento Core Team + * @method Mage_Sales_Model_Resource_Quote_Item _getResource() + * @method Mage_Sales_Model_Resource_Quote_Item getResource() + * @method int getQuoteId() + * @method Mage_Sales_Model_Quote_Item setQuoteId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote_Item setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote_Item setUpdatedAt(string $value) + * @method int getProductId() + * @method Mage_Sales_Model_Quote_Item setProductId(int $value) + * @method int getStoreId() + * @method Mage_Sales_Model_Quote_Item setStoreId(int $value) + * @method int getParentItemId() + * @method Mage_Sales_Model_Quote_Item setParentItemId(int $value) + * @method int getIsVirtual() + * @method Mage_Sales_Model_Quote_Item setIsVirtual(int $value) + * @method string getSku() + * @method Mage_Sales_Model_Quote_Item setSku(string $value) + * @method string getName() + * @method Mage_Sales_Model_Quote_Item setName(string $value) + * @method string getDescription() + * @method Mage_Sales_Model_Quote_Item setDescription(string $value) + * @method string getAppliedRuleIds() + * @method Mage_Sales_Model_Quote_Item setAppliedRuleIds(string $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Quote_Item setAdditionalData(string $value) + * @method int getFreeShipping() + * @method Mage_Sales_Model_Quote_Item setFreeShipping(int $value) + * @method int getIsQtyDecimal() + * @method Mage_Sales_Model_Quote_Item setIsQtyDecimal(int $value) + * @method int getNoDiscount() + * @method Mage_Sales_Model_Quote_Item setNoDiscount(int $value) + * @method float getWeight() + * @method Mage_Sales_Model_Quote_Item setWeight(float $value) + * @method float getBasePrice() + * @method Mage_Sales_Model_Quote_Item setBasePrice(float $value) + * @method float getCustomPrice() + * @method float getDiscountPercent() + * @method Mage_Sales_Model_Quote_Item setDiscountPercent(float $value) + * @method float getDiscountAmount() + * @method Mage_Sales_Model_Quote_Item setDiscountAmount(float $value) + * @method float getBaseDiscountAmount() + * @method Mage_Sales_Model_Quote_Item setBaseDiscountAmount(float $value) + * @method float getTaxPercent() + * @method Mage_Sales_Model_Quote_Item setTaxPercent(float $value) + * @method Mage_Sales_Model_Quote_Item setTaxAmount(float $value) + * @method Mage_Sales_Model_Quote_Item setBaseTaxAmount(float $value) + * @method float getRowTotal() + * @method Mage_Sales_Model_Quote_Item setRowTotal(float $value) + * @method float getBaseRowTotal() + * @method Mage_Sales_Model_Quote_Item setBaseRowTotal(float $value) + * @method float getRowTotalWithDiscount() + * @method Mage_Sales_Model_Quote_Item setRowTotalWithDiscount(float $value) + * @method float getRowWeight() + * @method Mage_Sales_Model_Quote_Item setRowWeight(float $value) + * @method Mage_Sales_Model_Quote_Item setProductType(string $value) + * @method float getBaseTaxBeforeDiscount() + * @method Mage_Sales_Model_Quote_Item setBaseTaxBeforeDiscount(float $value) + * @method float getTaxBeforeDiscount() + * @method Mage_Sales_Model_Quote_Item setTaxBeforeDiscount(float $value) + * @method float getOriginalCustomPrice() + * @method Mage_Sales_Model_Quote_Item setOriginalCustomPrice(float $value) + * @method string getRedirectUrl() + * @method Mage_Sales_Model_Quote_Item setRedirectUrl(string $value) + * @method float getBaseCost() + * @method Mage_Sales_Model_Quote_Item setBaseCost(float $value) + * @method float getPriceInclTax() + * @method Mage_Sales_Model_Quote_Item setPriceInclTax(float $value) + * @method float getBasePriceInclTax() + * @method Mage_Sales_Model_Quote_Item setBasePriceInclTax(float $value) + * @method float getRowTotalInclTax() + * @method Mage_Sales_Model_Quote_Item setRowTotalInclTax(float $value) + * @method float getBaseRowTotalInclTax() + * @method Mage_Sales_Model_Quote_Item setBaseRowTotalInclTax(float $value) + * @method int getGiftMessageId() + * @method Mage_Sales_Model_Quote_Item setGiftMessageId(int $value) + * @method string getWeeeTaxApplied() + * @method Mage_Sales_Model_Quote_Item setWeeeTaxApplied(string $value) + * @method float getWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Quote_Item setWeeeTaxAppliedAmount(float $value) + * @method float getWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Quote_Item setWeeeTaxAppliedRowAmount(float $value) + * @method float getBaseWeeeTaxAppliedAmount() + * @method Mage_Sales_Model_Quote_Item setBaseWeeeTaxAppliedAmount(float $value) + * @method float getBaseWeeeTaxAppliedRowAmount() + * @method Mage_Sales_Model_Quote_Item setBaseWeeeTaxAppliedRowAmount(float $value) + * @method float getWeeeTaxDisposition() + * @method Mage_Sales_Model_Quote_Item setWeeeTaxDisposition(float $value) + * @method float getWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Quote_Item setWeeeTaxRowDisposition(float $value) + * @method float getBaseWeeeTaxDisposition() + * @method Mage_Sales_Model_Quote_Item setBaseWeeeTaxDisposition(float $value) + * @method float getBaseWeeeTaxRowDisposition() + * @method Mage_Sales_Model_Quote_Item setBaseWeeeTaxRowDisposition(float $value) + * @method float getHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Item setHiddenTaxAmount(float $value) + * @method float getBaseHiddenTaxAmount() + * @method Mage_Sales_Model_Quote_Item setBaseHiddenTaxAmount(float $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Quote_Item extends Mage_Sales_Model_Quote_Item_Abstract { @@ -93,6 +192,18 @@ protected function _construct() $this->_init('sales/quote_item'); } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('quote_item'); + return $this; + } + /** * Quote Item Before Save prepare data process * diff --git a/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php b/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php index 5cebc4001a..92c226e077 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Quote/Item/Option.php b/app/code/core/Mage/Sales/Model/Quote/Item/Option.php index 71113cde4b..5791d29c81 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item/Option.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item/Option.php @@ -20,13 +20,24 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Item option model * + * @method Mage_Sales_Model_Resource_Quote_Item_Option _getResource() + * @method Mage_Sales_Model_Resource_Quote_Item_Option getResource() + * @method int getItemId() + * @method Mage_Sales_Model_Quote_Item_Option setItemId(int $value) + * @method int getProductId() + * @method Mage_Sales_Model_Quote_Item_Option setProductId(int $value) + * @method string getCode() + * @method Mage_Sales_Model_Quote_Item_Option setCode(string $value) + * @method string getValue() + * @method Mage_Sales_Model_Quote_Item_Option setValue(string $value) + * * @category Mage * @package Mage_Sales * @author Magento Core Team diff --git a/app/code/core/Mage/Sales/Model/Quote/Payment.php b/app/code/core/Mage/Sales/Model/Quote/Payment.php index ea45ee5b09..8c6ba65269 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Payment.php +++ b/app/code/core/Mage/Sales/Model/Quote/Payment.php @@ -20,12 +20,65 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Quote payment information + * + * @method Mage_Sales_Model_Resource_Quote_Payment _getResource() + * @method Mage_Sales_Model_Resource_Quote_Payment getResource() + * @method int getQuoteId() + * @method Mage_Sales_Model_Quote_Payment setQuoteId(int $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Quote_Payment setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Quote_Payment setUpdatedAt(string $value) + * @method string getMethod() + * @method Mage_Sales_Model_Quote_Payment setMethod(string $value) + * @method string getCcType() + * @method Mage_Sales_Model_Quote_Payment setCcType(string $value) + * @method string getCcNumberEnc() + * @method Mage_Sales_Model_Quote_Payment setCcNumberEnc(string $value) + * @method string getCcLast4() + * @method Mage_Sales_Model_Quote_Payment setCcLast4(string $value) + * @method string getCcCidEnc() + * @method Mage_Sales_Model_Quote_Payment setCcCidEnc(string $value) + * @method string getCcOwner() + * @method Mage_Sales_Model_Quote_Payment setCcOwner(string $value) + * @method int getCcExpMonth() + * @method Mage_Sales_Model_Quote_Payment setCcExpMonth(int $value) + * @method int getCcExpYear() + * @method Mage_Sales_Model_Quote_Payment setCcExpYear(int $value) + * @method string getCcSsOwner() + * @method Mage_Sales_Model_Quote_Payment setCcSsOwner(string $value) + * @method int getCcSsStartMonth() + * @method Mage_Sales_Model_Quote_Payment setCcSsStartMonth(int $value) + * @method int getCcSsStartYear() + * @method Mage_Sales_Model_Quote_Payment setCcSsStartYear(int $value) + * @method string getCybersourceToken() + * @method Mage_Sales_Model_Quote_Payment setCybersourceToken(string $value) + * @method string getPaypalCorrelationId() + * @method Mage_Sales_Model_Quote_Payment setPaypalCorrelationId(string $value) + * @method string getPaypalPayerId() + * @method Mage_Sales_Model_Quote_Payment setPaypalPayerId(string $value) + * @method string getPaypalPayerStatus() + * @method Mage_Sales_Model_Quote_Payment setPaypalPayerStatus(string $value) + * @method string getPoNumber() + * @method Mage_Sales_Model_Quote_Payment setPoNumber(string $value) + * @method string getAdditionalData() + * @method Mage_Sales_Model_Quote_Payment setAdditionalData(string $value) + * @method string getCcSsIssue() + * @method Mage_Sales_Model_Quote_Payment setCcSsIssue(string $value) + * @method string getIdealIssuerId() + * @method Mage_Sales_Model_Quote_Payment setIdealIssuerId(string $value) + * @method string getIdealIssuerList() + * @method Mage_Sales_Model_Quote_Payment setIdealIssuerList(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Quote_Payment extends Mage_Payment_Model_Info { diff --git a/app/code/core/Mage/Sales/Model/Recurring/Profile.php b/app/code/core/Mage/Sales/Model/Recurring/Profile.php index 00083f4e7b..8602916391 100644 --- a/app/code/core/Mage/Sales/Model/Recurring/Profile.php +++ b/app/code/core/Mage/Sales/Model/Recurring/Profile.php @@ -20,13 +20,84 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Sales implementation of recurring payment profiles * Implements saving and manageing profiles + * + * @method Mage_Sales_Model_Resource_Recurring_Profile _getResource() + * @method Mage_Sales_Model_Resource_Recurring_Profile getResource() + * @method string getState() + * @method Mage_Sales_Model_Recurring_Profile setState(string $value) + * @method int getCustomerId() + * @method Mage_Sales_Model_Recurring_Profile setCustomerId(int $value) + * @method int getStoreId() + * @method Mage_Sales_Model_Recurring_Profile setStoreId(int $value) + * @method string getMethodCode() + * @method Mage_Sales_Model_Recurring_Profile setMethodCode(string $value) + * @method string getCreatedAt() + * @method Mage_Sales_Model_Recurring_Profile setCreatedAt(string $value) + * @method string getUpdatedAt() + * @method Mage_Sales_Model_Recurring_Profile setUpdatedAt(string $value) + * @method string getReferenceId() + * @method Mage_Sales_Model_Recurring_Profile setReferenceId(string $value) + * @method string getSubscriberName() + * @method Mage_Sales_Model_Recurring_Profile setSubscriberName(string $value) + * @method string getStartDatetime() + * @method Mage_Sales_Model_Recurring_Profile setStartDatetime(string $value) + * @method string getInternalReferenceId() + * @method Mage_Sales_Model_Recurring_Profile setInternalReferenceId(string $value) + * @method string getScheduleDescription() + * @method Mage_Sales_Model_Recurring_Profile setScheduleDescription(string $value) + * @method int getSuspensionThreshold() + * @method Mage_Sales_Model_Recurring_Profile setSuspensionThreshold(int $value) + * @method int getBillFailedLater() + * @method Mage_Sales_Model_Recurring_Profile setBillFailedLater(int $value) + * @method string getPeriodUnit() + * @method Mage_Sales_Model_Recurring_Profile setPeriodUnit(string $value) + * @method int getPeriodFrequency() + * @method Mage_Sales_Model_Recurring_Profile setPeriodFrequency(int $value) + * @method int getPeriodMaxCycles() + * @method Mage_Sales_Model_Recurring_Profile setPeriodMaxCycles(int $value) + * @method float getBillingAmount() + * @method Mage_Sales_Model_Recurring_Profile setBillingAmount(float $value) + * @method string getTrialPeriodUnit() + * @method Mage_Sales_Model_Recurring_Profile setTrialPeriodUnit(string $value) + * @method int getTrialPeriodFrequency() + * @method Mage_Sales_Model_Recurring_Profile setTrialPeriodFrequency(int $value) + * @method int getTrialPeriodMaxCycles() + * @method Mage_Sales_Model_Recurring_Profile setTrialPeriodMaxCycles(int $value) + * @method float getTrialBillingAmount() + * @method Mage_Sales_Model_Recurring_Profile setTrialBillingAmount(float $value) + * @method string getCurrencyCode() + * @method Mage_Sales_Model_Recurring_Profile setCurrencyCode(string $value) + * @method float getShippingAmount() + * @method Mage_Sales_Model_Recurring_Profile setShippingAmount(float $value) + * @method float getTaxAmount() + * @method Mage_Sales_Model_Recurring_Profile setTaxAmount(float $value) + * @method float getInitAmount() + * @method Mage_Sales_Model_Recurring_Profile setInitAmount(float $value) + * @method int getInitMayFail() + * @method Mage_Sales_Model_Recurring_Profile setInitMayFail(int $value) + * @method string getOrderInfo() + * @method Mage_Sales_Model_Recurring_Profile setOrderInfo(string $value) + * @method string getOrderItemInfo() + * @method Mage_Sales_Model_Recurring_Profile setOrderItemInfo(string $value) + * @method string getBillingAddressInfo() + * @method Mage_Sales_Model_Recurring_Profile setBillingAddressInfo(string $value) + * @method string getShippingAddressInfo() + * @method Mage_Sales_Model_Recurring_Profile setShippingAddressInfo(string $value) + * @method string getProfileVendorInfo() + * @method Mage_Sales_Model_Recurring_Profile setProfileVendorInfo(string $value) + * @method string getAdditionalInfo() + * @method Mage_Sales_Model_Recurring_Profile setAdditionalInfo(string $value) + * + * @category Mage + * @package Mage_Sales + * @author Magento Core Team */ class Mage_Sales_Model_Recurring_Profile extends Mage_Payment_Model_Recurring_Profile { diff --git a/app/code/core/Mage/Sales/Model/Resource/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Abstract.php new file mode 100755 index 0000000000..3856210933 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Abstract.php @@ -0,0 +1,53 @@ + + */ +abstract class Mage_Sales_Model_Resource_Abstract extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Prepare data for save + * + * @param Mage_Core_Model_Abstract $object + * @return array + */ + protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) + { + $currentTime = Varien_Date::now(); + if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) { + $object->setCreatedAt($currentTime); + } + $object->setUpdatedAt($currentTime); + $data = parent::_prepareDataForSave($object); + return $data; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement.php b/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement.php new file mode 100755 index 0000000000..c76a6573b3 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement.php @@ -0,0 +1,63 @@ + + */ +class Mage_Sales_Model_Resource_Billing_Agreement extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/billing_agreement', 'agreement_id'); + } + + /** + * Add order relation to billing agreement + * + * @param int $agreementId + * @param int $orderId + * @return Mage_Sales_Model_Resource_Billing_Agreement + */ + public function addOrderRelation($agreementId, $orderId) + { + $this->_getWriteAdapter()->insert( + $this->getTable('sales/billing_agreement_order'), array( + 'agreement_id' => $agreementId, + 'order_id' => $orderId + ) + ); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement/Collection.php new file mode 100755 index 0000000000..982186d27d --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Billing/Agreement/Collection.php @@ -0,0 +1,84 @@ + + */ +class Mage_Sales_Model_Resource_Billing_Agreement_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Collection initialization + * + */ + protected function _construct() + { + $this->_init('sales/billing_agreement'); + } + + /** + * Add cutomer details(email, firstname, lastname) to select + * + * @return Mage_Sales_Model_Resource_Billing_Agreement_Collection + */ + public function addCustomerDetails() + { + $select = $this->getSelect()->joinInner( + array('ce' => $this->getTable('customer/entity')), + 'ce.entity_id = main_table.customer_id', + array('customer_email' => 'email') + ); + + $customer = Mage::getResourceSingleton('customer/customer'); + $adapter = $this->getConnection(); + $attr = $customer->getAttribute('firstname'); + $joinExpr = 'firstname.entity_id = main_table.customer_id AND ' + . $adapter->quoteInto('firstname.entity_type_id = ?', $customer->getTypeId()) . ' AND ' + . $adapter->quoteInto('firstname.attribute_id = ?', $attr->getAttributeId()); + + $select->joinLeft( + array('firstname' => $attr->getBackend()->getTable()), + $joinExpr, + array('customer_firstname' => 'value') + ); + + $attr = $customer->getAttribute('lastname'); + $joinExpr = 'lastname.entity_id = main_table.customer_id AND ' + . $adapter->quoteInto('lastname.entity_type_id = ?', $customer->getTypeId()) . ' AND ' + . $adapter->quoteInto('lastname.attribute_id = ?', $attr->getAttributeId()); + + $select->joinLeft( + array('lastname' => $attr->getBackend()->getTable()), + $joinExpr, + array('customer_lastname' => 'value') + ); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php new file mode 100755 index 0000000000..5aa6010991 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Collection/Abstract.php @@ -0,0 +1,166 @@ + + */ +abstract class Mage_Sales_Model_Resource_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Check if $attribute is Mage_Eav_Model_Entity_Attribute and convert to string field name + * + * @param string|Mage_Eav_Model_Entity_Attribute $attribute + * @return string + */ + protected function _attributeToField($attribute) + { + $field = false; + if (is_string($attribute)) { + $field = $attribute; + } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute) { + $field = $attribute->getAttributeCode(); + } + if (!$field) { + Mage::throwException(Mage::helper('sales')->__('Cannot determine the field name.')); + } + return $field; + } + + /** + * Add attribute to select result set. + * Backward compatibility with EAV collection + * + * @param string $attribute + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function addAttributeToSelect($attribute) + { + $this->addFieldToSelect($this->_attributeToField($attribute)); + return $this; + } + + /** + * Specify collection select filter by attribute value + * Backward compatibility with EAV collection + * + * @param string|Mage_Eav_Model_Entity_Attribute $attribute + * @param array|integer|string|null $condition + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function addAttributeToFilter($attribute, $condition = null) + { + $this->addFieldToFilter($this->_attributeToField($attribute), $condition); + return $this; + } + + /** + * Specify collection select order by attribute value + * Backward compatibility with EAV collection + * + * @param string $attribute + * @param string $dir + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function addAttributeToSort($attribute, $dir = 'asc') + { + $this->addOrder($this->_attributeToField($attribute), $dir); + return $this; + } + + /** + * Set collection page start and records to show + * Backward compatibility with EAV collection + * + * @param integer $pageNum + * @param integer $pageSize + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function setPage($pageNum, $pageSize) + { + $this->setCurPage($pageNum) + ->setPageSize($pageSize); + return $this; + } + + /** + * Create all ids retrieving select with limitation + * Backward compatibility with EAV collection + * + * @param int $limit + * @param int $offset + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + protected function _getAllIdsSelect($limit = null, $offset = null) + { + $idsSelect = clone $this->getSelect(); + $idsSelect->reset(Zend_Db_Select::ORDER); + $idsSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $idsSelect->reset(Zend_Db_Select::COLUMNS); + $idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table'); + $idsSelect->limit($limit, $offset); + return $idsSelect; + } + + /** + * Retrive all ids for collection + * Backward compatibility with EAV collection + * + * @param int $limit + * @param int $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + return $this->getConnection()->fetchCol( + $this->_getAllIdsSelect($limit, $offset), + $this->_bindParams + ); + } + + /** + * Backward compatibility with EAV collection + * + * @todo implement join functionality if necessary + * + * @param string $alias + * @param string $attribute + * @param string $bind + * @param string $filter + * @param string $joinType + * @param int $storeId + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function joinAttribute($alias, $attribute, $bind, $filter = null, $joinType = 'inner', $storeId = null) + { + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Sales/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..e52f9b3af3 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,100 @@ + + */ +class Mage_Sales_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Mysql4 +{ + /** + * Update rating position + * + * @param string $aggregation One of Mage_Sales_Model_Resource_Report_Bestsellers::AGGREGATION_XXX constants + * @param array $aggregationAliases + * @param string $mainTable + * @param string $aggregationTable + * @return Mage_Sales_Model_Resource_Helper_Abstract + */ + public function getBestsellersReportUpdateRatingPos($aggregation, $aggregationAliases, + $mainTable, $aggregationTable + ) { + $adapter = $this->_getWriteAdapter(); + $periodSubSelect = $adapter->select(); + $ratingSubSelect = $adapter->select(); + $ratingSelect = $adapter->select(); + + $periodCol = 't.period'; + if ($aggregation == $aggregationAliases['monthly']) { + $periodCol = $adapter->getDateFormatSql('t.period', '%Y-%m-01'); + } elseif ($aggregation == $aggregationAliases['yearly']) { + $periodCol = $adapter->getDateFormatSql('t.period', '%Y-01-01'); + } + + $columns = array( + 'period' => 't.period', + 'store_id' => 't.store_id', + 'product_id' => 't.product_id', + 'product_name' => 't.product_name', + 'product_price' => 't.product_price', + ); + + if ($aggregation == $aggregationAliases['daily']) { + $columns['id'] = 't.id'; // to speed-up insert on duplicate key update + } + + $cols = array_keys($columns); + $cols['total_qty_ordered'] = new Zend_Db_Expr('SUM(t.qty_ordered)'); + $periodSubSelect->from(array('t' => $mainTable), $cols) + ->group(array('t.store_id', $periodCol, 't.product_id')) + ->order(array('t.store_id', $periodCol, 'total_qty_ordered DESC')); + + $cols = $columns; + $cols['qty_ordered'] = 't.total_qty_ordered'; + $cols['rating_pos'] = new Zend_Db_Expr( + "(@pos := IF(t.`store_id` <> @prevStoreId OR {$periodCol} <> @prevPeriod, 1, @pos+1))"); + $cols['prevStoreId'] = new Zend_Db_Expr('(@prevStoreId := t.`store_id`)'); + $cols['prevPeriod'] = new Zend_Db_Expr("(@prevPeriod := {$periodCol})"); + $ratingSubSelect->from($periodSubSelect, $cols); + + $cols = $columns; + $cols['period'] = $periodCol; // important! + $cols['qty_ordered'] = 't.qty_ordered'; + $cols['rating_pos'] = 't.rating_pos'; + $ratingSelect->from($ratingSubSelect, $cols); + + $sql = $ratingSelect->insertFromSelect($aggregationTable, array_keys($cols)); + $adapter->query("SET @pos = 0, @prevStoreId = -1, @prevPeriod = '0000-00-00'"); + + $adapter->query($sql); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order.php b/app/code/core/Mage/Sales/Model/Resource/Order.php new file mode 100755 index 0000000000..fc474c2201 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order.php @@ -0,0 +1,154 @@ + + */ +class Mage_Sales_Model_Resource_Order extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_resource'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'resource'; + + /** + * Is grid + * + * @var boolean + */ + protected $_grid = true; + + /** + * Use increment id + * + * @var boolean + */ + protected $_useIncrementId = true; + + /** + * Entity code for increment id + * + * @var string + */ + protected $_entityCodeForIncrementId = 'order'; + + /** + * Model Initialization + * + */ + protected function _construct() + { + $this->_init('sales/order', 'entity_id'); + } + + /** + * Init virtual grid records for entity + * + * @return Mage_Sales_Model_Resource_Order + */ + protected function _initVirtualGridColumns() + { + parent::_initVirtualGridColumns(); + $adapter = $this->getReadConnection(); + $ifnullFirst = $adapter->getIfNullSql('{{table}}.firstname', $adapter->quote('')); + $ifnullLast = $adapter->getIfNullSql('{{table}}.lastname', $adapter->quote('')); + $concatAddress = $adapter->getConcatSql(array($ifnullFirst, $adapter->quote(' '), $ifnullLast)); + $this->addVirtualGridColumn( + 'billing_name', + 'sales/order_address', + array('billing_address_id' => 'entity_id'), + $concatAddress + ) + ->addVirtualGridColumn( + 'shipping_name', + 'sales/order_address', + array('shipping_address_id' => 'entity_id'), + $concatAddress + ); + + return $this; + } + + /** + * Count existent products of order items by specified product types + * + * @param int $orderId + * @param array $productTypeIds + * @param bool $isProductTypeIn + * @return array + */ + public function aggregateProductsByTypes($orderId, $productTypeIds = array(), $isProductTypeIn = false) + { + $adapter = $this->getReadConnection(); + $select = $adapter->select() + ->from( + array('o' => $this->getTable('sales/order_item')), + array('o.product_type', new Zend_Db_Expr('COUNT(*)'))) + ->joinInner( + array('p' => $this->getTable('catalog/product')), + 'o.product_id=p.entity_id', + array()) + ->where('o.order_id=?', $orderId) + ->group('o.product_type') + ; + if ($productTypeIds) { + $select->where( + sprintf('(o.product_type %s (?))', ($isProductTypeIn ? 'IN' : 'NOT IN')), + $productTypeIds); + } + return $adapter->fetchPairs($select); + } + + /** + * Retrieve order_increment_id by order_id + * + * @param int $orderId + * @return string + */ + public function getIncrementId($orderId) + { + $adapter = $this->getReadConnection(); + $bind = array(':entity_id' => $orderId); + $select = $adapter->select() + ->from($this->getMainTable(), array("increment_id")) + ->where('entity_id = :entity_id'); + return $adapter->fetchOne($select, $bind); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Order/Abstract.php new file mode 100755 index 0000000000..33d4d2c7bf --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Abstract.php @@ -0,0 +1,430 @@ + + */ +abstract class Mage_Sales_Model_Resource_Order_Abstract extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Is grid available + * + * @var boolean + */ + protected $_grid = false; + + /** + * Use additional is object new check for this resource + * + * @var boolean + */ + protected $_useIsObjectNew = true; + + /** + * Flag for using of increment id + * + * @var boolean + */ + protected $_useIncrementId = false; + + /** + * Entity code for increment id (Eav entity code) + * + * @var string + */ + protected $_entityTypeForIncrementId = ''; + + /** + * Grid virtual columns + * + * @var array|null + */ + protected $_virtualGridColumns = null; + + /** + * Grid columns + * + * @var array|null + */ + protected $_gridColumns = null; + + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_resource'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'resource'; + + /** + * Add new virtual grid column + * + * @param string $alias + * @param string $table + * @param array $joinCondition + * @param string $column + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function addVirtualGridColumn($alias, $table, $joinCondition, $column) + { + $table = $this->getTable($table); + + if (!in_array($alias, $this->getGridColumns())) { + Mage::throwException( + Mage::helper('sales')->__('Please specify a valid grid column alias name that exists in grid table.') + ); + } + + $this->_virtualGridColumns[$alias] = array( + $table, $joinCondition, $column + ); + + return $this; + } + + /** + * Retrieve virtual grid columns + * + * @return array + */ + public function getVirtualGridColumns() + { + if ($this->_virtualGridColumns === null) { + $this->_initVirtualGridColumns(); + } + + return $this->_virtualGridColumns; + } + + /** + * Init virtual grid records for entity + * + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + protected function _initVirtualGridColumns() + { + $this->_virtualGridColumns = array(); + if ($this->_eventPrefix && $this->_eventObject) { + Mage::dispatchEvent($this->_eventPrefix . '_init_virtual_grid_columns', array( + $this->_eventObject => $this + )); + } + return $this; + } + + /** + * Update records in grid table + * + * @param array|int $ids + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function updateGridRecords($ids) + { + if ($this->_grid) { + if (!is_array($ids)) { + $ids = array($ids); + } + + if ($this->_eventPrefix && $this->_eventObject) { + $proxy = new Varien_Object(); + $proxy->setIds($ids) + ->setData($this->_eventObject, $this); + + Mage::dispatchEvent($this->_eventPrefix . '_update_grid_records', array('proxy' => $proxy)); + $ids = $proxy->getIds(); + } + + if (empty($ids)) { // If nothing to update + return $this; + } + $columnsToSelect = array(); + $table = $this->getGridTable(); + $select = $this->getUpdateGridRecordsSelect($ids, $columnsToSelect); + $this->_getWriteAdapter()->query($select->insertFromSelect($table, $columnsToSelect, true)); + } + + return $this; + } + + /** + * Retrieve update grid records select + * + * @param array $ids + * @param array $flatColumnsToSelect + * @param array|null $gridColumns + * @return Varien_Db_Select + */ + public function getUpdateGridRecordsSelect($ids, &$flatColumnsToSelect, $gridColumns = null) + { + $flatColumns = array_keys($this->_getReadAdapter() + ->describeTable( + $this->getMainTable() + ) + ); + + if ($gridColumns === null) { + $gridColumns = $this->getGridColumns(); + } + + $flatColumnsToSelect = array_intersect($flatColumns, $gridColumns); + + $select = $this->_getWriteAdapter()->select() + ->from(array('main_table' => $this->getMainTable()), $flatColumnsToSelect) + ->where('main_table.' . $this->getIdFieldName() . ' IN(?)', $ids); + + $this->joinVirtualGridColumnsToSelect('main_table', $select, $flatColumnsToSelect); + + return $select; + } + + /** + * Join virtual grid columns to select + * + * @param string $mainTableAlias + * @param Zend_Db_Select $select + * @param array $columnsToSelect + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function joinVirtualGridColumnsToSelect($mainTableAlias, Zend_Db_Select $select, &$columnsToSelect) + { + $adapter = $this->_getWriteAdapter(); + foreach ($this->getVirtualGridColumns() as $alias => $expression) { + list($table, $joinCondition, $column) = $expression; + $tableAlias = 'table_' . $alias; + + $joinConditionExpr = array(); + foreach ($joinCondition as $fkField=>$pkField) { + $pkField = $adapter->quoteIdentifier( + $tableAlias . '.' . $pkField + ); + $fkField = $adapter->quoteIdentifier( + $mainTableAlias . '.' . $fkField + ); + $joinConditionExpr[] = $fkField . '=' . $pkField; + } + + $select->joinLeft( + array($tableAlias=> $table), + implode(' AND ', $joinConditionExpr), + array($alias => str_replace('{{table}}', $tableAlias, $column)) + ); + + $columnsToSelect[] = $alias; + } + + return $this; + } + + /** + * Retrieve list of grid columns + * + * @return array + */ + public function getGridColumns() + { + if ($this->_gridColumns === null) { + if ($this->_grid) { + $this->_gridColumns = array_keys( + $this->_getReadAdapter()->describeTable($this->getGridTable()) + ); + } else { + $this->_gridColumns = array(); + } + } + + return $this->_gridColumns; + } + + /** + * Retrieve grid table + * + * @return string + */ + public function getGridTable() + { + if ($this->_grid) { + return $this->getTable($this->_mainTable . '_grid'); + } + return false; + } + + /** + * Before save object attribute + * + * @param Mage_Core_Model_Abstract $object + * @param string $attribute + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + protected function _beforeSaveAttribute(Mage_Core_Model_Abstract $object, $attribute) + { + if ($this->_eventObject && $this->_eventPrefix) { + Mage::dispatchEvent($this->_eventPrefix . '_save_attribute_before', array( + $this->_eventObject => $this, + 'object' => $object, + 'attribute' => $attribute + )); + } + return $this; + } + + /** + * After save object attribute + * + * @param Mage_Core_Model_Abstract $object + * @param string $attribute + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + protected function _afterSaveAttribute(Mage_Core_Model_Abstract $object, $attribute) + { + if ($this->_eventObject && $this->_eventPrefix) { + Mage::dispatchEvent($this->_eventPrefix . '_save_attribute_after', array( + $this->_eventObject => $this, + 'object' => $object, + 'attribute' => $attribute + )); + } + return $this; + } + + /** + * Perform actions after object save + * + * @param Mage_Core_Model_Abstract $object + * @param string $attribute + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function saveAttribute(Mage_Core_Model_Abstract $object, $attribute) + { + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + $attribute = $attribute->getAttributeCode(); + } + + if (is_string($attribute)) { + $attribute = array($attribute); + } + + if (is_array($attribute) && !empty($attribute)) { + $this->beginTransaction(); + try { + $this->_beforeSaveAttribute($object, $attribute); + $data = new Varien_Object(); + foreach ($attribute as $code) { + $data->setData($code, $object->getData($code)); + } + + $updateArray = $this->_prepareDataForTable($data, $this->getMainTable()); + $this->_postSaveFieldsUpdate($object, $updateArray); + if (!$object->getForceUpdateGridRecords() && + count(array_intersect($this->getGridColumns(), $attribute)) > 0 + ) { + $this->updateGridRecords($object->getId()); + } + $this->_afterSaveAttribute($object, $attribute); + $this->commit(); + } catch (Exception $e) { + $this->rollBack(); + throw $e; + } + } + + return $this; + } + + /** + * Perform actions before object save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if ($this->_useIncrementId && !$object->getIncrementId()) { + /* @var $entityType Mage_Eav_Model_Entity_Type */ + $entityType = Mage::getModel('eav/entity_type')->loadByCode($this->_entityTypeForIncrementId); + $object->setIncrementId($entityType->fetchNewIncrementId($object->getStoreId())); + } + parent::_beforeSave($object); + return $this; + } + + /** + * Update field in table if model have been already saved + * + * @param Mage_Core_Model_Abstract $object + * @param array $data + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + protected function _postSaveFieldsUpdate($object, $data) + { + if ($object->getId() && !empty($data)) { + $table = $this->getMainTable(); + $this->_getWriteAdapter()->update($table, $data, + array($this->getIdFieldName() . '=?' => (int) $object->getId()) + ); + $object->addData($data); + } + + return $this; + } + + /** + * Set main resource table + * + * @param string $table + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function setMainTable($table) + { + $this->_mainTable = $table; + return $this; + } + + /** + * Save object data + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Sales_Model_Resource_Order_Abstract + */ + public function save(Mage_Core_Model_Abstract $object) + { + if (!$object->getForceObjectSave()) { + parent::save($object); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Address.php b/app/code/core/Mage/Sales/Model/Resource/Order/Address.php new file mode 100755 index 0000000000..93675e4c40 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Address.php @@ -0,0 +1,75 @@ + + */ +class Mage_Sales_Model_Resource_Order_Address extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_address_resource'; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_address', 'entity_id'); + } + + /** + * Return configuration for all attributes + * + * @return array + */ + public function getAllAttributes() + { + $attributes = array( + 'city' => Mage::helper('sales')->__('City'), + 'company' => Mage::helper('sales')->__('Company'), + 'country_id' => Mage::helper('sales')->__('Country'), + 'email' => Mage::helper('sales')->__('Email'), + 'firstname' => Mage::helper('sales')->__('First Name'), + 'lastname' => Mage::helper('sales')->__('Last Name'), + 'region_id' => Mage::helper('sales')->__('State/Province'), + 'street' => Mage::helper('sales')->__('Street Address'), + 'telephone' => Mage::helper('sales')->__('Telephone'), + 'postcode' => Mage::helper('sales')->__('Zip/Postal Code') + ); + asort($attributes); + return $attributes; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Address/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Address/Collection.php new file mode 100755 index 0000000000..49ffe13075 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Address/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Sales_Model_Resource_Order_Address_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_address_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_address_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_address'); + } + + /** + * Redeclare after load method for dispatch event + * + * @return Mage_Sales_Model_Resource_Order_Address_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + Mage::dispatchEvent($this->_eventPrefix . '_load_after', array( + $this->_eventObject => $this + )); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Billing.php b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Billing.php new file mode 100755 index 0000000000..96f4219698 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Billing.php @@ -0,0 +1,68 @@ + + */ +class Mage_Sales_Model_Resource_Order_Attribute_Backend_Billing extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Perform operation before save + * + * @param Varien_Object $object + */ + public function beforeSave($object) + { + $billingAddressId = $object->getBillingAddressId(); + if (is_null($billingAddressId)) { + $object->unsetBillingAddressId(); + } + } + + /** + * Perform operation after save + * + * @param Varien_Object $object + */ + public function afterSave($object) + { + $billingAddressId = false; + foreach ($object->getAddressesCollection() as $address) { + if ('billing' == $address->getAddressType()) { + $billingAddressId = $address->getId(); + } + } + if ($billingAddressId) { + $object->setBillingAddressId($billingAddressId); + $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode()); + } + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Child.php new file mode 100755 index 0000000000..15857d1d5f --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Child.php @@ -0,0 +1,51 @@ + + */ +class Mage_Sales_Model_Resource_Order_Attribute_Backend_Child extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Perform operation before save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Attribute_Backend_Child + */ + public function beforeSave($object) + { + if ($object->getOrder()) { + $object->setParentId($object->getOrder()->getId()); + } + parent::beforeSave($object); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Parent.php new file mode 100755 index 0000000000..c16d381a0a --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Parent.php @@ -0,0 +1,64 @@ + + */ +class Mage_Sales_Model_Resource_Order_Attribute_Backend_Parent extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Perform operation after save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Attribute_Backend_Parent + */ + public function afterSave($object) + { + parent::afterSave($object); + + foreach ($object->getAddressesCollection() as $item) { + $item->save(); + } + foreach ($object->getItemsCollection() as $item) { + $item->save(); + } + foreach ($object->getPaymentsCollection() as $item) { + $item->save(); + } + foreach ($object->getStatusHistoryCollection() as $item) { + $item->save(); + } + foreach ($object->getRelatedObjects() as $object) { + $object->save(); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Shipping.php b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Shipping.php new file mode 100755 index 0000000000..73740a6320 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Attribute/Backend/Shipping.php @@ -0,0 +1,69 @@ + + */ +class Mage_Sales_Model_Resource_Order_Attribute_Backend_Shipping + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Perform operation before save + * + * @param Varien_Object $object + */ + public function beforeSave($object) + { + $shippingAddressId = $object->getShippingAddressId(); + if (is_null($shippingAddressId)) { + $object->unsetShippingAddressId(); + } + } + + /** + * Perform operation after save + * + * @param Varien_Object $object + */ + public function afterSave($object) + { + $shippingAddressId = false; + foreach ($object->getAddressesCollection() as $address) { + if ('shipping' == $address->getAddressType()) { + $shippingAddressId = $address->getId(); + } + } + if ($shippingAddressId) { + $object->setShippingAddressId($shippingAddressId); + $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getAttributeCode()); + } + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Collection.php new file mode 100755 index 0000000000..9fa8e9425c --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Collection.php @@ -0,0 +1,242 @@ + + */ +class Mage_Sales_Model_Resource_Order_Collection extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order'); + $this + ->addFilterToMap('entity_id', 'main_table.entity_id') + ->addFilterToMap('customer_id', 'main_table.customer_id') + ->addFilterToMap('quote_address_id', 'main_table.quote_address_id'); + } + + /** + * Add items count expr to collection select, backward capability with eav structure + * + * @return Mage_Sales_Model_Resource_Order_Collection + */ + public function addItemCountExpr() + { + if (is_null($this->_fieldsToSelect)) { + // If we select all fields from table, we need to add column alias + $this->getSelect()->columns(array('items_count'=>'total_item_count')); + } else { + $this->addFieldToSelect('total_item_count', 'items_count'); + } + return $this; + } + + /** + * Minimize usual count select + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + /* @var $countSelect Varien_Db_Select */ + $countSelect = parent::getSelectCountSql(); + $countSelect->resetJoinLeft(); + return $countSelect; + } + + /** + * Reset left join + * + * @param int $limit + * @param int $offset + * @return Mage_Eav_Model_Entity_Collection_Abstract + */ + protected function _getAllIdsSelect($limit = null, $offset = null) + { + $idsSelect = parent::_getAllIdsSelect($limit, $offset); + $idsSelect->resetJoinLeft(); + return $idsSelect; + } + + /** + * Join table sales_flat_order_address to select for billing and shipping order addresses. + * Create corillation map + * + * @return Mage_Sales_Model_Resource_Order_Collection + */ + protected function _addAddressFields() + { + $billingAliasName = 'billing_o_a'; + $shippingAliasName = 'shipping_o_a'; + $joinTable = $this->getTable('sales/order_address'); + + $this + ->addFilterToMap('billing_firstname', $billingAliasName . '.firstname') + ->addFilterToMap('billing_lastname', $billingAliasName . '.lastname') + ->addFilterToMap('billing_telephone', $billingAliasName . '.telephone') + ->addFilterToMap('billing_postcode', $billingAliasName . '.postcode') + + ->addFilterToMap('shipping_firstname', $shippingAliasName . '.firstname') + ->addFilterToMap('shipping_lastname', $shippingAliasName . '.lastname') + ->addFilterToMap('shipping_telephone', $shippingAliasName . '.telephone') + ->addFilterToMap('shipping_postcode', $shippingAliasName . '.postcode'); + + $this + ->getSelect() + ->joinLeft( + array($billingAliasName => $joinTable), + "(main_table.entity_id = {$billingAliasName}.parent_id" + . " AND {$billingAliasName}.address_type = 'billing')", + array( + $billingAliasName . '.firstname', + $billingAliasName . '.lastname', + $billingAliasName . '.telephone', + $billingAliasName . '.postcode' + ) + ) + ->joinLeft( + array($shippingAliasName => $joinTable), + "(main_table.entity_id = {$shippingAliasName}.parent_id" + . " AND {$shippingAliasName}.address_type = 'shipping')", + array( + $shippingAliasName . '.firstname', + $shippingAliasName . '.lastname', + $shippingAliasName . '.telephone', + $shippingAliasName . '.postcode' + ) + ); + Mage::getResourceHelper('core')->prepareColumnsList($this->getSelect()); + return $this; + } + + /** + * Add addresses information to select + * + * @return Mage_Sales_Model_Resource_Collection_Abstract + */ + public function addAddressFields() + { + return $this->_addAddressFields(); + } + + /** + * Add field search filter to collection as OR condition + * + * @see self::_getConditionSql for $condition + * + * @param string $field + * @param null|string|array $condition + * @return Mage_Sales_Model_Resource_Order_Collection + */ + public function addFieldToSearchFilter($field, $condition = null) + { + $field = $this->_getMappedField($field); + $this->_select->orWhere($this->_getConditionSql($field, $condition)); + return $this; + } + + /** + * Specify collection select filter by attribute value + * + * @param array $attributes + * @param array|integer|string|null $condition + * @return Mage_Sales_Model_Resource_Order_Collection + */ + public function addAttributeToSearchFilter($attributes, $condition = null) + { + if (is_array($attributes) && !empty($attributes)) { + $this->_addAddressFields(); + + $toFilterData = array(); + foreach ($attributes as $attribute) { + $this->addFieldToSearchFilter($this->_attributeToField($attribute['attribute']), $attribute); + } + } else { + $this->addAttributeToFilter($attributes, $condition); + } + + return $this; + } + + /** + * Add filter by specified billing agreements + * + * @param int|array $agreements + * @return Mage_Sales_Model_Resource_Order_Collection + */ + public function addBillingAgreementsFilter($agreements) + { + $agreements = (is_array($agreements)) ? $agreements : array($agreements); + $this->getSelect() + ->joinInner( + array('sbao' => $this->getTable('sales/billing_agreement_order')), + 'main_table.entity_id = sbao.order_id', + array()) + ->where('sbao.agreement_id IN(?)', $agreements); + return $this; + } + + /** + * Add filter by specified recurring profile id(s) + * + * @param array|int $ids + * @return Mage_Sales_Model_Resource_Order_Collection + */ + public function addRecurringProfilesFilter($ids) + { + $ids = (is_array($ids)) ? $ids : array($ids); + $this->getSelect() + ->joinInner( + array('srpo' => $this->getTable('sales/recurring_profile_order')), + 'main_table.entity_id = srpo.order_id', + array()) + ->where('srpo.profile_id IN(?)', $ids); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php new file mode 100755 index 0000000000..c1ebe82a65 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Collection/Abstract.php @@ -0,0 +1,103 @@ + + */ +abstract class Mage_Sales_Model_Resource_Order_Collection_Abstract extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Order object + * + * @var Mage_Sales_Model_Order + */ + protected $_salesOrder = null; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'parent_id'; + + /** + * Set sales order model as parent collection object + * + * @param Mage_Sales_Model_Order $order + * @return Mage_Sales_Model_Resource_Order_Collection_Abstract + */ + public function setSalesOrder($order) + { + $this->_salesOrder = $order; + if ($this->_eventPrefix && $this->_eventObject) { + Mage::dispatchEvent($this->_eventPrefix . '_set_sales_order', array( + 'collection' => $this, + $this->_eventObject => $this, + 'order' => $order + )); + } + + return $this; + } + + /** + * Retrieve sales order as parent collection object + * + * @return Mage_Sales_Model_Order|null + */ + public function getSalesOrder() + { + return $this->_salesOrder; + } + + /** + * Add order filter + * + * @param int|Mage_Sales_Model_Order $order + * @return Mage_Sales_Model_Resource_Order_Collection_Abstract + */ + public function setOrderFilter($order) + { + if ($order instanceof Mage_Sales_Model_Order) { + $this->setSalesOrder($order); + $orderId = $order->getId(); + if ($orderId) { + $this->addFieldToFilter($this->_orderField, $orderId); + } else { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + } + } else { + $this->addFieldToFilter($this->_orderField, $order); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Comment/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Order/Comment/Collection/Abstract.php new file mode 100755 index 0000000000..22f912d2a6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Comment/Collection/Abstract.php @@ -0,0 +1,73 @@ + + */ +abstract class Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract + extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Set filter on comments by their parent item + * + * @param Mage_Core_Model_Abstract|int $parent + * @return Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract + */ + public function setParentFilter($parent) + { + if ($parent instanceof Mage_Core_Model_Abstract) { + $parent = $parent->getId(); + } + return $this->addFieldToFilter('parent_id', $parent); + } + + /** + * Adds filter to get only 'visible on front' comments + * + * @param int $flag + * @return Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract + */ + public function addVisibleOnFrontFilter($flag = 1) + { + return $this->addFieldToFilter('is_visible_on_front', $flag); + } + + /** + * Set created_at sort order + * + * @param string $direction + * @return Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract + */ + public function setCreatedAtOrder($direction = 'desc') + { + return $this->setOrder('created_at', $direction); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo.php new file mode 100755 index 0000000000..c5262d0ec0 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo.php @@ -0,0 +1,108 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_resource'; + + /** + * Is grid available + * + * @var bool + */ + protected $_grid = true; + + /** + * Flag for using of increment id + * + * @var bool + */ + protected $_useIncrementId = true; + + /** + * Entity code for increment id (Eav entity code) + * + * @var string + */ + protected $_entityTypeForIncrementId = 'creditmemo'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/creditmemo', 'entity_id'); + } + + /** + * Init virtual grid records for entity + * + * @return Mage_Sales_Model_Resource_Order_Creditmemo + */ + protected function _initVirtualGridColumns() + { + parent::_initVirtualGridColumns(); + $adapter = $this->getReadConnection(); + $checkedFirstname = $adapter->getIfNullSql('{{table}}.firstname', $adapter->quote('')); + $checkedLastname = $adapter->getIfNullSql('{{table}}.lastname', $adapter->quote('')); + $concatName = $adapter->getConcatSql(array($checkedFirstname, $adapter->quote(' '), $checkedLastname)); + + $this->addVirtualGridColumn( + 'billing_name', + 'sales/order_address', + array('billing_address_id' => 'entity_id'), + $concatName + ) + ->addVirtualGridColumn( + 'order_increment_id', + 'sales/order', + array('order_id' => 'entity_id'), + 'increment_id' + ) + ->addVirtualGridColumn( + 'order_created_at', + 'sales/order', + array('order_id' => 'entity_id'), + 'created_at' + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Child.php new file mode 100755 index 0000000000..3fa14d97bc --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Child.php @@ -0,0 +1,51 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Attribute_Backend_Child + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked before save + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ + public function beforeSave($object) + { + if ($object->getCreditmemo()) { + $object->setParentId($object->getCreditmemo()->getId()); + } + return parent::beforeSave($object); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Parent.php new file mode 100755 index 0000000000..dd1394370b --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Attribute/Backend/Parent.php @@ -0,0 +1,61 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Attribute_Backend_Parent + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked after save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Creditmemo_Attribute_Backend_Parent + */ + public function afterSave($object) + { + parent::afterSave($object); + + /** + * Save creditmemo items + */ + foreach ($object->getAllItems() as $item) { + $item->save(); + } + + foreach ($object->getCommentsCollection() as $comment) { + $comment->save(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Collection.php new file mode 100755 index 0000000000..f13bd467c3 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Collection.php @@ -0,0 +1,77 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_creditmemo_collection'; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_creditmemo'); + } + + /** + * Used to emulate after load functionality for each item without loading them + * + * @return Mage_Sales_Model_Resource_Order_Creditmemo_Collection + */ + protected function _afterLoad() + { + $this->walk('afterLoad'); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment.php new file mode 100755 index 0000000000..53aab25ace --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Comment extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_comment_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/creditmemo_comment', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment/Collection.php new file mode 100755 index 0000000000..a9cff368fb --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Comment/Collection.php @@ -0,0 +1,72 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_comment_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_creditmemo_comment_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('sales/order_creditmemo_comment'); + } + + /** + * Set creditmemo filter + * + * @param int $creditmemoId + * @return Mage_Sales_Model_Resource_Order_Creditmemo_Comment_Collection + */ + public function setCreditmemoFilter($creditmemoId) + { + return $this->setParentFilter($creditmemoId); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php new file mode 100755 index 0000000000..dcdbd9a85e --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php @@ -0,0 +1,61 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Grid_Collection + extends Mage_Sales_Model_Resource_Order_Creditmemo_Collection +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_grid_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_creditmemo_grid_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->setMainTable('sales/creditmemo_grid'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item.php new file mode 100755 index 0000000000..c9651021a6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Item extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_item_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/creditmemo_item', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item/Collection.php new file mode 100755 index 0000000000..1d0309cd31 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Creditmemo/Item/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Sales_Model_Resource_Order_Creditmemo_Item_Collection extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_creditmemo_item_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_creditmemo_item_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_creditmemo_item'); + } + + /** + * Set creditmemo filter + * + * @param int $creditmemoId + * @return Mage_Sales_Model_Resource_Order_Creditmemo_Item_Collection + */ + public function setCreditmemoFilter($creditmemoId) + { + $this->addFieldToFilter('parent_id', $creditmemoId); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Grid/Collection.php new file mode 100755 index 0000000000..b2de6c4762 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Grid/Collection.php @@ -0,0 +1,111 @@ + + */ +class Mage_Sales_Model_Resource_Order_Grid_Collection extends Mage_Sales_Model_Resource_Order_Collection +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_grid_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_grid_collection'; + + /** + * Customer mode flag + * + * @var bool + */ + protected $_customerModeFlag = false; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->setMainTable('sales/order_grid'); + } + + /** + * Get SQL for get record count + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $this->_renderFilters(); + + $unionSelect = clone $this->getSelect(); + + $unionSelect->reset(Zend_Db_Select::ORDER); + $unionSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $unionSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + + $countSelect = clone $this->getSelect(); + $countSelect->reset(); + $countSelect->from(array('a' => $unionSelect), 'COUNT(*)'); + + return $countSelect; + } + + /** + * Set customer mode flag value + * + * @param bool $value + * @return Mage_Sales_Model_Resource_Order_Grid_Collection + */ + public function setIsCustomerMode($value) + { + $this->_customerModeFlag = (bool)$value; + return $this; + } + + /** + * Get customer mode flag value + * + * @return bool + */ + public function getIsCustomerMode() + { + return $this->_customerModeFlag; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice.php new file mode 100755 index 0000000000..9c3fa2fd92 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice.php @@ -0,0 +1,107 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_resource'; + + /** + * Is grid available + * + * @var bool + */ + protected $_grid = true; + + /** + * Flag for using of increment id + * + * @var bool + */ + protected $_useIncrementId = true; + + /** + * Entity code for increment id (Eav entity code) + * + * @var string + */ + protected $_entityTypeForIncrementId = 'invoice'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/invoice', 'entity_id'); + } + + /** + * Init virtual grid records for entity + * + * @return Mage_Sales_Model_Resource_Order_Invoice + */ + protected function _initVirtualGridColumns() + { + parent::_initVirtualGridColumns(); + $adapter = $this->_getReadAdapter(); + $checkedFirstname = $adapter->getIfNullSql('{{table}}.firstname', $adapter->quote('')); + $checkedLastname = $adapter->getIfNullSql('{{table}}.lastname', $adapter->quote('')); + + $this->addVirtualGridColumn( + 'billing_name', + 'sales/order_address', + array('billing_address_id' => 'entity_id'), + $adapter->getConcatSql(array($checkedFirstname, $adapter->quote(' '), $checkedLastname)) + ) + ->addVirtualGridColumn( + 'order_increment_id', + 'sales/order', + array('order_id' => 'entity_id'), + 'increment_id' + ) + ->addVirtualGridColumn( + 'order_created_at', + 'sales/order', + array('order_id' => 'entity_id'), + 'created_at' + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Child.php new file mode 100755 index 0000000000..4a3fb85329 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Child.php @@ -0,0 +1,51 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Child + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked before save + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ + public function beforeSave($object) + { + if ($object->getInvoice()) { + $object->setParentId($object->getInvoice()->getId()); + } + return parent::beforeSave($object); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Item.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Item.php new file mode 100755 index 0000000000..d77e31aeda --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Item.php @@ -0,0 +1,51 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Item + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked after save + * + * @param Varien_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ + public function afterSave($object) + { + if ($object->getOrderItem()) { + $object->getOrderItem()->save(); + } + return parent::beforeSave($object); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Order.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Order.php new file mode 100755 index 0000000000..b522931dc6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Order.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Order + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked before save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Order + */ + public function beforeSave($object) + { + if ($object->getOrder()) { + $object->setOrderId($object->getOrder()->getId()); + $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId()); + } + return parent::beforeSave($object); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Parent.php new file mode 100755 index 0000000000..67a9d09222 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Attribute/Backend/Parent.php @@ -0,0 +1,62 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Parent + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Method is invoked after save + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Invoice_Attribute_Backend_Parent + */ + public function afterSave($object) + { + parent::afterSave($object); + + /** + * Save invoice items + */ + foreach ($object->getAllItems() as $item) { + $item->setOrderItem($item->getOrderItem()); + $item->save(); + } + + foreach ($object->getCommentsCollection() as $comment) { + $comment->save(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Collection.php new file mode 100755 index 0000000000..4d0f63e975 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Collection.php @@ -0,0 +1,75 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_invoice_collection'; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_invoice'); + } + + /** + * Used to emulate after load functionality for each item without loading them + * + */ + protected function _afterLoad() + { + $this->walk('afterLoad'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment.php new file mode 100755 index 0000000000..473c793835 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Comment extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_comment_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/invoice_comment', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment/Collection.php new file mode 100755 index 0000000000..5d971fb350 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Comment/Collection.php @@ -0,0 +1,72 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_comment_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_invoice_comment_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('sales/order_invoice_comment'); + } + + /** + * Set invoice filter + * + * @param int $invoiceId + * @return Mage_Sales_Model_Resource_Order_Invoice_Comment_Collection + */ + public function setInvoiceFilter($invoiceId) + { + return $this->setParentFilter($invoiceId); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Grid/Collection.php new file mode 100755 index 0000000000..ce34dc3f56 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Grid/Collection.php @@ -0,0 +1,60 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Grid_Collection extends Mage_Sales_Model_Resource_Order_Invoice_Collection +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_grid_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_invoice_grid_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->setMainTable('sales/invoice_grid'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item.php new file mode 100755 index 0000000000..50534bf8e3 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Item extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_item_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/invoice_item', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item/Collection.php new file mode 100755 index 0000000000..fc26b31228 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Invoice/Item/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Sales_Model_Resource_Order_Invoice_Item_Collection extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_invoice_item_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_invoice_item_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_invoice_item'); + } + + /** + * Set invoice filter + * + * @param int $invoiceId + * @return Mage_Sales_Model_Resource_Order_Invoice_Item_Collection + */ + public function setInvoiceFilter($invoiceId) + { + $this->addFieldToFilter('parent_id', $invoiceId); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Item.php b/app/code/core/Mage/Sales/Model/Resource/Order/Item.php new file mode 100755 index 0000000000..da5b4ae20a --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Item.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Item extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_item_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_item', 'item_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Item/Collection.php new file mode 100755 index 0000000000..cc57da2537 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Item/Collection.php @@ -0,0 +1,142 @@ + + */ +class Mage_Sales_Model_Resource_Order_Item_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_item_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_item_collection'; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_item'); + } + + /** + * Assign parent items on after collection load + * + * @return Mage_Sales_Model_Resource_Order_Item_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + /** + * Assign parent items + */ + foreach ($this as $item) { + if ($item->getParentItemId()) { + $item->setParentItem($this->getItemById($item->getParentItemId())); + } + } + return $this; + } + + /** + * Set random items order + * + * @return Mage_Sales_Model_Resource_Order_Item_Collection + */ + public function setRandomOrder() + { + $this->getConnection()->orderRand($this->getSelect()); + return $this; + } + + /** + * Set filter by item id + * + * @param mixed $item + * @return Mage_Sales_Model_Resource_Order_Item_Collection + */ + public function addIdFilter($item) + { + if (is_array($item)) { + $this->addFieldToFilter('item_id', array('in'=>$item)); + } elseif ($item instanceof Mage_Sales_Model_Order_Item) { + $this->addFieldToFilter('item_id', $item->getId()); + } else { + $this->addFieldToFilter('item_id', $item); + } + return $this; + } + + /** + * Filter collection by specified product types + * + * @param array $typeIds + * @return Mage_Sales_Model_Resource_Order_Item_Collection + */ + public function filterByTypes($typeIds) + { + $this->addFieldToFilter('product_type', array('in' => $typeIds)); + return $this; + } + + /** + * Filter collection by parent_item_id + * + * @param int $parentId + * @return Mage_Sales_Model_Resource_Order_Item_Collection + */ + public function filterByParent($parentId = null) + { + if (empty($parentId)) { + $this->addFieldToFilter('parent_item_id', array('null' => true)); + } else { + $this->addFieldToFilter('parent_item_id', $parentId); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Payment.php b/app/code/core/Mage/Sales/Model/Resource/Order/Payment.php new file mode 100755 index 0000000000..d2ae6ebf7e --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Payment.php @@ -0,0 +1,61 @@ + + */ +class Mage_Sales_Model_Resource_Order_Payment extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Serializeable field: additional_information + * + * @var array + */ + protected $_serializableFields = array( + 'additional_information' => array(null, array()) + ); + + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_payment_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_payment', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Collection.php new file mode 100755 index 0000000000..94e38d20f0 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Collection.php @@ -0,0 +1,72 @@ + + */ +class Mage_Sales_Model_Resource_Order_Payment_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_payment_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_payment_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_payment'); + } + + /** + * Unserialize additional_information in each item + * + * @return Mage_Sales_Model_Resource_Order_Payment_Collection + */ + protected function _afterLoad() + { + foreach ($this->_items as $item) { + $this->getResource()->unserializeFields($item); + } + return parent::_afterLoad(); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction.php b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction.php new file mode 100755 index 0000000000..928f7cc705 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction.php @@ -0,0 +1,208 @@ + + */ +class Mage_Sales_Model_Resource_Order_Payment_Transaction extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Serializeable field: additional_information + * + * @var array + */ + protected $_serializableFields = array( + 'additional_information' => array(null, array()) + ); + + /** + * Initialize main table and the primary key field name + * + */ + protected function _construct() + { + $this->_init('sales/payment_transaction', 'transaction_id'); + } + + /** + * Update transactions in database using provided transaction as parent for them + * have to repeat the business logic to avoid accidental injection of wrong transactions + * + * @param Mage_Sales_Model_Order_Payment_Transaction $transaction + */ + public function injectAsParent(Mage_Sales_Model_Order_Payment_Transaction $transaction) + { + $txnId = $transaction->getTxnId(); + if ($txnId && Mage_Sales_Model_Order_Payment_Transaction::TYPE_PAYMENT === $transaction->getTxnType() + && $id = $transaction->getId() + ) { + $adapter = $this->_getWriteAdapter(); + + // verify such transaction exists, determine payment and order id + $verificationRow = $adapter->fetchRow( + $adapter->select()->from($this->getMainTable(), array('payment_id', 'order_id')) + ->where("{$this->getIdFieldName()} = ?", (int)$id) + ); + if (!$verificationRow) { + return; + } + list($paymentId, $orderId) = array_values($verificationRow); + + // inject + $where = array( + $adapter->quoteIdentifier($this->getIdFieldName()) . '!=?' => $id, + new Zend_Db_Expr('parent_id IS NULL'), + 'payment_id = ?' => (int)$paymentId, + 'order_id = ?' => (int)$orderId, + 'parent_txn_id = ?' => $txnId + ); + $adapter->update($this->getMainTable(), + array('parent_id' => $id), + $where + ); + } + } + + /** + * Load the transaction object by specified txn_id + * + * @param Mage_Sales_Model_Order_Payment_Transaction $transaction + * @param int $orderId + * @param int $paymentId + * @param string $txnId + */ + public function loadObjectByTxnId(Mage_Sales_Model_Order_Payment_Transaction $transaction, $orderId, $paymentId, + $txnId) + { + $select = $this->_getLoadByUniqueKeySelect($orderId, $paymentId, $txnId); + $data = $this->_getWriteAdapter()->fetchRow($select); + $transaction->setData($data); + $this->unserializeFields($transaction); + $this->_afterLoad($transaction); + } + + /** + * Retrieve order website id + * + * @param int $orderId + * @return string + */ + public function getOrderWebsiteId($orderId) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':entity_id' => $orderId); + $select = $adapter->select() + ->from(array('so' => $this->getTable('sales/order')), 'cs.website_id') + ->joinInner(array('cs' => $this->getTable('core/store')), 'cs.store_id = so.store_id') + ->where('so.entity_id = :entity_id'); + return $adapter->fetchOne($select, $bind); + } + + /** + * Lookup for parent_id in already saved transactions of this payment by the order_id + * Also serialize additional information, if any + * + * @throws Mage_Core_Exception + * + * @param Mage_Sales_Model_Order_Payment_Transaction $transaction + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction + */ + protected function _beforeSave(Mage_Core_Model_Abstract $transaction) + { + $parentTxnId = $transaction->getData('parent_txn_id'); + $txnId = $transaction->getData('txn_id'); + $orderId = $transaction->getData('order_id'); + $paymentId = $transaction->getData('payment_id'); + $idFieldName = $this->getIdFieldName(); + + if ($parentTxnId) { + if (!$txnId || !$orderId || !$paymentId) { + Mage::throwException( + Mage::helper('sales')->__('Not enough valid data to save the parent transaction ID.')); + } + $parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName); + if ($parentId) { + $transaction->setData('parent_id', $parentId); + } + } + + // make sure unique key won't cause trouble + if ($transaction->isFailsafe()) { + $autoincrementId = (int)$this->_lookupByTxnId($orderId, $paymentId, $txnId, $idFieldName); + if ($autoincrementId) { + $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false); + } + } + + return parent::_beforeSave($transaction); + } + + /** + * Load cell/row by specified unique key parts + * + * @param int $orderId + * @param int $paymentId + * @param string $txnId + * @param mixed (array|string|object) $columns + * @param bool $isRow + * @param string $txnType + * @return mixed (array|string) + */ + private function _lookupByTxnId($orderId, $paymentId, $txnId, $columns, $isRow = false, $txnType = null) + { + $select = $this->_getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $columns); + if ($txnType) { + $select->where('txn_type = ?', $txnType); + } + if ($isRow) { + return $this->_getWriteAdapter()->fetchRow($select); + } + return $this->_getWriteAdapter()->fetchOne($select); + } + + /** + * Get select object for loading transaction by the unique key of order_id, payment_id, txn_id + * + * @param int $orderId + * @param int $paymentId + * @param string $txnId + * @param string|array|Zend_Db_Expr $columns + * @return Varien_Db_Select + */ + private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $columns = '*') + { + return $this->_getWriteAdapter()->select() + ->from($this->getMainTable(), $columns) + ->where('order_id = ?', $orderId) + ->where('payment_id = ?', $paymentId) + ->where('txn_id = ?', $txnId); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction/Collection.php new file mode 100755 index 0000000000..dbc5f8c5ee --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Payment/Transaction/Collection.php @@ -0,0 +1,256 @@ + + */ +class Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Order ID filter + * + * @var int + */ + protected $_orderId = null; + + /** + * Columns of order info that should be selected + * + * @var array + */ + protected $_addOrderInformation = array(); + + /** + * Columns of payment info that should be selected + * + * @var array + */ + protected $_addPaymentInformation = array(); + + /** + * Order Store ids + * + * @var array + */ + protected $_storeIds = array(); + + /** + * Payment ID filter + * + * @var int + */ + protected $_paymentId = null; + + /** + * Parent ID filter + * + * @var int + */ + protected $_parentId = null; + + /** + * Filter by transaction type + * + * @var array + */ + protected $_txnTypes = null; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Initialize collection items factory class + */ + protected function _construct() + { + $this->_init('sales/order_payment_transaction'); + parent::_construct(); + } + + /** + * Join order information + * + * @param array $keys + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addOrderInformation(array $keys) + { + $this->_addOrderInformation = array_merge($this->_addOrderInformation, $keys); + $this->addFilterToMap('created_at', 'main_table.created_at'); + return $this; + } + + /** + * Join payment information + * + * @param array $keys + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addPaymentInformation(array $keys) + { + $this->_addPaymentInformation = array_merge($this->_addPaymentInformation, $keys); + return $this; + } + + /** + * Order ID filter setter + * + * @param int $orderId + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addOrderIdFilter($orderId) + { + $this->_orderId = (int)$orderId; + return $this; + } + + /** + * Payment ID filter setter + * Can take either the integer id or the payment instance + * + * @param Mage_Sales_Model_Order_Payment|int $payment + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addPaymentIdFilter($payment) + { + $id = $payment; + if (is_object($payment)) { + $id = $payment->getId(); + } + $this->_paymentId = (int)$id; + return $this; + } + + /** + * Parent ID filter setter + * + * @param int $parentId + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addParentIdFilter($parentId) + { + $this->_parentId = (int)$parentId; + return $this; + } + + /** + * Transaction type filter setter + * + * @param array|string $txnType + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addTxnTypeFilter($txnType) + { + if (!is_array($txnType)) { + $txnType = array($txnType); + } + $this->_txnTypes = $txnType; + return $this; + } + + /** + * Add filter by store ids + * + * @param int|array $storeIds + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + public function addStoreFilter($storeIds) + { + $storeIds = (is_array($storeIds)) ? $storeIds : array($storeIds); + $this->_storeIds = array_merge($this->_storeIds, $storeIds); + return $this; + } + + /** + * Prepare filters + * + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + protected function _beforeLoad() + { + parent::_beforeLoad(); + + if ($this->isLoaded()) { + return $this; + } + + // filters + if ($this->_paymentId) { + $this->getSelect()->where('main_table.payment_id = ?', $this->_paymentId); + } + if ($this->_parentId) { + $this->getSelect()->where('main_table.parent_id = ?', $this->_parentId); + } + if ($this->_txnTypes) { + $this->getSelect()->where('main_table.txn_type IN(?)', $this->_txnTypes); + } + if ($this->_orderId) { + $this->getSelect()->where('main_table.order_id = ?', $this->_orderId); + } + if ($this->_addPaymentInformation) { + $this->getSelect()->joinInner( + array('sop' => $this->getTable('sales/order_payment')), + 'main_table.payment_id = sop.entity_id', + $this->_addPaymentInformation + ); + } + if ($this->_storeIds) { + $this->getSelect()->where('so.store_id IN(?)', $this->_storeIds); + $this->addOrderInformation(array('store_id')); + } + if ($this->_addOrderInformation) { + $this->getSelect()->joinInner( + array('so' => $this->getTable('sales/order')), + 'main_table.order_id = so.entity_id', + $this->_addOrderInformation + ); + } + return $this; + } + + /** + * Unserialize additional_information in each item + * + * @return Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection + */ + protected function _afterLoad() + { + foreach ($this->_items as $item) { + $this->getResource()->unserializeFields($item); + } + return parent::_afterLoad(); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment.php new file mode 100755 index 0000000000..df07300008 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment.php @@ -0,0 +1,108 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_resource'; + + /** + * Is grid available + * + * @var bool + */ + protected $_grid = true; + + /** + * Use increment id + * + * @var bool + */ + protected $_useIncrementId = true; + + /** + * Entity type for increment id + * + * @var string + */ + protected $_entityTypeForIncrementId = 'shipment'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/shipment', 'entity_id'); + } + + /** + * Init virtual grid records for entity + * + * @return Mage_Sales_Model_Resource_Order_Shipment + */ + protected function _initVirtualGridColumns() + { + parent::_initVirtualGridColumns(); + $adapter = $this->getReadConnection(); + $checkedFirstname = $adapter->getIfNullSql('{{table}}.firstname', $adapter->quote('')); + $checkedLastname = $adapter->getIfNullSql('{{table}}.lastname', $adapter->quote('')); + $concatName = $adapter->getConcatSql(array($checkedFirstname, $adapter->quote(' '), $checkedLastname)); + + $this->addVirtualGridColumn( + 'shipping_name', + 'sales/order_address', + array('shipping_address_id' => 'entity_id'), + $concatName + ) + ->addVirtualGridColumn( + 'order_increment_id', + 'sales/order', + array('order_id' => 'entity_id'), + 'increment_id' + ) + ->addVirtualGridColumn( + 'order_created_at', + 'sales/order', + array('order_id' => 'entity_id'), + 'created_at' + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Child.php new file mode 100755 index 0000000000..260908e1ac --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Child.php @@ -0,0 +1,51 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Child + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Performed before data is saved + * + * @param Varieb_Object $object + * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract + */ + public function beforeSave($object) + { + if ($object->getShipment()) { + $object->setParentId($object->getShipment()->getId()); + } + return parent::beforeSave($object); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Parent.php new file mode 100755 index 0000000000..e78baebaf8 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Attribute/Backend/Parent.php @@ -0,0 +1,67 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Parent + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Performed after data is saved + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Order_Shipment_Attribute_Backend_Parent + */ + public function afterSave($object) + { + parent::afterSave($object); + + /** + * Save Shipment items + */ + foreach ($object->getAllItems() as $item) { + $item->save(); + } + + /** + * Save Shipment tracks + */ + foreach ($object->getAllTracks() as $track) { + $track->save(); + } + + foreach ($object->getCommentsCollection() as $comment) { + $comment->save(); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Collection.php new file mode 100755 index 0000000000..aa383f3fcb --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Collection.php @@ -0,0 +1,78 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Collection extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_shipment_collection'; + + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_shipment'); + } + + /** + * Used to emulate after load functionality for each item without loading them + * + * @return Mage_Sales_Model_Resource_Order_Shipment_Collection + */ + protected function _afterLoad() + { + $this->walk('afterLoad'); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment.php new file mode 100755 index 0000000000..1dc0188151 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Comment extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_comment_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/shipment_comment', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment/Collection.php new file mode 100755 index 0000000000..f35894cc36 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Comment/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Comment_Collection + extends Mage_Sales_Model_Resource_Order_Comment_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_comment_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_shipment_comment_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_shipment_comment'); + } + + /** + * Set shipment filter + * + * @param int $shipmentId + * @return Mage_Sales_Model_Resource_Order_Shipment_Comment_Collection + */ + public function setShipmentFilter($shipmentId) + { + return $this->setParentFilter($shipmentId); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Grid/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Grid/Collection.php new file mode 100755 index 0000000000..db0de8352f --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Grid/Collection.php @@ -0,0 +1,61 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Grid_Collection + extends Mage_Sales_Model_Resource_Order_Shipment_Collection +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_grid_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_shipment_grid_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + parent::_construct(); + $this->setMainTable('sales/shipment_grid'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item.php new file mode 100755 index 0000000000..fbd4f4c4b6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Item extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_item_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/shipment_item', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item/Collection.php new file mode 100755 index 0000000000..375e427501 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Item/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Item_Collection extends Mage_Sales_Model_Resource_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_item_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_shipment_item_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_shipment_item'); + } + + /** + * Set shipment filter + * + * @param int $shipmentId + * @return Mage_Sales_Model_Resource_Order_Shipment_Item_Collection + */ + public function setShipmentFilter($shipmentId) + { + $this->addFieldToFilter('parent_id', $shipmentId); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track.php new file mode 100755 index 0000000000..5db8d62760 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Track extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_track_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/shipment_track', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track/Collection.php new file mode 100755 index 0000000000..4090546ecb --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Shipment/Track/Collection.php @@ -0,0 +1,79 @@ + + */ +class Mage_Sales_Model_Resource_Order_Shipment_Track_Collection + extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_shipment_track_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_shipment_track_collection'; + + /** + * Order field + * + * @var string + */ + protected $_orderField = 'order_id'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_shipment_track'); + } + + /** + * Set shipment filter + * + * @param int $shipmentId + * @return Mage_Sales_Model_Resource_Order_Shipment_Track_Collection + */ + public function setShipmentFilter($shipmentId) + { + $this->addFieldToFilter('parent_id', $shipmentId); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Status.php b/app/code/core/Mage/Sales/Model/Resource/Order/Status.php new file mode 100644 index 0000000000..730495fe44 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Status.php @@ -0,0 +1,212 @@ + + */ +class Mage_Sales_Model_Resource_Order_Status extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Status labels table + * + * @var string + */ + protected $_labelsTable; + + /** + * Status state table + * + * @var string + */ + protected $_stateTable; + + /** + * Internal constructor + */ + protected function _construct() + { + $this->_init('sales/order_status', 'status'); + $this->_isPkAutoIncrement = false; + $this->_labelsTable = $this->getTable('sales/order_status_label'); + $this->_stateTable = $this->getTable('sales/order_status_state'); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + if ($field == 'default_state') { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array('label')) + ->join( + array('state_table' => $this->_stateTable), + $this->getMainTable() . '.status = state_table.status', + 'status' + ) + ->where('state_table.state = ?', $value) + ->order('state_table.is_default DESC') + ->limit(1); + } else { + $select = parent::_getLoadSelect($field, $value, $object); + } + return $select; + } + + /** + * Store labels getter + * + * @param Mage_Core_Model_Abstract $status + * @return array + */ + public function getStoreLabels(Mage_Core_Model_Abstract $status) + { + $select = $this->_getWriteAdapter()->select() + ->from($this->_labelsTable, array('store_id', 'label')) + ->where('status = ?', $status->getStatus()); + return $this->_getReadAdapter()->fetchPairs($select); + } + + /** + * Save status labels per store + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Sales_Model_Resource_Order_Status + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if ($object->hasStoreLabels()) { + $labels = $object->getStoreLabels(); + $this->_getWriteAdapter()->delete( + $this->_labelsTable, + array('status = ?' => $object->getStatus()) + ); + $data = array(); + foreach ($labels as $storeId => $label) { + if (empty($label)) { + continue; + } + $data[] = array( + 'status' => $object->getStatus(), + 'store_id' => $storeId, + 'label' => $label + ); + } + if (!empty($data)) { + $this->_getWriteAdapter()->insertMultiple($this->_labelsTable, $data); + } + } + return parent::_afterSave($object); + } + + /** + * Assign order status to order state + * + * @param string $status + * @param string $state + * @param bool $isDefault + * @return Mage_Sales_Model_Resource_Order_Status + */ + public function assignState($status, $state, $isDefault) + { + if ($isDefault) { + $this->_getWriteAdapter()->update( + $this->_stateTable, + array('is_default' => 0), + array('state = ?' => $state) + ); + } + $this->_getWriteAdapter()->insertOnDuplicate( + $this->_stateTable, + array( + 'status' => $status, + 'state' => $state, + 'is_default' => (int) $isDefault + ) + ); + return $this; + } + + /** + * Unassign order status from order state + * + * @param string $status + * @param string $state + * @return Mage_Sales_Model_Resource_Order_Status + */ + public function unassignState($status, $state) + { + $select = $this->_getWriteAdapter()->select() + ->from($this->_stateTable, array('qty' => new Zend_Db_Expr('COUNT(*)'))) + ->where('state = ?', $state); + + if ($this->_getWriteAdapter()->fetchOne($select) == 1) { + throw new Mage_Core_Exception( + Mage::helper('sales')->__('Last status can\'t be unassigned from state.') + ); + } + $select = $this->_getWriteAdapter()->select() + ->from($this->_stateTable, 'is_default') + ->where('state = ?', $state) + ->where('status = ?', $status) + ->limit(1); + $isDefault = $this->_getWriteAdapter()->fetchOne($select); + $this->_getWriteAdapter()->delete( + $this->_stateTable, + array( + 'state = ?' => $state, + 'status = ?' => $status + ) + ); + + if ($isDefault) { + $select = $this->_getWriteAdapter()->select() + ->from($this->_stateTable, 'status') + ->where('state = ?', $state) + ->limit(1); + $defaultStatus = $this->_getWriteAdapter()->fetchOne($select); + if ($defaultStatus) { + $this->_getWriteAdapter()->update( + $this->_stateTable, + array('is_default' => 1), + array( + 'state = ?' => $state, + 'status = ?' => $defaultStatus + ) + ); + } + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Status/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Status/Collection.php new file mode 100644 index 0000000000..e2929f5992 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Status/Collection.php @@ -0,0 +1,104 @@ + + */ +class Mage_Sales_Model_Resource_Order_Status_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Internal constructor + */ + protected function _construct() + { + $this->_init('sales/order_status'); + } + + /** + * Get collection data as options array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('status', 'label'); + } + + /** + * Get collection data as options hash + * + * @return array + */ + public function toOptionHash() + { + return $this->_toOptionHash('status', 'label'); + } + + /** + * Join order states table + */ + public function joinStates() + { + if (!$this->getFlag('states_joined')) { + $this->_idFieldName = 'status_state'; + $this->getSelect()->joinLeft( + array('state_table' => $this->getTable('sales/order_status_state')), + 'main_table.status=state_table.status', + array('state', 'is_default') + ); + $this->setFlag('states_joined', true); + } + return $this; + } + + /** + * add state code filter to collection + * + * @param string $state + */ + public function addStateFilter($state) + { + $this->joinStates(); + $this->getSelect()->where('state_table.state=?', $state); + return $this; + } + + /** + * Define label order + * + * @param string $dir + * @return Mage_Sales_Model_Mysql4_Order_Status_Collection + */ + public function orderByLabel($dir = 'ASC') + { + $this->getSelect()->order('main_table.label '.$dir); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Status/History.php b/app/code/core/Mage/Sales/Model/Resource/Order/Status/History.php new file mode 100755 index 0000000000..7369846fec --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Status/History.php @@ -0,0 +1,52 @@ + + */ +class Mage_Sales_Model_Resource_Order_Status_History extends Mage_Sales_Model_Resource_Order_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_status_history_resource'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_status_history', 'entity_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Status/History/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Status/History/Collection.php new file mode 100755 index 0000000000..14817344f1 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Status/History/Collection.php @@ -0,0 +1,60 @@ + + */ +class Mage_Sales_Model_Resource_Order_Status_History_Collection + extends Mage_Sales_Model_Resource_Order_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_order_status_history_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'order_status_history_collection'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_status_history'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Tax.php b/app/code/core/Mage/Sales/Model/Resource/Order/Tax.php new file mode 100755 index 0000000000..fe4dd117e7 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Tax.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sales_Model_Resource_Order_Tax extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_tax', 'tax_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Order/Tax/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Order/Tax/Collection.php new file mode 100755 index 0000000000..adbcdde32f --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Order/Tax/Collection.php @@ -0,0 +1,60 @@ + + */ +class Mage_Sales_Model_Resource_Order_Tax_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_tax', 'sales/order_tax'); + } + + /** + * Load by order + * + * @param Mage_Sales_Model_Order $order + * @return Mage_Sales_Model_Resource_Order_Tax_Collection + */ + public function loadByOrder($order) + { + $orderId = $order->getId(); + $this->getSelect() + ->where('main_table.order_id = ?', $orderId) + ->order('process'); + return $this->load(); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote.php b/app/code/core/Mage/Sales/Model/Resource/Quote.php new file mode 100755 index 0000000000..99f3d89c9e --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote.php @@ -0,0 +1,259 @@ + + */ +class Mage_Sales_Model_Resource_Quote extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Initialize table nad PK name + * + */ + protected function _construct() + { + $this->_init('sales/quote', 'entity_id'); + } + + /** + * Retrieve select object for load object data + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Varien_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + $storeIds = $object->getSharedStoreIds(); + if ($storeIds) { + $select->where('store_id IN (?)', $storeIds); + } else { + /** + * For empty result + */ + $select->where('store_id < ?', 0); + } + + return $select; + } + + /** + * Load quote data by customer identifier + * + * @param Mage_Sales_Model_Quote $quote + * @param int $customerId + * @return Mage_Sales_Model_Resource_Quote + */ + public function loadByCustomerId($quote, $customerId) + { + $adapter = $this->_getReadAdapter(); + $select = $this->_getLoadSelect('customer_id', $customerId, $quote) + ->where('is_active = ?', 1) + ->order('updated_at ' . Varien_Db_Select::SQL_DESC) + ->limit(1); + + $data = $adapter->fetchRow($select); + + if ($data) { + $quote->setData($data); + } + + $this->_afterLoad($quote); + + return $this; + } + + /** + * Load only active quote + * + * @param Mage_Sales_Model_Quote $quote + * @param int $quoteId + * @return Mage_Sales_Model_Resource_Quote + */ + public function loadActive($quote, $quoteId) + { + $adapter = $this->_getReadAdapter(); + $select = $this->_getLoadSelect('entity_id', $quoteId, $quote) + ->where('is_active = ?', 1); + + $data = $adapter->fetchRow($select); + if ($data) { + $quote->setData($data); + } + + $this->_afterLoad($quote); + + return $this; + } + + /** + * Load quote data by identifier without store + * + * @param Mage_Sales_Model_Quote $quote + * @param int $quoteId + * @return Mage_Sales_Model_Resource_Quote + */ + public function loadByIdWithoutStore($quote, $quoteId) + { + $read = $this->_getReadAdapter(); + if ($read) { + $select = parent::_getLoadSelect('entity_id', $quoteId, $quote); + + $data = $read->fetchRow($select); + + if ($data) { + $quote->setData($data); + } + } + + $this->_afterLoad($quote); + return $this; + } + + /** + * Get reserved order id + * + * @param Mage_Sales_Model_Quote $quote + * @return string + */ + public function getReservedOrderId($quote) + { + $storeId = (int)$quote->getStoreId(); + return Mage::getSingleton('eav/config')->getEntityType(Mage_Sales_Model_Order::ENTITY) + ->fetchNewIncrementId($storeId); + } + + /** + * Check is order increment id use in sales/order table + * + * @param int $orderIncrementId + * @return boolean + */ + public function isOrderIncrementIdUsed($orderIncrementId) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':increment_id' => (int)$orderIncrementId); + $select = $adapter->select(); + $select->from($this->getTable('sales/order'), 'entity_id') + ->where('increment_id = :increment_id'); + $entity_id = $adapter->fetchOne($select, $bind); + if ($entity_id > 0) { + return true; + } + + return false; + } + + /** + * Mark quotes - that depend on catalog price rules - to be recollected on demand + * + * @return Mage_Sales_Model_Resource_Quote + */ + public function markQuotesRecollectOnCatalogRules() + { + $readAdapter = $this->_getReadAdapter(); + $selectProductId = $readAdapter->select() + ->from($this->getTable('catalogrule/rule_product_price'), 'product_id') + ->distinct(); + + $selectQuoteId = $readAdapter->select() + ->from($this->getTable('sales/quote_item'), 'quote_id') + ->where('product_id IN(?)', $selectProductId) + ->distinct(); + + $data = array('trigger_recollect' => 1); + $where = array('entity_id IN(?)' => $selectQuoteId); + + $this->_getWriteAdapter()->update($this->getTable('sales/quote'), $data, $where); + + return $this; + } + + /** + * Subtract product from all quotes quantities + * + * @param Mage_Catalog_Model_Product $product + * @return Mage_Sales_Model_Resource_Quote + */ + public function substractProductFromQuotes($product) + { + $productId = (int)$product->getId(); + if (!$productId) { + return $this; + } + $adapter = $this->_getWriteAdapter(); + $subSelect = $adapter->select(); + + $subSelect->from(false, array( + 'items_qty' => new Zend_Db_Expr( + $adapter->quoteIdentifier('q.items_qty') . ' - ' . $adapter->quoteIdentifier('qi.qty')), + 'items_count' => new Zend_Db_Expr($adapter->quoteIdentifier('q.items_count') . ' - 1') + )) + ->join( + array('qi' => $this->getTable('sales/quote_item')), + implode(' AND ', array( + 'q.entity_id = qi.quote_id', + 'qi.parent_item_id IS NULL', + $adapter->quoteInto('qi.product_id = ?', $productId) + )), + array() + ); + + $updateQuery = $adapter->updateFromSelect($subSelect, array('q' => $this->getTable('sales/quote'))); + + $adapter->query($updateQuery); + + return $this; + } + + /** + * Mark recollect contain product(s) quotes + * + * @param array|int $productIds + * @return Mage_Sales_Model_Resource_Quote + */ + public function markQuotesRecollect($productIds) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('sales/quote_item'), 'quote_id') + ->where('product_id IN(?)', $productIds) + ->distinct(true); + + $data = array('trigger_recollect' => 1); + $where = array('entity_id IN(?)' => $select); + $this->_getWriteAdapter()->update($this->getTable('sales/quote'), $data, $where); + + return $this; + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address.php new file mode 100755 index 0000000000..2af8f4e1a4 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address.php @@ -0,0 +1,46 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address', 'address_id'); + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend.php new file mode 100755 index 0000000000..56dbb43236 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend.php @@ -0,0 +1,47 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Collect totals + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend + */ + public function collectTotals(Mage_Sales_Model_Quote_Address $address) + { + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Child.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Child.php new file mode 100755 index 0000000000..cdb00856ed --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Child.php @@ -0,0 +1,53 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Child + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Set store id to the attribute + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Child + */ + public function beforeSave($object) + { + if ($object->getAddress()) { + $object->setParentId($object->getAddress()->getId()) + ->setStoreId($object->getAddress()->getStoreId()); + } + parent::beforeSave($object); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Parent.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Parent.php new file mode 100755 index 0000000000..445ed2e4a6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Parent.php @@ -0,0 +1,53 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Parent + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Save items collection and shipping rates collection + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Parent + */ + public function afterSave($object) + { + parent::afterSave($object); + + $object->getItemsCollection()->save(); + $object->getShippingRatesCollection()->save(); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Region.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Region.php new file mode 100755 index 0000000000..8ed21576ed --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Backend/Region.php @@ -0,0 +1,56 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Region + extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract +{ + /** + * Set region to the attribute + * + * @param Varien_Object $object + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Backend_Region + */ + public function beforeSave($object) + { + if (is_numeric($object->getRegion())) { + $region = Mage::getModel('directory/region')->load((int)$object->getRegion()); + if ($region) { + $object->setRegionId($region->getId()); + $object->setRegion($region->getCode()); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend.php new file mode 100755 index 0000000000..20640c9558 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend.php @@ -0,0 +1,50 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend + extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract +{ + /** + * Fetch totals + * + * @param Mage_Sales_Model_Quote_Address $address + * @return array + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $arr = array(); + + return $arr; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Custbalance.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Custbalance.php new file mode 100755 index 0000000000..c39bf93b08 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Custbalance.php @@ -0,0 +1,56 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Custbalance + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Fetch customer balance + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Custbalance + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $custbalance = $address->getCustbalanceAmount(); + if ($custbalance != 0) { + $address->addTotal(array( + 'code' => 'custbalance', + 'title' => Mage::helper('sales')->__('Store Credit'), + 'value' => -$custbalance + )); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Discount.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Discount.php new file mode 100755 index 0000000000..c2363b0697 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Discount.php @@ -0,0 +1,60 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Discount + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Fetch discount + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Discount + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $amount = $address->getDiscountAmount(); + if ($amount != 0) { + $title = Mage::helper('sales')->__('Discount'); + if ($address->getQuote()->getCouponCode()) { + $title .= sprintf(' (%s)', $address->getQuote()->getCouponCode()); + } + $address->addTotal(array( + 'code' => 'discount', + 'title' => $title, + 'value' => -$amount + )); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Grand.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Grand.php new file mode 100755 index 0000000000..aa3b5bd312 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Grand.php @@ -0,0 +1,54 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Grand + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Fetch grand total + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Grand + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $address->addTotal(array( + 'code' => 'grand_total', + 'title' => Mage::helper('sales')->__('Grand Total'), + 'value' => $address->getGrandTotal(), + 'area' => 'footer', + )); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Shipping.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Shipping.php new file mode 100755 index 0000000000..e41da0daef --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Shipping.php @@ -0,0 +1,60 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Shipping + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Fetch totals + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Shipping + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $amount = $address->getShippingAmount(); + if ($amount != 0) { + $title = Mage::helper('sales')->__('Shipping & Handling'); + if ($address->getShippingDescription()) { + $title .= sprintf(' (%s)', $address->getShippingDescription()); + } + $address->addTotal(array( + 'code' => 'shipping', + 'title' => $title, + 'value' => $address->getShippingAmount() + )); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Subtotal.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Subtotal.php new file mode 100755 index 0000000000..e1bf4ca73a --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Subtotal.php @@ -0,0 +1,54 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Subtotal + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Add total + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Subtotal + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $address->addTotal(array( + 'code' => 'subtotal', + 'title' => Mage::helper('sales')->__('Subtotal'), + 'value' => $address->getSubtotal() + )); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Tax.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Tax.php new file mode 100755 index 0000000000..b1f3b99a35 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Attribute/Frontend/Tax.php @@ -0,0 +1,56 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Tax + extends Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend +{ + /** + * Fetch totals + * + * @param Mage_Sales_Model_Quote_Address $address + * @return Mage_Sales_Model_Resource_Quote_Address_Attribute_Frontend_Tax + */ + public function fetchTotals(Mage_Sales_Model_Quote_Address $address) + { + $amount = $address->getTaxAmount(); + if ($amount != 0) { + $address->addTotal(array( + 'code' => 'tax', + 'title' => Mage::helper('sales')->__('Tax'), + 'value' => $amount + )); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Collection.php new file mode 100755 index 0000000000..e51624cff4 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Collection.php @@ -0,0 +1,89 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_quote_address_collection'; + + /** + * Event object name + * + * @var string + */ + protected $_eventObject = 'quote_address_collection'; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address'); + } + + /** + * Setting filter on quote_id field but if quote_id is 0 + * we should exclude loading junk data from DB + * + * @param int $quoteId + * @return Mage_Sales_Model_Resource_Quote_Address_Collection + */ + public function setQuoteFilter($quoteId) + { + $this->addFieldToFilter('quote_id', $quoteId ? $quoteId : array('null' => 1)); + return $this; + } + + /** + * Redeclare after load method for dispatch event + * + * @return Mage_Sales_Model_Resource_Quote_Address_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + Mage::dispatchEvent($this->_eventPrefix.'_load_after', array( + $this->_eventObject => $this + )); + + return $this; + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item.php new file mode 100755 index 0000000000..4309ba7c9c --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Item extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address_item', 'address_item_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item/Collection.php new file mode 100755 index 0000000000..b578863484 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Item/Collection.php @@ -0,0 +1,83 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address_item'); + } + + /** + * Set parent items + * + * @return Mage_Sales_Model_Resource_Quote_Address_Item_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + /** + * Assign parent items + */ + foreach ($this as $item) { + if ($item->getParentItemId()) { + $item->setParentItem($this->getItemById($item->getParentItemId())); + } + } + + return $this; + } + + /** + * Set address filter + * + * @param int $addressId + * @return Mage_Sales_Model_Resource_Quote_Address_Item_Collection + */ + public function setAddressFilter($addressId) + { + if ($addressId) { + $this->addFieldToFilter('quote_address_id', $addressId); + } else { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate.php new file mode 100755 index 0000000000..1d45e968ea --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Rate extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address_shipping_rate', 'rate_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate/Collection.php new file mode 100755 index 0000000000..803d4a4e93 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Address/Rate/Collection.php @@ -0,0 +1,95 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Address_Rate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Whether to load fixed items only + * + * @var bool + */ + protected $_allowFixedOnly = false; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_address_rate'); + } + + /** + * Set filter by address id + * + * @param int $addressId + * @return Mage_Sales_Model_Resource_Quote_Address_Rate_Collection + */ + public function setAddressFilter($addressId) + { + if ($addressId) { + $this->addFieldToFilter('address_id', $addressId); + } else { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + } + return $this; + } + + /** + * Setter for loading fixed items only + * + * @param bool $value + * @return Mage_Sales_Model_Resource_Quote_Address_Rate_Collection + */ + public function setFixedOnlyFilter($value) + { + $this->_allowFixedOnly = (bool)$value; + return $this; + } + + /** + * Don't add item to the collection if only fixed are allowed and its carrier is not fixed + * + * @param Mage_Sales_Model_Quote_Address_Rate $rate + * @return Mage_Sales_Model_Resource_Quote_Address_Rate_Collection + */ + public function addItem(Varien_Object $rate) + { + if ($this->_allowFixedOnly && (!$rate->getCarrierInstance() || !$rate->getCarrierInstance()->isFixed())) { + return $this; + } + return parent::addItem($rate); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Collection.php new file mode 100755 index 0000000000..5a5a10d597 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Collection.php @@ -0,0 +1,46 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote'); + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Item.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Item.php new file mode 100755 index 0000000000..415a82612d --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Item.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Item extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_item', 'item_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Collection.php new file mode 100755 index 0000000000..0e482230b9 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Collection.php @@ -0,0 +1,243 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Collection quote instance + * + * @var Mage_Sales_Model_Quote + */ + protected $_quote; + + /** + * Product Ids array + * + * @var array + */ + protected $_productIds = array(); + + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('sales/quote_item'); + } + + /** + * Retrieve store Id (From Quote) + * + * @return int + */ + public function getStoreId() + { + return (int)$this->_quote->getStoreId(); + } + + /** + * Set Quote object to Collection + * + * @param Mage_Sales_Model_Quote $quote + * @return Mage_Sales_Model_Resource_Quote_Item_Collection + */ + public function setQuote($quote) + { + $this->_quote = $quote; + $quoteId = $quote->getId(); + if ($quoteId) { + $this->addFieldToFilter('quote_id', $quote->getId()); + } else { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + } + return $this; + } + + /** + * Reset the collection and inner join it to quotes table + * Optionally can select items with specified product id only + * + * @param string $quotesTableName + * @param int $productId + * @return Mage_Sales_Model_Resource_Quote_Item_Collection + */ + public function resetJoinQuotes($quotesTableName, $productId = null) + { + $this->getSelect()->reset() + ->from( + array('qi' => $this->getResource()->getMainTable()), + array('item_id', 'qty', 'quote_id')) + ->joinInner( + array('q' => $quotesTableName), + 'qi.quote_id = q.entity_id', + array('store_id', 'items_qty', 'items_count') + ); + if ($productId) { + $this->getSelect()->where('qi.product_id = ?', (int)$productId); + } + return $this; + } + + /** + * After load processing + * + * @return Mage_Sales_Model_Resource_Quote_Item_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + /** + * Assign parent items + */ + foreach ($this as $item) { + if ($item->getParentItemId()) { + $item->setParentItem($this->getItemById($item->getParentItemId())); + } + if ($this->_quote) { + $item->setQuote($this->_quote); + } + } + + /** + * Assign options and products + */ + $this->_assignOptions(); + $this->_assignProducts(); + $this->resetItemsDataChanged(); + + return $this; + } + + /** + * Add options to items + * + * @return Mage_Sales_Model_Resource_Quote_Item_Collection + */ + protected function _assignOptions() + { + $itemIds = array_keys($this->_items); + $optionCollection = Mage::getModel('sales/quote_item_option')->getCollection() + ->addItemFilter($itemIds); + foreach ($this as $item) { + $item->setOptions($optionCollection->getOptionsByItem($item)); + } + $productIds = $optionCollection->getProductIds(); + $this->_productIds = array_merge($this->_productIds, $productIds); + + return $this; + } + + /** + * Add products to items and item options + * + * @return Mage_Sales_Model_Resource_Quote_Item_Collection + */ + protected function _assignProducts() + { + Varien_Profiler::start('QUOTE:'.__METHOD__); + $productIds = array(); + foreach ($this as $item) { + $productIds[] = (int)$item->getProductId(); + } + $this->_productIds = array_merge($this->_productIds, $productIds); + + $productCollection = Mage::getModel('catalog/product')->getCollection() + ->setStoreId($this->getStoreId()) + ->addIdFilter($this->_productIds) + ->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes()) + ->addOptionsToResult() + ->addStoreFilter() + ->addUrlRewrite() + ->addTierPriceData(); + + Mage::dispatchEvent('prepare_catalog_product_collection_prices', array( + 'collection' => $productCollection, + 'store_id' => $this->getStoreId(), + )); + Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array( + 'product_collection' => $productCollection + )); + + $recollectQuote = false; + foreach ($this as $item) { + $product = $productCollection->getItemById($item->getProductId()); + if ($product) { + $product->setCustomOptions(array()); + $qtyOptions = array(); + $optionProductIds = array(); + foreach ($item->getOptions() as $option) { + /** + * Call type specified logic for product associated with quote item + */ + $product->getTypeInstance(true)->assignProductToOption( + $productCollection->getItemById($option->getProductId()), + $option, + $product + ); + + if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) { + $optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId(); + } + } + + if ($optionProductIds) { + foreach ($optionProductIds as $optionProductId) { + $qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId); + if ($qtyOption) { + $qtyOptions[$optionProductId] = $qtyOption; + } + } + } + $item->setQtyOptions($qtyOptions); + + $item->setProduct($product); + } else { + $item->isDeleted(true); + $recollectQuote = true; + } + $item->checkData(); + } + + if ($recollectQuote && $this->_quote) { + $this->_quote->collectTotals(); + } + Varien_Profiler::stop('QUOTE:'.__METHOD__); + + return $this; + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option.php new file mode 100755 index 0000000000..70aff70216 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Item_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_item_option', 'option_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option/Collection.php new file mode 100755 index 0000000000..8e74cafdc5 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Item/Option/Collection.php @@ -0,0 +1,174 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Item_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Array of option ids grouped by item id + * + * @var array + */ + protected $_optionsByItem = array(); + + /** + * Array of option ids grouped by product id + * + * @var array + */ + protected $_optionsByProduct = array(); + + /** + * Define resource model for collection + * + */ + protected function _construct() + { + $this->_init('sales/quote_item_option'); + } + + /** + * Fill array of options by item and product + * + * @return Mage_Sales_Model_Resource_Quote_Item_Option_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + foreach ($this as $option) { + $optionId = $option->getId(); + $itemId = $option->getItemId(); + $productId = $option->getProductId(); + if (isset($this->_optionsByItem[$itemId])) { + $this->_optionsByItem[$itemId][] = $optionId; + } else { + $this->_optionsByItem[$itemId] = array($optionId); + } + if (isset($this->_optionsByProduct[$productId])) { + $this->_optionsByProduct[$productId][] = $optionId; + } else { + $this->_optionsByProduct[$productId] = array($optionId); + } + } + + return $this; + } + + /** + * Apply quote item(s) filter to collection + * + * @param int | array $item + * @return Mage_Sales_Model_Resource_Quote_Item_Option_Collection + */ + public function addItemFilter($item) + { + if (empty($item)) { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + //$this->addFieldToFilter('item_id', ''); + } elseif (is_array($item)) { + $this->addFieldToFilter('item_id', array('in' => $item)); + } elseif ($item instanceof Mage_Sales_Model_Quote_Item) { + $this->addFieldToFilter('item_id', $item->getId()); + } else { + $this->addFieldToFilter('item_id', $item); + } + + return $this; + } + + /** + * Get array of all product ids + * + * @return array + */ + public function getProductIds() + { + $this->load(); + + return array_keys($this->_optionsByProduct); + } + + /** + * Get all option for item + * + * @param mixed $item + * @return array + */ + public function getOptionsByItem($item) + { + if ($item instanceof Mage_Sales_Model_Quote_Item) { + $itemId = $item->getId(); + } else { + $itemId = $item; + } + + $this->load(); + + $options = array(); + if (isset($this->_optionsByItem[$itemId])) { + foreach ($this->_optionsByItem[$itemId] as $optionId) { + $options[] = $this->_items[$optionId]; + } + } + + return $options; + } + + /** + * Get all option for item + * + * @param int | Mage_Catalog_Model_Product $product + * @return array + */ + public function getOptionsByProduct($product) + { + if ($product instanceof Mage_Catalog_Model_Product) { + $productId = $product->getId(); + } else { + $productId = $product; + } + + $this->load(); + + $options = array(); + if (isset($this->_optionsByProduct[$productId])) { + foreach ($this->_optionsByProduct[$productId] as $optionId) { + $options[] = $this->_items[$optionId]; + } + } + + return $options; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Payment.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Payment.php new file mode 100755 index 0000000000..c36456b7be --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Payment.php @@ -0,0 +1,54 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Payment extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Serializeable field: additional_information + * + * @var array + */ + protected $_serializableFields = array( + 'additional_information' => array(null, array()) + ); + + /** + * Main table and field initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_payment', 'payment_id'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Quote/Payment/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Quote/Payment/Collection.php new file mode 100755 index 0000000000..a04e532c65 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Quote/Payment/Collection.php @@ -0,0 +1,70 @@ + + */ +class Mage_Sales_Model_Resource_Quote_Payment_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('sales/quote_payment'); + } + + /** + * Setquote filter to result + * + * @param int $quoteId + * @return Mage_Sales_Model_Resource_Quote_Payment_Collection + */ + public function setQuoteFilter($quoteId) + { + return $this->addFieldToFilter('quote_id', $quoteId); + } + + /** + * Unserialize additional_information in each item + * + * @return Mage_Core_Model_Resource_Db_Collection_Abstract + */ + protected function _afterLoad() + { + foreach ($this->_items as $item) { + $this->getResource()->unserializeFields($item); + } + return parent::_afterLoad(); + } +} + diff --git a/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile.php b/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile.php new file mode 100755 index 0000000000..6c020f3ec7 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile.php @@ -0,0 +1,93 @@ + + */ +class Mage_Sales_Model_Resource_Recurring_Profile extends Mage_Sales_Model_Resource_Abstract +{ + /** + * Initialize main table and column + * + */ + protected function _construct() + { + $this->_init('sales/recurring_profile', 'profile_id'); + + $this->_serializableFields = array( + 'profile_vendor_info' => array(null, array()), + 'additional_info' => array(null, array()), + + 'order_info' => array(null, array()), + 'order_item_info' => array(null, array()), + 'billing_address_info' => array(null, array()), + 'shipping_address_info' => array(null, array()) + ); + } + + /** + * Return recurring profile child Orders Ids + * + * + * @param Varien_Object $object + * @return array + */ + public function getChildOrderIds($object) + { + $adapter = $this->_getReadAdapter(); + $bind = array(':profile_id' => $object->getId()); + $select = $adapter->select() + ->from( + array('main_table' => $this->getTable('sales/recurring_profile_order')), + array('order_id')) + ->where('profile_id=:profile_id'); + + return $adapter->fetchCol($select, $bind); + } + + /** + * Add order relation to recurring profile + * + * @param int $recurringProfileId + * @param int $orderId + * @return Mage_Sales_Model_Resource_Recurring_Profile + */ + public function addOrderRelation($recurringProfileId, $orderId) + { + $this->_getWriteAdapter()->insert( + $this->getTable('sales/recurring_profile_order'), array( + 'profile_id' => $recurringProfileId, + 'order_id' => $orderId + ) + ); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile/Collection.php new file mode 100755 index 0000000000..a40e6de6b9 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Recurring/Profile/Collection.php @@ -0,0 +1,59 @@ + + */ +class Mage_Sales_Model_Resource_Recurring_Profile_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'sales_recurring_profile_collection'; + + /** + * Event object + * + * @var string + */ + protected $_eventObject = 'recurring_profile_collection'; + + /** + * Entity initialization + * + */ + protected function _construct() + { + $this->_init('sales/recurring_profile'); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report.php b/app/code/core/Mage/Sales/Model/Resource/Report.php new file mode 100755 index 0000000000..e010dc4d64 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report.php @@ -0,0 +1,58 @@ + + */ +class Mage_Sales_Model_Resource_Report extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + + } + + /** + * Set main table and idField + * + * @param string $table + * @param string $field + * @return Mage_Sales_Model_Resource_Report + */ + public function init($table, $field = 'id') + { + $this->_init($table, $field); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Report/Abstract.php new file mode 100755 index 0000000000..1db59e0a59 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Abstract.php @@ -0,0 +1,38 @@ + + */ +abstract class Mage_Sales_Model_Resource_Report_Abstract extends Mage_Reports_Model_Resource_Report_Abstract +{ + +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers.php new file mode 100755 index 0000000000..c553ce647a --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers.php @@ -0,0 +1,286 @@ + + */ +class Mage_Sales_Model_Resource_Report_Bestsellers extends Mage_Sales_Model_Resource_Report_Abstract +{ + const AGGREGATION_DAILY = 'daily'; + const AGGREGATION_MONTHLY = 'monthly'; + const AGGREGATION_YEARLY = 'yearly'; + + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/bestsellers_aggregated_' . self::AGGREGATION_DAILY, 'id'); + } + + /** + * Aggregate Orders data by order created at + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Bestsellers + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $adapter = $this->_getWriteAdapter(); + //$this->_getWriteAdapter()->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect( + $this->getTable('sales/order'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('source_table.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + + $helper = Mage::getResourceHelper('core'); + $select = $adapter->select(); + + $select->group(array( + $periodExpr, + 'source_table.store_id', + 'order_item.product_id' + )); + + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'source_table.store_id', + 'product_id' => 'order_item.product_id', + 'product_name' => new Zend_Db_Expr( + sprintf('MIN(%s)', + $adapter->getIfNullSql('product_name.value','product_default_name.value') + ) + ), + 'product_price' => new Zend_Db_Expr( + sprintf('%s * %s', + $helper->prepareColumn( + sprintf('MIN(%s)', + $adapter->getIfNullSql( + $adapter->getIfNullSql('product_price.value','product_default_price.value'),0) + ), + $select->getPart(Zend_Db_Select::GROUP) + ), + $helper->prepareColumn( + sprintf('MIN(%s)', + $adapter->getIfNullSql('source_table.base_to_global_rate', '0') + ), + $select->getPart(Zend_Db_Select::GROUP) + ) + ) + ), + 'qty_ordered' => new Zend_Db_Expr('SUM(order_item.qty_ordered)') + ); + + $select + ->from( + array( + 'source_table' => $this->getTable('sales/order')), + $columns) + ->joinInner( + array( + 'order_item' => $this->getTable('sales/order_item')), + 'order_item.order_id = source_table.entity_id', + array() + ) + ->where('source_table.state != ?', Mage_Sales_Model_Order::STATE_CANCELED); + + + /** @var Mage_Catalog_Model_Resource_Product $product */ + $product = Mage::getResourceSingleton('catalog/product'); + + $productTypes = array( + Mage_Catalog_Model_Product_Type::TYPE_GROUPED, + Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, + Mage_Catalog_Model_Product_Type::TYPE_BUNDLE, + ); + + $joinExpr = array( + 'product.entity_id = order_item.product_id', + $adapter->quoteInto('product.entity_type_id = ?', $product->getTypeId()), + $adapter->quoteInto('product.type_id NOT IN(?)', $productTypes) + ); + + $joinExpr = implode(' AND ', $joinExpr); + $select->joinInner( + array( + 'product' => $this->getTable('catalog/product')), + $joinExpr, + array() + ); + + // join product attributes Name & Price + $attr = $product->getAttribute('name'); + $joinExprProductName = array( + 'product_name.entity_id = product.entity_id', + 'product_name.store_id = source_table.store_id', + $adapter->quoteInto('product_name.entity_type_id = ?', $product->getTypeId()), + $adapter->quoteInto('product_name.attribute_id = ?', $attr->getAttributeId()) + ); + $joinExprProductName = implode(' AND ', $joinExprProductName); + $joinExprProductDefaultName = array( + 'product_default_name.entity_id = product.entity_id', + 'product_default_name.store_id = 0', + $adapter->quoteInto('product_default_name.entity_type_id = ?', $product->getTypeId()), + $adapter->quoteInto('product_default_name.attribute_id = ?', $attr->getAttributeId()) + ); + $joinExprProductDefaultName = implode(' AND ', $joinExprProductDefaultName); + $select->joinLeft( + array( + 'product_name' => $attr->getBackend()->getTable()), + $joinExprProductName, + array() + ) + ->joinLeft( + array( + 'product_default_name' => $attr->getBackend()->getTable()), + $joinExprProductDefaultName, + array() + ); + $attr = $product->getAttribute('price'); + $joinExprProductPrice = array( + 'product_price.entity_id = product.entity_id', + 'product_price.store_id = source_table.store_id', + $adapter->quoteInto('product_price.entity_type_id = ?', $product->getTypeId()), + $adapter->quoteInto('product_price.attribute_id = ?', $attr->getAttributeId()) + ); + $joinExprProductPrice = implode(' AND ', $joinExprProductPrice); + + $joinExprProductDefPrice = array( + 'product_default_price.entity_id = product.entity_id', + 'product_default_price.store_id = 0', + $adapter->quoteInto('product_default_price.entity_type_id = ?', $product->getTypeId()), + $adapter->quoteInto('product_default_price.attribute_id = ?', $attr->getAttributeId()) + ); + $joinExprProductDefPrice = implode(' AND ', $joinExprProductDefPrice); + $select->joinLeft( + array('product_price' => $attr->getBackend()->getTable()), + $joinExprProductPrice, + array() + ) + ->joinLeft( + array('product_default_price' => $attr->getBackend()->getTable()), + $joinExprProductDefPrice, + array() + ); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); + } + + + $select->useStraightJoin(); // important! + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $this->getMainTable(), + array_keys($columns)); + $adapter->query($insertQuery); + + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'product_id' => 'product_id', + 'product_name' => new Zend_Db_expr('MIN(product_name)'), + 'product_price' => new Zend_Db_expr('MIN(product_price)'), + 'qty_ordered' => new Zend_Db_expr('SUM(qty_ordered)'), + ); + + $select->reset(); + $select->from($this->getMainTable(), $columns) + ->where('store_id <> ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'product_id' + )); + + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $this->getMainTable(), + array_keys($columns)); + $adapter->query($insertQuery); + + // update rating + $this->_updateRatingPos(self::AGGREGATION_DAILY); + $this->_updateRatingPos(self::AGGREGATION_MONTHLY); + $this->_updateRatingPos(self::AGGREGATION_YEARLY); + + + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_BESTSELLERS_FLAG_CODE); + } catch (Exception $e) { + //$this->_getWriteAdapter()->rollBack(); + throw $e; + } + + //$this->_getWriteAdapter()->commit(); + return $this; + } + + /** + * Update rating position + * + * @param string $aggregation One of Mage_Sales_Model_Resource_Report_Bestsellers::AGGREGATION_XXX constants + * @return Mage_Sales_Model_Resource_Report_Bestsellers + */ + protected function _updateRatingPos($aggregation) + { + $aggregationTable = $this->getTable('sales/bestsellers_aggregated_' . $aggregation); + + $aggregationAliases = array( + 'daily' => self::AGGREGATION_DAILY, + 'monthly' => self::AGGREGATION_MONTHLY, + 'yearly' => self::AGGREGATION_YEARLY + ); + Mage::getResourceHelper('sales') + ->getBestsellersReportUpdateRatingPos($aggregation, $aggregationAliases, + $this->getMainTable(), $aggregationTable); + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php new file mode 100755 index 0000000000..41f879ce7b --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -0,0 +1,368 @@ + + */ +class Mage_Sales_Model_Resource_Report_Bestsellers_Collection + extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Rating limit + * + * @var int + */ + protected $_ratingLimit = 5; + + /** + * Columns for select + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/bestsellers_aggregated_daily'); + $this->setConnection($this->getResource()->getReadConnection()); + // overwrite default behaviour + $this->_applyFilters = false; + } + + /** + * Retrieve columns for select + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + + if (!$this->_selectedColumns) { + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } else { + $this->_selectedColumns = array( + 'period' => sprintf('MAX(%s)', $adapter->getDateFormatSql('period', '%Y-%m-%d')), + 'qty_ordered' => 'SUM(qty_ordered)', + 'product_id' => 'product_id', + 'product_name' => 'MAX(product_name)', + 'product_price' => 'MAX(product_price)', + ); + if ('year' == $this->_period) { + $this->_selectedColumns['period'] = $adapter->getDateFormatSql('period', '%Y'); + } elseif ('month' == $this->_period) { + $this->_selectedColumns['period'] = $adapter->getDateFormatSql('period', '%Y-%m'); + } + } + } + return $this->_selectedColumns; + } + + /** + * Make select object for date boundary + * + * @param mixed $from + * @param mixed $to + * @return Zend_Db_Select + */ + protected function _makeBoundarySelect($from, $to) + { + $adapter = $this->getConnection(); + $cols = $this->_getSelectedColumns(); + $cols['qty_ordered'] = 'SUM(qty_ordered)'; + $sel = $adapter->select() + ->from($this->getResource()->getMainTable(), $cols) + ->where('period >= ?', $from) + ->where('period <= ?', $to) + ->group('product_id') + ->order('qty_ordered') + ->limit($this->_ratingLimit); + + $this->_applyStoresFilterToSelect($sel); + + return $sel; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Bestsellers_Collection + */ + protected function _initSelect() + { + $select = $this->getSelect(); + + // if grouping by product, not by period + if (!$this->_period) { + $cols = $this->_getSelectedColumns(); + $cols['qty_ordered'] = 'SUM(qty_ordered)'; + if ($this->_from || $this->_to) { + $mainTable = $this->getTable('sales/bestsellers_aggregated_daily'); + $select->from($mainTable, $cols); + } else { + $mainTable = $this->getTable('sales/bestsellers_aggregated_yearly'); + $select->from($mainTable, $cols); + } + + //exclude removed products + $subSelect = $this->getConnection()->select(); + $subSelect->from(array('existed_products' => $this->getTable('catalog/product')), new Zend_Db_Expr('1)')); + + $select->exists($subSelect, $mainTable . '.product_id = existed_products.entity_id') + ->group('product_id') + ->order('qty_ordered ' . Varien_Db_Select::SQL_DESC) + ->limit($this->_ratingLimit); + + return $this; + } + + if ('year' == $this->_period) { + $mainTable = $this->getTable('sales/bestsellers_aggregated_yearly'); + $select->from($mainTable, $this->_getSelectedColumns()); + } elseif ('month' == $this->_period) { + $mainTable = $this->getTable('sales/bestsellers_aggregated_monthly'); + $select->from($mainTable, $this->_getSelectedColumns()); + } else { + $mainTable = $this->getTable('sales/bestsellers_aggregated_daily'); + $select->from($mainTable, $this->_getSelectedColumns()); + } + if (!$this->isTotals()) { + $select->group(array('period', 'product_id')); + } + $select->where('rating_pos <= ?', $this->_ratingLimit); + + return $this; + } + + /** + * Get SQL for get record count + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $this->_renderFilters(); + return $this->getConnection()->select()->from($this->getSelect(), 'COUNT(*)'); + } + + /** + * Set ids for store restrictions + * + * @param array $storeIds + * @return Mage_Sales_Model_Resource_Report_Bestsellers_Collection + */ + public function addStoreRestrictions($storeIds) + { + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + $currentStoreIds = $this->_storesIds; + if (isset($currentStoreIds) && $currentStoreIds != Mage_Core_Model_App::ADMIN_STORE_ID + && $currentStoreIds != array(Mage_Core_Model_App::ADMIN_STORE_ID)) { + if (!is_array($currentStoreIds)) { + $currentStoreIds = array($currentStoreIds); + } + $this->_storesIds = array_intersect($currentStoreIds, $storeIds); + } else { + $this->_storesIds = $storeIds; + } + + return $this; + } + + /** + * Redeclare parent method for applying filters after parent method + * but before adding unions and calculating totals + * + * @return Mage_Sales_Model_Resource_Report_Bestsellers_Collection + */ + protected function _beforeLoad() + { + parent::_beforeLoad(); + + $this->_applyStoresFilter(); + $this->_applyDateRangeFilter(); + + if ($this->_period) { + // + $selectUnions = array(); + + // apply date boundaries (before calling $this->_applyDateRangeFilter()) + $dtFormat = Varien_Date::DATE_INTERNAL_FORMAT; + $periodFrom = (!is_null($this->_from) ? new Zend_Date($this->_from, $dtFormat) : null); + $periodTo = (!is_null($this->_to) ? new Zend_Date($this->_to, $dtFormat) : null); + if ('year' == $this->_period) { + + if ($periodFrom) { + // not the first day of the year + if ($periodFrom->toValue(Zend_Date::MONTH) != 1 || $periodFrom->toValue(Zend_Date::DAY) != 1) { + $dtFrom = $periodFrom->getDate(); + // last day of the year + $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + // first day of the next year + $this->_from = $periodFrom->getDate() + ->addYear(1) + ->setMonth(1) + ->setDay(1) + ->toString($dtFormat); + } + } + } + + if ($periodTo) { + // not the last day of the year + if ($periodTo->toValue(Zend_Date::MONTH) != 12 || $periodTo->toValue(Zend_Date::DAY) != 31) { + $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); // first day of the year + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + // last day of the previous year + $this->_to = $periodTo->getDate() + ->subYear(1) + ->setMonth(12) + ->setDay(31) + ->toString($dtFormat); + } + } + } + + if ($periodFrom && $periodTo) { + // the same year + if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR)) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + $this->getSelect()->where('1<>1'); + } + } + + } + else if ('month' == $this->_period) { + if ($periodFrom) { + // not the first day of the month + if ($periodFrom->toValue(Zend_Date::DAY) != 1) { + $dtFrom = $periodFrom->getDate(); + // last day of the month + $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); + if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + // first day of the next month + $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); + } + } + } + + if ($periodTo) { + // not the last day of the month + if ($periodTo->toValue(Zend_Date::DAY) != $periodTo->toValue(Zend_Date::MONTH_DAYS)) { + $dtFrom = $periodTo->getDate()->setDay(1); // first day of the month + $dtTo = $periodTo->getDate(); + if (!$periodFrom || $dtFrom->isLater($periodFrom)) { + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + // last day of the previous month + $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); + } + } + } + + if ($periodFrom && $periodTo) { + // the same month + if ($periodFrom->toValue(Zend_Date::YEAR) == $periodTo->toValue(Zend_Date::YEAR) + && $periodFrom->toValue(Zend_Date::MONTH) == $periodTo->toValue(Zend_Date::MONTH) + ) { + $dtFrom = $periodFrom->getDate(); + $dtTo = $periodTo->getDate(); + $selectUnions[] = $this->_makeBoundarySelect( + $dtFrom->toString($dtFormat), + $dtTo->toString($dtFormat) + ); + + $this->getSelect()->where('1<>1'); + } + } + + } + + // add unions to select + if ($selectUnions) { + $unionParts = array(); + $cloneSelect = clone $this->getSelect(); + $helper = Mage::getResourceHelper('core'); + $unionParts[] = '(' . $cloneSelect . ')'; + foreach ($selectUnions as $union) { + $query = $helper->getQueryUsingAnalyticFunction($union); + $unionParts[] = '(' . $query . ')'; + } + $this->getSelect()->reset()->union($unionParts, Zend_Db_Select::SQL_UNION_ALL); + } + + if ($this->isTotals()) { + // calculate total + $cloneSelect = clone $this->getSelect(); + $this->getSelect()->reset()->from($cloneSelect, $this->getAggregatedColumns()); + } else { + // add sorting + $this->getSelect()->order(array('period ASC', 'qty_ordered DESC')); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Collection/Abstract.php b/app/code/core/Mage/Sales/Model/Resource/Report/Collection/Abstract.php new file mode 100755 index 0000000000..8c19fe7d68 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Collection/Abstract.php @@ -0,0 +1,314 @@ + + */ +class Mage_Sales_Model_Resource_Report_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * From date + * + * @var string + */ + protected $_from = null; + + /** + * To date + * + * @var string + */ + protected $_to = null; + + /** + * Order status + * + * @var string + */ + protected $_orderStatus = null; + + /** + * Period + * + * @var string + */ + protected $_period = null; + + /** + * Store ids + * + * @var int|array + */ + protected $_storesIds = 0; + + /** + * Does filters should be applied + * + * @var bool + */ + protected $_applyFilters = true; + + /** + * Is totals + * + * @var bool + */ + protected $_isTotals = false; + + /** + * Is subtotals + * + * @var bool + */ + protected $_isSubTotals = false; + + /** + * Aggregated columns + * + * @var array + */ + protected $_aggregatedColumns = array(); + + /** + * Set array of columns that should be aggregated + * + * @param array $columns + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function setAggregatedColumns(array $columns) + { + $this->_aggregatedColumns = $columns; + return $this; + } + + /** + * Retrieve array of columns that should be aggregated + * + * @return array + */ + public function getAggregatedColumns() + { + return $this->_aggregatedColumns; + } + + /** + * Set date range + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function setDateRange($from = null, $to = null) + { + $this->_from = $from; + $this->_to = $to; + return $this; + } + + /** + * Set period + * + * @param string $period + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function setPeriod($period) + { + $this->_period = $period; + return $this; + } + + /** + * Apply date range filter + * + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + protected function _applyDateRangeFilter() + { + // Remember that field PERIOD is a DATE(YYYY-MM-DD) in all databases including Oracle + if ($this->_from !== null) { + $this->getSelect()->where('period >= ?', $this->_from); + } + if ($this->_to !== null) { + $this->getSelect()->where('period <= ?', $this->_to); + } + + return $this; + } + + /** + * Set store ids + * + * @param mixed $storeIds (null, int|string, array, array may contain null) + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function addStoreFilter($storeIds) + { + $this->_storesIds = $storeIds; + return $this; + } + + /** + * Apply stores filter to select object + * + * @param Zend_Db_Select $select + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + protected function _applyStoresFilterToSelect(Zend_Db_Select $select) + { + $nullCheck = false; + $storeIds = $this->_storesIds; + + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + + $storeIds = array_unique($storeIds); + + if ($index = array_search(null, $storeIds)) { + unset($storeIds[$index]); + $nullCheck = true; + } + + $storeIds[0] = ($storeIds[0] == '') ? 0 : $storeIds[0]; + + if ($nullCheck) { + $select->where('store_id IN(?) OR store_id IS NULL', $storeIds); + } else { + $select->where('store_id IN(?)', $storeIds); + } + + return $this; + } + + /** + * Apply stores filter + * + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + protected function _applyStoresFilter() + { + return $this->_applyStoresFilterToSelect($this->getSelect()); + } + + /** + * Set status filter + * + * @param string $orderStatus + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function addOrderStatusFilter($orderStatus) + { + $this->_orderStatus = $orderStatus; + return $this; + } + + /** + * Apply order status filter + * + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + protected function _applyOrderStatusFilter() + { + if (is_null($this->_orderStatus)) { + return $this; + } + $orderStatus = $this->_orderStatus; + if (!is_array($orderStatus)) { + $orderStatus = array($orderStatus); + } + $this->getSelect()->where('order_status IN(?)', $orderStatus); + return $this; + } + + /** + * Set apply filters flag + * + * @param boolean $flag + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function setApplyFilters($flag) + { + $this->_applyFilters = $flag; + return $this; + } + + /** + * Getter/Setter for isTotals + * + * @param null|boolean $flag + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function isTotals($flag = null) + { + if (is_null($flag)) { + return $this->_isTotals; + } + $this->_isTotals = $flag; + return $this; + } + + /** + * Getter/Setter for isSubTotals + * + * @param null|boolean $flag + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function isSubTotals($flag = null) + { + if (is_null($flag)) { + return $this->_isSubTotals; + } + $this->_isSubTotals = $flag; + return $this; + } + + /** + * Load data + * Redeclare parent load method just for adding method _beforeLoad + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Sales_Model_Resource_Report_Collection_Abstract + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + $this->_initSelect(); + if ($this->_applyFilters) { + $this->_applyDateRangeFilter(); + $this->_applyStoresFilter(); + $this->_applyOrderStatusFilter(); + } + return parent::load($printQuery, $logQuery); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced.php b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced.php new file mode 100755 index 0000000000..606b8ac7a6 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced.php @@ -0,0 +1,291 @@ + + */ +class Mage_Sales_Model_Resource_Report_Invoiced extends Mage_Sales_Model_Resource_Report_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_setResource('sales'); + } + + /** + * Aggregate Invoiced data + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Invoiced + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $this->_aggregateByOrderCreatedAt($from, $to); + $this->_aggregateByInvoiceCreatedAt($from, $to); + + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_INVOICE_FLAG_CODE); + return $this; + } + + /** + * Aggregate Invoiced data by invoice created_at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Invoiced + */ + protected function _aggregateByInvoiceCreatedAt($from, $to) + { + $table = $this->getTable('sales/invoiced_aggregated'); + $sourceTable = $this->getTable('sales/invoice'); + $orderTable = $this->getTable('sales/order'); + $helper = Mage::getResourceHelper('core'); + $adapter = $this->_getWriteAdapter(); + + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeRelatedSelect( + $sourceTable, $orderTable, array('order_id'=>'entity_id'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('source_table.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + $columns = array( + // convert dates from UTC to current admin timezone + 'period' => $periodExpr, + 'store_id' => 'order_table.store_id', + 'order_status' => 'order_table.status', + 'orders_count' => new Zend_Db_expr('COUNT(order_table.entity_id)'), + 'orders_invoiced' => new Zend_Db_expr('COUNT(order_table.entity_id)'), + 'invoiced' => new Zend_Db_expr('SUM(order_table.base_total_invoiced' + . ' * order_table.base_to_global_rate)'), + 'invoiced_captured' => new Zend_Db_expr('SUM(order_table.base_total_paid' + . ' * order_table.base_to_global_rate)'), + 'invoiced_not_captured' => new Zend_Db_expr( + 'SUM((order_table.base_total_invoiced - order_table.base_total_paid)' + . ' * order_table.base_to_global_rate)') + ); + + $select = $adapter->select(); + $select->from(array('source_table' => $sourceTable), $columns) + ->joinInner( + array('order_table' => $orderTable), + $adapter->quoteInto( + 'source_table.order_id = order_table.entity_id AND order_table.state <> ?', + Mage_Sales_Model_Order::STATE_CANCELED), + array() + ); + + $filterSubSelect = $adapter->select(); + $filterSubSelect->from(array('filter_source_table' => $sourceTable), 'MAX(filter_source_table.entity_id)') + ->where('filter_source_table.order_id = source_table.order_id'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); + } + + $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); + unset($filterSubSelect); + + $select->group(array( + $periodExpr, + 'order_table.store_id', + 'order_table.status' + )); + + $select->having('orders_count > 0'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'order_status' => 'order_status', + 'orders_count' => new Zend_Db_expr('SUM(orders_count)'), + 'orders_invoiced' => new Zend_Db_expr('SUM(orders_invoiced)'), + 'invoiced' => new Zend_Db_expr('SUM(invoiced)'), + 'invoiced_captured' => new Zend_Db_expr('SUM(invoiced_captured)'), + 'invoiced_not_captured' => new Zend_Db_expr('SUM(invoiced_not_captured)') + ); + + $select + ->from($table, $columns) + ->where('store_id <> ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status' + )); + + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Aggregate Invoiced data by order created_at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Invoiced + */ + protected function _aggregateByOrderCreatedAt($from, $to) + { + $table = $this->getTable('sales/invoiced_aggregated_order'); + $sourceTable = $this->getTable('sales/order'); + $adapter = $this->_getWriteAdapter(); + + + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql( + $adapter->getDateAddSql('created_at', + $this->_getStoreTimezoneUtcOffset(), + Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'store_id', + 'order_status' => 'status', + 'orders_count' => new Zend_Db_Expr('COUNT(base_total_invoiced)'), + 'orders_invoiced' => new Zend_Db_Expr( + sprintf('SUM(%s)', + $adapter->getCheckSql('base_total_invoiced > 0', 1, 0) + ) + ), + 'invoiced' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('base_total_invoiced',0), + $adapter->getIfNullSql('base_to_global_rate',0) + ) + ), + 'invoiced_captured' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('base_total_paid',0), + $adapter->getIfNullSql('base_to_global_rate',0) + ) + ), + 'invoiced_not_captured' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('base_total_invoiced',0), + $adapter->getIfNullSql('base_total_paid',0), + $adapter->getIfNullSql('base_to_global_rate',0) + ) + ) + + ); + + $select = $adapter->select(); + $select->from($sourceTable, $columns) + ->where('state <> ?', Mage_Sales_Model_Order::STATE_CANCELED); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); + } + + $select->group(array( + $periodExpr, + 'store_id', + 'status' + )); + + $select->having('orders_count > 0'); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'order_status' => 'order_status', + 'orders_count' => new Zend_Db_expr('SUM(orders_count)'), + 'orders_invoiced' => new Zend_Db_expr('SUM(orders_invoiced)'), + 'invoiced' => new Zend_Db_expr('SUM(invoiced)'), + 'invoiced_captured' => new Zend_Db_expr('SUM(invoiced_captured)'), + 'invoiced_not_captured' => new Zend_Db_expr('SUM(invoiced_not_captured)') + ); + + $select->from($table, $columns) + ->where('store_id <> ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status' + )); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + + + return $this; + } +} diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Gallery.php b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Invoiced.php old mode 100644 new mode 100755 similarity index 61% rename from app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Gallery.php rename to app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Invoiced.php index 4194680ad9..d90addd025 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Gallery.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Invoiced.php @@ -19,32 +19,31 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Catalog - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Sales + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Category image attribute backend + * Sales report invoiced collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Sales * @author Magento Core Team */ - -class Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Gallery extends Mage_Eav_Model_Entity_Attribute_Backend_Gallery +class Mage_Sales_Model_Resource_Report_Invoiced_Collection_Invoiced + extends Mage_Sales_Model_Resource_Report_Invoiced_Collection_Order { - + /** + * Initialize custom resource model + * + */ public function __construct() { - parent::__construct(); - $resource = Mage::getSingleton('core/resource'); - $this->setConnection($resource->getConnection('catalog_read'), $resource->getConnection('catalog_write')); - /** - * 0 - big image - * 1 - thumbnail - */ - $this->_imageTypes = array(0, 1); + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/invoiced_aggregated'); + $this->setConnection($this->getResource()->getReadConnection()); } - } diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Order.php b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Order.php new file mode 100755 index 0000000000..fb95dd1e7b --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Invoiced/Collection/Order.php @@ -0,0 +1,112 @@ + + */ +class Mage_Sales_Model_Resource_Report_Invoiced_Collection_Order + extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var string + */ + protected $_periodFormat; + + /** + * Columns for select + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/invoiced_aggregated_order'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Retrieve columns for select + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'orders_count' => 'SUM(orders_count)', + 'orders_invoiced' => 'SUM(orders_invoiced)', + 'invoiced' => 'SUM(invoiced)', + 'invoiced_captured' => 'SUM(invoiced_captured)', + 'invoiced_not_captured' => 'SUM(invoiced_not_captured)' + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Invoiced_Collection_Order + */ + protected function _initSelect() + { + $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); + if (!$this->isTotals()) { + $this->getSelect()->group($this->_periodFormat); + $this->getSelect()->having('SUM(orders_count) > 0'); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Order.php b/app/code/core/Mage/Sales/Model/Resource/Report/Order.php new file mode 100755 index 0000000000..0253e5133b --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Order.php @@ -0,0 +1,239 @@ + + */ +class Mage_Sales_Model_Resource_Report_Order extends Mage_Sales_Model_Resource_Report_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_init('sales/order_aggregated_created', 'id'); + } + + /** + * Aggregate Orders data by order created at + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Order + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $adapter = $this->_getWriteAdapter(); + + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect( + $this->getTable('sales/order'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); + + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('o.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + // Columns list + $columns = array( + // convert dates from UTC to current admin timezone + 'period' => $periodExpr, + 'store_id' => 'o.store_id', + 'order_status' => 'o.status', + 'orders_count' => new Zend_Db_Expr('COUNT(o.entity_id)'), + 'total_qty_ordered' => new Zend_Db_Expr('SUM(oi.total_qty_ordered)'), + 'total_qty_invoiced' => new Zend_Db_Expr('SUM(oi.total_qty_invoiced)'), + 'total_income_amount' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_grand_total', 0), + $adapter->getIfNullSql('o.base_total_canceled',0), + $adapter->getIfNullSql('o.base_to_global_rate',0) + ) + ), + 'total_revenue_amount' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_total_paid', 0), + $adapter->getIfNullSql('o.base_total_refunded', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_profit_amount' => new Zend_Db_Expr( + sprintf('SUM((%s - %s - %s - %s - %s) * %s)', + $adapter->getIfNullSql('o.base_total_paid', 0), + $adapter->getIfNullSql('o.base_total_refunded', 0), + $adapter->getIfNullSql('o.base_tax_invoiced', 0), + $adapter->getIfNullSql('o.base_shipping_invoiced', 0), + $adapter->getIfNullSql('o.base_total_invoiced_cost', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_invoiced_amount' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('o.base_total_invoiced', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_canceled_amount' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('o.base_total_canceled', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_paid_amount' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('o.base_total_paid', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_refunded_amount' => new Zend_Db_Expr( + sprintf('SUM(%s * %s)', + $adapter->getIfNullSql('o.base_total_refunded', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_tax_amount' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_tax_amount', 0), + $adapter->getIfNullSql('o.base_tax_canceled', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_tax_amount_actual' => new Zend_Db_Expr( + sprintf('SUM((%s -%s) * %s)', + $adapter->getIfNullSql('o.base_tax_invoiced', 0), + $adapter->getIfNullSql('o.base_tax_refunded', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_shipping_amount' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_shipping_amount', 0), + $adapter->getIfNullSql('o.base_shipping_canceled', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_shipping_amount_actual' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_shipping_invoiced', 0), + $adapter->getIfNullSql('o.base_shipping_refunded', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_discount_amount' => new Zend_Db_Expr( + sprintf('SUM((ABS(%s) - %s) * %s)', + $adapter->getIfNullSql('o.base_discount_amount', 0), + $adapter->getIfNullSql('o.base_discount_canceled', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ), + 'total_discount_amount_actual' => new Zend_Db_Expr( + sprintf('SUM((%s - %s) * %s)', + $adapter->getIfNullSql('o.base_discount_invoiced', 0), + $adapter->getIfNullSql('o.base_discount_refunded', 0), + $adapter->getIfNullSql('o.base_to_global_rate', 0) + ) + ) + ); + + $select = $adapter->select(); + $selectOrderItem = $adapter->select(); + + $qtyCanceledExpr = $adapter->getIfNullSql('qty_canceled', 0); + $cols = array( + 'order_id' => 'order_id', + 'total_qty_ordered' => new Zend_Db_expr("SUM(qty_ordered - {$qtyCanceledExpr})"), + 'total_qty_invoiced' => new Zend_Db_expr('SUM(qty_invoiced)'), + ); + $selectOrderItem->from($this->getTable('sales/order_item'), $cols) + ->where('parent_item_id IS NULL') + ->group('order_id'); + + $select->from(array('o' => $this->getTable('sales/order')), $columns) + ->join(array('oi' => $selectOrderItem), 'oi.order_id = o.entity_id', array()) + ->where('o.state NOT IN (?)', array( + Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, + Mage_Sales_Model_Order::STATE_NEW + )); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'o.created_at')); + } + + $select->group(array( + $periodExpr, + 'o.store_id', + 'o.status', + )); + + $adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); + + // setup all columns to select SUM() except period, store_id and order_status + foreach ($columns as $k => $v) { + $columns[$k] = new Zend_Db_expr('SUM(' . $k . ')'); + } + $columns['period'] = 'period'; + $columns['store_id'] = new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID); + $columns['order_status'] = 'order_status'; + + $select->reset(); + $select->from($this->getMainTable(), $columns) + ->where('store_id <> 0'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status' + )); + $adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE); + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Collection.php new file mode 100755 index 0000000000..49a4d65339 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Collection.php @@ -0,0 +1,121 @@ + + */ +class Mage_Sales_Model_Resource_Report_Order_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var string + */ + protected $_periodFormat; + + /** + * Selected columns + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order_aggregated_created'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Get selected columns + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'orders_count' => 'SUM(orders_count)', + 'total_qty_ordered' => 'SUM(total_qty_ordered)', + 'total_qty_invoiced' => 'SUM(total_qty_invoiced)', + 'total_income_amount' => 'SUM(total_income_amount)', + 'total_revenue_amount' => 'SUM(total_revenue_amount)', + 'total_profit_amount' => 'SUM(total_profit_amount)', + 'total_invoiced_amount' => 'SUM(total_invoiced_amount)', + 'total_canceled_amount' => 'SUM(total_canceled_amount)', + 'total_paid_amount' => 'SUM(total_paid_amount)', + 'total_refunded_amount' => 'SUM(total_refunded_amount)', + 'total_tax_amount' => 'SUM(total_tax_amount)', + 'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)', + 'total_shipping_amount' => 'SUM(total_shipping_amount)', + 'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)', + 'total_discount_amount' => 'SUM(total_discount_amount)', + 'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)', + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Order_Collection + */ + protected function _initSelect() + { + $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns()); + if (!$this->isTotals()) { + $this->getSelect()->group($this->_periodFormat); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Updatedat/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Updatedat/Collection.php new file mode 100755 index 0000000000..026159436a --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Updatedat/Collection.php @@ -0,0 +1,283 @@ + + */ +class Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection + extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var string + */ + protected $_periodFormat; + + /** + * Is inited + * + * @var bool + */ + protected $_inited = false; + + /** + * Selected columns + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order', 'entity_id'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Apply stores filter + * + * @return Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection + */ + protected function _applyStoresFilter() + { + $nullCheck = false; + $storeIds = $this->_storesIds; + + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + + $storeIds = array_unique($storeIds); + + if ($index = array_search(null, $storeIds)) { + unset($storeIds[$index]); + $nullCheck = true; + } + + if ($nullCheck) { + $this->getSelect()->where('store_id IN(?) OR store_id IS NULL', $storeIds); + } elseif ($storeIds[0] != '') { + $this->getSelect()->where('store_id IN(?)', $storeIds); + } + + return $this; + } + + /** + * Apply order status filter + * + * @return Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection + */ + protected function _applyOrderStatusFilter() + { + if (is_null($this->_orderStatus)) { + return $this; + } + $orderStatus = $this->_orderStatus; + if (!is_array($orderStatus)) { + $orderStatus = array($orderStatus); + } + $this->getSelect()->where('status IN(?)', $orderStatus); + return $this; + } + + /** + * Retrieve array of columns to select + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + $ifnullBaseTotalCanceled = $adapter->getIfNullSql('e.base_total_canceled', 0); + $totalIncomeAmount = "SUM((e.base_grand_total - {$ifnullBaseTotalCanceled}) * e.base_to_global_rate)"; + + $ifnullBaseTotalRefunded = $adapter->getIfNullSql('e.base_total_refunded', 0); + $totalRevenueAmount = "SUM((e.base_total_paid - {$ifnullBaseTotalRefunded}) * e.base_to_global_rate)"; + + $ifnullTotalRefunded = $adapter->getIfNullSql('e.base_total_refunded', 0); + $ifnullBaseTaxInvoiced = $adapter->getIfNullSql('e.base_tax_invoiced', 0); + $ifnullBaseShippingInvoiced = $adapter->getIfNullSql('e.base_shipping_invoiced', 0); + $ifnullBaseTotalInvoicedCost = $adapter->getIfNullSql('e.base_total_invoiced_cost', 0); + $totalProfitAmountSum = new Zend_Db_Expr( + "SUM((e.base_total_paid - " + . $ifnullTotalRefunded . " - " + . $ifnullBaseTaxInvoiced . " - " + . $ifnullBaseShippingInvoiced ." - " + . $ifnullBaseTotalInvoicedCost + . ") * e.base_to_global_rate)" + ); + + $ifnullBaseTaxCanceled = $adapter->getIfNullSql('e.base_tax_canceled', 0); + $sumTotalTaxAmount = new Zend_Db_Expr( + "SUM((e.base_tax_amount - {$ifnullBaseTaxCanceled}) * e.base_to_global_rate)" + ); + + $ifnullBaseTaxRefunded = $adapter->getIfNullSql('e.base_tax_refunded', 0); + $sumTotalTaxAmountActual = new Zend_Db_Expr( + "SUM((e.base_tax_invoiced - {$ifnullBaseTaxRefunded}) * e.base_to_global_rate)" + ); + + $ifnullBaseShippingCanceled = $adapter->getIfNullSql('e.base_shipping_canceled', 0); + $sumTotalShippingAmount = new Zend_Db_Expr( + "SUM((e.base_shipping_amount - {$ifnullBaseShippingCanceled}) * e.base_to_global_rate)" + ); + + $ifnullBaseShippingRefunded = $adapter->getIfNullSql('e.base_shipping_refunded', 0); + $sumTotalShippingAmountActual = new Zend_Db_Expr( + "SUM((e.base_shipping_invoiced - {$ifnullBaseShippingRefunded}) * e.base_to_global_rate)" + ); + + $ifnullBaseDiscountCanceled = $adapter->getIfNullSql('e.base_discount_canceled', 0); + $sumTotalDiscountAmount = new Zend_Db_Expr( + "SUM((ABS(e.base_discount_amount) - {$ifnullBaseDiscountCanceled}) * e.base_to_global_rate)" + ); + + $ifnullBaseDiscountRefunded = $adapter->getIfNullSql('e.base_discount_refunded', 0); + $sumTotalDiscountAmountActual = new Zend_Db_Expr( + "SUM((e.base_discount_invoiced - {$ifnullBaseDiscountRefunded}) * e.base_to_global_rate)" + ); + + $this->_selectedColumns = array( + 'orders_count' => 'COUNT(e.entity_id)', + 'total_qty_ordered' => $adapter->getIfNullSql('SUM(oi.total_qty_ordered)', 0), + 'total_qty_invoiced' => $adapter->getIfNullSql('SUM(oi.total_qty_invoiced)', 0), + 'total_income_amount' => $adapter->getIfNullSql($totalIncomeAmount, 0), + 'total_revenue_amount' => $adapter->getIfNullSql($totalRevenueAmount, 0), + 'total_profit_amount' => $adapter->getIfNullSql($totalProfitAmountSum, 0), + 'total_invoiced_amount' => $adapter->getIfNullSql( + 'SUM(e.base_total_invoiced * e.base_to_global_rate)', 0), + 'total_canceled_amount' => $adapter->getIfNullSql( + 'SUM(e.base_total_canceled * e.base_to_global_rate)', 0), + 'total_paid_amount' => $adapter->getIfNullSql( + 'SUM(e.base_total_paid * e.base_to_global_rate)', 0), + 'total_refunded_amount' => $adapter->getIfNullSql( + 'SUM(e.base_total_refunded * e.base_to_global_rate)', 0), + 'total_tax_amount' => $adapter->getIfNullSql($sumTotalTaxAmount, 0), + 'total_tax_amount_actual' => $adapter->getIfNullSql($sumTotalTaxAmountActual, 0), + 'total_shipping_amount' => $adapter->getIfNullSql($sumTotalShippingAmount, 0), + 'total_shipping_amount_actual' => $adapter->getIfNullSql($sumTotalShippingAmountActual, 0), + 'total_discount_amount' => $adapter->getIfNullSql($sumTotalDiscountAmount, 0), + 'total_discount_amount_actual' => $adapter->getIfNullSql($sumTotalDiscountAmountActual, 0), + ); + + if (!$this->isTotals()) { + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('e.updated_at', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('e.updated_at', + Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('e.updated_at', '%Y-%m-%d'); + } + $this->_selectedColumns['period'] = $this->_periodFormat; + } + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection + */ + protected function _initSelect() + { + if ($this->_inited) { + return $this; + } + + $columns = $this->_getSelectedColumns(); + $adapter = $this->getConnection(); + $mainTable = $this->getResource()->getMainTable(); + $ifnullQtyCanceled = $adapter->getIfNullSql('qty_canceled', 0); + $selectOrderItem = $adapter->select() + ->from($this->getTable('sales/order_item'), array( + 'order_id' => 'order_id', + 'total_qty_ordered' => "SUM(qty_ordered - {$ifnullQtyCanceled})", + 'total_qty_invoiced' => 'SUM(qty_invoiced)', + )) + ->where('parent_item_id IS NULL') + ->group('order_id'); + + $select = $this->getSelect() + ->from(array('e' => $mainTable), $columns) + ->join(array('oi' => $selectOrderItem), 'oi.order_id = e.entity_id', array()) + ->where('e.state NOT IN (?)', array( + Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, + Mage_Sales_Model_Order::STATE_NEW + )); + + $this->_applyStoresFilter(); + $this->_applyOrderStatusFilter(); + + $dateUpdatedAt = $adapter->getDatePartSql('e.updated_at'); + if ($this->_to !== null) { + $dateTo = $adapter->formatDate($this->_to, false); + $select->where("{$dateUpdatedAt} <= {$dateTo}"); + } + + if ($this->_from !== null) { + $dateFrom = $adapter->formatDate($this->_from, false); + $select->where("{$dateUpdatedAt} >= {$dateFrom}"); + } + + if (!$this->isTotals()) { + $select->group($this->_periodFormat); + } + + $this->_inited = true; + return $this; + } + + /** + * Load + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + $this->_initSelect(); + $this->setApplyFilters(false); + return parent::load($printQuery, $logQuery); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Refunded.php b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded.php new file mode 100755 index 0000000000..9d95cd7a87 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded.php @@ -0,0 +1,272 @@ + + */ +class Mage_Sales_Model_Resource_Report_Refunded extends Mage_Sales_Model_Resource_Report_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_setResource('sales'); + } + + /** + * Aggregate Refunded data + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Refunded + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $this->_aggregateByOrderCreatedAt($from, $to); + $this->_aggregateByRefundCreatedAt($from, $to); + + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_REFUNDED_FLAG_CODE); + return $this; + } + + /** + * Aggregate refunded data by order created at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Refunded + */ + protected function _aggregateByOrderCreatedAt($from, $to) + { + $table = $this->getTable('sales/refunded_aggregated_order'); + $sourceTable = $this->getTable('sales/order'); + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'store_id', + 'order_status' => 'status', + 'orders_count' => new Zend_Db_Expr('COUNT(total_refunded)'), + 'refunded' => new Zend_Db_Expr('SUM(base_total_refunded * base_to_global_rate)'), + 'online_refunded' => new Zend_Db_Expr('SUM(base_total_online_refunded * base_to_global_rate)'), + 'offline_refunded' => new Zend_Db_Expr('SUM(base_total_offline_refunded * base_to_global_rate)') + ); + + $select = $adapter->select(); + $select->from($sourceTable, $columns) + ->where('state != ?', Mage_Sales_Model_Order::STATE_CANCELED) + ->where('base_total_refunded > ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); + } + + $select->group(array( + $periodExpr, + 'store_id', + 'status' + )); + + $select->having('orders_count > 0'); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr('0'), + 'order_status' => 'order_status', + 'orders_count' => new Zend_Db_Expr('SUM(orders_count)'), + 'refunded' => new Zend_Db_Expr('SUM(refunded)'), + 'online_refunded' => new Zend_Db_Expr('SUM(online_refunded)'), + 'offline_refunded' => new Zend_Db_Expr('SUM(offline_refunded)') + ); + + $select + ->from($table, $columns) + ->where('store_id != ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status' + )); + + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + $adapter->commit(); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + return $this; + } + + /** + * Aggregate refunded data by creditmemo created at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Refunded + */ + protected function _aggregateByRefundCreatedAt($from, $to) + { + $table = $this->getTable('sales/refunded_aggregated'); + $sourceTable = $this->getTable('sales/creditmemo'); + $orderTable = $this->getTable('sales/order'); + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeRelatedSelect( + $sourceTable, $orderTable, array('order_id'=>'entity_id'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('source_table.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'order_table.store_id', + 'order_status' => 'order_table.status', + 'orders_count' => new Zend_Db_Expr('COUNT(order_table.entity_id)'), + 'refunded' => new Zend_Db_Expr( + 'SUM(order_table.base_total_refunded * order_table.base_to_global_rate)'), + 'online_refunded' => new Zend_Db_Expr( + 'SUM(order_table.base_total_online_refunded * order_table.base_to_global_rate)'), + 'offline_refunded' => new Zend_Db_Expr( + 'SUM(order_table.base_total_offline_refunded * order_table.base_to_global_rate)') + ); + + $select = $adapter->select(); + $select->from(array('source_table' => $sourceTable), $columns) + ->joinInner( + array('order_table' => $orderTable), + 'source_table.order_id = order_table.entity_id AND ' + . $adapter->quoteInto('order_table.state != ?', Mage_Sales_Model_Order::STATE_CANCELED) + . ' AND order_table.base_total_refunded > 0', + array() + ); + + $filterSubSelect = $adapter->select(); + $filterSubSelect + ->from( + array('filter_source_table' => $sourceTable), + new Zend_Db_Expr('MAX(filter_source_table.entity_id)')) + ->where('filter_source_table.order_id = source_table.order_id'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); + } + + $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); + unset($filterSubSelect); + + $select->group(array( + $periodExpr, + 'order_table.store_id', + 'order_table.status' + )); + + $select->having('orders_count > 0'); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr('0'), + 'order_status' => 'order_status', + 'orders_count' => new Zend_Db_Expr('SUM(orders_count)'), + 'refunded' => new Zend_Db_Expr('SUM(refunded)'), + 'online_refunded' => new Zend_Db_Expr('SUM(online_refunded)'), + 'offline_refunded' => new Zend_Db_Expr('SUM(offline_refunded)') + ); + + $select + ->from($table, $columns) + ->where('store_id != ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status' + )); + + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + $adapter->commit(); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Order.php b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Order.php new file mode 100755 index 0000000000..57168b3456 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Order.php @@ -0,0 +1,113 @@ + + */ +class Mage_Sales_Model_Resource_Report_Refunded_Collection_Order + extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var string + */ + protected $_periodFormat; + + /** + * Selected columns + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/refunded_aggregated_order'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Retrieve selected columns + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'orders_count' => 'SUM(orders_count)', + 'refunded' => 'SUM(refunded)', + 'online_refunded' => 'SUM(online_refunded)', + 'offline_refunded' => 'SUM(offline_refunded)' + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Refunded_Collection_Order + */ + protected function _initSelect() + { + $this->getSelect()->from( + $this->getResource()->getMainTable() , + $this->_getSelectedColumns() + ); + if (!$this->isTotals()) { + $this->getSelect()->group($this->_periodFormat); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Refunded.php b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Refunded.php new file mode 100755 index 0000000000..d295af28bf --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Refunded/Collection/Refunded.php @@ -0,0 +1,48 @@ + + */ +class Mage_Sales_Model_Resource_Report_Refunded_Collection_Refunded + extends Mage_Sales_Model_Resource_Report_Refunded_Collection_Order +{ + /** + * Initialize custom resource model + * + */ + public function __construct() + { + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/refunded_aggregated'); + $this->setConnection($this->getResource()->getReadConnection()); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Shipping.php b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping.php new file mode 100755 index 0000000000..69c913d54e --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping.php @@ -0,0 +1,278 @@ + + */ +class Mage_Sales_Model_Resource_Report_Shipping extends Mage_Sales_Model_Resource_Report_Abstract +{ + /** + * Model initialization + * + */ + protected function _construct() + { + $this->_setResource('sales'); + } + + /** + * Aggregate Shipping data + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Shipping + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $this->_aggregateByOrderCreatedAt($from, $to); + $this->_aggregateByShippingCreatedAt($from, $to); + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_SHIPPING_FLAG_CODE); + return $this; + } + + /** + * Aggregate shipping report by order create_at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Shipping + */ + protected function _aggregateByOrderCreatedAt($from, $to) + { + $table = $this->getTable('sales/shipping_aggregated_order'); + $sourceTable = $this->getTable('sales/order'); + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + $ifnullBaseShippingCanceled = $adapter->getIfNullSql('base_shipping_canceled', 0); + $ifnullBaseShippingRefunded = $adapter->getIfNullSql('base_shipping_refunded', 0); + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'store_id', + 'order_status' => 'status', + 'shipping_description' => 'shipping_description', + 'orders_count' => new Zend_Db_Expr('COUNT(entity_id)'), + 'total_shipping' => new Zend_Db_Expr( + "SUM((base_shipping_amount - {$ifnullBaseShippingCanceled}) * base_to_global_rate)"), + 'total_shipping_actual' => new Zend_Db_Expr( + "SUM((base_shipping_invoiced - {$ifnullBaseShippingRefunded}) * base_to_global_rate)"), + ); + + $select = $adapter->select(); + $select->from($sourceTable, $columns) + ->where('state NOT IN (?)', array( + Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, + Mage_Sales_Model_Order::STATE_NEW + )) + ->where('is_virtual = 0'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); + } + + $select->group(array( + $periodExpr, + 'store_id', + 'status', + 'shipping_description' + )); + + $select->having('orders_count > 0'); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'order_status' => 'order_status', + 'shipping_description' => 'shipping_description', + 'orders_count' => new Zend_Db_Expr('SUM(orders_count)'), + 'total_shipping' => new Zend_Db_Expr('SUM(total_shipping)'), + 'total_shipping_actual' => new Zend_Db_Expr('SUM(total_shipping_actual)'), + ); + + $select + ->from($table, $columns) + ->where('store_id != ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status', + 'shipping_description' + )); + + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + $adapter->commit(); + return $this; + } + + /** + * Aggregate shipping report by shipment create_at as period + * + * @param mixed $from + * @param mixed $to + * @return Mage_Sales_Model_Resource_Report_Shipping + */ + protected function _aggregateByShippingCreatedAt($from, $to) + { + $table = $this->getTable('sales/shipping_aggregated'); + $sourceTable = $this->getTable('sales/invoice'); + $orderTable = $this->getTable('sales/order'); + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeRelatedSelect( + $sourceTable, $orderTable, array('order_id'=>'entity_id'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('source_table.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + $ifnullBaseShippingCanceled = $adapter->getIfNullSql('order_table.base_shipping_canceled', 0); + $ifnullBaseShippingRefunded = $adapter->getIfNullSql('order_table.base_shipping_refunded', 0); + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'order_table.store_id', + 'order_status' => 'order_table.status', + 'shipping_description' => 'order_table.shipping_description', + 'orders_count' => new Zend_Db_Expr('COUNT(order_table.entity_id)'), + 'total_shipping' => new Zend_Db_Expr('SUM((order_table.base_shipping_amount - ' + . "{$ifnullBaseShippingCanceled}) * order_table.base_to_global_rate)"), + 'total_shipping_actual' => new Zend_Db_Expr('SUM((order_table.base_shipping_invoiced - ' + . "{$ifnullBaseShippingRefunded}) * order_table.base_to_global_rate)"), + ); + + $select = $adapter->select(); + $select->from(array('source_table' => $sourceTable), $columns) + ->joinInner( + array('order_table' => $orderTable), + $adapter->quoteInto( + 'source_table.order_id = order_table.entity_id AND order_table.state != ?', + Mage_Sales_Model_Order::STATE_CANCELED), + array() + ) + ->useStraightJoin(); + + $filterSubSelect = $adapter->select() + ->from(array('filter_source_table' => $sourceTable), 'MIN(filter_source_table.entity_id)') + ->where('filter_source_table.order_id = source_table.order_id'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'source_table.created_at')); + } + + $select->where('source_table.entity_id = (?)', new Zend_Db_Expr($filterSubSelect)); + unset($filterSubSelect); + + $select->group(array( + $periodExpr, + 'order_table.store_id', + 'order_table.status', + 'order_table.shipping_description' + )); + + $helper = Mage::getResourceHelper('core'); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'order_status' => 'order_status', + 'shipping_description' => 'shipping_description', + 'orders_count' => new Zend_Db_Expr('SUM(orders_count)'), + 'total_shipping' => new Zend_Db_Expr('SUM(total_shipping)'), + 'total_shipping_actual' => new Zend_Db_Expr('SUM(total_shipping_actual)'), + ); + + $select + ->from($table, $columns) + ->where('store_id != ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status', + 'shipping_description' + )); + $insertQuery = $helper->getInsertFromSelectUsingAnalytic($select, $table, array_keys($columns)); + $adapter->query($insertQuery); + } catch (Exception $e) { + $adapter->rollBack(); + throw $e; + } + + $adapter->commit(); + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Order.php b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Order.php new file mode 100755 index 0000000000..80725fc945 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Order.php @@ -0,0 +1,126 @@ + + */ +class Mage_Sales_Model_Resource_Report_Shipping_Collection_Order + extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var string + */ + protected $_periodFormat; + + /** + * Selected columns + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/shipping_aggregated_order'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Get selected columns + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'shipping_description' => 'shipping_description', + 'orders_count' => 'SUM(orders_count)', + 'total_shipping' => 'SUM(total_shipping)', + 'total_shipping_actual' => 'SUM(total_shipping_actual)', + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + if ($this->isSubTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Sales_Model_Resource_Report_Shipping_Collection_Order + */ + protected function _initSelect() + { + $this->getSelect()->from( + $this->getResource()->getMainTable() , + $this->_getSelectedColumns() + ); + + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->getSelect()->group(array( + $this->_periodFormat, + 'shipping_description' + )); + } + if ($this->isSubTotals()) { + $this->getSelect()->group(array( + $this->_periodFormat + )); + } + return $this; + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Shipment.php b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Shipment.php new file mode 100755 index 0000000000..1d7297c711 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Shipping/Collection/Shipment.php @@ -0,0 +1,48 @@ + + */ +class Mage_Sales_Model_Resource_Report_Shipping_Collection_Shipment + extends Mage_Sales_Model_Resource_Report_Shipping_Collection_Order +{ + /** + * Initialize custom resource model + * + */ + public function __construct() + { + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/shipping_aggregated'); + $this->setConnection($this->getResource()->getReadConnection()); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php new file mode 100755 index 0000000000..638954b13c --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php @@ -0,0 +1,216 @@ + + */ +class Mage_Sales_Model_Resource_Sale_Collection extends Varien_Data_Collection_Db +{ + + /** + * Totals data + * + * @var array + */ + protected $_totals = array( + 'lifetime' => 0, 'base_lifetime' => 0, 'base_avgsale' => 0, 'num_orders' => 0); + + + /** + * Customer model + * + * @var Mage_Customer_Model_Customer + */ + protected $_customer; + + /** + * Order state value + * + * @var null|string|array + */ + protected $_state = null; + + /** + * Order state condition + * + * @var string + */ + protected $_orderStateCondition = null; + + /** + * Set sales order entity and establish read connection + * + */ + public function __construct() + { + $conn = Mage::getResourceSingleton('sales/order')->getReadConnection(); + $this->setConnection($conn); + } + + /** + * Set filter by customer + * + * @param Mage_Customer_Model_Customer $customer + * @return Mage_Sales_Model_Resource_Sale_Collection + */ + public function setCustomerFilter(Mage_Customer_Model_Customer $customer) + { + $this->_customer = $customer; + return $this; + } + + /** + * Add filter by stores + * + * @param array $storeIds + * @return Mage_Sales_Model_Resource_Sale_Collection + */ + public function addStoreFilter($storeIds) + { + return $this->addFieldToFilter('store_id', array('in' => $storeIds)); + } + + /** + * Set filter by order state + * + * @param string|array $state + * @param bool_type $exclude + * @return Mage_Sales_Model_Resource_Sale_Collection + */ + public function setOrderStateFilter($state, $exclude = false) + { + $this->_orderStateCondition = ($exclude) ? 'NOT IN' : 'IN'; + $this->_orderStateValue = (!is_array($state)) ? array($state) : $state; + return $this; + } + + + /** + * Before load action + * + * @return Varien_Data_Collection_Db + */ + protected function _beforeLoad() + { + $this->getSelect() + ->from( + array('sales' => Mage::getResourceSingleton('sales/order')->getMainTable()), + array( + 'store_id', + 'lifetime' => new Zend_Db_Expr('SUM(sales.base_grand_total)'), + 'base_lifetime' => new Zend_Db_Expr('SUM(sales.base_grand_total * sales.base_to_global_rate)'), + 'avgsale' => new Zend_Db_Expr('AVG(sales.base_grand_total)'), + 'base_avgsale' => new Zend_Db_Expr('AVG(sales.base_grand_total * sales.base_to_global_rate)'), + 'num_orders' => new Zend_Db_Expr('COUNT(sales.base_grand_total)') + ) + ) + ->group('sales.store_id'); + + if ($this->_customer instanceof Mage_Customer_Model_Customer) { + $this->addFieldToFilter('sales.customer_id', $this->_customer->getId()); + } + + if (!is_null($this->_orderStateValue)) { + $condition = ''; + switch ($this->_orderStateCondition) { + case 'IN' : + $condition = 'in'; + break; + case 'NOT IN' : + $condition = 'nin'; + break; + } + $this->addFieldToFilter('state', array($condition => $this->_orderStateValue)); + } + + Mage::dispatchEvent('sales_sale_collection_query_before', array('collection' => $this)); + return $this; + } + + /** + * Load data + * + * @return Varien_Data_Collection_Db + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + + $this->_beforeLoad(); + + $this->_renderFilters() + ->_renderOrders() + ->_renderLimit(); + + $this->printLogQuery($printQuery, $logQuery); + + $data = $this->getData(); + $this->resetData(); + + $stores = Mage::getResourceModel('core/store_collection') + ->setWithoutDefaultFilter() + ->load() + ->toOptionHash(); + $this->_items = array(); + foreach ($data as $v) { + $storeObject = new Varien_Object($v); + $storeId = $v['store_id']; + $storeName = isset($stores[$storeId]) ? $stores[$storeId] : null; + $storeObject->setStoreName($storeName) + ->setWebsiteId(Mage::app()->getStore($storeId)->getWebsiteId()) + ->setAvgNormalized($v['avgsale'] * $v['num_orders']); + $this->_items[$storeId] = $storeObject; + foreach ($this->_totals as $key => $value) { + $this->_totals[$key] += $storeObject->getData($key); + } + } + + if ($this->_totals['num_orders']) { + $this->_totals['avgsale'] = $this->_totals['base_lifetime'] / $this->_totals['num_orders']; + } + + $this->_setIsLoaded(); + $this->_afterLoad(); + return $this; + } + + /** + * Retrieve totals data converted into Varien_Object + * + * @return Varien_Object + */ + public function getTotals() + { + return new Varien_Object($this->_totals); + } +} diff --git a/app/code/core/Mage/Sales/Model/Resource/Setup.php b/app/code/core/Mage/Sales/Model/Resource/Setup.php new file mode 100755 index 0000000000..6fc5564636 --- /dev/null +++ b/app/code/core/Mage/Sales/Model/Resource/Setup.php @@ -0,0 +1,987 @@ + + */ +class Mage_Sales_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup +{ + /** + * List of entities converted from EAV to flat data structure + * + * @var $_flatEntityTables array + */ + protected $_flatEntityTables = array( + 'quote' => 'sales/quote', + 'quote_item' => 'sales/quote_item', + 'quote_address' => 'sales/quote_address', + 'quote_address_item'=> 'sales/quote_address_item', + 'quote_address_rate'=> 'sales/quote_shipping_rate', + 'quote_payment' => 'sales/quote_payment', + 'order' => 'sales/order', + 'order_payment' => 'sales/order_payment', + 'order_item' => 'sales/order_item', + 'order_address' => 'sales/order_address', + 'order_status_history' => 'sales/order_status_history', + 'invoice' => 'sales/invoice', + 'invoice_item' => 'sales/invoice_item', + 'invoice_comment' => 'sales/invoice_comment', + 'creditmemo' => 'sales/creditmemo', + 'creditmemo_item' => 'sales/creditmemo_item', + 'creditmemo_comment'=> 'sales/creditmemo_comment', + 'shipment' => 'sales/shipment', + 'shipment_item' => 'sales/shipment_item', + 'shipment_track' => 'sales/shipment_track', + 'shipment_comment' => 'sales/shipment_comment', + ); + + /** + * List of entities used with separate grid table + * + * @var $_flatEntitiesGrid array + */ + protected $_flatEntitiesGrid = array( + 'order', + 'invoice', + 'shipment', + 'creditmemo' + ); + + /** + * Check if table exist for flat entity + * + * @param string $table + * @return bool + */ + protected function _flatTableExist($table) + { + $tablesList = $this->getConnection()->listTables(); + return in_array(strtoupper($this->getTable($table)), array_map('strtoupper', $tablesList)); + } + + /** + * Add entity attribute. Overwrited for flat entities support + * + * @param int|string $entityTypeId + * @param string $code + * @param array $attr + * @return Mage_Sales_Model_Resource_Setup + */ + public function addAttribute($entityTypeId, $code, array $attr) + { + if (isset($this->_flatEntityTables[$entityTypeId]) && + $this->_flatTableExist($this->_flatEntityTables[$entityTypeId])) + { + $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr); + $this->_addGridAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr, $entityTypeId); + } else { + parent::addAttribute($entityTypeId, $code, $attr); + } + return $this; + } + + /** + * Add attribute as separate column in the table + * + * @param string $table + * @param string $attribute + * @param array $attr + * @return Mage_Sales_Model_Resource_Setup + */ + protected function _addFlatAttribute($table, $attribute, $attr) + { + $tableInfo = $this->getConnection()->describeTable($this->getTable($table)); + if (isset($tableInfo[$attribute])) { + return $this; + } + $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); + $this->getConnection()->addColumn($this->getTable($table), $attribute, $columnDefinition); + return $this; + } + + /** + * Add attribute to grid table if necessary + * + * @param string $table + * @param string $attribute + * @param array $attr + * @param string $entityTypeId + * @return Mage_Sales_Model_Resource_Setup + */ + protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId) + { + if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) { + $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); + $this->getConnection()->addColumn($this->getTable($table . '_grid'), $attribute, $columnDefinition); + } + return $this; + } + + /** + * Retrieve definition of column for create in flat table + * + * @param string $code + * @param array $data + * @return array + */ + protected function _getAttributeColumnDefinition($code, $data) + { + // Convert attribute type to column info + $data['type'] = isset($data['type']) ? $data['type'] : Varien_Db_Ddl_Table::TYPE_TEXT; + $type = null; + $length = null; + switch ($data['type']) { + case 'datetime': + $type = Varien_Db_Ddl_Table::TYPE_TIMESTAMP; + break; + case 'decimal': + $type = Varien_Db_Ddl_Table::TYPE_DECIMAL; + $length = '12,4'; + break; + case 'int': + $type = Varien_Db_Ddl_Table::TYPE_INTEGER; + break; + case 'text': + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + $length = 65536; + break; + case 'varchar': + $type = Varien_Db_Ddl_Table::TYPE_TEXT; + $length = 255; + break; + } + if ($type !== null) { + $data['type'] = $type; + $data['length'] = $length; + } + + $data['nullable'] = isset($data['required']) ? !$data['required'] : true; + $data['comment'] = isset($data['comment']) ? $data['comment'] : ucwords(str_replace('_', ' ', $code)); + return $data; + } + + /** + * Retrieve default entities + * + * @return array + */ + public function getDefaultEntities() + { + return array( + 'quote'=>array( + 'entity_model' => 'sales/quote', + 'table' => 'sales/quote', + 'attributes' => array( + 'entity_id' => array('type'=>'static'), + 'is_active' => array('type'=>'static'), + 'store_id' => array('type'=>'static'), + 'remote_ip' => array('type'=>'static'), + 'checkout_method' => array('type'=>'static'), + 'password_hash' => array('type'=>'static'), + 'orig_order_id' => array('type'=>'static'), + 'converted_at' => array('type'=>'static'), + 'reserved_order_id' => array('type'=>'static'), + + 'coupon_code' => array('type'=>'static'), + 'global_currency_code' => array('type'=>'static'), + 'base_currency_code' => array('type'=>'static'), + 'store_currency_code' => array('type'=>'static'), + 'quote_currency_code' => array('type'=>'static'), + 'store_to_base_rate' => array('type'=>'static'), + 'store_to_quote_rate' => array('type'=>'static'), + 'base_to_global_rate' => array('type'=>'static'), + 'base_to_quote_rate' => array('type'=>'static'), + + 'items_count' => array('type'=>'static'), + 'items_qty' => array('type'=>'static'), + + 'grand_total' => array('type'=>'static'), + 'base_grand_total' => array('type'=>'static'), + + 'applied_rule_ids' => array('type'=>'static'), + + 'is_virtual' => array('type'=>'static'), + 'is_multi_shipping' => array('type'=>'static'), + + 'customer_id' => array('type'=>'static'), + 'customer_tax_class_id' => array('type'=>'static'), + 'customer_group_id' => array('type'=>'static'), + 'customer_email' => array('type'=>'static'), + 'customer_prefix' => array('type'=>'static'), + 'customer_firstname' => array('type'=>'static'), + 'customer_middlename' => array('type'=>'static'), + 'customer_lastname' => array('type'=>'static'), + 'customer_suffix' => array('type'=>'static'), + 'customer_note' => array('type'=>'static'), + 'customer_note_notify' => array('type'=>'static'), + 'customer_is_guest' => array('type'=>'static'), + 'customer_taxvat' => array('type'=>'static'), + 'customer_dob' => array('type'=>'static'), + 'customer_gender' => array('type'=>'static'), + ), + ), + + 'quote_item' => array( + 'entity_model' => 'sales/quote_item', + 'table' => 'sales/quote_item', + 'attributes' => array( + 'product_id' => array('type'=>'static'), + 'super_product_id' => array('type'=>'static'), + 'parent_product_id' => array('type'=>'static'), + 'sku' => array('type'=>'static'), + 'name' => array('type'=>'static'), + 'description' => array('type'=>'static'), + + 'weight' => array('type'=>'static'), + 'free_shipping' => array('type'=>'static'), + 'qty' => array('type'=>'static'), + 'is_qty_decimal' => array('type'=>'static'), + + 'price' => array('type'=>'static'), + 'custom_price' => array('type'=>'static'), + 'discount_percent' => array('type'=>'static'), + 'discount_amount' => array('type'=>'static'), + 'no_discount' => array('type'=>'static'), + 'tax_percent' => array('type'=>'static'), + 'tax_amount' => array('type'=>'static'), + 'row_total' => array('type'=>'static'), + 'row_total_with_discount' => array('type'=>'static'), + + 'base_price' => array('type'=>'static'), + 'base_discount_amount' => array('type'=>'static'), + 'base_tax_amount' => array('type'=>'static'), + 'base_row_total' => array('type'=>'static'), + + 'row_weight' => array('type'=>'static'), + 'applied_rule_ids' => array('type'=>'static'), + 'additional_data' => array('type'=>'static'), + ), + ), + + 'quote_address' => array( + 'entity_model' => 'sales/quote_address', + 'table' => 'sales/quote_address', + 'attributes' => array( + 'address_type' => array('type'=>'static'), + + 'customer_id' => array('type'=>'static'), + 'customer_address_id' => array('type'=>'static'), + 'save_in_address_book' => array('type'=>'static'), + 'email' => array('type'=>'static'), + 'prefix' => array('type'=>'static'), + 'firstname' => array('type'=>'static'), + 'middlename' => array('type'=>'static'), + 'lastname' => array('type'=>'static'), + 'suffix' => array('type'=>'static'), + 'company' => array('type'=>'static'), + 'street' => array('type'=>'static'), + 'city' => array('type'=>'static'), + 'region' => array('type'=>'static'), + 'region_id' => array('type'=>'static'), + 'postcode' => array('type'=>'static'), + 'country_id' => array('type'=>'static'), + 'telephone' => array('type'=>'static'), + 'fax' => array('type'=>'static'), + + 'same_as_billing' => array('type'=>'static'), + 'free_shipping' => array('type'=>'static'), + 'weight' => array('type'=>'static'), + 'collect_shipping_rates' => array('type'=>'static'), + + 'shipping_method' => array('type'=>'static'), + 'shipping_description' => array('type'=>'static'), + + 'subtotal' => array('type'=>'static'), + 'subtotal_with_discount' => array('type'=>'static'), + 'tax_amount' => array('type'=>'static'), + 'shipping_amount' => array('type'=>'static'), + 'shipping_tax_amount' => array('type'=>'static'), + 'discount_amount' => array('type'=>'static'), + 'grand_total' => array('type'=>'static'), + + 'base_subtotal' => array('type'=>'static'), + 'base_subtotal_with_discount' => array('type'=>'static'), + 'base_tax_amount' => array('type'=>'static'), + 'base_shipping_amount' => array('type'=>'static'), + 'base_shipping_tax_amount' => array('type'=>'static'), + 'base_discount_amount' => array('type'=>'static'), + 'base_grand_total' => array('type'=>'static'), + + 'customer_notes' => array('type'=>'static'), + 'applied_taxes' => array('type'=>'text'), + ), + ), + 'quote_address_item' => array( + 'entity_model' => 'sales/quote_address_item', + 'table' =>'sales/quote_entity', + 'attributes' => array( + 'quote_item_id' => array('type'=>'int'), + 'product_id' => array('type'=>'int'), + 'super_product_id' => array('type'=>'int'), + 'parent_product_id' => array('type'=>'int'), + 'sku' => array(), + 'image' => array(), + 'name' => array(), + 'description' => array('type'=>'text'), + + 'weight' => array('type'=>'decimal'), + 'free_shipping' => array('type'=>'int'), + 'qty' => array('type'=>'decimal'), + 'is_qty_decimal' => array('type'=>'int'), + + 'price' => array('type'=>'decimal'), + 'discount_percent' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'no_discount' => array('type'=>'int'), + 'tax_percent' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'row_total' => array('type'=>'decimal'), + 'row_total_with_discount' => array('type'=>'decimal'), + + 'base_price' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_row_total' => array('type'=>'decimal'), + + 'row_weight' => array('type'=>'decimal'), + 'applied_rule_ids' => array(), + 'additional_data' => array('type'=>'text'), + ), + ), + 'quote_address_rate' => array( + 'entity_model' => 'sales/quote_address_rate', + 'table' => 'sales/quote_entity', + 'attributes' => array( + 'code' => array(), + 'carrier' => array(), + 'carrier_title' => array(), + 'method' => array(), + 'method_description' => array('type'=>'text'), + 'price' => array('type'=>'decimal'), + 'error_message' => array('type'=>'text'), + ), + ), + 'quote_payment' => array( + 'entity_model' => 'sales/quote_payment', + 'table' =>'sales/quote_entity', + 'attributes' => array( + 'method' => array(), + 'additional_data' => array('type'=>'text'), + 'po_number' => array(), + 'cc_type' => array(), + 'cc_number_enc' => array(), + 'cc_last4' => array(), + 'cc_owner' => array(), + 'cc_exp_month' => array('type'=>'int'), + 'cc_exp_year' => array('type'=>'int'), + 'cc_cid_enc' => array(), + 'cc_ss_issue' => array(), + 'cc_ss_start_month' => array('type'=>'int'), + 'cc_ss_start_year' => array('type'=>'int'), + ), + ), + + 'order' => array( + 'entity_model' => 'sales/order', + 'table' => 'sales/order', + 'increment_model' => 'eav/entity_increment_numeric', + 'increment_per_store' =>true, + 'backend_prefix' =>'sales_entity/order_attribute_backend', + 'attributes' => array( + 'entity_id' => array( + 'type' =>'static', + 'backend' =>'sales_entity/order_attribute_backend_parent' + ), + 'store_id' => array('type'=>'static'), + 'store_name' => array('type'=>'varchar'), + 'remote_ip' => array(), + + 'status' => array('type'=>'varchar'), + 'state' => array('type'=>'varchar'), + 'hold_before_status' => array('type'=>'varchar'), + 'hold_before_state' => array('type'=>'varchar'), + + 'relation_parent_id' => array('type'=>'varchar'), + 'relation_parent_real_id' => array('type'=>'varchar'), + 'relation_child_id' => array('type'=>'varchar'), + 'relation_child_real_id' => array('type'=>'varchar'), + 'original_increment_id' => array('type'=>'varchar'), + 'edit_increment' => array('type'=>'int'), + + 'ext_order_id' => array('type'=>'varchar'), + 'ext_customer_id' => array('type'=>'varchar'), + + 'quote_id' => array('type'=>'int'), + 'quote_address_id' => array('type'=>'int'), + 'billing_address_id' => array('type'=>'int', 'backend'=>'_billing'), + 'shipping_address_id' => array('type'=>'int', 'backend'=>'_shipping'), + + 'coupon_code' => array(), + 'applied_rule_ids' => array(), + + 'global_currency_code' => array(), + 'base_currency_code' => array(), + 'store_currency_code' => array(), + 'order_currency_code' => array(), + 'store_to_base_rate' => array('type'=>'decimal'), + 'store_to_order_rate' => array('type'=>'decimal'), + 'base_to_global_rate' => array('type'=>'decimal'), + 'base_to_order_rate' => array('type'=>'decimal'), + + 'is_virtual' => array('type'=>'int'), + + 'shipping_method' => array(), + 'shipping_description' => array(), + 'weight' => array('type'=>'decimal'), + + 'tax_amount' => array('type'=>'static'), + 'shipping_amount' => array('type'=>'static'), + 'shipping_tax_amount' => array('type'=>'static'), + 'discount_amount' => array('type'=>'static'), + + 'subtotal' => array('type'=>'static'), + 'grand_total' => array('type'=>'static'), + 'total_paid' => array('type'=>'static'), + 'total_due' => array('type'=>'decimal'), + 'total_refunded' => array('type'=>'static'), + 'total_qty_ordered' => array('type'=>'static'), + 'total_canceled' => array('type'=>'static'), + 'total_invoiced' => array('type'=>'static'), + 'total_online_refunded' => array('type'=>'static'), + 'total_offline_refunded' => array('type'=>'static'), + 'adjustment_positive' => array('type'=>'decimal'), + 'adjustment_negative' => array('type'=>'decimal'), + + 'base_tax_amount' => array('type'=>'static'), + 'base_shipping_amount' => array('type'=>'static'), + 'base_shipping_tax_amount' => array('type'=>'static'), + 'base_discount_amount' => array('type'=>'static'), + + 'base_subtotal' => array('type'=>'static'), + 'base_grand_total' => array('type'=>'static'), + 'base_total_paid' => array('type'=>'static'), + 'base_total_due' => array('type'=>'decimal'), + 'base_total_refunded' => array('type'=>'static'), + 'base_total_qty_ordered' => array('type'=>'static'), + 'base_total_canceled' => array('type'=>'static'), + 'base_total_invoiced' => array('type'=>'static'), + 'base_total_online_refunded' => array('type'=>'static'), + 'base_total_offline_refunded'=> array('type'=>'static'), + 'base_adjustment_positive' => array('type'=>'decimal'), + 'base_adjustment_negative' => array('type'=>'decimal'), + + 'subtotal_refunded' => array('type'=>'static'), + 'subtotal_canceled' => array('type'=>'static'), + 'discount_refunded' => array('type'=>'static'), + 'discount_canceled' => array('type'=>'static'), + 'discount_invoiced' => array('type'=>'static'), + 'subtotal_invoiced' => array('type'=>'static'), + 'tax_refunded' => array('type'=>'static'), + 'tax_canceled' => array('type'=>'static'), + 'tax_invoiced' => array('type'=>'static'), + 'shipping_refunded' => array('type'=>'static'), + 'shipping_canceled' => array('type'=>'static'), + 'shipping_invoiced' => array('type'=>'static'), + 'base_subtotal_refunded' => array('type'=>'static'), + 'base_subtotal_canceled' => array('type'=>'static'), + 'base_discount_refunded' => array('type'=>'static'), + 'base_discount_canceled' => array('type'=>'static'), + 'base_discount_invoiced' => array('type'=>'static'), + 'base_subtotal_invoiced' => array('type'=>'static'), + 'base_tax_refunded' => array('type'=>'static'), + 'base_tax_canceled' => array('type'=>'static'), + 'base_tax_invoiced' => array('type'=>'static'), + 'base_shipping_refunded' => array('type'=>'static'), + 'base_shipping_canceled' => array('type'=>'static'), + 'base_shipping_invoiced' => array('type'=>'static'), + + 'protect_code' => array('type' => 'static'), + + 'customer_id' => array('type'=>'static', 'visible'=>false), + 'customer_group_id' => array('type'=>'int', 'visible'=>false), + 'customer_email' => array('type'=>'varchar', 'visible'=>false), + 'customer_prefix' => array('type'=>'varchar', 'visible'=>false), + 'customer_firstname' => array('type'=>'varchar', 'visible'=>false), + 'customer_middlename' => array('type'=>'varchar', 'visible'=>false), + 'customer_lastname' => array('type'=>'varchar', 'visible'=>false), + 'customer_suffix' => array('type'=>'varchar', 'visible'=>false), + 'customer_note' => array('type'=>'text', 'visible'=>false), + 'customer_note_notify' => array('type'=>'int', 'visible'=>false), + 'customer_is_guest' => array('type'=>'int', 'visible'=>false), + 'email_sent' => array('type'=>'int', 'visible'=>false), + 'customer_taxvat' => array('type'=>'varchar', 'visible'=>false), + 'customer_dob' => array('type'=>'datetime', + 'backend' => 'eav/entity_attribute_backend_datetime'), + 'customer_gender' => array('type'=>'int', 'visible'=>false), + ), + ), + 'order_address' => array( + 'entity_model' => 'sales/order_address', + 'table' =>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array('type'=>'static', 'backend'=>'sales_entity/order_attribute_backend_child'), + 'quote_address_id' => array('type'=>'int'), + 'address_type' => array(), + 'customer_id' => array('type'=>'int'), + 'customer_address_id' => array('type'=>'int'), + 'email' => array(), + 'prefix' => array(), + 'firstname' => array(), + 'middlename' => array(), + 'lastname' => array(), + 'suffix' => array(), + 'company' => array(), + 'street' => array(), + 'city' => array(), + 'region' => array(), + 'region_id' => array('type'=>'int'), + 'postcode' => array(), + 'country_id' => array('type'=>'varchar'), + 'telephone' => array(), + 'fax' => array(), + + ), + ), + 'order_item' => array( + 'entity_model' => 'sales/order_item', + 'table' =>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type' =>'static', + 'backend' =>'sales_entity/order_attribute_backend_child' + ), + + 'quote_item_id' => array('type'=>'int'), + 'product_id' => array('type'=>'int'), + 'super_product_id' => array('type'=>'int'), + 'parent_product_id' => array('type'=>'int'), + 'is_virtual' => array('type'=>'int'), + 'sku' => array(), + 'name' => array(), + 'description' => array('type'=>'text'), + 'weight' => array('type'=>'decimal'), + + 'is_qty_decimal' => array('type'=>'int'), + 'qty_ordered' => array('type'=>'decimal'), + 'qty_backordered' => array('type'=>'decimal'), + 'qty_invoiced' => array('type'=>'decimal'), + 'qty_canceled' => array('type'=>'decimal'), + 'qty_shipped' => array('type'=>'decimal'), + 'qty_refunded' => array('type'=>'decimal'), + + 'original_price' => array('type'=>'decimal'), + 'price' => array('type'=>'decimal'), + 'cost' => array('type'=>'decimal'), + + 'discount_percent' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'discount_invoiced' => array('type'=>'decimal'), + + 'tax_percent' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'tax_invoiced' => array('type'=>'decimal'), + + 'row_total' => array('type'=>'decimal'), + 'row_weight' => array('type'=>'decimal'), + 'row_invoiced' => array('type'=>'decimal'), + 'invoiced_total' => array('type'=>'decimal'), + 'amount_refunded' => array('type'=>'decimal'), + + 'base_price' => array('type'=>'decimal'), + 'base_original_price' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_discount_invoiced' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_tax_invoiced' => array('type'=>'decimal'), + 'base_row_total' => array('type'=>'decimal'), + 'base_row_invoiced' => array('type'=>'decimal'), + 'base_invoiced_total' => array('type'=>'decimal'), + 'base_amount_refunded' => array('type'=>'decimal'), + + 'applied_rule_ids' => array(), + 'additional_data' => array('type'=>'text'), + ), + ), + 'order_payment' => array( + 'entity_model' => 'sales/order_payment', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_attribute_backend_child' + ), + 'quote_payment_id' => array('type'=>'int'), + 'method' => array(), + 'additional_data' => array('type'=>'text'), + 'last_trans_id' => array(), + 'po_number' => array(), + + 'cc_type' => array(), + 'cc_number_enc' => array(), + 'cc_last4' => array(), + 'cc_owner' => array(), + 'cc_exp_month' => array(), + 'cc_exp_year' => array(), + + 'cc_ss_issue' => array(), + 'cc_ss_start_month' => array(), + 'cc_ss_start_year' => array(), + + 'cc_status' => array(), + 'cc_status_description' => array(), + 'cc_trans_id' => array(), + 'cc_approval' => array(), + 'cc_avs_status' => array(), + 'cc_cid_status' => array(), + + 'cc_debug_request_body' => array(), + 'cc_debug_response_body'=> array(), + 'cc_debug_response_serialized' => array(), + + 'anet_trans_method' => array(), + 'echeck_routing_number' => array(), + 'echeck_bank_name' => array(), + 'echeck_account_type' => array(), + 'echeck_account_name' => array(), + 'echeck_type' => array(), + + 'amount_ordered' => array('type'=>'decimal'), + 'amount_authorized' => array('type'=>'decimal'), + 'amount_paid' => array('type'=>'decimal'), + 'amount_canceled' => array('type'=>'decimal'), + 'amount_refunded' => array('type'=>'decimal'), + 'shipping_amount' => array('type'=>'decimal'), + 'shipping_captured' => array('type'=>'decimal'), + 'shipping_refunded' => array('type'=>'decimal'), + + 'base_amount_ordered' => array('type'=>'decimal'), + 'base_amount_authorized' => array('type'=>'decimal'), + 'base_amount_paid' => array('type'=>'decimal'), + 'base_amount_paid_online' => array('type'=>'decimal'), + 'base_amount_canceled' => array('type'=>'decimal'), + 'base_amount_refunded' => array('type'=>'decimal'), + 'base_amount_refunded_online' => array('type'=>'decimal'), + 'base_shipping_amount' => array('type'=>'decimal'), + 'base_shipping_captured' => array('type'=>'decimal'), + 'base_shipping_refunded' => array('type'=>'decimal'), + ), + ), + + 'order_status_history' => array( + 'entity_model' => 'sales/order_status_history', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_attribute_backend_child' + ), + 'status' => array('type'=>'varchar'), + 'comment' => array('type'=>'text'), + 'is_customer_notified' => array('type'=>'int'), + ), + ), + + 'invoice' => array( + 'entity_model' => 'sales/order_invoice', + 'table' =>'sales/order_entity', + 'increment_model' =>'eav/entity_increment_numeric', + 'increment_per_store'=>true, + 'backend_prefix' =>'sales_entity/order_attribute_backend', + 'attributes' => array( + 'entity_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_invoice_attribute_backend_parent' + ), + + 'state' => array('type'=>'int'), + 'is_used_for_refund' => array('type'=>'int'), + 'transaction_id' => array(), + + + 'order_id' => array( + 'type'=>'int', + 'backend'=>'sales_entity/order_invoice_attribute_backend_order' + ), + + 'billing_address_id' => array('type'=>'int'), + 'shipping_address_id' => array('type'=>'int'), + + 'global_currency_code' => array(), + 'base_currency_code' => array(), + 'store_currency_code' => array(), + 'order_currency_code' => array(), + 'store_to_base_rate' => array('type'=>'decimal'), + 'store_to_order_rate' => array('type'=>'decimal'), + 'base_to_global_rate' => array('type'=>'decimal'), + 'base_to_order_rate' => array('type'=>'decimal'), + + 'subtotal' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'shipping_amount' => array('type'=>'decimal'), + 'grand_total' => array('type'=>'decimal'), + 'total_qty' => array('type'=>'decimal'), + + 'can_void_flag' => array('type'=>'int'), + + 'base_subtotal' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_shipping_amount' => array('type'=>'decimal'), + 'base_grand_total' => array('type'=>'decimal'), + 'email_sent' => array('type'=>'int'), + 'store_id' => array('type'=>'static'), + ), + ), + + 'invoice_item' => array( + 'entity_model' => 'sales/order_invoice_item', + //'table'=>'sales/invoice', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_invoice_attribute_backend_child' + ), + 'order_item_id' => array('type'=>'int'), + 'product_id' => array('type'=>'int'), + 'name' => array(), + 'description' => array('type'=>'text'), + 'sku' => array(), + 'qty' => array('type'=>'decimal'), + 'cost' => array('type'=>'decimal'), + 'price' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'row_total' => array('type'=>'decimal'), + + 'base_price' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_row_total' => array('type'=>'decimal'), + + 'additional_data' => array('type'=>'text'), + ), + ), + + 'invoice_comment' => array( + 'entity_model' => 'sales/order_invoice_comment', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_invoice_attribute_backend_child' + ), + 'comment' => array('type'=>'text'), + 'is_customer_notified' => array('type'=>'int'), + ), + ), + + + + 'shipment' => array( + 'entity_model' => 'sales/order_shipment', + //'table'=>'sales/shipment', + 'table'=>'sales/order_entity', + 'increment_model'=>'eav/entity_increment_numeric', + 'increment_per_store'=>true, + 'backend_prefix'=>'sales_entity/order_attribute_backend', + 'attributes' => array( + 'entity_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_shipment_attribute_backend_parent' + ), + + 'customer_id' => array('type'=>'int'), + 'order_id' => array('type'=>'int'), + 'shipment_status' => array('type'=>'int'), + 'billing_address_id' => array('type'=>'int'), + 'shipping_address_id' => array('type'=>'int'), + + 'total_qty' => array('type'=>'decimal'), + 'total_weight' => array('type'=>'decimal'), + 'email_sent' => array('type'=>'int'), + 'store_id' => array('type' => 'static'), + ), + ), + + 'shipment_item' => array( + 'entity_model' => 'sales/order_shipment_item', + //'table'=>'sales/shipment', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_shipment_attribute_backend_child' + ), + 'order_item_id' => array('type'=>'int'), + 'product_id' => array('type'=>'int'), + 'name' => array(), + 'description' => array('type'=>'text'), + 'sku' => array(), + 'qty' => array('type'=>'decimal'), + 'price' => array('type'=>'decimal'), + 'weight' => array('type'=>'decimal'), + 'row_total' => array('type'=>'decimal'), + + 'additional_data' => array('type'=>'text'), + ), + ), + + 'shipment_comment' => array( + 'entity_model' => 'sales/order_shipment_comment', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_shipment_attribute_backend_child' + ), + 'comment' => array('type'=>'text'), + 'is_customer_notified' => array('type'=>'int'), + ), + ), + + 'shipment_track' => array( + 'entity_model' => 'sales/order_shipment_track', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_shipment_attribute_backend_child' + ), + 'order_id' => array('type'=>'int'), + 'number' => array('type'=>'text'), + 'carrier_code' => array('type'=>'varchar'), + 'title' => array('type'=>'varchar'), + 'description' => array('type'=>'text'), + 'qty' => array('type'=>'decimal'), + 'weight' => array('type'=>'decimal'), + ), + ), + + 'creditmemo' => array( + 'entity_model' => 'sales/order_creditmemo', + //'table'=>'sales/creditmemo', + 'table'=>'sales/order_entity', + 'increment_model'=>'eav/entity_increment_numeric', + 'increment_per_store'=>true, + 'backend_prefix'=>'sales_entity/order_attribute_backend', + 'attributes' => array( + 'entity_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_creditmemo_attribute_backend_parent' + ), + 'state' => array('type'=>'int'), + 'invoice_id' => array('type'=>'int'), + 'transaction_id'=> array(), + + 'order_id' => array('type'=>'int'), + 'creditmemo_status' => array('type'=>'int'), + 'billing_address_id' => array('type'=>'int'), + 'shipping_address_id' => array('type'=>'int'), + + 'global_currency_code' => array(), + 'base_currency_code' => array(), + 'store_currency_code' => array(), + 'order_currency_code' => array(), + 'store_to_base_rate' => array('type'=>'decimal'), + 'store_to_order_rate' => array('type'=>'decimal'), + 'base_to_global_rate' => array('type'=>'decimal'), + 'base_to_order_rate' => array('type'=>'decimal'), + + 'subtotal' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'shipping_amount' => array('type'=>'decimal'), + 'adjustment' => array('type'=>'decimal'), + 'adjustment_positive' => array('type'=>'decimal'), + 'adjustment_negative' => array('type'=>'decimal'), + 'grand_total' => array('type'=>'decimal'), + + 'base_subtotal' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_shipping_amount' => array('type'=>'decimal'), + 'base_adjustment' => array('type'=>'decimal'), + 'base_adjustment_positive' => array('type'=>'decimal'), + 'base_adjustment_negative' => array('type'=>'decimal'), + 'base_grand_total' => array('type'=>'decimal'), + 'email_sent' => array('type' => 'int'), + 'store_id' => array('type' => 'static'), + ), + ), + + 'creditmemo_item' => array( + 'entity_model' => 'sales/order_creditmemo_item', + //'table'=>'sales/creditmemo', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_creditmemo_attribute_backend_child' + ), + 'order_item_id' => array('type'=>'int'), + 'product_id' => array('type'=>'int'), + 'name' => array(), + 'description' => array('type'=>'text'), + 'sku' => array(), + 'qty' => array('type'=>'decimal'), + 'cost' => array('type'=>'decimal'), + 'price' => array('type'=>'decimal'), + 'discount_amount' => array('type'=>'decimal'), + 'tax_amount' => array('type'=>'decimal'), + 'row_total' => array('type'=>'decimal'), + + 'base_price' => array('type'=>'decimal'), + 'base_discount_amount' => array('type'=>'decimal'), + 'base_tax_amount' => array('type'=>'decimal'), + 'base_row_total' => array('type'=>'decimal'), + + 'additional_data' => array('type'=>'text'), + ), + ), + + 'creditmemo_comment' => array( + 'entity_model' => 'sales/order_creditmemo_comment', + 'table'=>'sales/order_entity', + 'attributes' => array( + 'parent_id' => array( + 'type'=>'static', + 'backend'=>'sales_entity/order_creditmemo_attribute_backend_child' + ), + 'comment' => array('type'=>'text'), + 'is_customer_notified' => array('type'=>'int'), + ), + ), + + ); + } +} diff --git a/app/code/core/Mage/Sales/Model/Service/Order.php b/app/code/core/Mage/Sales/Model/Service/Order.php index f766b5b014..cdc6367fbd 100644 --- a/app/code/core/Mage/Sales/Model/Service/Order.php +++ b/app/code/core/Mage/Sales/Model/Service/Order.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/Model/Service/Quote.php b/app/code/core/Mage/Sales/Model/Service/Quote.php index 5729f4206a..8f4ce59820 100644 --- a/app/code/core/Mage/Sales/Model/Service/Quote.php +++ b/app/code/core/Mage/Sales/Model/Service/Quote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php b/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php index 7e086e72ae..353a1f4bb9 100644 --- a/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php +++ b/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/controllers/DownloadController.php b/app/code/core/Mage/Sales/controllers/DownloadController.php index 19bd184fb9..36b66ef2d3 100644 --- a/app/code/core/Mage/Sales/controllers/DownloadController.php +++ b/app/code/core/Mage/Sales/controllers/DownloadController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/controllers/OrderController.php b/app/code/core/Mage/Sales/controllers/OrderController.php index 84179c2c82..6ba6fd4151 100644 --- a/app/code/core/Mage/Sales/controllers/OrderController.php +++ b/app/code/core/Mage/Sales/controllers/OrderController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php b/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php index beb820de13..84b160b535 100644 --- a/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php +++ b/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/data/sales_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Sales/data/sales_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..30e582420a --- /dev/null +++ b/app/code/core/Mage/Sales/data/sales_setup/data-install-1.6.0.0.php @@ -0,0 +1,68 @@ +getNode('global/sales/order/statuses')->asArray(); +foreach ($statuses as $code => $info) { + $data[] = array( + 'status' => $code, + 'label' => $info['label'] + ); +} +$installer->getConnection()->insertArray( + $installer->getTable('sales/order_status'), + array('status', 'label'), + $data +); + +/** + * Install order states from config + */ +$data = array(); +$states = Mage::getConfig()->getNode('global/sales/order/states')->asArray(); + +foreach ($states as $code => $info) { + if (isset($info['statuses'])) { + foreach ($info['statuses'] as $status => $statusInfo) { + $data[] = array( + 'status' => $status, + 'state' => $code, + 'is_default' => is_array($statusInfo) && isset($statusInfo['@']['default']) ? 1 : 0 + ); + } + } +} +$installer->getConnection()->insertArray( + $installer->getTable('sales/order_status_state'), + array('status', 'state', 'is_default'), + $data +); diff --git a/app/code/core/Mage/Sales/doc/test.php b/app/code/core/Mage/Sales/doc/test.php index f630d757d4..081543f24e 100644 --- a/app/code/core/Mage/Sales/doc/test.php +++ b/app/code/core/Mage/Sales/doc/test.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ include "lib/Varien/Object.php"; diff --git a/app/code/core/Mage/Sales/etc/adminhtml.xml b/app/code/core/Mage/Sales/etc/adminhtml.xml index 18ccf8d906..ddb53242bc 100644 --- a/app/code/core/Mage/Sales/etc/adminhtml.xml +++ b/app/code/core/Mage/Sales/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Sales/etc/api.xml b/app/code/core/Mage/Sales/etc/api.xml index 207db1ff16..7beb6c37fa 100644 --- a/app/code/core/Mage/Sales/etc/api.xml +++ b/app/code/core/Mage/Sales/etc/api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Sales/etc/config.xml b/app/code/core/Mage/Sales/etc/config.xml index d7a000d188..7b508a16db 100644 --- a/app/code/core/Mage/Sales/etc/config.xml +++ b/app/code/core/Mage/Sales/etc/config.xml @@ -21,543 +21,1166 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.25 + 1.6.0.0 - * - * + + * + + + * + - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - * - * - - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - - quote_base_grand_total - - * - * - * - order_currency_code - * - store_to_order_rate - * - base_to_order_rate - - * - * - * - * - - total_qty_ordered + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + quote_base_grand_total + + + * + + + * + + + * + + + order_currency_code + + + * + + + store_to_order_rate + + + * + + + base_to_order_rate + + + * + + + * + + + * + + + * + + + total_qty_ordered + - - * - * - * - * - - * - * - * - * - * - * - * - * - * - - * - * - * - * - * - * - * - * - - * - * - * - * - - ** - ** - ** - ** - ** - ** - street - * - ** - ** - ** - ** - ** - ** - ** - ** + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + + + street + + + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + + + * + * + - - * - * - * - * - * - * - * - * - * - * - - * - * - - * - * - * + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - - * - * - * - * - * - qty_ordered - * - * - * - * - price - base_price - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * + + * + + + * + + + * + + + * + + + * + + + qty_ordered + + + * + + + * + + + * + + + * + + + price + + + base_price + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - - * - * - * - * - * - - * - * - * - - **** - **** - **** - quote_currency_code*** - **** - store_to_quote_rate*** - **** - base_to_quote_rate*** - - ** - ** - - * - * - - * - * - * - * - - * - * - * - * - * - * - * - - * - * - * - * - * - * - - * - * - + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + * + * + * + + + * + * + * + * + + + * + * + * + * + + + quote_currency_code + * + * + * + + + * + * + * + * + + + store_to_quote_rate + * + * + * + + + * + * + * + * + + + base_to_quote_rate + * + * + * + + + * + * + + + * + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - - * - * - * - * - * - * - street - * - * - * - * - * - * - * + + * + + + * + + + * + + + * + + + * + + + * + + + street + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - - * - * - * - * - * - * - * - * - * - * - - * - * - * + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - - **** - **** - **** - ** - custom_price*** - * - * - * - * - * - * - * - * - - * - * - * - - base_price** - *** + + * + * + * + * + + + * + * + * + * + + + * + * + * + * + + + * + * + + + custom_price + * + * + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + * + + + base_price + * + * + + + * + * + * + - - customer_id - customer_email - customer_prefix - customer_firstname - customer_middlename - customer_lastname - customer_suffix - customer_group_id - customer_tax_class_id - customer_taxvat - customer_dob - customer_gender + + customer_id + + + customer_email + + + customer_prefix + + + customer_firstname + + + customer_middlename + + + customer_lastname + + + customer_suffix + + + customer_group_id + + + customer_tax_class_id + + + customer_taxvat + + + customer_dob + + + customer_gender + - - customer_address_id - customer_id - * - * - * - * - * - - * - street - * - * - * - * - * - * - * + + customer_address_id + + + customer_id + + + * + + + * + + + * + + + * + + + * + + + * + + + street + + + * + + + * + + + * + + + * + + + * + + + * + + + * + - Mage_Sales_Model - sales_mysql4 + sales_resource - - Mage_Sales_Model_Mysql4 - - sales_flat_quote
      - sales_flat_quote_item
      - sales_flat_quote_address
      - sales_flat_quote_address_item
      - sales_flat_quote_item_option
      - sales_flat_quote_payment
      - sales_flat_quote_shipping_rate
      - - sales_flat_order
      - sales_flat_order_grid
      - sales_flat_order_item
      - sales_flat_order_address
      - sales_flat_order_payment
      - sales_flat_order_status_history
      - sales_order_status
      - sales_order_status_state
      - sales_order_status_label
      - - sales_flat_invoice
      - sales_flat_invoice_grid
      - sales_flat_invoice_item
      - sales_flat_invoice_comment
      - - sales_flat_shipment
      - sales_flat_shipment_grid
      - sales_flat_shipment_item
      - sales_flat_shipment_comment
      - sales_flat_shipment_track
      - - sales_flat_creditmemo
      - sales_flat_creditmemo_grid
      - sales_flat_creditmemo_item
      - sales_flat_creditmemo_comment
      - - sales_recurring_profile
      - sales_recurring_profile_order
      - - - sales_order_tax
      - - - sales_flat_order_item_option
      - - - - sales_order_entity
      - - - sales_order_aggregated_created
      - sales_order_aggregated_updated
      - - sales_shipping_aggregated
      - sales_shipping_aggregated_order
      - - sales_invoiced_aggregated
      - sales_invoiced_aggregated_order
      - - sales_refunded_aggregated
      - sales_refunded_aggregated_order
      - - sales_payment_transaction
      - - sales_bestsellers_aggregated_daily
      - sales_bestsellers_aggregated_monthly
      - sales_bestsellers_aggregated_yearly
      - - sales_billing_agreement
      - sales_billing_agreement_order
      - - -
      -
      Mage_Sales_Model_Entity - sales_quote
      - sales_quote_address
      - sales_quote_item
      - sales_quote_entity
      - sales_quote_temp
      - sales_order
      - sales_order_entity
      + + sales_quote
      +
      + + sales_quote_address
      +
      + + sales_quote_item
      +
      + + sales_quote_entity
      +
      + + sales_quote_temp
      +
      + + sales_order
      +
      + + sales_order_entity
      +
      + + Mage_Sales_Model_Resource + sales_mysql4 + + + sales_flat_quote
      +
      + + sales_flat_quote_item
      +
      + + sales_flat_quote_address
      +
      + + sales_flat_quote_address_item
      +
      + + sales_flat_quote_item_option
      +
      + + sales_flat_quote_payment
      +
      + + sales_flat_quote_shipping_rate
      +
      + + sales_flat_order
      +
      + + sales_flat_order_grid
      +
      + + sales_flat_order_item
      +
      + + sales_flat_order_address
      +
      + + sales_flat_order_payment
      +
      + + sales_flat_order_status_history
      +
      + + sales_order_status
      +
      + + sales_order_status_state
      +
      + + sales_order_status_label
      +
      + + sales_flat_invoice
      +
      + + sales_flat_invoice_grid
      +
      + + sales_flat_invoice_item
      +
      + + sales_flat_invoice_comment
      +
      + + sales_flat_shipment
      +
      + + sales_flat_shipment_grid
      +
      + + sales_flat_shipment_item
      +
      + + sales_flat_shipment_comment
      +
      + + sales_flat_shipment_track
      +
      + + sales_flat_creditmemo
      +
      + + sales_flat_creditmemo_grid
      +
      + + sales_flat_creditmemo_item
      +
      + + sales_flat_creditmemo_comment
      +
      + + sales_recurring_profile
      +
      + + sales_recurring_profile_order
      +
      + + sales_order_tax
      +
      + + sales_flat_order_item_option
      +
      + + sales_order_entity
      +
      + + sales_order_aggregated_created
      +
      + + sales_order_aggregated_updated
      +
      + + sales_shipping_aggregated
      +
      + + sales_shipping_aggregated_order
      +
      + + sales_invoiced_aggregated
      +
      + + sales_invoiced_aggregated_order
      +
      + + sales_refunded_aggregated
      +
      + + sales_refunded_aggregated_order
      +
      + + sales_payment_transaction
      +
      + + sales_bestsellers_aggregated_daily
      +
      + + sales_bestsellers_aggregated_monthly
      +
      + + sales_bestsellers_aggregated_yearly
      +
      + + sales_billing_agreement
      +
      + + sales_billing_agreement_order
      +
      +
      +
      Mage_Sales - Mage_Sales_Model_Mysql4_Setup + Mage_Sales_Model_Resource_Setup - Mage_Sales_Block + + Mage_Sales_Block + @@ -569,6 +1192,13 @@ + + + payment_auth_expiration + forced_shipment_with_invoice + base_shipping_hidden_tax_amnt + + @@ -626,8 +1256,8 @@ - - + + @@ -638,15 +1268,33 @@ */ --> - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -811,7 +1459,6 @@
      - /sales/ @@ -924,7 +1571,6 @@
      - @@ -933,7 +1579,6 @@ Google Checkout - 20 @@ -1019,33 +1664,55 @@ 0 - - 0 0 * * * - sales/observer::cleanExpiredQuotes + + 0 0 * * * + + + sales/observer::cleanExpiredQuotes + - - 0 0 * * * - sales/observer::aggregateSalesReportOrderData + + 0 0 * * * + + + sales/observer::aggregateSalesReportOrderData + - 0 0 * * * - sales/observer::aggregateSalesReportShipmentData + + 0 0 * * * + + + sales/observer::aggregateSalesReportShipmentData + - 0 0 * * * - sales/observer::aggregateSalesReportInvoicedData + + 0 0 * * * + + + sales/observer::aggregateSalesReportInvoicedData + - 0 0 * * * - sales/observer::aggregateSalesReportRefundedData + + 0 0 * * * + + + sales/observer::aggregateSalesReportRefundedData + - 0 0 * * * - sales/observer::aggregateSalesReportBestsellersData + + 0 0 * * * + + + sales/observer::aggregateSalesReportBestsellersData + diff --git a/app/code/core/Mage/Sales/etc/system.xml b/app/code/core/Mage/Sales/etc/system.xml index b36a1619db..265175a700 100644 --- a/app/code/core/Mage/Sales/etc/system.xml +++ b/app/code/core/Mage/Sales/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -373,7 +373,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -438,7 +438,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -502,7 +502,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -567,7 +567,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -631,7 +631,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -696,7 +696,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 @@ -760,7 +760,7 @@ Comma-separated. - + select adminhtml/system_config_source_email_method 5 diff --git a/app/code/core/Mage/Sales/sql/sales_setup/install-1.6.0.0.php b/app/code/core/Mage/Sales/sql/sales_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..85ed2fceb3 --- /dev/null +++ b/app/code/core/Mage/Sales/sql/sales_setup/install-1.6.0.0.php @@ -0,0 +1,3451 @@ +startSetup(); + +/** + * Create table 'sales/order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'State') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Status') + ->addColumn('coupon_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Coupon Code') + ->addColumn('protect_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Protect Code') + ->addColumn('shipping_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Description') + ->addColumn('is_virtual', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Virtual') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Amount') + ->addColumn('base_discount_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Canceled') + ->addColumn('base_discount_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Invoiced') + ->addColumn('base_discount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Refunded') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('base_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Amount') + ->addColumn('base_shipping_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Canceled') + ->addColumn('base_shipping_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Invoiced') + ->addColumn('base_shipping_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Refunded') + ->addColumn('base_shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Tax Amount') + ->addColumn('base_shipping_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Tax Refunded') + ->addColumn('base_subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal') + ->addColumn('base_subtotal_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Canceled') + ->addColumn('base_subtotal_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Invoiced') + ->addColumn('base_subtotal_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Refunded') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Amount') + ->addColumn('base_tax_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Canceled') + ->addColumn('base_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Invoiced') + ->addColumn('base_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Refunded') + ->addColumn('base_to_global_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Global Rate') + ->addColumn('base_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Order Rate') + ->addColumn('base_total_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Canceled') + ->addColumn('base_total_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Invoiced') + ->addColumn('base_total_invoiced_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Invoiced Cost') + ->addColumn('base_total_offline_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Offline Refunded') + ->addColumn('base_total_online_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Online Refunded') + ->addColumn('base_total_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Paid') + ->addColumn('base_total_qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Qty Ordered') + ->addColumn('base_total_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Refunded') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Amount') + ->addColumn('discount_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Canceled') + ->addColumn('discount_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Invoiced') + ->addColumn('discount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Refunded') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Amount') + ->addColumn('shipping_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Canceled') + ->addColumn('shipping_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Invoiced') + ->addColumn('shipping_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Refunded') + ->addColumn('shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Tax Amount') + ->addColumn('shipping_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Tax Refunded') + ->addColumn('store_to_base_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Base Rate') + ->addColumn('store_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Order Rate') + ->addColumn('subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal') + ->addColumn('subtotal_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Canceled') + ->addColumn('subtotal_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Invoiced') + ->addColumn('subtotal_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Refunded') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('tax_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Canceled') + ->addColumn('tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Invoiced') + ->addColumn('tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Refunded') + ->addColumn('total_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Canceled') + ->addColumn('total_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Invoiced') + ->addColumn('total_offline_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Offline Refunded') + ->addColumn('total_online_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Online Refunded') + ->addColumn('total_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Paid') + ->addColumn('total_qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Qty Ordered') + ->addColumn('total_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Refunded') + ->addColumn('can_ship_partially', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Can Ship Partially') + ->addColumn('can_ship_partially_item', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Can Ship Partially Item') + ->addColumn('customer_is_guest', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Customer Is Guest') + ->addColumn('customer_note_notify', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Customer Note Notify') + ->addColumn('billing_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Billing Address Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + ), 'Customer Group Id') + ->addColumn('edit_increment', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Edit Increment') + ->addColumn('email_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Email Sent') + ->addColumn('forced_shipment_with_invoice', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Forced Do Shipment With Invoice') + ->addColumn('payment_auth_expiration', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Payment Authorization Expiration') + ->addColumn('paypal_ipn_customer_notified', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Paypal Ipn Customer Notified') + ->addColumn('quote_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Quote Address Id') + ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Quote Id') + ->addColumn('shipping_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipping Address Id') + ->addColumn('adjustment_negative', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Adjustment Negative') + ->addColumn('adjustment_positive', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Adjustment Positive') + ->addColumn('base_adjustment_negative', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Adjustment Negative') + ->addColumn('base_adjustment_positive', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Adjustment Positive') + ->addColumn('base_shipping_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Discount Amount') + ->addColumn('base_subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Incl Tax') + ->addColumn('base_total_due', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Due') + ->addColumn('payment_authorization_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Payment Authorization Amount') + ->addColumn('shipping_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Discount Amount') + ->addColumn('subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Incl Tax') + ->addColumn('total_due', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Due') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Weight') + ->addColumn('customer_dob', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Customer Dob') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('applied_rule_ids', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Applied Rule Ids') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('customer_email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Email') + ->addColumn('customer_firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Firstname') + ->addColumn('customer_lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Lastname') + ->addColumn('customer_middlename', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Middlename') + ->addColumn('customer_prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Prefix') + ->addColumn('customer_suffix', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Suffix') + ->addColumn('customer_taxvat', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Taxvat') + ->addColumn('discount_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Discount Description') + ->addColumn('ext_customer_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ext Customer Id') + ->addColumn('ext_order_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ext Order Id') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Global Currency Code') + ->addColumn('hold_before_state', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Hold Before State') + ->addColumn('hold_before_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Hold Before Status') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Order Currency Code') + ->addColumn('original_increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Original Increment Id') + ->addColumn('relation_child_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Relation Child Id') + ->addColumn('relation_child_real_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Relation Child Real Id') + ->addColumn('relation_parent_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Relation Parent Id') + ->addColumn('relation_parent_real_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Relation Parent Real Id') + ->addColumn('remote_ip', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Remote Ip') + ->addColumn('shipping_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Method') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Store Currency Code') + ->addColumn('store_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Store Name') + ->addColumn('x_forwarded_for', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'X Forwarded For') + ->addColumn('customer_note', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Customer Note') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('total_item_count', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Total Item Count') + ->addColumn('customer_gender', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Customer Gender') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addColumn('shipping_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Hidden Tax Amount') + ->addColumn('base_shipping_hidden_tax_amnt', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Hidden Tax Amount') + ->addColumn('hidden_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Invoiced') + ->addColumn('base_hidden_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Invoiced') + ->addColumn('hidden_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Refunded') + ->addColumn('base_hidden_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Refunded') + ->addColumn('shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Incl Tax') + ->addColumn('base_shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Incl Tax') + ->addIndex($installer->getIdxName('sales/order', array('status')), + array('status')) + ->addIndex($installer->getIdxName('sales/order', array('state')), + array('state')) + ->addIndex($installer->getIdxName('sales/order', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/order', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/order', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/order', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('sales/order', array('ext_order_id')), + array('ext_order_id')) + ->addIndex($installer->getIdxName('sales/order', array('quote_id')), + array('quote_id')) + ->addIndex($installer->getIdxName('sales/order', array('updated_at')), + array('updated_at')) + ->addForeignKey($installer->getFkName('sales/order', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/order', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'sales/order_grid' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_grid')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Status') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('store_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Store Name') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('base_total_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Paid') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('total_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Paid') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Order Currency Code') + ->addColumn('shipping_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Name') + ->addColumn('billing_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Billing Name') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addIndex($installer->getIdxName('sales/order_grid', array('status')), + array('status')) + ->addIndex($installer->getIdxName('sales/order_grid', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/order_grid', array('base_grand_total')), + array('base_grand_total')) + ->addIndex($installer->getIdxName('sales/order_grid', array('base_total_paid')), + array('base_total_paid')) + ->addIndex($installer->getIdxName('sales/order_grid', array('grand_total')), + array('grand_total')) + ->addIndex($installer->getIdxName('sales/order_grid', array('total_paid')), + array('total_paid')) + ->addIndex($installer->getIdxName('sales/order_grid', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/order_grid', array('shipping_name')), + array('shipping_name')) + ->addIndex($installer->getIdxName('sales/order_grid', array('billing_name')), + array('billing_name')) + ->addIndex($installer->getIdxName('sales/order_grid', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/order_grid', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('sales/order_grid', array('updated_at')), + array('updated_at')) + ->addForeignKey($installer->getFkName('sales/order_grid', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/order_grid', 'entity_id', 'sales/order', 'entity_id'), + 'entity_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/order_grid', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order Grid'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_address' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_address')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Id') + ->addColumn('customer_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Customer Address Id') + ->addColumn('quote_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Quote Address Id') + ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Region Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Customer Id') + ->addColumn('fax', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Fax') + ->addColumn('region', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Region') + ->addColumn('postcode', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Postcode') + ->addColumn('lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Lastname') + ->addColumn('street', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Street') + ->addColumn('city', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'City') + ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Email') + ->addColumn('telephone', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Telephone') + ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + ), 'Country Id') + ->addColumn('firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Firstname') + ->addColumn('address_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Address Type') + ->addColumn('prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Prefix') + ->addColumn('middlename', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Middlename') + ->addColumn('suffix', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Suffix') + ->addColumn('company', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Company') + ->addIndex($installer->getIdxName('sales/order_address', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/order_address', 'parent_id', 'sales/order', 'entity_id'), + 'parent_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order Address'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_status_history' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_status_history')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('is_customer_notified', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Is Customer Notified') + ->addColumn('is_visible_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible On Front') + ->addColumn('comment', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Comment') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Status') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('sales/order_status_history', array('parent_id')), + array('parent_id')) + ->addIndex($installer->getIdxName('sales/order_status_history', array('created_at')), + array('created_at')) + ->addForeignKey($installer->getFkName('sales/order_status_history', 'parent_id', 'sales/order', 'entity_id'), + 'parent_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order Status History'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_item')) + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Item Id') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Order Id') + ->addColumn('parent_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Item Id') + ->addColumn('quote_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Quote Item Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('product_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Product Type') + ->addColumn('product_options', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Product Options') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Weight') + ->addColumn('is_virtual', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Virtual') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('applied_rule_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Applied Rule Ids') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('free_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Free Shipping') + ->addColumn('is_qty_decimal', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Qty Decimal') + ->addColumn('no_discount', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'No Discount') + ->addColumn('qty_backordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Backordered') + ->addColumn('qty_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Canceled') + ->addColumn('qty_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Invoiced') + ->addColumn('qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Ordered') + ->addColumn('qty_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Refunded') + ->addColumn('qty_shipped', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Qty Shipped') + ->addColumn('base_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Cost') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('base_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Price') + ->addColumn('original_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Original Price') + ->addColumn('base_original_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Original Price') + ->addColumn('tax_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Percent') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Amount') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Tax Amount') + ->addColumn('tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Invoiced') + ->addColumn('base_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Tax Invoiced') + ->addColumn('discount_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Percent') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Discount Amount') + ->addColumn('discount_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Invoiced') + ->addColumn('base_discount_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Discount Invoiced') + ->addColumn('amount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Amount Refunded') + ->addColumn('base_amount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Amount Refunded') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Row Total') + ->addColumn('base_row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Row Total') + ->addColumn('row_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Row Invoiced') + ->addColumn('base_row_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Row Invoiced') + ->addColumn('row_weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Row Weight') + ->addColumn('base_tax_before_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Before Discount') + ->addColumn('tax_before_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Before Discount') + ->addColumn('ext_order_item_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ext Order Item Id') + ->addColumn('locked_do_invoice', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Locked Do Invoice') + ->addColumn('locked_do_ship', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Locked Do Ship') + ->addColumn('price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price Incl Tax') + ->addColumn('base_price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price Incl Tax') + ->addColumn('row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total Incl Tax') + ->addColumn('base_row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total Incl Tax') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addColumn('hidden_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Invoiced') + ->addColumn('base_hidden_tax_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Invoiced') + ->addColumn('hidden_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Refunded') + ->addColumn('base_hidden_tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Refunded') + ->addColumn('is_nominal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Nominal') + ->addColumn('tax_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Canceled') + ->addColumn('hidden_tax_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Canceled') + ->addColumn('tax_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Refunded') + ->addIndex($installer->getIdxName('sales/order_item', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/order_item', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/order_item', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/order_item', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order Item'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_payment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_payment')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('base_shipping_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Captured') + ->addColumn('shipping_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Captured') + ->addColumn('amount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount Refunded') + ->addColumn('base_amount_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Paid') + ->addColumn('amount_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount Canceled') + ->addColumn('base_amount_authorized', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Authorized') + ->addColumn('base_amount_paid_online', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Paid Online') + ->addColumn('base_amount_refunded_online', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Refunded Online') + ->addColumn('base_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Amount') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Amount') + ->addColumn('amount_paid', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount Paid') + ->addColumn('amount_authorized', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount Authorized') + ->addColumn('base_amount_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Ordered') + ->addColumn('base_shipping_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Refunded') + ->addColumn('shipping_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Refunded') + ->addColumn('base_amount_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Refunded') + ->addColumn('amount_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount Ordered') + ->addColumn('base_amount_canceled', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount Canceled') + ->addColumn('ideal_transaction_checked', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Ideal Transaction Checked') + ->addColumn('quote_payment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Quote Payment Id') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('cc_exp_month', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Exp Month') + ->addColumn('cc_ss_start_year', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Ss Start Year') + ->addColumn('echeck_bank_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Echeck Bank Name') + ->addColumn('method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Method') + ->addColumn('cc_debug_request_body', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Debug Request Body') + ->addColumn('cc_secure_verify', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Secure Verify') + ->addColumn('cybersource_token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cybersource Token') + ->addColumn('ideal_issuer_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ideal Issuer Title') + ->addColumn('protection_eligibility', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Protection Eligibility') + ->addColumn('cc_approval', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Approval') + ->addColumn('cc_last4', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Last4') + ->addColumn('cc_status_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Status Description') + ->addColumn('echeck_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Echeck Type') + ->addColumn('paybox_question_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Paybox Question Number') + ->addColumn('cc_debug_response_serialized', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Debug Response Serialized') + ->addColumn('cc_ss_start_month', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Ss Start Month') + ->addColumn('echeck_account_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Echeck Account Type') + ->addColumn('last_trans_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Last Trans Id') + ->addColumn('cc_cid_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Cid Status') + ->addColumn('cc_owner', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Owner') + ->addColumn('cc_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Type') + ->addColumn('ideal_issuer_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ideal Issuer Id') + ->addColumn('po_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Po Number') + ->addColumn('cc_exp_year', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Exp Year') + ->addColumn('cc_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Status') + ->addColumn('echeck_routing_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Echeck Routing Number') + ->addColumn('account_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Account Status') + ->addColumn('anet_trans_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Anet Trans Method') + ->addColumn('cc_debug_response_body', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Debug Response Body') + ->addColumn('cc_ss_issue', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Ss Issue') + ->addColumn('echeck_account_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Echeck Account Name') + ->addColumn('cc_avs_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Avs Status') + ->addColumn('cc_number_enc', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Number Enc') + ->addColumn('cc_trans_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Trans Id') + ->addColumn('flo2cash_account_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Flo2cash Account Id') + ->addColumn('paybox_request_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Paybox Request Number') + ->addColumn('address_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Address Status') + ->addColumn('additional_information', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Information') + ->addIndex($installer->getIdxName('sales/order_payment', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/order_payment', 'parent_id', 'sales/order', 'entity_id'), + 'parent_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Order Payment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipment')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('total_weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Weight') + ->addColumn('total_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Qty') + ->addColumn('email_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Email Sent') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Customer Id') + ->addColumn('shipping_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipping Address Id') + ->addColumn('billing_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Billing Address Id') + ->addColumn('shipment_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipment Status') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addIndex($installer->getIdxName('sales/shipment', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/shipment', array('total_qty')), + array('total_qty')) + ->addIndex($installer->getIdxName('sales/shipment', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/shipment', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/shipment', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/shipment', array('updated_at')), + array('updated_at')) + ->addForeignKey($installer->getFkName('sales/shipment', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/shipment', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Shipment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipment_grid' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipment_grid')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('total_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Qty') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('shipment_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipment Status') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('order_created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Order Created At') + ->addColumn('shipping_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Name') + ->addIndex($installer->getIdxName('sales/shipment_grid', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('total_qty')), + array('total_qty')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('shipment_status')), + array('shipment_status')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('order_increment_id')), + array('order_increment_id')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('order_created_at')), + array('order_created_at')) + ->addIndex($installer->getIdxName('sales/shipment_grid', array('shipping_name')), + array('shipping_name')) + ->addForeignKey($installer->getFkName('sales/shipment_grid', 'entity_id', 'sales/shipment', 'entity_id'), + 'entity_id', $installer->getTable('sales/shipment'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/shipment_grid', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Shipment Grid'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipment_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipment_item')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Weight') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Qty') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Product Id') + ->addColumn('order_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Order Item Id') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addIndex($installer->getIdxName('sales/shipment_item', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/shipment_item', 'parent_id', 'sales/shipment', 'entity_id'), + 'parent_id', $installer->getTable('sales/shipment'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Shipment Item'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipment_track' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipment_track')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Weight') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Qty') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('track_number', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Number') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Title') + ->addColumn('carrier_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Carrier Code') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addIndex($installer->getIdxName('sales/shipment_track', array('parent_id')), + array('parent_id')) + ->addIndex($installer->getIdxName('sales/shipment_track', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/shipment_track', array('created_at')), + array('created_at')) + ->addForeignKey($installer->getFkName('sales/shipment_track', 'parent_id', 'sales/shipment', 'entity_id'), + 'parent_id', $installer->getTable('sales/shipment'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Shipment Track'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipment_comment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipment_comment')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('is_customer_notified', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Is Customer Notified') + ->addColumn('is_visible_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible On Front') + ->addColumn('comment', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Comment') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('sales/shipment_comment', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/shipment_comment', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/shipment_comment', 'parent_id', 'sales/shipment', 'entity_id'), + 'parent_id', $installer->getTable('sales/shipment'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Shipment Comment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoice' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoice')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'identity' => true + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Tax Amount') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Amount') + ->addColumn('store_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Order Rate') + ->addColumn('base_shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Tax Amount') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Amount') + ->addColumn('base_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Order Rate') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Amount') + ->addColumn('subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Incl Tax') + ->addColumn('base_subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Incl Tax') + ->addColumn('store_to_base_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Base Rate') + ->addColumn('base_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Amount') + ->addColumn('total_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Qty') + ->addColumn('base_to_global_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Global Rate') + ->addColumn('subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal') + ->addColumn('base_subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Amount') + ->addColumn('billing_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Billing Address Id') + ->addColumn('is_used_for_refund', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Used For Refund') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('email_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Email Sent') + ->addColumn('can_void_flag', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Can Void Flag') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'State') + ->addColumn('shipping_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipping Address Id') + ->addColumn('cybersource_token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cybersource Token') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Store Currency Code') + ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Transaction Id') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Order Currency Code') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Global Currency Code') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addColumn('shipping_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Hidden Tax Amount') + ->addColumn('base_shipping_hidden_tax_amnt', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Hidden Tax Amount') + ->addColumn('shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Incl Tax') + ->addColumn('base_shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Incl Tax') + ->addColumn('base_total_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Total Refunded') + ->addIndex($installer->getIdxName('sales/invoice', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/invoice', array('grand_total')), + array('grand_total')) + ->addIndex($installer->getIdxName('sales/invoice', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/invoice', array('state')), + array('state')) + ->addIndex($installer->getIdxName('sales/invoice', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/invoice', array('created_at')), + array('created_at')) + ->addForeignKey($installer->getFkName('sales/invoice', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/invoice', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Invoice'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoice_grid' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoice_grid')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'State') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Store Currency Code') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Order Currency Code') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Global Currency Code') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('order_created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Order Created At') + ->addColumn('billing_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Billing Name') + ->addIndex($installer->getIdxName('sales/invoice_grid', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('grand_total')), + array('grand_total')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('state')), + array('state')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('order_increment_id')), + array('order_increment_id')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('order_created_at')), + array('order_created_at')) + ->addIndex($installer->getIdxName('sales/invoice_grid', array('billing_name')), + array('billing_name')) + ->addForeignKey($installer->getFkName('sales/invoice_grid', 'entity_id', 'sales/invoice', 'entity_id'), + 'entity_id', $installer->getTable('sales/invoice'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/invoice_grid', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Invoice Grid'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoice_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoice_item')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('base_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('base_row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Amount') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Amount') + ->addColumn('price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price Incl Tax') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Amount') + ->addColumn('base_price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price Incl Tax') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Qty') + ->addColumn('base_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Cost') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('base_row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total Incl Tax') + ->addColumn('row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total Incl Tax') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Product Id') + ->addColumn('order_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Order Item Id') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addIndex($installer->getIdxName('sales/invoice_item', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/invoice_item', 'parent_id', 'sales/invoice', 'entity_id'), + 'parent_id', $installer->getTable('sales/invoice'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Invoice Item'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoice_comment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoice_comment')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('is_customer_notified', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Customer Notified') + ->addColumn('is_visible_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible On Front') + ->addColumn('comment', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Comment') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('sales/invoice_comment', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/invoice_comment', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/invoice_comment', 'parent_id', 'sales/invoice', 'entity_id'), + 'parent_id', $installer->getTable('sales/invoice'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Invoice Comment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/creditmemo' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/creditmemo')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('adjustment_positive', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Adjustment Positive') + ->addColumn('base_shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Tax Amount') + ->addColumn('store_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Order Rate') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Amount') + ->addColumn('base_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Order Rate') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('base_adjustment_negative', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Adjustment Negative') + ->addColumn('base_subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Incl Tax') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Amount') + ->addColumn('subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Incl Tax') + ->addColumn('adjustment_negative', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Adjustment Negative') + ->addColumn('base_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Amount') + ->addColumn('store_to_base_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Base Rate') + ->addColumn('base_to_global_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Global Rate') + ->addColumn('base_adjustment', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Adjustment') + ->addColumn('base_subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Amount') + ->addColumn('subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal') + ->addColumn('adjustment', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Adjustment') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('base_adjustment_positive', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Adjustment Positive') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Amount') + ->addColumn('shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Tax Amount') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('email_sent', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Email Sent') + ->addColumn('creditmemo_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Creditmemo Status') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'State') + ->addColumn('shipping_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Shipping Address Id') + ->addColumn('billing_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Billing Address Id') + ->addColumn('invoice_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Invoice Id') + ->addColumn('cybersource_token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cybersource Token') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Store Currency Code') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Order Currency Code') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Global Currency Code') + ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Transaction Id') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addColumn('shipping_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Hidden Tax Amount') + ->addColumn('base_shipping_hidden_tax_amnt', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Hidden Tax Amount') + ->addColumn('shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Incl Tax') + ->addColumn('base_shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Incl Tax') + ->addIndex($installer->getIdxName('sales/creditmemo', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/creditmemo', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/creditmemo', array('creditmemo_status')), + array('creditmemo_status')) + ->addIndex($installer->getIdxName('sales/creditmemo', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/creditmemo', array('state')), + array('state')) + ->addIndex($installer->getIdxName('sales/creditmemo', array('created_at')), + array('created_at')) + ->addForeignKey($installer->getFkName('sales/creditmemo', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/creditmemo', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Creditmemo'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/creditmemo_grid' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/creditmemo_grid')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('store_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Order Rate') + ->addColumn('base_to_order_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Order Rate') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Grand Total') + ->addColumn('store_to_base_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Store To Base Rate') + ->addColumn('base_to_global_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Global Rate') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Grand Total') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('creditmemo_status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Creditmemo Status') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'State') + ->addColumn('invoice_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Invoice Id') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Store Currency Code') + ->addColumn('order_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Order Currency Code') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Base Currency Code') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + ), 'Global Currency Code') + ->addColumn('increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Increment Id') + ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Increment Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('order_created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Order Created At') + ->addColumn('billing_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Billing Name') + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('grand_total')), + array('grand_total')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('base_grand_total')), + array('base_grand_total')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('creditmemo_status')), + array('creditmemo_status')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('state')), + array('state')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('increment_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('increment_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('order_increment_id')), + array('order_increment_id')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('order_created_at')), + array('order_created_at')) + ->addIndex($installer->getIdxName('sales/creditmemo_grid', array('billing_name')), + array('billing_name')) + ->addForeignKey($installer->getFkName('sales/creditmemo_grid', 'entity_id', 'sales/creditmemo', 'entity_id'), + 'entity_id', $installer->getTable('sales/creditmemo'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/creditmemo_grid', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Creditmemo Grid'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/creditmemo_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/creditmemo_item')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('base_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('base_row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Amount') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Discount Amount') + ->addColumn('price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price Incl Tax') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Amount') + ->addColumn('base_price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price Incl Tax') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Qty') + ->addColumn('base_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Cost') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('base_row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total Incl Tax') + ->addColumn('row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total Incl Tax') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Product Id') + ->addColumn('order_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Order Item Id') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addIndex($installer->getIdxName('sales/creditmemo_item', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/creditmemo_item', 'parent_id', 'sales/creditmemo', 'entity_id'), + 'parent_id', $installer->getTable('sales/creditmemo'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Creditmemo Item'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'sales/creditmemo_comment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/creditmemo_comment')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Parent Id') + ->addColumn('is_customer_notified', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + ), 'Is Customer Notified') + ->addColumn('is_visible_on_front', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Visible On Front') + ->addColumn('comment', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Comment') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('sales/creditmemo_comment', array('created_at')), + array('created_at')) + ->addIndex($installer->getIdxName('sales/creditmemo_comment', array('parent_id')), + array('parent_id')) + ->addForeignKey($installer->getFkName('sales/creditmemo_comment', 'parent_id', 'sales/creditmemo', 'entity_id'), + 'parent_id', $installer->getTable('sales/creditmemo'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Creditmemo Comment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Entity Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('converted_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Converted At') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '1', + ), 'Is Active') + ->addColumn('is_virtual', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Is Virtual') + ->addColumn('is_multi_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Is Multi Shipping') + ->addColumn('items_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Items Count') + ->addColumn('items_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Items Qty') + ->addColumn('orig_order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Orig Order Id') + ->addColumn('store_to_base_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Store To Base Rate') + ->addColumn('store_to_quote_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Store To Quote Rate') + ->addColumn('base_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Base Currency Code') + ->addColumn('store_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Store Currency Code') + ->addColumn('quote_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Quote Currency Code') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Grand Total') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Grand Total') + ->addColumn('checkout_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Checkout Method') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Customer Id') + ->addColumn('customer_tax_class_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Customer Tax Class Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Customer Group Id') + ->addColumn('customer_email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Email') + ->addColumn('customer_prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Customer Prefix') + ->addColumn('customer_firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Firstname') + ->addColumn('customer_middlename', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Customer Middlename') + ->addColumn('customer_lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Lastname') + ->addColumn('customer_suffix', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Customer Suffix') + ->addColumn('customer_dob', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Customer Dob') + ->addColumn('customer_note', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Note') + ->addColumn('customer_note_notify', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '1', + ), 'Customer Note Notify') + ->addColumn('customer_is_guest', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Customer Is Guest') + ->addColumn('remote_ip', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Remote Ip') + ->addColumn('applied_rule_ids', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Applied Rule Ids') + ->addColumn('reserved_order_id', Varien_Db_Ddl_Table::TYPE_TEXT, 64, array( + 'nullable' => true, + ), 'Reserved Order Id') + ->addColumn('password_hash', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Password Hash') + ->addColumn('coupon_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Coupon Code') + ->addColumn('global_currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Global Currency Code') + ->addColumn('base_to_global_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Global Rate') + ->addColumn('base_to_quote_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base To Quote Rate') + ->addColumn('customer_taxvat', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Taxvat') + ->addColumn('customer_gender', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Customer Gender') + ->addColumn('subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal') + ->addColumn('base_subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal') + ->addColumn('subtotal_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal With Discount') + ->addColumn('base_subtotal_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal With Discount') + ->addColumn('is_changed', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Is Changed') + ->addColumn('trigger_recollect', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Trigger Recollect') + ->addColumn('ext_shipping_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Ext Shipping Info') + ->addIndex($installer->getIdxName('sales/quote', array('customer_id', 'store_id', 'is_active')), + array('customer_id', 'store_id', 'is_active')) + ->addIndex($installer->getIdxName('sales/quote', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/quote', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote_address' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_address')) + ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Address Id') + ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quote Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('save_in_address_book', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'default' => '0', + ), 'Save In Address Book') + ->addColumn('customer_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Address Id') + ->addColumn('address_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Address Type') + ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Email') + ->addColumn('prefix', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Prefix') + ->addColumn('firstname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Firstname') + ->addColumn('middlename', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Middlename') + ->addColumn('lastname', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Lastname') + ->addColumn('suffix', Varien_Db_Ddl_Table::TYPE_TEXT, 40, array( + ), 'Suffix') + ->addColumn('company', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Company') + ->addColumn('street', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Street') + ->addColumn('city', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'City') + ->addColumn('region', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Region') + ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Region Id') + ->addColumn('postcode', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Postcode') + ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Country Id') + ->addColumn('telephone', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Telephone') + ->addColumn('fax', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Fax') + ->addColumn('same_as_billing', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Same As Billing') + ->addColumn('free_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Free Shipping') + ->addColumn('collect_shipping_rates', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Collect Shipping Rates') + ->addColumn('shipping_method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Method') + ->addColumn('shipping_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Description') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Weight') + ->addColumn('subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Subtotal') + ->addColumn('base_subtotal', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Subtotal') + ->addColumn('subtotal_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Subtotal With Discount') + ->addColumn('base_subtotal_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Subtotal With Discount') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Tax Amount') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Tax Amount') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Shipping Amount') + ->addColumn('base_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Shipping Amount') + ->addColumn('shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Tax Amount') + ->addColumn('base_shipping_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Tax Amount') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Discount Amount') + ->addColumn('grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Grand Total') + ->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Grand Total') + ->addColumn('customer_notes', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Customer Notes') + ->addColumn('applied_taxes', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Applied Taxes') + ->addColumn('discount_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Discount Description') + ->addColumn('shipping_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Discount Amount') + ->addColumn('base_shipping_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Discount Amount') + ->addColumn('subtotal_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Subtotal Incl Tax') + ->addColumn('base_subtotal_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Subtotal Total Incl Tax') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addColumn('shipping_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Hidden Tax Amount') + ->addColumn('base_shipping_hidden_tax_amnt', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Hidden Tax Amount') + ->addColumn('shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Incl Tax') + ->addColumn('base_shipping_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Shipping Incl Tax') + ->addIndex($installer->getIdxName('sales/quote_address', array('quote_id')), + array('quote_id')) + ->addForeignKey($installer->getFkName('sales/quote_address', 'quote_id', 'sales/quote', 'entity_id'), + 'quote_id', $installer->getTable('sales/quote'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Address'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_item')) + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Item Id') + ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quote Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('parent_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Item Id') + ->addColumn('is_virtual', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Virtual') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('applied_rule_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Applied Rule Ids') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('free_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Free Shipping') + ->addColumn('is_qty_decimal', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Qty Decimal') + ->addColumn('no_discount', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'No Discount') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Weight') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('base_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Price') + ->addColumn('custom_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Custom Price') + ->addColumn('discount_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Percent') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Discount Amount') + ->addColumn('tax_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Percent') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Amount') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Tax Amount') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Row Total') + ->addColumn('base_row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Row Total') + ->addColumn('row_total_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Row Total With Discount') + ->addColumn('row_weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Row Weight') + ->addColumn('product_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Product Type') + ->addColumn('base_tax_before_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Tax Before Discount') + ->addColumn('tax_before_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Before Discount') + ->addColumn('original_custom_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Original Custom Price') + ->addColumn('redirect_url', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Redirect Url') + ->addColumn('base_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Cost') + ->addColumn('price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price Incl Tax') + ->addColumn('base_price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price Incl Tax') + ->addColumn('row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total Incl Tax') + ->addColumn('base_row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total Incl Tax') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addIndex($installer->getIdxName('sales/quote_item', array('parent_item_id')), + array('parent_item_id')) + ->addIndex($installer->getIdxName('sales/quote_item', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('sales/quote_item', array('quote_id')), + array('quote_id')) + ->addIndex($installer->getIdxName('sales/quote_item', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/quote_item', 'parent_item_id', 'sales/quote_item', 'item_id'), + 'parent_item_id', $installer->getTable('sales/quote_item'), 'item_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/quote_item', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/quote_item', 'quote_id', 'sales/quote', 'entity_id'), + 'quote_id', $installer->getTable('sales/quote'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/quote_item', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Item'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'sales/quote_address_item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_address_item')) + ->addColumn('address_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Address Item Id') + ->addColumn('parent_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Item Id') + ->addColumn('quote_address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quote Address Id') + ->addColumn('quote_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quote Item Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('applied_rule_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Applied Rule Ids') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Weight') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Tax Amount') + ->addColumn('row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Row Total') + ->addColumn('base_row_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Base Row Total') + ->addColumn('row_total_with_discount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Row Total With Discount') + ->addColumn('base_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Discount Amount') + ->addColumn('base_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Base Tax Amount') + ->addColumn('row_weight', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'default' => '0.0000', + ), 'Row Weight') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('super_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Super Product Id') + ->addColumn('parent_product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Product Id') + ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sku') + ->addColumn('image', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Image') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('free_shipping', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Free Shipping') + ->addColumn('is_qty_decimal', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Is Qty Decimal') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price') + ->addColumn('discount_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Discount Percent') + ->addColumn('no_discount', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'No Discount') + ->addColumn('tax_percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Percent') + ->addColumn('base_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price') + ->addColumn('base_cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Cost') + ->addColumn('price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Price Incl Tax') + ->addColumn('base_price_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Price Incl Tax') + ->addColumn('row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Row Total Incl Tax') + ->addColumn('base_row_total_incl_tax', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Row Total Incl Tax') + ->addColumn('hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Hidden Tax Amount') + ->addColumn('base_hidden_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Hidden Tax Amount') + ->addIndex($installer->getIdxName('sales/quote_address_item', array('quote_address_id')), + array('quote_address_id')) + ->addIndex($installer->getIdxName('sales/quote_address_item', array('parent_item_id')), + array('parent_item_id')) + ->addIndex($installer->getIdxName('sales/quote_address_item', array('quote_item_id')), + array('quote_item_id')) + ->addForeignKey($installer->getFkName('sales/quote_address_item', 'quote_address_id', 'sales/quote_address', 'address_id'), + 'quote_address_id', $installer->getTable('sales/quote_address'), 'address_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/quote_address_item', 'parent_item_id', 'sales/quote_address_item', 'address_item_id'), + 'parent_item_id', $installer->getTable('sales/quote_address_item'), 'address_item_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/quote_address_item', 'quote_item_id', 'sales/quote_item', 'item_id'), + 'quote_item_id', $installer->getTable('sales/quote_item'), 'item_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Address Item'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote_item_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_item_option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Id') + ->addColumn('item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Item Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Code') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Value') + ->addIndex($installer->getIdxName('sales/quote_item_option', array('item_id')), + array('item_id')) + ->addForeignKey($installer->getFkName('sales/quote_item_option', 'item_id', 'sales/quote_item', 'item_id'), + 'item_id', $installer->getTable('sales/quote_item'), 'item_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Item Option'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote_payment' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_payment')) + ->addColumn('payment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Payment Id') + ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Quote Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Method') + ->addColumn('cc_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Type') + ->addColumn('cc_number_enc', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Number Enc') + ->addColumn('cc_last4', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Last4') + ->addColumn('cc_cid_enc', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Cid Enc') + ->addColumn('cc_owner', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Owner') + ->addColumn('cc_exp_month', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Cc Exp Month') + ->addColumn('cc_exp_year', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Cc Exp Year') + ->addColumn('cc_ss_owner', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Ss Owner') + ->addColumn('cc_ss_start_month', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Cc Ss Start Month') + ->addColumn('cc_ss_start_year', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Cc Ss Start Year') + ->addColumn('cybersource_token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cybersource Token') + ->addColumn('paypal_correlation_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Paypal Correlation Id') + ->addColumn('paypal_payer_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Paypal Payer Id') + ->addColumn('paypal_payer_status', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Paypal Payer Status') + ->addColumn('po_number', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Po Number') + ->addColumn('additional_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Data') + ->addColumn('cc_ss_issue', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Cc Ss Issue') + ->addColumn('additional_information', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Information') + ->addColumn('ideal_issuer_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Ideal Issuer Id') + ->addColumn('ideal_issuer_list', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Ideal Issuer List') + ->addIndex($installer->getIdxName('sales/quote_payment', array('quote_id')), + array('quote_id')) + ->addForeignKey($installer->getFkName('sales/quote_payment', 'quote_id', 'sales/quote', 'entity_id'), + 'quote_id', $installer->getTable('sales/quote'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Payment'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/quote_address_shipping_rate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/quote_address_shipping_rate')) + ->addColumn('rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rate Id') + ->addColumn('address_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Address Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Updated At') + ->addColumn('carrier', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Carrier') + ->addColumn('carrier_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Carrier Title') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Code') + ->addColumn('method', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Method') + ->addColumn('method_description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Method Description') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('error_message', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Error Message') + ->addColumn('method_title', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Method Title') + ->addIndex($installer->getIdxName('sales/quote_address_shipping_rate', array('address_id')), + array('address_id')) + ->addForeignKey($installer->getFkName('sales/quote_address_shipping_rate', 'address_id', 'sales/quote_address', 'address_id'), + 'address_id', $installer->getTable('sales/quote_address'), 'address_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Flat Quote Shipping Rate'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoiced_aggregated' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoiced_aggregated')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('orders_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Orders Invoiced') + ->addColumn('invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced') + ->addColumn('invoiced_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced Captured') + ->addColumn('invoiced_not_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced Not Captured') + ->addIndex($installer->getIdxName('sales/invoiced_aggregated', array('period', 'store_id', 'order_status'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/invoiced_aggregated', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/invoiced_aggregated', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Invoiced Aggregated'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/invoiced_aggregated_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/invoiced_aggregated_order')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Order Status') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('orders_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Orders Invoiced') + ->addColumn('invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced') + ->addColumn('invoiced_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced Captured') + ->addColumn('invoiced_not_captured', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Invoiced Not Captured') + ->addIndex($installer->getIdxName('sales/invoiced_aggregated_order', array('period', 'store_id', 'order_status'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/invoiced_aggregated_order', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/invoiced_aggregated_order', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Invoiced Aggregated Order'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_aggregated_created' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_aggregated_created')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Order Status') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('total_qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Qty Ordered') + ->addColumn('total_qty_invoiced', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Qty Invoiced') + ->addColumn('total_income_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Income Amount') + ->addColumn('total_revenue_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Revenue Amount') + ->addColumn('total_profit_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Profit Amount') + ->addColumn('total_invoiced_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Invoiced Amount') + ->addColumn('total_canceled_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Canceled Amount') + ->addColumn('total_paid_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Paid Amount') + ->addColumn('total_refunded_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Refunded Amount') + ->addColumn('total_tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Tax Amount') + ->addColumn('total_tax_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Tax Amount Actual') + ->addColumn('total_shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Shipping Amount') + ->addColumn('total_shipping_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Shipping Amount Actual') + ->addColumn('total_discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Discount Amount') + ->addColumn('total_discount_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Discount Amount Actual') + ->addIndex($installer->getIdxName('sales/order_aggregated_created', array('period', 'store_id', 'order_status'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/order_aggregated_created', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/order_aggregated_created', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Order Aggregated Created'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/payment_transaction' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/payment_transaction')) + ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Transaction Id') + ->addColumn('parent_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Parent Id') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Order Id') + ->addColumn('payment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Payment Id') + ->addColumn('txn_id', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + ), 'Txn Id') + ->addColumn('parent_txn_id', Varien_Db_Ddl_Table::TYPE_TEXT, 100, array( + ), 'Parent Txn Id') + ->addColumn('txn_type', Varien_Db_Ddl_Table::TYPE_TEXT, 15, array( + ), 'Txn Type') + ->addColumn('is_closed', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Closed') + ->addColumn('additional_information', Varien_Db_Ddl_Table::TYPE_BLOB, '64K', array( + ), 'Additional Information') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('sales/payment_transaction', array('order_id', 'payment_id', 'txn_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('order_id', 'payment_id', 'txn_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/payment_transaction', array('order_id')), + array('order_id')) + ->addIndex($installer->getIdxName('sales/payment_transaction', array('parent_id')), + array('parent_id')) + ->addIndex($installer->getIdxName('sales/payment_transaction', array('payment_id')), + array('payment_id')) + ->addForeignKey($installer->getFkName('sales/payment_transaction', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/payment_transaction', 'parent_id', 'sales/payment_transaction', 'transaction_id'), + 'parent_id', $installer->getTable('sales/payment_transaction'), 'transaction_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/payment_transaction', 'payment_id', 'sales/order_payment', 'entity_id'), + 'payment_id', $installer->getTable('sales/order_payment'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Payment Transaction'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/refunded_aggregated' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/refunded_aggregated')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + 'default' => '', + ), 'Order Status') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Refunded') + ->addColumn('online_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Online Refunded') + ->addColumn('offline_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Offline Refunded') + ->addIndex($installer->getIdxName('sales/refunded_aggregated', array('period', 'store_id', 'order_status'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/refunded_aggregated', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/refunded_aggregated', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Refunded Aggregated'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/refunded_aggregated_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/refunded_aggregated_order')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Refunded') + ->addColumn('online_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Online Refunded') + ->addColumn('offline_refunded', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Offline Refunded') + ->addIndex($installer->getIdxName('sales/refunded_aggregated_order', array('period', 'store_id', 'order_status'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/refunded_aggregated_order', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/refunded_aggregated_order', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Refunded Aggregated Order'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipping_aggregated' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipping_aggregated')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('shipping_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Description') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('total_shipping', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Shipping') + ->addColumn('total_shipping_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Shipping Actual') + ->addIndex($installer->getIdxName('sales/shipping_aggregated', array('period', 'store_id', 'order_status', 'shipping_description'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status', 'shipping_description'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/shipping_aggregated', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/shipping_aggregated', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Shipping Aggregated'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/shipping_aggregated_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/shipping_aggregated_order')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('shipping_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Shipping Description') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('total_shipping', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Shipping') + ->addColumn('total_shipping_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Total Shipping Actual') + ->addIndex($installer->getIdxName('sales/shipping_aggregated_order', array('period', 'store_id', 'order_status', 'shipping_description'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status', 'shipping_description'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/shipping_aggregated_order', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/shipping_aggregated_order', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Shipping Aggregated Order'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/bestsellers_aggregated_daily' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/bestsellers_aggregated_daily')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('product_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Product Name') + ->addColumn('product_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Product Price') + ->addColumn('qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty Ordered') + ->addColumn('rating_pos', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Rating Pos') + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_daily', array('period', 'store_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_daily', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_daily', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_daily', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_daily', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Bestsellers Aggregated Daily'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/bestsellers_aggregated_monthly' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/bestsellers_aggregated_monthly')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('product_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Product Name') + ->addColumn('product_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Product Price') + ->addColumn('qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty Ordered') + ->addColumn('rating_pos', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Rating Pos') + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_monthly', array('period', 'store_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_monthly', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_monthly', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_monthly', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_monthly', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Bestsellers Aggregated Monthly'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'sales/bestsellers_aggregated_yearly' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/bestsellers_aggregated_yearly')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Product Id') + ->addColumn('product_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => true, + ), 'Product Name') + ->addColumn('product_price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Product Price') + ->addColumn('qty_ordered', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Qty Ordered') + ->addColumn('rating_pos', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Rating Pos') + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_yearly', array('period', 'store_id', 'product_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'product_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_yearly', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('sales/bestsellers_aggregated_yearly', array('product_id')), + array('product_id')) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_yearly', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/bestsellers_aggregated_yearly', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Bestsellers Aggregated Yearly'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/billing_agreement' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/billing_agreement')) + ->addColumn('agreement_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Agreement Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Customer Id') + ->addColumn('method_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Method Code') + ->addColumn('reference_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Reference Id') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + ), 'Status') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('agreement_label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Agreement Label') + ->addIndex($installer->getIdxName('sales/billing_agreement', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('sales/billing_agreement', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/billing_agreement', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/billing_agreement', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Billing Agreement'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/billing_agreement_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/billing_agreement_order')) + ->addColumn('agreement_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Agreement Id') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Order Id') + ->addIndex($installer->getIdxName('sales/billing_agreement_order', array('order_id')), + array('order_id')) + ->addForeignKey($installer->getFkName('sales/billing_agreement_order', 'agreement_id', 'sales/billing_agreement', 'agreement_id'), + 'agreement_id', $installer->getTable('sales/billing_agreement'), 'agreement_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/billing_agreement_order', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Billing Agreement Order'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/recurring_profile' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/recurring_profile')) + ->addColumn('profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Profile Id') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + ), 'State') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('method_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Method Code') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Created At') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('reference_id', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Reference Id') + ->addColumn('subscriber_name', Varien_Db_Ddl_Table::TYPE_TEXT, 150, array( + ), 'Subscriber Name') + ->addColumn('start_datetime', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => false, + ), 'Start Datetime') + ->addColumn('internal_reference_id', Varien_Db_Ddl_Table::TYPE_TEXT, 42, array( + 'nullable' => false, + ), 'Internal Reference Id') + ->addColumn('schedule_description', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Schedule Description') + ->addColumn('suspension_threshold', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Suspension Threshold') + ->addColumn('bill_failed_later', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Bill Failed Later') + ->addColumn('period_unit', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + ), 'Period Unit') + ->addColumn('period_frequency', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Period Frequency') + ->addColumn('period_max_cycles', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Period Max Cycles') + ->addColumn('billing_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Billing Amount') + ->addColumn('trial_period_unit', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + ), 'Trial Period Unit') + ->addColumn('trial_period_frequency', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Trial Period Frequency') + ->addColumn('trial_period_max_cycles', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Trial Period Max Cycles') + ->addColumn('trial_billing_amount', Varien_Db_Ddl_Table::TYPE_TEXT, null, array( + ), 'Trial Billing Amount') + ->addColumn('currency_code', Varien_Db_Ddl_Table::TYPE_TEXT, 3, array( + 'nullable' => false, + ), 'Currency Code') + ->addColumn('shipping_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Shipping Amount') + ->addColumn('tax_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Tax Amount') + ->addColumn('init_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Init Amount') + ->addColumn('init_may_fail', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Init May Fail') + ->addColumn('order_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Order Info') + ->addColumn('order_item_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Order Item Info') + ->addColumn('billing_address_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Billing Address Info') + ->addColumn('shipping_address_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Shipping Address Info') + ->addColumn('profile_vendor_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Profile Vendor Info') + ->addColumn('additional_info', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Additional Info') + ->addIndex($installer->getIdxName('sales/recurring_profile', array('internal_reference_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('internal_reference_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/recurring_profile', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('sales/recurring_profile', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/recurring_profile', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/recurring_profile', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Recurring Profile'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/recurring_profile_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/recurring_profile_order')) + ->addColumn('link_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Link Id') + ->addColumn('profile_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Profile Id') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Order Id') + ->addIndex($installer->getIdxName('sales/recurring_profile_order', array('profile_id', 'order_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('profile_id', 'order_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('sales/recurring_profile_order', array('order_id')), + array('order_id')) + ->addForeignKey($installer->getFkName('sales/recurring_profile_order', 'order_id', 'sales/order', 'entity_id'), + 'order_id', $installer->getTable('sales/order'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/recurring_profile_order', 'profile_id', 'sales/recurring_profile', 'profile_id'), + 'profile_id', $installer->getTable('sales/recurring_profile'), 'profile_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Recurring Profile Order'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_tax' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_tax')) + ->addColumn('tax_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tax Id') + ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Order Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Code') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Title') + ->addColumn('percent', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Percent') + ->addColumn('amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Amount') + ->addColumn('priority', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Priority') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Position') + ->addColumn('base_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Amount') + ->addColumn('process', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + ), 'Process') + ->addColumn('base_real_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + ), 'Base Real Amount') + ->addColumn('hidden', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Hidden') + ->addIndex($installer->getIdxName('sales/order_tax', array('order_id', 'priority', 'position')), + array('order_id', 'priority', 'position')) + ->setComment('Sales Order Tax Table'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_status' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_status')) + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'primary' => true, + ), 'Status') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array( + 'nullable' => false, + ), 'Label') + ->setComment('Sales Order Status Table'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_status_state' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_status_state')) + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'primary' => true, + ), 'Status') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'primary' => true, + ), 'Label') + ->addColumn('is_default', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Is Default') + ->addForeignKey($installer->getFkName('sales/order_status_state', 'status', 'sales/order_status', 'status'), + 'status', $installer->getTable('sales/order_status'), 'status', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Order Status Table'); +$installer->getConnection()->createTable($table); + + +/** + * Create table 'sales/order_status_label' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sales/order_status_label')) + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + 'primary' => true, + ), 'Status') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Store Id') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 128, array( + 'nullable' => false, + ), 'Label') + ->addIndex($installer->getIdxName('sales/order_status_label', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sales/order_status_label', 'status', 'sales/order_status', 'status'), + 'status', $installer->getTable('sales/order_status'), 'status', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('sales/order_status_label', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Sales Order Status Label Table'); +$installer->getConnection()->createTable($table); + + +/** + * Install eav entity types to the eav/entity_type table + */ +$installer->addEntityType('order', array( + 'entity_model' => 'sales/order', + 'table' => 'sales/order', + 'increment_model' => 'eav/entity_increment_numeric', + 'increment_per_store' => true +)); + +$installer->addEntityType('invoice', array( + 'entity_model' => 'sales/order_invoice', + 'table' => 'sales/invoice', + 'increment_model' => 'eav/entity_increment_numeric', + 'increment_per_store' => true +)); + +$installer->addEntityType('creditmemo', array( + 'entity_model' => 'sales/order_creditmemo', + 'table' => 'sales/creditmemo', + 'increment_model' => 'eav/entity_increment_numeric', + 'increment_per_store' => true +)); + +$installer->addEntityType('shipment', array( + 'entity_model' => 'sales/order_shipment', + 'table' => 'sales/shipment', + 'increment_model' => 'eav/entity_increment_numeric', + 'increment_per_store' => true +)); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.7.0.php index 986ea3ddf0..904c82ed6b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.8.11.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.8.11.php index cfb5389ae7..cbe1c071ee 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.8.11.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.8.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.9.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.9.0.php index 569f7c12af..3aeb3ad690 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.9.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-0.9.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-1.4.0.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-1.4.0.0.php index 04bc81fb11..30f3a3058b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-1.4.0.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-install-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.6.2-0.7.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.6.2-0.7.0.php index 2f1aa92d2b..8373eb02ea 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.6.2-0.7.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.6.2-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.0-0.7.1.php index 3e1126c776..17d407e5fc 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.1-0.7.2.php index 699a1d058a..ae2579cd28 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.2-0.7.3.php index 9973543e18..983dd6c476 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.9-0.7.10.php index 7fcfa9e0c2..e31409c06c 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.0-0.8.1.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.0-0.8.1.php index dfa93c9c62..8ed6efc812 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.0-0.8.1.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.0-0.8.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.1-0.8.2.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.1-0.8.2.php index e29aa89214..90709cf009 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.1-0.8.2.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.1-0.8.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.11-0.8.12.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.11-0.8.12.php index c50c3c88dd..f4e6633e8f 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.11-0.8.12.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.11-0.8.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.12-0.8.13.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.12-0.8.13.php index b31db00efe..95394181a3 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.12-0.8.13.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.12-0.8.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php index 5a04deccf7..d5435d7797 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.14-0.8.15.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.14-0.8.15.php index 451bb9ad36..20cfecbd06 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.14-0.8.15.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.14-0.8.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.15-0.8.16.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.15-0.8.16.php index a806eb57bb..0782b73e4f 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.15-0.8.16.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.15-0.8.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.16-0.8.17.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.16-0.8.17.php index 12efd4ed14..7ac80c6f94 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.16-0.8.17.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.16-0.8.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.17-0.8.18.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.17-0.8.18.php index 7b659f9e53..e8d8a62c1f 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.17-0.8.18.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.17-0.8.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.18-0.8.19.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.18-0.8.19.php index dac2192c1d..14e3322c26 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.18-0.8.19.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.18-0.8.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.19-0.8.20.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.19-0.8.20.php index 17ad9ce8f1..da4d4f86b7 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.19-0.8.20.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.19-0.8.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.2-0.8.3.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.2-0.8.3.php index 02e75ca90c..233c192b89 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.2-0.8.3.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.2-0.8.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.20-0.8.21.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.20-0.8.21.php index 145eb27c5d..dd2960644d 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.20-0.8.21.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.20-0.8.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.21-0.8.22.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.21-0.8.22.php index b4626d4466..f8ddde2e35 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.21-0.8.22.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.21-0.8.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.22-0.8.23.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.22-0.8.23.php index bf1b8e1280..4869254a45 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.22-0.8.23.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.22-0.8.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.23-0.8.24.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.23-0.8.24.php index 726ec69ec6..277452603e 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.23-0.8.24.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.23-0.8.24.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.24-0.8.25.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.24-0.8.25.php index 21443e9a14..a2432c087c 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.24-0.8.25.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.24-0.8.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.25-0.8.26.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.25-0.8.26.php index 6b61b6926c..203c861140 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.25-0.8.26.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.25-0.8.26.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.26-0.8.27.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.26-0.8.27.php index 7355ba48f3..38dc933790 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.26-0.8.27.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.26-0.8.27.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.27-0.8.28.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.27-0.8.28.php index 1558911fc7..74705ccf0e 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.27-0.8.28.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.27-0.8.28.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.28-0.8.29.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.28-0.8.29.php index 8faf83b0f6..e8b0e0400b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.28-0.8.29.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.28-0.8.29.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.29-0.9.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.29-0.9.0.php index 8733eb2257..6b7ea8294b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.29-0.9.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.29-0.9.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.3-0.8.4.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.3-0.8.4.php index 0de9508f60..92c14742e8 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.3-0.8.4.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.3-0.8.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.6-0.8.7.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.6-0.8.7.php index 02e75ca90c..233c192b89 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.6-0.8.7.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.6-0.8.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.7-0.8.8.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.7-0.8.8.php index 0ced576b6b..8aa1f006c0 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.7-0.8.8.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.7-0.8.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.8-0.8.9.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.8-0.8.9.php index 65527563aa..7119292bb3 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.8-0.8.9.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.8-0.8.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = $this; diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.0-0.9.1.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.0-0.9.1.php index c7e2eb7224..93dc06bfd2 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.0-0.9.1.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.0-0.9.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.1-0.9.2.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.1-0.9.2.php index 94f5221598..99347057f4 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.1-0.9.2.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.1-0.9.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.10-0.9.11.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.10-0.9.11.php index df66092f13..ca485ff1e2 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.10-0.9.11.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.10-0.9.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.11-0.9.12.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.11-0.9.12.php index 396f730c65..da73b325c2 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.11-0.9.12.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.11-0.9.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php index 56f32ae5f1..1eb501a12a 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.13-0.9.14.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.13-0.9.14.php index 7feb5f0d41..4584800fce 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.13-0.9.14.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.13-0.9.14.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.14-0.9.15.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.14-0.9.15.php index 7483baf227..f6a24ab027 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.14-0.9.15.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.14-0.9.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.15-0.9.16.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.15-0.9.16.php index f33018f6a5..8b9bf8fa30 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.15-0.9.16.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.15-0.9.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php index ac37d1c8a6..4e5bf60880 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.17-0.9.18.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.17-0.9.18.php index 507e8e536a..24b69f89eb 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.17-0.9.18.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.17-0.9.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.18-0.9.19.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.18-0.9.19.php index c99152973b..4e8c94d17c 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.18-0.9.19.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.18-0.9.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.19-0.9.20.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.19-0.9.20.php index e87fce6c08..4de229f669 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.19-0.9.20.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.19-0.9.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.2-0.9.3.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.2-0.9.3.php index 956bdade3c..3d4b673816 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.2-0.9.3.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.2-0.9.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.20-0.9.21.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.20-0.9.21.php index 8db3dc817f..e452b05971 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.20-0.9.21.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.20-0.9.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.21-0.9.22.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.21-0.9.22.php index f2cac246a0..ce90b73072 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.21-0.9.22.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.21-0.9.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.22-0.9.23.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.22-0.9.23.php index 889c2642a5..00abc56230 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.22-0.9.23.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.22-0.9.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.23-0.9.24.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.23-0.9.24.php index dac1670619..a766648b9e 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.23-0.9.24.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.23-0.9.24.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.24-0.9.25.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.24-0.9.25.php index 427d63ece1..4565c00aca 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.24-0.9.25.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.24-0.9.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.25-0.9.26.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.25-0.9.26.php index 3e7b878b15..c0ae895cea 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.25-0.9.26.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.25-0.9.26.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.26-0.9.27.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.26-0.9.27.php index af175892a5..7631192c69 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.26-0.9.27.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.26-0.9.27.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.27-0.9.28.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.27-0.9.28.php index 4b4186e28f..ba5860d4db 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.27-0.9.28.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.27-0.9.28.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php index 430e796081..8c6afb8906 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.29-0.9.30.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.29-0.9.30.php index 8ed4bc4378..92c3d3c7ad 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.29-0.9.30.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.29-0.9.30.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.3-0.9.4.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.3-0.9.4.php index 42f0c6f41f..2acb8c2a25 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.3-0.9.4.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.3-0.9.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.30-0.9.31.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.30-0.9.31.php index 271ec30dde..be2805e2be 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.30-0.9.31.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.30-0.9.31.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.31-0.9.32.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.31-0.9.32.php index ddb93dbf0d..41018f0d45 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.31-0.9.32.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.31-0.9.32.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.32-0.9.33.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.32-0.9.33.php index d0ae0e9ebe..e48308c0e8 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.32-0.9.33.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.32-0.9.33.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.33-0.9.34.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.33-0.9.34.php index 5a4d4e592b..729760a431 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.33-0.9.34.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.33-0.9.34.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.34-0.9.35.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.34-0.9.35.php index 1d2d3cfb51..950068647d 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.34-0.9.35.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.34-0.9.35.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.35-0.9.36.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.35-0.9.36.php index f90d5ab293..d72ff1c3be 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.35-0.9.36.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.35-0.9.36.php @@ -20,15 +20,10 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /* @var $installer Mage_Sales_Model_Mysql4_Setup */ $installer = $this; -$installer->startSetup(); - -$installer->addAttribute('order', 'forced_do_shipment_with_invoice', array('type'=>'int', 'default' => 0)); - -$installer->endSetup(); diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.36-0.9.37.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.36-0.9.37.php index 35eebbf75a..bc9d64e1d2 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.36-0.9.37.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.36-0.9.37.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.37-0.9.38.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.37-0.9.38.php index bc586ad7db..c277591b29 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.37-0.9.38.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.37-0.9.38.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.38-0.9.39.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.38-0.9.39.php index d6122353f7..d548f59b16 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.38-0.9.39.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.38-0.9.39.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.39-0.9.40.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.39-0.9.40.php index ec254a25ef..d98f53e8e0 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.39-0.9.40.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.39-0.9.40.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.4-0.9.5.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.4-0.9.5.php index 9cfff382fe..5e99299036 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.4-0.9.5.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.4-0.9.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.40-0.9.41.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.40-0.9.41.php index abc8601bd4..76e2765253 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.40-0.9.41.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.40-0.9.41.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.41-0.9.42.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.41-0.9.42.php index 5272c9fce1..b5e06a1b9f 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.41-0.9.42.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.41-0.9.42.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.42-0.9.43.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.42-0.9.43.php index cc97543451..c9ace5506e 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.42-0.9.43.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.42-0.9.43.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.43-0.9.44.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.43-0.9.44.php index 3543c4b5f4..a2016447cc 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.43-0.9.44.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.43-0.9.44.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.44-0.9.45.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.44-0.9.45.php index 15094e7548..88ae83b32d 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.44-0.9.45.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.44-0.9.45.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php index a5903cb911..e7e216c67e 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php index f395b07857..7298a0214c 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.47-0.9.48.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.47-0.9.48.php index 951a17ee25..e238efbf85 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.47-0.9.48.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.47-0.9.48.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.48-0.9.49.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.48-0.9.49.php index 2452fc16bb..925e61de39 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.48-0.9.49.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.48-0.9.49.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.49-0.9.50.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.49-0.9.50.php index 68b5d9ee77..35fd149ad4 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.49-0.9.50.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.49-0.9.50.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.5-0.9.6.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.5-0.9.6.php index 5758840334..bbef9b53dc 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.5-0.9.6.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.5-0.9.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php index bf8bd0e579..7f760226b0 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.51-0.9.52.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.51-0.9.52.php index 897a7c50e8..08ff1780f0 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.51-0.9.52.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.51-0.9.52.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.52-0.9.53.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.52-0.9.53.php index b993da82b7..9fce796aa7 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.52-0.9.53.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.52-0.9.53.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.53-0.9.54.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.53-0.9.54.php index ab901e37e6..0f8d88de57 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.53-0.9.54.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.53-0.9.54.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.54-0.9.55.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.54-0.9.55.php index feb1cd0456..cecd4d163b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.54-0.9.55.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.54-0.9.55.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.55-0.9.56.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.55-0.9.56.php index 82a763d2d2..66abf86827 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.55-0.9.56.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.55-0.9.56.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.6-0.9.7.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.6-0.9.7.php index 009aef7ef7..536d155e60 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.6-0.9.7.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.6-0.9.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.7-0.9.8.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.7-0.9.8.php index 7230cf02d2..ed0bd3ee45 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.7-0.9.8.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.7-0.9.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.8-0.9.9.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.8-0.9.9.php index 0065da865e..bc532d92c6 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.8-0.9.9.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.8-0.9.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.9-0.9.10.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.9-0.9.10.php index 98e257625c..1d2a4ff6a8 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.9-0.9.10.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.9-0.9.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php index 777b7efb0c..daca9b0a84 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1146,7 +1146,7 @@ * The problem is that Mage_SalesRule depends on Mage_Sales and sometimes the attribute doesn't get updated before this line of code. * As a result: an existing column in the sales_flat_order table, but wrong type in the attribute registry and sometimes even data lost * Reproduces on upgrading from 1.4.0.x to 1.4.1.0 - * + * * Test case: * 1) Have Magento instance without flat sales yet, and without Mage_SalesRule/sql/mysql4-upgrade-0.7.10-0.7.11.php * 2) Upgrade it to the flat one instantly (runs this upgrade). Without this code the proper upgrade of coupon_code is missed. Data is lost. @@ -1201,4 +1201,63 @@ ); } + +/* Add columns to tables */ +$tableData = array( + 'sales/quote_item' => array( + 'price_incl_tax' => 'decimal', + 'base_price_incl_tax' => 'decimal', + 'row_total_incl_tax' => 'decimal', + 'base_row_total_incl_tax' => 'decimal' + ), + 'sales/order_item' => array( + 'price_incl_tax' => 'decimal', + 'base_price_incl_tax' => 'decimal', + 'row_total_incl_tax' => 'decimal', + 'base_row_total_incl_tax' => 'decimal' + ), + 'sales/quote_address' => array( + 'shipping_discount_amount' => 'decimal', + 'base_shipping_discount_amount' => 'decimal', + 'subtotal_incl_tax' => 'decimal', + 'base_subtotal_total_incl_tax' => 'decimal', + 'discount_description' => 'varchar' + ), + 'sales/quote_address_item' => array( + 'product_id' => 'int', + 'super_product_id' => 'int', + 'parent_product_id' => 'int', + 'sku' => 'varchar', + 'image' => 'varchar', + 'name' => 'varchar', + 'description' => 'text', + 'free_shipping' => 'int', + 'is_qty_decimal' => 'int', + 'price' => 'decimal', + 'discount_percent' => 'decimal', + 'no_discount' => 'int', + 'tax_percent' => 'decimal', + 'base_price' => 'decimal', + 'price_incl_tax' => 'decimal', + 'base_price_incl_tax' => 'decimal', + 'row_total_incl_tax' => 'decimal', + 'base_row_total_incl_tax' => 'decimal' + ), + 'sales/quote_payment' => array( + 'additional_data' => 'text', + 'cc_ss_issue' => 'varchar' + ), + 'sales/quote_address_shipping_rate' => array( + 'error_message' => 'text' + ) +); + +foreach ($tableData as $table => $columns) { + foreach ($columns as $columnName => $columnType) { + $installer->getConnection()->addColumn( + $installer->getTable($table), $columnName, $definitions[$columnType] + ); + } +} + $installer->endSetup(); diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php index c6d83e9243..ea5ebedaf9 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php index b720b38e82..ed98946eb2 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.15-1.4.0.16.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.15-1.4.0.16.php index 6f1d7614a8..be4daabef7 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.15-1.4.0.16.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.15-1.4.0.16.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.16-1.4.0.17.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.16-1.4.0.17.php index 300b812499..e5f8201871 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.16-1.4.0.17.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.16-1.4.0.17.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.17-1.4.0.18.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.17-1.4.0.18.php index e749322256..94cd413a27 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.17-1.4.0.18.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.17-1.4.0.18.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.18-1.4.0.19.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.18-1.4.0.19.php index 2f350067c5..1766ca5a3a 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.18-1.4.0.19.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.18-1.4.0.19.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.19-1.4.0.20.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.19-1.4.0.20.php index 09d8a91fc9..c87473b56a 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.19-1.4.0.20.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.19-1.4.0.20.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php index 7d174d9c5f..026045fa2d 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.20-1.4.0.21.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.20-1.4.0.21.php index f8c59acd2a..f198c75eac 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.20-1.4.0.21.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.20-1.4.0.21.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php index 7c16325469..e6ae0d7d9f 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.22-1.4.0.23.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.22-1.4.0.23.php index 24a90f0242..86e0757661 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.22-1.4.0.23.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.22-1.4.0.23.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php index 674531c768..bc737d36e6 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php @@ -20,11 +20,11 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /* @var $installer Mage_Sales_Model_Entity_Setup */ $installer = $this; -$installer->getConnection()->addColumn($installer->getTable('sales_flat_invoice'), +$installer->getConnection()->addColumn($installer->getTable('sales/invoice'), 'base_total_refunded', 'decimal(12,4) default NULL'); diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.24-1.4.0.25.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.24-1.4.0.25.php index 310453d483..43984549f4 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.24-1.4.0.25.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.24-1.4.0.25.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /* @var $installer Mage_Sales_Model_Entity_Setup */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.3-1.4.0.4.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.3-1.4.0.4.php index 21d994331a..841400246b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.3-1.4.0.4.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.3-1.4.0.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.4-1.4.0.5.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.4-1.4.0.5.php index 15d06a5626..c8a2ccd35c 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.4-1.4.0.5.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.4-1.4.0.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.5-1.4.0.6.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.5-1.4.0.6.php index 2214affa76..bb2ece782b 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.5-1.4.0.6.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.5-1.4.0.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.6-1.4.0.7.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.6-1.4.0.7.php index 4c5dbb71d7..96937171bc 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.6-1.4.0.7.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.6-1.4.0.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.7-1.4.0.8.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.7-1.4.0.8.php index c6d432e421..252c464230 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.7-1.4.0.8.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.7-1.4.0.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.8-1.4.0.15.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.8-1.4.0.15.php index cd982674f1..c4ab9310ab 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.8-1.4.0.15.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.8-1.4.0.15.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sales - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..f4b6d9c54e --- /dev/null +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,8276 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'FK_PRODUCT_ORDERED_AGGREGATED_DAILY_PRODUCT_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'FK_PRODUCT_ORDERED_AGGREGATED_DAILY_STORE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'FK_PRODUCT_ORDERED_AGGREGATED_MONTHLY_PRODUCT_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'FK_PRODUCT_ORDERED_AGGREGATED_MONTHLY_STORE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'FK_PRODUCT_ORDERED_AGGREGATED_YEARLY_PRODUCT_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'FK_PRODUCT_ORDERED_AGGREGATED_YEARLY_STORE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/billing_agreement'), + 'FK_BILLING_AGREEMENT_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/billing_agreement'), + 'FK_BILLING_AGREEMENT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/billing_agreement_order'), + 'FK_BILLING_AGREEMENT_ORDER_AGREEMENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/billing_agreement_order'), + 'FK_BILLING_AGREEMENT_ORDER_ORDER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo'), + 'FK_SALES_FLAT_CREDITMEMO_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo'), + 'FK_SALES_FLAT_CREDITMEMO_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo_comment'), + 'FK_SALES_FLAT_CREDITMEMO_COMMENT_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo_grid'), + 'FK_SALES_FLAT_CREDITMEMO_GRID_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo_grid'), + 'FK_SALES_FLAT_CREDITMEMO_GRID_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/creditmemo_item'), + 'FK_SALES_FLAT_CREDITMEMO_ITEM_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice'), + 'FK_SALES_FLAT_INVOICE_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice'), + 'FK_SALES_FLAT_INVOICE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice_comment'), + 'FK_SALES_FLAT_INVOICE_COMMENT_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice_grid'), + 'FK_SALES_FLAT_INVOICE_GRID_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice_grid'), + 'FK_SALES_FLAT_INVOICE_GRID_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoice_item'), + 'FK_SALES_FLAT_INVOICE_ITEM_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order'), + 'FK_SALES_FLAT_ORDER_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order'), + 'FK_SALES_FLAT_ORDER_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_address'), + 'FK_SALES_FLAT_ORDER_ADDRESS_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_grid'), + 'FK_SALES_FLAT_ORDER_GRID_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_grid'), + 'FK_SALES_FLAT_ORDER_GRID_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_grid'), + 'FK_SALES_FLAT_ORDER_GRID_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_item'), + 'FK_SALES_FLAT_ORDER_ITEM_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_item'), + 'FK_SALES_FLAT_ORDER_ITEM_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_payment'), + 'FK_SALES_FLAT_ORDER_PAYMENT_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_status_history'), + 'FK_SALES_FLAT_ORDER_STATUS_HISTORY_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote'), + 'FK_SALES_QUOTE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_address'), + 'FK_SALES_QUOTE_ADDRESS_SALES_QUOTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_address_item'), + 'FK_QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_address_item'), + 'FK_SALES_FLAT_QUOTE_ADDRESS_ITEM_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_address_item'), + 'FK_SALES_QUOTE_ADDRESS_ITEM_QUOTE_ITEM' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_item'), + 'FK_SALES_FLAT_QUOTE_ITEM_PARENT_ITEM' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_CATALOG_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_SALES_QUOTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_item_option'), + 'FK_SALES_QUOTE_ITEM_OPTION_ITEM_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_payment'), + 'FK_SALES_QUOTE_PAYMENT_SALES_QUOTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/quote_address_shipping_rate'), + 'FK_SALES_QUOTE_SHIPPING_RATE_ADDRESS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment'), + 'FK_SALES_FLAT_SHIPMENT_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment'), + 'FK_SALES_FLAT_SHIPMENT_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment_comment'), + 'FK_SALES_FLAT_SHIPMENT_COMMENT_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment_grid'), + 'FK_SALES_FLAT_SHIPMENT_GRID_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment_grid'), + 'FK_SALES_FLAT_SHIPMENT_GRID_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment_item'), + 'FK_SALES_FLAT_SHIPMENT_ITEM_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipment_track'), + 'FK_SALES_FLAT_SHIPMENT_TRACK_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoiced_aggregated'), + 'FK_SALES_INVOICED_AGGREGATED_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/invoiced_aggregated_order'), + 'FK_SALES_INVOICED_AGGREGATED_ORDER_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_aggregated_created'), + 'FK_SALES_ORDER_AGGREGATED_CREATED' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_status_label'), + 'FK_SALES_ORDER_STATUS_LABEL_STATUS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_status_label'), + 'FK_SALES_ORDER_STATUS_LABEL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_status_state'), + 'FK_SALES_ORDER_STATUS_STATE_STATUS' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/order_tax'), + 'FK_SALES_ORDER_TAX_ORDER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/payment_transaction'), + 'FK_SALES_PAYMENT_TRANSACTION_ORDER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/payment_transaction'), + 'FK_SALES_PAYMENT_TRANSACTION_PARENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/payment_transaction'), + 'FK_SALES_PAYMENT_TRANSACTION_PAYMENT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/recurring_profile'), + 'FK_RECURRING_PROFILE_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/recurring_profile'), + 'FK_RECURRING_PROFILE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/recurring_profile_order'), + 'FK_RECURRING_PROFILE_ORDER_ORDER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/recurring_profile_order'), + 'FK_RECURRING_PROFILE_ORDER_PROFILE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/refunded_aggregated'), + 'FK_SALES_REFUNDED_AGGREGATED_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/refunded_aggregated_order'), + 'FK_SALES_REFUNDED_AGGREGATED_ORDER_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipping_aggregated'), + 'FK_SALES_SHIPPING_AGGREGATED_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('sales/shipping_aggregated_order'), + 'FK_SALES_SHIPPING_AGGREGATED_ORDER_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'UNQ_PERIOD_STORE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'IDX_PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'UNQ_PERIOD_STORE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'IDX_PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'UNQ_PERIOD_STORE_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'IDX_PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/billing_agreement'), + 'IDX_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/billing_agreement'), + 'FK_BILLING_AGREEMENT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/billing_agreement_order'), + 'UNQ_BILLING_AGREEMENT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/billing_agreement_order'), + 'FK_BILLING_AGREEMENT_ORDER_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'IDX_CREDITMEMO_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'IDX_STATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_comment'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_comment'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_BASE_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_CREDITMEMO_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_STATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_ORDER_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_ORDER_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_grid'), + 'IDX_BILLING_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/creditmemo_item'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'IDX_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'IDX_STATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_comment'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_comment'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_STATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_ORDER_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_ORDER_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_grid'), + 'IDX_BILLING_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoice_item'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_STATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_CUSTOMER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_EXT_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_UPDATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order'), + 'IDX_QUOTE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_address'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_BASE_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_BASE_TOTAL_PAID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_GRAND_TOTAL' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_TOTAL_PAID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_SHIPPING_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_BILLING_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_CUSTOMER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_grid'), + 'IDX_UPDATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_item'), + 'IDX_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_item'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_item'), + 'IDX_PRODUCT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_payment'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_status_history'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_status_history'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote'), + 'FK_SALES_QUOTE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote'), + 'IDX_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote'), + 'IDX_IS_ACTIVE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_address'), + 'FK_SALES_QUOTE_ADDRESS_SALES_QUOTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_address_item'), + 'FK_QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_address_item'), + 'FK_SALES_QUOTE_ADDRESS_ITEM_QUOTE_ITEM' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_address_item'), + 'FK_SALES_FLAT_QUOTE_ADDRESS_ITEM_PARENT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_SALES_QUOTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_item'), + 'FK_SALES_FLAT_QUOTE_ITEM_PARENT_ITEM' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_CATALOG_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_item'), + 'FK_SALES_QUOTE_ITEM_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_item_option'), + 'FK_SALES_QUOTE_ITEM_OPTION_ITEM_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_payment'), + 'FK_SALES_QUOTE_PAYMENT_SALES_QUOTE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/quote_address_shipping_rate'), + 'FK_SALES_QUOTE_SHIPPING_RATE_ADDRESS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'IDX_TOTAL_QTY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment'), + 'IDX_UPDATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_comment'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_comment'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'UNQ_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_TOTAL_QTY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_SHIPMENT_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_ORDER_INCREMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_ORDER_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_grid'), + 'IDX_SHIPPING_NAME' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_item'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_track'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_track'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipment_track'), + 'IDX_CREATED_AT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoiced_aggregated'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoiced_aggregated'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoiced_aggregated_order'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/invoiced_aggregated_order'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_aggregated_created'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_aggregated_created'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_status_label'), + 'FK_SALES_ORDER_STATUS_LABEL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/order_tax'), + 'IDX_ORDER_TAX' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/payment_transaction'), + 'UNQ_ORDER_PAYMENT_TXN' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/payment_transaction'), + 'IDX_ORDER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/payment_transaction'), + 'IDX_PARENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/payment_transaction'), + 'IDX_PAYMENT_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/recurring_profile'), + 'UNQ_INTERNAL_REF_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/recurring_profile'), + 'IDX_RECURRING_PROFILE_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/recurring_profile'), + 'IDX_RECURRING_PROFILE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/recurring_profile_order'), + 'UNQ_PROFILE_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/recurring_profile_order'), + 'IDX_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/refunded_aggregated'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/refunded_aggregated'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/refunded_aggregated_order'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/refunded_aggregated_order'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipping_aggregated'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipping_aggregated'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipping_aggregated_order'), + 'UNQ_PERIOD_STORE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sales/shipping_aggregated_order'), + 'IDX_STORE_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('sales/quote') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'converted_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Converted At' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '1', + 'comment' => 'Is Active' + ), + 'is_virtual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Is Virtual' + ), + 'is_multi_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Is Multi Shipping' + ), + 'items_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Items Count' + ), + 'items_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Items Qty' + ), + 'orig_order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Orig Order Id' + ), + 'store_to_base_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Store To Base Rate' + ), + 'store_to_quote_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Store To Quote Rate' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Base Currency Code' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Store Currency Code' + ), + 'quote_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Quote Currency Code' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Grand Total' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Grand Total' + ), + 'checkout_method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Checkout Method' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer Id' + ), + 'customer_tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer Tax Class Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer Group Id' + ), + 'customer_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Email' + ), + 'customer_prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Customer Prefix' + ), + 'customer_firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Firstname' + ), + 'customer_middlename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Customer Middlename' + ), + 'customer_lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Lastname' + ), + 'customer_suffix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Customer Suffix' + ), + 'customer_dob' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Customer Dob' + ), + 'customer_note' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Note' + ), + 'customer_note_notify' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '1', + 'comment' => 'Customer Note Notify' + ), + 'customer_is_guest' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Customer Is Guest' + ), + 'remote_ip' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Remote Ip' + ), + 'applied_rule_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Applied Rule Ids' + ), + 'reserved_order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 64, + 'comment' => 'Reserved Order Id' + ), + 'password_hash' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Password Hash' + ), + 'coupon_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Coupon Code' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Global Currency Code' + ), + 'base_to_global_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Global Rate' + ), + 'base_to_quote_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Quote Rate' + ), + 'customer_taxvat' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Taxvat' + ), + 'customer_gender' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Gender' + ), + 'subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal' + ), + 'base_subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal' + ), + 'subtotal_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal With Discount' + ), + 'base_subtotal_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal With Discount' + ), + 'is_changed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Is Changed' + ), + 'trigger_recollect' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'comment' => 'Trigger Recollect' + ), + 'ext_shipping_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Ext Shipping Info' + ) + ), + 'comment' => 'Sales Flat Quote' + ), + $installer->getTable('sales/quote_item') => array( + 'columns' => array( + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Item Id' + ), + 'quote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Quote Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'parent_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Item Id' + ), + 'is_virtual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Virtual' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'applied_rule_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Applied Rule Ids' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'free_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Free Shipping' + ), + 'is_qty_decimal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Qty Decimal' + ), + 'no_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'No Discount' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Weight' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'base_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Price' + ), + 'custom_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Custom Price' + ), + 'discount_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Percent' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Discount Amount' + ), + 'tax_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Percent' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Amount' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Tax Amount' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Row Total' + ), + 'base_row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Row Total' + ), + 'row_total_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Row Total With Discount' + ), + 'row_weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Row Weight' + ), + 'product_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product Type' + ), + 'base_tax_before_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Before Discount' + ), + 'tax_before_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Before Discount' + ), + 'original_custom_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Original Custom Price' + ), + 'redirect_url' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Redirect Url' + ), + 'base_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Cost' + ), + 'price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price Incl Tax' + ), + 'base_price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price Incl Tax' + ), + 'row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total Incl Tax' + ), + 'base_row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total Incl Tax' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ) + ), + 'comment' => 'Sales Flat Quote Item' + ), + $installer->getTable('sales/quote_address') => array( + 'columns' => array( + 'address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Address Id' + ), + 'quote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Quote Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'save_in_address_book' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'default' => '0', + 'comment' => 'Save In Address Book' + ), + 'customer_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Address Id' + ), + 'address_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Address Type' + ), + 'email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Email' + ), + 'prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Prefix' + ), + 'firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Firstname' + ), + 'middlename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Middlename' + ), + 'lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Lastname' + ), + 'suffix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 40, + 'comment' => 'Suffix' + ), + 'company' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Company' + ), + 'street' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Street' + ), + 'city' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'City' + ), + 'region' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Region' + ), + 'region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Region Id' + ), + 'postcode' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Postcode' + ), + 'country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Country Id' + ), + 'telephone' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Telephone' + ), + 'fax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Fax' + ), + 'same_as_billing' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Same As Billing' + ), + 'free_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Free Shipping' + ), + 'collect_shipping_rates' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Collect Shipping Rates' + ), + 'shipping_method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Method' + ), + 'shipping_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Description' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Weight' + ), + 'subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Subtotal' + ), + 'base_subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Subtotal' + ), + 'subtotal_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Subtotal With Discount' + ), + 'base_subtotal_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Subtotal With Discount' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Tax Amount' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Tax Amount' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Shipping Amount' + ), + 'base_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Shipping Amount' + ), + 'shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Tax Amount' + ), + 'base_shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Tax Amount' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Discount Amount' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Grand Total' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Grand Total' + ), + 'customer_notes' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Customer Notes' + ), + 'applied_taxes' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Applied Taxes' + ), + 'discount_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Discount Description' + ), + 'shipping_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Discount Amount' + ), + 'base_shipping_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Discount Amount' + ), + 'subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Incl Tax' + ), + 'base_subtotal_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Total Incl Tax' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ), + 'shipping_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Hidden Tax Amount' + ), + 'shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Incl Tax' + ), + 'base_shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Incl Tax' + ) + ), + 'comment' => 'Sales Flat Quote Address' + ), + $installer->getTable('sales/quote_address_item') => array( + 'columns' => array( + 'address_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Address Item Id' + ), + 'parent_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Item Id' + ), + 'quote_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Quote Address Id' + ), + 'quote_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Quote Item Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'applied_rule_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Applied Rule Ids' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Weight' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Amount' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Row Total' + ), + 'base_row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Row Total' + ), + 'row_total_with_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Row Total With Discount' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Discount Amount' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Tax Amount' + ), + 'row_weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Row Weight' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'super_product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Super Product Id' + ), + 'parent_product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Product Id' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ), + 'image' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Image' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'free_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Free Shipping' + ), + 'is_qty_decimal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Is Qty Decimal' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'discount_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Percent' + ), + 'no_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'No Discount' + ), + 'tax_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Percent' + ), + 'base_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price' + ), + 'base_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Cost' + ), + 'price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price Incl Tax' + ), + 'base_price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price Incl Tax' + ), + 'row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total Incl Tax' + ), + 'base_row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total Incl Tax' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ) + ), + 'comment' => 'Sales Flat Quote Address Item' + ), + $installer->getTable('sales/quote_item_option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Id' + ), + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Item Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Code' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Value' + ) + ), + 'comment' => 'Sales Flat Quote Item Option' + ), + $installer->getTable('sales/quote_payment') => array( + 'columns' => array( + 'payment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Payment Id' + ), + 'quote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Quote Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Method' + ), + 'cc_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Type' + ), + 'cc_number_enc' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Number Enc' + ), + 'cc_last4' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Last4' + ), + 'cc_cid_enc' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Cid Enc' + ), + 'cc_owner' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Owner' + ), + 'cc_exp_month' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Cc Exp Month' + ), + 'cc_exp_year' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Cc Exp Year' + ), + 'cc_ss_owner' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Ss Owner' + ), + 'cc_ss_start_month' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Cc Ss Start Month' + ), + 'cc_ss_start_year' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Cc Ss Start Year' + ), + 'cybersource_token' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cybersource Token' + ), + 'paypal_correlation_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Paypal Correlation Id' + ), + 'paypal_payer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Paypal Payer Id' + ), + 'paypal_payer_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Paypal Payer Status' + ), + 'po_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Po Number' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'cc_ss_issue' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Ss Issue' + ), + 'additional_information' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Information' + ), + 'ideal_issuer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ideal Issuer Id' + ), + 'ideal_issuer_list' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Ideal Issuer List' + ) + ), + 'comment' => 'Sales Flat Quote Payment' + ), + $installer->getTable('sales/quote_address_shipping_rate') => array( + 'columns' => array( + 'rate_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rate Id' + ), + 'address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Address Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'carrier' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Carrier' + ), + 'carrier_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Carrier Title' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Code' + ), + 'method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Method' + ), + 'method_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Method Description' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'error_message' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Error Message' + ), + 'method_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Method Title' + ) + ), + 'comment' => 'Sales Flat Quote Shipping Rate' + ), + $installer->getTable('sales/order') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'State' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Status' + ), + 'coupon_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Coupon Code' + ), + 'protect_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Protect Code' + ), + 'shipping_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Description' + ), + 'is_virtual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Virtual' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Amount' + ), + 'base_discount_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Canceled' + ), + 'base_discount_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Invoiced' + ), + 'base_discount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Refunded' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'base_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Amount' + ), + 'base_shipping_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Canceled' + ), + 'base_shipping_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Invoiced' + ), + 'base_shipping_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Refunded' + ), + 'base_shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Tax Amount' + ), + 'base_shipping_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Tax Refunded' + ), + 'base_subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal' + ), + 'base_subtotal_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Canceled' + ), + 'base_subtotal_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Invoiced' + ), + 'base_subtotal_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Refunded' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Amount' + ), + 'base_tax_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Canceled' + ), + 'base_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Invoiced' + ), + 'base_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Refunded' + ), + 'base_to_global_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Global Rate' + ), + 'base_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Order Rate' + ), + 'base_total_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Canceled' + ), + 'base_total_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Invoiced' + ), + 'base_total_invoiced_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Invoiced Cost' + ), + 'base_total_offline_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Offline Refunded' + ), + 'base_total_online_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Online Refunded' + ), + 'base_total_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Paid' + ), + 'base_total_qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Qty Ordered' + ), + 'base_total_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Refunded' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Amount' + ), + 'discount_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Canceled' + ), + 'discount_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Invoiced' + ), + 'discount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Refunded' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Amount' + ), + 'shipping_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Canceled' + ), + 'shipping_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Invoiced' + ), + 'shipping_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Refunded' + ), + 'shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Tax Amount' + ), + 'shipping_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Tax Refunded' + ), + 'store_to_base_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Base Rate' + ), + 'store_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Order Rate' + ), + 'subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal' + ), + 'subtotal_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Canceled' + ), + 'subtotal_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Invoiced' + ), + 'subtotal_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Refunded' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'tax_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Canceled' + ), + 'tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Invoiced' + ), + 'tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Refunded' + ), + 'total_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Canceled' + ), + 'total_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Invoiced' + ), + 'total_offline_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Offline Refunded' + ), + 'total_online_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Online Refunded' + ), + 'total_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Paid' + ), + 'total_qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Qty Ordered' + ), + 'total_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Refunded' + ), + 'can_ship_partially' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Can Ship Partially' + ), + 'can_ship_partially_item' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Can Ship Partially Item' + ), + 'customer_is_guest' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Customer Is Guest' + ), + 'customer_note_notify' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Customer Note Notify' + ), + 'billing_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Billing Address Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'comment' => 'Customer Group Id' + ), + 'edit_increment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Edit Increment' + ), + 'email_sent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Email Sent' + ), + 'paypal_ipn_customer_notified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Paypal Ipn Customer Notified' + ), + 'quote_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Quote Address Id' + ), + 'quote_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Quote Id' + ), + 'shipping_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipping Address Id' + ), + 'adjustment_negative' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Adjustment Negative' + ), + 'adjustment_positive' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Adjustment Positive' + ), + 'base_adjustment_negative' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Adjustment Negative' + ), + 'base_adjustment_positive' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Adjustment Positive' + ), + 'base_shipping_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Discount Amount' + ), + 'base_subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Incl Tax' + ), + 'base_total_due' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Due' + ), + 'payment_authorization_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Payment Authorization Amount' + ), + 'shipping_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Discount Amount' + ), + 'subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Incl Tax' + ), + 'total_due' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Due' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weight' + ), + 'customer_dob' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Customer Dob' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'applied_rule_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Applied Rule Ids' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'customer_email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Email' + ), + 'customer_firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Firstname' + ), + 'customer_lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Lastname' + ), + 'customer_middlename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Middlename' + ), + 'customer_prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Prefix' + ), + 'customer_suffix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Suffix' + ), + 'customer_taxvat' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Customer Taxvat' + ), + 'discount_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Discount Description' + ), + 'ext_customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ext Customer Id' + ), + 'ext_order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ext Order Id' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Global Currency Code' + ), + 'hold_before_state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Hold Before State' + ), + 'hold_before_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Hold Before Status' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Order Currency Code' + ), + 'original_increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Original Increment Id' + ), + 'relation_child_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Relation Child Id' + ), + 'relation_child_real_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Relation Child Real Id' + ), + 'relation_parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Relation Parent Id' + ), + 'relation_parent_real_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Relation Parent Real Id' + ), + 'remote_ip' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Remote Ip' + ), + 'shipping_method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Method' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Store Currency Code' + ), + 'store_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Store Name' + ), + 'x_forwarded_for' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'X Forwarded For' + ), + 'customer_note' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Customer Note' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ), + 'total_item_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Total Item Count' + ), + 'customer_gender' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Customer Gender' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ), + 'shipping_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Hidden Tax Amount' + ), + /* TODO: remove comment + 'base_shipping_hidden_tax_amnt' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ), + */ + 'hidden_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Invoiced' + ), + 'base_hidden_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Invoiced' + ), + 'hidden_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Refunded' + ), + 'base_hidden_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Refunded' + ), + 'shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Incl Tax' + ), + 'base_shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Incl Tax' + ) + ), + 'comment' => 'Sales Flat Order' + ), + $installer->getTable('sales/order_grid') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Status' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'store_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Store Name' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'base_total_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Paid' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'total_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Paid' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Order Currency Code' + ), + 'shipping_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Name' + ), + 'billing_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Billing Name' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ) + ), + 'comment' => 'Sales Flat Order Grid' + ), + $installer->getTable('sales/order_item') => array( + 'columns' => array( + 'item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Item Id' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'parent_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Item Id' + ), + 'quote_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Quote Item Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Updated At' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'product_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product Type' + ), + 'product_options' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Product Options' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Weight' + ), + 'is_virtual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Virtual' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'applied_rule_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Applied Rule Ids' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'free_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Free Shipping' + ), + 'is_qty_decimal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Qty Decimal' + ), + 'no_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'No Discount' + ), + 'qty_backordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Backordered' + ), + 'qty_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Canceled' + ), + 'qty_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Invoiced' + ), + 'qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Ordered' + ), + 'qty_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Refunded' + ), + 'qty_shipped' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Qty Shipped' + ), + 'base_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Cost' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'base_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Price' + ), + 'original_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Original Price' + ), + 'base_original_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Original Price' + ), + 'tax_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Percent' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Amount' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Tax Amount' + ), + 'tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Tax Invoiced' + ), + 'base_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Tax Invoiced' + ), + 'discount_percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Percent' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Discount Amount' + ), + 'discount_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Discount Invoiced' + ), + 'base_discount_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Discount Invoiced' + ), + 'amount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Amount Refunded' + ), + 'base_amount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Base Amount Refunded' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Row Total' + ), + 'base_row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Row Total' + ), + 'row_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Row Invoiced' + ), + 'base_row_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Base Row Invoiced' + ), + 'row_weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'default' => '0.0000', + 'comment' => 'Row Weight' + ), + 'base_tax_before_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Before Discount' + ), + 'tax_before_discount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Before Discount' + ), + 'ext_order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ext Order Item Id' + ), + 'locked_do_invoice' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Locked Do Invoice' + ), + 'locked_do_ship' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Locked Do Ship' + ), + 'price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price Incl Tax' + ), + 'base_price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price Incl Tax' + ), + 'row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total Incl Tax' + ), + 'base_row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total Incl Tax' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ), + 'hidden_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Invoiced' + ), + 'base_hidden_tax_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Invoiced' + ), + 'hidden_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Refunded' + ), + 'base_hidden_tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Refunded' + ), + 'is_nominal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Is Nominal' + ), + 'tax_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Canceled' + ), + 'hidden_tax_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Canceled' + ), + 'tax_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Refunded' + ) + ), + 'comment' => 'Sales Flat Order Item' + ), + $installer->getTable('sales/order_address') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Id' + ), + 'customer_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Customer Address Id' + ), + 'quote_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Quote Address Id' + ), + 'region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Region Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Customer Id' + ), + 'fax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Fax' + ), + 'region' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Region' + ), + 'postcode' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Postcode' + ), + 'lastname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Lastname' + ), + 'street' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Street' + ), + 'city' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'City' + ), + 'email' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Email' + ), + 'telephone' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Telephone' + ), + 'country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'comment' => 'Country Id' + ), + 'firstname' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Firstname' + ), + 'address_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Address Type' + ), + 'prefix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Prefix' + ), + 'middlename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Middlename' + ), + 'suffix' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Suffix' + ), + 'company' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Company' + ) + ), + 'comment' => 'Sales Flat Order Address' + ), + $installer->getTable('sales/order_payment') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'base_shipping_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Captured' + ), + 'shipping_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Captured' + ), + 'amount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount Refunded' + ), + 'base_amount_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Paid' + ), + 'amount_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount Canceled' + ), + 'base_amount_authorized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Authorized' + ), + 'base_amount_paid_online' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Paid Online' + ), + 'base_amount_refunded_online' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Refunded Online' + ), + 'base_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Amount' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Amount' + ), + 'amount_paid' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount Paid' + ), + 'amount_authorized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount Authorized' + ), + 'base_amount_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Ordered' + ), + 'base_shipping_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Refunded' + ), + 'shipping_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Refunded' + ), + 'base_amount_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Refunded' + ), + 'amount_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount Ordered' + ), + 'base_amount_canceled' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount Canceled' + ), + 'ideal_transaction_checked' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Ideal Transaction Checked' + ), + 'quote_payment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Quote Payment Id' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'cc_exp_month' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Exp Month' + ), + 'cc_ss_start_year' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Ss Start Year' + ), + 'echeck_bank_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Echeck Bank Name' + ), + 'method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Method' + ), + 'cc_debug_request_body' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Debug Request Body' + ), + 'cc_secure_verify' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Secure Verify' + ), + 'cybersource_token' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cybersource Token' + ), + 'ideal_issuer_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ideal Issuer Title' + ), + 'protection_eligibility' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Protection Eligibility' + ), + 'cc_approval' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Approval' + ), + 'cc_last4' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Last4' + ), + 'cc_status_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Status Description' + ), + 'echeck_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Echeck Type' + ), + 'paybox_question_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Paybox Question Number' + ), + 'cc_debug_response_serialized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Debug Response Serialized' + ), + 'cc_ss_start_month' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Ss Start Month' + ), + 'echeck_account_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Echeck Account Type' + ), + 'last_trans_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Last Trans Id' + ), + 'cc_cid_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Cid Status' + ), + 'cc_owner' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Owner' + ), + 'cc_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Type' + ), + 'ideal_issuer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Ideal Issuer Id' + ), + 'po_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Po Number' + ), + 'cc_exp_year' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Exp Year' + ), + 'cc_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Status' + ), + 'echeck_routing_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Echeck Routing Number' + ), + 'account_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Account Status' + ), + 'anet_trans_method' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Anet Trans Method' + ), + 'cc_debug_response_body' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Debug Response Body' + ), + 'cc_ss_issue' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Ss Issue' + ), + 'echeck_account_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Echeck Account Name' + ), + 'cc_avs_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Avs Status' + ), + 'cc_number_enc' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Number Enc' + ), + 'cc_trans_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cc Trans Id' + ), + 'flo2cash_account_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Flo2cash Account Id' + ), + 'paybox_request_number' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Paybox Request Number' + ), + 'address_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Address Status' + ), + 'additional_information' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Information' + ) + ), + 'comment' => 'Sales Flat Order Payment' + ), + $installer->getTable('sales/order_status_history') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'is_customer_notified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Is Customer Notified' + ), + 'is_visible_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Is Visible On Front' + ), + 'comment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Comment' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Status' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Sales Flat Order Status History' + ), + $installer->getTable('sales/order_status') => array( + 'columns' => array( + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Status' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'nullable' => false, + 'comment' => 'Label' + ) + ), + 'comment' => 'Sales Order Status Table' + ), + $installer->getTable('sales/order_status_state') => array( + 'columns' => array( + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Status' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Label' + ), + 'is_default' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Is Default' + ) + ), + 'comment' => 'Sales Order Status Table' + ), + $installer->getTable('sales/order_status_label') => array( + 'columns' => array( + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Status' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Store Id' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 128, + 'nullable' => false, + 'comment' => 'Label' + ) + ), + 'comment' => 'Sales Order Status Label Table' + ), + $installer->getTable('sales/invoice') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Tax Amount' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Amount' + ), + 'store_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Order Rate' + ), + 'base_shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Tax Amount' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Amount' + ), + 'base_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Order Rate' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Amount' + ), + 'subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Incl Tax' + ), + 'base_subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Incl Tax' + ), + 'store_to_base_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Base Rate' + ), + 'base_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Amount' + ), + 'total_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Qty' + ), + 'base_to_global_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Global Rate' + ), + 'subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal' + ), + 'base_subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Amount' + ), + 'billing_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Billing Address Id' + ), + 'is_used_for_refund' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Used For Refund' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'email_sent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Email Sent' + ), + 'can_void_flag' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Can Void Flag' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'State' + ), + 'shipping_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipping Address Id' + ), + 'cybersource_token' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cybersource Token' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Store Currency Code' + ), + 'transaction_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Transaction Id' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Order Currency Code' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Global Currency Code' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ), + 'shipping_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Hidden Tax Amount' + ), + /* TODO: remove comment + 'base_shipping_hidden_tax_amnt' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ), + */ + 'shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Incl Tax' + ), + 'base_shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Incl Tax' + ), + 'base_total_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Total Refunded' + ) + ), + 'comment' => 'Sales Flat Invoice' + ), + $installer->getTable('sales/invoice_grid') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'State' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Store Currency Code' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Order Currency Code' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Global Currency Code' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'order_increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'order_created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Order Created At' + ), + 'billing_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Billing Name' + ) + ), + 'comment' => 'Sales Flat Invoice Grid' + ), + $installer->getTable('sales/invoice_item') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'base_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'base_row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Amount' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Amount' + ), + 'price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price Incl Tax' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Amount' + ), + 'base_price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price Incl Tax' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Qty' + ), + 'base_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Cost' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'base_row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total Incl Tax' + ), + 'row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total Incl Tax' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Product Id' + ), + 'order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Order Item Id' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ) + ), + 'comment' => 'Sales Flat Invoice Item' + ), + $installer->getTable('sales/invoice_comment') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'is_customer_notified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Customer Notified' + ), + 'is_visible_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Is Visible On Front' + ), + 'comment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Comment' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Sales Flat Invoice Comment' + ), + $installer->getTable('sales/shipment') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'total_weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Weight' + ), + 'total_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Qty' + ), + 'email_sent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Email Sent' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Customer Id' + ), + 'shipping_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipping Address Id' + ), + 'billing_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Billing Address Id' + ), + 'shipment_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipment Status' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ) + ), + 'comment' => 'Sales Flat Shipment' + ), + $installer->getTable('sales/shipment_grid') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'total_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Qty' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'shipment_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipment Status' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'order_increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'order_created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Order Created At' + ), + 'shipping_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Name' + ) + ), + 'comment' => 'Sales Flat Shipment Grid' + ), + $installer->getTable('sales/shipment_item') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weight' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Qty' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Product Id' + ), + 'order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Order Item Id' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ) + ), + 'comment' => 'Sales Flat Shipment Item' + ), + $installer->getTable('sales/shipment_comment') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'is_customer_notified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Is Customer Notified' + ), + 'is_visible_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Is Visible On Front' + ), + 'comment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Comment' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Sales Flat Shipment Comment' + ), + $installer->getTable('sales/shipment_track') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'weight' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weight' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Qty' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Title' + ), + 'carrier_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Carrier Code' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ) + ), + 'comment' => 'Sales Flat Shipment Track' + ), + $installer->getTable('sales/creditmemo') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'adjustment_positive' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Adjustment Positive' + ), + 'base_shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Tax Amount' + ), + 'store_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Order Rate' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Amount' + ), + 'base_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Order Rate' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'base_adjustment_negative' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Adjustment Negative' + ), + 'base_subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal Incl Tax' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Amount' + ), + 'subtotal_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal Incl Tax' + ), + 'adjustment_negative' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Adjustment Negative' + ), + 'base_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Amount' + ), + 'store_to_base_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Base Rate' + ), + 'base_to_global_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Global Rate' + ), + 'base_adjustment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Adjustment' + ), + 'base_subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Subtotal' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Amount' + ), + 'subtotal' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Subtotal' + ), + 'adjustment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Adjustment' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'base_adjustment_positive' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Adjustment Positive' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Amount' + ), + 'shipping_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Tax Amount' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'email_sent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Email Sent' + ), + 'creditmemo_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Creditmemo Status' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'State' + ), + 'shipping_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Shipping Address Id' + ), + 'billing_address_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Billing Address Id' + ), + 'invoice_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Invoice Id' + ), + 'cybersource_token' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Cybersource Token' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Store Currency Code' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Order Currency Code' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Global Currency Code' + ), + 'transaction_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Transaction Id' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ), + 'shipping_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Hidden Tax Amount' + ), + /* TODO: remove comment + 'base_shipping_hidden_tax_amnt' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ), + */ + 'shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Incl Tax' + ), + 'base_shipping_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Incl Tax' + ) + ), + 'comment' => 'Sales Flat Creditmemo' + ), + $installer->getTable('sales/creditmemo_grid') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'store_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Order Rate' + ), + 'base_to_order_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Order Rate' + ), + 'grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Grand Total' + ), + 'store_to_base_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Store To Base Rate' + ), + 'base_to_global_rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base To Global Rate' + ), + 'base_grand_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Grand Total' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'creditmemo_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Creditmemo Status' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'State' + ), + 'invoice_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Invoice Id' + ), + 'store_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Store Currency Code' + ), + 'order_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Order Currency Code' + ), + 'base_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Base Currency Code' + ), + 'global_currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'comment' => 'Global Currency Code' + ), + 'increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Increment Id' + ), + 'order_increment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Increment Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ), + 'order_created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Order Created At' + ), + 'billing_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Billing Name' + ) + ), + 'comment' => 'Sales Flat Creditmemo Grid' + ), + $installer->getTable('sales/creditmemo_item') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'base_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'base_row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Amount' + ), + 'row_total' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total' + ), + 'base_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Discount Amount' + ), + 'price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price Incl Tax' + ), + 'base_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Tax Amount' + ), + 'base_price_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Price Incl Tax' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Qty' + ), + 'base_cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Cost' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Price' + ), + 'base_row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Row Total Incl Tax' + ), + 'row_total_incl_tax' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Row Total Incl Tax' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Product Id' + ), + 'order_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Order Item Id' + ), + 'additional_data' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Data' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'sku' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sku' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Hidden Tax Amount' + ), + 'base_hidden_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Hidden Tax Amount' + ) + ), + 'comment' => 'Sales Flat Creditmemo Item' + ), + $installer->getTable('sales/creditmemo_comment') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Entity Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Parent Id' + ), + 'is_customer_notified' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Is Customer Notified' + ), + 'is_visible_on_front' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Is Visible On Front' + ), + 'comment' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Comment' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Sales Flat Creditmemo Comment' + ), + $installer->getTable('sales/recurring_profile') => array( + 'columns' => array( + 'profile_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Profile Id' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'comment' => 'State' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'method_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Method Code' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ), + 'reference_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Reference Id' + ), + 'subscriber_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 150, + 'comment' => 'Subscriber Name' + ), + 'start_datetime' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Start Datetime' + ), + 'internal_reference_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 42, + 'nullable' => false, + 'comment' => 'Internal Reference Id' + ), + 'schedule_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Schedule Description' + ), + 'suspension_threshold' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Suspension Threshold' + ), + 'bill_failed_later' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Bill Failed Later' + ), + 'period_unit' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'comment' => 'Period Unit' + ), + 'period_frequency' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Period Frequency' + ), + 'period_max_cycles' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Period Max Cycles' + ), + 'billing_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Billing Amount' + ), + 'trial_period_unit' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'comment' => 'Trial Period Unit' + ), + 'trial_period_frequency' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Trial Period Frequency' + ), + 'trial_period_max_cycles' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Trial Period Max Cycles' + ), + 'trial_billing_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Trial Billing Amount' + ), + 'currency_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 3, + 'nullable' => false, + 'comment' => 'Currency Code' + ), + 'shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Shipping Amount' + ), + 'tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Tax Amount' + ), + 'init_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Init Amount' + ), + 'init_may_fail' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Init May Fail' + ), + 'order_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Order Info' + ), + 'order_item_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Order Item Info' + ), + 'billing_address_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Billing Address Info' + ), + 'shipping_address_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Shipping Address Info' + ), + 'profile_vendor_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Profile Vendor Info' + ), + 'additional_info' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Additional Info' + ) + ), + 'comment' => 'Sales Recurring Profile' + ), + $installer->getTable('sales/recurring_profile_order') => array( + 'columns' => array( + 'link_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Link Id' + ), + 'profile_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Profile Id' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ) + ), + 'comment' => 'Sales Recurring Profile Order' + ), + $installer->getTable('sales/order_tax') => array( + 'columns' => array( + 'tax_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tax Id' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Code' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Title' + ), + 'percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Percent' + ), + 'amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Amount' + ), + 'priority' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Priority' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Position' + ), + 'base_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Amount' + ), + 'process' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'comment' => 'Process' + ), + 'base_real_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Real Amount' + ), + 'hidden' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Hidden' + ) + ), + 'comment' => 'Sales Order Tax Table' + ), + $installer->getTable('sales/order_aggregated_created') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Order Status' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'total_qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Qty Ordered' + ), + 'total_qty_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Qty Invoiced' + ), + 'total_income_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Income Amount' + ), + 'total_revenue_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Revenue Amount' + ), + 'total_profit_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Profit Amount' + ), + 'total_invoiced_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Invoiced Amount' + ), + 'total_canceled_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Canceled Amount' + ), + 'total_paid_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Paid Amount' + ), + 'total_refunded_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Refunded Amount' + ), + 'total_tax_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Tax Amount' + ), + 'total_tax_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Tax Amount Actual' + ), + 'total_shipping_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Shipping Amount' + ), + 'total_shipping_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Shipping Amount Actual' + ), + 'total_discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Discount Amount' + ), + 'total_discount_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Discount Amount Actual' + ) + ), + 'comment' => 'Sales Order Aggregated Created' + ), + $installer->getTable('sales/shipping_aggregated') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'shipping_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Description' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'total_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Shipping' + ), + 'total_shipping_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Shipping Actual' + ) + ), + 'comment' => 'Sales Shipping Aggregated' + ), + $installer->getTable('sales/shipping_aggregated_order') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'shipping_description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Shipping Description' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'total_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Shipping' + ), + 'total_shipping_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Total Shipping Actual' + ) + ), + 'comment' => 'Sales Shipping Aggregated Order' + ), + $installer->getTable('sales/invoiced_aggregated') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'orders_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Orders Invoiced' + ), + 'invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced' + ), + 'invoiced_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced Captured' + ), + 'invoiced_not_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced Not Captured' + ) + ), + 'comment' => 'Sales Invoiced Aggregated' + ), + $installer->getTable('sales/invoiced_aggregated_order') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Order Status' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'orders_invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Orders Invoiced' + ), + 'invoiced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced' + ), + 'invoiced_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced Captured' + ), + 'invoiced_not_captured' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Invoiced Not Captured' + ) + ), + 'comment' => 'Sales Invoiced Aggregated Order' + ), + $installer->getTable('sales/refunded_aggregated') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Order Status' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Refunded' + ), + 'online_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Online Refunded' + ), + 'offline_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Offline Refunded' + ) + ), + 'comment' => 'Sales Refunded Aggregated' + ), + $installer->getTable('sales/refunded_aggregated_order') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Orders Count' + ), + 'refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Refunded' + ), + 'online_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Online Refunded' + ), + 'offline_refunded' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Offline Refunded' + ) + ), + 'comment' => 'Sales Refunded Aggregated Order' + ), + $installer->getTable('sales/payment_transaction') => array( + 'columns' => array( + 'transaction_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Transaction Id' + ), + 'parent_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Parent Id' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Order Id' + ), + 'payment_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Payment Id' + ), + 'txn_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'comment' => 'Txn Id' + ), + 'parent_txn_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 100, + 'comment' => 'Parent Txn Id' + ), + 'txn_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 15, + 'comment' => 'Txn Type' + ), + 'is_closed' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Closed' + ), + 'additional_information' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BLOB, + 'length' => '64K', + 'comment' => 'Additional Information' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Sales Payment Transaction' + ), + $installer->getTable('sales/bestsellers_aggregated_daily') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'product_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product Name' + ), + 'product_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Product Price' + ), + 'qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty Ordered' + ), + 'rating_pos' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Rating Pos' + ) + ), + 'comment' => 'Sales Bestsellers Aggregated Daily' + ), + $installer->getTable('sales/bestsellers_aggregated_monthly') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'product_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product Name' + ), + 'product_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Product Price' + ), + 'qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty Ordered' + ), + 'rating_pos' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Rating Pos' + ) + ), + 'comment' => 'Sales Bestsellers Aggregated Monthly' + ), + $installer->getTable('sales/bestsellers_aggregated_yearly') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Product Id' + ), + 'product_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Product Name' + ), + 'product_price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Product Price' + ), + 'qty_ordered' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Qty Ordered' + ), + 'rating_pos' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Rating Pos' + ) + ), + 'comment' => 'Sales Bestsellers Aggregated Yearly' + ), + $installer->getTable('sales/billing_agreement') => array( + 'columns' => array( + 'agreement_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Agreement Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Customer Id' + ), + 'method_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Method Code' + ), + 'reference_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Reference Id' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'comment' => 'Status' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => false, + 'comment' => 'Created At' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Updated At' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'agreement_label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Agreement Label' + ) + ), + 'comment' => 'Sales Billing Agreement' + ), + $installer->getTable('sales/billing_agreement_order') => array( + 'columns' => array( + 'agreement_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Agreement Id' + ), + 'order_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Order Id' + ) + ), + 'comment' => 'Sales Billing Agreement Order' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/creditmemo'), + 'base_shipping_hidden_tax_amount', + 'base_shipping_hidden_tax_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/invoice'), + 'base_shipping_hidden_tax_amount', + 'base_shipping_hidden_tax_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/order'), + 'forced_do_shipment_with_invoice', + 'forced_shipment_with_invoice', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Forced Do Shipment With Invoice' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/order'), + 'payment_authorization_expiration', + 'payment_auth_expiration', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'comment' => 'Payment Authorization Expiration' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/order'), + 'base_shipping_hidden_tax_amount', + 'base_shipping_hidden_tax_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/quote_address'), + 'base_shipping_hidden_tax_amount', + 'base_shipping_hidden_tax_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Shipping Hidden Tax Amount' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/shipment_track'), + 'number', + 'track_number', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Number' + ) +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + $installer->getIdxName( + 'sales/bestsellers_aggregated_daily', + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + $installer->getIdxName('sales/bestsellers_aggregated_daily', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_daily'), + $installer->getIdxName('sales/bestsellers_aggregated_daily', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + $installer->getIdxName( + 'sales/bestsellers_aggregated_monthly', + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + $installer->getIdxName('sales/bestsellers_aggregated_monthly', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_monthly'), + $installer->getIdxName('sales/bestsellers_aggregated_monthly', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + $installer->getIdxName( + 'sales/bestsellers_aggregated_yearly', + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'product_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + $installer->getIdxName('sales/bestsellers_aggregated_yearly', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/bestsellers_aggregated_yearly'), + $installer->getIdxName('sales/bestsellers_aggregated_yearly', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/billing_agreement'), + $installer->getIdxName('sales/billing_agreement', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/billing_agreement'), + $installer->getIdxName('sales/billing_agreement', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/billing_agreement_order'), + 'PRIMARY', + array('agreement_id', 'order_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/billing_agreement_order'), + $installer->getIdxName('sales/billing_agreement_order', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName( + 'sales/creditmemo', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName('sales/creditmemo', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName('sales/creditmemo', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName('sales/creditmemo', array('creditmemo_status')), + array('creditmemo_status') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName('sales/creditmemo', array('state')), + array('state') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo'), + $installer->getIdxName('sales/creditmemo', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_comment'), + $installer->getIdxName('sales/creditmemo_comment', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_comment'), + $installer->getIdxName('sales/creditmemo_comment', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName( + 'sales/creditmemo_grid', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('grand_total')), + array('grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('base_grand_total')), + array('base_grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('creditmemo_status')), + array('creditmemo_status') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('state')), + array('state') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('order_increment_id')), + array('order_increment_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('order_created_at')), + array('order_created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_grid'), + $installer->getIdxName('sales/creditmemo_grid', array('billing_name')), + array('billing_name') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/creditmemo_item'), + $installer->getIdxName('sales/creditmemo_item', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName( + 'sales/invoice', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName('sales/invoice', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName('sales/invoice', array('grand_total')), + array('grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName('sales/invoice', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName('sales/invoice', array('state')), + array('state') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice'), + $installer->getIdxName('sales/invoice', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_comment'), + $installer->getIdxName('sales/invoice_comment', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_comment'), + $installer->getIdxName('sales/invoice_comment', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName( + 'sales/invoice_grid', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('grand_total')), + array('grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('state')), + array('state') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('order_increment_id')), + array('order_increment_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('order_created_at')), + array('order_created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_grid'), + $installer->getIdxName('sales/invoice_grid', array('billing_name')), + array('billing_name') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoice_item'), + $installer->getIdxName('sales/invoice_item', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName( + 'sales/order', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('status')), + array('status') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('state')), + array('state') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('ext_order_id')), + array('ext_order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('quote_id')), + array('quote_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order'), + $installer->getIdxName('sales/order', array('updated_at')), + array('updated_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_address'), + $installer->getIdxName('sales/order_address', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName( + 'sales/order_grid', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('status')), + array('status') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('base_grand_total')), + array('base_grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('base_total_paid')), + array('base_total_paid') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('grand_total')), + array('grand_total') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('total_paid')), + array('total_paid') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('shipping_name')), + array('shipping_name') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('billing_name')), + array('billing_name') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_grid'), + $installer->getIdxName('sales/order_grid', array('updated_at')), + array('updated_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_item'), + $installer->getIdxName('sales/order_item', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_item'), + $installer->getIdxName('sales/order_item', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_payment'), + $installer->getIdxName('sales/order_payment', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_status_history'), + $installer->getIdxName('sales/order_status_history', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_status_history'), + $installer->getIdxName('sales/order_status_history', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote'), + $installer->getIdxName('sales/quote', array('customer_id', 'store_id', 'is_active')), + array('customer_id', 'store_id', 'is_active') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote'), + $installer->getIdxName('sales/quote', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_address'), + $installer->getIdxName('sales/quote_address', array('quote_id')), + array('quote_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_address_item'), + $installer->getIdxName('sales/quote_address_item', array('quote_address_id')), + array('quote_address_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_address_item'), + $installer->getIdxName('sales/quote_address_item', array('parent_item_id')), + array('parent_item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_address_item'), + $installer->getIdxName('sales/quote_address_item', array('quote_item_id')), + array('quote_item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_item'), + $installer->getIdxName('sales/quote_item', array('parent_item_id')), + array('parent_item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_item'), + $installer->getIdxName('sales/quote_item', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_item'), + $installer->getIdxName('sales/quote_item', array('quote_id')), + array('quote_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_item'), + $installer->getIdxName('sales/quote_item', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_item_option'), + $installer->getIdxName('sales/quote_item_option', array('item_id')), + array('item_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_payment'), + $installer->getIdxName('sales/quote_payment', array('quote_id')), + array('quote_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/quote_address_shipping_rate'), + $installer->getIdxName('sales/quote_address_shipping_rate', array('address_id')), + array('address_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName( + 'sales/shipment', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName('sales/shipment', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName('sales/shipment', array('total_qty')), + array('total_qty') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName('sales/shipment', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName('sales/shipment', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment'), + $installer->getIdxName('sales/shipment', array('updated_at')), + array('updated_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_comment'), + $installer->getIdxName('sales/shipment_comment', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_comment'), + $installer->getIdxName('sales/shipment_comment', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName( + 'sales/shipment_grid', + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('increment_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('total_qty')), + array('total_qty') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('shipment_status')), + array('shipment_status') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('order_increment_id')), + array('order_increment_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('order_created_at')), + array('order_created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_grid'), + $installer->getIdxName('sales/shipment_grid', array('shipping_name')), + array('shipping_name') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_item'), + $installer->getIdxName('sales/shipment_item', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_track'), + $installer->getIdxName('sales/shipment_track', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_track'), + $installer->getIdxName('sales/shipment_track', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipment_track'), + $installer->getIdxName('sales/shipment_track', array('created_at')), + array('created_at') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoiced_aggregated'), + $installer->getIdxName( + 'sales/invoiced_aggregated', + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoiced_aggregated'), + $installer->getIdxName('sales/invoiced_aggregated', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoiced_aggregated_order'), + $installer->getIdxName( + 'sales/invoiced_aggregated_order', + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/invoiced_aggregated_order'), + $installer->getIdxName('sales/invoiced_aggregated_order', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_aggregated_created'), + $installer->getIdxName( + 'sales/order_aggregated_created', + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_aggregated_created'), + $installer->getIdxName('sales/order_aggregated_created', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_status_label'), + $installer->getIdxName('sales/order_status_label', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/order_tax'), + $installer->getIdxName('sales/order_tax', array('order_id', 'priority', 'position')), + array('order_id', 'priority', 'position') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/payment_transaction'), + $installer->getIdxName( + 'sales/payment_transaction', + array('order_id', 'payment_id', 'txn_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('order_id', 'payment_id', 'txn_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/payment_transaction'), + $installer->getIdxName('sales/payment_transaction', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/payment_transaction'), + $installer->getIdxName('sales/payment_transaction', array('parent_id')), + array('parent_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/payment_transaction'), + $installer->getIdxName('sales/payment_transaction', array('payment_id')), + array('payment_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/recurring_profile'), + $installer->getIdxName( + 'sales/recurring_profile', + array('internal_reference_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('internal_reference_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/recurring_profile'), + $installer->getIdxName('sales/recurring_profile', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/recurring_profile'), + $installer->getIdxName('sales/recurring_profile', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/recurring_profile_order'), + $installer->getIdxName( + 'sales/recurring_profile_order', + array('profile_id', 'order_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('profile_id', 'order_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/recurring_profile_order'), + $installer->getIdxName('sales/recurring_profile_order', array('order_id')), + array('order_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/refunded_aggregated'), + $installer->getIdxName( + 'sales/refunded_aggregated', + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/refunded_aggregated'), + $installer->getIdxName('sales/refunded_aggregated', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/refunded_aggregated_order'), + $installer->getIdxName( + 'sales/refunded_aggregated_order', + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/refunded_aggregated_order'), + $installer->getIdxName('sales/refunded_aggregated_order', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipping_aggregated'), + $installer->getIdxName( + 'sales/shipping_aggregated', + array('period', 'store_id', 'order_status', 'shipping_description'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status', 'shipping_description'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipping_aggregated'), + $installer->getIdxName('sales/shipping_aggregated', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipping_aggregated_order'), + $installer->getIdxName( + 'sales/shipping_aggregated_order', + array('period', 'store_id', 'order_status', 'shipping_description'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status', 'shipping_description'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('sales/shipping_aggregated_order'), + $installer->getIdxName('sales/shipping_aggregated_order', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_daily', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_daily', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('sales/bestsellers_aggregated_daily'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_monthly', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_monthly', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('sales/bestsellers_aggregated_monthly'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_yearly', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/bestsellers_aggregated_yearly', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('sales/bestsellers_aggregated_yearly'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/billing_agreement', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('sales/billing_agreement'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/billing_agreement', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/billing_agreement'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/billing_agreement_order', 'agreement_id', 'sales/billing_agreement', 'agreement_id'), + $installer->getTable('sales/billing_agreement_order'), + 'agreement_id', + $installer->getTable('sales/billing_agreement'), + 'agreement_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/billing_agreement_order', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/billing_agreement_order'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/creditmemo'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/creditmemo'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo_comment', 'parent_id', 'sales/creditmemo', 'entity_id'), + $installer->getTable('sales/creditmemo_comment'), + 'parent_id', + $installer->getTable('sales/creditmemo'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo_grid', 'entity_id', 'sales/creditmemo', 'entity_id'), + $installer->getTable('sales/creditmemo_grid'), + 'entity_id', + $installer->getTable('sales/creditmemo'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo_grid', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/creditmemo_grid'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/creditmemo_item', 'parent_id', 'sales/creditmemo', 'entity_id'), + $installer->getTable('sales/creditmemo_item'), + 'parent_id', + $installer->getTable('sales/creditmemo'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/invoice'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/invoice'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice_comment', 'parent_id', 'sales/invoice', 'entity_id'), + $installer->getTable('sales/invoice_comment'), + 'parent_id', + $installer->getTable('sales/invoice'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice_grid', 'entity_id', 'sales/invoice', 'entity_id'), + $installer->getTable('sales/invoice_grid'), + 'entity_id', + $installer->getTable('sales/invoice'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice_grid', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/invoice_grid'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoice_item', 'parent_id', 'sales/invoice', 'entity_id'), + $installer->getTable('sales/invoice_item'), + 'parent_id', + $installer->getTable('sales/invoice'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('sales/order'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/order'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_address', 'parent_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/order_address'), + 'parent_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_grid', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('sales/order_grid'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_grid', 'entity_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/order_grid'), + 'entity_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_grid', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/order_grid'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_item', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/order_item'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_item', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/order_item'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_payment', 'parent_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/order_payment'), + 'parent_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_status_history', 'parent_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/order_status_history'), + 'parent_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/quote'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_address', 'quote_id', 'sales/quote', 'entity_id'), + $installer->getTable('sales/quote_address'), + 'quote_id', + $installer->getTable('sales/quote'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_address_item', 'quote_item_id', 'sales/quote_item', 'item_id'), + $installer->getTable('sales/quote_address_item'), + 'quote_item_id', + $installer->getTable('sales/quote_item'), + 'item_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_address_item', 'parent_item_id', 'sales/quote_address_item', 'address_item_id'), + $installer->getTable('sales/quote_address_item'), + 'parent_item_id', + $installer->getTable('sales/quote_address_item'), + 'address_item_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_address_item', 'quote_address_id', 'sales/quote_address', 'address_id'), + $installer->getTable('sales/quote_address_item'), + 'quote_address_id', + $installer->getTable('sales/quote_address'), + 'address_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_item', 'parent_item_id', 'sales/quote_item', 'item_id'), + $installer->getTable('sales/quote_item'), + 'parent_item_id', + $installer->getTable('sales/quote_item'), + 'item_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_item', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('sales/quote_item'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_item', 'quote_id', 'sales/quote', 'entity_id'), + $installer->getTable('sales/quote_item'), + 'quote_id', + $installer->getTable('sales/quote'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_item', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/quote_item'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_item_option', 'item_id', 'sales/quote_item', 'item_id'), + $installer->getTable('sales/quote_item_option'), + 'item_id', + $installer->getTable('sales/quote_item'), + 'item_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_payment', 'quote_id', 'sales/quote', 'entity_id'), + $installer->getTable('sales/quote_payment'), + 'quote_id', + $installer->getTable('sales/quote'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/quote_address_shipping_rate', 'address_id', 'sales/quote_address', 'address_id'), + $installer->getTable('sales/quote_address_shipping_rate'), + 'address_id', + $installer->getTable('sales/quote_address'), + 'address_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/shipment'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/shipment'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment_comment', 'parent_id', 'sales/shipment', 'entity_id'), + $installer->getTable('sales/shipment_comment'), + 'parent_id', + $installer->getTable('sales/shipment'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment_grid', 'entity_id', 'sales/shipment', 'entity_id'), + $installer->getTable('sales/shipment_grid'), + 'entity_id', + $installer->getTable('sales/shipment'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment_grid', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/shipment_grid'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment_item', 'parent_id', 'sales/shipment', 'entity_id'), + $installer->getTable('sales/shipment_item'), + 'parent_id', + $installer->getTable('sales/shipment'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipment_track', 'parent_id', 'sales/shipment', 'entity_id'), + $installer->getTable('sales/shipment_track'), + 'parent_id', + $installer->getTable('sales/shipment'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoiced_aggregated', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/invoiced_aggregated'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/invoiced_aggregated_order', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/invoiced_aggregated_order'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_aggregated_created', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/order_aggregated_created'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_status_label', 'status', 'sales/order_status', 'status'), + $installer->getTable('sales/order_status_label'), + 'status', + $installer->getTable('sales/order_status'), + 'status' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_status_label', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/order_status_label'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/order_status_state', 'status', 'sales/order_status', 'status'), + $installer->getTable('sales/order_status_state'), + 'status', + $installer->getTable('sales/order_status'), + 'status' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/payment_transaction', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/payment_transaction'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/payment_transaction', 'parent_id', 'sales/payment_transaction', 'transaction_id'), + $installer->getTable('sales/payment_transaction'), + 'parent_id', + $installer->getTable('sales/payment_transaction'), + 'transaction_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/payment_transaction', 'payment_id', 'sales/order_payment', 'entity_id'), + $installer->getTable('sales/payment_transaction'), + 'payment_id', + $installer->getTable('sales/order_payment'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/recurring_profile', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('sales/recurring_profile'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/recurring_profile', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/recurring_profile'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/recurring_profile_order', 'order_id', 'sales/order', 'entity_id'), + $installer->getTable('sales/recurring_profile_order'), + 'order_id', + $installer->getTable('sales/order'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/recurring_profile_order', 'profile_id', 'sales/recurring_profile', 'profile_id'), + $installer->getTable('sales/recurring_profile_order'), + 'profile_id', + $installer->getTable('sales/recurring_profile'), + 'profile_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/refunded_aggregated', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/refunded_aggregated'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/refunded_aggregated_order', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/refunded_aggregated_order'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipping_aggregated', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/shipping_aggregated'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('sales/shipping_aggregated_order', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sales/shipping_aggregated_order'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/SalesRule/Exception.php b/app/code/core/Mage/SalesRule/Exception.php index 9c122dd43f..5db103e8d8 100644 --- a/app/code/core/Mage/SalesRule/Exception.php +++ b/app/code/core/Mage/SalesRule/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Helper/Data.php b/app/code/core/Mage/SalesRule/Helper/Data.php index fd43bfef7b..406247d6de 100644 --- a/app/code/core/Mage/SalesRule/Helper/Data.php +++ b/app/code/core/Mage/SalesRule/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Coupon.php b/app/code/core/Mage/SalesRule/Model/Coupon.php index 004c07e8f4..cbd0c40411 100644 --- a/app/code/core/Mage/SalesRule/Model/Coupon.php +++ b/app/code/core/Mage/SalesRule/Model/Coupon.php @@ -20,11 +20,35 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * SalesRule Coupon Model + * + * @method Mage_SalesRule_Model_Resource_Coupon _getResource() + * @method Mage_SalesRule_Model_Resource_Coupon getResource() + * @method int getRuleId() + * @method Mage_SalesRule_Model_Coupon setRuleId(int $value) + * @method string getCode() + * @method Mage_SalesRule_Model_Coupon setCode(string $value) + * @method int getUsageLimit() + * @method Mage_SalesRule_Model_Coupon setUsageLimit(int $value) + * @method int getUsagePerCustomer() + * @method Mage_SalesRule_Model_Coupon setUsagePerCustomer(int $value) + * @method int getTimesUsed() + * @method Mage_SalesRule_Model_Coupon setTimesUsed(int $value) + * @method string getExpirationDate() + * @method Mage_SalesRule_Model_Coupon setExpirationDate(string $value) + * @method int getIsPrimary() + * @method Mage_SalesRule_Model_Coupon setIsPrimary(int $value) + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ class Mage_SalesRule_Model_Coupon extends Mage_Core_Model_Abstract { /** diff --git a/app/code/core/Mage/SalesRule/Model/Coupon/Codegenerator.php b/app/code/core/Mage/SalesRule/Model/Coupon/Codegenerator.php index acbcc2d934..a4216854fb 100644 --- a/app/code/core/Mage/SalesRule/Model/Coupon/Codegenerator.php +++ b/app/code/core/Mage/SalesRule/Model/Coupon/Codegenerator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Coupon/CodegeneratorInterface.php b/app/code/core/Mage/SalesRule/Model/Coupon/CodegeneratorInterface.php index 5ae5b796dd..1cc8e3e053 100644 --- a/app/code/core/Mage/SalesRule/Model/Coupon/CodegeneratorInterface.php +++ b/app/code/core/Mage/SalesRule/Model/Coupon/CodegeneratorInterface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon.php index f90679f421..155706acb5 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon.php @@ -20,73 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Coupon extends Mage_Core_Model_Mysql4_Abstract +/** + * SalesRule Coupon Resource Model + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Coupon extends Mage_SalesRule_Model_Resource_Coupon { - /** - * Constructor adds unique fileds - */ - protected function _construct() - { - $this->_init('salesrule/coupon', 'coupon_id'); - $this->addUniqueField(array( - 'field' => 'code', - 'title' => Mage::helper('salesRule')->__('Coupon with the same code') - )); - } - - /** - * Perform actions before object save - * - * @param Varien_Object $object - */ - public function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getExpirationDate()) { - $object->setExpirationDate(new Zend_Db_Expr('NULL')); - } else if ($object->getExpirationDate() instanceof Zend_Date) { - $object->setExpirationDate($object->getExpirationDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } - - // maintain single primary coupon per rule - $object->setIsPrimary($object->getIsPrimary() ? 1 : null); - - return parent::_beforeSave($object); - } - - /** - * Load primary coupon (is_primary = 1) for specified rule - * - * @param Mage_SalesRule_Model_Coupon Coupon model - * @param Mage_SalesRule_Model_Rule|int Rule - */ - public function loadPrimaryByRule(Mage_SalesRule_Model_Coupon $object, $rule) - { - $read = $this->_getReadAdapter(); - - if ($rule instanceof Mage_SalesRule_Model_Rule) { - $ruleId = $rule->getId(); - } else { - $ruleId = (int)$rule; - } - - $select = $read->select()->from($this->getMainTable()) - ->where('rule_id=?', $ruleId) - ->where('is_primary=?', 1); - - $data = $read->fetchRow($select); - - if (!$data) { - return false; - } - - $object->setData($data); - - $this->_afterLoad($object); - return true; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Collection.php index 57dd470d72..6b1b2c68a6 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Collection.php @@ -20,41 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Coupon_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * SalesRule Mysql4 coupon collection + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Coupon_Collection extends Mage_SalesRule_Model_Resource_Coupon_Collection { - protected function _construct() - { - parent::_construct(); - $this->_init('salesrule/coupon'); - } - - /** - * Add rule to filter - * - * @param Mage_SalesRule_Model_Rule|int Rule - */ - public function addRuleToFilter($rule) - { - if ($rule instanceof Mage_SalesRule_Model_Rule) { - $ruleId = $rule->getId(); - } else { - $ruleId = (int)$rule; - } - $this->addFieldToFilter('rule_id', $ruleId); - } - - /** - * Add rule IDs to filter - * - * @param array Rule Ids - */ - public function addRuleIdsToFilter(array $ruleIds) - { - $this->addFieldToFilter('rule_id', array('in' => $ruleIds)); - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Usage.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Usage.php index 335dead565..3a3910b12c 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Usage.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Coupon/Usage.php @@ -20,63 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Coupon_Usage extends Mage_Core_Model_Mysql4_Abstract +/** + * SalesRule Mysql4 Coupon Usage Resource Model + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Coupon_Usage extends Mage_SalesRule_Model_Resource_Coupon_Usage { - protected function _construct() - { - $this->_init('salesrule/coupon_usage', ''); - } - - /** - * Increment times_used counter - * - * @param int Customer Id - * @param int Coupon Id - */ - public function updateCustomerCouponTimesUsed($customerId, $couponId) - { - $this->_getWriteAdapter()->insertOnDuplicate( - $this->getMainTable(), - array( - 'coupon_id' => $couponId, - 'customer_id' => $customerId, - 'times_used' => 1 - ), - array( - 'times_used' => new Zend_Db_Expr('times_used + 1') - ) - ); - } - - /** - * Load an object by customer_id & coupon_id - * - * @param Varien_Object Object to load data to - * @param int Customer Id - * @param int Coupon Id - * @return Mage_Core_Model_Mysql4_Abstract - */ - public function loadByCustomerCoupon(Varien_Object $object, $customerId, $couponId) - { - $read = $this->_getReadAdapter(); - if ($read && $couponId && $customerId) { - $select = $read->select() - ->from($this->getMainTable()) - ->where($this->getMainTable() . '.customer_id=?', $customerId) - ->where($this->getMainTable() . '.coupon_id=?', $couponId); - $data = $read->fetchRow($select); - if ($data) { - $object->setData($data); - } - } - if ($object instanceof Mage_Core_Model_Abstract) { - $this->_afterLoad($object); - } - return $this; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Collection.php index ce2980124b..9ccf59f036 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Collection.php @@ -20,87 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sales report coupons collection * - * @category Mage - * @package Mage_SalesRule - * @author Magento Core Team + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team */ -class Mage_SalesRule_Model_Mysql4_Report_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_SalesRule_Model_Mysql4_Report_Collection extends Mage_SalesRule_Model_Resource_Report_Collection { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('salesrule/coupon_aggregated'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'coupon_code', - 'coupon_uses' => 'SUM(coupon_uses)', - 'subtotal_amount' => 'SUM(subtotal_amount)', - 'discount_amount' => 'SUM(discount_amount)', - 'total_amount' => 'SUM(total_amount)', - 'subtotal_amount_actual' => 'SUM(subtotal_amount_actual)', - 'discount_amount_actual' => 'SUM(discount_amount_actual)', - 'total_amount_actual' => 'SUM(total_amount_actual)', - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - if ($this->isSubTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat); - } - - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_SalesRule_Model_Mysql4_Report_Collection - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); - if ($this->isSubTotals()) { - $this->getSelect()->group($this->_periodFormat); - } else if (!$this->isTotals()) { - $this->getSelect()->group(array( - $this->_periodFormat, - 'coupon_code' - )); - } - return $this; - } - } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Rule.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Rule.php index 72fbb79b43..70af07fc49 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Rule.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Rule.php @@ -20,135 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Rule report resource model + * Rule report Resource Model * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team */ - -class Mage_SalesRule_Model_Mysql4_Report_Rule extends Mage_Reports_Model_Mysql4_Report_Abstract +class Mage_SalesRule_Model_Mysql4_Report_Rule extends Mage_SalesRule_Model_Resource_Report_Rule { - protected function _construct() - { - $this->_setResource('salesrule'); - } - - - /** - * Aggregate Coupons data - * - * @param mixed $from - * @param mixed $to - * @return Mage_SalesRule_Model_Mysql4_Report_Rule - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $this->_aggregateByOrderCreatedAt($from, $to); - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_COUPONS_FLAG_CODE); - return $this; - } - - /** - * Aggregate coupons reports by order created at as range - * - * @param mixed $from - * @param mixed $to - * @return Mage_SalesRule_Model_Mysql4_Report_Rule - */ - protected function _aggregateByOrderCreatedAt($from, $to) - { - $table = $this->getTable('salesrule/coupon_aggregated'); - $sourceTable = $this->getTable('sales/order'); - $this->_getWriteAdapter()->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($table, $from, $to, $subSelect); - - $columns = array( - // convert dates from UTC to current admin timezone - 'period' => "DATE(CONVERT_TZ(created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'store_id', - 'order_status' => 'status', - 'coupon_code' => 'coupon_code', - 'coupon_uses' => 'COUNT(`entity_id`)', - 'subtotal_amount' => 'SUM((`base_subtotal` - IFNULL(`base_subtotal_canceled`, 0)) * `base_to_global_rate`)', - 'discount_amount' => 'SUM((ABS(`base_discount_amount`) - IFNULL(`base_discount_canceled`, 0)) * `base_to_global_rate`)', - 'total_amount' => 'SUM((`base_subtotal` - IFNULL(`base_subtotal_canceled`, 0) + IFNULL(ABS(`base_discount_amount`) - IFNULL(`base_discount_canceled`, 0), 0)) * `base_to_global_rate`)', - 'subtotal_amount_actual' => 'SUM((`base_subtotal_invoiced` - IFNULL(`base_subtotal_refunded`, 0)) * `base_to_global_rate`)', - 'discount_amount_actual' => 'SUM((`base_discount_invoiced` - IFNULL(`base_discount_refunded`, 0)) * `base_to_global_rate`)', - 'total_amount_actual' => 'SUM((`base_subtotal_invoiced` - IFNULL(`base_subtotal_refunded`, 0) - IFNULL(`base_discount_invoiced` - IFNULL(`base_discount_refunded`, 0), 0)) * `base_to_global_rate`)', - ); - - $select = $this->_getWriteAdapter()->select(); - $select->from($sourceTable, $columns) - ->where('coupon_code <> ?', ''); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); - } - - $select->group(array( - 'period', - 'store_id', - 'order_status', - 'coupon_code' - )); - - $select->having('coupon_uses > 0'); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'order_status' => 'order_status', - 'coupon_code' => 'coupon_code', - 'coupon_uses' => 'SUM(`coupon_uses`)', - 'subtotal_amount' => 'SUM(`subtotal_amount`)', - 'discount_amount' => 'SUM(`discount_amount`)', - 'total_amount' => 'SUM(`total_amount`)', - 'subtotal_amount_actual' => 'SUM(`subtotal_amount_actual`)', - 'discount_amount_actual' => 'SUM(`discount_amount_actual`)', - 'total_amount_actual' => 'SUM(`total_amount_actual`)', - ); - - $select - ->from($table, $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array( - 'period', - 'order_status', - 'coupon_code' - )); - - $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); - } catch (Exception $e) { - $this->_getWriteAdapter()->rollBack(); - throw $e; - } - - $this->_getWriteAdapter()->commit(); - return $this; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Updatedat/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Updatedat/Collection.php index 4190b82407..14ab798b20 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Updatedat/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Report/Updatedat/Collection.php @@ -20,74 +20,19 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Sales report coupons collection + * SalesRule Report Updatedat Collection * - * @category Mage - * @package Mage_SalesRule - * @author Magento Core Team + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team */ -class Mage_SalesRule_Model_Mysql4_Report_Updatedat_Collection extends Mage_Sales_Model_Mysql4_Report_Order_Updatedat_Collection +class Mage_SalesRule_Model_Mysql4_Report_Updatedat_Collection + extends Mage_SalesRule_Model_Resource_Report_Updatedat_Collection { - protected $_selectedColumns = array( - 'store_id' => 'e.store_id', - 'order_status' => 'e.status', - 'coupon_code' => 'e.coupon_code', - 'coupon_uses' => 'COUNT(e.`entity_id`)', - 'subtotal_amount' => 'SUM((e.`base_subtotal` - IFNULL(e.`base_subtotal_canceled`, 0)) * e.`base_to_global_rate`)', - 'discount_amount' => 'SUM((ABS(e.`base_discount_amount`) - IFNULL(e.`base_discount_canceled`, 0)) * e.`base_to_global_rate`)', - 'total_amount' => 'SUM((e.`base_subtotal` - IFNULL(e.`base_subtotal_canceled`, 0) + IFNULL(ABS(e.`base_discount_amount`) - IFNULL(e.`base_discount_canceled`, 0), 0)) * e.`base_to_global_rate`)', - 'subtotal_amount_actual' => 'SUM((e.`base_subtotal_invoiced` - IFNULL(e.`base_subtotal_refunded`, 0)) * e.`base_to_global_rate`)', - 'discount_amount_actual' => 'SUM((e.`base_discount_invoiced` - IFNULL(e.`base_discount_refunded`, 0)) * e.`base_to_global_rate`)', - 'total_amount_actual' => 'SUM((e.`base_subtotal_invoiced` - IFNULL(e.`base_subtotal_refunded`, 0) - IFNULL(e.`base_discount_invoiced` - IFNULL(e.`base_discount_refunded`, 0), 0)) * e.`base_to_global_rate`)', - ); - - /** - * Add selected data - * - * @return Mage_SalesRule_Model_Mysql4_Report_Updatedat_Collection - */ - protected function _initSelect() - { - if ($this->_inited) { - return $this; - } - - $columns = $this->_getSelectedColumns(); - if ($this->isTotals() || $this->isSubTotals()) { - unset($columns['coupon_code']); - } - - $this->getSelect() - ->from(array('e' => $this->getResource()->getMainTable()), $columns) - ->where('e.coupon_code <> ?', ''); - - $this->_applyStoresFilter(); - $this->_applyOrderStatusFilter(); - - if ($this->_to !== null) { - $this->getSelect()->where('DATE(e.updated_at) <= DATE(?)', $this->_to); - } - if ($this->_from !== null) { - $this->getSelect()->where('DATE(e.updated_at) >= DATE(?)', $this->_from); - } - - if ($this->isSubTotals()) { - $this->getSelect()->group($this->_periodFormat); - } else if (!$this->isTotals()) { - $this->getSelect()->group(array( - $this->_periodFormat, - 'coupon_code' - )); - } - - $this->getSelect()->having('coupon_uses > 0'); - - $this->_inited = true; - return $this; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule.php index c9cd3c773d..b7f85da73a 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule.php @@ -20,171 +20,19 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Rule extends Mage_Core_Model_Mysql4_Abstract +/** + * SalesRule resource model + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule extends Mage_SalesRule_Model_Resource_Rule { - protected function _construct() - { - $this->_init('salesrule/rule', 'rule_id'); - } - - public function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getFromDate()) { - $object->setFromDate(Mage::app()->getLocale()->date()); - } - if ($object->getFromDate() instanceof Zend_Date) { - $object->setFromDate($object->getFromDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } - - if (!$object->getToDate()) { - $object->setToDate(new Zend_Db_Expr('NULL')); - } - else { - if ($object->getToDate() instanceof Zend_Date) { - $object->setToDate($object->getToDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); - } - } - - if (!$object->getDiscountQty()) { - $object->setDiscountQty(new Zend_Db_Expr('NULL')); - } - - parent::_beforeSave($object); - } - - public function getCustomerUses($rule, $customerId) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getTable('rule_customer'), array('cnt'=>'count(*)')) - ->where('rule_id=?', $rule->getRuleId()) - ->where('customer_id=?', $customerId); - return $read->fetchOne($select); - } - - /** - * Save rule labels for different store views - * - * @param int $ruleId - * @param array $labels - * @return Mage_SalesRule_Model_Mysql4_Rule - */ - public function saveStoreLabels($ruleId, $labels) - { - $delete = array(); - $save = array(); - $table = $this->getTable('salesrule/label'); - $adapter = $this->_getWriteAdapter(); - - foreach ($labels as $storeId => $label) { - if (Mage::helper('core/string')->strlen($label)) { - $data = array('rule_id' => $ruleId, 'store_id' => $storeId, 'label' => $label); - $adapter->insertOnDuplicate($table, $data, array('label')); - } else { - $delete[] = $storeId; - } - } - - if (!empty($delete)) { - $adapter->delete($table, - $adapter->quoteInto('rule_id=? AND ', $ruleId) . $adapter->quoteInto('store_id IN (?)', $delete) - ); - } - return $this; - } - - /** - * Get all existing rule labels - * - * @param int $ruleId - * @return array - */ - public function getStoreLabels($ruleId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('salesrule/label'), array('store_id', 'label')) - ->where('rule_id=?', $ruleId); - return $this->_getReadAdapter()->fetchPairs($select); - } - - /** - * Get rule label by specific store id - * - * @param int $ruleId - * @param int $storeId - * @return string - */ - public function getStoreLabel($ruleId, $storeId) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('salesrule/label'), 'label') - ->where('rule_id=?', $ruleId) - ->where('store_id IN(?)', array($storeId, 0)) - ->order('store_id DESC'); - return $this->_getReadAdapter()->fetchOne($select); - } - - /** - * Return codes of all product attributes currently used in promo rules for specified customer group and website - * - * @param unknown_type $websiteId - * @param unknown_type $customerGroupId - * @return mixed - */ - public function getActiveAttributes($websiteId, $customerGroupId) - { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from(array('a' => $this->getTable('salesrule/product_attribute')), - new Zend_Db_Expr('DISTINCT ea.attribute_code')) - ->joinInner(array('ea' => $this->getTable('eav/attribute')), 'ea.attribute_id = a.attribute_id', '') - ; - return $read->fetchAll($select); - } - - /** - * Save product attributes currently used in conditions and actions of rule - * - * @param Mage_SalesRule_Model_Rule $rule - * @param mixed $attributes - * return Mage_SalesRule_Model_Mysql4_Rule - */ - public function setActualProductAttributes($rule, $attributes) - { - $write = $this->_getWriteAdapter(); - $write->delete($this->getTable('salesrule/product_attribute'), - $write->quoteInto('rule_id=?', $rule->getId())); - - //Getting attribute IDs for attribute codes - $attributeIds = array(); - $select = $this->_getReadAdapter()->select() - ->from(array('a'=>$this->getTable('eav/attribute')), array('a.attribute_id')) - ->where('a.attribute_code IN (?)', array($attributes)); - $attributesFound = $this->_getReadAdapter()->fetchAll($select); - if ($attributesFound) { - foreach ($attributesFound as $attribute) { - $attributeIds[] = $attribute['attribute_id']; - } - $data = array(); - foreach (explode(',', $rule->getCustomerGroupIds()) as $customerGroupId) { - foreach (explode(',', $rule->getWebsiteIds()) as $websiteId) { - foreach ($attributeIds as $attribute) { - $data[] = array ( - 'rule_id' => $rule->getId(), - 'website_id' => $websiteId, - 'customer_group_id' => $customerGroupId, - 'attribute_id' => $attribute - ); - } - } - } - $write->insertMultiple($this->getTable('salesrule/product_attribute'), $data); - } - return $this; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Collection.php index ec41f31e93..e9a0a9d93c 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Collection.php @@ -20,108 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Rule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * SalesRule Mysql4 Rule Collection + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule_Collection extends Mage_SalesRule_Model_Resource_Rule_Collection { - protected function _construct() - { - $this->_init('salesrule/rule'); - $this->_map['fields']['rule_id'] = 'main_table.rule_id'; - } - - public function setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null) - { - if (is_null($now)) { - $now = Mage::getModel('core/date')->date('Y-m-d'); - } - - $this->getSelect()->where('is_active=1'); - $this->getSelect()->where('find_in_set(?, website_ids)', (int)$websiteId); - $this->getSelect()->where('find_in_set(?, customer_group_ids)', (int)$customerGroupId); - - if ($couponCode) { - $this->getSelect()->joinLeft( - array('extra_coupon' => $this->getTable('salesrule/coupon')), - 'extra_coupon.rule_id = main_table.rule_id AND extra_coupon.is_primary IS NULL', - array() - ); - $this->getSelect()->group('main_table.rule_id'); - $this->getSelect()->where('' - . $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC) - . $this->getSelect()->getAdapter()->quoteInto(' OR primary_coupon.code = ?', $couponCode) - ); - $this->getSelect()->having('' - . $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO) - . $this->getSelect()->getAdapter()->quoteInto(' OR FIND_IN_SET(?, GROUP_CONCAT(extra_coupon.code))', $couponCode) - ); - } else { - $this->getSelect()->where('main_table.coupon_type = ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON); - } - $this->getSelect()->where('from_date is null or from_date<=?', $now); - $this->getSelect()->where('to_date is null or to_date>=?', $now); - $this->getSelect()->order('sort_order'); - - return $this; - } - - /** - * Filter collection by specified website IDs - * - * @param int|array $websiteIds - * @return Mage_CatalogRule_Model_Mysql4_Rule_Collection - */ - public function addWebsiteFilter($websiteIds) - { - if (!is_array($websiteIds)) { - $websiteIds = array($websiteIds); - } - $parts = array(); - foreach ($websiteIds as $websiteId) { - $parts[] = $this->getConnection()->quoteInto('FIND_IN_SET(?, main_table.website_ids)', $websiteId); - } - if ($parts) { - $this->getSelect()->where(new Zend_Db_Expr(implode(' OR ', $parts))); - } - return $this; - } - - /** - * Init collection select - * - * @return unknown - */ - public function _initSelect() - { - parent::_initSelect(); - $this->getSelect() - ->joinLeft( - array('primary_coupon' => $this->getTable('salesrule/coupon')), - 'main_table.rule_id = primary_coupon.rule_id AND primary_coupon.is_primary = 1', - array('code') - ); - return $this; - } - - /** - * Find product attribute in conditions or actions - * - * @param string $attributeCode - * @return Mage_CatalogRule_Model_Mysql4_Rule_Collection - */ - public function addAttributeInConditionFilter($attributeCode) - { - $match = sprintf('%%%s%%', substr(serialize(array('attribute' => $attributeCode)), 5, -1)); - $field = $this->_getMappedField('conditions_serialized'); - $cCond = $this->_getConditionSql($field, array('like' => $match)); - $field = $this->_getMappedField('actions_serialized'); - $aCond = $this->_getConditionSql($field, array('like' => $match)); - - $this->getSelect()->where(sprintf('(%s OR %s)', $cCond, $aCond), null, Varien_Db_Select::TYPE_CONDITION); - - return $this; - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer.php index a433fb9e60..623db6acc1 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer.php @@ -20,40 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - -class Mage_SalesRule_Model_Mysql4_Rule_Customer extends Mage_Core_Model_Mysql4_Abstract +/** + * SalesRule Mysql4 Rule Customer Resource Model + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule_Customer extends Mage_SalesRule_Model_Resource_Rule_Customer { - protected function _construct() - { - $this->_init('salesrule/rule_customer', 'rule_customer_id'); - } - - /** - * Get rule usage record for a customer - * - * @param Mage_SalesRule_Model_Rule_Customer $rule - * @param int $customerId - * @param int $ruleId - * @return Mage_SalesRule_Model_Mysql4_Rule_Customer - */ - public function loadByCustomerRule($rule, $customerId, $ruleId) - { - $read = $this->_getReadAdapter(); - $select = $read->select()->from($this->getMainTable()) - ->where('customer_id=?', $customerId) - ->where('rule_id=?', $ruleId); - $data = $read->fetchRow($select); - if (false === $data) { - // set empty data, as an existing rule object might be used - $data = array(); - } - $rule->setData($data); - return $this; - } - } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer/Collection.php index fc1b4e3653..ef5f41a3f2 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Customer/Collection.php @@ -20,16 +20,19 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Rule_Customer_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * SalesRule Mysql4 Rule Customer Collection + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule_Customer_Collection + extends Mage_SalesRule_Model_Resource_Rule_Customer_Collection { - protected function _construct() - { - parent::_construct(); - $this->_init('salesrule/rule_customer'); - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product.php index a12ad83832..0f31ba7380 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product.php @@ -20,16 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - -class Mage_SalesRule_Model_Mysql4_Rule_Product extends Mage_Core_Model_Mysql4_Abstract +/** + * SalesRule Mysql4 Rule Product Resource Model + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule_Product extends Mage_SalesRule_Model_Resource_Rule_Product { - protected function _construct() - { - $this->_init('salesrule/rule_product', 'product_rule_id'); - } } diff --git a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product/Collection.php b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product/Collection.php index 809587a613..9bc2ee28c7 100644 --- a/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Mysql4/Rule/Product/Collection.php @@ -20,16 +20,18 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_SalesRule_Model_Mysql4_Rule_Product_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +/** + * SalesRule Mysql4 Rule Product Collection + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ +class Mage_SalesRule_Model_Mysql4_Rule_Product_Collection extends Mage_SalesRule_Model_Resource_Rule_Product_Collection { - protected function _construct() - { - parent::_construct(); - $this->_init('salesrule/rule_product'); - } } diff --git a/app/code/core/Mage/SalesRule/Model/Observer.php b/app/code/core/Mage/SalesRule/Model/Observer.php index 6d80a14769..9235701076 100644 --- a/app/code/core/Mage/SalesRule/Model/Observer.php +++ b/app/code/core/Mage/SalesRule/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Quote/Discount.php b/app/code/core/Mage/SalesRule/Model/Quote/Discount.php index 8e4c705f13..01639d91bc 100644 --- a/app/code/core/Mage/SalesRule/Model/Quote/Discount.php +++ b/app/code/core/Mage/SalesRule/Model/Quote/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Quote/Freeshipping.php b/app/code/core/Mage/SalesRule/Model/Quote/Freeshipping.php index d942bc5b14..ae6d546aa8 100644 --- a/app/code/core/Mage/SalesRule/Model/Quote/Freeshipping.php +++ b/app/code/core/Mage/SalesRule/Model/Quote/Freeshipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Quote/Nominal/Discount.php b/app/code/core/Mage/SalesRule/Model/Quote/Nominal/Discount.php index ecbca23052..afdce233d0 100644 --- a/app/code/core/Mage/SalesRule/Model/Quote/Nominal/Discount.php +++ b/app/code/core/Mage/SalesRule/Model/Quote/Nominal/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php new file mode 100755 index 0000000000..96045a2102 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Coupon.php @@ -0,0 +1,103 @@ + + */ +class Mage_SalesRule_Model_Resource_Coupon extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor adds unique fields + * + */ + protected function _construct() + { + $this->_init('salesrule/coupon', 'coupon_id'); + $this->addUniqueField(array( + 'field' => 'code', + 'title' => Mage::helper('salesRule')->__('Coupon with the same code') + )); + } + + /** + * Perform actions before object save + * + * @param Varien_Object $object + * @return unknown + */ + public function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getExpirationDate()) { + $object->setExpirationDate(new Zend_Db_Expr('NULL')); + } else if ($object->getExpirationDate() instanceof Zend_Date) { + $object->setExpirationDate($object->getExpirationDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + + // maintain single primary coupon per rule + $object->setIsPrimary($object->getIsPrimary() ? 1 : null); + + return parent::_beforeSave($object); + } + + /** + * Load primary coupon (is_primary = 1) for specified rule + * + * + * @param Mage_SalesRule_Model_Coupon $object + * @param unknown_type $rule + * @return unknown + */ + public function loadPrimaryByRule(Mage_SalesRule_Model_Coupon $object, $rule) + { + $read = $this->_getReadAdapter(); + + if ($rule instanceof Mage_SalesRule_Model_Rule) { + $ruleId = $rule->getId(); + } else { + $ruleId = (int)$rule; + } + + $select = $read->select()->from($this->getMainTable()) + ->where('rule_id = :rule_id') + ->where('is_primary = :is_primary'); + + $data = $read->fetchRow($select, array(':rule_id' => $ruleId, ':is_primary' => 1)); + + if (!$data) { + return false; + } + + $object->setData($data); + + $this->_afterLoad($object); + return true; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Collection.php new file mode 100755 index 0000000000..f0f0af9a5b --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Collection.php @@ -0,0 +1,73 @@ + + */ +class Mage_SalesRule_Model_Resource_Coupon_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('salesrule/coupon'); + } + + /** + * Add rule to filter + * + * + * @param unknown_type $rule + */ + public function addRuleToFilter($rule) + { + if ($rule instanceof Mage_SalesRule_Model_Rule) { + $ruleId = $rule->getId(); + } else { + $ruleId = (int)$rule; + } + $this->addFieldToFilter('rule_id', $ruleId); + } + + /** + * Add rule IDs to filter + * + * + * @param array $ruleIds + */ + public function addRuleIdsToFilter(array $ruleIds) + { + $this->addFieldToFilter('rule_id', array('in' => $ruleIds)); + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Usage.php b/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Usage.php new file mode 100755 index 0000000000..debbf653cd --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Coupon/Usage.php @@ -0,0 +1,113 @@ + + */ +class Mage_SalesRule_Model_Resource_Coupon_Usage extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + $this->_init('salesrule/coupon_usage', ''); + } + + /** + * Increment times_used counter + * + * + * @param unknown_type $customerId + * @param unknown_type $couponId + */ + public function updateCustomerCouponTimesUsed($customerId, $couponId) + { + $read = $this->_getReadAdapter(); + $select = $read->select(); + $select->from($this->getMainTable(), array('times_used')) + ->where('coupon_id = :coupon_id') + ->where('customer_id = :customer_id'); + + $timesUsed = $read->fetchOne($select, array(':coupon_id' => $couponId, ':customer_id' => $customerId)); + + if ($timesUsed > 0) { + $this->_getWriteAdapter()->update( + $this->getMainTable(), + array( + 'times_used' => $timesUsed + 1 + ), + array( + 'coupon_id = ?' => $couponId, + 'customer_id = ?' => $customerId, + ) + ); + } else { + $this->_getWriteAdapter()->insert( + $this->getMainTable(), + array( + 'coupon_id' => $couponId, + 'customer_id' => $customerId, + 'times_used' => 1 + ) + ); + } + } + + /** + * Load an object by customer_id & coupon_id + * + * + * @param Varien_Object $object + * @param unknown_type $customerId + * @param unknown_type $couponId + * @return Mage_SalesRule_Model_Resource_Coupon_Usage + */ + public function loadByCustomerCoupon(Varien_Object $object, $customerId, $couponId) + { + $read = $this->_getReadAdapter(); + if ($read && $couponId && $customerId) { + $select = $read->select() + ->from($this->getMainTable()) + ->where('customer_id =:customet_id') + ->where('coupon_id = :coupon_id'); + $data = $read->fetchRow($select, array(':coupon_id' => $couponId, ':customet_id' => $customerId)); + if ($data) { + $object->setData($data); + } + } + if ($object instanceof Mage_Core_Model_Abstract) { + $this->_afterLoad($object); + } + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Report/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Report/Collection.php new file mode 100755 index 0000000000..0e8b4d9141 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Report/Collection.php @@ -0,0 +1,128 @@ + + */ +class Mage_SalesRule_Model_Resource_Report_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format for report (day, month, year) + * + * @var string + */ + protected $_periodFormat; + + /** + * array of columns that should be aggregated + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('salesrule/coupon_aggregated'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * collect columns for collection + * + * @return unknown + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = + $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'coupon_code', + 'coupon_uses' => 'SUM(coupon_uses)', + 'subtotal_amount' => 'SUM(subtotal_amount)', + 'discount_amount' => 'SUM(discount_amount)', + 'total_amount' => 'SUM(total_amount)', + 'subtotal_amount_actual' => 'SUM(subtotal_amount_actual)', + 'discount_amount_actual' => 'SUM(discount_amount_actual)', + 'total_amount_actual' => 'SUM(total_amount_actual)', + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + if ($this->isSubTotals()) { + $this->_selectedColumns = + $this->getAggregatedColumns() + + array('period' => $this->_periodFormat); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_SalesRule_Model_Resource_Report_Collection + */ + protected function _initSelect() + { + $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns()); + if ($this->isSubTotals()) { + $this->getSelect()->group($this->_periodFormat); + } else if (!$this->isTotals()) { + $this->getSelect()->group(array( + $this->_periodFormat, + 'coupon_code' + )); + } + + return $this; + } + + +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Report/Rule.php b/app/code/core/Mage/SalesRule/Model/Resource/Report/Rule.php new file mode 100755 index 0000000000..c447bbe4e7 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Report/Rule.php @@ -0,0 +1,190 @@ + + */ +class Mage_SalesRule_Model_Resource_Report_Rule extends Mage_Reports_Model_Resource_Report_Abstract +{ + /** + * Resource Report Rule constructor + * + */ + protected function _construct() + { + $this->_setResource('salesrule'); + } + + /** + * Aggregate Coupons data + * + * @param mixed $from + * @param mixed $to + * @return Mage_SalesRule_Model_Resource_Report_Rule + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $this->_aggregateByOrderCreatedAt($from, $to); + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_COUPONS_FLAG_CODE); + return $this; + } + + /** + * Aggregate coupons reports by order created at as range + * + * @param mixed $from + * @param mixed $to + * @return Mage_SalesRule_Model_Resource_Report_Rule + */ + protected function _aggregateByOrderCreatedAt($from, $to) + { + $table = $this->getTable('salesrule/coupon_aggregated'); + $sourceTable = $this->getTable('sales/order'); + $this->_getWriteAdapter()->beginTransaction(); + $adapter = $this->_getWriteAdapter(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($table, $from, $to, $subSelect); + + // convert dates from UTC to current admin timezone + $periodExpr = $adapter->getDatePartSql($adapter->getDateAddSql('source_table.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'store_id', + 'order_status' => 'status', + 'coupon_code' => 'coupon_code', + 'coupon_uses' => 'COUNT(entity_id)', + + 'subtotal_amount' => + $adapter->getIfNullSql('SUM((base_subtotal - ' . + $adapter->getIfNullSql('base_subtotal_canceled', 0).') * base_to_global_rate)', 0), + + 'discount_amount' => + $adapter->getIfNullSql('SUM((ABS(base_discount_amount) - ' . + $adapter->getIfNullSql('base_discount_canceled', 0).') * base_to_global_rate)', 0), + + 'total_amount' => + $adapter->getIfNullSql('SUM((base_subtotal - ' . + $adapter->getIfNullSql('base_subtotal_canceled', 0) . ' - '. + $adapter->getIfNullSql('ABS(base_discount_amount) - ' . + $adapter->getIfNullSql('base_discount_canceled', 0), 0). ') + * base_to_global_rate)', 0), + + 'subtotal_amount_actual' => + $adapter->getIfNullSql('SUM((base_subtotal_invoiced - ' . + $adapter->getIfNullSql('base_subtotal_refunded', 0). ') * base_to_global_rate)', 0), + + 'discount_amount_actual' => + $adapter->getIfNullSql('SUM((base_discount_invoiced - ' . + $adapter->getIfNullSql('base_discount_refunded', 0) . ') + * base_to_global_rate)', 0), + + 'total_amount_actual' => + $adapter->getIfNullSql('SUM((base_subtotal_invoiced - ' . + $adapter->getIfNullSql('base_subtotal_refunded', 0) . ' - ' . + $adapter->getIfNullSql('base_discount_invoiced - ' . + $adapter->getIfNullSql('base_discount_refunded', 0), 0) . + ') * base_to_global_rate)', 0), + ); + + $select = $this->_getWriteAdapter()->select(); + $select->from(array('source_table' => $sourceTable), $columns) + ->where('coupon_code IS NOT NULL'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'created_at')); + } + + $select->group(array( + $periodExpr, + 'store_id', + 'status', + 'coupon_code' + )); + + $select->having('COUNT(entity_id) > 0'); + $select->insertFromSelect($table, array_keys($columns)); + + $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr('0'), + 'order_status' => 'order_status', + 'coupon_code' => 'coupon_code', + 'coupon_uses' => 'SUM(coupon_uses)', + 'subtotal_amount' => 'SUM(subtotal_amount)', + 'discount_amount' => 'SUM(discount_amount)', + 'total_amount' => 'SUM(total_amount)', + 'subtotal_amount_actual' => 'SUM(subtotal_amount_actual)', + 'discount_amount_actual' => 'SUM(discount_amount_actual)', + 'total_amount_actual' => 'SUM(total_amount_actual)', + ); + + $select + ->from($table, $columns) + ->where('store_id <> 0'); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array( + 'period', + 'order_status', + 'coupon_code' + )); + + $this->_getWriteAdapter()->query($select->insertFromSelect($table, array_keys($columns))); + } catch (Exception $e) { + $this->_getWriteAdapter()->rollBack(); + throw $e; + } + + $this->_getWriteAdapter()->commit(); + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Report/Updatedat/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Report/Updatedat/Collection.php new file mode 100755 index 0000000000..94f36a3518 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Report/Updatedat/Collection.php @@ -0,0 +1,165 @@ + + */ +class Mage_SalesRule_Model_Resource_Report_Updatedat_Collection + extends Mage_Sales_Model_Resource_Report_Order_Updatedat_Collection +{ + /** + * Selected columns array + * + * @var array + */ + protected $_selectedColumns = array(); + + /** + * Retrieve array of columns to select + * + * @return array + */ + + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + + $this->_selectedColumns = array( + 'store_id' => 'MIN(e.store_id)', + 'order_status' => 'MIN(e.status)', + 'coupon_code' => 'MIN(e.coupon_code)', + 'coupon_uses' => 'COUNT(e.entity_id)', + + 'subtotal_amount' => + 'SUM((e.base_subtotal - '. + $adapter->getIfNullSql('e.base_subtotal_canceled', 0). + ') * e.base_to_global_rate)', + + 'discount_amount' => + 'SUM((ABS(e.base_discount_amount) - '. + $adapter->getIfNullSql('e.base_discount_canceled', 0). + ') * e.base_to_global_rate)', + + 'total_amount' => + 'SUM((e.base_subtotal - '. + $adapter->getIfNullSql('e.base_subtotal_canceled', 0) . ' - ' . + $adapter->getIfNullSql('ABS(e.base_discount_amount) - ' . + $adapter->getIfNullSql('e.base_discount_canceled', 0), 0) . + ') * e.base_to_global_rate)', + + 'subtotal_amount_actual' => + 'SUM((e.base_subtotal_invoiced - '. + $adapter->getIfNullSql('e.base_subtotal_refunded', 0). + ') * e.base_to_global_rate)', + + 'discount_amount_actual' => + 'SUM((e.base_discount_invoiced - '. + $adapter->getIfNullSql('e.base_discount_refunded', 0). + ') * e.base_to_global_rate)', + + 'total_amount_actual' => + 'SUM((e.base_subtotal_invoiced - '. + $adapter->getIfNullSql('e.base_subtotal_refunded', 0) . ' - '. + $adapter->getIfNullSql('e.base_discount_invoiced - '. + $adapter->getIfNullSql('e.base_discount_refunded', 0), 0). + ') * e.base_to_global_rate)', + ); + + if (!$this->isTotals()) { + + + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql( + 'e.updated_at', + '%Y-%m' + ); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql( + 'e.updated_at', + Varien_Db_Adapter_Interface::INTERVAL_YEAR + ); + } else { + $this->_periodFormat = $adapter->getDateFormatSql( + 'e.updated_at', + '%Y-%m-%d' + ); + } + $this->_selectedColumns['period'] = $this->_periodFormat; + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_SalesRule_Model_Resource_Report_Updatedat_Collection + */ + protected function _initSelect() + { + if ($this->_inited) { + return $this; + } + + $columns = $this->_getSelectedColumns(); + if ($this->isTotals() || $this->isSubTotals()) { + unset($columns['coupon_code']); + } + + $this->getSelect() + ->from(array('e' => $this->getResource()->getMainTable()), $columns) + ->where('e.coupon_code IS NOT NULL'); + + $this->_applyStoresFilter(); + $this->_applyOrderStatusFilter(); + + if ($this->_to !== null) { + $this->getSelect()->where('e.updated_at <= ?', $this->_to); + } + if ($this->_from !== null) { + $this->getSelect()->where('e.updated_at >= ?', $this->_from); + } + + if ($this->isSubTotals()) { + $this->getSelect()->group($this->_periodFormat); + } else if (!$this->isTotals()) { + $this->getSelect()->group(array( + $this->_periodFormat, + 'coupon_code' + )); + } + + $this->getSelect()->having('COUNT(e.entity_id) > 0'); + + $this->_inited = true; + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule.php new file mode 100755 index 0000000000..250b9f2acf --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule.php @@ -0,0 +1,210 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + $this->_init('salesrule/rule', 'rule_id'); + } + + /** + * On beforeSave + * + * @param Mage_Core_Model_Abstract $object + */ + public function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getFromDate()) { + $object->setFromDate(Mage::app()->getLocale()->date()); + } + if ($object->getFromDate() instanceof Zend_Date) { + $object->setFromDate($object->getFromDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + + if (!$object->getToDate()) { + $object->setToDate(new Zend_Db_Expr('NULL')); + } else { + if ($object->getToDate() instanceof Zend_Date) { + $object->setToDate($object->getToDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)); + } + } + + if (!$object->getDiscountQty()) { + $object->setDiscountQty(new Zend_Db_Expr('NULL')); + } + + parent::_beforeSave($object); + } + + /** + * Get customer uses + * + * @param unknown_type $rule + * @param unknown_type $customerId + * @return unknown + */ + public function getCustomerUses($rule, $customerId) + { + $read = $this->_getReadAdapter(); + $select = $read->select()->from($this->getTable('rule_customer'), array('cnt'=>'count(*)')) + ->where('rule_id = :rule_id') + ->where('customer_id = :customer_id'); + return $read->fetchOne($select, array(':rule_id' => $rule->getRuleId(), ':customer_id' => $customerId)); + } + + /** + * Save rule labels for different store views + * + * @param int $ruleId + * @param array $labels + * @return Mage_SalesRule_Model_Resource_Rule + */ + public function saveStoreLabels($ruleId, $labels) + { + $delete = array(); + $table = $this->getTable('salesrule/label'); + $adapter = $this->_getWriteAdapter(); + + foreach ($labels as $storeId => $label) { + if (Mage::helper('core/string')->strlen($label)) { + $data = array('rule_id' => $ruleId, 'store_id' => $storeId, 'label' => $label); + $adapter->insertOnDuplicate($table, $data, array('label')); + } else { + $delete[] = $storeId; + } + } + + if (!empty($delete)) { + $adapter->delete($table, array( + 'rule_id=?' => $ruleId, + 'store_id IN (?)' => $delete + )); + } + return $this; + } + + /** + * Get all existing rule labels + * + * @param int $ruleId + * @return array + */ + public function getStoreLabels($ruleId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('salesrule/label'), array('store_id', 'label')) + ->where('rule_id = :rule_id'); + return $this->_getReadAdapter()->fetchPairs($select, array(':rule_id' => $ruleId)); + } + + /** + * Get rule label by specific store id + * + * @param int $ruleId + * @param int $storeId + * @return string + */ + public function getStoreLabel($ruleId, $storeId) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getTable('salesrule/label'), 'label') + ->where('rule_id = :rule_id') + ->where('store_id IN(0, :store_id)') + ->order('store_id DESC'); + return $this->_getReadAdapter()->fetchOne($select, array(':rule_id' => $ruleId, ':store_id' => $storeId)); + } + + /** + * Return codes of all product attributes currently used in promo rules for specified customer group and website + * + * @param unknown_type $websiteId + * @param unknown_type $customerGroupId + * @return mixed + */ + public function getActiveAttributes($websiteId, $customerGroupId) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('a' => $this->getTable('salesrule/product_attribute')), + new Zend_Db_Expr('DISTINCT ea.attribute_code')) + ->joinInner(array('ea' => $this->getTable('eav/attribute')), 'ea.attribute_id = a.attribute_id', array()); + return $read->fetchAll($select); + } + + /** + * Save product attributes currently used in conditions and actions of rule + * + * @param Mage_SalesRule_Model_Rule $rule + * @param mixed $attributes + * return Mage_SalesRule_Model_Mysql4_Rule + */ + public function setActualProductAttributes($rule, $attributes) + { + $write = $this->_getWriteAdapter(); + $write->delete($this->getTable('salesrule/product_attribute'), array('rule_id=?' => $rule->getId())); + + //Getting attribute IDs for attribute codes + $attributeIds = array(); + $select = $this->_getReadAdapter()->select() + ->from(array('a'=>$this->getTable('eav/attribute')), array('a.attribute_id')) + ->where('a.attribute_code IN (?)', array($attributes)); + $attributesFound = $this->_getReadAdapter()->fetchAll($select); + if ($attributesFound) { + foreach ($attributesFound as $attribute) { + $attributeIds[] = $attribute['attribute_id']; + } + + $data = array(); + foreach (explode(',', $rule->getCustomerGroupIds()) as $customerGroupId) { + foreach (explode(',', $rule->getWebsiteIds()) as $websiteId) { + foreach ($attributeIds as $attribute) { + $data[] = array ( + 'rule_id' => $rule->getId(), + 'website_id' => $websiteId, + 'customer_group_id' => $customerGroupId, + 'attribute_id' => $attribute + ); + } + } + } + $write->insertMultiple($this->getTable('salesrule/product_attribute'), $data); + } + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Collection.php new file mode 100755 index 0000000000..7755c3606a --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Collection.php @@ -0,0 +1,145 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + $this->_init('salesrule/rule'); + $this->_map['fields']['rule_id'] = 'main_table.rule_id'; + } + + /** + * Set filter to select rules that matches current criteria + * + * @param unknown_type $websiteId + * @param unknown_type $customerGroupId + * @param unknown_type $couponCode + * @param unknown_type $now + * @return Mage_SalesRule_Model_Resource_Rule_Collection + */ + public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null) + { + if (is_null($now)) { + $now = Mage::getModel('core/date')->date('Y-m-d'); + } + /* We need to overwrite joinLeft if coupon is applied */ + $this->getSelect()->reset(); + parent::_initSelect(); + + $this->addFieldToFilter('website_ids', array('finset' => (int)$websiteId)) + ->addFieldToFilter('customer_group_ids', array('finset' => (int)$customerGroupId)) + ->addFieldToFilter('is_active', 1); + + if ($couponCode) { + $this->getSelect()->where('main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON); + $this->getSelect() + ->join( + array('rule_coupons' => $this->getTable('salesrule/coupon')), + 'main_table.rule_id = rule_coupons.rule_id '. + $this->getSelect()->getAdapter()->quoteInto('AND rule_coupons.code = ?', $couponCode), + array('code') + ); + } else { + $this->addFieldToFilter('main_table.coupon_type', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON); + } + $this->getSelect()->where('from_date is null or from_date <= ?', $now); + $this->getSelect()->where('to_date is null or to_date >= ?', $now); + $this->getSelect()->order('sort_order'); + return $this; + } + + /** + * Filter collection by specified website IDs + * + * @param int|array $websiteIds + * @return Mage_SalesRule_Model_Resource_Rule_Collection + */ + public function addWebsiteFilter($websiteIds) + { + if (!is_array($websiteIds)) { + $websiteIds = array($websiteIds); + } + $parts = array(); + foreach ($websiteIds as $websiteId) { + $parts[] = $this->getConnection() + ->prepareSqlCondition('main_table.website_ids', array('finset' => $websiteId)); + } + if ($parts) { + $this->getSelect()->where(new Zend_Db_Expr(implode(' OR ', $parts))); + } + return $this; + } + + /** + * Init collection select + * + * + * @return Mage_SalesRule_Model_Resource_Rule_Collection + */ + public function _initSelect() + { + parent::_initSelect(); + $this->getSelect() + ->joinLeft( + array('rule_coupons' => $this->getTable('salesrule/coupon')), + 'main_table.rule_id = rule_coupons.rule_id AND rule_coupons.is_primary = 1', + array('code') + ); + return $this; + } + + /** + * Find product attribute in conditions or actions + * + * @param string $attributeCode + * @return Mage_SalesRule_Model_Resource_Rule_Collection + */ + public function addAttributeInConditionFilter($attributeCode) + { + $match = sprintf('%%%s%%', substr(serialize(array('attribute' => $attributeCode)), 5, -1)); + $field = $this->_getMappedField('conditions_serialized'); + $cCond = $this->_getConditionSql($field, array('like' => $match)); + $field = $this->_getMappedField('actions_serialized'); + $aCond = $this->_getConditionSql($field, array('like' => $match)); + + $this->getSelect()->where(sprintf('(%s OR %s)', $cCond, $aCond), null, Varien_Db_Select::TYPE_CONDITION); + + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer.php new file mode 100755 index 0000000000..d80343aaad --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer.php @@ -0,0 +1,68 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule_Customer extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * constructor + * + */ + protected function _construct() + { + $this->_init('salesrule/rule_customer', 'rule_customer_id'); + } + + /** + * Get rule usage record for a customer + * + * @param Mage_SalesRule_Model_Rule_Customer $rule + * @param int $customerId + * @param int $ruleId + * @return Mage_SalesRule_Model_Resource_Rule_Customer + */ + public function loadByCustomerRule($rule, $customerId, $ruleId) + { + $read = $this->_getReadAdapter(); + $select = $read->select()->from($this->getMainTable()) + ->where('customer_id = :customer_id') + ->where('rule_id = :rule_id'); + $data = $read->fetchRow($select, array(':rule_id' => $ruleId, ':customer_id' => $customerId)); + if (false === $data) { + // set empty data, as an existing rule object might be used + $data = array(); + } + $rule->setData($data); + return $this; + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer/Collection.php new file mode 100755 index 0000000000..6c26d253c6 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Customer/Collection.php @@ -0,0 +1,46 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule_Customer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Collection constructor + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('salesrule/rule_customer'); + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product.php new file mode 100755 index 0000000000..4cf2e7abc1 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product.php @@ -0,0 +1,45 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule_Product extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + $this->_init('salesrule/rule_product', 'product_rule_id'); + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product/Collection.php b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product/Collection.php new file mode 100755 index 0000000000..3b4f58fb42 --- /dev/null +++ b/app/code/core/Mage/SalesRule/Model/Resource/Rule/Product/Collection.php @@ -0,0 +1,46 @@ + + */ +class Mage_SalesRule_Model_Resource_Rule_Product_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Collection constructor + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('salesrule/rule_product'); + } +} diff --git a/app/code/core/Mage/SalesRule/Model/Rule.php b/app/code/core/Mage/SalesRule/Model/Rule.php index 2ba01176c5..a25044b7d4 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule.php +++ b/app/code/core/Mage/SalesRule/Model/Rule.php @@ -20,11 +20,67 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * SalesRule Model + * + * @method Mage_SalesRule_Model_Resource_Rule _getResource() + * @method Mage_SalesRule_Model_Resource_Rule getResource() + * @method string getName() + * @method Mage_SalesRule_Model_Rule setName(string $value) + * @method string getDescription() + * @method Mage_SalesRule_Model_Rule setDescription(string $value) + * @method string getFromDate() + * @method Mage_SalesRule_Model_Rule setFromDate(string $value) + * @method string getToDate() + * @method Mage_SalesRule_Model_Rule setToDate(string $value) + * @method int getUsesPerCustomer() + * @method Mage_SalesRule_Model_Rule setUsesPerCustomer(int $value) + * @method string getCustomerGroupIds() + * @method Mage_SalesRule_Model_Rule setCustomerGroupIds(string $value) + * @method int getIsActive() + * @method Mage_SalesRule_Model_Rule setIsActive(int $value) + * @method string getConditionsSerialized() + * @method Mage_SalesRule_Model_Rule setConditionsSerialized(string $value) + * @method string getActionsSerialized() + * @method Mage_SalesRule_Model_Rule setActionsSerialized(string $value) + * @method int getStopRulesProcessing() + * @method Mage_SalesRule_Model_Rule setStopRulesProcessing(int $value) + * @method int getIsAdvanced() + * @method Mage_SalesRule_Model_Rule setIsAdvanced(int $value) + * @method string getProductIds() + * @method Mage_SalesRule_Model_Rule setProductIds(string $value) + * @method int getSortOrder() + * @method Mage_SalesRule_Model_Rule setSortOrder(int $value) + * @method string getSimpleAction() + * @method Mage_SalesRule_Model_Rule setSimpleAction(string $value) + * @method float getDiscountAmount() + * @method Mage_SalesRule_Model_Rule setDiscountAmount(float $value) + * @method float getDiscountQty() + * @method Mage_SalesRule_Model_Rule setDiscountQty(float $value) + * @method int getDiscountStep() + * @method Mage_SalesRule_Model_Rule setDiscountStep(int $value) + * @method int getSimpleFreeShipping() + * @method Mage_SalesRule_Model_Rule setSimpleFreeShipping(int $value) + * @method int getApplyToShipping() + * @method Mage_SalesRule_Model_Rule setApplyToShipping(int $value) + * @method int getTimesUsed() + * @method Mage_SalesRule_Model_Rule setTimesUsed(int $value) + * @method int getIsRss() + * @method Mage_SalesRule_Model_Rule setIsRss(int $value) + * @method string getWebsiteIds() + * @method Mage_SalesRule_Model_Rule setWebsiteIds(string $value) + * @method int getCouponType() + * @method Mage_SalesRule_Model_Rule setCouponType(int $value) + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ class Mage_SalesRule_Model_Rule extends Mage_Rule_Model_Rule { const FREE_SHIPPING_ITEM = 1; diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Action/Collection.php b/app/code/core/Mage/SalesRule/Model/Rule/Action/Collection.php index 7eb9fcdc78..a14deafd8c 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Action/Collection.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Action/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php b/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php index c95b07a658..1e01b8c790 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Action/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php index d1efbfd147..24d0114ef8 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Combine.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Combine.php index 7d7fb60965..91d7c23a47 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Combine.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Combine.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product.php index 1f369a8664..fbf5416338 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php index c8a119c4cf..4f3f32db2c 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Combine.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php index a3a622a747..a0a9ae0388 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Found.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php index 8acd4a6d75..2bdd63178c 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Customer.php b/app/code/core/Mage/SalesRule/Model/Rule/Customer.php index 57d2820d44..42b96625ab 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Customer.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Customer.php @@ -20,11 +20,27 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * SalesRule Rule Customer Model + * + * @method Mage_SalesRule_Model_Resource_Rule_Customer _getResource() + * @method Mage_SalesRule_Model_Resource_Rule_Customer getResource() + * @method int getRuleId() + * @method Mage_SalesRule_Model_Rule_Customer setRuleId(int $value) + * @method int getCustomerId() + * @method Mage_SalesRule_Model_Rule_Customer setCustomerId(int $value) + * @method int getTimesUsed() + * @method Mage_SalesRule_Model_Rule_Customer setTimesUsed(int $value) + * + * @category Mage + * @package Mage_SalesRule + * @author Magento Core Team + */ class Mage_SalesRule_Model_Rule_Customer extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/SalesRule/Model/Rule/Product.php b/app/code/core/Mage/SalesRule/Model/Rule/Product.php index 9842cef9b1..3ea4fbdf99 100644 --- a/app/code/core/Mage/SalesRule/Model/Rule/Product.php +++ b/app/code/core/Mage/SalesRule/Model/Rule/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/Model/Validator.php b/app/code/core/Mage/SalesRule/Model/Validator.php index e8092540a3..ae17e47b87 100644 --- a/app/code/core/Mage/SalesRule/Model/Validator.php +++ b/app/code/core/Mage/SalesRule/Model/Validator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/etc/adminhtml.xml b/app/code/core/Mage/SalesRule/etc/adminhtml.xml index 7383f133af..3e4a7fad83 100644 --- a/app/code/core/Mage/SalesRule/etc/adminhtml.xml +++ b/app/code/core/Mage/SalesRule/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/SalesRule/etc/config.xml b/app/code/core/Mage/SalesRule/etc/config.xml index aacdaa7325..1c63b2fbf1 100644 --- a/app/code/core/Mage/SalesRule/etc/config.xml +++ b/app/code/core/Mage/SalesRule/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.0.6 + 1.6.0.0 @@ -40,39 +40,58 @@ Mage_SalesRule_Model - salesrule_mysql4 + salesrule_resource - - Mage_SalesRule_Model_Mysql4 + + Mage_SalesRule_Model_Resource + salesrule_mysql4 - salesrule
      - salesrule_customer
      - - salesrule_coupon
      - salesrule_coupon_usage
      + + salesrule
      +
      + + salesrule_customer
      +
      + + + salesrule_coupon
      +
      + + salesrule_coupon_usage
      +
      coupon_aggregated
      coupon_aggregated_order
      - salesrule_product_attribute
      + + salesrule_product_attribute
      +
      -
      +
      Mage_SalesRule - Mage_Sales_Model_Mysql4_Setup + Mage_Sales_Model_Resource_Setup - * - * - * + + * + + + * + + + * + @@ -145,7 +164,6 @@ - @@ -157,12 +175,15 @@ - - 0 0 * * * - salesrule/observer::aggregateSalesReportCouponsData + + 0 0 * * * + + + salesrule/observer::aggregateSalesReportCouponsData + diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/install-1.6.0.0.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..e96737cec9 --- /dev/null +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/install-1.6.0.0.php @@ -0,0 +1,428 @@ +startSetup(); + +/** + * Create table 'salesrule/rule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/rule')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Description') + ->addColumn('from_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'From Date') + ->addColumn('to_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'To Date') + ->addColumn('uses_per_customer', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Uses Per Customer') + ->addColumn('customer_group_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Customer Group Ids') + ->addColumn('is_active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Active') + ->addColumn('conditions_serialized', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Conditions Serialized') + ->addColumn('actions_serialized', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array( + ), 'Actions Serialized') + ->addColumn('stop_rules_processing', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '1', + ), 'Stop Rules Processing') + ->addColumn('is_advanced', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Is Advanced') + ->addColumn('product_ids', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Product Ids') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort Order') + ->addColumn('simple_action', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Simple Action') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('discount_qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + ), 'Discount Qty') + ->addColumn('discount_step', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Discount Step') + ->addColumn('simple_free_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Simple Free Shipping') + ->addColumn('apply_to_shipping', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Apply To Shipping') + ->addColumn('times_used', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Times Used') + ->addColumn('is_rss', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Is Rss') + ->addColumn('website_ids', Varien_Db_Ddl_Table::TYPE_TEXT, 4000, array( + ), 'Website Ids') + ->addColumn('coupon_type', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Coupon Type') + ->addIndex($installer->getIdxName('salesrule/rule', array('is_active', 'sort_order', 'to_date', 'from_date')), + array('is_active', 'sort_order', 'to_date', 'from_date')) + ->setComment('Salesrule'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/coupon' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/coupon')) + ->addColumn('coupon_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Coupon Id') + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Rule Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Code') + ->addColumn('usage_limit', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Usage Limit') + ->addColumn('usage_per_customer', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Usage Per Customer') + ->addColumn('times_used', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Times Used') + ->addColumn('expiration_date', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Expiration Date') + ->addColumn('is_primary', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Is Primary') + ->addIndex($installer->getIdxName('salesrule/coupon', array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('salesrule/coupon', array('rule_id', 'is_primary'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('rule_id', 'is_primary'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('salesrule/coupon', array('rule_id')), + array('rule_id')) + ->addForeignKey($installer->getFkName('salesrule/coupon', 'rule_id', 'salesrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('salesrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Salesrule Coupon'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/coupon_usage' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/coupon_usage')) + ->addColumn('coupon_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Coupon Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Id') + ->addColumn('times_used', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Times Used') + ->addIndex($installer->getIdxName('salesrule/coupon_usage', array('coupon_id')), + array('coupon_id')) + ->addIndex($installer->getIdxName('salesrule/coupon_usage', array('customer_id')), + array('customer_id')) + ->addForeignKey($installer->getFkName('salesrule/coupon_usage', 'coupon_id', 'salesrule/coupon', 'coupon_id'), + 'coupon_id', $installer->getTable('salesrule/coupon'), 'coupon_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('salesrule/coupon_usage', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Salesrule Coupon Usage'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/rule_customer' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/rule_customer')) + ->addColumn('rule_customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Customer Id') + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Rule Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer Id') + ->addColumn('times_used', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Times Used') + ->addIndex($installer->getIdxName('salesrule/rule_customer', array('rule_id', 'customer_id')), + array('rule_id', 'customer_id')) + ->addIndex($installer->getIdxName('salesrule/rule_customer', array('customer_id', 'rule_id')), + array('customer_id', 'rule_id')) + ->addForeignKey($installer->getFkName('salesrule/rule_customer', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('salesrule/rule_customer', 'rule_id', 'salesrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('salesrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Salesrule Customer'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/label' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/label')) + ->addColumn('label_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Label Id') + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Rule Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Label') + ->addIndex($installer->getIdxName('salesrule/label', array('rule_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('rule_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('salesrule/label', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('salesrule/label', array('rule_id')), + array('rule_id')) + ->addForeignKey($installer->getFkName('salesrule/label', 'rule_id', 'salesrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('salesrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('salesrule/label', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Salesrule Label'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/product_attribute' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/product_attribute')) + ->addColumn('rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Rule Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Website Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Customer Group Id') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Attribute Id') + ->addIndex($installer->getIdxName('salesrule/product_attribute', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('salesrule/product_attribute', array('customer_group_id')), + array('customer_group_id')) + ->addIndex($installer->getIdxName('salesrule/product_attribute', array('attribute_id')), + array('attribute_id')) + ->addForeignKey($installer->getFkName('salesrule/product_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('salesrule/product_attribute', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('salesrule/product_attribute', 'rule_id', 'salesrule/rule', 'rule_id'), + 'rule_id', $installer->getTable('salesrule/rule'), 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('salesrule/product_attribute', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Salesrule Product Attribute'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/coupon_aggregated' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/coupon_aggregated')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => false, + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('coupon_code', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Coupon Code') + ->addColumn('coupon_uses', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Coupon Uses') + ->addColumn('subtotal_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Subtotal Amount') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('total_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Amount') + ->addColumn('subtotal_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Subtotal Amount Actual') + ->addColumn('discount_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Discount Amount Actual') + ->addColumn('total_amount_actual', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Amount Actual') + ->addIndex($installer->getIdxName('salesrule/coupon_aggregated', array('period', 'store_id', 'order_status', 'coupon_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status', 'coupon_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('salesrule/coupon_aggregated', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('salesrule/coupon_aggregated', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Coupon Aggregated'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'salesrule/coupon_aggregated_order' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('salesrule/coupon_aggregated_order')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => false, + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Order Status') + ->addColumn('coupon_code', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + ), 'Coupon Code') + ->addColumn('coupon_uses', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Coupon Uses') + ->addColumn('subtotal_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Subtotal Amount') + ->addColumn('discount_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Discount Amount') + ->addColumn('total_amount', Varien_Db_Ddl_Table::TYPE_DECIMAL, array(12,4), array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Total Amount') + ->addIndex($installer->getIdxName('salesrule/coupon_aggregated_order', array('period', 'store_id', 'order_status', 'coupon_code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('period', 'store_id', 'order_status', 'coupon_code'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('salesrule/coupon_aggregated_order', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('salesrule/coupon_aggregated_order', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Coupon Aggregated Order'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-0.7.0.php index 100da10d8a..bf6b5c35b9 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-1.4.0.0.0.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-1.4.0.0.0.php index 78d448c59c..a8f1ed4af0 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-1.4.0.0.0.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-install-1.4.0.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.0-0.7.1.php index 1341215bbd..3ca4aaf977 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.1-0.7.2.php index e46ab46bfd..9ceb9f3c1f 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.10-0.7.11.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.10-0.7.11.php index 0d549a1530..dbf95a5439 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.10-0.7.11.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.10-0.7.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.11-0.7.12.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.11-0.7.12.php index cbe3a7f2ee..18c55bb551 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.11-0.7.12.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.11-0.7.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.2-0.7.3.php index ba2a8e766d..2ed6964806 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.3-0.7.4.php index 62227aa9a1..77e93b1220 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.4-0.7.5.php index d4c7d60b5a..e750aed4c9 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.5-0.7.6.php index f21f027fcc..802d6c0dbc 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.6-0.7.7.php index 8b6250d049..b23ac0b2c3 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.7-0.7.8.php index b153ed227c..dd69db4793 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.8-0.7.9.php index 6cdaad2041..1f69fa7cba 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.9-0.7.10.php index a5c7d68f2b..eaba3fd6cb 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php index 36c6937335..cce3d821a4 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.0-1.4.0.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php index cd65fee188..e3777c4d67 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.1-1.4.0.0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php index 11f8517afb..012e298396 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.2-1.4.0.0.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php index 978a3e9049..5f41aca548 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.3-1.4.0.0.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php index f47ad91dcc..2374e2264c 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.4-1.4.0.0.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php index f5c8fb14a7..123e4c91d4 100644 --- a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.4.0.0.5-1.4.0.0.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_SalesRule - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..553f257fb5 --- /dev/null +++ b/app/code/core/Mage/SalesRule/sql/salesrule_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,941 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/coupon_aggregated'), + 'FK_SALESTRULE_COUPON_AGGREGATED_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/coupon_aggregated_order'), + 'FK_SALESTRULE_COUPON_AGGREGATED_ORDER_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/coupon'), + 'FK_SALESRULE_COUPON_RULE_ID_SALESRULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/coupon_usage'), + 'FK_SALESRULE_CPN_CUST_CPN_ID_CUST_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/coupon_usage'), + 'FK_SALESRULE_CPN_CUST_CUST_ID_CUST_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/rule_customer'), + 'FK_SALESRULE_CUSTOMER_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/rule_customer'), + 'FK_SALESRULE_CUSTOMER_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/label'), + 'FK_SALESRULE_LABEL_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/label'), + 'FK_SALESRULE_LABEL_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/product_attribute'), + 'FK_SALESRULE_PRODUCT_ATTRIBUTE_ATTRIBUTE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/product_attribute'), + 'FK_SALESRULE_PRODUCT_ATTRIBUTE_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/product_attribute'), + 'FK_SALESRULE_PRODUCT_ATTRIBUTE_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('salesrule/product_attribute'), + 'FK_SALESRULE_PRODUCT_ATTRIBUTE_WEBSITE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_aggregated'), + 'UNQ_COUPON_AGGREGATED_PSOC' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_aggregated'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_aggregated_order'), + 'UNQ_COUPON_AGGREGATED_ORDER_PSOC' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_aggregated_order'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/rule'), + 'SORT_ORDER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon'), + 'UNQ_COUPON_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon'), + 'UNQ_RULE_MAIN_COUPON' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon'), + 'FK_SALESRULE_COUPON_RULE_ID_SALESRULE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_usage'), + 'FK_SALESRULE_COUPON_CUSTOMER_COUPON_ID_CUSTOMER_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/coupon_usage'), + 'FK_SALESRULE_COUPON_CUSTOMER_CUSTOMER_ID_CUSTOMER_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/rule_customer'), + 'RULE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/rule_customer'), + 'CUSTOMER_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'IDX_RULE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'IDX_STORE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'IDX_RULE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'UNQ_RULE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'FK_SALESRULE_LABEL_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/label'), + 'FK_SALESRULE_LABEL_RULE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/product_attribute'), + 'IDX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/product_attribute'), + 'IDX_CUSTOMER_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('salesrule/product_attribute'), + 'IDX_ATTRIBUTE' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('salesrule/rule') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Description' + ), + 'from_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'From Date' + ), + 'to_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'To Date' + ), + 'uses_per_customer' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Uses Per Customer' + ), + 'customer_group_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Customer Group Ids' + ), + 'is_active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Active' + ), + 'conditions_serialized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Conditions Serialized' + ), + 'actions_serialized' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '2M', + 'comment' => 'Actions Serialized' + ), + 'stop_rules_processing' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Stop Rules Processing' + ), + 'is_advanced' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Is Advanced' + ), + 'product_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Product Ids' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort Order' + ), + 'simple_action' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Simple Action' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'discount_qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Discount Qty' + ), + 'discount_step' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Discount Step' + ), + 'simple_free_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Simple Free Shipping' + ), + 'apply_to_shipping' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Apply To Shipping' + ), + 'times_used' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Times Used' + ), + 'is_rss' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Is Rss' + ), + 'website_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Website Ids' + ), + 'coupon_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Coupon Type' + ) + ), + 'comment' => 'Salesrule' + ), + $installer->getTable('salesrule/rule_customer') => array( + 'columns' => array( + 'rule_customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Customer Id' + ), + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Rule Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer Id' + ), + 'times_used' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Times Used' + ) + ), + 'comment' => 'Salesrule Customer' + ), + $installer->getTable('salesrule/label') => array( + 'columns' => array( + 'label_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Label Id' + ), + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Rule Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'label' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Label' + ) + ), + 'comment' => 'Salesrule Label' + ), + $installer->getTable('salesrule/coupon') => array( + 'columns' => array( + 'coupon_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Coupon Id' + ), + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Rule Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Code' + ), + 'usage_limit' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Usage Limit' + ), + 'usage_per_customer' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Usage Per Customer' + ), + 'times_used' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Times Used' + ), + 'expiration_date' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Expiration Date' + ), + 'is_primary' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Is Primary' + ) + ), + 'comment' => 'Salesrule Coupon' + ), + $installer->getTable('salesrule/coupon_usage') => array( + 'columns' => array( + 'coupon_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Coupon Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Id' + ), + 'times_used' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Times Used' + ) + ), + 'comment' => 'Salesrule Coupon Usage' + ), + $installer->getTable('salesrule/coupon_aggregated') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'nullable' => false, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'coupon_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Coupon Code' + ), + 'coupon_uses' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Coupon Uses' + ), + 'subtotal_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Subtotal Amount' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'total_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Amount' + ), + 'subtotal_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Subtotal Amount Actual' + ), + 'discount_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount Actual' + ), + 'total_amount_actual' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Amount Actual' + ) + ), + 'comment' => 'Coupon Aggregated' + ), + $installer->getTable('salesrule/coupon_aggregated_order') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'nullable' => false, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Order Status' + ), + 'coupon_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'comment' => 'Coupon Code' + ), + 'coupon_uses' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Coupon Uses' + ), + 'subtotal_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Subtotal Amount' + ), + 'discount_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Discount Amount' + ), + 'total_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Total Amount' + ) + ), + 'comment' => 'Coupon Aggregated Order' + ), + $installer->getTable('salesrule/product_attribute') => array( + 'columns' => array( + 'rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Rule Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Website Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Customer Group Id' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Attribute Id' + ) + ), + 'comment' => 'Salesrule Product Attribute' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_aggregated'), + $installer->getIdxName( + 'salesrule/coupon_aggregated', + array('period', 'store_id', 'order_status', 'coupon_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status', 'coupon_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_aggregated'), + $installer->getIdxName('salesrule/coupon_aggregated', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_aggregated_order'), + $installer->getIdxName( + 'salesrule/coupon_aggregated_order', + array('period', 'store_id', 'order_status', 'coupon_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'order_status', 'coupon_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_aggregated_order'), + $installer->getIdxName('salesrule/coupon_aggregated_order', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/rule'), + $installer->getIdxName('salesrule/rule', array('is_active', 'sort_order', 'to_date', 'from_date')), + array('is_active', 'sort_order', 'to_date', 'from_date') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon'), + $installer->getIdxName( + 'salesrule/coupon', + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon'), + $installer->getIdxName( + 'salesrule/coupon', + array('rule_id', 'is_primary'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('rule_id', 'is_primary'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon'), + $installer->getIdxName('salesrule/coupon', array('rule_id')), + array('rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_usage'), + $installer->getIdxName('salesrule/coupon_usage', array('coupon_id')), + array('coupon_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/coupon_usage'), + $installer->getIdxName('salesrule/coupon_usage', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/rule_customer'), + $installer->getIdxName('salesrule/rule_customer', array('rule_id', 'customer_id')), + array('rule_id', 'customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/rule_customer'), + $installer->getIdxName('salesrule/rule_customer', array('customer_id', 'rule_id')), + array('customer_id', 'rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/label'), + $installer->getIdxName( + 'salesrule/label', + array('rule_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('rule_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/label'), + $installer->getIdxName('salesrule/label', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/label'), + $installer->getIdxName('salesrule/label', array('rule_id')), + array('rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/product_attribute'), + $installer->getIdxName('salesrule/product_attribute', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/product_attribute'), + $installer->getIdxName('salesrule/product_attribute', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('salesrule/product_attribute'), + $installer->getIdxName('salesrule/product_attribute', array('attribute_id')), + array('attribute_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/coupon_aggregated', 'store_id', 'core/store', 'store_id'), + $installer->getTable('salesrule/coupon_aggregated'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/coupon_aggregated_order', 'store_id', 'core/store', 'store_id'), + $installer->getTable('salesrule/coupon_aggregated_order'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/coupon', 'rule_id', 'salesrule/rule', 'rule_id'), + $installer->getTable('salesrule/coupon'), + 'rule_id', + $installer->getTable('salesrule/rule'), + 'rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/coupon_usage', 'coupon_id', 'salesrule/coupon', 'coupon_id'), + $installer->getTable('salesrule/coupon_usage'), + 'coupon_id', + $installer->getTable('salesrule/coupon'), + 'coupon_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/coupon_usage', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('salesrule/coupon_usage'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/rule_customer', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('salesrule/rule_customer'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/rule_customer', 'rule_id', 'salesrule/rule', 'rule_id'), + $installer->getTable('salesrule/rule_customer'), + 'rule_id', + $installer->getTable('salesrule/rule'), + 'rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/label', 'rule_id', 'salesrule/rule', 'rule_id'), + $installer->getTable('salesrule/label'), + 'rule_id', + $installer->getTable('salesrule/rule'), + 'rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/label', 'store_id', 'core/store', 'store_id'), + $installer->getTable('salesrule/label'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/product_attribute', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('salesrule/product_attribute'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/product_attribute', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('salesrule/product_attribute'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/product_attribute', 'rule_id', 'salesrule/rule', 'rule_id'), + $installer->getTable('salesrule/product_attribute'), + 'rule_id', + $installer->getTable('salesrule/rule'), + 'rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('salesrule/product_attribute', 'website_id', 'core/website', 'website_id'), + $installer->getTable('salesrule/product_attribute'), + 'website_id', + $installer->getTable('core/website'), + 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Sendfriend/Block/Send.php b/app/code/core/Mage/Sendfriend/Block/Send.php index 338ad149db..74d0e88505 100644 --- a/app/code/core/Mage/Sendfriend/Block/Send.php +++ b/app/code/core/Mage/Sendfriend/Block/Send.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/Helper/Data.php b/app/code/core/Mage/Sendfriend/Helper/Data.php index 9c8475e2a0..0279d8a3ab 100644 --- a/app/code/core/Mage/Sendfriend/Helper/Data.php +++ b/app/code/core/Mage/Sendfriend/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend.php b/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend.php index a27595fd32..1b1e74ecaf 100644 --- a/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend.php +++ b/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,75 +32,6 @@ * @package Mage_Sendfriend * @author Magento Core Team */ -class Mage_Sendfriend_Model_Mysql4_Sendfriend extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sendfriend_Model_Mysql4_Sendfriend extends Mage_Sendfriend_Model_Resource_Sendfriend { - /** - * Initialize connection and table - * - */ - protected function _construct() - { - $this->_init('sendfriend/sendfriend', 'log_id'); - } - - /** - * Retrieve Sended Emails By Ip - * - * @param Mage_Sendfriend_Model_Sendfriend $object - * @param int $ip - * @param int $startTime - * @param int $websiteId - * @return int - */ - public function getSendCount($object, $ip, $startTime, $websiteId = null) - { - $select = $this->_getReadAdapter()->select() - ->from( - array('main_table' => $this->getTable('sendfriend')), - array('count' => new Zend_Db_Expr('count(*)'))) - ->where('ip=?', $ip) - ->where('time>=?', $startTime); - - if ($websiteId) { - $select->where('website_id=?', $websiteId); - } - - $row = $this->_getReadAdapter()->fetchRow($select); - return $row['count']; - } - - /** - * Add sended email by ip item - * - * @param int $ip - * @param int $startTime - * @param int $websiteId - * @return Mage_Sendfriend_Model_Mysql4_Sendfriend - */ - public function addSendItem($ip, $startTime, $websiteId) - { - $this->_getWriteAdapter()->insert( - $this->getTable('sendfriend'), - array( - 'ip' => $ip, - 'time' => $startTime, - 'website_id' => $websiteId - ) - ); - return $this; - } - - /** - * Delete Old logs - * - * @param int $time - * @return Mage_Sendfriend_Model_Mysql4_Sendfriend - */ - public function deleteLogsBefore($time) - { - $cond = $this->_getWriteAdapter()->quoteInto('time_getWriteAdapter()->delete($this->getMainTable(), $cond); - - return $this; - } } diff --git a/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend/Collection.php b/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend/Collection.php index ca8cf0e85c..c251bbc1e3 100644 --- a/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend/Collection.php +++ b/app/code/core/Mage/Sendfriend/Model/Mysql4/Sendfriend/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,14 +32,6 @@ * @package Mage_Sendfriend * @author Magento Core Team */ -class Mage_Sendfriend_Model_Mysql4_Sendfriend_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sendfriend_Model_Mysql4_Sendfriend_Collection extends Mage_Sendfriend_Model_Resource_Sendfriend_Collection { - /** - * Init resource collection - * - */ - protected function _construct() - { - $this->_init('sendfriend/sendfriend'); - } } diff --git a/app/code/core/Mage/Sendfriend/Model/Mysql4/Setup.php b/app/code/core/Mage/Sendfriend/Model/Mysql4/Setup.php index 254aef8b8a..4f5b062d45 100644 --- a/app/code/core/Mage/Sendfriend/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Sendfriend/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,6 +32,6 @@ * @package Mage_Sendfriend * @author Magento Core Team */ -class Mage_Sendfriend_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup +class Mage_Sendfriend_Model_Mysql4_Setup extends Mage_Sendfriend_Model_Resource_Setup { } diff --git a/app/code/core/Mage/Sendfriend/Model/Observer.php b/app/code/core/Mage/Sendfriend/Model/Observer.php index df4dc1a04e..ccb3b3267b 100644 --- a/app/code/core/Mage/Sendfriend/Model/Observer.php +++ b/app/code/core/Mage/Sendfriend/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend.php b/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend.php new file mode 100755 index 0000000000..d95a3c5508 --- /dev/null +++ b/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend.php @@ -0,0 +1,107 @@ + + */ +class Mage_Sendfriend_Model_Resource_Sendfriend extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and table + * + */ + protected function _construct() + { + $this->_init('sendfriend/sendfriend', 'log_id'); + } + + /** + * Retrieve Sended Emails By Ip + * + * @param Mage_Sendfriend_Model_Sendfriend $object + * @param int $ip + * @param int $startTime + * @param int $websiteId + * @return int + */ + public function getSendCount($object, $ip, $startTime, $websiteId = null) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), array('count' => new Zend_Db_Expr('count(*)'))) + ->where('ip=:ip + AND time>=:time + AND website_id=:website_id'); + $bind = array( + 'ip' => $ip, + 'time' => $startTime, + 'website_id' => (int)$websiteId, + ); + + $row = $adapter->fetchRow($select, $bind); + return $row['count']; + } + + /** + * Add sended email by ip item + * + * @param int $ip + * @param int $startTime + * @param int $websiteId + * @return Mage_Sendfriend_Model_Resource_Sendfriend + */ + public function addSendItem($ip, $startTime, $websiteId) + { + $this->_getWriteAdapter()->insert( + $this->getMainTable(), + array( + 'ip' => $ip, + 'time' => $startTime, + 'website_id' => $websiteId + ) + ); + return $this; + } + + /** + * Delete Old logs + * + * @param int $time + * @return Mage_Sendfriend_Model_Resource_Sendfriend + */ + public function deleteLogsBefore($time) + { + $cond = $this->_getWriteAdapter()->quoteInto('time_getWriteAdapter()->delete($this->getMainTable(), $cond); + + return $this; + } +} diff --git a/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend/Collection.php b/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend/Collection.php new file mode 100755 index 0000000000..c6a5dd72fb --- /dev/null +++ b/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sendfriend_Model_Resource_Sendfriend_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init resource collection + * + */ + protected function _construct() + { + $this->_init('sendfriend/sendfriend'); + } +} diff --git a/app/code/core/Mage/Sendfriend/Model/Resource/Setup.php b/app/code/core/Mage/Sendfriend/Model/Resource/Setup.php new file mode 100755 index 0000000000..001e7057e6 --- /dev/null +++ b/app/code/core/Mage/Sendfriend/Model/Resource/Setup.php @@ -0,0 +1,37 @@ + + */ +class Mage_Sendfriend_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/Sendfriend/Model/Sendfriend.php b/app/code/core/Mage/Sendfriend/Model/Sendfriend.php index ffc2ddf436..1e70d5202b 100644 --- a/app/code/core/Mage/Sendfriend/Model/Sendfriend.php +++ b/app/code/core/Mage/Sendfriend/Model/Sendfriend.php @@ -20,10 +20,24 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * SendFriend Log + * + * @method Mage_Sendfriend_Model_Resource_Sendfriend _getResource() + * @method Mage_Sendfriend_Model_Resource_Sendfriend getResource() + * @method int getIp() + * @method Mage_Sendfriend_Model_Sendfriend setIp(int $value) + * @method int getTime() + * @method Mage_Sendfriend_Model_Sendfriend setTime(int $value) + * + * @category Mage + * @package Mage_Sendfriend + * @author Magento Core Team + */ class Mage_Sendfriend_Model_Sendfriend extends Mage_Core_Model_Abstract { /** diff --git a/app/code/core/Mage/Sendfriend/controllers/ProductController.php b/app/code/core/Mage/Sendfriend/controllers/ProductController.php index 4aefb9de22..0f37dcc1de 100644 --- a/app/code/core/Mage/Sendfriend/controllers/ProductController.php +++ b/app/code/core/Mage/Sendfriend/controllers/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/etc/config.xml b/app/code/core/Mage/Sendfriend/etc/config.xml index d205730f97..cfeecf3537 100644 --- a/app/code/core/Mage/Sendfriend/etc/config.xml +++ b/app/code/core/Mage/Sendfriend/etc/config.xml @@ -21,42 +21,45 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.4 + 1.6.0.0 Mage_Sendfriend_Model - sendfriend_mysql4 + sendfriend_resource - - Mage_Sendfriend_Model_Mysql4 + + Mage_Sendfriend_Model_Resource + sendfriend_mysql4 sendfriend_mysql4 sendfriend_log
      -
      +
      - Mage_Sendfriend - Mage_Sendfriend_Model_Mysql4_Setup + Mage_Sendfriend + Mage_Sendfriend_Model_Resource_Setup - Mage_Sendfriend_Block + + Mage_Sendfriend_Block +
      - @@ -80,7 +82,6 @@ - @@ -118,7 +119,6 @@ - diff --git a/app/code/core/Mage/Sendfriend/etc/system.xml b/app/code/core/Mage/Sendfriend/etc/system.xml index 8bc6e2d43a..756af4194d 100644 --- a/app/code/core/Mage/Sendfriend/etc/system.xml +++ b/app/code/core/Mage/Sendfriend/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/install-1.6.0.0.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..8bc136df4b --- /dev/null +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/install-1.6.0.0.php @@ -0,0 +1,60 @@ +startSetup(); + +$table = $installer->getConnection() + ->newTable($installer->getTable('sendfriend/sendfriend')) + ->addColumn('log_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Log ID') + ->addColumn('ip', Varien_Db_Ddl_Table::TYPE_BIGINT, '20', array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer IP address') + ->addColumn('time', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Log time') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website ID') + ->addIndex($installer->getIdxName('sendfriend/sendfriend', 'ip'), 'ip') + ->addIndex($installer->getIdxName('sendfriend/sendfriend', 'time'), 'time') + ->setComment('Send to friend function log storage table'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-install-0.7.0.php index a166bd1879..c5d3427f8d 100644 --- a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.1-0.7.2.php index 3c103bf254..9f85c7ec53 100644 --- a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.2-0.7.3.php index 213bb2a99f..1dfd03a790 100644 --- a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.3-0.7.4.php index 99a67837ae..b84aeead40 100644 --- a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sendfriend - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..6ec3a80840 --- /dev/null +++ b/app/code/core/Mage/Sendfriend/sql/sendfriend_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,104 @@ +startSetup(); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('sendfriend/sendfriend'), + 'IDX_REMOTE_ADDR' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('sendfriend/sendfriend'), + 'IDX_LOG_TIME' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('sendfriend/sendfriend') => array( + 'columns' => array( + 'log_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Log ID' + ), + 'ip' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BIGINT, + 'length' => 20, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer IP address' + ), + 'time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Log time' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website ID' + ) + ), + 'comment' => 'Send to friend function log storage table', + 'engine' => 'InnoDB' + ) +); + +$installer->getConnection()->modifyTables($tables); + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('sendfriend/sendfriend'), + $installer->getIdxName('sendfriend/sendfriend', array('ip')), + array('ip') +); + +$installer->getConnection()->addIndex( + $installer->getTable('sendfriend/sendfriend'), + $installer->getIdxName('sendfriend/sendfriend', array('time')), + array('time') +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Shipping/Block/Tracking/Ajax.php b/app/code/core/Mage/Shipping/Block/Tracking/Ajax.php index 8716c55b47..80d900c843 100644 --- a/app/code/core/Mage/Shipping/Block/Tracking/Ajax.php +++ b/app/code/core/Mage/Shipping/Block/Tracking/Ajax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php index 9a944f8c36..30e2f417c3 100644 --- a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php +++ b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Exception.php b/app/code/core/Mage/Shipping/Exception.php index 5d5724017d..737caa97f3 100644 --- a/app/code/core/Mage/Shipping/Exception.php +++ b/app/code/core/Mage/Shipping/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Helper/Data.php b/app/code/core/Mage/Shipping/Helper/Data.php index e17e253f68..e0f951c53e 100644 --- a/app/code/core/Mage/Shipping/Helper/Data.php +++ b/app/code/core/Mage/Shipping/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Abstract.php b/app/code/core/Mage/Shipping/Model/Carrier/Abstract.php index 2361607041..2caf89f60b 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Abstract.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php b/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php index 05d9faeb7b..e225934be3 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Freeshipping.php b/app/code/core/Mage/Shipping/Model/Carrier/Freeshipping.php index ac806704e1..d2ef1e3ebe 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Freeshipping.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Freeshipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Interface.php b/app/code/core/Mage/Shipping/Model/Carrier/Interface.php index c4aa838118..9bc201dac3 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Interface.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Pickup.php b/app/code/core/Mage/Shipping/Model/Carrier/Pickup.php index e647d82ffa..53a708049e 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Pickup.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Pickup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php b/app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php index 286af389db..fc1b184a78 100644 --- a/app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php +++ b/app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Config.php b/app/code/core/Mage/Shipping/Model/Config.php index 4af1f0aebb..4b81e4d998 100644 --- a/app/code/core/Mage/Shipping/Model/Config.php +++ b/app/code/core/Mage/Shipping/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Info.php b/app/code/core/Mage/Shipping/Model/Info.php index 95010123f3..83b77ca8bb 100644 --- a/app/code/core/Mage/Shipping/Model/Info.php +++ b/app/code/core/Mage/Shipping/Model/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate.php b/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate.php index ba19d9db93..0b15309c4f 100644 --- a/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate.php +++ b/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate.php @@ -20,440 +20,18 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Shipping table rates * - * @category Mage - * @package Mage_Shipping + * @category Mage + * @package Mage_Shipping * @author Magento Core Team */ -class Mage_Shipping_Model_Mysql4_Carrier_Tablerate extends Mage_Core_Model_Mysql4_Abstract +class Mage_Shipping_Model_Mysql4_Carrier_Tablerate extends Mage_Shipping_Model_Resource_Carrier_Tablerate { - /** - * Import table rates website ID - * - * @var int - */ - protected $_importWebsiteId = 0; - - /** - * Errors in import process - * - * @var array - */ - protected $_importErrors = array(); - - /** - * Count of imported table rates - * - * @var int - */ - protected $_importedRows = 0; - - /** - * Array of unique table rate keys to protect from duplicates - * - * @var array - */ - protected $_importUniqueHash = array(); - - /** - * Array of countries keyed by iso2 code - * - * @var array - */ - protected $_importIso2Countries; - - /** - * Array of countries keyed by iso3 code - * - * @var array - */ - protected $_importIso3Countries; - - /** - * Associative array of countries and regions - * [country_id][region_code] = region_id - * - * @var array - */ - protected $_importRegions; - - /** - * Import Table Rate condition name - * - * @var string - */ - protected $_importConditionName; - - /** - * Array of condition full names - * - * @var array - */ - protected $_conditionFullNames = array(); - - /** - * Define main table and id field name - * - * @return void - */ - protected function _construct() - { - $this->_init('shipping/tablerate', 'pk'); - } - - /** - * Return table rate array or false by rate request - * - * @param Mage_Shipping_Model_Rate_Request $request - * @return array|false - */ - public function getRate(Mage_Shipping_Model_Rate_Request $request) - { - $adapter = $this->_getReadAdapter(); - $bind = array( - ':website_id' => (int)$request->getWebsiteId(), - ':country_id' => $request->getDestCountryId(), - ':region_id' => $request->getDestRegionId(), - ':postcode' => $request->getDestPostcode() - ); - $select = $adapter->select() - ->from($this->getMainTable()) - ->where('website_id=:website_id') - ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC')) - ->limit(1); - - // render destination condition - $orWhere = '(' . implode(') OR (', array( - "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode", - "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", - "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", - "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode", - "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''", - )) . ')'; - $select->where($orWhere); - - // render condition by condition name - if (is_array($request->getConditionName())) { - $orWhere = array(); - $i = 0; - foreach ($request->getConditionName() as $conditionName) { - $bindNameKey = sprintf(':condition_name_%d', $i); - $bindValueKey = sprintf(':condition_value_%d', $i); - $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})"; - $bind[$bindNameKey] = $conditionName; - $bind[$bindValueKey] = $request->getData($conditionName); - $i ++; - } - - if ($orWhere) { - $select->where(implode(' OR ', $orWhere)); - } - } else { - $bind[':condition_name'] = $request->getConditionName(); - $bind[':condition_value'] = $request->getData($request->getConditionName()); - - $select->where('condition_name = :condition_name'); - $select->where('condition_value <= :condition_value'); - } - - return $adapter->fetchRow($select, $bind); - } - - /** - * Upload table rate file and import data from it - * - * @param Varien_Object $object - * @throws Mage_Core_Exception - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate - */ - public function uploadAndImport(Varien_Object $object) - { - if (empty($_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'])) { - return $this; - } - - $csvFile = $_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value']; - $website = Mage::app()->getWebsite($object->getScopeId()); - - $this->_importWebsiteId = (int)$website->getId(); - $this->_importUniqueHash = array(); - $this->_importErrors = array(); - $this->_importedRows = 0; - - $io = new Varien_Io_File(); - $info = pathinfo($csvFile); - $io->open(array('path' => $info['dirname'])); - $io->streamOpen($info['basename'], 'r'); - - // check and skip headers - $headers = $io->streamReadCsv(); - if ($headers === false || count($headers) < 5) { - $io->streamClose(); - Mage::throwException(Mage::helper('shipping')->__('Invalid Table Rates File Format')); - } - - if ($object->getData('groups/tablerate/fields/condition_name/inherit') == '1') { - $conditionName = (string)Mage::getConfig()->getNode('default/carriers/tablerate/condition_name'); - } else { - $conditionName = $object->getData('groups/tablerate/fields/condition_name/value'); - } - $this->_importConditionName = $conditionName; - - $adapter = $this->_getWriteAdapter(); - $adapter->beginTransaction(); - - try { - $rowNumber = 1; - $importData = array(); - - $this->_loadDirectoryCountries(); - $this->_loadDirectoryRegions(); - - // delete old data by website and condition name - $condition = array( - 'website_id = ?' => $this->_importWebsiteId, - 'condition_name = ?' => $this->_importConditionName - ); - $adapter->delete($this->getMainTable(), $condition); - - while (false !== ($csvLine = $io->streamReadCsv())) { - $rowNumber ++; - - if (empty($csvLine)) { - continue; - } - - $row = $this->_getImportRow($csvLine, $rowNumber); - if ($row !== false) { - $importData[] = $row; - } - - if (count($importData) == 5000) { - $this->_saveImportData($importData); - $importData = array(); - } - } - $this->_saveImportData($importData); - $io->streamClose(); - } catch (Mage_Core_Exception $e) { - $adapter->rollback(); - $io->streamClose(); - Mage::throwException($e->getMessage()); - } catch (Exception $e) { - $adapter->rollback(); - $io->streamClose(); - Mage::logException($e); - Mage::throwException(Mage::helper('shipping')->__('An error occurred while import table rates.')); - } - - $adapter->commit(); - - if ($this->_importErrors) { - $error = Mage::helper('shipping')->__('%1$d records have been imported. See the following list of errors for each record that has not been imported: %2$s', - $this->_importedRows, implode(" \n", $this->_importErrors)); - Mage::throwException($error); - } - - return $this; - } - - /** - * Load directory countries - * - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate - */ - protected function _loadDirectoryCountries() - { - if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) { - return $this; - } - - $this->_importIso2Countries = array(); - $this->_importIso3Countries = array(); - - /** @var $collection Mage_Directory_Model_Mysql4_Country_Collection */ - $collection = Mage::getResourceModel('directory/country_collection'); - foreach ($collection->getData() as $row) { - $this->_importIso2Countries[$row['iso2_code']] = $row['country_id']; - $this->_importIso3Countries[$row['iso3_code']] = $row['country_id']; - } - - return $this; - } - - /** - * Load directory regions - * - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate - */ - protected function _loadDirectoryRegions() - { - if (!is_null($this->_importRegions)) { - return $this; - } - - $this->_importRegions = array(); - - /** @var $collection Mage_Directory_Model_Mysql4_Region_Collection */ - $collection = Mage::getResourceModel('directory/region_collection'); - foreach ($collection->getData() as $row) { - $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id']; - } - - return $this; - } - - /** - * Return import condition full name by condition name code - * - * @return string - */ - protected function _getConditionFullName($conditionName) - { - if (!isset($this->_conditionFullNames[$conditionName])) { - $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName); - $this->_conditionFullNames[$conditionName] = $name; - } - - return $this->_conditionFullNames[$conditionName]; - } - - /** - * Validate row for import and return table rate array or false - * Error will be add to _importErrors array - * - * @param array $row - * @param int $rowNumber - * @return array|false - */ - protected function _getImportRow($row, $rowNumber = 0) - { - // validate row - if (count($row) < 5) { - $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Table Rates format in the Row #%s', - $rowNumber); - return false; - } - // validate country - if (isset($this->_importIso2Countries[$row[0]])) { - $countryId = $this->_importIso2Countries[$row[0]]; - } else if (isset($this->_importIso3Countries[$row[0]])) { - $countryId = $this->_importIso3Countries[$row[0]]; - } else if ($row[0] == '*' || $row[0] == '') { - $countryId = '0'; - } else { - $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Country "%s" in the Row #%s.', - $row[0], $rowNumber); - return false; - } - - // validate region - if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) { - $regionId = $this->_importRegions[$countryId][$row[1]]; - } else if ($row[1] == '*' || $row[1] == '') { - $regionId = 0; - } else { - $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Region/State "%s" in the Row #%s.', - $row[1], $rowNumber); - return false; - } - - // detect zip code - if ($row[2] == '*' || $row[2] == '') { - $zipCode = ''; - } else { - $zipCode = $row[2]; - } - - // validate condition value - $value = $this->_parseDecimalValue($row[3]); - if ($value === false) { - $this->_importErrors[] = Mage::helper('shipping')->__('Invalid %s "%s" in the Row #%s.', - $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber); - return false; - } - - // validate price - $price = $this->_parseDecimalValue($row[4]); - if ($price === false) { - $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Shipping Price "%s" in the Row #%s.', - $row[4], $rowNumber); - return false; - } - - // protect from duplicate - $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value); - if (isset($this->_importUniqueHash[$hash])) { - $this->_importErrors[] = Mage::helper('shipping')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', - $rowNumber, $row[0], $row[1], $zipCode, $value); - return false; - } - $this->_importUniqueHash[$hash] = true; - - return array( - $this->_importWebsiteId, // website_id - $countryId, // dest_country_id - $regionId, // dest_region_id, - $zipCode, // dest_zip - $this->_importConditionName,// condition_name, - $value, // condition_value - $price // price - ); - } - - /** - * Save import data batch - * - * @param array $data - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate - */ - protected function _saveImportData(array $data) - { - if (!empty($data)) { - $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', - 'condition_name', 'condition_value', 'price'); - $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data); - $this->_importedRows += count($data); - } - - return $this; - } - - /** - * Parse and validate positive decimal value - * Return false if value is not decimal or is not positive - * - * @param string $value - * @return bool|float - */ - protected function _parseDecimalValue($value) - { - if (!is_numeric($value)) { - return false; - } - $value = (float)sprintf('%.4F', $value); - if ($value < 0.0000) { - return false; - } - return $value; - } - - /** - * Parse and validate positive decimal value - * - * @see Mage_Shipping_Model_Mysql4_Carrier_Tablerate::_parseDecimalValue() - * @deprecated since 1.4.1.0 - * @param string $value - * @return bool|float - */ - protected function _isPositiveDecimalNumber($value) - { - return $this->_parseDecimalValue($value); - } } diff --git a/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate/Collection.php b/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate/Collection.php index 6f0a6de817..4778e31317 100644 --- a/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate/Collection.php +++ b/app/code/core/Mage/Shipping/Model/Mysql4/Carrier/Tablerate/Collection.php @@ -20,107 +20,19 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Shipping table rates collection * - * @category Mage - * @package Mage_Shipping + * @category Mage + * @package Mage_Shipping * @author Magento Core Team */ -class Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection + extends Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection { - /** - * main table name - * - * @deprecated since 1.4.1.0 - * @var string - */ - protected $_shipTable; - - /** - * directory/country table name - * - * @var string - */ - protected $_countryTable; - - /** - * directory/country_region table name - * - * @var string - */ - protected $_regionTable; - - /** - * Define resource model and item - * - */ - protected function _construct() - { - $this->_init('shipping/carrier_tablerate'); - $this->_shipTable = $this->getMainTable(); - $this->_countryTable = $this->getTable('directory/country'); - $this->_regionTable = $this->getTable('directory/country_region'); - } - - /** - * Initialize select, add country iso3 code and region name - * - * @return void - */ - public function _initSelect() - { - parent::_initSelect(); - - $this->_select - ->joinLeft( - array('country_table' => $this->_countryTable), - 'country_table.country_id = main_table.dest_country_id', - array('dest_country' => 'iso3_code')) - ->joinLeft( - array('region_table' => $this->_regionTable), - 'region_table.region_id = main_table.dest_region_id', - array('dest_region' => 'code')); - - $this->addOrder('dest_country', self::SORT_ORDER_ASC); - $this->addOrder('dest_region', self::SORT_ORDER_ASC); - $this->addOrder('dest_zip', self::SORT_ORDER_ASC); - } - - /** - * Add website filter to collection - * - * @param int $websiteId - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection - */ - public function setWebsiteFilter($websiteId) - { - return $this->addFieldToFilter('website_id', $websiteId); - } - - /** - * Add condition name (code) filter to collection - * - * @param string $conditionName - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection - */ - public function setConditionFilter($conditionName) - { - return $this->addFieldToFilter('condition_name', $conditionName); - } - - /** - * Add country filter to collection - * - * @param string $countryId - * @return Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection - */ - public function setCountryFilter($countryId) - { - return $this->addFieldToFilter('dest_country_id', $countryId); - } } diff --git a/app/code/core/Mage/Shipping/Model/Rate/Abstract.php b/app/code/core/Mage/Shipping/Model/Rate/Abstract.php index 5c0b0d9d7f..8125a3f8dd 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Abstract.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Rate/Request.php b/app/code/core/Mage/Shipping/Model/Rate/Request.php index 5b6fce56d5..7990f862e3 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Request.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result.php b/app/code/core/Mage/Shipping/Model/Rate/Result.php index 5572656e9a..fc6d23394c 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result/Abstract.php b/app/code/core/Mage/Shipping/Model/Rate/Result/Abstract.php index aa20a4def0..91975e7c51 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result/Abstract.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result/Error.php b/app/code/core/Mage/Shipping/Model/Rate/Result/Error.php index 289464a921..e0a3704e5e 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result/Error.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result/Error.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result/Method.php b/app/code/core/Mage/Shipping/Model/Rate/Result/Method.php index 8c4c0638f9..9f2e454970 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result/Method.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate.php b/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate.php new file mode 100755 index 0000000000..7ca3261f4e --- /dev/null +++ b/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate.php @@ -0,0 +1,466 @@ + + */ +class Mage_Shipping_Model_Resource_Carrier_Tablerate extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Import table rates website ID + * + * @var int + */ + protected $_importWebsiteId = 0; + + /** + * Errors in import process + * + * @var array + */ + protected $_importErrors = array(); + + /** + * Count of imported table rates + * + * @var int + */ + protected $_importedRows = 0; + + /** + * Array of unique table rate keys to protect from duplicates + * + * @var array + */ + protected $_importUniqueHash = array(); + + /** + * Array of countries keyed by iso2 code + * + * @var array + */ + protected $_importIso2Countries; + + /** + * Array of countries keyed by iso3 code + * + * @var array + */ + protected $_importIso3Countries; + + /** + * Associative array of countries and regions + * [country_id][region_code] = region_id + * + * @var array + */ + protected $_importRegions; + + /** + * Import Table Rate condition name + * + * @var string + */ + protected $_importConditionName; + + /** + * Array of condition full names + * + * @var array + */ + protected $_conditionFullNames = array(); + + /** + * Define main table and id field name + * + * @return void + */ + protected function _construct() + { + $this->_init('shipping/tablerate', 'pk'); + } + + /** + * Return table rate array or false by rate request + * + * @param Mage_Shipping_Model_Rate_Request $request + * @return array + */ + public function getRate(Mage_Shipping_Model_Rate_Request $request) + { + $adapter = $this->_getReadAdapter(); + $bind = array( + ':website_id' => (int)$request->getWebsiteId(), + ':country_id' => $request->getDestCountryId(), + ':region_id' => (int)$request->getDestRegionId(), + ':postcode' => $request->getDestPostcode() + ); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('website_id = :website_id') + ->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC')) + ->limit(1); + + // render destination condition + $orWhere = '(' . implode(') OR (', array( + "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode", + "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", + "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", + "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode", + "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'", + "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'", + )) . ')'; + $select->where($orWhere); + + // render condition by condition name + if (is_array($request->getConditionName())) { + $orWhere = array(); + $i = 0; + foreach ($request->getConditionName() as $conditionName) { + $bindNameKey = sprintf(':condition_name_%d', $i); + $bindValueKey = sprintf(':condition_value_%d', $i); + $orWhere[] = "(condition_name = {$bindNameKey} AND condition_value <= {$bindValueKey})"; + $bind[$bindNameKey] = $conditionName; + $bind[$bindValueKey] = $request->getData($conditionName); + $i++; + } + + if ($orWhere) { + $select->where(implode(' OR ', $orWhere)); + } + } else { + $bind[':condition_name'] = $request->getConditionName(); + $bind[':condition_value'] = $request->getData($request->getConditionName()); + + $select->where('condition_name = :condition_name'); + $select->where('condition_value <= :condition_value'); + } + + $result = $adapter->fetchRow($select, $bind); + // normalize destination zip code + if ($result && $result['dest_zip'] == '*') { + $result['dest_zip'] = ''; + } + return $result; + } + + /** + * Upload table rate file and import data from it + * + * @param Varien_Object $object + * @throws Mage_Core_Exception + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate + */ + public function uploadAndImport(Varien_Object $object) + { + if (empty($_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'])) { + return $this; + } + + $csvFile = $_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value']; + $website = Mage::app()->getWebsite($object->getScopeId()); + + $this->_importWebsiteId = (int)$website->getId(); + $this->_importUniqueHash = array(); + $this->_importErrors = array(); + $this->_importedRows = 0; + + $io = new Varien_Io_File(); + $info = pathinfo($csvFile); + $io->open(array('path' => $info['dirname'])); + $io->streamOpen($info['basename'], 'r'); + + // check and skip headers + $headers = $io->streamReadCsv(); + if ($headers === false || count($headers) < 5) { + $io->streamClose(); + Mage::throwException(Mage::helper('shipping')->__('Invalid Table Rates File Format')); + } + + if ($object->getData('groups/tablerate/fields/condition_name/inherit') == '1') { + $conditionName = (string)Mage::getConfig()->getNode('default/carriers/tablerate/condition_name'); + } else { + $conditionName = $object->getData('groups/tablerate/fields/condition_name/value'); + } + $this->_importConditionName = $conditionName; + + $adapter = $this->_getWriteAdapter(); + $adapter->beginTransaction(); + + try { + $rowNumber = 1; + $importData = array(); + + $this->_loadDirectoryCountries(); + $this->_loadDirectoryRegions(); + + // delete old data by website and condition name + $condition = array( + 'website_id = ?' => $this->_importWebsiteId, + 'condition_name = ?' => $this->_importConditionName + ); + $adapter->delete($this->getMainTable(), $condition); + + while (false !== ($csvLine = $io->streamReadCsv())) { + $rowNumber ++; + + if (empty($csvLine)) { + continue; + } + + $row = $this->_getImportRow($csvLine, $rowNumber); + if ($row !== false) { + $importData[] = $row; + } + + if (count($importData) == 5000) { + $this->_saveImportData($importData); + $importData = array(); + } + } + $this->_saveImportData($importData); + $io->streamClose(); + } catch (Mage_Core_Exception $e) { + $adapter->rollback(); + $io->streamClose(); + Mage::throwException($e->getMessage()); + } catch (Exception $e) { + $adapter->rollback(); + $io->streamClose(); + Mage::logException($e); + Mage::throwException(Mage::helper('shipping')->__('An error occurred while import table rates.')); + } + + $adapter->commit(); + + if ($this->_importErrors) { + $error = Mage::helper('shipping')->__('%1$d records have been imported. See the following list of errors for each record that has not been imported: %2$s', + $this->_importedRows, implode(" \n", $this->_importErrors)); + Mage::throwException($error); + } + + return $this; + } + + /** + * Load directory countries + * + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate + */ + protected function _loadDirectoryCountries() + { + if (!is_null($this->_importIso2Countries) && !is_null($this->_importIso3Countries)) { + return $this; + } + + $this->_importIso2Countries = array(); + $this->_importIso3Countries = array(); + + /** @var $collection Mage_Directory_Model_Resource_Country_Collection */ + $collection = Mage::getResourceModel('directory/country_collection'); + foreach ($collection->getData() as $row) { + $this->_importIso2Countries[$row['iso2_code']] = $row['country_id']; + $this->_importIso3Countries[$row['iso3_code']] = $row['country_id']; + } + + return $this; + } + + /** + * Load directory regions + * + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate + */ + protected function _loadDirectoryRegions() + { + if (!is_null($this->_importRegions)) { + return $this; + } + + $this->_importRegions = array(); + + /** @var $collection Mage_Directory_Model_Resource_Region_Collection */ + $collection = Mage::getResourceModel('directory/region_collection'); + foreach ($collection->getData() as $row) { + $this->_importRegions[$row['country_id']][$row['code']] = (int)$row['region_id']; + } + + return $this; + } + + /** + * Return import condition full name by condition name code + * + * @param string $conditionName + * @return string + */ + protected function _getConditionFullName($conditionName) + { + if (!isset($this->_conditionFullNames[$conditionName])) { + $name = Mage::getSingleton('shipping/carrier_tablerate')->getCode('condition_name_short', $conditionName); + $this->_conditionFullNames[$conditionName] = $name; + } + + return $this->_conditionFullNames[$conditionName]; + } + + /** + * Validate row for import and return table rate array or false + * Error will be add to _importErrors array + * + * @param array $row + * @param int $rowNumber + * @return array|false + */ + protected function _getImportRow($row, $rowNumber = 0) + { + // validate row + if (count($row) < 5) { + $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Table Rates format in the Row #%s', + $rowNumber); + return false; + } + // validate country + if (isset($this->_importIso2Countries[$row[0]])) { + $countryId = $this->_importIso2Countries[$row[0]]; + } elseif (isset($this->_importIso3Countries[$row[0]])) { + $countryId = $this->_importIso3Countries[$row[0]]; + } elseif ($row[0] == '*' || $row[0] == '') { + $countryId = '0'; + } else { + $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Country "%s" in the Row #%s.', + $row[0], $rowNumber); + return false; + } + + // validate region + if ($countryId != '0' && isset($this->_importRegions[$countryId][$row[1]])) { + $regionId = $this->_importRegions[$countryId][$row[1]]; + } elseif ($row[1] == '*' || $row[1] == '') { + $regionId = 0; + } else { + $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Region/State "%s" in the Row #%s.', + $row[1], $rowNumber); + return false; + } + + // detect zip code + if ($row[2] == '*' || $row[2] == '') { + $zipCode = '*'; + } else { + $zipCode = $row[2]; + } + + // validate condition value + $value = $this->_parseDecimalValue($row[3]); + if ($value === false) { + $this->_importErrors[] = Mage::helper('shipping')->__('Invalid %s "%s" in the Row #%s.', + $this->_getConditionFullName($this->_importConditionName), $row[3], $rowNumber); + return false; + } + + // validate price + $price = $this->_parseDecimalValue($row[4]); + if ($price === false) { + $this->_importErrors[] = Mage::helper('shipping')->__('Invalid Shipping Price "%s" in the Row #%s.', + $row[4], $rowNumber); + return false; + } + + // protect from duplicate + $hash = sprintf("%s-%d-%s-%F", $countryId, $regionId, $zipCode, $value); + if (isset($this->_importUniqueHash[$hash])) { + $this->_importErrors[] = Mage::helper('shipping')->__('Duplicate Row #%s (Country "%s", Region/State "%s", Zip "%s" and Value "%s").', + $rowNumber, $row[0], $row[1], $zipCode, $value); + return false; + } + $this->_importUniqueHash[$hash] = true; + + return array( + $this->_importWebsiteId, // website_id + $countryId, // dest_country_id + $regionId, // dest_region_id, + $zipCode, // dest_zip + $this->_importConditionName,// condition_name, + $value, // condition_value + $price // price + ); + } + + /** + * Save import data batch + * + * @param array $data + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate + */ + protected function _saveImportData(array $data) + { + if (!empty($data)) { + $columns = array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', + 'condition_name', 'condition_value', 'price'); + $this->_getWriteAdapter()->insertArray($this->getMainTable(), $columns, $data); + $this->_importedRows += count($data); + } + + return $this; + } + + /** + * Parse and validate positive decimal value + * Return false if value is not decimal or is not positive + * + * @param string $value + * @return bool|float + */ + protected function _parseDecimalValue($value) + { + if (!is_numeric($value)) { + return false; + } + $value = (float)sprintf('%.4F', $value); + if ($value < 0.0000) { + return false; + } + return $value; + } + + /** + * Parse and validate positive decimal value + * + * @see self::_parseDecimalValue() + * @deprecated since 1.4.1.0 + * @param string $value + * @return bool|float + */ + protected function _isPositiveDecimalNumber($value) + { + return $this->_parseDecimalValue($value); + } +} diff --git a/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate/Collection.php b/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate/Collection.php new file mode 100755 index 0000000000..bceaafb924 --- /dev/null +++ b/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate/Collection.php @@ -0,0 +1,126 @@ + + */ +class Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * main table name + * + * @deprecated since 1.4.1.0 + * @var string + */ + protected $_shipTable; + + /** + * directory/country table name + * + * @var string + */ + protected $_countryTable; + + /** + * directory/country_region table name + * + * @var string + */ + protected $_regionTable; + + /** + * Define resource model and item + * + */ + protected function _construct() + { + $this->_init('shipping/carrier_tablerate'); + $this->_shipTable = $this->getMainTable(); + $this->_countryTable = $this->getTable('directory/country'); + $this->_regionTable = $this->getTable('directory/country_region'); + } + + /** + * Initialize select, add country iso3 code and region name + * + * @return void + */ + public function _initSelect() + { + parent::_initSelect(); + + $this->_select + ->joinLeft( + array('country_table' => $this->_countryTable), + 'country_table.country_id = main_table.dest_country_id', + array('dest_country' => 'iso3_code')) + ->joinLeft( + array('region_table' => $this->_regionTable), + 'region_table.region_id = main_table.dest_region_id', + array('dest_region' => 'code')); + + $this->addOrder('dest_country', self::SORT_ORDER_ASC); + $this->addOrder('dest_region', self::SORT_ORDER_ASC); + $this->addOrder('dest_zip', self::SORT_ORDER_ASC); + } + + /** + * Add website filter to collection + * + * @param int $websiteId + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection + */ + public function setWebsiteFilter($websiteId) + { + return $this->addFieldToFilter('website_id', $websiteId); + } + + /** + * Add condition name (code) filter to collection + * + * @param string $conditionName + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection + */ + public function setConditionFilter($conditionName) + { + return $this->addFieldToFilter('condition_name', $conditionName); + } + + /** + * Add country filter to collection + * + * @param string $countryId + * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection + */ + public function setCountryFilter($countryId) + { + return $this->addFieldToFilter('dest_country_id', $countryId); + } +} diff --git a/app/code/core/Mage/Shipping/Model/Rule/Condition/Dest/Country.php b/app/code/core/Mage/Shipping/Model/Rule/Condition/Dest/Country.php deleted file mode 100644 index 954fa7b860..0000000000 --- a/app/code/core/Mage/Shipping/Model/Rule/Condition/Dest/Country.php +++ /dev/null @@ -1,31 +0,0 @@ - diff --git a/app/code/core/Mage/Shipping/etc/config.xml b/app/code/core/Mage/Shipping/etc/config.xml index d430f7d6b5..ffad8c882e 100644 --- a/app/code/core/Mage/Shipping/etc/config.xml +++ b/app/code/core/Mage/Shipping/etc/config.xml @@ -21,30 +21,31 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.0 + 1.6.0.0 Mage_Shipping_Model - shipping_mysql4 + shipping_resource - - Mage_Shipping_Model_Mysql4 + + Mage_Shipping_Model_Resource + shipping_mysql4 shipping_tablerate
      -
      +
      @@ -126,21 +127,18 @@ - - US 90034 12 - 1 @@ -153,7 +151,6 @@ This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. F - 0 0 @@ -163,7 +160,6 @@ Free Shipping This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. - 0 0 diff --git a/app/code/core/Mage/Shipping/etc/system.xml b/app/code/core/Mage/Shipping/etc/system.xml index f7a5ae2420..3f6eba0c5a 100644 --- a/app/code/core/Mage/Shipping/etc/system.xml +++ b/app/code/core/Mage/Shipping/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Shipping/sql/shipping_setup/install-1.6.0.0.php b/app/code/core/Mage/Shipping/sql/shipping_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..e7abec0eed --- /dev/null +++ b/app/code/core/Mage/Shipping/sql/shipping_setup/install-1.6.0.0.php @@ -0,0 +1,79 @@ +startSetup(); + +/** + * Create table 'shipping/tablerate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('shipping/tablerate')) + ->addColumn('pk', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Primary key') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Website Id') + ->addColumn('dest_country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 4, array( + 'nullable' => false, + 'default' => '0', + ), 'Destination coutry ISO/2 or ISO/3 code') + ->addColumn('dest_region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Destination Region Id') + ->addColumn('dest_zip', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array( + 'nullable' => false, + 'default' => '*', + ), 'Destination Post Code (Zip)') + ->addColumn('condition_name', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array( + 'nullable' => false, + ), 'Rate Condition name') + ->addColumn('condition_value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Rate condition value') + ->addColumn('price', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Price') + ->addColumn('cost', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Cost') + ->addIndex($installer->getIdxName('shipping/tablerate', array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'condition_name', 'condition_value'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'condition_name', 'condition_value'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->setComment('Shipping Tablerate'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-install-0.7.0.php index 7919ea58ce..542f18222f 100644 --- a/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Shipping - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..7f5aa58018 --- /dev/null +++ b/app/code/core/Mage/Shipping/sql/shipping_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,132 @@ +startSetup(); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('shipping/tablerate'), + 'DEST_COUNTRY' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('shipping/tablerate') => array( + 'columns' => array( + 'pk' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Primary key' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'dest_country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 4, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Destination coutry ISO/2 or ISO/3 code' + ), + 'dest_region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Destination Region Id' + ), + 'dest_zip' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 10, + 'nullable' => false, + 'default' => '*', + 'comment' => 'Destination Post Code (Zip)' + ), + 'condition_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 20, + 'nullable' => false, + 'comment' => 'Rate Condition name' + ), + 'condition_value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Rate condition value' + ), + 'price' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Price' + ), + 'cost' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Cost' + ) + ), + 'comment' => 'Shipping Tablerate' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('shipping/tablerate'), + $installer->getIdxName( + 'shipping/tablerate', + array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'condition_name', 'condition_value'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('website_id', 'dest_country_id', 'dest_region_id', 'dest_zip', 'condition_name', 'condition_value'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Sitemap/Helper/Data.php b/app/code/core/Mage/Sitemap/Helper/Data.php index 970b6e8e3c..1cf500a0e0 100644 --- a/app/code/core/Mage/Sitemap/Helper/Data.php +++ b/app/code/core/Mage/Sitemap/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Category.php b/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Category.php index a71cad3a84..d299a03773 100644 --- a/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Category.php +++ b/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Category.php @@ -20,174 +20,18 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sitemap resource catalog collection model * - * @category Mage - * @package Mage_Sitemap + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ - -class Mage_Sitemap_Model_Mysql4_Catalog_Category extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sitemap_Model_Mysql4_Catalog_Category extends Mage_Sitemap_Model_Resource_Catalog_Category { - /** - * Collection Zend Db select - * - * @var Zend_Db_Select - */ - protected $_select; - - /** - * Attribute cache - * - * @var array - */ - protected $_attributesCache = array(); - - /** - * Init resource model (catalog/category) - */ - protected function _construct() - { - $this->_init('catalog/category', 'entity_id'); - } - - /** - * Get category collection array - * - * @return array - */ - public function getCollection($storeId) - { - $categories = array(); - - $store = Mage::app()->getStore($storeId); - /* @var $store Mage_Core_Model_Store */ - - if (!$store) { - return false; - } - - $this->_select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable()) - ->where($this->getIdFieldName() . '=?', $store->getRootCategoryId()); - $categoryRow = $this->_getWriteAdapter()->fetchRow($this->_select); - - if (!$categoryRow) { - return false; - } - - $urConditions = array( - 'e.entity_id=ur.category_id', - $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()), - 'ur.product_id IS NULL', - $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1), - ); - $this->_select = $this->_getWriteAdapter()->select() - ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName())) - ->joinLeft( - array('ur' => $this->getTable('core/url_rewrite')), - join(' AND ', $urConditions), - array('url'=>'request_path') - ) - ->where('e.path LIKE ?', $categoryRow['path'] . '/%'); - - $this->_addFilter($storeId, 'is_active', 1); - - $query = $this->_getWriteAdapter()->query($this->_select); - while ($row = $query->fetch()) { - $category = $this->_prepareCategory($row); - $categories[$category->getId()] = $category; - } - - return $categories; - } - - /** - * Prepare category - * - * @param array $categoryRow - * @return Varien_Object - */ - protected function _prepareCategory(array $categoryRow) - { - $category = new Varien_Object(); - $category->setId($categoryRow[$this->getIdFieldName()]); - $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId(); - $category->setUrl($categoryUrl); - return $category; - } - - /** - * Add attribute to filter - * - * @param int $storeId - * @param string $attributeCode - * @param mixed $value - * @param string $type - * - * @return Zend_Db_Select - */ - protected function _addFilter($storeId, $attributeCode, $value, $type = '=') - { - if (!isset($this->_attributesCache[$attributeCode])) { - $attribute = Mage::getSingleton('catalog/category')->getResource()->getAttribute($attributeCode); - - $this->_attributesCache[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal(), - 'backend_type' => $attribute->getBackendType() - ); - } - - $attribute = $this->_attributesCache[$attributeCode]; - - if (!$this->_select instanceof Zend_Db_Select) { - return false; - } - - switch ($type) { - case '=': - $conditionRule = '=?'; - break; - case 'in': - $conditionRule = ' IN(?)'; - break; - default: - return false; - break; - } - - if ($attribute['backend_type'] == 'static') { - $this->_select->where('e.' . $attributeCode . $conditionRule, $value); - } - else { - $this->_select->join( - array('t1_'.$attributeCode => $attribute['table']), - 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0', - array() - ) - ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']); - - if ($attribute['is_global']) { - $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value); - } - else { - $this->_select->joinLeft( - array('t2_'.$attributeCode => $attribute['table']), - $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId), - array() - ) - ->where('IF(t2_'.$attributeCode.'.value_id>0, t2_'.$attributeCode.'.value, t1_'.$attributeCode.'.value)'.$conditionRule, $value); - } - } - - return $this->_select; - } } diff --git a/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Product.php b/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Product.php index e9f0c15c84..0ec4c74e88 100644 --- a/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Product.php +++ b/app/code/core/Mage/Sitemap/Model/Mysql4/Catalog/Product.php @@ -20,173 +20,18 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sitemap resource product collection model * - * @category Mage - * @package Mage_Sitemap + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ - -class Mage_Sitemap_Model_Mysql4_Catalog_Product extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sitemap_Model_Mysql4_Catalog_Product extends Mage_Sitemap_Model_Resource_Catalog_Product { - /** - * Collection Zend Db select - * - * @var Zend_Db_Select - */ - protected $_select; - - /** - * Attribute cache - * - * @var array - */ - protected $_attributesCache = array(); - - /** - * Init resource model (catalog/category) - */ - protected function _construct() - { - $this->_init('catalog/product', 'entity_id'); - } - - /** - * Add attribute to filter - * - * @param int $storeId - * @param string $attributeCode - * @param mixed $value - * @param string $type - * - * @return Zend_Db_Select - */ - protected function _addFilter($storeId, $attributeCode, $value, $type = '=') - { - if (!isset($this->_attributesCache[$attributeCode])) { - $attribute = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attributeCode); - - $this->_attributesCache[$attributeCode] = array( - 'entity_type_id' => $attribute->getEntityTypeId(), - 'attribute_id' => $attribute->getId(), - 'table' => $attribute->getBackend()->getTable(), - 'is_global' => $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, - 'backend_type' => $attribute->getBackendType() - ); - } - - $attribute = $this->_attributesCache[$attributeCode]; - - if (!$this->_select instanceof Zend_Db_Select) { - return false; - } - - switch ($type) { - case '=': - $conditionRule = '=?'; - break; - case 'in': - $conditionRule = ' IN(?)'; - break; - default: - return false; - break; - } - - if ($attribute['backend_type'] == 'static') { - $this->_select->where('e.' . $attributeCode . $conditionRule, $value); - } - else { - $this->_select->join( - array('t1_'.$attributeCode => $attribute['table']), - 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0', - array() - ) - ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']); - - if ($attribute['is_global']) { - $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value); - } - else { - $this->_select->joinLeft( - array('t2_'.$attributeCode => $attribute['table']), - $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId), - array() - ) - ->where('IF(t2_'.$attributeCode.'.value_id>0, t2_'.$attributeCode.'.value, t1_'.$attributeCode.'.value)'.$conditionRule, $value); - } - } - - return $this->_select; - } - - - /** - * Get category collection array - * - * @return array - */ - public function getCollection($storeId) - { - $products = array(); - - $store = Mage::app()->getStore($storeId); - /* @var $store Mage_Core_Model_Store */ - - if (!$store) { - return false; - } - - $urCondions = array( - 'e.entity_id=ur.product_id', - 'ur.category_id IS NULL', - $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()), - $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1), - ); - $this->_select = $this->_getWriteAdapter()->select() - ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName())) - ->join( - array('w' => $this->getTable('catalog/product_website')), - 'e.entity_id=w.product_id', - array() - ) - ->where('w.website_id=?', $store->getWebsiteId()) - ->joinLeft( - array('ur' => $this->getTable('core/url_rewrite')), - join(' AND ', $urCondions), - array('url' => 'request_path') - ) - ; - - $this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in'); - $this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in'); - - $query = $this->_getWriteAdapter()->query($this->_select); - while ($row = $query->fetch()) { - $product = $this->_prepareProduct($row); - $products[$product->getId()] = $product; - } - - return $products; - } - - /** - * Prepare product - * - * @param array $productRow - * @return Varien_Object - */ - protected function _prepareProduct(array $productRow) - { - $product = new Varien_Object(); - $product->setId($productRow[$this->getIdFieldName()]); - $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); - $product->setUrl($productUrl); - return $product; - } } diff --git a/app/code/core/Mage/Sitemap/Model/Mysql4/Cms/Page.php b/app/code/core/Mage/Sitemap/Model/Mysql4/Cms/Page.php index b511646bbd..630a5b9ad1 100644 --- a/app/code/core/Mage/Sitemap/Model/Mysql4/Cms/Page.php +++ b/app/code/core/Mage/Sitemap/Model/Mysql4/Cms/Page.php @@ -20,70 +20,18 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Sitemap cms page collection model * - * @category Mage - * @package Mage_Sitemap + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ -class Mage_Sitemap_Model_Mysql4_Cms_Page extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sitemap_Model_Mysql4_Cms_Page extends Mage_Sitemap_Model_Resource_Cms_Page { - /** - * Init resource model (catalog/category) - */ - protected function _construct() - { - $this->_init('cms/page', 'page_id'); - } - - /** - * Retrieve cms page collection array - * - * @return array - */ - public function getCollection($storeId) - { - $pages = array(); - - $select = $this->_getWriteAdapter()->select() - ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'identifier AS url')) - ->join( - array('store_table' => $this->getTable('cms/page_store')), - 'main_table.page_id=store_table.page_id', - array() - ) - ->where('main_table.is_active=1') - ->where('store_table.store_id IN(?)', array(0, $storeId)); - $query = $this->_getWriteAdapter()->query($select); - while ($row = $query->fetch()) { - if ($row['url'] == Mage_Cms_Model_Page::NOROUTE_PAGE_ID) { - continue; - } - $page = $this->_prepareObject($row); - $pages[$page->getId()] = $page; - } - - return $pages; - } - - /** - * Prepare page object - * - * @param array $data - * @return Varien_Object - */ - protected function _prepareObject(array $data) - { - $object = new Varien_Object(); - $object->setId($data[$this->getIdFieldName()]); - $object->setUrl($data['url']); - - return $object; - } - } diff --git a/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap.php b/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap.php index ba8ce4a6da..348dac0cf6 100644 --- a/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap.php +++ b/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,19 +28,10 @@ /** * Sitemap resource model * - * @category Mage - * @package Mage_Sitemap + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ -class Mage_Sitemap_Model_Mysql4_Sitemap extends Mage_Core_Model_Mysql4_Abstract +class Mage_Sitemap_Model_Mysql4_Sitemap extends Mage_Sitemap_Model_Resource_Sitemap { - - /** - * Init resource model - */ - protected function _construct() - { - $this->_init('sitemap/sitemap', 'sitemap_id'); - } - } diff --git a/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap/Collection.php b/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap/Collection.php index c683331b9f..2fd92c6557 100644 --- a/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap/Collection.php +++ b/app/code/core/Mage/Sitemap/Model/Mysql4/Sitemap/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,30 +28,10 @@ /** * Sitemap resource model collection * - * @category Mage - * @package Mage_Sitemap + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ -class Mage_Sitemap_Model_Mysql4_Sitemap_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Sitemap_Model_Mysql4_Sitemap_Collection extends Mage_Sitemap_Model_Resource_Sitemap_Collection { - - /** - * Init collection - */ - public function _construct() - { - $this->_init('sitemap/sitemap'); - } - - /** - * Filter collection by specified store ids - * - * @param array|int $storeIds - * @return Mage_Sitemap_Model_Mysql4_Sitemap_Collection - */ - public function addStoreFilter($storeIds) - { - $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); - return $this; - } } diff --git a/app/code/core/Mage/Sitemap/Model/Observer.php b/app/code/core/Mage/Sitemap/Model/Observer.php index 09177b6b83..da0075f123 100644 --- a/app/code/core/Mage/Sitemap/Model/Observer.php +++ b/app/code/core/Mage/Sitemap/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php new file mode 100755 index 0000000000..03fde11376 --- /dev/null +++ b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php @@ -0,0 +1,193 @@ + + */ +class Mage_Sitemap_Model_Resource_Catalog_Category extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Collection Zend Db select + * + * @var Zend_Db_Select + */ + protected $_select; + + /** + * Attribute cache + * + * @var array + */ + protected $_attributesCache = array(); + + /** + * Init resource model (catalog/category) + * + */ + protected function _construct() + { + $this->_init('catalog/category', 'entity_id'); + } + + /** + * Get category collection array + * + * @param unknown_type $storeId + * @return array + */ + public function getCollection($storeId) + { + $categories = array(); + + $store = Mage::app()->getStore($storeId); + /* @var $store Mage_Core_Model_Store */ + + if (!$store) { + return false; + } + + $this->_select = $this->_getWriteAdapter()->select() + ->from($this->getMainTable()) + ->where($this->getIdFieldName() . '=?', $store->getRootCategoryId()); + $categoryRow = $this->_getWriteAdapter()->fetchRow($this->_select); + + if (!$categoryRow) { + return false; + } + + $urConditions = array( + 'e.entity_id=ur.category_id', + $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()), + 'ur.product_id IS NULL', + $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1), + ); + $this->_select = $this->_getWriteAdapter()->select() + ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName())) + ->joinLeft( + array('ur' => $this->getTable('core/url_rewrite')), + join(' AND ', $urConditions), + array('url'=>'request_path') + ) + ->where('e.path LIKE ?', $categoryRow['path'] . '/%'); + + $this->_addFilter($storeId, 'is_active', 1); + + $query = $this->_getWriteAdapter()->query($this->_select); + while ($row = $query->fetch()) { + $category = $this->_prepareCategory($row); + $categories[$category->getId()] = $category; + } + + return $categories; + } + + /** + * Prepare category + * + * @param array $categoryRow + * @return Varien_Object + */ + protected function _prepareCategory(array $categoryRow) + { + $category = new Varien_Object(); + $category->setId($categoryRow[$this->getIdFieldName()]); + $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId(); + $category->setUrl($categoryUrl); + return $category; + } + + /** + * Add attribute to filter + * + * @param int $storeId + * @param string $attributeCode + * @param mixed $value + * @param string $type + * @return Zend_Db_Select + */ + protected function _addFilter($storeId, $attributeCode, $value, $type = '=') + { + if (!isset($this->_attributesCache[$attributeCode])) { + $attribute = Mage::getSingleton('catalog/category')->getResource()->getAttribute($attributeCode); + + $this->_attributesCache[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal(), + 'backend_type' => $attribute->getBackendType() + ); + } + + $attribute = $this->_attributesCache[$attributeCode]; + + if (!$this->_select instanceof Zend_Db_Select) { + return false; + } + + switch ($type) { + case '=': + $conditionRule = '=?'; + break; + case 'in': + $conditionRule = ' IN(?)'; + break; + default: + return false; + break; + } + + if ($attribute['backend_type'] == 'static') { + $this->_select->where('e.' . $attributeCode . $conditionRule, $value); + } else { + $this->_select->join( + array('t1_'.$attributeCode => $attribute['table']), + 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0', + array() + ) + ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']); + + if ($attribute['is_global']) { + $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value); + } else { + $ifCase = $this->_select->getAdapter()->getCheckSql('t2_'.$attributeCode.'.value_id > 0', 't2_'.$attributeCode.'.value', 't1_'.$attributeCode.'.value'); + $this->_select->joinLeft( + array('t2_'.$attributeCode => $attribute['table']), + $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId), + array() + ) + ->where('('.$ifCase.')'.$conditionRule, $value); + } + } + + return $this->_select; + } +} diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php new file mode 100755 index 0000000000..5ad70dd46d --- /dev/null +++ b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php @@ -0,0 +1,190 @@ + + */ +class Mage_Sitemap_Model_Resource_Catalog_Product extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Collection Zend Db select + * + * @var Zend_Db_Select + */ + protected $_select; + + /** + * Attribute cache + * + * @var array + */ + protected $_attributesCache = array(); + + /** + * Init resource model (catalog/category) + * + */ + protected function _construct() + { + $this->_init('catalog/product', 'entity_id'); + } + + /** + * Add attribute to filter + * + * @param int $storeId + * @param string $attributeCode + * @param mixed $value + * @param string $type + * @return Zend_Db_Select + */ + protected function _addFilter($storeId, $attributeCode, $value, $type = '=') + { + if (!isset($this->_attributesCache[$attributeCode])) { + $attribute = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attributeCode); + + $this->_attributesCache[$attributeCode] = array( + 'entity_type_id' => $attribute->getEntityTypeId(), + 'attribute_id' => $attribute->getId(), + 'table' => $attribute->getBackend()->getTable(), + 'is_global' => $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, + 'backend_type' => $attribute->getBackendType() + ); + } + + $attribute = $this->_attributesCache[$attributeCode]; + + if (!$this->_select instanceof Zend_Db_Select) { + return false; + } + + switch ($type) { + case '=': + $conditionRule = '=?'; + break; + case 'in': + $conditionRule = ' IN(?)'; + break; + default: + return false; + break; + } + + if ($attribute['backend_type'] == 'static') { + $this->_select->where('e.' . $attributeCode . $conditionRule, $value); + } else { + $this->_select->join( + array('t1_'.$attributeCode => $attribute['table']), + 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0', + array() + ) + ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']); + + if ($attribute['is_global']) { + $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value); + } else { + $ifCase = $this->_select->getAdapter()->getCheckSql('t2_'.$attributeCode.'.value_id > 0', 't2_'.$attributeCode.'.value', 't1_'.$attributeCode.'.value'); + $this->_select->joinLeft( + array('t2_'.$attributeCode => $attribute['table']), + $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId), + array() + ) + ->where('('.$ifCase.')'.$conditionRule, $value); + } + } + + return $this->_select; + } + + /** + * Get category collection array + * + * @param unknown_type $storeId + * @return array + */ + public function getCollection($storeId) + { + $products = array(); + + $store = Mage::app()->getStore($storeId); + /* @var $store Mage_Core_Model_Store */ + + if (!$store) { + return false; + } + + $urCondions = array( + 'e.entity_id=ur.product_id', + 'ur.category_id IS NULL', + $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()), + $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1), + ); + $this->_select = $this->_getWriteAdapter()->select() + ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName())) + ->join( + array('w' => $this->getTable('catalog/product_website')), + 'e.entity_id=w.product_id', + array() + ) + ->where('w.website_id=?', $store->getWebsiteId()) + ->joinLeft( + array('ur' => $this->getTable('core/url_rewrite')), + join(' AND ', $urCondions), + array('url' => 'request_path') + ); + + $this->_addFilter($storeId, 'visibility', Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in'); + $this->_addFilter($storeId, 'status', Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in'); + + $query = $this->_getWriteAdapter()->query($this->_select); + while ($row = $query->fetch()) { + $product = $this->_prepareProduct($row); + $products[$product->getId()] = $product; + } + + return $products; + } + + /** + * Prepare product + * + * @param array $productRow + * @return Varien_Object + */ + protected function _prepareProduct(array $productRow) + { + $product = new Varien_Object(); + $product->setId($productRow[$this->getIdFieldName()]); + $productUrl = !empty($productRow['url']) ? $productRow['url'] : 'catalog/product/view/id/' . $product->getId(); + $product->setUrl($productUrl); + return $product; + } +} diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Cms/Page.php b/app/code/core/Mage/Sitemap/Model/Resource/Cms/Page.php new file mode 100755 index 0000000000..abaaa2bb8c --- /dev/null +++ b/app/code/core/Mage/Sitemap/Model/Resource/Cms/Page.php @@ -0,0 +1,91 @@ + + */ +class Mage_Sitemap_Model_Resource_Cms_Page extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init resource model (catalog/category) + * + */ + protected function _construct() + { + $this->_init('cms/page', 'page_id'); + } + + /** + * Retrieve cms page collection array + * + * @param unknown_type $storeId + * @return array + */ + public function getCollection($storeId) + { + $pages = array(); + + $select = $this->_getWriteAdapter()->select() + ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'identifier AS url')) + ->join( + array('store_table' => $this->getTable('cms/page_store')), + 'main_table.page_id=store_table.page_id', + array() + ) + ->where('main_table.is_active=1') + ->where('store_table.store_id IN(?)', array(0, $storeId)); + $query = $this->_getWriteAdapter()->query($select); + while ($row = $query->fetch()) { + if ($row['url'] == Mage_Cms_Model_Page::NOROUTE_PAGE_ID) { + continue; + } + $page = $this->_prepareObject($row); + $pages[$page->getId()] = $page; + } + + return $pages; + } + + /** + * Prepare page object + * + * @param array $data + * @return Varien_Object + */ + protected function _prepareObject(array $data) + { + $object = new Varien_Object(); + $object->setId($data[$this->getIdFieldName()]); + $object->setUrl($data['url']); + + return $object; + } +} diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Sitemap.php b/app/code/core/Mage/Sitemap/Model/Resource/Sitemap.php new file mode 100755 index 0000000000..cb09364746 --- /dev/null +++ b/app/code/core/Mage/Sitemap/Model/Resource/Sitemap.php @@ -0,0 +1,45 @@ + + */ +class Mage_Sitemap_Model_Resource_Sitemap extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Init resource model + * + */ + protected function _construct() + { + $this->_init('sitemap/sitemap', 'sitemap_id'); + } +} diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Sitemap/Collection.php b/app/code/core/Mage/Sitemap/Model/Resource/Sitemap/Collection.php new file mode 100755 index 0000000000..569b5d18b2 --- /dev/null +++ b/app/code/core/Mage/Sitemap/Model/Resource/Sitemap/Collection.php @@ -0,0 +1,57 @@ + + */ +class Mage_Sitemap_Model_Resource_Sitemap_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Init collection + * + */ + public function _construct() + { + $this->_init('sitemap/sitemap'); + } + + /** + * Filter collection by specified store ids + * + * @param array|int $storeIds + * @return Mage_Sitemap_Model_Resource_Sitemap_Collection + */ + public function addStoreFilter($storeIds) + { + $this->getSelect()->where('main_table.store_id IN (?)', $storeIds); + return $this; + } +} diff --git a/app/code/core/Mage/Sitemap/Model/Sitemap.php b/app/code/core/Mage/Sitemap/Model/Sitemap.php index 17160ddef0..492a7da754 100644 --- a/app/code/core/Mage/Sitemap/Model/Sitemap.php +++ b/app/code/core/Mage/Sitemap/Model/Sitemap.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,8 +28,21 @@ /** * Sitemap model * - * @category Mage - * @package Mage_Sitemap + * @method Mage_Sitemap_Model_Resource_Sitemap _getResource() + * @method Mage_Sitemap_Model_Resource_Sitemap getResource() + * @method string getSitemapType() + * @method Mage_Sitemap_Model_Sitemap setSitemapType(string $value) + * @method string getSitemapFilename() + * @method Mage_Sitemap_Model_Sitemap setSitemapFilename(string $value) + * @method string getSitemapPath() + * @method Mage_Sitemap_Model_Sitemap setSitemapPath(string $value) + * @method string getSitemapTime() + * @method Mage_Sitemap_Model_Sitemap setSitemapTime(string $value) + * @method int getStoreId() + * @method Mage_Sitemap_Model_Sitemap setStoreId(int $value) + * + * @category Mage + * @package Mage_Sitemap * @author Magento Core Team */ class Mage_Sitemap_Model_Sitemap extends Mage_Core_Model_Abstract diff --git a/app/code/core/Mage/Sitemap/etc/adminhtml.xml b/app/code/core/Mage/Sitemap/etc/adminhtml.xml index 5b9e4545da..a34d8636c2 100644 --- a/app/code/core/Mage/Sitemap/etc/adminhtml.xml +++ b/app/code/core/Mage/Sitemap/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Sitemap/etc/config.xml b/app/code/core/Mage/Sitemap/etc/config.xml index a0190ec64b..9985cf4652 100644 --- a/app/code/core/Mage/Sitemap/etc/config.xml +++ b/app/code/core/Mage/Sitemap/etc/config.xml @@ -21,30 +21,31 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.2 + 1.6.0.0 Mage_Sitemap_Model - sitemap_mysql4 + sitemap_resource - - Mage_Sitemap_Model_Mysql4 + + Mage_Sitemap_Model_Resource + sitemap_mysql4 sitemap
      -
      +
      @@ -90,7 +91,7 @@ 0 - + sitemap_generate_error_email_template general diff --git a/app/code/core/Mage/Sitemap/etc/system.xml b/app/code/core/Mage/Sitemap/etc/system.xml index 6302e91dce..9c0b4aa5cc 100644 --- a/app/code/core/Mage/Sitemap/etc/system.xml +++ b/app/code/core/Mage/Sitemap/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Sitemap/sql/sitemap_setup/install-1.6.0.0.php b/app/code/core/Mage/Sitemap/sql/sitemap_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..822ad40177 --- /dev/null +++ b/app/code/core/Mage/Sitemap/sql/sitemap_setup/install-1.6.0.0.php @@ -0,0 +1,69 @@ +startSetup(); + +/** + * Create table 'sitemap' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('sitemap/sitemap')) + ->addColumn('sitemap_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Sitemap Id') + ->addColumn('sitemap_type', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Sitemap Type') + ->addColumn('sitemap_filename', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Sitemap Filename') + ->addColumn('sitemap_path', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Sitemap Path') + ->addColumn('sitemap_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + 'nullable' => true, + ), 'Sitemap Time') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Store id') + ->addIndex($installer->getIdxName('sitemap/sitemap', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('sitemap/sitemap', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Google Sitemap'); + +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-install-0.7.0.php index a53004b3a7..6c25d7c256 100644 --- a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.0-0.7.1.php index 2468390947..d8802212f0 100644 --- a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.1-0.7.2.php index 5861629297..126a0c5144 100644 --- a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Sitemap - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..5c3fc44d08 --- /dev/null +++ b/app/code/core/Mage/Sitemap/sql/sitemap_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,117 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$connection = $installer->getConnection()->dropForeignKey( + $installer->getTable('sitemap/sitemap'), + 'FK_SITEMAP_STORE' +); + + +/** + * Drop indexes + */ +$connection = $installer->getConnection()->dropIndex( + $installer->getTable('sitemap/sitemap'), + 'FK_SITEMAP_STORE' +); + +/** + * Change columns + */ +$tables = array( + $installer->getTable('sitemap/sitemap') => array( + 'columns' => array( + 'sitemap_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Sitemap Id' + ), + 'sitemap_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Sitemap Type' + ), + 'sitemap_filename' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Sitemap Filename' + ), + 'sitemap_path' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Sitemap Path' + ), + 'sitemap_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Sitemap Time' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store id' + ) + ), + 'comment' => 'Google Sitemap' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$connection = $installer->getConnection()->addIndex( + $installer->getTable('sitemap/sitemap'), + $installer->getIdxName('sitemap/sitemap', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$connection = $installer->getConnection()->addForeignKey( + $installer->getFkName('sitemap/sitemap', 'store_id', 'core/store', 'store_id'), + $installer->getTable('sitemap/sitemap'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Tag/Block/All.php b/app/code/core/Mage/Tag/Block/All.php index b6036cbe8d..3387daeafb 100644 --- a/app/code/core/Mage/Tag/Block/All.php +++ b/app/code/core/Mage/Tag/Block/All.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Customer/Edit.php b/app/code/core/Mage/Tag/Block/Customer/Edit.php index 545754a086..9848ddd870 100644 --- a/app/code/core/Mage/Tag/Block/Customer/Edit.php +++ b/app/code/core/Mage/Tag/Block/Customer/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Customer/Recent.php b/app/code/core/Mage/Tag/Block/Customer/Recent.php index 753a2c3e8b..cc12f951c2 100644 --- a/app/code/core/Mage/Tag/Block/Customer/Recent.php +++ b/app/code/core/Mage/Tag/Block/Customer/Recent.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Customer/Tags.php b/app/code/core/Mage/Tag/Block/Customer/Tags.php index 67b36b2b30..472c3c6062 100644 --- a/app/code/core/Mage/Tag/Block/Customer/Tags.php +++ b/app/code/core/Mage/Tag/Block/Customer/Tags.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Customer/View.php b/app/code/core/Mage/Tag/Block/Customer/View.php index 3ae5d37822..34aa19058a 100644 --- a/app/code/core/Mage/Tag/Block/Customer/View.php +++ b/app/code/core/Mage/Tag/Block/Customer/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Popular.php b/app/code/core/Mage/Tag/Block/Popular.php index c0ed4ee97e..ae4754a302 100644 --- a/app/code/core/Mage/Tag/Block/Popular.php +++ b/app/code/core/Mage/Tag/Block/Popular.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Product/List.php b/app/code/core/Mage/Tag/Block/Product/List.php index b44dd77c84..938c326023 100644 --- a/app/code/core/Mage/Tag/Block/Product/List.php +++ b/app/code/core/Mage/Tag/Block/Product/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Block/Product/Result.php b/app/code/core/Mage/Tag/Block/Product/Result.php index 63147c51d6..38bb1562e9 100644 --- a/app/code/core/Mage/Tag/Block/Product/Result.php +++ b/app/code/core/Mage/Tag/Block/Product/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Helper/Data.php b/app/code/core/Mage/Tag/Helper/Data.php index 12dbea4834..423d299f1e 100644 --- a/app/code/core/Mage/Tag/Helper/Data.php +++ b/app/code/core/Mage/Tag/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Model/Entity/Customer/Collection.php b/app/code/core/Mage/Tag/Model/Entity/Customer/Collection.php index 4b820defaa..a08d6f3728 100644 --- a/app/code/core/Mage/Tag/Model/Entity/Customer/Collection.php +++ b/app/code/core/Mage/Tag/Model/Entity/Customer/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Model/Indexer/Summary.php b/app/code/core/Mage/Tag/Model/Indexer/Summary.php index 1dc14a5ded..ae4bc93816 100644 --- a/app/code/core/Mage/Tag/Model/Indexer/Summary.php +++ b/app/code/core/Mage/Tag/Model/Indexer/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,28 @@ /** * Tag Indexer Model * - * @category Mage - * @package Mage_Tag - * @author Magento Core Team + * @method Mage_Tag_Model_Resource_Indexer_Summary _getResource() + * @method Mage_Tag_Model_Resource_Indexer_Summary getResource() + * @method int getTagId() + * @method Mage_Tag_Model_Indexer_Summary setTagId(int $value) + * @method int getStoreId() + * @method Mage_Tag_Model_Indexer_Summary setStoreId(int $value) + * @method int getCustomers() + * @method Mage_Tag_Model_Indexer_Summary setCustomers(int $value) + * @method int getProducts() + * @method Mage_Tag_Model_Indexer_Summary setProducts(int $value) + * @method int getUses() + * @method Mage_Tag_Model_Indexer_Summary setUses(int $value) + * @method int getHistoricalUses() + * @method Mage_Tag_Model_Indexer_Summary setHistoricalUses(int $value) + * @method int getPopularity() + * @method Mage_Tag_Model_Indexer_Summary setPopularity(int $value) + * @method int getBasePopularity() + * @method Mage_Tag_Model_Indexer_Summary setBasePopularity(int $value) + * + * @category Mage + * @package Mage_Tag + * @author Magento Core Team */ class Mage_Tag_Model_Indexer_Summary extends Mage_Index_Model_Indexer_Abstract { diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Customer/Collection.php b/app/code/core/Mage/Tag/Model/Mysql4/Customer/Collection.php index 6074103a2d..f9c354e980 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Customer/Collection.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Customer/Collection.php @@ -20,245 +20,18 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tags customer collection * - * @category Mage - * @package Mage_Tag + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ - -class Mage_Tag_Model_Mysql4_Customer_Collection extends Mage_Customer_Model_Entity_Customer_Collection +class Mage_Tag_Model_Mysql4_Customer_Collection extends Mage_Tag_Model_Resource_Customer_Collection { - protected $_allowDisableGrouping = true; - protected $_countAttribute = 'tr.tag_id'; - - /** - * @deprecated after 1.3.2.3 - */ - protected $_joinFlags = array(); - - public function _initSelect() - { - parent::_initSelect(); - $this->_joinFields(); - $this->_setIdFieldName('tag_relation_id'); - return $this; - } - - /** - * Set flag about joined table. - * setFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param string $table - * @return Mage_Tag_Model_Mysql4_Customer_Collection - */ - public function setJoinFlag($table) - { - $this->setFlag($table, true); - return $this; - } - - /** - * Get flag's status about joined table. - * getFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return bool - */ - public function getJoinFlag($table) - { - return $this->getFlag($table); - } - - /** - * Unset value of join flag. - * Set false (bool) value to flag instead in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return Mage_Tag_Model_Mysql4_Customer_Collection - */ - public function unsetJoinFlag($table=null) - { - $this->setFlag($table, false); - return $this; - } - - public function addTagFilter($tagId) - { - $this->getSelect() - ->where('tr.tag_id = ?', $tagId); - return $this; - } - - public function addProductFilter($productId) - { - $this->getSelect() - ->where('tr.product_id = ?', $productId); - return $this; - } - - /** - * Apply filter by store id(s). - * - * @param int|array $storeId - * @return Mage_Tag_Model_Mysql4_Customer_Collection - */ - public function addStoreFilter($storeId) - { - $this->getSelect()->where('tr.store_id IN (?)', $storeId); - return $this; - } - - public function addStatusFilter($status) - { - $this->getSelect() - ->where('t.status = ?', $status); - return $this; - } - - public function addDescOrder() - { - $this->getSelect() - ->order('tr.tag_relation_id desc'); - return $this; - } - - public function addGroupByTag() - { - $this->getSelect() - ->group('tr.tag_id'); - - $this->_allowDisableGrouping = true; - return $this; - } - - public function addGroupByCustomer() - { - $this->getSelect() - ->group('tr.customer_id'); - - $this->_allowDisableGrouping = false; - return $this; - } - - public function addGroupByCustomerProduct() - { - // Nothing need to group - $this->_allowDisableGrouping = false; - return $this; - } - - public function addCustomerFilter($customerId) - { - $this->getSelect()->where('tr.customer_id = ?', $customerId); - return $this; - } - - protected function _joinFields() - { - $tagRelationTable = $this->getTable('tag/relation'); - $tagTable = $this->getTable('tag/tag'); - - //TODO: add full name logic - $this->addAttributeToSelect('firstname') - ->addAttributeToSelect('lastname') - ->addAttributeToSelect('email'); - - $this->getSelect() - ->join(array('tr' => $tagRelationTable), 'tr.customer_id = e.entity_id') - ->join(array('t' => $tagTable), 't.tag_id = tr.tag_id'); - } - - public function getSelectCountSql() - { - $countSelect = parent::getSelectCountSql(); - - if ($this->_allowDisableGrouping) { - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->columns('COUNT(DISTINCT ' . $this->getCountAttribute() . ')'); - } - return $countSelect; - } - - public function addProductName() - { - $productsId = array(); - $productsData = array(); - - foreach ($this->getItems() as $item) - { - $productsId[] = $item->getProductId(); - } - - $productsId = array_unique($productsId); - - /* small fix */ - if( sizeof($productsId) == 0 ) { - return; - } - - $collection = Mage::getModel('catalog/product')->getCollection() - ->addAttributeToSelect('name') - ->addAttributeToSelect('sku') - ->addIdFilter($productsId); - - $collection->load(); - - foreach ($collection->getItems() as $item) - { - $productsData[$item->getId()] = $item->getName(); - $productsSku[$item->getId()] = $item->getSku(); - } - - foreach ($this->getItems() as $item) - { - $item->setProduct($productsData[$item->getProductId()]); - $item->setProductSku($productsSku[$item->getProductId()]); - } - return $this; - } - - public function setOrder($attribute, $dir='desc') - { - switch( $attribute ) { - case 'name': - case 'status': - $this->getSelect()->order($attribute . ' ' . $dir); - break; - - default: - parent::setOrder($attribute, $dir); - } - return $this; - } - - public function setCountAttribute($value) - { - $this->_countAttribute = $value; - return $this; - } - - public function getCountAttribute() - { - return $this->_countAttribute; - } - - public function addFieldToFilter($attribute, $condition=null){ - if ($attribute == 'name') { - $where = $this->_getConditionSql('t.name', $condition); - $this->getSelect()->where($where, null, Varien_Db_Select::TYPE_CONDITION); - return $this; - } else { - return parent::addFieldToFilter($attribute, $condition); - } - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Indexer/Summary.php b/app/code/core/Mage/Tag/Model/Mysql4/Indexer/Summary.php index 610147d7bf..8059a59f4d 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Indexer/Summary.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Indexer/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,232 +28,10 @@ /** * Tag Indexer Model * - * @category Mage - * @package Mage_Tag - * @author Magento Core Team + * @category Mage + * @package Mage_Tag + * @author Magento Core Team */ -class Mage_Tag_Model_Mysql4_Indexer_Summary extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Abstract +class Mage_Tag_Model_Mysql4_Indexer_Summary extends Mage_Tag_Model_Resource_Indexer_Summary { - /** - * Define main table - * - */ - protected function _construct() - { - $this->_init('tag/summary', 'tag_id'); - } - - /** - * Process tag save - * - * @param Mage_Index_Model_Event $event - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function tagSave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['tag_reindex_tag_id'])) { - return $this; - } - return $this->aggregate($data['tag_reindex_tag_id']); - } - - /** - * Process tag relation save - * - * @param Mage_Index_Model_Event $event - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function tagRelationSave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['tag_reindex_tag_id'])) { - return $this; - } - return $this->aggregate($data['tag_reindex_tag_id']); - } - - /** - * Process product save. - * Method is responsible for index support when product was saved. - * - * @param Mage_Index_Model_Event $event - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function catalogProductSave(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['tag_reindex_required'])) { - return $this; - } - - $tagIds = Mage::getModel('tag/tag_relation') - ->setProductId($event->getEntityPk()) - ->getRelatedTagIds(); - - return $this->aggregate($tagIds); - } - - /** - * Process product delete. - * Method is responsible for index support when product was deleted - * - * @param Mage_Index_Model_Event $event - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function catalogProductDelete(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['tag_reindex_tag_ids'])) { - return $this; - } - return $this->aggregate($data['tag_reindex_tag_ids']); - } - - /** - * Process product massaction - * - * @param Mage_Index_Model_Event $event - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function catalogProductMassAction(Mage_Index_Model_Event $event) - { - $data = $event->getNewData(); - if (empty($data['tag_reindex_tag_ids'])) { - return $this; - } - return $this->aggregate($data['tag_reindex_tag_ids']); - } - - /** - * Reindex all tags - * - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function reindexAll() - { - return $this->aggregate(); - } - - /** - * Aggregate tags by specified ids - * - * @param null|int|array $tagIds - * @return Mage_Tag_Model_Mysql4_Indexer_Summary - */ - public function aggregate($tagIds = null) - { - $writeAdapter = $this->_getWriteAdapter(); - $writeAdapter->beginTransaction(); - - try { - if (!is_null($tagIds)) { - $writeAdapter->delete( - $this->getTable('tag/summary'), $writeAdapter->quoteInto('tag_id IN(?)', $tagIds) - ); - } else { - $writeAdapter->truncate($this->getTable('tag/summary')); - } - - $select = $writeAdapter->select() - ->from( - array('tr' => $this->getTable('tag/relation')), - array( - 'tr.tag_id', - 'tr.store_id', - 'customers' => 'COUNT(DISTINCT tr.customer_id)', - 'products' => 'COUNT(DISTINCT tr.product_id)', - 'popularity' => 'COUNT(tr.customer_id) + IFNULL(tp.base_popularity, 0)', - 'uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 - 'historical_uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 - 'base_popularity' => new Zend_Db_Expr(0) // deprecated since 1.4.0.1 - ) - ) - ->joinInner( - array('cs' => $this->getTable('core/store')), - 'cs.store_id = tr.store_id', - array() - ) - ->joinInner( - array('pw' => $this->getTable('catalog/product_website')), - 'cs.website_id = pw.website_id AND tr.product_id = pw.product_id', - array() - ) - ->joinInner( - array('e' => $this->getTable('catalog/product')), - 'tr.product_id = e.entity_id', - array() - ) - ->joinLeft( - array('tp' => $this->getTable('tag/properties')), - 'tp.tag_id = tr.tag_id AND tp.store_id = tr.store_id', - array() - ) - ->group(array( - 'tr.tag_id', - 'tr.store_id' - )); - - $statusCond = $writeAdapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); - $this->_addAttributeToSelect($select, 'status', 'e.entity_id' , 'cs.store_id', $statusCond); - - $visibilityCond = $writeAdapter - ->quoteInto('!=?', Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE); - $this->_addAttributeToSelect($select, 'visibility', 'e.entity_id' , 'cs.store_id', $visibilityCond); - - if (!is_null($tagIds)) { - $select->where('tr.tag_id IN(?)', $tagIds); - } - - Mage::dispatchEvent('prepare_catalog_product_index_select', array( - 'select' => $select, - 'entity_field' => new Zend_Db_Expr('e.entity_id'), - 'website_field' => new Zend_Db_Expr('cs.website_id'), - 'store_field' => new Zend_Db_Expr('cs.store_id') - )); - - $writeAdapter->query( - $select->insertFromSelect($this->getTable('tag/summary'), array( - 'tag_id', - 'store_id', - 'customers', - 'products', - 'popularity', - 'uses', // deprecated since 1.4.0.1 - 'historical_uses', // deprecated since 1.4.0.1 - 'base_popularity' // deprecated since 1.4.0.1 - )) - ); - - - $selectedFields = array( - 'tag_id' => 'tag_id', - 'store_id' => new Zend_Db_Expr(0), - 'customers' => 'COUNT(DISTINCT customer_id)', - 'products' => 'COUNT(DISTINCT product_id)', - 'popularity' => 'COUNT(customer_id)', - 'uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 - 'historical_uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 - 'base_popularity' => new Zend_Db_Expr(0) // deprecated since 1.4.0.1 - ); - - $agregateSelect = $writeAdapter->select(); - $agregateSelect->from($this->getTable('tag/relation'), $selectedFields) - ->group('tag_id'); - - if (!is_null($tagIds)) { - $agregateSelect->where('tag_id IN(?)', $tagIds); - } - - $writeAdapter->query( - $agregateSelect->insertFromSelect($this->getTable('tag/summary'), array_keys($selectedFields)) - ); - } catch (Exception $e) { - $writeAdapter->rollBack(); - throw $e; - } - - $writeAdapter->commit(); - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Popular/Collection.php b/app/code/core/Mage/Tag/Model/Mysql4/Popular/Collection.php index 25746fd4e1..0f529250e2 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Popular/Collection.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Popular/Collection.php @@ -20,77 +20,18 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Popular tags collection model * - * @category Mage - * @package Mage_Tag + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ - -class Mage_Tag_Model_Mysql4_Popular_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tag_Model_Mysql4_Popular_Collection extends Mage_Tag_Model_Resource_Popular_Collection { - - protected function _construct() - { - $this->_init('tag/tag'); - } - - /** - * Replacing popularity by sum of popularity and base_popularity - * - * @param int $storeId - * @return Mage_Tag_Model_Mysql4_Popular_Collection - */ - public function joinFields($storeId = 0) - { - $this->getSelect() - ->reset() - ->from( - array('tag_summary' => $this->getTable('tag/summary')), - array( - 'tag_id', - 'popularity' - ) - ) - ->joinInner( - array('tag' => $this->getTable('tag/tag')), - 'tag.tag_id = tag_summary.tag_id AND tag.status = '.Mage_Tag_Model_Tag::STATUS_APPROVED - ) - ->where('tag_summary.store_id = ?', $storeId) - ->where('tag_summary.products > 0') - ->order('popularity desc'); - return $this; - } - - /** - * Add filter by specified tag status - * - * @param string $statusCode - * @return Mage_Tag_Model_Mysql4_Popular_Collection - */ - public function addStatusFilter($statusCode) - { - $this->getSelect()->where('main_table.status = ?', $statusCode); - return $this; - } - - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - parent::load($printQuery, $logQuery); - return $this; - } - - public function limit($limit) - { - $this->getSelect()->limit($limit); - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Product/Collection.php b/app/code/core/Mage/Tag/Model/Mysql4/Product/Collection.php index 428862cfd0..23716a7032 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Product/Collection.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Product/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,440 +28,10 @@ /** * Tagged Product(s) Collection * - * @category Mage - * @package Mage_Tag - * @author Magento Core Team + * @category Mage + * @package Mage_Tag + * @author Magento Core Team */ -class Mage_Tag_Model_Mysql4_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Tag_Model_Mysql4_Product_Collection extends Mage_Tag_Model_Resource_Product_Collection { - /** - * Customer Id Filter - * - * @var int - */ - protected $_customerFilterId; - - /** - * Tag Id Filter - * - * @var int - */ - protected $_tagIdFilter; - - /** - * Join Flags - * - * @deprecated after 1.3.2.3 - * @var array - */ - protected $_joinFlags = array(); - - /** - * Initialize collection select - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - protected function _initSelect() - { - parent::_initSelect(); - - $this->_joinFields(); - $this->getSelect()->group('e.entity_id'); - - return $this; - } - - /** - * Set flag about joined table. - * setFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param string $table - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function setJoinFlag($table) - { - $this->setFlag($table, true); - return $this; - } - - /** - * Get flag's status about joined table. - * getFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return bool - */ - public function getJoinFlag($table) - { - return $this->getFlag($table); - } - - /** - * Unset value of join flag. - * Set false (bool) value to flag instead in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function unsetJoinFlag($table=null) - { - $this->setFlag($table, false); - return $this; - } - - /** - * Add tag visibility on stores - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addStoresVisibility() - { - $this->setFlag('add_stores_after', true); - return $this; - } - - /** - * Add tag visibility on stores process - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - protected function _addStoresVisibility() - { - $tagIds = array(); - foreach ($this as $item) { - $tagIds[] = $item->getTagId(); - } - - $tagsStores = array(); - if (sizeof($tagIds) > 0) { - $select = $this->getConnection()->select() - ->from($this->getTable('tag/relation'), array('store_id', 'tag_id')) - ->where('tag_id IN(?)', $tagIds); - $tagsRaw = $this->getConnection()->fetchAll($select); - foreach ($tagsRaw as $tag) { - if (!isset($tagsStores[$tag['tag_id']])) { - $tagsStores[$tag['tag_id']] = array(); - } - - $tagsStores[$tag['tag_id']][] = $tag['store_id']; - } - } - - foreach ($this as $item) { - if (isset($tagsStores[$item->getTagId()])) { - $item->setStores($tagsStores[$item->getTagId()]); - } - else { - $item->setStores(array()); - } - } - - return $this; - } - - /** - * Add group by tag - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addGroupByTag() - { - $this->getSelect()->group('relation.tag_relation_id'); - return $this; - } - - /** - * Add Store ID filter - * - * @param int|array $store - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addStoreFilter($store=null) - { - if (!is_null($store)) { - $this->getSelect()->where('relation.store_id IN (?)', $store); - } - return $this; - } - - /** - * Set Customer filter - * If incoming parameter is array and has element with key 'null' - * then condition with IS NULL or IS NOT NULL will be added. - * Otherwise condition with IN() will be added - * - * @param int|array $customerId - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addCustomerFilter($customerId) - { - if (is_array($customerId) && isset($customerId['null'])) { - $condition = ($customerId['null']) ? 'IS NULL' : 'IS NOT NULL'; - $this->getSelect()->where('relation.customer_id ' . $condition); - return $this; - } - $this->getSelect()->where('relation.customer_id IN(?)', $customerId); - $this->_customerFilterId = $customerId; - return $this; - } - - /** - * Set tag filter - * - * @param int $tagId - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addTagFilter($tagId) - { - $this->getSelect()->where('relation.tag_id = ?', $tagId); - $this->setFlag('distinct', true); - return $this; - } - - /** - * Add tag status filter - * - * @param int $status - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addStatusFilter($status) - { - $this->getSelect()->where('t.status = ?', $status); - return $this; - } - - /** - * Set DESC order to collection - * - * @param string $dir - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function setDescOrder($dir = 'DESC') - { - $this->setOrder('relation.tag_relation_id', $dir); - return $this; - } - - /** - * Add Popularity - * - * @param int $tagId - * @param int $storeId - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addPopularity($tagId, $storeId=null) - { - $tagRelationTable = $this->getTable('tag/relation'); - - $condition = array( - 'prelation.product_id=e.entity_id' - ); - - if (!is_null($storeId)) { - $condition[] = $this->getConnection()->quoteInto('prelation.store_id = ?', $storeId); - } - $condition = join(' AND ', $condition); - - $this->getSelect() - ->joinLeft( - array('prelation' => $tagRelationTable), - $condition, - array('popularity' => 'COUNT(DISTINCT prelation.tag_relation_id)')) - ->where('prelation.tag_id = ?', $tagId); - - $this->_tagIdFilter = $tagId; - $this->setFlag('prelation', true); - return $this; - } - - /** - * Add Popularity Filter - * - * @param mixed $condition - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addPopularityFilter($condition) - { - $tagRelationTable = Mage::getSingleton('core/resource') - ->getTableName('tag/relation'); - - $select = $this->getConnection()->select() - ->from($tagRelationTable, array('product_id', 'popularity' => 'COUNT(DISTINCT tag_relation_id)')) - ->where('tag_id = ?', $this->_tagIdFilter) - ->group('product_id') - ->having($this->_getConditionSql('popularity', $condition)); - - $prodIds = array(); - foreach ($this->getConnection()->fetchAll($select) as $item) { - $prodIds[] = $item['product_id']; - } - - if (sizeof($prodIds) > 0) { - $this->getSelect()->where('e.entity_id IN(?)', $prodIds); - } - else { - $this->getSelect()->where('e.entity_id IN(0)'); - } - - return $this; - } - - /** - * Set tag active filter to collection - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function setActiveFilter() - { - $active = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE; - $this->getSelect()->where('relation.active=?', $active); - if ($this->getFlag('prelation')) { - $this->getSelect()->where('prelation.active=?', $active); - } - return $this; - } - - /** - * Add Product Tags - * - * @param int $storeId - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function addProductTags($storeId = null) - { - foreach ($this->getItems() as $item) { - $tagsCollection = Mage::getModel('tag/tag')->getResourceCollection(); - - if (!is_null($storeId)) { - $tagsCollection->addStoreFilter($storeId); - } - - $tagsCollection->addPopularity() - ->addProductFilter($item->getEntityId()) - ->addCustomerFilter($this->_customerFilterId) - ->setActiveFilter(); - - $tagsCollection->load(); - $item->setProductTags($tagsCollection); - } - - return $this; - } - - /** - * Join fields process - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - protected function _joinFields() - { - $tagTable = $this->getTable('tag/tag'); - $tagRelationTable = $this->getTable('tag/relation'); - - $this->addAttributeToSelect('name') - ->addAttributeToSelect('price') - ->addAttributeToSelect('small_image'); - - $this->getSelect() - ->join(array('relation' => $tagRelationTable), 'relation.product_id = e.entity_id', array( - 'product_id' => 'product_id', - 'item_store_id' => 'store_id', - )) - ->join(array('t' => $tagTable), - 't.tag_id = relation.tag_id', - array( - 'tag_id', - 'name', - 'tag_status' => 'status', - 'tag_name' => 'name', - 'store_id' => 'IF(t.first_store_id = 0, relation.store_id, t.first_store_id)' - ) - ); - - return $this; - } - - /** - * After load adding data - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - if ($this->getFlag('add_stores_after')) { - $this->_addStoresVisibility(); - } - - if (count($this) > 0) { - Mage::dispatchEvent('tag_tag_product_collection_load_after', array( - 'collection' => $this - )); - } - - return $this; - } - - /** - * Render SQL for retrieve product count - * - * @return string - */ - public function getSelectCountSql() - { - $countSelect = clone $this->getSelect(); - - $countSelect->reset(Zend_Db_Select::COLUMNS); - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - $countSelect->reset(Zend_Db_Select::GROUP); - - if ($this->getFlag('group_tag')) { - $field = 'relation.tag_id'; - } - else { - $field = 'e.entity_id'; - } - $expr = new Zend_Db_Expr('COUNT(' - . ($this->getFlag('distinct') ? 'DISTINCT ' : '') - . $field . ')'); - - $countSelect->columns($expr); - - return $countSelect; - } - - /** - * Set attribute order - * - * @param string $attribute - * @param string $dir - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function setOrder($attribute, $dir='desc') - { - if ($attribute == 'popularity') { - $this->getSelect()->order($attribute . ' ' . $dir); - } - else { - parent::setOrder($attribute, $dir); - } - return $this; - } - - /** - * Set Id Fieldname as Tag Relation Id - * - * @return Mage_Tag_Model_Mysql4_Product_Collection - */ - public function setRelationId() - { - $this->_setIdFieldName('tag_relation_id'); - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Tag.php b/app/code/core/Mage/Tag/Model/Mysql4/Tag.php index 33fab8fc73..41d2d4fe01 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Tag.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Tag.php @@ -20,384 +20,18 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tag resourse model * - * @category Mage - * @package Mage_Tag + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ - -class Mage_Tag_Model_Mysql4_Tag extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tag_Model_Mysql4_Tag extends Mage_Tag_Model_Resource_Tag { - protected function _construct() - { - $this->_init('tag/tag', 'tag_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => 'name', - 'title' => Mage::helper('tag')->__('Tag') - )); - return $this; - } - - /** - * Loading tag by name - * - * @param Mage_Tag_Model_Tag $model - * @param string $name - * @return unknown - */ - public function loadByName($model, $name) - { - if( $name ) { - $read = $this->_getReadAdapter(); - $select = $read->select(); - if (Mage::helper('core/string')->strlen($name) > 255) { - $name = Mage::helper('core/string')->substr($name, 0, 255); - } - - $select->from($this->getMainTable()) - ->where('name = ?', $name); - $data = $read->fetchRow($select); - - $model->setData( ( is_array($data) ) ? $data : array() ); - } else { - return false; - } - } - - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getId() && $object->getStatus()==$object->getApprovedStatus()) { - $searchTag = new Varien_Object(); - $this->loadByName($searchTag, $object->getName()); - if($searchTag->getData($this->getIdFieldName()) && $searchTag->getStatus()==$object->getPendingStatus()) { - $object->setId($searchTag->getData($this->getIdFieldName())); - } - } - - if (Mage::helper('core/string')->strlen($object->getName()) > 255) { - $object->setName(Mage::helper('core/string')->substr($object->getName(), 0, 255)); - } - - return parent::_beforeSave($object); - } - - /** - * Saving tag's base popularity - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getStore() || !Mage::app()->getStore()->isAdmin()) { - return parent::_afterSave($object); - } - - $tagId = ($object->isObjectNew()) ? $object->getTagId() : $object->getId(); - - $writeAdapter = $this->_getWriteAdapter(); - $writeAdapter->insertOnDuplicate($this->getTable('tag/properties'), array( - 'tag_id' => $tagId, - 'store_id' => $object->getStore(), - 'base_popularity' => (is_null($object->getBasePopularity())) ? 0 : $object->getBasePopularity() - )); - - return parent::_afterSave($object); - } - - /** - * Getting base popularity per store view for specified tag - * - * @deprecated after 1.4.0.0 - * @param int $tagId - * @return array - */ - protected function _getExistingBasePopularity($tagId) - { - $selectSummary = $this->_getReadAdapter()->select() - ->from( - array('main' => $this->getTable('summary')), - array('store_id', 'base_popularity') - ) - ->where('main.tag_id = ?', $tagId) - ->where('main.store_id != 0'); - - return $this->_getReadAdapter()->fetchAssoc($selectSummary); - } - - - /** - * Get aggregation data per store view - * - * @deprecated after 1.4.0.0 - * @param int $tagId - * @return array - */ - protected function _getAggregationPerStoreView($tagId) - { - $readAdapter = $this->_getReadAdapter(); - $selectLocal = $readAdapter->select() - ->from( - array('main' => $this->getTable('relation')), - array( - 'customers'=>'COUNT(DISTINCT main.customer_id)', - 'products'=>'COUNT(DISTINCT main.product_id)', - 'store_id', - 'uses'=>'COUNT(main.tag_relation_id)' - ) - ) - ->join(array('store' => $this->getTable('core/store')), - 'store.store_id=main.store_id AND store.store_id>0', - array() - ) - ->join(array('product_website' => $this->getTable('catalog/product_website')), - 'product_website.website_id=store.website_id AND product_website.product_id=main.product_id', - array() - ) - ->where('main.tag_id = ?', $tagId) - ->where('main.active') - ->group('main.store_id'); - - $selectLocalResult = $readAdapter->fetchAll($selectLocal); - - $selectHistorical = $readAdapter->select() - ->from( - array('main'=>$this->getTable('relation')), - array('historical_uses'=>'COUNT(main.tag_relation_id)', - 'store_id') - ) - ->join(array('store' => $this->getTable('core/store')), - 'store.store_id=main.store_id AND store.store_id>0', - array() - ) - ->join(array('product_website' => $this->getTable('catalog/product_website')), - 'product_website.website_id=store.website_id AND product_website.product_id=main.product_id', - array() - ) - ->group('main.store_id') - ->where('main.tag_id = ?', $tagId); - - $selectHistoricalResult = $readAdapter->fetchAll($selectHistorical); - - foreach ($selectHistoricalResult as $historical) { - foreach ($selectLocalResult as $key => $local) { - if ($local['store_id'] == $historical['store_id']) { - $selectLocalResult[$key]['historical_uses'] = $historical['historical_uses']; - break; - } - } - } - - return $selectLocalResult; - } - - /** - * Get global aggregation data for row with store_id = 0 - * - * @deprecated after 1.4.0.0 - * @param int $tagId - * @return array - */ - protected function _getGlobalAggregation($tagId) - { - $readAdapter = $this->_getReadAdapter(); - // customers and products stats - $selectGlobal = $readAdapter->select() - ->from( - array('main'=>$this->getTable('relation')), - array( - 'customers'=>'COUNT(DISTINCT main.customer_id)', - 'products'=>'COUNT(DISTINCT main.product_id)', - 'store_id'=>'( 0 )' /* Workaround*/, - 'uses'=>'COUNT(main.tag_relation_id)' - ) - ) - ->join(array('store' => $this->getTable('core/store')), - 'store.store_id=main.store_id AND store.store_id>0', - array() - ) - ->join(array('product_website' => $this->getTable('catalog/product_website')), - 'product_website.website_id=store.website_id AND product_website.product_id=main.product_id', - array() - ) - ->where('main.tag_id = ?', $tagId) - ->where('main.active'); - $result = $readAdapter->fetchRow($selectGlobal); - if (!$result) { - return array(); - } - - // historical uses stats - $selectHistoricalGlobal = $readAdapter->select() - ->from( - array('main'=>$this->getTable('relation')), - array('historical_uses'=>'COUNT(main.tag_relation_id)') - ) - ->join(array('store' => $this->getTable('core/store')), - 'store.store_id=main.store_id AND store.store_id>0', - array() - ) - ->join(array('product_website' => $this->getTable('catalog/product_website')), - 'product_website.website_id=store.website_id AND product_website.product_id=main.product_id', - array() - ) - ->where('main.tag_id = ?', $tagId); - $result['historical_uses'] = (int) $readAdapter->fetchOne($selectHistoricalGlobal); - - return $result; - } - - /** - * Getting statistics data into buffer. - * Replacing our buffer array with new statistics and incoming data. - * - * @deprecated after 1.4.0.0 - * @param Mage_Tag_Model_Tag $object - * @return Mage_Tag_Model_Tag - */ - public function aggregate($object) - { - $tagId = (int)$object->getId(); - $storeId = (int)$object->getStore(); - - // create final summary from existing data and add specified base popularity - $finalSummary = $this->_getExistingBasePopularity($tagId); - if ($object->hasBasePopularity() && $storeId) { - $finalSummary[$storeId]['store_id'] = $storeId; - $finalSummary[$storeId]['base_popularity'] = $object->getBasePopularity(); - } - - // calculate aggregation data - $summaries = $this->_getAggregationPerStoreView($tagId); - $summariesGlobal = $this->_getGlobalAggregation($tagId); - if ($summariesGlobal) { - $summaries[] = $summariesGlobal; - } - - // override final summary with aggregated data - foreach ($summaries as $row) { - $storeId = (int)$row['store_id']; - foreach ($row as $key => $value) { - $finalSummary[$storeId][$key] = $value; - } - } - - // prepare static parameters to final summary for insertion - foreach ($finalSummary as $key => $row) { - $finalSummary[$key]['tag_id'] = $tagId; - foreach (array('base_popularity', 'popularity', 'historical_uses', 'uses', 'products', 'customers') as $k) { - if (!isset($row[$k])) { - $finalSummary[$key][$k] = 0; - } - } - $finalSummary[$key]['popularity'] = $finalSummary[$key]['historical_uses']; - } - - // remove old and insert new data - $this->_getWriteAdapter()->delete( - $this->getTable('summary'), $this->_getWriteAdapter()->quoteInto('tag_id = ?', $tagId) - ); - $this->_getWriteAdapter()->insertMultiple($this->getTable('summary'), $finalSummary); - - return $object; - } - - /** - * Decrementing tag products quantity as action for product delete - * - * @param array $tagsId - * @return int The number of affected rows - */ - public function decrementProducts(array $tagsId) - { - $writeAdapter = $this->_getWriteAdapter(); - $whereCond = $writeAdapter->quoteInto('`tag_id` IN (?)', $tagsId, Zend_Db::INT_TYPE); - - return $writeAdapter->update($this->getTable('summary'), array('products' => new Zend_Db_Expr('products - 1')), $whereCond); - } - - /** - * Add summary data to specified object - * - * @deprecated after 1.4.0.0 - * @param Mage_Tag_Model_Tag $object - * @return Mage_Tag_Model_Tag - */ - public function addSummary($object) - { - $select = $this->_getReadAdapter()->select() - ->from(array('relation' => $this->getTable('tag/relation')), array()) - ->joinLeft( - array('summary' => $this->getTable('tag/summary')), - 'relation.tag_id = summary.tag_id AND relation.store_id = summary.store_id', - array( - 'customers', - 'products', - 'popularity' - ) - ) - ->where('relation.tag_id = ?', (int)$object->getId()) - ->where('relation.store_id = ?', (int)$object->getStoreId()) - ->limit(1); - - $row = $this->_getReadAdapter()->fetchRow($select); - if ($row) { - $object->addData($row); - } - return $object; - } - - /** - * Retrieve select object for load object data - * Redeclare parent method just for adding tag's base popularity if flag exists - * - * @param string $field - * @param mixed $value - * @param Mage_Core_Model_Abstract $object - * @return Zend_Db_Select - */ - protected function _getLoadSelect($field, $value, $object) - { - $select = parent::_getLoadSelect($field, $value, $object); - if ($object->getAddBasePopularity() && $object->hasStoreId()) { - $select->joinLeft( - array('properties' => $this->getTable('tag/properties')), - "properties.tag_id = {$this->getMainTable()}.tag_id AND properties.store_id = {$object->getStoreId()}", - 'base_popularity' - ); - } - return $select; - } - - /** - * Fetch store ids in which tag visible - * - * @param Mage_Tag_Model_Mysql4_Tag $object - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('tag/summary'), array('store_id')) - ->where('tag_id = ?', $object->getId()); - $storeIds = $this->_getReadAdapter()->fetchCol($select); - - $object->setVisibleInStoreIds($storeIds); - - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Tag/Collection.php b/app/code/core/Mage/Tag/Model/Mysql4/Tag/Collection.php index 30347489d9..49c7c88680 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Tag/Collection.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Tag/Collection.php @@ -20,302 +20,18 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tag collection model * - * @category Mage - * @package Mage_Tag + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ - -class Mage_Tag_Model_Mysql4_Tag_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tag_Model_Mysql4_Tag_Collection extends Mage_Tag_Model_Resource_Tag_Collection { - /** - * Use getFlag('store_filter') & setFlag('store_filter', true) instead. - * - * @deprecated after 1.3.2.3 - */ - protected $_isStoreFilter = false; - - /** - * @deprecated after 1.3.2.3 - */ - protected $_joinFlags = array(); - - var $_map = array( - 'fields' => array( - 'tag_id' => 'main_table.tag_id' - ), - ); - - protected function _construct() - { - $this->_init('tag/tag'); - } - - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - parent::load($printQuery, $logQuery); - if ($this->getFlag('add_stores_after')) { - $this->_addStoresVisibility(); - } - return $this; - } - - /** - * Set flag about joined table. - * setFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param string $table - * @return Mage_Tag_Model_Mysql4_Tag_Collection - */ - public function setJoinFlag($table) - { - $this->setFlag($table, true); - return $this; - } - - /** - * Get flag's status about joined table. - * getFlag method must be used in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return bool - */ - public function getJoinFlag($table) - { - return $this->getFlag($table); - } - - /** - * Unset value of join flag. - * Set false (bool) value to flag instead in future. - * - * @deprecated after 1.3.2.3 - * @param $table - * @return Mage_Tag_Model_Mysql4_Tag_Collection - */ - public function unsetJoinFlag($table=null) - { - $this->setFlag($table, false); - return $this; - } - - public function limit($limit) - { - $this->getSelect()->limit($limit); - return $this; - } - - /** - * Replacing popularity by sum of popularity and base_popularity - * - * @param int $limit - * @return Mage_Tag_Model_Mysql4_Tag_Collection - */ - public function addPopularity($limit = null) - { - if (!$this->getFlag('popularity')) { - $this->getSelect() - ->joinLeft(array('relation' => $this->getTable('tag/relation')), 'main_table.tag_id=relation.tag_id') - ->joinLeft(array('summary' => $this->getTable('tag/summary')), - 'relation.tag_id = summary.tag_id AND relation.store_id = summary.store_id', 'popularity' - ) - ->group('main_table.tag_id'); - - if (!is_null($limit)) { - $this->getSelect()->limit($limit); - } - - $this->setFlag('popularity'); - } - return $this; - } - - public function addSummary($storeId) - { - if (!$this->getFlag('summary')) { - $tableAlias = 'summary'; - $joinCondition = $this->getConnection()->quoteInto(' AND '. $tableAlias .'.store_id IN(?)', $storeId); - - $this->getSelect() - ->joinLeft( - array($tableAlias => $this->getTable('tag/summary')), - 'main_table.tag_id='. $tableAlias .'.tag_id' . $joinCondition, - array('store_id','popularity', 'customers', 'products' - )); - - $this->addFilterToMap('store_id', $tableAlias . '.store_id'); - $this->addFilterToMap('popularity', $tableAlias . '.popularity'); - $this->addFilterToMap('customers', $tableAlias . '.customers'); - $this->addFilterToMap('products', $tableAlias . '.products'); - - $this->setFlag('summary', true); - } - return $this; - } - - public function addStoresVisibility() - { - $this->setFlag('add_stores_after', true); - return $this; - } - - protected function _addStoresVisibility() - { - $tagIds = $this->getColumnValues('tag_id'); - - $tagsStores = array(); - if (sizeof($tagIds)>0) { - $select = $this->getConnection()->select() - ->from($this->getTable('summary'), array('store_id', 'tag_id')) - ->where('tag_id IN(?)', $tagIds); - $tagsRaw = $this->getConnection()->fetchAll($select); - - foreach ($tagsRaw as $tag) { - if (!isset($tagsStores[$tag['tag_id']])) { - $tagsStores[$tag['tag_id']] = array(); - } - - $tagsStores[$tag['tag_id']][] = $tag['store_id']; - } - } - - foreach ($this as $item) { - if(isset($tagsStores[$item->getId()])) { - $item->setStores($tagsStores[$item->getId()]); - } else { - $item->setStores(array()); - } - } - - return $this; - } - - public function addFieldToFilter($field, $condition=null) - { - if ($this->getFlag('relation') && 'popularity' == $field) { - // TOFIX - $this->getSelect()->having($this->_getConditionSql('count(relation.tag_relation_id)', $condition)); - } elseif ($this->getFlag('summary') && in_array($field, array('customers', 'products', 'uses', 'historical_uses', 'popularity'))) { - $this->getSelect()->where($this->_getConditionSql('summary.'.$field, $condition)); - } else { - parent::addFieldToFilter($field, $condition); - } - return $this; - } - - /** - * Get sql for get record count - * - * @return string - */ - - public function getSelectCountSql() - { - $this->_renderFilters(); - $countSelect = clone $this->_select; - $countSelect->reset(Zend_Db_Select::ORDER); - $countSelect->reset(Zend_Db_Select::GROUP); - $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); - $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); - - $sql = $countSelect->__toString(); - // TOFIX - $sql = preg_replace('/^select\s+.+?\s+from\s+/is', 'select COUNT(DISTINCT main_table.tag_id) from ', $sql); - return $sql; - } - - /** - * Add filter by store - * - * @param array | int $storeId - * @param bool $allFilter - * @return Mage_Tag_Model_Mysql4_Tag_Collection - */ - public function addStoreFilter($storeId, $allFilter = true) - { - if (!$this->getFlag('store_filter')) { - - $this->getSelect()->joinLeft( - array('summary_store'=>$this->getTable('summary')), - 'main_table.tag_id = summary_store.tag_id' - ); - - $this->getSelect()->where('summary_store.store_id IN (?)', $storeId); - - $this->getSelect()->group('summary_store.tag_id'); - - if($this->getFlag('relation') && $allFilter) { - $this->getSelect()->where('relation.store_id IN (?)', $storeId); - } - if($this->getFlag('prelation') && $allFilter) { - $this->getSelect()->where('prelation.store_id IN (?)', $storeId); - } - - $this->setFlag('store_filter', true); - } - - return $this; - } - - public function setActiveFilter() - { - $statusActive = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE; - $this->getSelect()->where('relation.active = ?', $statusActive); - if($this->getFlag('prelation')) { - $this->getSelect()->where('prelation.active = ?', $statusActive); - } - return $this; - } - - public function addStatusFilter($status) - { - $this->getSelect()->where('main_table.status = ?', $status); - return $this; - } - - public function addProductFilter($productId) - { - $this->addFieldToFilter('relation.product_id', $productId); - if($this->getFlag('prelation')) { - $this->addFieldToFilter('prelation.product_id', $productId); - } - return $this; - } - - public function addCustomerFilter($customerId) - { - $this->getSelect() - ->where('relation.customer_id = ?', $customerId); - if($this->getFlag('prelation')) { - $this->getSelect() - ->where('prelation.customer_id = ?', $customerId); - } - return $this; - } - - - public function addTagGroup() - { - $this->getSelect()->group('main_table.tag_id'); - return $this; - } - - - public function joinRel() - { - $this->setFlag('relation', true); - $this->getSelect()->joinLeft(array('relation'=>$this->getTable('tag/relation')), 'main_table.tag_id=relation.tag_id'); - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Mysql4/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Mysql4/Tag/Relation.php index 8a2b29b26e..0fb3171c72 100644 --- a/app/code/core/Mage/Tag/Model/Mysql4/Tag/Relation.php +++ b/app/code/core/Mage/Tag/Model/Mysql4/Tag/Relation.php @@ -20,161 +20,18 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tag Relation resource model * - * @category Mage - * @package Mage_Tag + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ - -class Mage_Tag_Model_Mysql4_Tag_Relation extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tag_Model_Mysql4_Tag_Relation extends Mage_Tag_Model_Resource_Tag_Relation { - /** - * Initialize resource connection and define table resource - * - */ - protected function _construct() - { - $this->_init('tag/relation', 'tag_relation_id'); - } - - /** - * Load by Tag and Customer - * - * @param Mage_Tag_Model_Tag_Relation $model - * @return Mage_Tag_Model_Mysql4_Tag_Relation - */ - public function loadByTagCustomer($model) - { - if ($model->getTagId() && $model->getCustomerId()) { - $read = $this->_getReadAdapter(); - $select = $read->select() - ->from($this->getMainTable()) - ->join($this->getTable('tag/tag'), "{$this->getTable('tag/tag')}.tag_id = {$this->getMainTable()}.tag_id") - ->where("{$this->getMainTable()}.tag_id = ?", $model->getTagId()) - ->where('customer_id = ?', $model->getCustomerId()); - - if ($model->getProductId()) { - $select->where("{$this->getMainTable()}.product_id = ?", $model->getProductId()); - } - - if ($model->hasStoreId()) { - $select->where("{$this->getMainTable()}.store_id = ?", $model->getStoreId()); - } - $data = $read->fetchRow($select); - $model->setData( ( is_array($data) ) ? $data : array() ); - } - - return $this; - } - - /** - * Retrieve Tagged Products - * - * @param Mage_Tag_Model_Tag_Relation $model - * @return array - */ - public function getProductIds($model) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'product_id') - ->where("{$this->getMainTable()}.tag_id=?", $model->getTagId()); - - if (!is_null($model->getCustomerId())) { - $select->where("{$this->getMainTable()}.customer_id=?", $model->getCustomerId()); - } - - if ($model->hasStoreId()) { - $select->where("{$this->getMainTable()}.store_id = ?", $model->getStoreId()); - } - - if (!is_null($model->getStatusFilter())) { - $select->join($this->getTable('tag/tag'), "{$this->getTable('tag/tag')}.tag_id = {$this->getMainTable()}.tag_id") - ->where("{$this->getTable('tag/tag')}.status = ?", $model->getStatusFilter()); - } - - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Retrieve related to product tag ids - * - * @param Mage_Tag_Model_Tag_Relation $model - * @return array - */ - public function getRelatedTagIds($model) - { - $productIds = (is_array($model->getProductId())) ? $model->getProductId() : array($model->getProductId()); - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'tag_id') - ->where("product_id IN(?)", $productIds) - ->order('tag_id'); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Deactivate tag relations by tag and customer - * - * @param int $tagId - * @param int $customerId - * @return Mage_Tag_Model_Mysql4_Tag_Relation - */ - public function deactivate($tagId, $customerId) - { - $condition = $this->_getWriteAdapter()->quoteInto('tag_id = ?', $tagId) . ' AND '; - $condition.= $this->_getWriteAdapter()->quoteInto('customer_id = ?', $customerId); - $data = array('active' => Mage_Tag_Model_Tag_Relation::STATUS_NOT_ACTIVE); - $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); - return $this; - } - - /** - * Add TAG to PRODUCT relations - * - * @param Mage_Tag_Model_Tag_Relation $model - * @return Mage_Tag_Model_Mysql4_Tag_Relation - */ - public function addRelations($model) - { - $addedIds = $model->getAddedProductIds(); - - $select = $this->_getWriteAdapter()->select() - ->from($this->getMainTable(), 'product_id') - ->where("tag_id = ?", $model->getTagId()) - ->where("store_id = ?", $model->getStoreId()) - ->where("customer_id IS NULL"); - $oldRelationIds = $this->_getWriteAdapter()->fetchCol($select); - - $insert = array_diff($addedIds, $oldRelationIds); - $delete = array_diff($oldRelationIds, $addedIds); - - if (!empty($insert)) { - $insertData = array(); - foreach ($insert as $value) { - $insertData[] = array( - 'tag_id' => $model->getTagId(), - 'store_id' => $model->getStoreId(), - 'product_id' => $value, - 'customer_id' => $model->getCustomerId(), - 'created_at' => $this->formatDate(time()) - ); - } - $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $insertData); - } - - if (!empty($delete)) { - $this->_getWriteAdapter()->delete($this->getMainTable(), array( - $this->_getWriteAdapter()->quoteInto('product_id IN (?)', $delete), - $this->_getWriteAdapter()->quoteInto('store_id = ?', $model->getStoreId()), - 'customer_id IS NULL' - )); - } - - return $this; - } } diff --git a/app/code/core/Mage/Tag/Model/Resource/Customer/Collection.php b/app/code/core/Mage/Tag/Model/Resource/Customer/Collection.php new file mode 100755 index 0000000000..6cf9ac9411 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Customer/Collection.php @@ -0,0 +1,376 @@ + + */ +class Mage_Tag_Model_Resource_Customer_Collection extends Mage_Customer_Model_Resource_Customer_Collection +{ + /** + * Allows disabling grouping + * + * @var bool + */ + protected $_allowDisableGrouping = true; + + /** + * Count attribute for count sql + * + * @var string + */ + protected $_countAttribute = 'tr.tag_id'; + + /** + * Array with joined tables + * + * @var array + */ + protected $_joinFlags = array(); + + /** + * Prepare select + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function _initSelect() + { + parent::_initSelect(); + $this->_joinFields(); + $this->_setIdFieldName('tag_relation_id'); + return $this; + } + + /** + * Set flag about joined table. + * setFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function setJoinFlag($table) + { + $this->setFlag($table, true); + return $this; + } + + /** + * Get flag's status about joined table. + * getFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return bool + */ + public function getJoinFlag($table) + { + return $this->getFlag($table); + } + + /** + * Unset value of join flag. + * Set false (bool) value to flag instead in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function unsetJoinFlag($table = null) + { + $this->setFlag($table, false); + return $this; + } + + /** + * Adds filter by tag is + * + * @param int $tagId + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addTagFilter($tagId) + { + $this->getSelect() + ->where('tr.tag_id = ?', $tagId); + return $this; + } + + /** + * adds filter by product id + * + * @param int $productId + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addProductFilter($productId) + { + $this->getSelect() + ->where('tr.product_id = ?', $productId); + return $this; + } + + /** + * Apply filter by store id(s). + * + * @param int|array $storeId + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addStoreFilter($storeId) + { + $this->getSelect()->where('tr.store_id IN (?)', $storeId); + return $this; + } + + /** + * Adds filter by status + * + * @param int $status + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addStatusFilter($status) + { + $this->getSelect() + ->where('t.status = ?', $status); + return $this; + } + + /** + * Adds desc order by tag relation id + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addDescOrder() + { + $this->getSelect() + ->order('tr.tag_relation_id desc'); + return $this; + } + + /** + * Adds grouping by tag id + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addGroupByTag() + { + $this->getSelect() + ->group('tr.tag_id'); + + /* + * Allow analytic functions usage + */ + $this->_useAnalyticFunction = true; + + $this->_allowDisableGrouping = true; + return $this; + } + + /** + * Adds grouping by customer id + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addGroupByCustomer() + { + $this->getSelect() + ->group('tr.customer_id'); + + $this->_allowDisableGrouping = false; + return $this; + } + + /** + * Disables grouping + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addGroupByCustomerProduct() + { + // Nothing need to group + $this->_allowDisableGrouping = false; + return $this; + } + + /** + * Adds filter by customer id + * + * @param int $customerId + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addCustomerFilter($customerId) + { + $this->getSelect()->where('tr.customer_id = ?', $customerId); + return $this; + } + + /** + * Joins tables to select + * + */ + protected function _joinFields() + { + $tagRelationTable = $this->getTable('tag/relation'); + $tagTable = $this->getTable('tag/tag'); + + //TODO: add full name logic + $this->addAttributeToSelect('firstname') + ->addAttributeToSelect('lastname') + ->addAttributeToSelect('email'); + + $this->getSelect() + ->join( + array('tr' => $tagRelationTable), + 'tr.customer_id = e.entity_id', + array('tag_relation_id', 'product_id', 'active') + ) + ->join(array('t' => $tagTable), 't.tag_id = tr.tag_id', array('*')); + } + + /** + * Gets number of rows + * + * @return Varien_Db_Select + */ + public function getSelectCountSql() + { + $countSelect = parent::getSelectCountSql(); + + if ($this->_allowDisableGrouping) { + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::GROUP); + $countSelect->columns('COUNT(DISTINCT ' . $this->getCountAttribute() . ')'); + } + return $countSelect; + } + + /** + * Adds Product names to select + * + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addProductName() + { + $productsId = array(); + $productsData = array(); + + foreach ($this->getItems() as $item) { + $productsId[] = $item->getProductId(); + } + + $productsId = array_unique($productsId); + + /* small fix */ + if ( sizeof($productsId) == 0 ) { + return; + } + + $collection = Mage::getModel('catalog/product')->getCollection() + ->addAttributeToSelect('name') + ->addAttributeToSelect('sku') + ->addIdFilter($productsId); + + $collection->load(); + + foreach ($collection->getItems() as $item) { + $productsData[$item->getId()] = $item->getName(); + $productsSku[$item->getId()] = $item->getSku(); + } + + foreach ($this->getItems() as $item) { + $item->setProduct($productsData[$item->getProductId()]); + $item->setProductSku($productsSku[$item->getProductId()]); + } + return $this; + } + + /** + * Sets order by attribute + * + * @param string $attribute + * @param string $dir + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function setOrder($attribute, $dir = 'desc') + { + switch( $attribute ) { + case 'name': + case 'status': + $this->getSelect()->order($attribute . ' ' . $dir); + break; + + default: + parent::setOrder($attribute, $dir); + } + return $this; + } + + /** + * Sets attribute for count + * + * @param string $value + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function setCountAttribute($value) + { + $this->_countAttribute = $value; + return $this; + } + + /** + * Gets attribure for count + * + * @return string + */ + public function getCountAttribute() + { + return $this->_countAttribute; + } + + /** + * Adds field to filter + * + * @param string $attribute + * @param array $condition + * @return Mage_Tag_Model_Resource_Customer_Collection + */ + public function addFieldToFilter($attribute, $condition = null) + { + if ($attribute == 'name') { + $where = $this->_getConditionSql('t.name', $condition); + $this->getSelect()->where($where, null, Varien_Db_Select::TYPE_CONDITION); + return $this; + } else { + return parent::addFieldToFilter($attribute, $condition); + } + } + +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Indexer/Summary.php b/app/code/core/Mage/Tag/Model/Resource/Indexer/Summary.php new file mode 100755 index 0000000000..0a494e0c11 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Indexer/Summary.php @@ -0,0 +1,265 @@ + + */ +class Mage_Tag_Model_Resource_Indexer_Summary extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('tag/summary', 'tag_id'); + } + + /** + * Process tag save + * + * @param Mage_Index_Model_Event $event + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function tagSave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['tag_reindex_tag_id'])) { + return $this; + } + return $this->aggregate($data['tag_reindex_tag_id']); + } + + /** + * Process tag relation save + * + * @param Mage_Index_Model_Event $event + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function tagRelationSave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['tag_reindex_tag_id'])) { + return $this; + } + return $this->aggregate($data['tag_reindex_tag_id']); + } + + /** + * Process product save. + * Method is responsible for index support when product was saved. + * + * @param Mage_Index_Model_Event $event + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function catalogProductSave(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['tag_reindex_required'])) { + return $this; + } + + $tagIds = Mage::getModel('tag/tag_relation') + ->setProductId($event->getEntityPk()) + ->getRelatedTagIds(); + + return $this->aggregate($tagIds); + } + + /** + * Process product delete. + * Method is responsible for index support when product was deleted + * + * @param Mage_Index_Model_Event $event + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function catalogProductDelete(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['tag_reindex_tag_ids'])) { + return $this; + } + return $this->aggregate($data['tag_reindex_tag_ids']); + } + + /** + * Process product massaction + * + * @param Mage_Index_Model_Event $event + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function catalogProductMassAction(Mage_Index_Model_Event $event) + { + $data = $event->getNewData(); + if (empty($data['tag_reindex_tag_ids'])) { + return $this; + } + return $this->aggregate($data['tag_reindex_tag_ids']); + } + + /** + * Reindex all tags + * + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function reindexAll() + { + return $this->aggregate(); + } + + /** + * Aggregate tags by specified ids + * + * @param null|int|array $tagIds + * @return Mage_Tag_Model_Resource_Indexer_Summary + */ + public function aggregate($tagIds = null) + { + $writeAdapter = $this->_getWriteAdapter(); + $writeAdapter->beginTransaction(); + + try { + if (!empty($tagIds)) { + $writeAdapter->delete( + $this->getTable('tag/summary'), array('tag_id IN(?)' => $tagIds) + ); + } else { + $writeAdapter->delete($this->getTable('tag/summary')); + } + + $select = $writeAdapter->select() + ->from( + array('tr' => $this->getTable('tag/relation')), + array( + 'tr.tag_id', + 'tr.store_id', + 'customers' => 'COUNT(DISTINCT tr.customer_id)', + 'products' => 'COUNT(DISTINCT tr.product_id)', + 'popularity' => 'COUNT(tr.customer_id) + MIN(' + . $writeAdapter->getCheckSql( + 'tp.base_popularity IS NOT NULL', + 'tp.base_popularity', + '0' + ) + . ')', + 'uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 + 'historical_uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 + 'base_popularity' => new Zend_Db_Expr(0) // deprecated since 1.4.0.1 + ) + ) + ->joinInner( + array('cs' => $this->getTable('core/store')), + 'cs.store_id = tr.store_id', + array() + ) + ->joinInner( + array('pw' => $this->getTable('catalog/product_website')), + 'cs.website_id = pw.website_id AND tr.product_id = pw.product_id', + array() + ) + ->joinInner( + array('e' => $this->getTable('catalog/product')), + 'tr.product_id = e.entity_id', + array() + ) + ->joinLeft( + array('tp' => $this->getTable('tag/properties')), + 'tp.tag_id = tr.tag_id AND tp.store_id = tr.store_id', + array() + ) + ->group(array( + 'tr.tag_id', + 'tr.store_id' + )); + + $statusCond = $writeAdapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); + $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond); + + $visibilityCond = $writeAdapter + ->quoteInto('!=?', Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE); + $this->_addAttributeToSelect($select, 'visibility', 'e.entity_id', 'cs.store_id', $visibilityCond); + + if (!empty($tagIds)) { + $select->where('tr.tag_id IN(?)', $tagIds); + } + + Mage::dispatchEvent('prepare_catalog_product_index_select', array( + 'select' => $select, + 'entity_field' => new Zend_Db_Expr('e.entity_id'), + 'website_field' => new Zend_Db_Expr('cs.website_id'), + 'store_field' => new Zend_Db_Expr('cs.store_id') + )); + + $writeAdapter->query( + $select->insertFromSelect($this->getTable('tag/summary'), array( + 'tag_id', + 'store_id', + 'customers', + 'products', + 'popularity', + 'uses', // deprecated since 1.4.0.1 + 'historical_uses', // deprecated since 1.4.0.1 + 'base_popularity' // deprecated since 1.4.0.1 + )) + ); + + + $selectedFields = array( + 'tag_id' => 'tag_id', + 'store_id' => new Zend_Db_Expr(0), + 'customers' => 'COUNT(DISTINCT customer_id)', + 'products' => 'COUNT(DISTINCT product_id)', + 'popularity' => 'COUNT(customer_id)', + 'uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 + 'historical_uses' => new Zend_Db_Expr(0), // deprecated since 1.4.0.1 + 'base_popularity' => new Zend_Db_Expr(0) // deprecated since 1.4.0.1 + ); + + $agregateSelect = $writeAdapter->select(); + $agregateSelect->from($this->getTable('tag/relation'), $selectedFields) + ->group('tag_id'); + + if (!empty($tagIds)) { + $agregateSelect->where('tag_id IN(?)', $tagIds); + } + + $writeAdapter->query( + $agregateSelect->insertFromSelect($this->getTable('tag/summary'), array_keys($selectedFields)) + ); + } catch (Exception $e) { + $writeAdapter->rollBack(); + throw $e; + } + + $writeAdapter->commit(); + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Popular/Collection.php b/app/code/core/Mage/Tag/Model/Resource/Popular/Collection.php new file mode 100755 index 0000000000..2318fa27a5 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Popular/Collection.php @@ -0,0 +1,108 @@ + + */ +class Mage_Tag_Model_Resource_Popular_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Defines resource model and model + * + */ + protected function _construct() + { + $this->_init('tag/tag'); + } + + /** + * Replacing popularity by sum of popularity and base_popularity + * + * @param int $storeId + * @return Mage_Tag_Model_Resource_Popular_Collection + */ + public function joinFields($storeId = 0) + { + $this->getSelect() + ->reset() + ->from( + array('tag_summary' => $this->getTable('tag/summary')), + array('popularity' => 'tag_summary.popularity')) + ->joinInner( + array('tag' => $this->getTable('tag/tag')), + 'tag.tag_id = tag_summary.tag_id AND tag.status = ' . Mage_Tag_Model_Tag::STATUS_APPROVED) + ->where('tag_summary.store_id = ?', $storeId) + ->where('tag_summary.products > ?', 0) + ->order('popularity ' . Varien_Db_Select::SQL_DESC); + + return $this; + } + + /** + * Add filter by specified tag status + * + * @param string $statusCode + * @return Mage_Tag_Model_Resource_Popular_Collection + */ + public function addStatusFilter($statusCode) + { + $this->getSelect()->where('main_table.status = ?', $statusCode); + return $this; + } + + /** + * Loads collection + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Tag_Model_Resource_Popular_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + parent::load($printQuery, $logQuery); + return $this; + } + + /** + * Sets limit + * + * @param int $limit + * @return Mage_Tag_Model_Resource_Popular_Collection + */ + public function limit($limit) + { + $this->getSelect()->limit($limit); + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Product/Collection.php b/app/code/core/Mage/Tag/Model/Resource/Product/Collection.php new file mode 100755 index 0000000000..ffeb3ebc18 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Product/Collection.php @@ -0,0 +1,480 @@ + + */ +class Mage_Tag_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Customer Id Filter + * + * @var int + */ + protected $_customerFilterId; + + /** + * Tag Id Filter + * + * @var int + */ + protected $_tagIdFilter; + + /** + * Join Flags + * + * @var array + */ + protected $_joinFlags = array(); + + /** + * Initialize collection select + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + + $this->_joinFields(); + $this->getSelect()->group('e.entity_id'); + + /* + * Allow analytic function usage + */ + $this->_useAnalyticFunction = true; + + return $this; + } + + /** + * Set flag about joined table. + * setFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function setJoinFlag($table) + { + $this->setFlag($table, true); + return $this; + } + + /** + * Get flag's status about joined table. + * getFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return bool + */ + public function getJoinFlag($table) + { + return $this->getFlag($table); + } + + /** + * Unset value of join flag. + * Set false (bool) value to flag instead in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function unsetJoinFlag($table = null) + { + $this->setFlag($table, false); + return $this; + } + + /** + * Add tag visibility on stores + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addStoresVisibility() + { + $this->setFlag('add_stores_after', true); + return $this; + } + + /** + * Add tag visibility on stores process + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + protected function _addStoresVisibility() + { + $tagIds = array(); + foreach ($this as $item) { + $tagIds[] = $item->getTagId(); + } + + $tagsStores = array(); + if (sizeof($tagIds) > 0) { + $select = $this->getConnection()->select() + ->from($this->getTable('tag/relation'), array('store_id', 'tag_id')) + ->where('tag_id IN(?)', $tagIds); + $tagsRaw = $this->getConnection()->fetchAll($select); + foreach ($tagsRaw as $tag) { + if (!isset($tagsStores[$tag['tag_id']])) { + $tagsStores[$tag['tag_id']] = array(); + } + + $tagsStores[$tag['tag_id']][] = $tag['store_id']; + } + } + + foreach ($this as $item) { + if (isset($tagsStores[$item->getTagId()])) { + $item->setStores($tagsStores[$item->getTagId()]); + } else { + $item->setStores(array()); + } + } + + return $this; + } + + /** + * Add group by tag + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addGroupByTag() + { + $this->getSelect()->group('relation.tag_relation_id'); + return $this; + } + + /** + * Add Store ID filter + * + * @param int|array $store + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addStoreFilter($store = null) + { + if (!is_null($store)) { + $this->getSelect()->where('relation.store_id IN (?)', $store); + } + return $this; + } + + /** + * Set Customer filter + * If incoming parameter is array and has element with key 'null' + * then condition with IS NULL or IS NOT NULL will be added. + * Otherwise condition with IN() will be added + * + * @param int|array $customerId + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addCustomerFilter($customerId) + { + if (is_array($customerId) && isset($customerId['null'])) { + $condition = ($customerId['null']) ? 'IS NULL' : 'IS NOT NULL'; + $this->getSelect()->where('relation.customer_id ' . $condition); + return $this; + } + $this->getSelect()->where('relation.customer_id IN(?)', $customerId); + $this->_customerFilterId = $customerId; + return $this; + } + + /** + * Set tag filter + * + * @param int $tagId + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addTagFilter($tagId) + { + $this->getSelect()->where('relation.tag_id = ?', $tagId); + $this->setFlag('distinct', true); + return $this; + } + + /** + * Add tag status filter + * + * @param int $status + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addStatusFilter($status) + { + $this->getSelect()->where('t.status = ?', $status); + return $this; + } + + /** + * Set DESC order to collection + * + * @param string $dir + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function setDescOrder($dir = 'DESC') + { + $this->setOrder('relation.tag_relation_id', $dir); + return $this; + } + + /** + * Add Popularity + * + * @param int $tagId + * @param int $storeId + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addPopularity($tagId, $storeId = null) + { + $tagRelationTable = $this->getTable('tag/relation'); + + $condition = array( + 'prelation.product_id=e.entity_id' + ); + + if (!is_null($storeId)) { + $condition[] = $this->getConnection()->quoteInto('prelation.store_id = ?', $storeId); + } + $condition = join(' AND ', $condition); + $innerSelect = $this->getConnection()->select() + ->from( + array('relation' => $tagRelationTable), + array('product_id', 'store_id', 'popularity' => 'COUNT(DISTINCT relation.tag_relation_id)') + ) + ->where('relation.tag_id = ?', $tagId) + ->group(array('product_id', 'store_id')); + + $this->getSelect() + ->joinLeft( + array('prelation' => $innerSelect), + $condition, + array('popularity' => 'prelation.popularity') + ); + + $this->_tagIdFilter = $tagId; + $this->setFlag('prelation', true); + return $this; + } + + /** + * Add Popularity Filter + * + * @param mixed $condition + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addPopularityFilter($condition) + { + $tagRelationTable = Mage::getSingleton('core/resource') + ->getTableName('tag/relation'); + + $select = $this->getConnection()->select() + ->from($tagRelationTable, array('product_id', 'popularity' => 'COUNT(DISTINCT tag_relation_id)')) + ->where('tag_id = :tag_id') + ->group('product_id') + ->having($this->_getConditionSql('popularity', $condition)); + + $prodIds = array(); + foreach ($this->getConnection()->fetchAll($select, array('tag_id' => $this->_tagIdFilter)) as $item) { + $prodIds[] = $item['product_id']; + } + + if (sizeof($prodIds) > 0) { + $this->getSelect()->where('e.entity_id IN(?)', $prodIds); + } else { + $this->getSelect()->where('e.entity_id IN(0)'); + } + + return $this; + } + + /** + * Set tag active filter to collection + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function setActiveFilter() + { + $active = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE; + $this->getSelect()->where('relation.active = ?', $active); + if ($this->getFlag('prelation')) { + $this->getSelect()->where('prelation.active = ?', $active); + } + return $this; + } + + /** + * Add Product Tags + * + * @param int $storeId + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function addProductTags($storeId = null) + { + foreach ($this->getItems() as $item) { + $tagsCollection = Mage::getModel('tag/tag')->getResourceCollection(); + + if (!is_null($storeId)) { + $tagsCollection->addStoreFilter($storeId); + } + + $tagsCollection->addPopularity() + ->addProductFilter($item->getEntityId()) + ->addCustomerFilter($this->_customerFilterId) + ->setActiveFilter(); + + $tagsCollection->load(); + $item->setProductTags($tagsCollection); + } + + return $this; + } + + /** + * Join fields process + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + protected function _joinFields() + { + $tagTable = $this->getTable('tag/tag'); + $tagRelationTable = $this->getTable('tag/relation'); + + $this->addAttributeToSelect('name') + ->addAttributeToSelect('price') + ->addAttributeToSelect('small_image'); + + $this->getSelect() + ->join(array('relation' => $tagRelationTable), 'relation.product_id = e.entity_id', array( + 'product_id' => 'product_id', + 'item_store_id' => 'store_id', + )) + ->join(array('t' => $tagTable), + 't.tag_id = relation.tag_id', + array( + 'tag_id', + 'tag_status' => 'status', + 'tag_name' => 'name', + 'store_id' => $this->getConnection()->getCheckSql( + 't.first_store_id = 0', + 'relation.store_id', + 't.first_store_id' + ) + ) + ); + + return $this; + } + + /** + * After load adding data + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + if ($this->getFlag('add_stores_after')) { + $this->_addStoresVisibility(); + } + + if (count($this) > 0) { + Mage::dispatchEvent('tag_tag_product_collection_load_after', array( + 'collection' => $this + )); + } + + return $this; + } + + /** + * Render SQL for retrieve product count + * + * @return string + */ + public function getSelectCountSql() + { + $countSelect = clone $this->getSelect(); + + $countSelect->reset(Zend_Db_Select::COLUMNS); + $countSelect->reset(Zend_Db_Select::ORDER); + $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); + $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); + $countSelect->reset(Zend_Db_Select::GROUP); + + if ($this->getFlag('group_tag')) { + $field = 'relation.tag_id'; + } else { + $field = 'e.entity_id'; + } + $expr = new Zend_Db_Expr('COUNT(' + . ($this->getFlag('distinct') ? 'DISTINCT ' : '') + . $field . ')'); + + $countSelect->columns($expr); + + return $countSelect; + } + + /** + * Set attribute order + * + * @param string $attribute + * @param string $dir + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function setOrder($attribute, $dir = 'desc') + { + if ($attribute == 'popularity') { + $this->getSelect()->order($attribute . ' ' . $dir); + } else { + parent::setOrder($attribute, $dir); + } + return $this; + } + + /** + * Set Id Fieldname as Tag Relation Id + * + * @return Mage_Tag_Model_Resource_Product_Collection + */ + public function setRelationId() + { + $this->_setIdFieldName('tag_relation_id'); + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag.php b/app/code/core/Mage/Tag/Model/Resource/Tag.php new file mode 100755 index 0000000000..e51e277cb7 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Tag.php @@ -0,0 +1,432 @@ + + */ +class Mage_Tag_Model_Resource_Tag extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table and primary index + * + */ + protected function _construct() + { + $this->_init('tag/tag', 'tag_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Tag_Model_Resource_Tag + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => 'name', + 'title' => Mage::helper('tag')->__('Tag') + )); + return $this; + } + + /** + * Loading tag by name + * + * @param Mage_Tag_Model_Tag $model + * @param string $name + * @return array|false + */ + public function loadByName($model, $name) + { + if ( $name ) { + $read = $this->_getReadAdapter(); + $select = $read->select(); + if (Mage::helper('core/string')->strlen($name) > 255) { + $name = Mage::helper('core/string')->substr($name, 0, 255); + } + + $select->from($this->getMainTable()) + ->where('name = :name'); + $data = $read->fetchRow($select, array('name' => $name)); + + $model->setData(( is_array($data) ) ? $data : array()); + } else { + return false; + } + } + + /** + * Before saving actions + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Tag_Model_Resource_Tag + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getId() && $object->getStatus() == $object->getApprovedStatus()) { + $searchTag = new Varien_Object(); + $this->loadByName($searchTag, $object->getName()); + if ($searchTag->getData($this->getIdFieldName()) + && $searchTag->getStatus() == $object->getPendingStatus()) { + $object->setId($searchTag->getData($this->getIdFieldName())); + } + } + + if (Mage::helper('core/string')->strlen($object->getName()) > 255) { + $object->setName(Mage::helper('core/string')->substr($object->getName(), 0, 255)); + } + + return parent::_beforeSave($object); + } + + /** + * Saving tag's base popularity + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Resource_Db_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getStore() || !Mage::app()->getStore()->isAdmin()) { + return parent::_afterSave($object); + } + + $tagId = ($object->isObjectNew()) ? $object->getTagId() : $object->getId(); + + $writeAdapter = $this->_getWriteAdapter(); + $writeAdapter->insertOnDuplicate($this->getTable('tag/properties'), array( + 'tag_id' => $tagId, + 'store_id' => $object->getStore(), + 'base_popularity' => (!$object->getBasePopularity()) ? 0 : $object->getBasePopularity() + )); + + return parent::_afterSave($object); + } + + /** + * Getting base popularity per store view for specified tag + * + * @deprecated after 1.4.0.0 + * + * @param int $tagId + * @return array + */ + protected function _getExistingBasePopularity($tagId) + { + $read = $this->_getReadAdapter(); + $selectSummary = $read->select() + ->from( + array('main' => $this->getTable('tag/summary')), + array('store_id', 'base_popularity') + ) + ->where('main.tag_id = :tag_id') + ->where('main.store_id != 0'); + + return $read->fetchAssoc($selectSummary, array('tag_id' => $tagId)); + } + + /** + * Get aggregation data per store view + * + * @deprecated after 1.4.0.0 + * + * @param int $tagId + * @return array + */ + protected function _getAggregationPerStoreView($tagId) + { + $readAdapter = $this->_getReadAdapter(); + $selectLocal = $readAdapter->select() + ->from( + array('main' => $this->getTable('tag/relation')), + array( + 'customers' => 'COUNT(DISTINCT main.customer_id)', + 'products' => 'COUNT(DISTINCT main.product_id)', + 'store_id', + 'uses' => 'COUNT(main.tag_relation_id)' + ) + ) + ->join(array('store' => $this->getTable('core/store')), + 'store.store_id = main.store_id AND store.store_id > 0', + array() + ) + ->join(array('product_website' => $this->getTable('catalog/product_website')), + 'product_website.website_id = store.website_id AND product_website.product_id = main.product_id', + array() + ) + ->where('main.tag_id = :tag_id') + ->where('main.active = 1') + ->group('main.store_id'); + + $selectLocalResult = $readAdapter->fetchAll($selectLocal, array('tag_id' => $tagId)); + + $selectHistorical = $readAdapter->select() + ->from( + array('main' => $this->getTable('tag/relation')), + array('historical_uses' => 'COUNT(main.tag_relation_id)', + 'store_id') + ) + ->join(array('store' => $this->getTable('core/store')), + 'store.store_id = main.store_id AND store.store_id > 0', + array() + ) + ->join(array('product_website' => $this->getTable('catalog/product_website')), + 'product_website.website_id = store.website_id AND product_website.product_id = main.product_id', + array() + ) + ->group('main.store_id') + ->where('main.tag_id = :tag_id'); + + $selectHistoricalResult = $readAdapter->fetchAll($selectHistorical, array('tag_id' => $tagId)); + + foreach ($selectHistoricalResult as $historical) { + foreach ($selectLocalResult as $key => $local) { + if ($local['store_id'] == $historical['store_id']) { + $selectLocalResult[$key]['historical_uses'] = $historical['historical_uses']; + break; + } + } + } + + return $selectLocalResult; + } + + /** + * Get global aggregation data for row with store_id = 0 + * + * @deprecated after 1.4.0.0 + * + * @param int $tagId + * @return array + */ + protected function _getGlobalAggregation($tagId) + { + $readAdapter = $this->_getReadAdapter(); + // customers and products stats + $selectGlobal = $readAdapter->select() + ->from( + array('main' => $this->getTable('tag/relation')), + array( + 'customers' => 'COUNT(DISTINCT main.customer_id)', + 'products' => 'COUNT(DISTINCT main.product_id)', + 'store_id' => new Zend_Db_Expr(0), + 'uses' => 'COUNT(main.tag_relation_id)' + ) + ) + ->join(array('store' => $this->getTable('core/store')), + 'store.store_id=main.store_id AND store.store_id>0', + array() + ) + ->join(array('product_website' => $this->getTable('catalog/product_website')), + 'product_website.website_id = store.website_id AND product_website.product_id = main.product_id', + array() + ) + ->where('main.tag_id = :tag_id') + ->where('main.active = 1'); + $result = $readAdapter->fetchRow($selectGlobal, array('tag_id' => $tagId)); + if (!$result) { + return array(); + } + + // historical uses stats + $selectHistoricalGlobal = $readAdapter->select() + ->from( + array('main' => $this->getTable('tag/relation')), + array('historical_uses' => 'COUNT(main.tag_relation_id)') + ) + ->join(array('store' => $this->getTable('core/store')), + 'store.store_id = main.store_id AND store.store_id > 0', + array() + ) + ->join(array('product_website' => $this->getTable('catalog/product_website')), + 'product_website.website_id = store.website_id AND product_website.product_id = main.product_id', + array() + ) + ->where('main.tag_id = :tag_id'); + $result['historical_uses'] = (int) $readAdapter->fetchOne($selectHistoricalGlobal, array('tag_id' => $tagId)); + + return $result; + } + + /** + * Getting statistics data into buffer. + * Replacing our buffer array with new statistics and incoming data. + * + * @deprecated after 1.4.0.0 + * + * @param Mage_Tag_Model_Tag $object + * @return Mage_Tag_Model_Tag + */ + public function aggregate($object) + { + $tagId = (int)$object->getId(); + $storeId = (int)$object->getStore(); + + // create final summary from existing data and add specified base popularity + $finalSummary = $this->_getExistingBasePopularity($tagId); + if ($object->hasBasePopularity() && $storeId) { + $finalSummary[$storeId]['store_id'] = $storeId; + $finalSummary[$storeId]['base_popularity'] = $object->getBasePopularity(); + } + + // calculate aggregation data + $summaries = $this->_getAggregationPerStoreView($tagId); + $summariesGlobal = $this->_getGlobalAggregation($tagId); + if ($summariesGlobal) { + $summaries[] = $summariesGlobal; + } + + // override final summary with aggregated data + foreach ($summaries as $row) { + $storeId = (int)$row['store_id']; + foreach ($row as $key => $value) { + $finalSummary[$storeId][$key] = $value; + } + } + + // prepare static parameters to final summary for insertion + foreach ($finalSummary as $key => $row) { + $finalSummary[$key]['tag_id'] = $tagId; + foreach (array('base_popularity', 'popularity', 'historical_uses', 'uses', 'products', 'customers') as $k) { + if (!isset($row[$k])) { + $finalSummary[$key][$k] = 0; + } + } + $finalSummary[$key]['popularity'] = $finalSummary[$key]['historical_uses']; + } + + // remove old and insert new data + $write = $this->_getWriteAdapter(); + $write->delete( + $this->getTable('tag/summary'), array('tag_id = ?' => $tagId) + ); + $write->insertMultiple($this->getTable('tag/summary'), $finalSummary); + + return $object; + } + + /** + * Decrementing tag products quantity as action for product delete + * + * @param array $tagsId + * @return int The number of affected rows + */ + public function decrementProducts(array $tagsId) + { + $writeAdapter = $this->_getWriteAdapter(); + if (empty($tagsId)) { + return 0; + } + + return $writeAdapter->update( + $this->getTable('tag/summary'), + array('products' => 'products - 1'), + array('tag_id IN (?)' => $tagsId) + ); + } + + /** + * Add summary data to specified object + * + * @deprecated after 1.4.0.0 + * + * @param Mage_Tag_Model_Tag $object + * @return Mage_Tag_Model_Tag + */ + public function addSummary($object) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from(array('relation' => $this->getTable('tag/relation')), array()) + ->joinLeft( + array('summary' => $this->getTable('tag/summary')), + 'relation.tag_id = summary.tag_id AND relation.store_id = summary.store_id', + array( + 'customers', + 'products', + 'popularity' + ) + ) + ->where('relation.tag_id = :tag_id') + ->where('relation.store_id = :store_id') + ->limit(1); + $bind = array( + 'tag_id' => (int)$object->getId(), + 'store_id' => (int)$object->getStoreId() + ); + $row = $read->fetchRow($select, $bind); + if ($row) { + $object->addData($row); + } + return $object; + } + + /** + * Retrieve select object for load object data + * Redeclare parent method just for adding tag's base popularity if flag exists + * + * @param string $field + * @param mixed $value + * @param Mage_Core_Model_Abstract $object + * @return Zend_Db_Select + */ + protected function _getLoadSelect($field, $value, $object) + { + $select = parent::_getLoadSelect($field, $value, $object); + if ($object->getAddBasePopularity() && $object->hasStoreId()) { + $select->joinLeft( + array('properties' => $this->getTable('tag/properties')), + "properties.tag_id = {$this->getMainTable()}.tag_id AND properties.store_id = {$object->getStoreId()}", + 'base_popularity' + ); + } + return $select; + } + + /** + * Fetch store ids in which tag visible + * + * @param Mage_Tag_Model_Resource_Tag $object + * @return Mage_Tag_Model_Resource_Tag + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + $read = $this->_getReadAdapter(); + $select = $read->select() + ->from($this->getTable('tag/summary'), array('store_id')) + ->where('tag_id = :tag_id'); + $storeIds = $read->fetchCol($select, array('tag_id' => $object->getId())); + + $object->setVisibleInStoreIds($storeIds); + + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag/Collection.php b/app/code/core/Mage/Tag/Model/Resource/Tag/Collection.php new file mode 100755 index 0000000000..f5b7e36ea5 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Tag/Collection.php @@ -0,0 +1,423 @@ + + */ +class Mage_Tag_Model_Resource_Tag_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Use getFlag('store_filter') & setFlag('store_filter', true) instead. + * + * @var bool + */ + protected $_isStoreFilter = false; + + /** + * Joined tables + * + * @var array + */ + protected $_joinFlags = array(); + + /** + * Mapping for fields + * + * @var array + */ + public $_map = array( + 'fields' => array( + 'tag_id' => 'main_table.tag_id' + ), + ); + + /** + * Define resource model and model + * + */ + protected function _construct() + { + $this->_init('tag/tag'); + } + + /** + * Loads collection + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + parent::load($printQuery, $logQuery); + if ($this->getFlag('add_stores_after')) { + $this->_addStoresVisibility(); + } + return $this; + } + + /** + * Set flag about joined table. + * setFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function setJoinFlag($table) + { + $this->setFlag($table, true); + return $this; + } + + /** + * Get flag's status about joined table. + * getFlag method must be used in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return bool + */ + public function getJoinFlag($table) + { + return $this->getFlag($table); + } + + /** + * Unset value of join flag. + * Set false (bool) value to flag instead in future. + * + * @deprecated after 1.3.2.3 + * + * @param string $table + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function unsetJoinFlag($table = null) + { + $this->setFlag($table, false); + return $this; + } + + /** + * Sett + * + * @param int $limit + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function limit($limit) + { + $this->getSelect()->limit($limit); + return $this; + } + + /** + * Replacing popularity by sum of popularity and base_popularity + * + * @param int $limit + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addPopularity($limit = null) + { + if (!$this->getFlag('popularity')) { + $this->getSelect() + ->joinLeft( + array('relation' => $this->getTable('tag/relation')), + 'main_table.tag_id = relation.tag_id', + array() + ) + ->joinLeft( + array('summary' => $this->getTable('tag/summary')), + 'relation.tag_id = summary.tag_id AND relation.store_id = summary.store_id', + array('popularity') + ) + ->group('main_table.tag_id'); + + /* + * Allow analytic function usage + */ + $this->_useAnalyticFunction = true; + + if (!is_null($limit)) { + $this->getSelect()->limit($limit); + } + + $this->setFlag('popularity'); + } + return $this; + } + + /** + * Adds summary + * + * @param int $storeId + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addSummary($storeId) + { + if (!$this->getFlag('summary')) { + $tableAlias = 'summary'; + $joinCondition = $this->getConnection() + ->quoteInto(' AND ' . $tableAlias . '.store_id IN(?)', $storeId); + + $this->getSelect() + ->joinLeft( + array($tableAlias => $this->getTable('tag/summary')), + 'main_table.tag_id = ' . $tableAlias . '.tag_id' . $joinCondition, + array('store_id','popularity', 'customers', 'products' + )); + + $this->addFilterToMap('store_id', $tableAlias . '.store_id'); + $this->addFilterToMap('popularity', $tableAlias . '.popularity'); + $this->addFilterToMap('customers', $tableAlias . '.customers'); + $this->addFilterToMap('products', $tableAlias . '.products'); + + $this->setFlag('summary', true); + } + return $this; + } + + /** + * Adds store visibility + * + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addStoresVisibility() + { + $this->setFlag('add_stores_after', true); + return $this; + } + + /** + * Adds store visibility + * + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + protected function _addStoresVisibility() + { + $tagIds = $this->getColumnValues('tag_id'); + + $tagsStores = array(); + if (sizeof($tagIds) > 0) { + $select = $this->getConnection()->select() + ->from($this->getTable('tag/summary'), array('store_id', 'tag_id')) + ->where('tag_id IN(?)', $tagIds); + $tagsRaw = $this->getConnection()->fetchAll($select); + + foreach ($tagsRaw as $tag) { + if (!isset($tagsStores[$tag['tag_id']])) { + $tagsStores[$tag['tag_id']] = array(); + } + + $tagsStores[$tag['tag_id']][] = $tag['store_id']; + } + } + + foreach ($this as $item) { + if (isset($tagsStores[$item->getId()])) { + $item->setStores($tagsStores[$item->getId()]); + } else { + $item->setStores(array()); + } + } + + return $this; + } + + /** + * Adds field to filter + * + * @param string $field + * @param array $condition + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addFieldToFilter($field, $condition = null) + { + if ($this->getFlag('relation') && 'popularity' == $field) { + // TOFIX + $this->getSelect()->having( + $this->_getConditionSql('COUNT(relation.tag_relation_id)', $condition) + ); + } elseif ($this->getFlag('summary') && in_array( + $field, array('customers', 'products', 'uses', 'historical_uses', 'popularity') + )) { + $this->getSelect()->where($this->_getConditionSql('summary.' . $field, $condition)); + } else { + parent::addFieldToFilter($field, $condition); + } + return $this; + } + + /** + * Get sql for get record count + * + * @return string + */ + public function getSelectCountSql() + { + $select = parent::getSelectCountSql(); + + $select->reset(Zend_Db_Select::COLUMNS); + $select->reset(Zend_Db_Select::GROUP); + $select->reset(Zend_Db_Select::HAVING); + $select->columns('COUNT(DISTINCT main_table.tag_id)'); + return $select; + } + + /** + * Add filter by store + * + * @param array | int $storeId + * @param bool $allFilter + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addStoreFilter($storeId, $allFilter = true) + { + if (!$this->getFlag('store_filter')) { + + $this->getSelect()->joinLeft( + array('summary_store' => $this->getTable('tag/summary')), + 'main_table.tag_id = summary_store.tag_id' + ); + + $this->getSelect()->where('summary_store.store_id IN (?)', $storeId); + + $this->getSelect()->group('main_table.tag_id'); + + if ($this->getFlag('relation') && $allFilter) { + $this->getSelect()->where('relation.store_id IN (?)', $storeId); + } + if ($this->getFlag('prelation') && $allFilter) { + $this->getSelect()->where('prelation.store_id IN (?)', $storeId); + } + + /* + * Allow Analytic functions usage + */ + + $this->_useAnalyticFunction = true; + + $this->setFlag('store_filter', true); + } + + return $this; + } + + /** + * Adds filtering by active + * + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function setActiveFilter() + { + $statusActive = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE; + $this->getSelect()->where('relation.active = ?', $statusActive); + if ($this->getFlag('prelation')) { + $this->getSelect()->where('prelation.active = ?', $statusActive); + } + return $this; + } + + /** + * Adds filter by status + * + * @param int $status + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addStatusFilter($status) + { + $this->getSelect()->where('main_table.status = ?', $status); + return $this; + } + + /** + * Adds filter by product id + * + * @param int $productId + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addProductFilter($productId) + { + $this->addFieldToFilter('relation.product_id', $productId); + if ($this->getFlag('prelation')) { + $this->addFieldToFilter('prelation.product_id', $productId); + } + return $this; + } + + /** + * Adds filter by customer id + * + * @param int $customerId + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addCustomerFilter($customerId) + { + $this->getSelect() + ->where('relation.customer_id = ?', $customerId); + if ($this->getFlag('prelation')) { + $this->getSelect() + ->where('prelation.customer_id = ?', $customerId); + } + return $this; + } + + /** + * Adds grouping by tag id + * + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function addTagGroup() + { + $this->getSelect()->group('main_table.tag_id'); + $this->_useAnalyticFunction = true; + return $this; + } + + /** + * Joins tag/relation table + * + * @return Mage_Tag_Model_Resource_Tag_Collection + */ + public function joinRel() + { + $this->setFlag('relation', true); + $this->getSelect()->joinLeft( + array('relation' => $this->getTable('tag/relation')), + 'main_table.tag_id=relation.tag_id' + ); + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php new file mode 100755 index 0000000000..17d3dcd417 --- /dev/null +++ b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php @@ -0,0 +1,208 @@ + + */ +class Mage_Tag_Model_Resource_Tag_Relation extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize resource connection and define table resource + * + */ + protected function _construct() + { + $this->_init('tag/relation', 'tag_relation_id'); + } + + /** + * Load by Tag and Customer + * + * @param Mage_Tag_Model_Tag_Relation $model + * @return Mage_Tag_Model_Resource_Tag_Relation + */ + public function loadByTagCustomer($model) + { + if ($model->getTagId() && $model->getCustomerId()) { + $read = $this->_getReadAdapter(); + $bind = array( + 'tag_id' => $model->getTagId(), + 'customer_id' => $model->getCustomerId() + ); + + $select = $read->select() + ->from($this->getMainTable()) + ->join( + $this->getTable('tag/tag'), + $this->getTable('tag/tag') . '.tag_id = ' . $this->getMainTable() . '.tag_id' + ) + ->where($this->getMainTable() . '.tag_id = :tag_id') + ->where('customer_id = :customer_id'); + + if ($model->getProductId()) { + $select->where($this->getMainTable() . '.product_id = :product_id'); + $bind['product_id'] = $model->getProductId(); + } + + if ($model->hasStoreId()) { + $select->where($this->getMainTable() . '.store_id = :sore_id'); + $bind['sore_id'] = $model->getStoreId(); + } + $data = $read->fetchRow($select, $bind); + $model->setData(( is_array($data) ) ? $data : array()); + } + + return $this; + } + + /** + * Retrieve Tagged Products + * + * @param Mage_Tag_Model_Tag_Relation $model + * @return array + */ + public function getProductIds($model) + { + $bind = array( + 'tag_id' => $model->getTagId() + ); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'product_id') + ->where($this->getMainTable() . '.tag_id=:tag_id'); + + if (!is_null($model->getCustomerId())) { + $select->where($this->getMainTable() . '.customer_id= :customer_id'); + $bind['customer_id'] = $model->getCustomerId(); + } + + if ($model->hasStoreId()) { + $select->where($this->getMainTable() . '.store_id = :store_id'); + $bind['store_id'] = $model->getStoreId(); + } + + if (!is_null($model->getStatusFilter())) { + $select->join( + $this->getTable('tag/tag'), + $this->getTable('tag/tag') . '.tag_id = ' . $this->getMainTable() . '.tag_id' + ) + ->where($this->getTable('tag/tag') . '.status = :t_status'); + $bind['t_status'] = $model->getStatusFilter(); + } + + return $this->_getReadAdapter()->fetchCol($select, $bind); + } + + /** + * Retrieve related to product tag ids + * + * @param Mage_Tag_Model_Tag_Relation $model + * @return array + */ + public function getRelatedTagIds($model) + { + $productIds = (is_array($model->getProductId())) ? $model->getProductId() : array($model->getProductId()); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'tag_id') + ->where("product_id IN(?)", $productIds) + ->order('tag_id'); + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Deactivate tag relations by tag and customer + * + * @param int $tagId + * @param int $customerId + * @return Mage_Tag_Model_Resource_Tag_Relation + */ + public function deactivate($tagId, $customerId) + { + $condition = array( + 'tag_id = ?' => $tagId, + 'customer_id = ?' => $customerId + ); + + $data = array('active' => Mage_Tag_Model_Tag_Relation::STATUS_NOT_ACTIVE); + $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition); + return $this; + } + + /** + * Add TAG to PRODUCT relations + * + * @param Mage_Tag_Model_Tag_Relation $model + * @return Mage_Tag_Model_Resource_Tag_Relation + */ + public function addRelations($model) + { + $addedIds = $model->getAddedProductIds(); + + $bind = array( + 'tag_id' => $model->getTagId(), + 'store_id' => $model->getStoreId() + ); + $write = $this->_getWriteAdapter(); + + $select = $write->select() + ->from($this->getMainTable(), 'product_id') + ->where('tag_id = :tag_id') + ->where('store_id = :store_id') + ->where('customer_id IS NULL'); + $oldRelationIds = $write->fetchCol($select, $bind); + + $insert = array_diff($addedIds, $oldRelationIds); + $delete = array_diff($oldRelationIds, $addedIds); + + if (!empty($insert)) { + $insertData = array(); + foreach ($insert as $value) { + $insertData[] = array( + 'tag_id' => $model->getTagId(), + 'store_id' => $model->getStoreId(), + 'product_id' => $value, + 'customer_id' => $model->getCustomerId(), + 'created_at' => $this->formatDate(time()) + ); + } + $write->insertMultiple($this->getMainTable(), $insertData); + } + + if (!empty($delete)) { + $write->delete($this->getMainTable(), array( + 'product_id IN (?)' => $delete, + 'store_id = ?' => $model->getStoreId(), + 'customer_id IS NULL' + )); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Tag/Model/Session.php b/app/code/core/Mage/Tag/Model/Session.php index d071087099..6ba1055208 100644 --- a/app/code/core/Mage/Tag/Model/Session.php +++ b/app/code/core/Mage/Tag/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/Model/Tag.php b/app/code/core/Mage/Tag/Model/Tag.php index c5ce4865f9..efa074404b 100644 --- a/app/code/core/Mage/Tag/Model/Tag.php +++ b/app/code/core/Mage/Tag/Model/Tag.php @@ -20,15 +20,25 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Tag model * - * @category Mage - * @package Mage_Tag + * @method Mage_Tag_Model_Resource_Tag _getResource() + * @method Mage_Tag_Model_Resource_Tag getResource() + * @method Mage_Tag_Model_Tag setName(string $value) + * @method int getStatus() + * @method Mage_Tag_Model_Tag setStatus(int $value) + * @method int getFirstCustomerId() + * @method Mage_Tag_Model_Tag setFirstCustomerId(int $value) + * @method int getFirstStoreId() + * @method Mage_Tag_Model_Tag setFirstStoreId(int $value) + * + * @category Mage + * @package Mage_Tag * @author Magento Core Team */ diff --git a/app/code/core/Mage/Tag/Model/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Tag/Relation.php index 2266bda60c..4c85ae27c5 100644 --- a/app/code/core/Mage/Tag/Model/Tag/Relation.php +++ b/app/code/core/Mage/Tag/Model/Tag/Relation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,24 @@ /** * Tag relation model * - * @category Mage - * @package Mage_Tag - * @author Magento Core Team + * @method Mage_Tag_Model_Resource_Tag_Relation _getResource() + * @method Mage_Tag_Model_Resource_Tag_Relation getResource() + * @method int getTagId() + * @method Mage_Tag_Model_Tag_Relation setTagId(int $value) + * @method int getCustomerId() + * @method Mage_Tag_Model_Tag_Relation setCustomerId(int $value) + * @method int getProductId() + * @method Mage_Tag_Model_Tag_Relation setProductId(int $value) + * @method int getStoreId() + * @method Mage_Tag_Model_Tag_Relation setStoreId(int $value) + * @method int getActive() + * @method Mage_Tag_Model_Tag_Relation setActive(int $value) + * @method string getCreatedAt() + * @method Mage_Tag_Model_Tag_Relation setCreatedAt(string $value) + * + * @category Mage + * @package Mage_Tag + * @author Magento Core Team */ class Mage_Tag_Model_Tag_Relation extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Tag/controllers/CustomerController.php b/app/code/core/Mage/Tag/controllers/CustomerController.php index eac08dabd2..5f338114f1 100644 --- a/app/code/core/Mage/Tag/controllers/CustomerController.php +++ b/app/code/core/Mage/Tag/controllers/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/controllers/IndexController.php b/app/code/core/Mage/Tag/controllers/IndexController.php index 023a08ba71..9942a63e27 100644 --- a/app/code/core/Mage/Tag/controllers/IndexController.php +++ b/app/code/core/Mage/Tag/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/controllers/ListController.php b/app/code/core/Mage/Tag/controllers/ListController.php index fb305c2276..cc7d4dbd24 100644 --- a/app/code/core/Mage/Tag/controllers/ListController.php +++ b/app/code/core/Mage/Tag/controllers/ListController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/controllers/ProductController.php b/app/code/core/Mage/Tag/controllers/ProductController.php index 501b86e0ab..033d47b132 100644 --- a/app/code/core/Mage/Tag/controllers/ProductController.php +++ b/app/code/core/Mage/Tag/controllers/ProductController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/etc/adminhtml.xml b/app/code/core/Mage/Tag/etc/adminhtml.xml index 8b88a35189..fe6eca11fb 100644 --- a/app/code/core/Mage/Tag/etc/adminhtml.xml +++ b/app/code/core/Mage/Tag/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -49,6 +49,28 @@ + + + + Tags + 50 + + + Customers + adminhtml/report_tag/customer + + + Products + adminhtml/report_tag/product + + + Popular + adminhtml/report_tag/popular + + + + + diff --git a/app/code/core/Mage/Tag/etc/config.xml b/app/code/core/Mage/Tag/etc/config.xml index c9b029fe92..14955ab1ae 100644 --- a/app/code/core/Mage/Tag/etc/config.xml +++ b/app/code/core/Mage/Tag/etc/config.xml @@ -21,31 +21,30 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.7 + 1.6.0.0 Mage_Tag_Model - tag_mysql4 + tag_resource Mage_Tag_Model_Customer - tag_entity_customer + + tag_customer_resource - - Mage_Tag_Model_Entity_Customer - - - Mage_Tag_Model_Mysql4 + + Mage_Tag_Model_Resource + tag_mysql4 tag
      @@ -60,7 +59,10 @@ tag_properties
      -
      + + + Mage_Tag_Model_Customer_Resource +
      @@ -70,7 +72,9 @@ - Mage_Tag_Block + + Mage_Tag_Block + @@ -99,13 +103,13 @@ - - - - tag.xml - - - + + + + tag.xml + + + /tag/customer/ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/install-1.6.0.0.php b/app/code/core/Mage/Tag/sql/tag_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..08f663c3d4 --- /dev/null +++ b/app/code/core/Mage/Tag/sql/tag_setup/install-1.6.0.0.php @@ -0,0 +1,219 @@ +startSetup(); + +/** + * Create table 'tag/tag' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tag/tag')) + ->addColumn('tag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tag Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Name') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + 'default' => '0', + ), 'Status') + ->addColumn('first_customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'First Customer Id') + ->addColumn('first_store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'First Store Id') + ->addForeignKey($installer->getFkName('tag/tag', 'first_customer_id', 'customer/entity', 'entity_id'), + 'first_customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->addForeignKey($installer->getFkName('tag/tag', 'first_store_id', 'core/store', 'store_id'), + 'first_store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_NO_ACTION) + ->setComment('Tag'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tag/relation' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tag/relation')) + ->addColumn('tag_relation_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tag Relation Id') + ->addColumn('tag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Tag Id') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Customer Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Store Id') + ->addColumn('active', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + ), 'Active') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addIndex($installer->getIdxName('tag/relation', array('tag_id', 'customer_id', 'product_id', 'store_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('tag_id', 'customer_id', 'product_id', 'store_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addIndex($installer->getIdxName('tag/relation', array('product_id')), + array('product_id')) + ->addIndex($installer->getIdxName('tag/relation', array('tag_id')), + array('tag_id')) + ->addIndex($installer->getIdxName('tag/relation', array('customer_id')), + array('customer_id')) + ->addIndex($installer->getIdxName('tag/relation', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('tag/relation', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tag/relation', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tag/relation', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tag/relation', 'tag_id', 'tag/tag', 'tag_id'), + 'tag_id', $installer->getTable('tag/tag'), 'tag_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tag Relation'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tag/summary' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tag/summary')) + ->addColumn('tag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Tag Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store Id') + ->addColumn('customers', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customers') + ->addColumn('products', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Products') + ->addColumn('uses', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Uses') + ->addColumn('historical_uses', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Historical Uses') + ->addColumn('popularity', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Popularity') + ->addColumn('base_popularity', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Base Popularity') + ->addIndex($installer->getIdxName('tag/summary', array('store_id')), + array('store_id')) + ->addIndex($installer->getIdxName('tag/summary', array('tag_id')), + array('tag_id')) + ->addForeignKey($installer->getFkName('tag/summary', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tag/summary', 'tag_id', 'tag/tag', 'tag_id'), + 'tag_id', $installer->getTable('tag/tag'), 'tag_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tag Summary'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tag/properties' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tag/properties')) + ->addColumn('tag_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Tag Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + ), 'Store Id') + ->addColumn('base_popularity', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Base Popularity') + ->addIndex($installer->getIdxName('tag/properties', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('tag/properties', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tag/properties', 'tag_id', 'tag/tag', 'tag_id'), + 'tag_id', $installer->getTable('tag/tag'), 'tag_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tag Properties'); +$installer->getConnection()->createTable($table); + + +$installer->endSetup(); diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-install-0.7.0.php index facfbfe0fe..25be2c1e28 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.0-0.7.1.php index 5297ec2eee..d9950f1b24 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.1-0.7.2.php index fd17a4cadf..a02fd10274 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.2-0.7.3.php index 40d1a29d01..4918a40bc6 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.3-0.7.4.php index 6a8ef58a3a..a051d00093 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.4-0.7.5.php index 8c2a4f9c06..31e533c313 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.5-0.7.6.php index 731bf41549..ee59427e05 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.6-0.7.7.php index 8e6a9d122d..8a4d58dc3c 100644 --- a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tag - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..3326d49c43 --- /dev/null +++ b/app/code/core/Mage/Tag/sql/tag_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,447 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/properties'), + 'FK_TAG_PROPERTIES_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/properties'), + 'FK_TAG_PROPERTIES_TAG' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/relation'), + 'FK_TAG_RELATION_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/relation'), + 'FK_TAG_RELATION_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/relation'), + 'FK_TAG_RELATION_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/relation'), + 'FK_TAG_RELATION_TAG' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/summary'), + 'FK_TAG_SUMMARY_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tag/summary'), + 'FK_TAG_SUMMARY_TAG' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('tag/relation'), + 'UNQ_TAG_CUSTOMER_PRODUCT_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/relation'), + 'IDX_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/relation'), + 'IDX_TAG' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/relation'), + 'IDX_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/relation'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/properties'), + 'FK_TAG_PROPERTIES_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/summary'), + 'FK_TAG_SUMMARY_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tag/summary'), + 'IDX_TAG' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('tag/tag') => array( + 'columns' => array( + 'tag_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tag Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Name' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Status' + ), + 'first_customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'First Customer Id' + ), + 'first_store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'First Store Id' + ) + ), + 'comment' => 'Tag' + ), + $installer->getTable('tag/relation') => array( + 'columns' => array( + 'tag_relation_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tag Relation Id' + ), + 'tag_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Tag Id' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Customer Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Store Id' + ), + 'active' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Active' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Created At' + ) + ), + 'comment' => 'Tag Relation' + ), + $installer->getTable('tag/summary') => array( + 'columns' => array( + 'tag_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Tag Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'customers' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customers' + ), + 'products' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Products' + ), + 'uses' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Uses' + ), + 'historical_uses' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Historical Uses' + ), + 'popularity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Popularity' + ), + 'base_popularity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Base Popularity' + ) + ), + 'comment' => 'Tag Summary' + ), + $installer->getTable('tag/properties') => array( + 'columns' => array( + 'tag_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Tag Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Store Id' + ), + 'base_popularity' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Base Popularity' + ) + ), + 'comment' => 'Tag Properties' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('tag/properties'), + $installer->getIdxName('tag/properties', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/relation'), + $installer->getIdxName( + 'tag/relation', + array('tag_id', 'customer_id', 'product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('tag_id', 'customer_id', 'product_id', 'store_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/relation'), + $installer->getIdxName('tag/relation', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/relation'), + $installer->getIdxName('tag/relation', array('tag_id')), + array('tag_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/relation'), + $installer->getIdxName('tag/relation', array('customer_id')), + array('customer_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/relation'), + $installer->getIdxName('tag/relation', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/summary'), + $installer->getIdxName('tag/summary', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tag/summary'), + $installer->getIdxName('tag/summary', array('tag_id')), + array('tag_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/tag', 'first_customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('tag/tag'), + 'first_customer_id', + $installer->getTable('customer/entity'), + 'entity_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/tag', 'first_store_id', 'core/store', 'store_id'), + $installer->getTable('tag/tag'), + 'first_store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, + Varien_Db_Ddl_Table::ACTION_NO_ACTION +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/properties', 'store_id', 'core/store', 'store_id'), + $installer->getTable('tag/properties'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/properties', 'tag_id', 'tag/tag', 'tag_id'), + $installer->getTable('tag/properties'), + 'tag_id', + $installer->getTable('tag/tag'), + 'tag_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/relation', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('tag/relation'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/relation', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('tag/relation'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/relation', 'store_id', 'core/store', 'store_id'), + $installer->getTable('tag/relation'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/relation', 'tag_id', 'tag/tag', 'tag_id'), + $installer->getTable('tag/relation'), + 'tag_id', + $installer->getTable('tag/tag'), + 'tag_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/summary', 'store_id', 'core/store', 'store_id'), + $installer->getTable('tag/summary'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tag/summary', 'tag_id', 'tag/tag', 'tag_id'), + $installer->getTable('tag/summary'), + 'tag_id', + $installer->getTable('tag/tag'), + 'tag_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Tax/Block/Adminhtml/Frontend/Region/Updater.php b/app/code/core/Mage/Tax/Block/Adminhtml/Frontend/Region/Updater.php index a84f2b3a77..007539941b 100644 --- a/app/code/core/Mage/Tax/Block/Adminhtml/Frontend/Region/Updater.php +++ b/app/code/core/Mage/Tax/Block/Adminhtml/Frontend/Region/Updater.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Checkout/Discount.php b/app/code/core/Mage/Tax/Block/Checkout/Discount.php index fa98422e92..f8de23db8f 100644 --- a/app/code/core/Mage/Tax/Block/Checkout/Discount.php +++ b/app/code/core/Mage/Tax/Block/Checkout/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Checkout/Grandtotal.php b/app/code/core/Mage/Tax/Block/Checkout/Grandtotal.php index 67b74de31b..300fdb2621 100644 --- a/app/code/core/Mage/Tax/Block/Checkout/Grandtotal.php +++ b/app/code/core/Mage/Tax/Block/Checkout/Grandtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Checkout/Shipping.php b/app/code/core/Mage/Tax/Block/Checkout/Shipping.php index 0e92702148..523f0f7095 100644 --- a/app/code/core/Mage/Tax/Block/Checkout/Shipping.php +++ b/app/code/core/Mage/Tax/Block/Checkout/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Checkout/Subtotal.php b/app/code/core/Mage/Tax/Block/Checkout/Subtotal.php index 99a53d04c1..78f736fdbd 100644 --- a/app/code/core/Mage/Tax/Block/Checkout/Subtotal.php +++ b/app/code/core/Mage/Tax/Block/Checkout/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Checkout/Tax.php b/app/code/core/Mage/Tax/Block/Checkout/Tax.php index 2f4ace741d..c7bedf4c8c 100644 --- a/app/code/core/Mage/Tax/Block/Checkout/Tax.php +++ b/app/code/core/Mage/Tax/Block/Checkout/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Block/Sales/Order/Tax.php b/app/code/core/Mage/Tax/Block/Sales/Order/Tax.php index cf545f9b7a..5161b31111 100644 --- a/app/code/core/Mage/Tax/Block/Sales/Order/Tax.php +++ b/app/code/core/Mage/Tax/Block/Sales/Order/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Exception.php b/app/code/core/Mage/Tax/Exception.php index d7d310a21b..572fc88706 100644 --- a/app/code/core/Mage/Tax/Exception.php +++ b/app/code/core/Mage/Tax/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Helper/Data.php b/app/code/core/Mage/Tax/Helper/Data.php index 99d549f221..0d4acac896 100644 --- a/app/code/core/Mage/Tax/Helper/Data.php +++ b/app/code/core/Mage/Tax/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -108,8 +108,7 @@ public function getProductPrice($product, $format=null) try { $value = $product->getPrice(); $value = Mage::app()->getStore()->convertPrice($value, $format); - } - catch (Exception $e){ + } catch (Exception $e){ $value = $e->getMessage(); } return $value; @@ -638,7 +637,7 @@ public function getPriceTaxSql($priceField, $taxClassField) $$rateVariable = ''; foreach ($$rateArray as $classId=>$rate) { if ($rate) { - $$rateVariable .= "WHEN '{$classId}' THEN '".($rate/100)."'"; + $$rateVariable .= sprintf("WHEN %d THEN %12.4f ", $classId, $rate/100); } } if ($$rateVariable) { @@ -666,19 +665,37 @@ public function getPriceTaxSql($priceField, $taxClassField) return $result; } - public function joinTaxClass($select, $storeId, $priceTable='main_table') + /** + * Join tax class + * @param Varien_Db_Select $select + * @param int $storeId + * @param string $priceTable + * @return Mage_Tax_Helper_Data + */ + public function joinTaxClass($select, $storeId, $priceTable = 'main_table') { - $taxClassAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'tax_class_id'); - $select->joinLeft( - array('tax_class_d'=>$taxClassAttribute->getBackend()->getTable()), - "tax_class_d.entity_id = {$priceTable}.entity_id AND tax_class_d.attribute_id = '{$taxClassAttribute->getId()}' - AND tax_class_d.store_id = 0", - array()); - $select->joinLeft( - array('tax_class_c'=>$taxClassAttribute->getBackend()->getTable()), - "tax_class_c.entity_id = {$priceTable}.entity_id AND tax_class_c.attribute_id = '{$taxClassAttribute->getId()}' - AND tax_class_c.store_id = '{$storeId}'", - array()); + $taxClassAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tax_class_id'); + $joinConditionD = implode(' AND ',array( + "tax_class_d.entity_id = {$priceTable}.entity_id", + $select->getAdapter()->quoteInto('tax_class_d.attribute_id = ?', (int)$taxClassAttribute->getId()), + 'tax_class_d.store_id = 0' + )); + $joinConditionC = implode(' AND ',array( + "tax_class_c.entity_id = {$priceTable}.entity_id", + $select->getAdapter()->quoteInto('tax_class_c.attribute_id = ?', (int)$taxClassAttribute->getId()), + $select->getAdapter()->quoteInto('tax_class_c.store_id = ?', (int)$storeId) + )); + $select + ->joinLeft( + array('tax_class_d' => $taxClassAttribute->getBackend()->getTable()), + $joinConditionD, + array()) + ->joinLeft( + array('tax_class_c' => $taxClassAttribute->getBackend()->getTable()), + $joinConditionC, + array()); + + return $this; } /** @@ -749,3 +766,4 @@ public function getCalculationAgorithm($store=null) return $this->_config->getAlgorithm($store); } } + diff --git a/app/code/core/Mage/Tax/Model/Calculation.php b/app/code/core/Mage/Tax/Model/Calculation.php index 4dcf7f0573..cb2cfc4104 100644 --- a/app/code/core/Mage/Tax/Model/Calculation.php +++ b/app/code/core/Mage/Tax/Model/Calculation.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,24 +31,24 @@ */ class Mage_Tax_Model_Calculation extends Mage_Core_Model_Abstract { - const CALC_TAX_BEFORE_DISCOUNT_ON_EXCL = '0_0'; - const CALC_TAX_BEFORE_DISCOUNT_ON_INCL = '0_1'; - const CALC_TAX_AFTER_DISCOUNT_ON_EXCL = '1_0'; - const CALC_TAX_AFTER_DISCOUNT_ON_INCL = '1_1'; + const CALC_TAX_BEFORE_DISCOUNT_ON_EXCL = '0_0'; + const CALC_TAX_BEFORE_DISCOUNT_ON_INCL = '0_1'; + const CALC_TAX_AFTER_DISCOUNT_ON_EXCL = '1_0'; + const CALC_TAX_AFTER_DISCOUNT_ON_INCL = '1_1'; - const CALC_UNIT_BASE = 'UNIT_BASE_CALCULATION'; - const CALC_ROW_BASE = 'ROW_BASE_CALCULATION'; - const CALC_TOTAL_BASE = 'TOTAL_BASE_CALCULATION'; + const CALC_UNIT_BASE = 'UNIT_BASE_CALCULATION'; + const CALC_ROW_BASE = 'ROW_BASE_CALCULATION'; + const CALC_TOTAL_BASE = 'TOTAL_BASE_CALCULATION'; - protected $_rates = array(); - protected $_ctc = array(); - protected $_ptc = array(); + protected $_rates = array(); + protected $_ctc = array(); + protected $_ptc = array(); - protected $_rateCache = array(); - protected $_rateCalculationProcess = array(); + protected $_rateCache = array(); + protected $_rateCalculationProcess = array(); - protected $_customer = null; - protected $_defaultCustomerTaxClass = null; + protected $_customer = null; + protected $_defaultCustomerTaxClass = null; protected function _construct() { @@ -67,7 +67,7 @@ public function setCustomer(Mage_Customer_Model_Customer $customer) return $this; } - public function getDefaultCustomerTaxClass($store=null) + public function getDefaultCustomerTaxClass($store = null) { if ($this->_defaultCustomerTaxClass === null) { $defaultCustomerGroup = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $store); @@ -401,11 +401,11 @@ protected function _getRates($request, $fieldName, $type) public function getRatesForAllProductTaxClasses($request) { - return $this->_getRates($request, 'product_class_id', 'PRODUCT'); + return $this->_getRates($request, 'product_class_id', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT); } public function getRatesForAllCustomerTaxClasses($request) { - return $this->_getRates($request, 'customer_class_id', 'CUSTOMER'); + return $this->_getRates($request, 'customer_class_id', Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER); } /** @@ -459,9 +459,9 @@ public function calcTaxAmount($price, $taxRate, $priceIncludeTax=false, $round=t if ($round) { return $this->round($amount); - } else { - return $amount; } + + return $amount; } /** diff --git a/app/code/core/Mage/Tax/Model/Calculation/Rate.php b/app/code/core/Mage/Tax/Model/Calculation/Rate.php index 61488691fb..32415a5295 100644 --- a/app/code/core/Mage/Tax/Model/Calculation/Rate.php +++ b/app/code/core/Mage/Tax/Model/Calculation/Rate.php @@ -20,14 +20,35 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Tax Rate Model * - * @author Magento Core Team + * @method Mage_Tax_Model_Resource_Calculation_Rate _getResource() + * @method Mage_Tax_Model_Resource_Calculation_Rate getResource() + * @method string getTaxCountryId() + * @method Mage_Tax_Model_Calculation_Rate setTaxCountryId(string $value) + * @method int getTaxRegionId() + * @method Mage_Tax_Model_Calculation_Rate setTaxRegionId(int $value) + * @method string getTaxPostcode() + * @method Mage_Tax_Model_Calculation_Rate setTaxPostcode(string $value) + * @method string getCode() + * @method Mage_Tax_Model_Calculation_Rate setCode(string $value) + * @method float getRate() + * @method Mage_Tax_Model_Calculation_Rate setRate(float $value) + * @method int getZipIsRange() + * @method Mage_Tax_Model_Calculation_Rate setZipIsRange(int $value) + * @method int getZipFrom() + * @method Mage_Tax_Model_Calculation_Rate setZipFrom(int $value) + * @method int getZipTo() + * @method Mage_Tax_Model_Calculation_Rate setZipTo(int $value) + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ class Mage_Tax_Model_Calculation_Rate extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Tax/Model/Calculation/Rate/Title.php b/app/code/core/Mage/Tax/Model/Calculation/Rate/Title.php index bb47fe36ce..eca6c03ced 100644 --- a/app/code/core/Mage/Tax/Model/Calculation/Rate/Title.php +++ b/app/code/core/Mage/Tax/Model/Calculation/Rate/Title.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,7 +28,18 @@ /** * Tax Rate Title Model * - * @author Magento Core Team + * @method Mage_Tax_Model_Resource_Calculation_Rate_Title _getResource() + * @method Mage_Tax_Model_Resource_Calculation_Rate_Title getResource() + * @method int getTaxCalculationRateId() + * @method Mage_Tax_Model_Calculation_Rate_Title setTaxCalculationRateId(int $value) + * @method int getStoreId() + * @method Mage_Tax_Model_Calculation_Rate_Title setStoreId(int $value) + * @method string getValue() + * @method Mage_Tax_Model_Calculation_Rate_Title setValue(string $value) + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ class Mage_Tax_Model_Calculation_Rate_Title extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/Tax/Model/Calculation/Rule.php b/app/code/core/Mage/Tax/Model/Calculation/Rule.php index f3c56b1337..b1ecab0539 100644 --- a/app/code/core/Mage/Tax/Model/Calculation/Rule.php +++ b/app/code/core/Mage/Tax/Model/Calculation/Rule.php @@ -20,26 +20,37 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Tax Rule Model * - * @author Magento Core Team + * @method Mage_Tax_Model_Resource_Calculation_Rule _getResource() + * @method Mage_Tax_Model_Resource_Calculation_Rule getResource() + * @method string getCode() + * @method Mage_Tax_Model_Calculation_Rule setCode(string $value) + * @method int getPriority() + * @method Mage_Tax_Model_Calculation_Rule setPriority(int $value) + * @method int getPosition() + * @method Mage_Tax_Model_Calculation_Rule setPosition(int $value) + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ class Mage_Tax_Model_Calculation_Rule extends Mage_Core_Model_Abstract { - protected $_ctcs = null; - protected $_ptcs = null; - protected $_rates = null; + protected $_ctcs = null; + protected $_ptcs = null; + protected $_rates = null; - protected $_ctcModel = null; - protected $_ptcModel = null; - protected $_rateModel = null; + protected $_ctcModel = null; + protected $_ptcModel = null; + protected $_rateModel = null; - protected $_calculationModel = null; + protected $_calculationModel = null; /** * Varien model constructor @@ -120,3 +131,4 @@ public function getProductTaxClasses() return $this->getCalculationModel()->getProductTaxClasses($this->getId()); } } + diff --git a/app/code/core/Mage/Tax/Model/Class.php b/app/code/core/Mage/Tax/Model/Class.php index aa0f2d956b..1eb958ffe0 100644 --- a/app/code/core/Mage/Tax/Model/Class.php +++ b/app/code/core/Mage/Tax/Model/Class.php @@ -20,15 +20,22 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Tax class model * - * @category Mage - * @package Mage_Tax + * @method Mage_Tax_Model_Resource_Class _getResource() + * @method Mage_Tax_Model_Resource_Class getResource() + * @method string getClassName() + * @method Mage_Tax_Model_Class setClassName(string $value) + * @method string getClassType() + * @method Mage_Tax_Model_Class setClassType(string $value) + * + * @category Mage + * @package Mage_Tax * @author Magento Core Team */ @@ -41,42 +48,4 @@ public function _construct() { $this->_init('tax/class'); } -// public function __construct($class=false) -// { -// parent::__construct(); -// $this->setIdFieldName($this->getResource()->getIdFieldName()); -// } -// -// public function getResource() -// { -// return Mage::getResourceModel('tax/class'); -// } -// -// public function load($classId) -// { -// $this->getResource()->load($this, $classId); -// return $this; -// } -// -// public function save() -// { -// $this->getResource()->save($this); -// return $this; -// } -// -// public function delete() -// { -// $this->getResource()->delete($this); -// return $this; -// } -// -// public function getCustomerGroupCollection() -// { -// return Mage::getResourceModel('customer/group_collection'); -// } -// -// public function itemExists() -// { -// return $this->getResource()->itemExists($this); -// } } diff --git a/app/code/core/Mage/Tax/Model/Class/Source/Customer.php b/app/code/core/Mage/Tax/Model/Class/Source/Customer.php index b577129a2d..852467816d 100644 --- a/app/code/core/Mage/Tax/Model/Class/Source/Customer.php +++ b/app/code/core/Mage/Tax/Model/Class/Source/Customer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ public function getAllOptions() { if (!$this->_options) { $this->_options = Mage::getResourceModel('tax/class_collection') - ->addFieldToFilter('class_type', 'CUSTOMER') + ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) ->load()->toOptionArray(); } return $this->_options; diff --git a/app/code/core/Mage/Tax/Model/Class/Source/Product.php b/app/code/core/Mage/Tax/Model/Class/Source/Product.php index ce21f949c3..9673d2888c 100644 --- a/app/code/core/Mage/Tax/Model/Class/Source/Product.php +++ b/app/code/core/Mage/Tax/Model/Class/Source/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,7 @@ public function getAllOptions($withEmpty = false) { if (is_null($this->_options)) { $this->_options = Mage::getResourceModel('tax/class_collection') - ->addFieldToFilter('class_type', 'PRODUCT') + ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) ->load() ->toOptionArray(); } @@ -76,11 +76,12 @@ public function getFlatColums() { $columns = array(); $columns[$this->getAttribute()->getAttributeCode()] = array( - 'type' => 'int', + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'unsigned' => false, - 'is_null' => true, + 'nullable' => true, 'default' => null, - 'extra' => null + 'extra' => null, + 'comment' => $this->getAttribute()->getAttributeCode() . ' tax column' ); return $columns; } diff --git a/app/code/core/Mage/Tax/Model/Config.php b/app/code/core/Mage/Tax/Model/Config.php index 57278d7e69..3350370f60 100644 --- a/app/code/core/Mage/Tax/Model/Config.php +++ b/app/code/core/Mage/Tax/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -483,3 +483,4 @@ public function displaySalesZeroTax($store = null) return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_ZERO_TAX, $store); } } + diff --git a/app/code/core/Mage/Tax/Model/Config/Price/Include.php b/app/code/core/Mage/Tax/Model/Config/Price/Include.php index c6548d5e46..e0258d81ca 100644 --- a/app/code/core/Mage/Tax/Model/Config/Price/Include.php +++ b/app/code/core/Mage/Tax/Model/Config/Price/Include.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Tax_Model_Config_Price_Include extends Mage_Core_Model_Config_Data diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation.php index df83aac2fb..8f4b3a096a 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation.php @@ -20,357 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax Calculation Resource Model * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tax_Model_Mysql4_Calculation extends Mage_Tax_Model_Resource_Calculation { - /* - * Internal array to cache identical rate SELECTs to DB - * @var array - */ - protected $_ratesCache = array(); - - protected function _construct() - { - $this->_setMainTable('tax/tax_calculation'); - } - - /** - * Delete calculation settings by rule id - * - * @param int $ruleId - */ - public function deleteByRuleId($ruleId) - { - $conn = $this->_getWriteAdapter(); - $where = $conn->quoteInto('tax_calculation_rule_id = ?', $ruleId); - $conn->delete($this->getMainTable(), $where); - } - - public function getDistinct($field, $ruleId) - { - $select = $this->_getReadAdapter()->select(); - $select->from($this->getMainTable(), $field) - ->where('tax_calculation_rule_id = ?', $ruleId); - return $this->_getReadAdapter()->fetchCol($select); - } - - /** - * Get tax rate information: calculation process data and tax rate - * - * @param Varien_Object $request - * @return array - */ - public function getRateInfo($request) - { - $rates = $this->_getRates($request); - return array( - 'process' => $this->getCalculationProcess($request, $rates), - 'value' => $this->_calculateRate($rates) - ); - } - - /** - * Get tax rate for specific tax rate request - * - * @param Varien_Object $request - */ - public function getRate($request) - { - return $this->_calculateRate($this->_getRates($request)); - } - - public function getCalculationProcess($request, $rates = null) - { - if (is_null($rates)) { - $rates = $this->_getRates($request); - } - - $result = array(); - $row = array(); - $ids = array(); - $currentRate = 0; - $totalPercent = 0; - $countedRates = count($rates); - for ($i = 0; $i < $countedRates; $i++) { - $rate = $rates[$i]; - $value = (isset($rate['value']) ? $rate['value'] : $rate['percent'])*1; - - $oneRate = array( - 'code'=>$rate['code'], - 'title'=>$rate['title'], - 'percent'=>$value, - 'position'=>$rate['position'], - 'priority'=>$rate['priority'], - ); - - - if (isset($rate['hidden'])) { - $row['hidden'] = $rate['hidden']; - } - - if (isset($rate['amount'])) { - $row['amount'] = $rate['amount']; - } - - if (isset($rate['base_amount'])) { - $row['base_amount'] = $rate['base_amount']; - } - if (isset($rate['base_real_amount'])) { - $row['base_real_amount'] = $rate['base_real_amount']; - } - $row['rates'][] = $oneRate; - - if (isset($rates[$i+1]['tax_calculation_rule_id'])) { - $rule = $rate['tax_calculation_rule_id']; - } - $priority = $rate['priority']; - $ids[] = $rate['code']; - - if (isset($rates[$i+1]['tax_calculation_rule_id'])) { - while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { - $i++; - } - } - - $currentRate += $value; - - if (!isset($rates[$i+1]) || $rates[$i+1]['priority'] != $priority - || (isset($rates[$i+1]['process']) && $rates[$i+1]['process'] != $rate['process']) - ) { - $row['percent'] = (100+$totalPercent)*($currentRate/100); - $row['id'] = implode($ids); - $result[] = $row; - $row = array(); - $ids = array(); - - $totalPercent += (100+$totalPercent)*($currentRate/100); - $currentRate = 0; - } - } - - return $result; - } - - /** - * Create search templates for postcode - * - * @param string $postcode - * @return array $strArr - */ - protected function _createSearchPostCodeTemplates($postcode) - { - - $len = Mage::helper('tax')->getPostCodeSubStringLength(); - $strlen = strlen($postcode); - if ($strlen > $len) { - $postcode = substr($postcode, 0, $len); - $strlen = $len; - } - - $strArr = array($postcode, $postcode . '*'); - if ($strlen > 1) { - for ($i = 1; $i < $strlen; $i++) { - $strArr[] = sprintf('%s*', substr($postcode, 0, - $i)); - } - } - - return $strArr; - - } - - /** - * Returns tax rates for request - either pereforms SELECT from DB, or returns already cached result - * Notice that productClassId due to optimization can be array of ids - * - * @param Varien_Object $request - * @return array - */ - protected function _getRates($request) - { - // Extract params that influence our SELECT statement and use them to create cache key - $storeId = Mage::app()->getStore($request->getStore())->getId(); - $customerClassId = $request->getCustomerClassId(); - $countryId = $request->getCountryId(); - $regionId = $request->getRegionId(); - $postcode = $request->getPostcode(); - - // Process productClassId as it can be array or usual value. Form best key for cache. - $productClassId = $request->getProductClassId(); - $ids = is_array($productClassId) ? $productClassId : array($productClassId); - foreach ($ids as $key => $val) { - $ids[$key] = (int) $val; // Make it integer for equal cache keys even in case of null/false/0 values - } - $ids = array_unique($ids); - sort($ids); - $productClassKey = implode(',', $ids); - - // Form cache key and either get data from cache or from DB - $cacheKey = implode('|', array($storeId, $customerClassId, $productClassKey, $countryId, $regionId, $postcode)); - - if (!isset($this->_ratesCache[$cacheKey])) { - // Make SELECT and get data - $select = $this->_getReadAdapter()->select(); - $select - ->from(array('main_table'=>$this->getMainTable())) - ->where('customer_tax_class_id = ?', $customerClassId); - if ($productClassId) { - $select->where('product_tax_class_id IN (?)', $productClassId); - } - - $select->join( - array('rule'=>$this->getTable('tax/tax_calculation_rule')), - 'rule.tax_calculation_rule_id = main_table.tax_calculation_rule_id', - array('rule.priority', 'rule.position') - ); - $select->join( - array('rate'=>$this->getTable('tax/tax_calculation_rate')), - 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id', - array( - 'value'=>'rate.rate', 'rate.tax_country_id', 'rate.tax_region_id', 'rate.tax_postcode', - 'rate.tax_calculation_rate_id', 'rate.code' - ) - ); - - $select->joinLeft( - array('title_table'=>$this->getTable('tax/tax_calculation_rate_title')), - "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id " - . "AND title_table.store_id = '{$storeId}'", - array('title'=>'IFNULL(title_table.value, rate.code)') - ); - - $select - ->where("rate.tax_country_id = ?", $countryId) - ->where("rate.tax_region_id in ('*', '', ?)", $regionId); - - $selectClone = clone $select; - - $select - ->where("rate.zip_is_range IS NULL"); - $selectClone - ->where("rate.zip_is_range IS NOT NULL"); - - if ($request->getPostcode() != '*') { - $select - ->where("rate.tax_postcode in ('*', '', ?)", $this->_createSearchPostCodeTemplates($postcode)); - $selectClone - ->where("? BETWEEN rate.zip_from AND rate.zip_to", $postcode); - } - - /** - * @see ZF-7592 issue http://framework.zend.com/issues/browse/ZF-7592 - */ - $select = $this->_getReadAdapter()->select()->union(array('(' . $select . ')', '(' . $selectClone . ')')); - $order = array('priority ASC', 'tax_calculation_rule_id ASC', 'tax_country_id DESC', 'tax_region_id DESC', - 'tax_postcode DESC', 'value DESC' - ); - $select->order($order); - - $this->_ratesCache[$cacheKey] = $this->_getReadAdapter()->fetchAll($select); - } - - return $this->_ratesCache[$cacheKey]; - } - - protected function _calculateRate($rates) - { - $result = 0; - $currentRate = 0; - $countedRates = count($rates); - for ($i = 0; $i < $countedRates; $i++) { - $rate = $rates[$i]; - $rule = $rate['tax_calculation_rule_id']; - $value = $rate['value']; - $priority = $rate['priority']; - - while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { - $i++; - } - - $currentRate += $value; - - if (!isset($rates[$i+1]) || $rates[$i+1]['priority'] != $priority) { - $result += (100+$result)*($currentRate/100); - $currentRate = 0; - } - } - - return $result; - } - - public function getRateIds($request) - { - $result = array(); - $rates = $this->_getRates($request); - $countedRates = count($rates); - for ($i = 0; $i < $countedRates; $i++) { - $rate = $rates[$i]; - $rule = $rate['tax_calculation_rule_id']; - $result[] = $rate['tax_calculation_rate_id']; - while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { - $i++; - } - } - return $result; - } - - public function getRatesByCustomerTaxClass($customerTaxClass, $productTaxClass = null) - { - $customerTaxClass = (int) $customerTaxClass; - - $calcJoinConditions = "calc_table.tax_calculation_rate_id = main_table.tax_calculation_rate_id"; - $calcJoinConditions .= " AND calc_table.customer_tax_class_id = '{$customerTaxClass}'"; - if ($productTaxClass) { - $productTaxClass = (int) $productTaxClass; - $calcJoinConditions .= " AND calc_table.product_tax_class_id = '{$productTaxClass}'"; - } - - $selectCSP = $this->_getReadAdapter()->select(); - $selectCSP->from(array('main_table'=>$this->getTable('tax/tax_calculation_rate')), - array('country'=>'tax_country_id', 'region_id'=>'tax_region_id', 'postcode'=>'tax_postcode') - ) - ->joinInner( - array('calc_table'=>$this->getTable('tax/tax_calculation')), - $calcJoinConditions, - array('product_class'=>'calc_table.product_tax_class_id')) - ->joinLeft( - array('state_table'=>$this->getTable('directory/country_region')), - 'state_table.region_id = main_table.tax_region_id', - array('region_code'=>'state_table.code')) - ->distinct(true); - - $CSP = $this->_getReadAdapter()->fetchAll($selectCSP); - - $result = array(); - foreach ($CSP as $one) { - $request = new Varien_Object(); - $request->setCountryId($one['country']) - ->setRegionId($one['region_id']) - ->setPostcode($one['postcode']) - ->setCustomerClassId($customerTaxClass) - ->setProductClassId($one['product_class']); - - $rate = $this->getRate($request); - if ($rate) { - $row = array( - 'value' => $rate/100, - 'country' => $one['country'], - 'state' => $one['region_code'], - 'postcode' => $one['postcode'], - 'product_class' => $one['product_class'], - ); - - $result[] = $row; - } - } - - return $result; - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Collection.php index d427a39210..96e91a0967 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Collection.php @@ -20,19 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax Calculation Collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Collection extends Mage_Tax_Model_Resource_Calculation_Collection { - protected function _construct() - { - $this->_init('tax/calculation'); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate.php index 4ab1057f40..728bff6694 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate.php @@ -20,56 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax rate resource model * - * @category Mage - * @package Mage_Tax - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation_Rate extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rate extends Mage_Tax_Model_Resource_Calculation_Rate { - protected function _construct() - { - $this->_init('tax/tax_calculation_rate', 'tax_calculation_rate_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => array('code'), - 'title' => Mage::helper('tax')->__('Code'), - )); - return $this; - } - - public function deleteAllRates() - { - $this->_getWriteAdapter()->delete($this->getMainTable()); - } - - - /** - * Check if this rate exists in rule - * - * @param int $rateId - * @return array - */ - public function isInRule($rateId) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from($this->getTable('tax/tax_calculation'), array('tax_calculation_rate_id')) - ->where('tax_calculation_rate_id = ?', $rateId); - return $adapter->fetchCol($select); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Collection.php index ad64439f9d..4f5bcb8031 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Collection.php @@ -20,115 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax rate collection * - * @category Mage - * @package Mage_Tax + * @category Mage + * @package Mage_Tax * @author Magento Core Team */ - -class Mage_Tax_Model_Mysql4_Calculation_Rate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rate_Collection extends Mage_Tax_Model_Resource_Calculation_Rate_Collection { - protected function _construct() - { - $this->_init('tax/calculation_rate'); - } - - public function joinCountryTable() - { - $this->_select->join( - array('country_table' => $this->getTable('directory/country')), - 'main_table.tax_country_id=country_table.country_id', - array('country_name' => 'iso2_code') - ); - return $this; - } - - /** - * Join Region Table - * - * @return object - */ - public function joinRegionTable() - { - $this->_select->joinLeft( - array('region_table' => $this->getTable('directory/country_region')), - 'main_table.tax_region_id=region_table.region_id', - array('region_name' => 'code') - ); - return $this; - } - - /** - * Join rate title for specified store - * - * @param mixed store - * @return object - */ - public function joinTitle($store = null) - { - $storeId = Mage::app()->getStore($store)->getId(); - $this->_select->joinLeft( - array('title_table' => $this->getTable('tax/tax_calculation_rate_title')), - "main_table.tax_calculation_rate_id=title_table.tax_calculation_rate_id AND title_table.store_id = '{$storeId}'", - array('title' => 'value') - ); - return $this; - } - - /** - * Joins store titles for rates - * - * @return object - */ - public function joinStoreTitles() - { - $storeCollection = Mage::getModel('core/store')->getCollection()->setLoadDefault(true); - foreach ($storeCollection as $store) { - $this->_select->joinLeft( - array('title_table_' . $store->getId() => $this->getTable('tax/tax_calculation_rate_title')), - "main_table.tax_calculation_rate_id=title_table_{$store->getId()}.tax_calculation_rate_id AND title_table_{$store->getId()}.store_id = '{$store->getId()}'", - array('title_' . $store->getId() => 'value') - ); - } - return $this; - } - - public function addRateFilter($rateId) - { - if (is_int($rateId) && $rateId > 0) { - return $this->_select->where('main_table.tax_rate_id=?', $rateId); - } - else { - return $this; - } - } - - public function toOptionArray() - { - return $this->_toOptionArray('tax_calculation_rate_id', 'code'); - } - - public function toOptionHash() - { - return $this->_toOptionHash('tax_calculation_rate_id', 'code'); - } - - /** - * Convert items array to hash for select options - * unsing fetchItem method - * - * @see _toOptionHashOptimized() - * - * @return array - */ - public function toOptionHashOptimized() - { - return $this->_toOptionHashOptimized('tax_calculation_rate_id', 'code'); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title.php index 7802edd2e5..9374c9fbc2 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,19 +28,10 @@ /** * Tax Rate Title Collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation_Rate_Title extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rate_Title extends Mage_Tax_Model_Resource_Calculation_Rate_Title { - protected function _construct() - { - $this->_init('tax/tax_calculation_rate_title', 'tax_calculation_rate_title_id'); - } - - public function deleteByRateId($rateId) - { - $conn = $this->_getWriteAdapter(); - $where = $conn->quoteInto('tax_calculation_rate_id = ?', $rateId); - $conn->delete($this->getMainTable(), $where); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title/Collection.php index 5a3053ea93..7731488d51 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rate/Title/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,18 +28,11 @@ /** * Tax Rate Title Collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation_Rate_Title_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rate_Title_Collection + extends Mage_Tax_Model_Resource_Calculation_Rate_Title_Collection { - protected function _construct() - { - $this->_init('tax/calculation_rate_title', 'tax/calculation_rate_title'); - } - - public function loadByRateId($rateId) - { - $this->getSelect()->where('main_table.tax_calculation_rate_id = ?', $rateId); - return $this->load(); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule.php index f9af51f812..4f5d38a411 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule.php @@ -20,35 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax rate resource model * - * @category Mage - * @package Mage_Tax - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Calculation_Rule extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rule extends Mage_Tax_Model_Resource_Calculation_Rule { - protected function _construct() - { - $this->_init('tax/tax_calculation_rule', 'tax_calculation_rule_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => array('code'), - 'title' => Mage::helper('tax')->__('Code'), - )); - return $this; - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule/Collection.php index 8ac4c33984..2f2a8323de 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Calculation/Rule/Collection.php @@ -20,95 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax rule collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ - -class Mage_Tax_Model_Mysql4_Calculation_Rule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Calculation_Rule_Collection extends Mage_Tax_Model_Resource_Calculation_Rule_Collection { - protected function _construct() - { - $this->_init('tax/calculation_rule'); - } - - public function joinCalculationData($alias) - { - $this->getSelect()->joinLeft( - array($alias=>$this->getTable('tax_calculation')), - "main_table.tax_calculation_rule_id = {$alias}.tax_calculation_rule_id", - array() - ); - $this->getSelect()->group('main_table.tax_calculation_rule_id'); - } - - protected function _add($itemTable, $primaryJoinField, $secondaryJoinField, $titleField, $dataField) - { - $children = array(); - foreach ($this as $rule) { - $children[$rule->getId()] = array(); - } - if (!empty($children)) { - $select = $this->getConnection()->select() - ->from( - array('calculation'=>$this->getTable('tax_calculation')), - array('calculation.tax_calculation_rule_id') - ) - ->join( - array('item'=>$this->getTable($itemTable)), - "item.{$secondaryJoinField} = calculation.{$primaryJoinField}", - array("item.{$titleField}", "item.{$secondaryJoinField}") - ) - ->where('calculation.tax_calculation_rule_id IN (?)', array_keys($children)) - ->distinct(true); - - $data = $this->getConnection()->fetchAll($select); - foreach ($data as $row) { - $children[$row['tax_calculation_rule_id']][$row[$secondaryJoinField]] = $row[$titleField]; - } - } - - foreach ($this as $rule) { - if (isset($children[$rule->getId()])) { - $rule->setData($dataField, array_keys($children[$rule->getId()])); - } - } - return $this; - } - - public function addProductTaxClassesToResult() - { - return $this->_add('tax_class', 'product_tax_class_id', 'class_id', 'class_name', 'product_tax_classes'); - } - public function addCustomerTaxClassesToResult() - { - return $this->_add('tax_class', 'customer_tax_class_id', 'class_id', 'class_name', 'customer_tax_classes'); - } - public function addRatesToResult() - { - return $this->_add('tax_calculation_rate', 'tax_calculation_rate_id', 'tax_calculation_rate_id', 'code', 'tax_rates'); - } - - public function setClassTypeFilter($type, $id) - { - switch ($type) { - case 'PRODUCT': - $field = 'cd.product_tax_class_id'; - break; - case 'CUSTOMER': - $field = 'cd.customer_tax_class_id'; - break; - default: - Mage::throwException('Invalid type supplied'); - } - - $this->joinCalculationData('cd'); - $this->addFieldToFilter($field, $id); - return $this; - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Class.php b/app/code/core/Mage/Tax/Model/Mysql4/Class.php index 8a30ea06b2..c20bfebe06 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Class.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Class.php @@ -20,36 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax class resource * - * @category Mage - * @package Mage_Tax + * @category Mage + * @package Mage_Tax * @author Magento Core Team */ - -class Mage_Tax_Model_Mysql4_Class extends Mage_Core_Model_Mysql4_Abstract +class Mage_Tax_Model_Mysql4_Class extends Mage_Tax_Model_Resource_Class { - public function _construct() - { - $this->_init('tax/tax_class', 'class_id'); - } - - /** - * Initialize unique fields - * - * @return Mage_Core_Model_Mysql4_Abstract - */ - protected function _initUniqueFields() - { - $this->_uniqueFields = array(array( - 'field' => array('class_type', 'class_name'), - 'title' => Mage::helper('tax')->__('An error occurred while saving this tax class. A class with the same name already exists.'), - )); - return $this; - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Class/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Class/Collection.php index ae1ad2f9c7..2040e5b226 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Class/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Class/Collection.php @@ -20,38 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax class collection * - * @category Mage - * @package Mage_Tax + * @category Mage + * @package Mage_Tax * @author Magento Core Team */ - -class Mage_Tax_Model_Mysql4_Class_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Class_Collection extends Mage_Tax_Model_Resource_Class_Collection { - public function _construct() - { - $this->_init('tax/class'); - } - - public function setClassTypeFilter($classTypeId) - { - $this->_select->where('main_table.class_type = ?', $classTypeId); - return $this; - } - - public function toOptionArray() - { - return $this->_toOptionArray('class_id', 'class_name'); - } - - public function toOptionHash() - { - return $this->_toOptionHash('class_id', 'class_name'); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Report/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Report/Collection.php index 8bad157710..5dc866dec2 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Report/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Report/Collection.php @@ -20,85 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax report collection * - * @category Mage - * @package Mage_Tax - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Report_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Tax_Model_Mysql4_Report_Collection extends Mage_Tax_Model_Resource_Report_Collection { - protected $_periodFormat; - protected $_selectedColumns = array(); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('tax/tax_order_aggregated_created'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(period, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM period)'; - } else { - $this->_periodFormat = 'period'; - } - - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'code' => 'code', - 'percent' => 'percent', - 'orders_count' => 'sum(orders_count)', - 'tax_base_amount_sum' => 'sum(tax_base_amount_sum)' - ); - } - - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } - - if ($this->isSubTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat); - } - - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_Tax_Model_Mysql4_Report_Collection - */ - protected function _initSelect() - { - $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->getSelect()->group(array($this->_periodFormat, 'code', 'percent')); - } - - if ($this->isSubTotals()) { - $this->getSelect()->group(array( - $this->_periodFormat - )); - } - - return $this; - } - } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php b/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php index f7fa141d42..dbfc058c7b 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Report/Tax.php @@ -20,106 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Tax_Model_Mysql4_Report_Tax extends Mage_Reports_Model_Mysql4_Report_Abstract +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team + */ +class Mage_Tax_Model_Mysql4_Report_Tax extends Mage_Tax_Model_Resource_Report_Tax { - protected function _construct() - { - $this->_init('tax/tax_order_aggregated_created', 'id'); - } - - /** - * Aggregate Tax data - * - * @param mixed $from - * @param mixed $to - * @return Mage_Tax_Model_Mysql4_Tax - */ - public function aggregate($from = null, $to = null) - { - // convert input dates to UTC to be comparable with DATETIME fields in DB - $from = $this->_dateToUtc($from); - $to = $this->_dateToUtc($to); - - $this->_checkDates($from, $to); - $writeAdapter = $this->_getWriteAdapter(); - $writeAdapter->beginTransaction(); - - try { - if ($from !== null || $to !== null) { - $subSelect = $this->_getTableDateRangeSelect( - $this->getTable('sales/order'), - 'created_at', 'updated_at', $from, $to - ); - } else { - $subSelect = null; - } - - $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); - - $columns = array( - 'period' => "DATE(CONVERT_TZ(e.created_at, '+00:00', '" . $this->_getStoreTimezoneUtcOffset() . "'))", - 'store_id' => 'e.store_id', - 'code' => 'tax.code', - 'order_status' => 'e.status', - 'percent' => 'tax.percent', - 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', - 'tax_base_amount_sum' => 'SUM(tax.base_amount * e.base_to_global_rate)' - ); - - $select = $writeAdapter->select(); - $select->from(array('tax' => $this->getTable('tax/sales_order_tax')), $columns) - ->joinInner(array('e' => $this->getTable('sales/order')), 'e.entity_id = tax.order_id', array()) - ->useStraightJoin(); - - $select->where('e.state NOT IN (?)', array( - Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, - Mage_Sales_Model_Order::STATE_NEW - )); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'e.created_at')); - } - - $select->group(array('period', 'store_id', 'code', 'tax.percent', 'order_status')); - - $writeAdapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); - - $select->reset(); - - $columns = array( - 'period' => 'period', - 'store_id' => new Zend_Db_Expr('0'), - 'code' => 'code', - 'order_status' => 'order_status', - 'percent' => 'percent', - 'orders_count' => 'SUM(orders_count)', - 'tax_base_amount_sum' => 'SUM(tax_base_amount_sum)' - ); - - $select - ->from($this->getMainTable(), $columns) - ->where('store_id <> 0'); - - if ($subSelect !== null) { - $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); - } - - $select->group(array('period', 'code', 'percent', 'order_status')); - - $writeAdapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); - - $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_TAX_FLAG_CODE); - } catch (Exception $e) { - $writeAdapter->rollBack(); - throw $e; - } - - $writeAdapter->commit(); - return $this; - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Report/Updatedat/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Report/Updatedat/Collection.php index f02bae9322..6d2132cd92 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Report/Updatedat/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Report/Updatedat/Collection.php @@ -20,178 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax report collection * - * @category Mage - * @package Mage_Tax - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Report_Updatedat_Collection extends Mage_Sales_Model_Mysql4_Report_Collection_Abstract +class Mage_Tax_Model_Mysql4_Report_Updatedat_Collection extends Mage_Tax_Model_Resource_Report_Updatedat_Collection { - protected $_periodFormat; - protected $_inited = false; - protected $_selectedColumns = array( - 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', - 'tax_base_amount_sum' => 'SUM(tax.base_real_amount * e.base_to_global_rate)' - ); - - /** - * Initialize custom resource model - * - * @param array $parameters - */ - public function __construct() - { - parent::_construct(); - $this->setModel('adminhtml/report_item'); - $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order', 'entity_id'); - $this->setConnection($this->getResource()->getReadConnection()); - } - - /** - * Apply stores filter - * - * @return Mage_Tax_Model_Mysql4_Report_Updatedat_Collection - */ - protected function _applyStoresFilter() - { - $nullCheck = false; - $storeIds = $this->_storesIds; - - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - - $storeIds = array_unique($storeIds); - - if ($index = array_search(null, $storeIds)) { - unset($storeIds[$index]); - $nullCheck = true; - } - - if ($nullCheck) { - $this->getSelect()->where('store_id IN(?) OR store_id IS NULL', $storeIds); - } elseif ($storeIds[0] != '') { - $this->getSelect()->where('store_id IN(?)', $storeIds); - } - - return $this; - } - - /** - * Apply order status filter - * - * @return Mage_Tax_Model_Mysql4_Report_Updatedat_Collection - */ - protected function _applyOrderStatusFilter() - { - if (is_null($this->_orderStatus)) { - return $this; - } - $orderStatus = $this->_orderStatus; - if (!is_array($orderStatus)) { - $orderStatus = array($orderStatus); - } - $this->getSelect()->where('status IN(?)', $orderStatus); - return $this; - } - - /** - * Retrieve array of columns to select - * - * @return array - */ - protected function _getSelectedColumns() - { - if ('month' == $this->_period) { - $this->_periodFormat = 'DATE_FORMAT(e.updated_at, \'%Y-%m\')'; - } elseif ('year' == $this->_period) { - $this->_periodFormat = 'EXTRACT(YEAR FROM e.updated_at)'; - } else { - $this->_periodFormat = 'DATE(e.updated_at)'; - } - - if (!$this->isTotals() && !$this->isSubTotals()) { - $this->_selectedColumns = array( - 'period' => $this->_periodFormat, - 'store_id' => 'store_id', - 'code' => 'tax.code', - 'order_status' => 'e.status', - 'percent' => 'tax.percent', - 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', - 'tax_base_amount_sum' => 'SUM(tax.base_real_amount * e.base_to_global_rate)' - ); - } - - if ($this->isSubTotals()) { - $this->_selectedColumns += array('period' => $this->_periodFormat); - } - - return $this->_selectedColumns; - } - - /** - * Add selected data - * - * @return Mage_Tax_Model_Mysql4_Report_Updatedat_Collection - */ - protected function _initSelect() - { - if ($this->_inited) { - return $this; - } - - $columns = $this->_getSelectedColumns(); - $mainTable = $this->getResource()->getMainTable(); - - $select = $this->getSelect() - ->from(array('e' => $mainTable), $columns) - ->joinInner(array('tax'=> $this->getTable('tax/sales_order_tax')), 'e.entity_id = tax.order_id', array()); - - $this->_applyStoresFilter(); - $this->_applyOrderStatusFilter(); - - if ($this->_from !== null) { - $select->where('DATE(e.updated_at) >= DATE(?)', $this->_from); - } - - if ($this->_to !== null) { - $select->where('DATE(e.updated_at) <= DATE(?)', $this->_to); - } - - if (!$this->isTotals() && !$this->isSubTotals()) { - $select->group(array($this->_periodFormat, 'code', 'percent')); - } - - if ($this->isSubTotals()) { - $select->group(array( - $this->_periodFormat - )); - } - - $this->_inited = true; - return $this; - } - - /** - * Load - * - * @param boolean $printQuery - * @param boolean $logQuery - * @return Mage_Tax_Model_Mysql4_Report_Updatedat_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if ($this->isLoaded()) { - return $this; - } - $this->_initSelect(); - $this->setApplyFilters(false); - return parent::load($printQuery, $logQuery); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax.php b/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax.php index 1f3ed90161..72ff1696ca 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax.php @@ -20,14 +20,18 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Tax_Model_Mysql4_Sales_Order_Tax extends Mage_Core_Model_Mysql4_Abstract + +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team + */ +class Mage_Tax_Model_Mysql4_Sales_Order_Tax extends Mage_Tax_Model_Resource_Sales_Order_Tax { - protected function _construct() - { - $this->_init('tax/sales_order_tax', 'tax_id'); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax/Collection.php b/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax/Collection.php index 3212faa2d0..ef27102200 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax/Collection.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Sales/Order/Tax/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,21 +28,10 @@ /** * Order Tax Collection * - * @author Magento Core Team + * @category Mage + * @package Mage_Tax + * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Sales_Order_Tax_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Tax_Model_Mysql4_Sales_Order_Tax_Collection extends Mage_Tax_Model_Resource_Sales_Order_Tax_Collection { - protected function _construct() - { - $this->_init('tax/sales_order_tax'); - } - - public function loadByOrder($order) - { - $orderId = $order->getId(); - $this->getSelect() - ->where('main_table.order_id = ?', $orderId) - ->order('process'); - return $this->load(); - } } diff --git a/app/code/core/Mage/Tax/Model/Mysql4/Setup.php b/app/code/core/Mage/Tax/Model/Mysql4/Setup.php index fa451119b4..bde2ad78d5 100644 --- a/app/code/core/Mage/Tax/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Tax/Model/Mysql4/Setup.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Tax Setup Resource Model * @@ -31,115 +32,6 @@ * @package Mage_Tax * @author Magento Core Team */ -class Mage_Tax_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup +class Mage_Tax_Model_Mysql4_Setup extends Mage_Tax_Model_Resource_Setup { - /** - * Convert old Tax data - * - */ - public function convertOldTaxData() - { - $oldRules = $this->_loadTableData('tax_rule'); - - $oldRateTypes = $this->_loadTableData('tax_rate_type'); - - $rateById = array(); - foreach ($oldRateTypes as $type) { - $rateById[$type['type_id']] = $type['type_name']; - } - - $oldRates = $this->_loadOldRates($oldRateTypes); - - $oldToNewRateIds = array(); - - foreach ($oldRates as $rate) { - foreach ($oldRateTypes as $type) { - if (isset($rate["data_{$type['type_id']}"])) { - $rateValue = $rate["data_{$type['type_id']}"]; - } else { - continue; - } - - $region = Mage::getModel('directory/region')->load($rate['tax_region_id']); - $regionName = $region->getCode() ? $region->getCode() : '*'; - $code = "{$rate['tax_country_id']}-{$regionName}-{$rate['tax_postcode']}-{$type['type_name']}"; - - if ($rateValue > 0) { - $insertData = array( - 'tax_country_id' => $rate['tax_country_id'], - 'tax_region_id' => $rate['tax_region_id'], - 'tax_postcode' => $rate['tax_postcode'], - 'code' => $code, - 'rate' => $rateValue, - ); - - $newRateModel = Mage::getModel('tax/calculation_rate'); - - $newRateModel->setData($insertData)->save(); - $oldToNewRateIds[$rate['tax_rate_id']] = $newRateModel->getId(); - $ratesByType[$type['type_id']][] = $newRateModel->getId(); - } - } - } - - foreach ($oldRules as $rule) { - if (!isset($ratesByType[$rule['tax_rate_type_id']]) || !count($ratesByType[$rule['tax_rate_type_id']])) { - continue; - } - - $customerTaxClasses = array($rule['tax_customer_class_id']); - $productTaxClasses = array($rule['tax_product_class_id']); - - $ctc = Mage::getModel('tax/class')->load($rule['tax_customer_class_id']); - $ptc = Mage::getModel('tax/class')->load($rule['tax_product_class_id']); - $type = $rateById[$rule['tax_rate_type_id']]; - - $rates = $ratesByType[$rule['tax_rate_type_id']]; - $code = "{$ctc->getClassName()}-{$ptc->getClassName()}-{$type}"; - - $ruleData = array( - 'tax_rate' => $rates, - 'tax_product_class' => $productTaxClasses, - 'tax_customer_class' => $customerTaxClasses, - 'code' => $code, - 'priority' => 1, - 'position' => 1 - ); - Mage::getModel('tax/calculation_rule')->setData($ruleData)->save(); - } - } - - /** - * Load Tax Table Data - * - * @return array - */ - protected function _loadTableData($table) - { - $table = $this->getTable($table); - $select = $this->_conn->select(); - $select->from($table); - return $this->_conn->fetchAll($select); - } - - /** - * Load Old Rate Data - * - * @return array - */ - protected function _loadOldRates($oldRateTypes) - { - $table = $this->getTable('tax_rate'); - $select = $this->_conn->select() - ->from(array('main_table'=>$table)); - foreach ($oldRateTypes as $type){ - $id = $type['type_id']; - $select->joinLeft( - array("data_{$id}"=>$this->getTable('tax_rate_data')), - "data_{$id}.rate_type_id = {$id} AND data_{$id}.tax_rate_id = main_table.tax_rate_id", - array("data_{$id}"=>'rate_value') - ); - } - return $this->_conn->fetchAll($select); - } } diff --git a/app/code/core/Mage/Tax/Model/Observer.php b/app/code/core/Mage/Tax/Model/Observer.php index 08fe98c82c..bb48e5223d 100644 --- a/app/code/core/Mage/Tax/Model/Observer.php +++ b/app/code/core/Mage/Tax/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -76,17 +76,17 @@ public function salesEventOrderAfterSave(Varien_Event_Observer $observer) } $hidden = (isset($row['hidden']) ? $row['hidden'] : 0); $data = array( - 'order_id'=>$order->getId(), - 'code'=>$tax['code'], - 'title'=>$tax['title'], - 'hidden'=>$hidden, - 'percent'=>$tax['percent'], - 'priority'=>$tax['priority'], - 'position'=>$tax['position'], - 'amount'=>$row['amount'], - 'base_amount'=>$row['base_amount'], - 'process'=>$row['process'], - 'base_real_amount'=>$baseRealAmount, + 'order_id' => $order->getId(), + 'code' => $tax['code'], + 'title' => $tax['title'], + 'hidden' => $hidden, + 'percent' => $tax['percent'], + 'priority' => $tax['priority'], + 'position' => $tax['position'], + 'amount' => $row['amount'], + 'base_amount' => $row['base_amount'], + 'process' => $row['process'], + 'base_real_amount' => $baseRealAmount, ); Mage::getModel('tax/sales_order_tax')->setData($data)->save(); diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation.php b/app/code/core/Mage/Tax/Model/Resource/Calculation.php new file mode 100755 index 0000000000..e678a68f97 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation.php @@ -0,0 +1,448 @@ + + */ +class Mage_Tax_Model_Resource_Calculation extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Rates cache + * + * @var unknown + */ + protected $_ratesCache = array(); + + /** + * Primery key auto increment flag + * + * @var bool + */ + protected $_isPkAutoIncrement = false; + + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_setMainTable('tax/tax_calculation'); + } + + /** + * Delete calculation settings by rule id + * + * @param int $ruleId + * @return Mage_Tax_Model_Resource_Calculation + */ + public function deleteByRuleId($ruleId) + { + $conn = $this->_getWriteAdapter(); + $where = $conn->quoteInto('tax_calculation_rule_id = ?', (int)$ruleId); + $conn->delete($this->getMainTable(), $where); + + return $this; + } + + /** + * Retreive distinct calculation + * + * @param string $field + * @param int $ruleId + * @return array + */ + public function getDistinct($field, $ruleId) + { + $select = $this->_getReadAdapter()->select(); + $select->from($this->getMainTable(), $field) + ->where('tax_calculation_rule_id = ?', (int)$ruleId); + + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Get tax rate information: calculation process data and tax rate + * + * @param Varien_Object $request + * @return array + */ + public function getRateInfo($request) + { + $rates = $this->_getRates($request); + return array( + 'process' => $this->getCalculationProcess($request, $rates), + 'value' => $this->_calculateRate($rates) + ); + } + + /** + * Get tax rate for specific tax rate request + * + * @param Varien_Object $request + * @return int + */ + public function getRate($request) + { + return $this->_calculateRate($this->_getRates($request)); + } + + /** + * Retrieve Calculation Process + * + * @param Varien_Object $request + * @param array $rates + * @return array + */ + public function getCalculationProcess($request, $rates = null) + { + if (is_null($rates)) { + $rates = $this->_getRates($request); + } + + $result = array(); + $row = array(); + $ids = array(); + $currentRate = 0; + $totalPercent = 0; + $countedRates = count($rates); + for ($i = 0; $i < $countedRates; $i++) { + $rate = $rates[$i]; + $value = (isset($rate['value']) ? $rate['value'] : $rate['percent'])*1; + + $oneRate = array( + 'code'=>$rate['code'], + 'title'=>$rate['title'], + 'percent'=>$value, + 'position'=>$rate['position'], + 'priority'=>$rate['priority'], + ); + + + if (isset($rate['hidden'])) { + $row['hidden'] = $rate['hidden']; + } + + if (isset($rate['amount'])) { + $row['amount'] = $rate['amount']; + } + + if (isset($rate['base_amount'])) { + $row['base_amount'] = $rate['base_amount']; + } + if (isset($rate['base_real_amount'])) { + $row['base_real_amount'] = $rate['base_real_amount']; + } + $row['rates'][] = $oneRate; + + if (isset($rates[$i+1]['tax_calculation_rule_id'])) { + $rule = $rate['tax_calculation_rule_id']; + } + $priority = $rate['priority']; + $ids[] = $rate['code']; + + if (isset($rates[$i+1]['tax_calculation_rule_id'])) { + while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { + $i++; + } + } + + $currentRate += $value; + + if (!isset($rates[$i+1]) || $rates[$i+1]['priority'] != $priority + || (isset($rates[$i+1]['process']) && $rates[$i+1]['process'] != $rate['process']) + ) { + $row['percent'] = (100+$totalPercent)*($currentRate/100); + $row['id'] = implode($ids); + $result[] = $row; + $row = array(); + $ids = array(); + + $totalPercent += (100+$totalPercent)*($currentRate/100); + $currentRate = 0; + } + } + + return $result; + } + + /** + * Create search templates for postcode + * + * @param string $postcode + * @return array $strArr + */ + protected function _createSearchPostCodeTemplates($postcode) + { + $len = Mage::helper('tax')->getPostCodeSubStringLength(); + $strlen = strlen($postcode); + if ($strlen > $len) { + $postcode = substr($postcode, 0, $len); + $strlen = $len; + } + + $strArr = array($postcode, $postcode . '*'); + if ($strlen > 1) { + for ($i = 1; $i < $strlen; $i++) { + $strArr[] = sprintf('%s*', substr($postcode, 0, - $i)); + } + } + + return $strArr; + } + + /** + * Returns tax rates for request - either pereforms SELECT from DB, or returns already cached result + * Notice that productClassId due to optimization can be array of ids + * + * @param Varien_Object $request + * @return array + */ + protected function _getRates($request) + { + // Extract params that influence our SELECT statement and use them to create cache key + $storeId = Mage::app()->getStore($request->getStore())->getId(); + $customerClassId = $request->getCustomerClassId(); + $countryId = $request->getCountryId(); + $regionId = $request->getRegionId(); + $postcode = $request->getPostcode(); + + // Process productClassId as it can be array or usual value. Form best key for cache. + $productClassId = $request->getProductClassId(); + $ids = is_array($productClassId) ? $productClassId : array($productClassId); + foreach ($ids as $key => $val) { + $ids[$key] = (int) $val; // Make it integer for equal cache keys even in case of null/false/0 values + } + $ids = array_unique($ids); + sort($ids); + $productClassKey = implode(',', $ids); + + // Form cache key and either get data from cache or from DB + $cacheKey = implode('|', array($storeId, $customerClassId, $productClassKey, $countryId, $regionId, $postcode)); + + if (!isset($this->_ratesCache[$cacheKey])) { + // Make SELECT and get data + $select = $this->_getReadAdapter()->select(); + $select + ->from(array('main_table' => $this->getMainTable()), + array( 'tax_calculation_rate_id', + 'tax_calculation_rule_id', + 'customer_tax_class_id', + 'product_tax_class_id' + ) + ) + ->where('customer_tax_class_id = ?', (int)$customerClassId); + if ($productClassId) { + $select->where('product_tax_class_id IN (?)', $productClassId); + } + $ifnullTitleValue = $this->_getReadAdapter()->getCheckSql( + 'title_table.value IS NULL', + 'rate.code', + 'title_table.value' + ); + $ruleTableAliasName = $this->_getReadAdapter()->quoteIdentifier('rule.tax_calculation_rule_id'); + $select + ->join( + array('rule' => $this->getTable('tax/tax_calculation_rule')), + $ruleTableAliasName . ' = main_table.tax_calculation_rule_id', + array('rule.priority', 'rule.position')) + ->join( + array('rate'=>$this->getTable('tax/tax_calculation_rate')), + 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id', + array( + 'value' => 'rate.rate', + 'rate.tax_country_id', + 'rate.tax_region_id', + 'rate.tax_postcode', + 'rate.tax_calculation_rate_id', + 'rate.code' + )) + ->joinLeft( + array('title_table' => $this->getTable('tax/tax_calculation_rate_title')), + "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id " + . "AND title_table.store_id = '{$storeId}'", + array('title' => $ifnullTitleValue)) + ->where('rate.tax_country_id = ?', $countryId) + ->where("rate.tax_region_id IN(?)", array(0, (int)$regionId)); + + $selectClone = clone $select; + + $select + ->where("rate.zip_is_range IS NULL"); + + $selectClone + ->where("rate.zip_is_range IS NOT NULL"); + + if ($request->getPostcode() != '*') { + $select + ->where("rate.tax_postcode IS NULL OR rate.tax_postcode IN('*', '', ?)", + $this->_createSearchPostCodeTemplates($postcode)); + /* Wrong expresion for mssql string to int comparison */ + //$selectClone + // ->where('? BETWEEN rate.zip_from AND rate.zip_to', $postcode); + } + + /** + * @see ZF-7592 issue http://framework.zend.com/issues/browse/ZF-7592 + */ + $select = $this->_getReadAdapter()->select()->union(array('(' . $select . ')', '(' . $selectClone . ')')); + + $select->order('priority ' . Varien_Db_Select::SQL_ASC) + ->order('tax_calculation_rule_id ' . Varien_Db_Select::SQL_ASC) + ->order('tax_country_id ' . Varien_Db_Select::SQL_DESC) + ->order('tax_region_id ' . Varien_Db_Select::SQL_DESC) + ->order('tax_postcode ' . Varien_Db_Select::SQL_DESC) + ->order('value ' . Varien_Db_Select::SQL_DESC); + + $this->_ratesCache[$cacheKey] = $this->_getReadAdapter()->fetchAll($select); + } + + return $this->_ratesCache[$cacheKey]; + } + + /** + * Calculate rate + * + * @param array $rates + * @return int + */ + protected function _calculateRate($rates) + { + $result = 0; + $currentRate = 0; + $countedRates = count($rates); + for ($i = 0; $i < $countedRates; $i++) { + $rate = $rates[$i]; + $rule = $rate['tax_calculation_rule_id']; + $value = $rate['value']; + $priority = $rate['priority']; + + while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { + $i++; + } + + $currentRate += $value; + + if (!isset($rates[$i+1]) || $rates[$i+1]['priority'] != $priority) { + $result += (100+$result)*($currentRate/100); + $currentRate = 0; + } + } + + return $result; + } + + /** + * Retrieve rate ids + * + * @param Varien_Object $request + * @return array + */ + public function getRateIds($request) + { + $result = array(); + $rates = $this->_getRates($request); + $countedRates = count($rates); + for ($i = 0; $i < $countedRates; $i++) { + $rate = $rates[$i]; + $rule = $rate['tax_calculation_rule_id']; + $result[] = $rate['tax_calculation_rate_id']; + while(isset($rates[$i+1]) && $rates[$i+1]['tax_calculation_rule_id'] == $rule) { + $i++; + } + } + + return $result; + } + + /** + * Retrieve rates by customer tax class + * + * @param int $customerTaxClassId + * @param int $productTaxClassId + * @return array + */ + public function getRatesByCustomerTaxClass($customerTaxClassId, $productTaxClassId = null) + { + $adapter = $this->_getReadAdapter(); + $customerTaxClass = (int)$customerTaxClass; + $calcJoinConditions = array( + 'calc_table.tax_calculation_rate_id = main_table.tax_calculation_rate_id', + $adapter->quoteInto('calc_table.customer_tax_class_id = ?', $customerTaxClassId), + + ); + if ($productTaxClassId) { + $productTaxClass = (int)$productTaxClass; + $calcJoinConditions[] = $adapter->quoteInto('calc_table.product_tax_class_id = ?', $productTaxClassId); + } + + $selectCSP = $adapter->select(); + $selectCSP + ->from( + array('main_table' => $this->getTable('tax/tax_calculation_rate')), + array('country' => 'tax_country_id', 'region_id' => 'tax_region_id', 'postcode' => 'tax_postcode')) + ->joinInner( + array('calc_table' => $this->getTable('tax/tax_calculation')), + implode(' AND ', $calcJoinConditions), + array('product_class' => 'calc_table.product_tax_class_id')) + ->joinLeft( + array('state_table' => $this->getTable('directory/country_region')), + 'state_table.region_id = main_table.tax_region_id', + array('region_code' => 'state_table.code')) + ->distinct(true); + + $CSP = $adapter->fetchAll($selectCSP); + + $result = array(); + foreach ($CSP as $one) { + $request = new Varien_Object(); + $request->setCountryId($one['country']) + ->setRegionId($one['region_id']) + ->setPostcode($one['postcode']) + ->setCustomerClassId($customerTaxClassId) + ->setProductClassId($one['product_class']); + + $rate = $this->getRate($request); + if ($rate) { + $row = array( + 'value' => $rate/100, + 'country' => $one['country'], + 'state' => $one['region_code'], + 'postcode' => $one['postcode'], + 'product_class' => $one['product_class'], + ); + + $result[] = $row; + } + } + + return $result; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Collection.php new file mode 100755 index 0000000000..7b8b0b74a8 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Collection.php @@ -0,0 +1,44 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/calculation'); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate.php new file mode 100755 index 0000000000..acfba89215 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate.php @@ -0,0 +1,84 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rate extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/tax_calculation_rate', 'tax_calculation_rate_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Tax_Model_Resource_Calculation_Rate + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => array('code'), + 'title' => Mage::helper('tax')->__('Code'), + )); + return $this; + } + + /** + * Delete all rates + * + * @return Mage_Tax_Model_Resource_Calculation_Rate + */ + public function deleteAllRates() + { + $this->_getWriteAdapter()->delete($this->getMainTable()); + return $this; + } + + /** + * Check if this rate exists in rule + * + * @param int $rateId + * @return array + */ + public function isInRule($rateId) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('tax/tax_calculation'), array('tax_calculation_rate_id')) + ->where('tax_calculation_rate_id = ?', $rateId); + return $adapter->fetchCol($select); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Collection.php new file mode 100755 index 0000000000..ae43196bf1 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Collection.php @@ -0,0 +1,165 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/calculation_rate'); + } + + /** + * Join country table to result + * + * @return Mage_Tax_Model_Resource_Calculation_Rate_Collection + */ + public function joinCountryTable() + { + $this->_select->join( + array('country_table' => $this->getTable('directory/country')), + 'main_table.tax_country_id = country_table.country_id', + array('country_name' => 'iso2_code') + ); + + return $this; + } + + /** + * Join Region Table + * + * @return Mage_Tax_Model_Resource_Calculation_Rate_Collection + */ + public function joinRegionTable() + { + $this->_select->joinLeft( + array('region_table' => $this->getTable('directory/country_region')), + 'main_table.tax_region_id = region_table.region_id', + array('region_name' => 'code') + ); + return $this; + } + + /** + * Join rate title for specified store + * + * @param Mage_Core_Model_Store|string|int $store + * @return Mage_Tax_Model_Resource_Calculation_Rate_Collection + */ + public function joinTitle($store = null) + { + $storeId = (int)Mage::app()->getStore($store)->getId(); + $this->_select->joinLeft( + array('title_table' => $this->getTable('tax/tax_calculation_rate_title')), + $this->getConnection()->quoteInto('main_table.tax_calculation_rate_id = title_table.tax_calculation_rate_id AND title_table.store_id = ?', $storeId), + array('title' => 'value') + ); + + return $this; + } + + /** + * Joins store titles for rates + * + * @return Mage_Tax_Model_Resource_Calculation_Rate_Collection + */ + public function joinStoreTitles() + { + $storeCollection = Mage::app()->getStores(true); + foreach ($storeCollection as $store) { + $tableAlias = sprintf('title_table_%s', $store->getId()); + $joinCondition = implode(' AND ', array( + "main_table.tax_calculation_rate_id = {$tableAlias}.tax_calculation_rate_id", + $this->getConnection()->quoteInto($tableAlias . '.store_id = ?', $store->getId()) + )); + $this->_select->joinLeft( + array($tableAlias => $this->getTable('tax/tax_calculation_rate_title')), + $joinCondition, + array($tableAlias => 'value') + ); + } + return $this; + } + + /** + * Add rate filter + * + * @param int $rateId + * @return Mage_Tax_Model_Resource_Calculation_Rate_Collection + */ + public function addRateFilter($rateId) + { + if (is_int($rateId) && $rateId > 0) { + return $this->addFieldToFilter('main_table.tax_rate_id', $rateId); + } + + return $this; + } + + /** + * Retrieve option array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('tax_calculation_rate_id', 'code'); + } + + /** + * Retrieve option hash + * + * @return array + */ + public function toOptionHash() + { + return $this->_toOptionHash('tax_calculation_rate_id', 'code'); + } + + /** + * Convert items array to hash for select options + * unsing fetchItem method + * + * @see _toOptionHashOptimized() + * + * @return array + */ + public function toOptionHashOptimized() + { + return $this->_toOptionHashOptimized('tax_calculation_rate_id', 'code'); + } +} + diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title.php new file mode 100755 index 0000000000..b4d18cc18e --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title.php @@ -0,0 +1,59 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rate_Title extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/tax_calculation_rate_title', 'tax_calculation_rate_title_id'); + } + + /** + * Delete title by rate identifier + * + * @param int $rateId + * @return Mage_Tax_Model_Resource_Calculation_Rate_Title + */ + public function deleteByRateId($rateId) + { + $conn = $this->_getWriteAdapter(); + $where = $conn->quoteInto('tax_calculation_rate_id = ?', (int)$rateId); + $conn->delete($this->getMainTable(), $where); + + return $this; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title/Collection.php new file mode 100755 index 0000000000..f3fa4668a4 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rate/Title/Collection.php @@ -0,0 +1,56 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rate_Title_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/calculation_rate_title', 'tax/calculation_rate_title'); + } + + /** + * Add rate id filter + * + * @param int $rateId + * @return Mage_Tax_Model_Resource_Calculation_Rate_Title_Collection + */ + public function loadByRateId($rateId) + { + $this->addFieldToFilter('main_table.tax_calculation_rate_id', $rateId); + return $this->load(); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule.php new file mode 100755 index 0000000000..4cfb06401d --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule.php @@ -0,0 +1,58 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rule extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/tax_calculation_rule', 'tax_calculation_rule_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Tax_Model_Resource_Calculation_Rule + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => array('code'), + 'title' => Mage::helper('tax')->__('Code'), + )); + return $this; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule/Collection.php new file mode 100755 index 0000000000..349a98ce3a --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Calculation/Rule/Collection.php @@ -0,0 +1,164 @@ + + */ +class Mage_Tax_Model_Resource_Calculation_Rule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/calculation_rule'); + } + + /** + * Join calculation data to result + * + * @param string $alias table alias + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + public function joinCalculationData($alias) + { + $this->getSelect()->joinLeft( + array($alias => $this->getTable('tax/tax_calculation')), + "main_table.tax_calculation_rule_id = {$alias}.tax_calculation_rule_id", + array() + ); + $this->getSelect()->group('main_table.tax_calculation_rule_id'); + + return $this; + } + + /** + * Join tax data to collection + * + * @param string $itemTable + * @param string $primaryJoinField + * @param string $secondaryJoinField + * @param string $titleField + * @param string $dataField + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + protected function _add($itemTable, $primaryJoinField, $secondaryJoinField, $titleField, $dataField) + { + $children = array(); + foreach ($this as $rule) { + $children[$rule->getId()] = array(); + } + if (!empty($children)) { + $joinCondition = sprintf('item.%s = calculation.%s', $secondaryJoinField, $primaryJoinField); + $select = $this->getConnection()->select() + ->from( + array('calculation' => $this->getTable('tax/tax_calculation')), + array('calculation.tax_calculation_rule_id') + ) + ->join( + array('item' => $this->getTable($itemTable)), + $joinCondition, + array("item.{$titleField}", "item.{$secondaryJoinField}") + ) + ->where('calculation.tax_calculation_rule_id IN (?)', array_keys($children)) + ->distinct(true); + + $data = $this->getConnection()->fetchAll($select); + foreach ($data as $row) { + $children[$row['tax_calculation_rule_id']][$row[$secondaryJoinField]] = $row[$titleField]; + } + } + + foreach ($this as $rule) { + if (isset($children[$rule->getId()])) { + $rule->setData($dataField, array_keys($children[$rule->getId()])); + } + } + + return $this; + } + + /** + * Add product tax classes to result + * + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + public function addProductTaxClassesToResult() + { + return $this->_add('tax_class', 'product_tax_class_id', 'class_id', 'class_name', 'product_tax_classes'); + } + + /** + * Add customer tax classes to result + * + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + public function addCustomerTaxClassesToResult() + { + return $this->_add('tax_class', 'customer_tax_class_id', 'class_id', 'class_name', 'customer_tax_classes'); + } + + /** + * Add rates to result + * + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + public function addRatesToResult() + { + return $this->_add('tax_calculation_rate', 'tax_calculation_rate_id', 'tax_calculation_rate_id', 'code', 'tax_rates'); + } + + /** + * Add class type filter + * + * @param string $type + * @param int $id + * @throws Mage_Core_Exception + * @return Mage_Tax_Model_Resource_Calculation_Rule_Collection + */ + public function setClassTypeFilter($type, $id) + { + switch ($type) { + case Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT: + $field = 'cd.product_tax_class_id'; + break; + case Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER: + $field = 'cd.customer_tax_class_id'; + break; + default: + Mage::throwException('Invalid type supplied'); + } + + $this->joinCalculationData('cd'); + $this->addFieldToFilter($field, $id); + return $this; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Class.php b/app/code/core/Mage/Tax/Model/Resource/Class.php new file mode 100755 index 0000000000..459956edb5 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Class.php @@ -0,0 +1,59 @@ + + */ +class Mage_Tax_Model_Resource_Class extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + public function _construct() + { + $this->_init('tax/tax_class', 'class_id'); + } + + /** + * Initialize unique fields + * + * @return Mage_Tax_Model_Resource_Class + */ + protected function _initUniqueFields() + { + $this->_uniqueFields = array(array( + 'field' => array('class_type', 'class_name'), + 'title' => Mage::helper('tax')->__('An error occurred while saving this tax class. A class with the same name already exists.'), + )); + return $this; + } +} diff --git a/app/code/core/Mage/Core/Model/Mysql4/History.php b/app/code/core/Mage/Tax/Model/Resource/Class/Collection.php old mode 100644 new mode 100755 similarity index 50% rename from app/code/core/Mage/Core/Model/Mysql4/History.php rename to app/code/core/Mage/Tax/Model/Resource/Class/Collection.php index 8ac8fa5043..b823414b4a --- a/app/code/core/Mage/Core/Model/Mysql4/History.php +++ b/app/code/core/Mage/Tax/Model/Resource/Class/Collection.php @@ -19,47 +19,57 @@ * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage - * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @package Mage_Tax + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * Data change history model + * Tax class collection * - * @category Mage - * @package Mage_Core + * @category Mage + * @package Mage_Tax * @author Magento Core Team */ -class Mage_Core_Model_Mysql4_History +class Mage_Tax_Model_Resource_Class_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { - protected $_changeTable = null; - protected $_changeInfoTable = null; - - public function __construct() + /** + * Resource initialization + */ + public function _construct() { - $this->_changeTable = Mage::getSingleton('core/resource')->getTableName('core/data_change'); - $this->_changeInfoTable = Mage::getSingleton('core/resource')->getTableName('core/data_change_info'); + $this->_init('tax/class'); } - + + /** + * Add class type filter to result + * + * @param int $classTypeId + * @return Mage_Tax_Model_Resource_Class_Collection + */ + public function setClassTypeFilter($classTypeId) + { + return $this->addFieldToFilter('main_table.class_type', $classTypeId); + } + + /** + * Retrieve option array + * + * @return array + */ + public function toOptionArray() + { + return $this->_toOptionArray('class_id', 'class_name'); + } + /** - * Add data changes - * - * $data = array( - * [$tableName] => array( - * [pk_value] - * [type] = 'insert' || 'update' || 'delete' - * [before] - * [after] - * ) - * ) - * - * @param string $code - * @param int $userId - * @param array $data + * Retrieve option hash + * + * @return array */ - public function addChanges($code, $userId, $data) + public function toOptionHash() { - + return $this->_toOptionHash('class_id', 'class_name'); } } diff --git a/app/code/core/Mage/Tax/Model/Resource/Report/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Report/Collection.php new file mode 100755 index 0000000000..ba3360b4f7 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Report/Collection.php @@ -0,0 +1,124 @@ + + */ +class Mage_Tax_Model_Resource_Report_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Enter description here ... + * + * @var unknown + */ + protected $_periodFormat; + + /** + * Enter description here ... + * + * @var unknown + */ + protected $_selectedColumns = array(); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('tax/tax_order_aggregated_created'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Enter description here ... + * + * @return unknown + */ + protected function _getSelectedColumns() + { + if ('month' == $this->_period) { + $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y'); + } else { + $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m-%d'); + } + + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'code' => 'code', + 'percent' => 'percent', + 'orders_count' => 'SUM(orders_count)', + 'tax_base_amount_sum' => 'SUM(tax_base_amount_sum)' + ); + } + + if ($this->isTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns(); + } + + if ($this->isSubTotals()) { + $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Tax_Model_Resource_Report_Collection + */ + protected function _initSelect() + { + $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns()); + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->getSelect()->group(array($this->_periodFormat, 'code', 'percent')); + } + + if ($this->isSubTotals()) { + $this->getSelect()->group(array( + $this->_periodFormat + )); + } + + /** + * Allow to use analytic function + */ + $this->_useAnalyticFunction = true; + + return $this; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Report/Tax.php b/app/code/core/Mage/Tax/Model/Resource/Report/Tax.php new file mode 100755 index 0000000000..c03fe186bb --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Report/Tax.php @@ -0,0 +1,138 @@ + + */ +class Mage_Tax_Model_Resource_Report_Tax extends Mage_Reports_Model_Resource_Report_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/tax_order_aggregated_created', 'id'); + } + + /** + * Aggregate Tax data + * + * @param mixed $from + * @param mixed $to + * @return Mage_Tax_Model_Resource_Report_Tax + */ + public function aggregate($from = null, $to = null) + { + // convert input dates to UTC to be comparable with DATETIME fields in DB + $from = $this->_dateToUtc($from); + $to = $this->_dateToUtc($to); + + $this->_checkDates($from, $to); + $writeAdapter = $this->_getWriteAdapter(); + $writeAdapter->beginTransaction(); + + try { + if ($from !== null || $to !== null) { + $subSelect = $this->_getTableDateRangeSelect( + $this->getTable('sales/order'), + 'created_at', 'updated_at', $from, $to + ); + } else { + $subSelect = null; + } + + $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect); + // convert dates from UTC to current admin timezone + $periodExpr = $writeAdapter->getDatePartSql($writeAdapter->getDateAddSql('e.created_at', + $this->_getStoreTimezoneUtcOffset(), Varien_Db_Adapter_Interface::INTERVAL_HOUR)); + + $columns = array( + 'period' => $periodExpr, + 'store_id' => 'e.store_id', + 'code' => 'tax.code', + 'order_status' => 'e.status', + 'percent' => 'MAX(tax.' . $writeAdapter->quoteIdentifier('percent') .')', + 'orders_count' => 'COUNT(DISTINCT e.entity_id)', + 'tax_base_amount_sum' => 'SUM(tax.base_amount * e.base_to_global_rate)' + ); + + $select = $writeAdapter->select(); + $select->from(array('tax' => $this->getTable('tax/sales_order_tax')), $columns) + ->joinInner(array('e' => $this->getTable('sales/order')), 'e.entity_id = tax.order_id', array()) + ->useStraightJoin(); + + $select->where('e.state NOT IN (?)', array( + Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, + Mage_Sales_Model_Order::STATE_NEW + )); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'e.created_at')); + } + + $select->group(array($periodExpr, 'e.store_id', 'code', 'tax.percent', 'e.status')); + + $insertQuery = $writeAdapter->insertFromSelect($select, $this->getMainTable(), array_keys($columns)); + $writeAdapter->query($insertQuery); + + $select->reset(); + + $columns = array( + 'period' => 'period', + 'store_id' => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID), + 'code' => 'code', + 'order_status' => 'order_status', + 'percent' => 'MAX(' . $writeAdapter->quoteIdentifier('percent') . ')', + 'orders_count' => 'SUM(orders_count)', + 'tax_base_amount_sum' => 'SUM(tax_base_amount_sum)' + ); + + $select + ->from($this->getMainTable(), $columns) + ->where('store_id <> ?', 0); + + if ($subSelect !== null) { + $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period')); + } + + $select->group(array('period', 'code', 'percent', 'order_status')); + $insertQuery = $writeAdapter->insertFromSelect($select, $this->getMainTable(), array_keys($columns)); + $writeAdapter->query($insertQuery); + $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_TAX_FLAG_CODE); + } catch (Exception $e) { + $writeAdapter->rollBack(); + throw $e; + } + + $writeAdapter->commit(); + return $this; + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Report/Updatedat/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Report/Updatedat/Collection.php new file mode 100755 index 0000000000..096741c47f --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Report/Updatedat/Collection.php @@ -0,0 +1,225 @@ + + */ +class Mage_Tax_Model_Resource_Report_Updatedat_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract +{ + /** + * Period format + * + * @var unknown + */ + protected $_periodFormat; + + /** + * Flag if collection was initiated + * + * @var unknown + */ + protected $_inited = false; + + /** + * Default selected columns + * + * @var unknown + */ + protected $_selectedColumns = array( + 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', + 'tax_base_amount_sum' => 'SUM(tax.base_real_amount * e.base_to_global_rate)' + ); + + /** + * Initialize custom resource model + * + */ + public function __construct() + { + parent::_construct(); + $this->setModel('adminhtml/report_item'); + $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order', 'entity_id'); + $this->setConnection($this->getResource()->getReadConnection()); + } + + /** + * Apply stores filter + * + * @return Mage_Tax_Model_Resource_Report_Updatedat_Collection + */ + protected function _applyStoresFilter() + { + $nullCheck = false; + $storeIds = $this->_storesIds; + + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + + $storeIds = array_unique($storeIds); + + if ($index = array_search(null, $storeIds)) { + unset($storeIds[$index]); + $nullCheck = true; + } + + if ($nullCheck) { + $this->getSelect()->where('store_id IN(?) OR store_id IS NULL', $storeIds); + } elseif ($storeIds[0] != '') { + $this->getSelect()->where('store_id IN(?)', $storeIds); + } + + return $this; + } + + /** + * Apply order status filter + * + * @return Mage_Tax_Model_Resource_Report_Updatedat_Collection + */ + protected function _applyOrderStatusFilter() + { + if (is_null($this->_orderStatus)) { + return $this; + } + $orderStatus = $this->_orderStatus; + if (!is_array($orderStatus)) { + $orderStatus = array($orderStatus); + } + $this->getSelect()->where('status IN(?)', $orderStatus); + return $this; + } + + /** + * Retrieve array of columns to select + * + * @return array + */ + protected function _getSelectedColumns() + { + $adapter = $this->getConnection(); + + if ('month' == $this->_period) { + $this->_periodFormat = $adapter->getDateFormatSql('e.updated_at', '%Y-%m'); + } elseif ('year' == $this->_period) { + $this->_periodFormat = $adapter->getDateExtractSql('e.updated_at', Varien_Db_Adapter_Interface::INTERVAL_YEAR); + } else { + $this->_periodFormat = $adapter->getDateFormatSql('e.updated_at', '%Y-%m-%d'); + } + + // To make this query valid in MSSQL and Oralce we have to add + // MIN() for store_id, status, percent. + // You should aggregate additional columns if override + + if (!$this->isTotals() && !$this->isSubTotals()) { + $this->_selectedColumns = array( + 'period' => $this->_periodFormat, + 'store_id' => 'MIN(store_id)', + 'code' => 'tax.code', + 'order_status' => 'MIN(e.status)', + 'percent' => 'MIN(' . $this->getConnection()->quoteIdentifier('tax.percent') . ')', + 'orders_count' => 'COUNT(DISTINCT(e.entity_id))', + 'tax_base_amount_sum' => 'SUM(tax.base_real_amount * e.base_to_global_rate)' + ); + } + + if ($this->isSubTotals()) { + $this->_selectedColumns += array('period' => $this->_periodFormat); + } + + return $this->_selectedColumns; + } + + /** + * Add selected data + * + * @return Mage_Tax_Model_Resource_Report_Updatedat_Collection + */ + protected function _initSelect() + { + if ($this->_inited) { + return $this; + } + + $columns = $this->_getSelectedColumns(); + $mainTable = $this->getResource()->getMainTable(); + + $select = $this->getSelect() + ->from(array('e' => $mainTable), $columns) + ->joinInner(array('tax'=> $this->getTable('tax/sales_order_tax')), 'e.entity_id = tax.order_id', array()); + + $this->_applyStoresFilter(); + $this->_applyOrderStatusFilter(); + + $adapter = $this->getConnection(); + $dateUpdatedAt = $adapter->getDatePartSql('e.updated_at'); + + if ($this->_to !== null) { + $dateTo = $adapter->formatDate($this->_to, false); + $select->where("{$dateUpdatedAt} <= {$dateTo}"); + } + + if ($this->_from !== null) { + $dateFrom = $adapter->formatDate($this->_from, false); + $select->where("{$dateUpdatedAt} >= {$dateFrom}"); + } + + if (!$this->isTotals() && !$this->isSubTotals()) { + $select->group(array($this->_periodFormat, 'code', 'percent')); + } + + if ($this->isSubTotals()) { + $select->group(array( + $this->_periodFormat + )); + } + + $this->_inited = true; + return $this; + } + + /** + * Load + * + * @param boolean $printQuery + * @param boolean $logQuery + * @return Mage_Tax_Model_Resource_Report_Updatedat_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if ($this->isLoaded()) { + return $this; + } + $this->_initSelect(); + $this->setApplyFilters(false); + return parent::load($printQuery, $logQuery); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax.php b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax.php new file mode 100755 index 0000000000..d408b28b1b --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax.php @@ -0,0 +1,44 @@ + + */ +class Mage_Tax_Model_Resource_Sales_Order_Tax extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/sales_order_tax', 'tax_id'); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Collection.php b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Collection.php new file mode 100755 index 0000000000..555eef5e37 --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Sales/Order/Tax/Collection.php @@ -0,0 +1,59 @@ + + */ +class Mage_Tax_Model_Resource_Sales_Order_Tax_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Resource initialization + */ + protected function _construct() + { + $this->_init('tax/sales_order_tax'); + } + + /** + * Retrieve order tax collection by order identifier + * + * @param Varien_Object $order + * @return Mage_Tax_Model_Resource_Sales_Order_Tax_Collection + */ + public function loadByOrder($order) + { + $orderId = $order->getId(); + $this->getSelect() + ->where('main_table.order_id = ?', (int)$orderId) + ->order('process'); + return $this->load(); + } +} diff --git a/app/code/core/Mage/Tax/Model/Resource/Setup.php b/app/code/core/Mage/Tax/Model/Resource/Setup.php new file mode 100755 index 0000000000..5c5b5a34ab --- /dev/null +++ b/app/code/core/Mage/Tax/Model/Resource/Setup.php @@ -0,0 +1,152 @@ + + */ +class Mage_Tax_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup +{ + /** + * Convert old Tax data + * @deprecated since 1.5.0.0 + */ + public function convertOldTaxData() + { + $oldRules = $this->_loadTableData('tax_rule'); + + $oldRateTypes = $this->_loadTableData('tax_rate_type'); + + $rateById = array(); + foreach ($oldRateTypes as $type) { + $rateById[$type['type_id']] = $type['type_name']; + } + + $oldRates = $this->_loadOldRates($oldRateTypes); + + $oldToNewRateIds = array(); + + foreach ($oldRates as $rate) { + foreach ($oldRateTypes as $type) { + $rateIndex = sprintf('data_%s', $type['type_id']); + if (isset($rate[$rateIndex])) { + $rateValue = $rate[$rateIndex]; + } else { + continue; + } + + $region = Mage::getModel('directory/region')->load($rate['tax_region_id']); + $regionName = $region->getCode() ? $region->getCode() : '*'; + $code = "{$rate['tax_country_id']}-{$regionName}-{$rate['tax_postcode']}-{$type['type_name']}"; + + if ($rateValue > 0) { + $insertData = array( + 'tax_country_id' => $rate['tax_country_id'], + 'tax_region_id' => $rate['tax_region_id'], + 'tax_postcode' => $rate['tax_postcode'], + 'code' => $code, + 'rate' => $rateValue, + ); + + $newRateModel = Mage::getModel('tax/calculation_rate'); + + $newRateModel->setData($insertData)->save(); + $oldToNewRateIds[$rate['tax_rate_id']] = $newRateModel->getId(); + $ratesByType[$type['type_id']][] = $newRateModel->getId(); + } + } + } + + foreach ($oldRules as $rule) { + if (!isset($ratesByType[$rule['tax_rate_type_id']]) || !count($ratesByType[$rule['tax_rate_type_id']])) { + continue; + } + + $customerTaxClasses = array($rule['tax_customer_class_id']); + $productTaxClasses = array($rule['tax_product_class_id']); + + $ctc = Mage::getModel('tax/class')->load($rule['tax_customer_class_id']); + $ptc = Mage::getModel('tax/class')->load($rule['tax_product_class_id']); + $type = $rateById[$rule['tax_rate_type_id']]; + + $rates = $ratesByType[$rule['tax_rate_type_id']]; + $code = "{$ctc->getClassName()}-{$ptc->getClassName()}-{$type}"; + + $ruleData = array( + 'tax_rate' => $rates, + 'tax_product_class' => $productTaxClasses, + 'tax_customer_class' => $customerTaxClasses, + 'code' => $code, + 'priority' => 1, + 'position' => 1 + ); + Mage::getModel('tax/calculation_rule')->setData($ruleData)->save(); + } + + return $this; + } + + /** + * Load Tax Table Data + * + * @param string $table + * @return array + */ + protected function _loadTableData($table) + { + $table = $this->getTable($table); + $select = $this->_conn->select(); + $select->from($table); + return $this->_conn->fetchAll($select); + } + + /** + * Load Old Rate Data + * @deprecated since 1.5.0.0 + * + * @param array $oldRateTypes + * @return array + */ + protected function _loadOldRates($oldRateTypes) + { + $table = $this->getTable('tax_rate'); + $select = $this->_conn->select() + ->from(array('main_table'=>$table)); + foreach ($oldRateTypes as $type){ + $id = $type['type_id']; + $select->joinLeft( + array("data_{$id}"=>$this->getTable('tax_rate_data')), + "data_{$id}.rate_type_id = {$id} AND data_{$id}.tax_rate_id = main_table.tax_rate_id", + array("data_{$id}"=>'rate_value') + ); + } + return $this->_conn->fetchAll($select); + } +} diff --git a/app/code/core/Mage/Tax/Model/Sales/Order/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Order/Tax.php index 872d9704af..0111d77fa7 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Order/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Order/Tax.php @@ -20,10 +20,42 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * Enter description here ... + * + * @method Mage_Tax_Model_Resource_Sales_Order_Tax _getResource() + * @method Mage_Tax_Model_Resource_Sales_Order_Tax getResource() + * @method int getOrderId() + * @method Mage_Tax_Model_Sales_Order_Tax setOrderId(int $value) + * @method string getCode() + * @method Mage_Tax_Model_Sales_Order_Tax setCode(string $value) + * @method string getTitle() + * @method Mage_Tax_Model_Sales_Order_Tax setTitle(string $value) + * @method float getPercent() + * @method Mage_Tax_Model_Sales_Order_Tax setPercent(float $value) + * @method float getAmount() + * @method Mage_Tax_Model_Sales_Order_Tax setAmount(float $value) + * @method int getPriority() + * @method Mage_Tax_Model_Sales_Order_Tax setPriority(int $value) + * @method int getPosition() + * @method Mage_Tax_Model_Sales_Order_Tax setPosition(int $value) + * @method float getBaseAmount() + * @method Mage_Tax_Model_Sales_Order_Tax setBaseAmount(float $value) + * @method int getProcess() + * @method Mage_Tax_Model_Sales_Order_Tax setProcess(int $value) + * @method float getBaseRealAmount() + * @method Mage_Tax_Model_Sales_Order_Tax setBaseRealAmount(float $value) + * @method int getHidden() + * @method Mage_Tax_Model_Sales_Order_Tax setHidden(int $value) + * + * @category Mage + * @package Mage_Tax + * @author Magento Core Team + */ class Mage_Tax_Model_Sales_Order_Tax extends Mage_Core_Model_Abstract { protected function _construct() diff --git a/app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php b/app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php index 86edf598c9..be0d996285 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php +++ b/app/code/core/Mage/Tax/Model/Sales/Pdf/Grandtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Pdf/Shipping.php b/app/code/core/Mage/Tax/Model/Sales/Pdf/Shipping.php index 0f947a38a2..4e0b9138b7 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Pdf/Shipping.php +++ b/app/code/core/Mage/Tax/Model/Sales/Pdf/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Pdf/Subtotal.php b/app/code/core/Mage/Tax/Model/Sales/Pdf/Subtotal.php index 99931b6cb1..1843b0e48c 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Pdf/Subtotal.php +++ b/app/code/core/Mage/Tax/Model/Sales/Pdf/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Pdf/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Pdf/Tax.php index 7c216d8ef8..1bbe320670 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Pdf/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Pdf/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Discount.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Discount.php index 82d2162ec1..efd0f29218 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Discount.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Discount.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php index 7d4652c3ce..94c946bf63 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Tax.php index f6f5b28f33..db346692e0 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Nominal/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Shipping.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Shipping.php index c6c10e5eca..43bc21c56b 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Shipping.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php index 18b3362f51..d72d1c2af2 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php index 621855eb44..43b713452f 100644 --- a/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/Algorithm.php b/app/code/core/Mage/Tax/Model/System/Config/Source/Algorithm.php index 3d906fc2ab..507792a162 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/Algorithm.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/Algorithm.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/Apply.php b/app/code/core/Mage/Tax/Model/System/Config/Source/Apply.php index 50d4e3d3eb..6940a402a2 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/Apply.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/Apply.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/PriceType.php b/app/code/core/Mage/Tax/Model/System/Config/Source/PriceType.php index f82db869c5..29d1ea72f3 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/PriceType.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/PriceType.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Country.php b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Country.php index d735c987e9..000cf61782 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Country.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Display/Type.php b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Display/Type.php index 08f2a51edd..b4c8a223ef 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Display/Type.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Display/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Region.php b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Region.php index 97c00a992b..a900aa1209 100644 --- a/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Region.php +++ b/app/code/core/Mage/Tax/Model/System/Config/Source/Tax/Region.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/data/tax_setup/data-install-1.6.0.0.php b/app/code/core/Mage/Tax/data/tax_setup/data-install-1.6.0.0.php new file mode 100644 index 0000000000..a7b8e9b7f1 --- /dev/null +++ b/app/code/core/Mage/Tax/data/tax_setup/data-install-1.6.0.0.php @@ -0,0 +1,106 @@ + 2, + 'class_name' => 'Taxable Goods', + 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT + ), + array( + 'class_id' => 3, + 'class_name' => 'Retail Customer', + 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER + ), + array( + 'class_id' => 4, + 'class_name' => 'Shipping', + 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT + ) +); +foreach ($data as $row) { + $installer->getConnection()->insertForce($installer->getTable('tax/tax_class'), $row); +} + +/** + * install tax calculation rule + */ +$data = array( + 'tax_calculation_rule_id' => 1, + 'code' => 'Retail Customer-Taxable Goods-Rate 1', + 'priority' => 1, + 'position' => 1 +); +$installer->getConnection()->insertForce($installer->getTable('tax/tax_calculation_rule'), $data); + +/** + * install tax calculation rates + */ +$data = array( + array( + 'tax_calculation_rate_id' => 1, + 'tax_country_id' => 'US', + 'tax_region_id' => 12, + 'tax_postcode' => '*', + 'code' => 'US-CA-*-Rate 1', + 'rate' => '8.2500' + ), + array( + 'tax_calculation_rate_id' => 2, + 'tax_country_id' => 'US', + 'tax_region_id' => 43, + 'tax_postcode' => '*', + 'code' => 'US-NY-*-Rate 1', + 'rate' => '8.3750' + ) +); +foreach ($data as $row) { + $installer->getConnection()->insertForce($installer->getTable('tax/tax_calculation_rate'), $row); +} + +/** + * install tax calculation + */ +$data = array( + array( + 'tax_calculation_rate_id' => 1, + 'tax_calculation_rule_id' => 1, + 'customer_tax_class_id' => 3, + 'product_tax_class_id' => 2 + ), + array( + 'tax_calculation_rate_id' => 2, + 'tax_calculation_rule_id' => 1, + 'customer_tax_class_id' => 3, + 'product_tax_class_id' => 2 + ) +); +$installer->getConnection()->insertMultiple($installer->getTable('tax/tax_calculation'), $data); + diff --git a/app/code/core/Mage/Tax/etc/adminhtml.xml b/app/code/core/Mage/Tax/etc/adminhtml.xml index 692087758f..3b7f5c2d61 100644 --- a/app/code/core/Mage/Tax/etc/adminhtml.xml +++ b/app/code/core/Mage/Tax/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Tax/etc/config.xml b/app/code/core/Mage/Tax/etc/config.xml index 483687d669..767f063b39 100644 --- a/app/code/core/Mage/Tax/etc/config.xml +++ b/app/code/core/Mage/Tax/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.1 + 1.6.0.0 Mage_Tax_Model - tax_mysql4 + tax_resource - - Mage_Tax_Model_Mysql4 + + Mage_Tax_Model_Resource + tax_mysql4 tax_class
      @@ -65,30 +66,50 @@ sales_order_tax
      -
      +
      Mage_Tax - Mage_Tax_Model_Mysql4_Setup + Mage_Tax_Model_Resource_Setup - * - * + + * + + + * + - * - * - * - * + + * + + + * + + + * + + + * + - *** - *** + + * + * + * + + + * + * + * + @@ -184,9 +205,15 @@ - tax/sales_pdf_subtotal - tax/sales_pdf_shipping - tax/sales_pdf_grandtotal + + tax/sales_pdf_subtotal + + + tax/sales_pdf_shipping + + + tax/sales_pdf_grandtotal + Tax tax_amount @@ -209,7 +236,6 @@ - @@ -224,7 +250,7 @@ - + TOTAL_BASE_CALCULATION @@ -268,8 +294,12 @@ - 0 0 * * * - tax/observer::aggregateSalesReportTaxData + + 0 0 * * * + + + tax/observer::aggregateSalesReportTaxData + diff --git a/app/code/core/Mage/Tax/etc/system.xml b/app/code/core/Mage/Tax/etc/system.xml index 935b5c3163..caf25e9074 100644 --- a/app/code/core/Mage/Tax/etc/system.xml +++ b/app/code/core/Mage/Tax/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Tax/sql/tax_setup/install-1.6.0.0.php b/app/code/core/Mage/Tax/sql/tax_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..488bca01ea --- /dev/null +++ b/app/code/core/Mage/Tax/sql/tax_setup/install-1.6.0.0.php @@ -0,0 +1,267 @@ +getConnection() + ->newTable($installer->getTable('tax/tax_class')) + ->addColumn('class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Class Id') + ->addColumn('class_name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false + ), 'Class Name') + ->addColumn('class_type', Varien_Db_Ddl_Table::TYPE_TEXT, 8, array( + 'nullable' => false, + 'default' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER, + ), 'Class Type') + ->setComment('Tax Class'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tax/calculation_rule' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tax/tax_calculation_rule')) + ->addColumn('tax_calculation_rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tax Calculation Rule Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Code') + ->addColumn('priority', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Priority') + ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Position') + ->addIndex($installer->getIdxName('tax/tax_calculation_rule', array('priority', 'position', 'tax_calculation_rule_id')), + array('priority', 'position', 'tax_calculation_rule_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation_rule', array('code')), + array('code')) + ->setComment('Tax Calculation Rule'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tax/calculation_rate' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tax/tax_calculation_rate')) + ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tax Calculation Rate Id') + ->addColumn('tax_country_id', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => false, + ), 'Tax Country Id') + ->addColumn('tax_region_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Tax Region Id') + ->addColumn('tax_postcode', Varien_Db_Ddl_Table::TYPE_TEXT, 21, array( + ), 'Tax Postcode') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Code') + ->addColumn('rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + ), 'Rate') + ->addColumn('zip_is_range', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + ), 'Zip Is Range') + ->addColumn('zip_from', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Zip From') + ->addColumn('zip_to', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + ), 'Zip To') + ->addIndex($installer->getIdxName('tax/tax_calculation_rate', array('tax_country_id', 'tax_region_id', 'tax_postcode')), + array('tax_country_id', 'tax_region_id', 'tax_postcode')) + ->addIndex($installer->getIdxName('tax/tax_calculation_rate', array('code')), + array('code')) + ->addIndex($installer->getIdxName('tax/tax_calculation_rate', array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode')), + array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode')) + ->setComment('Tax Calculation Rate'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tax/calculation' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tax/tax_calculation')) + ->addColumn('tax_calculation_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tax Calculation Id') + ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Tax Calculation Rate Id') + ->addColumn('tax_calculation_rule_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Tax Calculation Rule Id') + ->addColumn('customer_tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + ), 'Customer Tax Class Id') + ->addColumn('product_tax_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'nullable' => false, + ), 'Product Tax Class Id') + ->addIndex($installer->getIdxName('tax/tax_calculation', array('tax_calculation_rule_id')), + array('tax_calculation_rule_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation', array('tax_calculation_rate_id')), + array('tax_calculation_rate_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation', array('customer_tax_class_id')), + array('customer_tax_class_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation', array('product_tax_class_id')), + array('product_tax_class_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation', array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id')), + array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id')) + ->addForeignKey($installer->getFkName('tax/tax_calculation', 'product_tax_class_id', 'tax/tax_class', 'class_id'), + 'product_tax_class_id', $installer->getTable('tax/tax_class'), 'class_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tax/tax_calculation', 'customer_tax_class_id', 'tax/tax_class', 'class_id'), + 'customer_tax_class_id', $installer->getTable('tax/tax_class'), 'class_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tax/tax_calculation', 'tax_calculation_rate_id', 'tax/tax_calculation_rate', 'tax_calculation_rate_id'), + 'tax_calculation_rate_id', $installer->getTable('tax/tax_calculation_rate'), 'tax_calculation_rate_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tax/tax_calculation', 'tax_calculation_rule_id', 'tax/tax_calculation_rule', 'tax_calculation_rule_id'), + 'tax_calculation_rule_id', $installer->getTable('tax/tax_calculation_rule'), 'tax_calculation_rule_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tax Calculation'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tax/calculation_rate_title' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tax/tax_calculation_rate_title')) + ->addColumn('tax_calculation_rate_title_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Tax Calculation Rate Title Id') + ->addColumn('tax_calculation_rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'nullable' => false, + ), 'Tax Calculation Rate Id') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Store Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Value') + ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id', 'store_id')), + array('tax_calculation_rate_id', 'store_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id')), + array('tax_calculation_rate_id')) + ->addIndex($installer->getIdxName('tax/tax_calculation_rate_title', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('tax/tax_calculation_rate_title', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('tax/tax_calculation_rate_title', 'tax_calculation_rate_id', 'tax/tax_calculation_rate', 'tax_calculation_rate_id'), + 'tax_calculation_rate_id', $installer->getTable('tax/tax_calculation_rate'), 'tax_calculation_rate_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tax Calculation Rate Title'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'tax/order_aggregated_created' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('tax/tax_order_aggregated_created')) + ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Id') + ->addColumn('period', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + 'nullable' => true, + ), 'Period') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Code') + ->addColumn('order_status', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array( + 'nullable' => false, + ), 'Order Status') + ->addColumn('percent', Varien_Db_Ddl_Table::TYPE_FLOAT, null, array( + ), 'Percent') + ->addColumn('orders_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Orders Count') + ->addColumn('tax_base_amount_sum', Varien_Db_Ddl_Table::TYPE_FLOAT, null, array( + ), 'Tax Base Amount Sum') + ->addIndex($installer->getIdxName('tax/tax_order_aggregated_created', array('period', 'store_id', 'code', 'percent', 'order_status'), true), + array('period', 'store_id', 'code', 'percent', 'order_status'), array('type' => 'unique')) + ->addIndex($installer->getIdxName('tax/tax_order_aggregated_created', array('store_id')), + array('store_id')) + ->addForeignKey($installer->getFkName('tax/tax_order_aggregated_created', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Tax Order Aggregation'); +$installer->getConnection()->createTable($table); + +/** + * Add tax_class_id attribute to the 'eav/attribute' table + */ +$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'tax_class_id', array( + 'group' => 'Prices', + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Tax Class', + 'input' => 'select', + 'class' => '', + 'source' => 'tax/class_source_product', + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE, + 'visible' => true, + 'required' => true, + 'user_defined' => false, + 'default' => '', + 'searchable' => true, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => false, + 'visible_in_advanced_search' => true, + 'used_in_product_listing' => true, + 'unique' => false, + 'apply_to' => 'simple,configurable,virtual,downloadable,bundle' +)); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-0.7.0.php index ceb5f5cbf6..5f266b2111 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-1.4.0.0.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-1.4.0.0.php index 83d00f8d48..f103bb7055 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-1.4.0.0.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-install-1.4.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.6.1-0.7.0.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.6.1-0.7.0.php index 3977b93d04..eb0479322c 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.6.1-0.7.0.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.6.1-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.0-0.7.1.php index a472017d02..76417d25f9 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.1-0.7.2.php index 008c113fad..40448eb56c 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.10-0.7.11.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.10-0.7.11.php index 659d91f004..9b55276b7d 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.10-0.7.11.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.10-0.7.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -54,4 +54,3 @@ ); $installer->endSetup(); - diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.11-0.7.12.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.11-0.7.12.php index 43a387ed49..ee2435214c 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.11-0.7.12.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.11-0.7.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.12-0.7.13.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.12-0.7.13.php index abb4f490e5..6664b12ea7 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.12-0.7.13.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.12-0.7.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.2-0.7.3.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.2-0.7.3.php index 94573a6812..baa406da10 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.2-0.7.3.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.2-0.7.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.3-0.7.4.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.3-0.7.4.php index 3a5a982168..d5fd4c14d9 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.3-0.7.4.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.3-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.4-0.7.5.php index 0def77dee8..a4ca8245ea 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.5-0.7.6.php index 111a0b8e3f..86af095fcc 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.6-0.7.7.php index f670c8c40e..b5b96d56b4 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.7-0.7.8.php index 57612c62f1..1463009895 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.8-0.7.9.php index bf76b1759e..93294b7f9a 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.9-0.7.10.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.9-0.7.10.php index 4e29aaad88..87b2931415 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.9-0.7.10.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-0.7.9-0.7.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.3.9-1.4.0.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.3.9-1.4.0.php index 60f984a748..d2e8880503 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.3.9-1.4.0.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.3.9-1.4.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php index 2f78820bd8..4d226c2299 100644 --- a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Tax - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..fedda0c387 --- /dev/null +++ b/app/code/core/Mage/Tax/sql/tax_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,539 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_CTC' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_PTC' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_RATE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_RULE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation_rate_title'), + 'FK_TAX_CALCULATION_RATE_TITLE_RATE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_calculation_rate_title'), + 'FK_TAX_CALCULATION_RATE_TITLE_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('tax/tax_order_aggregated_created'), + 'FK_TAX_ORDER_AGGREGATED_CREATED_STORE' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_RULE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_RATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_CTC' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation'), + 'FK_TAX_CALCULATION_PTC' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation'), + 'IDX_TAX_CALCULATION' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate'), + 'IDX_TAX_CALCULATION_RATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate'), + 'IDX_TAX_CALCULATION_RATE_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate'), + 'IDX_TAX_CALCULATION_RATE_RANGE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + 'IDX_TAX_CALCULATION_RATE_TITLE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + 'FK_TAX_CALCULATION_RATE_TITLE_RATE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + 'FK_TAX_CALCULATION_RATE_TITLE_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rule'), + 'IDX_TAX_CALCULATION_RULE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_calculation_rule'), + 'IDX_TAX_CALCULATION_RULE_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_order_aggregated_created'), + 'UNQ_PERIOD_STORE_CODE_ORDER_STATUS' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('tax/tax_order_aggregated_created'), + 'IDX_STORE_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('tax/tax_class') => array( + 'columns' => array( + 'class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Class Id' + ), + 'class_name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Class Name' + ), + 'class_type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 8, + 'nullable' => false, + 'default' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER, + 'comment' => 'Class Type' + ) + ), + 'comment' => 'Tax Class' + ), + $installer->getTable('tax/tax_calculation') => array( + 'columns' => array( + 'tax_calculation_rate_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Tax Calculation Rate Id' + ), + 'tax_calculation_rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Tax Calculation Rule Id' + ), + 'customer_tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'comment' => 'Customer Tax Class Id' + ), + 'product_tax_class_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'nullable' => false, + 'comment' => 'Product Tax Class Id' + ) + ), + 'comment' => 'Tax Calculation' + ), + $installer->getTable('tax/tax_calculation_rate') => array( + 'columns' => array( + 'tax_calculation_rate_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tax Calculation Rate Id' + ), + 'tax_country_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'nullable' => false, + 'comment' => 'Tax Country Id' + ), + 'tax_region_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Tax Region Id' + ), + 'tax_postcode' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 21, + 'comment' => 'Tax Postcode' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Code' + ), + 'rate' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Rate' + ), + 'zip_is_range' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'comment' => 'Zip Is Range' + ), + 'zip_from' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Zip From' + ), + 'zip_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'comment' => 'Zip To' + ) + ), + 'comment' => 'Tax Calculation Rate' + ), + $installer->getTable('tax/tax_calculation_rate_title') => array( + 'columns' => array( + 'tax_calculation_rate_title_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tax Calculation Rate Title Id' + ), + 'tax_calculation_rate_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Tax Calculation Rate Id' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Store Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Value' + ) + ), + 'comment' => 'Tax Calculation Rate Title' + ), + $installer->getTable('tax/tax_calculation_rule') => array( + 'columns' => array( + 'tax_calculation_rule_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tax Calculation Rule Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Code' + ), + 'priority' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Priority' + ), + 'position' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'nullable' => false, + 'comment' => 'Position' + ) + ), + 'comment' => 'Tax Calculation Rule' + ), + $installer->getTable('tax/tax_order_aggregated_created') => array( + 'columns' => array( + 'id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Id' + ), + 'period' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Period' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Code' + ), + 'order_status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 50, + 'nullable' => false, + 'comment' => 'Order Status' + ), + 'percent' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_FLOAT, + 'comment' => 'Percent' + ), + 'orders_count' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Orders Count' + ), + 'tax_base_amount_sum' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_FLOAT, + 'comment' => 'Tax Base Amount Sum' + ) + ), + 'comment' => 'Tax Order Aggregation' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->addColumn( + $installer->getTable('tax/tax_calculation'), + 'tax_calculation_id', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Tax Calculation Id' + ) +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation'), + $installer->getIdxName('tax/tax_calculation', array('tax_calculation_rule_id')), + array('tax_calculation_rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation'), + $installer->getIdxName('tax/tax_calculation', array('tax_calculation_rate_id')), + array('tax_calculation_rate_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation'), + $installer->getIdxName('tax/tax_calculation', array('customer_tax_class_id')), + array('customer_tax_class_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation'), + $installer->getIdxName('tax/tax_calculation', array('product_tax_class_id')), + array('product_tax_class_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation'), + $installer->getIdxName('tax/tax_calculation', array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id')), + array('tax_calculation_rate_id', 'customer_tax_class_id', 'product_tax_class_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate'), + $installer->getIdxName('tax/tax_calculation_rate', array('tax_country_id', 'tax_region_id', 'tax_postcode')), + array('tax_country_id', 'tax_region_id', 'tax_postcode') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate'), + $installer->getIdxName('tax/tax_calculation_rate', array('code')), + array('code') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate'), + $installer->getIdxName('tax/tax_calculation_rate', array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode')), + array('tax_calculation_rate_id', 'tax_country_id', 'tax_region_id', 'zip_is_range', 'tax_postcode') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + $installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id', 'store_id')), + array('tax_calculation_rate_id', 'store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + $installer->getIdxName('tax/tax_calculation_rate_title', array('tax_calculation_rate_id')), + array('tax_calculation_rate_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rate_title'), + $installer->getIdxName('tax/tax_calculation_rate_title', array('store_id')), + array('store_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rule'), + $installer->getIdxName('tax/tax_calculation_rule', array('priority', 'position', 'tax_calculation_rule_id')), + array('priority', 'position', 'tax_calculation_rule_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_calculation_rule'), + $installer->getIdxName('tax/tax_calculation_rule', array('code')), + array('code') +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_order_aggregated_created'), + $installer->getIdxName( + 'tax/tax_order_aggregated_created', + array('period', 'store_id', 'code', 'percent', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('period', 'store_id', 'code', 'percent', 'order_status'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('tax/tax_order_aggregated_created'), + $installer->getIdxName('tax/tax_order_aggregated_created', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation', 'product_tax_class_id', 'tax/tax_class', 'class_id'), + $installer->getTable('tax/tax_calculation'), + 'product_tax_class_id', + $installer->getTable('tax/tax_class'), + 'class_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation', 'customer_tax_class_id', 'tax/tax_class', 'class_id'), + $installer->getTable('tax/tax_calculation'), + 'customer_tax_class_id', + $installer->getTable('tax/tax_class'), + 'class_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation', 'tax_calculation_rate_id', 'tax/tax_calculation_rate', 'tax_calculation_rate_id'), + $installer->getTable('tax/tax_calculation'), + 'tax_calculation_rate_id', + $installer->getTable('tax/tax_calculation_rate'), + 'tax_calculation_rate_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation', 'tax_calculation_rule_id', 'tax/tax_calculation_rule', 'tax_calculation_rule_id'), + $installer->getTable('tax/tax_calculation'), + 'tax_calculation_rule_id', + $installer->getTable('tax/tax_calculation_rule'), + 'tax_calculation_rule_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation_rate_title', 'store_id', 'core/store', 'store_id'), + $installer->getTable('tax/tax_calculation_rate_title'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_calculation_rate_title', 'tax_calculation_rate_id', 'tax/tax_calculation_rate', 'tax_calculation_rate_id'), + $installer->getTable('tax/tax_calculation_rate_title'), + 'tax_calculation_rate_id', + $installer->getTable('tax/tax_calculation_rate'), + 'tax_calculation_rate_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('tax/tax_order_aggregated_created', 'store_id', 'core/store', 'store_id'), + $installer->getTable('tax/tax_order_aggregated_created'), + 'store_id', + $installer->getTable('core/store'), + 'store_id' +); +$installer->endSetup(); diff --git a/app/code/core/Mage/Usa/Helper/Data.php b/app/code/core/Mage/Usa/Helper/Data.php index 4ac8f9eda1..0340ba2303 100644 --- a/app/code/core/Mage/Usa/Helper/Data.php +++ b/app/code/core/Mage/Usa/Helper/Data.php @@ -20,12 +20,12 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - + /** - * Catalog data helper + * Usa data helper * * @author Magento Core Team */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php index 5a7c74fe23..7f9129267d 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php index acdf699b0b..1054fbc8b8 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Dutypaymenttype.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Dutypaymenttype.php index 109e275b57..e0d6841ac0 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Dutypaymenttype.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Dutypaymenttype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Freemethod.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Freemethod.php index 982ab0c367..9d6e77f778 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Freemethod.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Freemethod.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Method.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Method.php index e01c18fe82..476ed37d2e 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Method.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Rounding.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Rounding.php index ff5f04f061..5c5acd6298 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Rounding.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Rounding.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Value.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Value.php index fcf1f8b1fa..6d81ca6e5b 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Value.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Protection/Value.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Shipmenttype.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Shipmenttype.php index dd61fd65bd..45b2b11db8 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Shipmenttype.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Source/Shipmenttype.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php index 9d8b2f4711..23e9ac4907 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Dropoff.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Dropoff.php index 547395b49a..19072853a3 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Dropoff.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Dropoff.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Freemethod.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Freemethod.php index c86d6af450..e7188fef49 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Freemethod.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Freemethod.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Method.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Method.php index 364e1b8cde..88135c4d45 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Method.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Packaging.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Packaging.php index 9c417f1f37..74e771570f 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Packaging.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex/Source/Packaging.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php index 4662ec2085..65d1dde87e 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,15 +37,15 @@ class Mage_Usa_Model_Shipping_Carrier_Ups implements Mage_Shipping_Model_Carrier_Interface { - protected $_code = 'ups'; + protected $_code = 'ups'; - protected $_request = null; + protected $_request = null; - protected $_result = null; + protected $_result = null; - protected $_xmlAccessRequest = null; + protected $_xmlAccessRequest = null; - protected $_defaultCgiGatewayUrl = 'http://www.ups.com:80/using/services/rave/qcostcgi.cgi'; + protected $_defaultCgiGatewayUrl = 'http://www.ups.com:80/using/services/rave/qcostcgi.cgi'; /** * Base currency rate @@ -336,7 +336,6 @@ protected function _parseCgiResponse($response) $error = Mage::getModel('shipping/rate_result_error'); $error->setCarrier('ups'); $error->setCarrierTitle($this->getConfigData('title')); - //$error->setErrorMessage($errorTitle); $error->setErrorMessage($this->getConfigData('specificerrmsg')); $result->append($error); } else { @@ -352,16 +351,9 @@ protected function _parseCgiResponse($response) $result->append($rate); } } -#echo "
      ".print_r($result,1)."
      "; - return $result; - } -/* - public function isEligibleForFree($method) - { - return $method=='GND' || $method=='GNDCOM' || $method=='GNDRES'; + return $result; } -*/ public function getCode($type, $code='') { diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Container.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Container.php index 77dc75fda9..13b78bda06 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Container.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/DestType.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/DestType.php index ca5cdaa8d9..53afeafaca 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/DestType.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/DestType.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Freemethod.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Freemethod.php index 475b67a0ca..dffe74c5c3 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Freemethod.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Freemethod.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php index fe58afe607..0962aff35f 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Mode.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Mode.php index 3ba32168fc..6df5ff0422 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Mode.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Mode.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/OriginShipment.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/OriginShipment.php index 3c3cf157db..cd337a6323 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/OriginShipment.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/OriginShipment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Pickup.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Pickup.php index 20f37a85b7..4eae390581 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Pickup.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Pickup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Type.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Type.php index 9a8e5fe4d0..31e7b07b04 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Type.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Unitofmeasure.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Unitofmeasure.php index 371156a806..7535edefea 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Unitofmeasure.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Unitofmeasure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php index 9135e40dde..f14d67d363 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -206,32 +206,30 @@ protected function _getXmlQuotes() $xml->addAttribute('USERID', $r->getUserId()); $package = $xml->addChild('Package'); - $package->addAttribute('ID', 0); - $service = $this->getCode('service_to_code', $r->getService()); - if (!$service) { - $service = $r->getService(); - } - $package->addChild('Service', $service); - - // no matter Letter, Flat or Parcel, use Parcel - if ($r->getService() == 'FIRST CLASS') { - $package->addChild('FirstClassMailType', 'PARCEL'); - } - $package->addChild('ZipOrigination', $r->getOrigPostal()); - //only 5 chars avaialble - $package->addChild('ZipDestination', substr($r->getDestPostal(),0,5)); - $package->addChild('Pounds', $r->getWeightPounds()); - $package->addChild('Ounces', $r->getWeightOunces()); -// $package->addChild('Pounds', '0'); -// $package->addChild('Ounces', '3'); + $package->addAttribute('ID', 0); + $service = $this->getCode('service_to_code', $r->getService()); + if (!$service) { + $service = $r->getService(); + } + $package->addChild('Service', $service); - // Because some methods don't accept VARIABLE and (NON)RECTANGULAR containers - if (strtoupper($r->getContainer()) == 'FLAT RATE ENVELOPE' || strtoupper($r->getContainer()) == 'FLAT RATE BOX') { - $package->addChild('Container', $r->getContainer()); - } + // no matter Letter, Flat or Parcel, use Parcel + if ($r->getService() == 'FIRST CLASS') { + $package->addChild('FirstClassMailType', 'PARCEL'); + } + $package->addChild('ZipOrigination', $r->getOrigPostal()); + //only 5 chars avaialble + $package->addChild('ZipDestination', substr($r->getDestPostal(),0,5)); + $package->addChild('Pounds', $r->getWeightPounds()); + $package->addChild('Ounces', $r->getWeightOunces()); + + // Because some methods don't accept VARIABLE and (NON)RECTANGULAR containers + if (strtoupper($r->getContainer()) == 'FLAT RATE ENVELOPE' || strtoupper($r->getContainer()) == 'FLAT RATE BOX') { + $package->addChild('Container', $r->getContainer()); + } - $package->addChild('Size', $r->getSize()); - $package->addChild('Machinable', $r->getMachinable()); + $package->addChild('Size', $r->getSize()); + $package->addChild('Machinable', $r->getMachinable()); $api = 'RateV3'; $request = $xml->asXML(); @@ -357,7 +355,7 @@ protected function _parseXmlResponse($response) $result->append($rate); } } - + return $result; } @@ -373,31 +371,7 @@ public function getCode($type, $code='') 'PARCEL' => Mage::helper('usa')->__('Parcel Post'), 'MEDIA' => Mage::helper('usa')->__('Media Mail'), 'LIBRARY' => Mage::helper('usa')->__('Library'), -// 'ALL' => Mage::helper('usa')->__('All Services'), - ), - -/* - 'method'=>array( - 'First-Class', - 'Express Mail', - 'Express Mail PO to PO', - 'Priority Mail', - 'Parcel Post', - 'Express Mail Flat-Rate Envelope', - 'Priority Mail Flat-Rate Box', - 'Bound Printed Matter', - 'Media Mail', - 'Library Mail', - 'Priority Mail Flat-Rate Envelope', - 'Global Express Guaranteed', - 'Global Express Guaranteed Non-Document Rectangular', - 'Global Express Guaranteed Non-Document Non-Rectangular', - 'Express Mail International (EMS)', - 'Express Mail International (EMS) Flat Rate Envelope', - 'Priority Mail International', - 'Priority Mail International Flat Rate Box', ), -*/ 'service_to_code'=>array( 'First-Class' => 'FIRST CLASS', diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Container.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Container.php index 8898fad4fe..de7dde9dbf 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Container.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Freemethod.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Freemethod.php index 4528999357..f5a9c83d30 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Freemethod.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Freemethod.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Machinable.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Machinable.php index ed966c9eb8..347bad4126 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Machinable.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Machinable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Method.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Method.php index 5f07fa440b..537e3ade61 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Method.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Method.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Size.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Size.php index 5c566b939e..ede643ac5f 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Size.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps/Source/Size.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Usa/etc/config.xml b/app/code/core/Mage/Usa/etc/config.xml index 670b2f1b4f..39b31ed81e 100644 --- a/app/code/core/Mage/Usa/etc/config.xml +++ b/app/code/core/Mage/Usa/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.1 + 1.6.0.0 @@ -92,25 +92,24 @@
      - - + 0 0 E,N,S,G,IE,E SAT,E 10:30AM Big Box - + R G https://eCommerce.airborne.com/ApiLandingTest.asp - + usa/shipping_carrier_dhl - + P - - + + DHL This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us. 150 @@ -120,13 +119,12 @@ 1,2,3,4,5 0 - - + 0 0 PRIORITYOVERNIGHT,STANDARDOVERNIGHT,FIRSTOVERNIGHT,FEDEX2DAY,FEDEXEXPRESSSAVER,INTERNATIONALPRIORITY,INTERNATIONALECONOMY,INTERNATIONALFIRST,FEDEX1DAYFREIGHT,FEDEX2DAYFREIGHT,FEDEX3DAYFREIGHT,FEDEXGROUND,GROUNDHOMEDELIVERY,INTERNATIONALPRIORITY FREIGHT,INTERNATIONALECONOMY FREIGHT,EUROPEFIRSTINTERNATIONALPRIORITY - + REGULARPICKUP FEDEXGROUND https://gateway.fedex.com/GatewayDC @@ -139,7 +137,6 @@ F O - 0 @@ -147,7 +144,7 @@ 1DM,1DML,1DA,1DAL,1DAPI,1DP,1DPL,2DM,2DML,2DA,2DAL,3DS,GND,GNDCOM,GNDRES,STD,XPR,WXS,XPRL,XDM,XDML,XPD Shipments Originating in United States CP - + RES GND http://www.ups.com/using/services/rave/qcostcgi.cgi @@ -169,16 +166,15 @@ 1 UPS - 0 0 Bound Printed Matter,Express Mail,Express Mail Flat Rate Envelope,Express Mail Flat Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International,Express Mail International Flat Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail Large Envelope,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,First-Class Mail Package,Global Express Guaranteed (GXG),Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Small Flat Rate Box,Priority Mail Medium Flat Rate Box,Priority Mail Large Flat Rate Box,Priority Mail Flat Rate Box,Priority Mail Flat Rate Envelope,Priority Mail International,Priority Mail International Flat Rate Box,Priority Mail International Flat Rate Envelope,Priority Mail International Small Flat Rate Box,Priority Mail International Medium Flat Rate Box,Priority Mail International Large Flat Rate Box,USPS GXG Envelopes VARIABLE - - + + http://production.shippingapis.com/ShippingAPI.dll - + true Bound Printed Matter,Express Mail,Express Mail Flat Rate Envelope,Express Mail Flat Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International,Express Mail International Flat Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail Large Envelope,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,First-Class Mail Package,Global Express Guaranteed (GXG),Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Small Flat Rate Box,Priority Mail Medium Flat Rate Box,Priority Mail Large Flat Rate Box,Priority Mail Flat Rate Box,Priority Mail Flat Rate Envelope,Priority Mail International,Priority Mail International Flat Rate Box,Priority Mail International Flat Rate Envelope,Priority Mail International Small Flat Rate Box,Priority Mail International Medium Flat Rate Box,Priority Mail International Large Flat Rate Box,USPS GXG Envelopes usa/shipping_carrier_usps diff --git a/app/code/core/Mage/Usa/etc/system.xml b/app/code/core/Mage/Usa/etc/system.xml index b71f8c8b73..e262ba57f5 100644 --- a/app/code/core/Mage/Usa/etc/system.xml +++ b/app/code/core/Mage/Usa/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Usa/Model/Tax/Uszip.php b/app/code/core/Mage/Usa/sql/usa_setup/install-1.6.0.0.php similarity index 86% rename from app/code/core/Mage/Usa/Model/Tax/Uszip.php rename to app/code/core/Mage/Usa/sql/usa_setup/install-1.6.0.0.php index d4530697ea..24fbca59ca 100644 --- a/app/code/core/Mage/Usa/Model/Tax/Uszip.php +++ b/app/code/core/Mage/Usa/sql/usa_setup/install-1.6.0.0.php @@ -20,12 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - -class Mage_Usa_Tax_Uszipcode extends Mage_Sales_Model_Tax_Abstract -{ - -} diff --git a/app/code/core/Mage/Usa/sql/usa_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Usa/sql/usa_setup/mysql4-upgrade-0.7.0-0.7.1.php index 677ca8ad22..e8df0ee550 100644 --- a/app/code/core/Mage/Usa/sql/usa_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Usa/sql/usa_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Usa - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Block/Element/Weee/Tax.php b/app/code/core/Mage/Weee/Block/Element/Weee/Tax.php index 1316428c28..a83d7b2484 100644 --- a/app/code/core/Mage/Weee/Block/Element/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Block/Element/Weee/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php b/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php index 8ebd77ebf7..2e1c1f6eb1 100644 --- a/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Block/Renderer/Weee/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Helper/Data.php b/app/code/core/Mage/Weee/Helper/Data.php index d66ab73a62..2e63651966 100644 --- a/app/code/core/Mage/Weee/Helper/Data.php +++ b/app/code/core/Mage/Weee/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,9 +30,9 @@ class Mage_Weee_Helper_Data extends Mage_Core_Helper_Abstract { - const XML_PATH_FPT_ENABLED = 'tax/weee/enable'; + const XML_PATH_FPT_ENABLED = 'tax/weee/enable'; - protected $_storeDisplayConfig = array(); + protected $_storeDisplayConfig = array(); /** * Get weee amount display type on product view page diff --git a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php index 0e73eae13e..bd500378fe 100644 --- a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php @@ -20,12 +20,16 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Weee_Model_Attribute_Backend_Weee_Tax extends Mage_Catalog_Model_Product_Attribute_Backend_Price { + public static function getBackendModelName() + { + return 'weee/attribute_backend_weee_tax'; + } /** * Retrieve resource model * @@ -33,7 +37,7 @@ class Mage_Weee_Model_Attribute_Backend_Weee_Tax extends Mage_Catalog_Model_Prod */ protected function _getResource() { - return Mage::getResourceSingleton('weee/attribute_backend_weee_tax'); + return Mage::getResourceSingleton(self::getBackendModelName()); } /** @@ -145,3 +149,4 @@ public function getTable() return $this->_getResource()->getTable('weee/tax'); } } + diff --git a/app/code/core/Mage/Weee/Model/Config/Source/Display.php b/app/code/core/Mage/Weee/Model/Config/Source/Display.php index 078b8f9469..d8a2fd4230 100644 --- a/app/code/core/Mage/Weee/Model/Config/Source/Display.php +++ b/app/code/core/Mage/Weee/Model/Config/Source/Display.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Weee_Model_Config_Source_Display diff --git a/app/code/core/Mage/Weee/Model/Mysql4/Attribute/Backend/Weee/Tax.php b/app/code/core/Mage/Weee/Model/Mysql4/Attribute/Backend/Weee/Tax.php index d185d6d733..38c29cf93d 100644 --- a/app/code/core/Mage/Weee/Model/Mysql4/Attribute/Backend/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Model/Mysql4/Attribute/Backend/Weee/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,63 +28,10 @@ /** * Catalog product WEEE tax backend attribute model * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_Weee * @author Magento Core Team */ - -class Mage_Weee_Model_Mysql4_Attribute_Backend_Weee_Tax extends Mage_Core_Model_Mysql4_Abstract +class Mage_Weee_Model_Mysql4_Attribute_Backend_Weee_Tax extends Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax { - protected function _construct() - { - $this->_init('weee/tax', 'value_id'); - } - - public function loadProductData($product, $attribute) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), array( - 'website_id', - 'country', - 'state', - 'value' - )) - ->where('entity_id=?', $product->getId()) - ->where('attribute_id=?', $attribute->getId()); - if ($attribute->isScopeGlobal()) { - $select->where('website_id=?', 0); - } - else { - if ($storeId = $product->getStoreId()) { - $select->where('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId())); - } - } - return $this->_getReadAdapter()->fetchAll($select); - } - - public function deleteProductData($product, $attribute) - { - $condition = array(); - - if (!$attribute->isScopeGlobal()) { - if ($storeId = $product->getStoreId()) { - $condition[] = $this->_getWriteAdapter()->quoteInto('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId())); - } - } - - $condition[] = $this->_getWriteAdapter()->quoteInto('entity_id=?', $product->getId()); - $condition[] = $this->_getWriteAdapter()->quoteInto('attribute_id=?', $attribute->getId()); - - $this->_getWriteAdapter()->delete($this->getMainTable(), implode(' AND ', $condition)); - return $this; - } - - public function insertProductData($product, $data) - { - $data['entity_id'] = $product->getId(); - $data['entity_type_id'] = $product->getEntityTypeId(); - - $this->_getWriteAdapter()->insert($this->getMainTable(), $data); - return $this; - } } diff --git a/app/code/core/Mage/Weee/Model/Mysql4/Setup.php b/app/code/core/Mage/Weee/Model/Mysql4/Setup.php index 10b389b44b..a9348617c0 100644 --- a/app/code/core/Mage/Weee/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/Weee/Model/Mysql4/Setup.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,10 +28,10 @@ /** * Weee tax setup * - * @category Mage - * @package Mage_Weee - * @author Magento Core Team + * @category Mage + * @package Mage_Weee + * @author Magento Core Team */ -class Mage_Weee_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup +class Mage_Weee_Model_Mysql4_Setup extends Mage_Weee_Model_Resource_Setup { } diff --git a/app/code/core/Mage/Weee/Model/Mysql4/Tax.php b/app/code/core/Mage/Weee/Model/Mysql4/Tax.php index cb57fe391e..b11f64bc9f 100644 --- a/app/code/core/Mage/Weee/Model/Mysql4/Tax.php +++ b/app/code/core/Mage/Weee/Model/Mysql4/Tax.php @@ -20,120 +20,18 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_Weee_Model_Mysql4_Tax extends Mage_Core_Model_Mysql4_Abstract -{ - protected function _construct() - { - $this->_init('weee/tax', 'value_id'); - } - - public function fetchOne($select) - { - return $this->_getReadAdapter()->fetchOne($select); - } - - public function fetchCol($select) - { - return $this->_getReadAdapter()->fetchCol($select); - } - - public function updateDiscountPercents() - { - return $this->_updateDiscountPercents(); - } - - public function updateProductsDiscountPercent($condition) - { - return $this->_updateDiscountPercents($condition); - } - - /** - * Update tax percents for WEEE based on products condition - * - * @param mixed $productCondition - * @return Mage_Weee_Model_Mysql4_Tax - */ - protected function _updateDiscountPercents($productCondition = null) - { - $now = strtotime(now()); - - $select = $this->_getReadAdapter()->select(); - $select->from(array('data'=>$this->getTable('catalogrule/rule_product'))); - - $deleteCondition = ''; - if ($productCondition) { - if ($productCondition instanceof Mage_Catalog_Model_Product) { - $select->where('product_id=?', $productCondition->getId()); - $deleteCondition = $this->_getWriteAdapter()->quoteInto('entity_id=?', $productCondition->getId()); - } elseif ($productCondition instanceof Mage_Catalog_Model_Product_Condition_Interface) { - $productCondition = $productCondition->getIdsSelect($this->_getWriteAdapter())->__toString(); - $select->where('product_id IN ('.$productCondition.')'); - $deleteCondition = 'entity_id IN ('.$productCondition.')'; - } else { - $select->where('product_id=?', $productCondition); - $deleteCondition = $this->_getWriteAdapter()->quoteInto('entity_id=?', $productCondition); - } - } else { - $select->where('(from_time <= ? OR from_time = 0)', $now) - ->where('(to_time >= ? OR to_time = 0)', $now); - } - $this->_getWriteAdapter()->delete($this->getTable('weee/discount'), $deleteCondition); - - $select->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order')); - - $data = $this->_getReadAdapter()->query($select); - $productData = array(); - $stops = array(); - $prevKey = false; - while ($row = $data->fetch()) { - $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}"; - if (isset($stops[$key]) && $stops[$key]) { - continue; - } - - if ($prevKey && ($prevKey != $key)) { - foreach ($productData as $product) { - $this->_getWriteAdapter()->insert($this->getTable('weee/discount'), $product); - } - $productData = array(); - } - if ($row['action_operator'] == 'by_percent') { - if (isset($productData[$key])) { - $productData[$key]['value'] -= $productData[$key]['value']/100*$row['action_amount']; - } else { - $productData[$key] = array( - 'entity_id' => $row['product_id'], - 'customer_group_id' => $row['customer_group_id'], - 'website_id' => $row['website_id'], - 'value' => 100-max(0, min(100, $row['action_amount'])), - ); - } - } - - if ($row['action_stop']) { - $stops[$key] = true; - } - $prevKey = $key; - } - foreach ($productData as $product) { - $this->_getWriteAdapter()->insert($this->getTable('weee/discount'), $product); - } - return $this; - } - - public function getProductDiscountPercent($product, $website, $group) - { - $select = $this->_getReadAdapter()->select(); - $select->from($this->getTable('weee/discount'), 'value') - ->where('website_id = ?', $website) - ->where('entity_id = ?', $product) - ->where('customer_group_id = ?', $group); - - return $this->_getReadAdapter()->fetchOne($select); - } +/** + * Enter description here ... + * + * @category Mage + * @package Mage_Weee + * @author Magento Core Team + */ +class Mage_Weee_Model_Mysql4_Tax extends Mage_Weee_Model_Resource_Tax +{ } diff --git a/app/code/core/Mage/Weee/Model/Observer.php b/app/code/core/Mage/Weee/Model/Observer.php index 7930f367a8..1921d0ddd2 100644 --- a/app/code/core/Mage/Weee/Model/Observer.php +++ b/app/code/core/Mage/Weee/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,13 +30,14 @@ class Mage_Weee_Model_Observer extends Mage_Core_Model_Abstract * Assign custom renderer for product create/edit form weee attribute element * * @param Varien_Event_Observer $observer + * @return Mage_Weee_Model_Observer */ public function setWeeeRendererInForm(Varien_Event_Observer $observer) { //adminhtml_catalog_product_edit_prepare_form $form = $observer->getEvent()->getForm(); - $product = $observer->getEvent()->getProduct(); +// $product = $observer->getEvent()->getProduct(); $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true); foreach ($attributes as $code) { @@ -46,34 +47,40 @@ public function setWeeeRendererInForm(Varien_Event_Observer $observer) ); } } + + return $this; } /** * Exclude WEEE attributes from standard form generation * * @param Varien_Event_Observer $observer + * @return Mage_Weee_Model_Observer */ public function updateExcludedFieldList(Varien_Event_Observer $observer) { //adminhtml_catalog_product_form_prepare_excluded_field_list - $block = $observer->getEvent()->getObject(); - $list = $block->getFormExcludedFieldList(); + $block = $observer->getEvent()->getObject(); + $list = $block->getFormExcludedFieldList(); $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(true); - foreach ($attributes as $code) { - $list[] = $code; - } + $list = array_merge($list, array_values($attributes)); + $block->setFormExcludedFieldList($list); + + return $this; } /** * Add additional price calculation to select object which is using for select indexed data * * @param Varien_Event_Observer $observer + * @return Mage_Weee_Model_Observer */ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer) { - if (!Mage::helper('weee')->isEnabled($observer->getEvent()->getStoreId())) { + $storeId = (int)$observer->getEvent()->getStoreId(); + if (!Mage::helper('weee')->isEnabled($storeId)) { return $this; } @@ -83,73 +90,74 @@ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer) return $this; } + /** @var $select Varien_Db_Select */ $select = $observer->getEvent()->getSelect(); $table = $observer->getEvent()->getTable(); - $storeId= $observer->getEvent()->getStoreId(); - $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); - - $response = $observer->getEvent()->getResponseObject(); + $websiteId = (int)Mage::app()->getStore($storeId)->getWebsiteId(); + $customerGroupId = (int)Mage::getSingleton('customer/session')->getCustomerGroupId(); + $response = $observer->getEvent()->getResponseObject(); $additionalCalculations = $response->getAdditionalCalculations(); $attributes = Mage::getSingleton('weee/tax')->getWeeeAttributeCodes(); + if ($attributes && Mage::helper('weee')->isDiscounted()) { - $discountField = 'IFNULL(_discount_percent.value, 0)'; $joinConditions = array( - "_discount_percent.entity_id = {$table}.entity_id", - "_discount_percent.website_id = '{$websiteId}'", - "_discount_percent.customer_group_id = '{$customerGroupId}'", + "discount_percent.entity_id = {$table}.entity_id", + $select->getAdapter()->quoteInto('discount_percent.website_id = ?', $websiteId), + $select->getAdapter()->quoteInto('discount_percent.customer_group_id = ?', $customerGroupId) ); $tableWeeDiscount = Mage::getSingleton('weee/tax')->getResource()->getTable('weee/discount'); $select->joinLeft( - array('_discount_percent' => $tableWeeDiscount), implode(' AND ', $joinConditions), array()); + array('discount_percent' => $tableWeeDiscount), + implode(' AND ', $joinConditions), + array() + ); } + $checkDiscountField = $select->getAdapter()->getCheckSql('discount_percent.value IS NULL', 0, 'discount_percent.value'); foreach ($attributes as $attribute) { - $tableAlias = "weee_{$attribute}_table"; - + $fieldAlias = sprintf('weee_%s_table.value', $attribute); + $checkAdditionalCalculation = $select->getAdapter()->getCheckSql("{$fieldAlias} IS NULL", 0, $fieldAlias); if (Mage::helper('weee')->isDiscounted()) { - $additionalCalculations[] = "+(IFNULL({$tableAlias}.value, 0)*(1-({$discountField}/100)))"; + $additionalCalculations[] = sprintf('+(%s*(1-(%s/100))', $checkAdditionalCalculation, $checkDiscountField); } else { - $additionalCalculations[] = "+(IFNULL({$tableAlias}.value, 0))"; + $additionalCalculations[] = "+($checkAdditionalCalculation)"; } } $response->setAdditionalCalculations($additionalCalculations); + /** @var $rateRequest Varien_Object */ $rateRequest = Mage::getSingleton('tax/calculation')->getRateRequest(); - $attributes = Mage::getSingleton('weee/tax')->getWeeeTaxAttributeCodes(); + $attributes = Mage::getSingleton('weee/tax')->getWeeeTaxAttributeCodes(); foreach ($attributes as $attribute) { - $attributeId = Mage::getSingleton('eav/entity_attribute')->getIdByCode('catalog_product', $attribute); - - $tableAlias = "weee_{$attribute}_table"; - $on = array(); - $on[] = "{$tableAlias}.attribute_id = '{$attributeId}'"; - $on[] = "({$tableAlias}.website_id in ('{$websiteId}', 0))"; - - $country = $rateRequest->getCountryId(); - $on[] = "({$tableAlias}.country = '{$country}')"; - - $region = $rateRequest->getRegionId(); - $on[] = "({$tableAlias}.state in ('{$region}', '*'))"; - - $attributeSelect = $this->_getSelect(); - $attributeSelect->from(array( - $tableAlias => Mage::getSingleton('weee/tax')->getResource()->getTable('weee/tax'))); - - - foreach ($on as $one) { - $attributeSelect->where($one); - } - $attributeSelect->limit(1); - - $order = array($tableAlias . '.state DESC', $tableAlias . '.website_id DESC'); - + $attributeId = (int)Mage::getSingleton('eav/entity_attribute')->getIdByCode(Mage_Catalog_Model_Product::ENTITY, $attribute); + $tableAlias = sprintf('weee_%s_table', $attribute); + $quotedTableAlias = $select->getAdapter()->quoteTableAs($tableAlias, null); + $attributeSelect = $this->_getSelect(); + $attributeSelect + ->from(array($tableAlias => Mage::getSingleton('weee/tax')->getResource()->getTable('weee/tax'))) + ->where("{$quotedTableAlias}.attribute_id = ?", $attributeId) + ->where("{$quotedTableAlias}.website_id IN(?)", array($websiteId, 0)) + ->where("{$quotedTableAlias}.country = ?", $rateRequest->getCountryId()) + ->where("{$quotedTableAlias}.state IN(?)", array($rateRequest->getRegionId(), '*')) + ->limit(1); + + $order = array( + sprintf('%s.state %s', $tableAlias, Varien_Db_Select::SQL_DESC), + sprintf('%s.website_id %s', $tableAlias, Varien_Db_Select::SQL_DESC) + ); $attributeSelect->order($order); - $select->joinLeft(array( - $tableAlias => $attributeSelect), $table . '.entity_id = ' . $tableAlias . '.entity_id', array()); + + $joinCondition = sprintf('%s.entity_id = %s.entity_id', $table, $quotedTableAlias); + $select->joinLeft( + array($tableAlias => $attributeSelect), + $joinCondition, + array() + ); } + return $this; } /** @@ -166,6 +174,7 @@ protected function _getSelect() * Add new attribute type to manage attributes interface * * @param Varien_Event_Observer $observer + * @return Mage_Weee_Model_Observer */ public function addWeeeTaxAttributeType(Varien_Event_Observer $observer) { @@ -187,28 +196,32 @@ public function addWeeeTaxAttributeType(Varien_Event_Observer $observer) '_front_fieldset', ), 'disabled_types' => array( - 'grouped', + Mage_Catalog_Model_Product_Type::TYPE_GROUPED, ) ); $response->setTypes($types); + + return $this; } /** * Automaticaly assign backend model to weee attributes * * @param Varien_Event_Observer $observer + * @return Mage_Weee_Model_Observer */ public function assignBackendModelToAttribute(Varien_Event_Observer $observer) { - $backendModel = 'weee/attribute_backend_weee_tax'; + $backendModel = Mage_Weee_Model_Attribute_Backend_Weee_Tax::getBackendModelName(); + /** @var $object Mage_Eav_Model_Entity_Attribute_Abstract */ $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { - if ($option['value'] == 'grouped') { + if ($option['value'] == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { continue; } $applyTo[] = $option['value']; @@ -216,6 +229,8 @@ public function assignBackendModelToAttribute(Varien_Event_Observer $observer) $object->setApplyTo($applyTo); } } + + return $this; } /** @@ -226,7 +241,7 @@ public function assignBackendModelToAttribute(Varien_Event_Observer $observer) public function updateElementTypes(Varien_Event_Observer $observer) { $response = $observer->getEvent()->getResponse(); - $types = $response->getTypes(); + $types = $response->getTypes(); $types['weee'] = Mage::getConfig()->getBlockClassName('weee/element_weee_tax'); $response->setTypes($types); return $this; @@ -244,12 +259,14 @@ public function updateDiscountPercents(Varien_Event_Observer $observer) return $this; } - $eventProduct = $observer->getEvent()->getProduct(); $productCondition = $observer->getEvent()->getProductCondition(); if ($productCondition) { $eventProduct = $productCondition; + } else { + $eventProduct = $observer->getEvent()->getProduct(); } Mage::getModel('weee/tax')->updateProductsDiscountPercent($eventProduct); + return $this; } @@ -266,7 +283,7 @@ public function updateCofigurableProductOptions(Varien_Event_Observer $observer) } $response = $observer->getEvent()->getResponseObject(); - $options = $response->getAdditionalOptions(); + $options = $response->getAdditionalOptions(); $_product = Mage::registry('current_product'); if (!$_product) { @@ -275,7 +292,7 @@ public function updateCofigurableProductOptions(Varien_Event_Observer $observer) if (!Mage::helper('weee')->typeOfDisplay($_product, array(0, 1, 4))) { return $this; } - $amount = Mage::helper('weee')->getAmount($_product); + $amount = Mage::helper('weee')->getAmount($_product); $origAmount = Mage::helper('weee')->getOriginalAmount($_product); $options['oldPlusDisposition'] = $origAmount; @@ -319,3 +336,4 @@ public function updateBundleProductOptions(Varien_Event_Observer $observer) return $this; } } + diff --git a/app/code/core/Mage/Weee/Model/Resource/Attribute/Backend/Weee/Tax.php b/app/code/core/Mage/Weee/Model/Resource/Attribute/Backend/Weee/Tax.php new file mode 100755 index 0000000000..4fbe732049 --- /dev/null +++ b/app/code/core/Mage/Weee/Model/Resource/Attribute/Backend/Weee/Tax.php @@ -0,0 +1,116 @@ + + */ +class Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Defines main resource table and table identifier field + * + */ + protected function _construct() + { + $this->_init('weee/tax', 'value_id'); + } + + /** + * Load product data + * + * @param Mage_Catalog_Model_Product $product + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return array + */ + public function loadProductData($product, $attribute) + { + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), array( + 'website_id', + 'country', + 'state', + 'value' + )) + ->where('entity_id = ?', (int)$product->getId()) + ->where('attribute_id = ?', (int)$attribute->getId()); + if ($attribute->isScopeGlobal()) { + $select->where('website_id = ?', 0); + } else { + $storeId = $product->getStoreId(); + if ($storeId) { + $select->where('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId())); + } + } + return $this->_getReadAdapter()->fetchAll($select); + } + + /** + * Delete product data + * + * @param Mage_Catalog_Model_Product $product + * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute + * @return Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax + */ + public function deleteProductData($product, $attribute) + { + $where = array( + 'entity_id = ?' => (int)$product->getId(), + 'attribute_id = ?' => (int)$attribute->getId() + ); + + $adapter = $this->_getWriteAdapter(); + if (!$attribute->isScopeGlobal()) { + $storeId = $product->getStoreId(); + if ($storeId) { + $where['website_id IN(?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId()); + } + } + $adapter->delete($this->getMainTable(), $where); + return $this; + } + + /** + * Insert product data + * + * @param Mage_Catalog_Model_Product $product + * @param array $data + * @return Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax + */ + public function insertProductData($product, $data) + { + $data['entity_id'] = (int)$product->getId(); + $data['entity_type_id'] = (int)$product->getEntityTypeId(); + + $this->_getWriteAdapter()->insert($this->getMainTable(), $data); + return $this; + } +} + diff --git a/app/code/core/Mage/Weee/Model/Resource/Setup.php b/app/code/core/Mage/Weee/Model/Resource/Setup.php new file mode 100755 index 0000000000..d736d91468 --- /dev/null +++ b/app/code/core/Mage/Weee/Model/Resource/Setup.php @@ -0,0 +1,37 @@ + + */ +class Mage_Weee_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup +{ +} diff --git a/app/code/core/Mage/Weee/Model/Resource/Tax.php b/app/code/core/Mage/Weee/Model/Resource/Tax.php new file mode 100755 index 0000000000..fe599ce36d --- /dev/null +++ b/app/code/core/Mage/Weee/Model/Resource/Tax.php @@ -0,0 +1,185 @@ + + */ +class Mage_Weee_Model_Resource_Tax extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Resource initialization + * + */ + protected function _construct() + { + $this->_init('weee/tax', 'value_id'); + } + + /** + * Fetch one + * + * @param Varien_Db_Select|string $select + * @return string + */ + public function fetchOne($select) + { + return $this->_getReadAdapter()->fetchOne($select); + } + + /** + * Fetch column + * + * @param Varien_Db_Select|string $select + * @return array + */ + public function fetchCol($select) + { + return $this->_getReadAdapter()->fetchCol($select); + } + + /** + * Update discount percents + * + * @return Mage_Weee_Model_Resource_Tax + */ + public function updateDiscountPercents() + { + return $this->_updateDiscountPercents(); + } + + /** + * Update products discount persent + * + * @param mixed $condition + * @return Mage_Weee_Model_Resource_Tax + */ + public function updateProductsDiscountPercent($condition) + { + return $this->_updateDiscountPercents($condition); + } + + /** + * Update tax percents for WEEE based on products condition + * + * @param mixed $productCondition + * @return Mage_Weee_Model_Resource_Tax + */ + protected function _updateDiscountPercents($productCondition = null) + { + $now = Varien_Date::toTimestamp(Varien_Date::now()); + $adapter = $this->_getWriteAdapter(); + + $select = $this->_getReadAdapter()->select(); + $select->from(array('data' => $this->getTable('catalogrule/rule_product'))); + + $deleteCondition = ''; + if ($productCondition) { + if ($productCondition instanceof Mage_Catalog_Model_Product) { + $select->where('product_id = ?', (int)$productCondition->getId()); + $deleteCondition = $adapter->quoteInto('entity_id=?', (int)$productCondition->getId()); + } elseif ($productCondition instanceof Mage_Catalog_Model_Product_Condition_Interface) { + $productCondition = $productCondition->getIdsSelect($adapter)->__toString(); + $select->where("product_id IN ({$productCondition})"); + $deleteCondition = "entity_id IN ({$productCondition})"; + } else { + $select->where('product_id = ?', (int)$productCondition); + $deleteCondition = $adapter->quoteInto('entity_id = ?', (int)$productCondition); + } + } else { + $select->where('(from_time <= ? OR from_time = 0)', $now) + ->where('(to_time >= ? OR to_time = 0)', $now); + } + $adapter->delete($this->getTable('weee/discount'), $deleteCondition); + + $select->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order')); + + $data = $this->_getReadAdapter()->query($select); + + $productData = array(); + $stops = array(); + $prevKey = false; + while ($row = $data->fetch()) { + $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}"; + if (isset($stops[$key]) && $stops[$key]) { + continue; + } + + if ($prevKey && ($prevKey != $key)) { + foreach ($productData as $product) { + $adapter->insert($this->getTable('weee/discount'), $product); + } + $productData = array(); + } + if ($row['action_operator'] == 'by_percent') { + if (isset($productData[$key])) { + $productData[$key]['value'] -= $productData[$key]['value']/100*$row['action_amount']; + } else { + $productData[$key] = array( + 'entity_id' => $row['product_id'], + 'customer_group_id' => $row['customer_group_id'], + 'website_id' => $row['website_id'], + 'value' => 100-max(0, min(100, $row['action_amount'])), + ); + } + } + + if ($row['action_stop']) { + $stops[$key] = true; + } + $prevKey = $key; + } + foreach ($productData as $product) { + $adapter->insert($this->getTable('weee/discount'), $product); + } + + return $this; + } + + /** + * Retrieve product discount percent + * + * @param int $productId + * @param int $websiteId + * @param int $customerGroupId + * @return string + */ + public function getProductDiscountPercent($productId, $websiteId, $customerGroupId) + { + $select = $this->_getReadAdapter()->select(); + $select->from($this->getTable('weee/discount'), 'value') + ->where('website_id = ?', (int)$websiteId) + ->where('entity_id = ?', (int)$productId) + ->where('customer_group_id = ?', (int)$customerGroupId); + + return $this->_getReadAdapter()->fetchOne($select); + } +} + diff --git a/app/code/core/Mage/Weee/Model/Tax.php b/app/code/core/Mage/Weee/Model/Tax.php index b24f7887d6..aba12e0126 100644 --- a/app/code/core/Mage/Weee/Model/Tax.php +++ b/app/code/core/Mage/Weee/Model/Tax.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -55,10 +55,23 @@ protected function _construct() } - public function getWeeeAmount($product, $shipping = null, $billing = null, $website = null, $calculateTax = false, $ignoreDiscount = false) + public function getWeeeAmount( + $product, + $shipping = null, + $billing = null, + $website = null, + $calculateTax = false, + $ignoreDiscount = false) { $amount = 0; - $attributes = $this->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTax, $ignoreDiscount); + $attributes = $this->getProductWeeeAttributes( + $product, + $shipping, + $billing, + $website, + $calculateTax, + $ignoreDiscount + ); foreach ($attributes as $attribute) { $amount += $attribute->getAmount(); } @@ -70,6 +83,12 @@ public function getWeeeAttributeCodes($forceEnabled = false) return $this->getWeeeTaxAttributeCodes($forceEnabled); } + /** + * Retrieve Wee tax attribute codes + * + * @param bool $forceEnabled + * @return array + */ public function getWeeeTaxAttributeCodes($forceEnabled = false) { if (!$forceEnabled && !Mage::helper('weee')->isEnabled()) { @@ -82,7 +101,13 @@ public function getWeeeTaxAttributeCodes($forceEnabled = false) return $this->_allAttributes; } - public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $ignoreDiscount = false) + public function getProductWeeeAttributes( + $product, + $shipping = null, + $billing = null, + $website = null, + $calculateTax = null, + $ignoreDiscount = false) { $result = array(); $allWeee = $this->getWeeeTaxAttributeCodes(); @@ -114,32 +139,22 @@ public function getProductWeeeAttributes($product, $shipping = null, $billing = } $productAttributes = $product->getTypeInstance(true)->getSetAttributes($product); - foreach ($productAttributes as $code=>$attribute) { + foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { - $attributeId = $attribute->getId(); $attributeSelect = $this->getResource()->getReadConnection()->select(); - $attributeSelect->from($this->getResource()->getTable('weee/tax'), 'value'); - - $on = array(); - $on[] = "attribute_id = '{$attributeId}'"; - $on[] = "(website_id in ('{$websiteId}', 0))"; - - $country = $rateRequest->getCountryId(); - $on[] = "(country = '{$country}')"; - - $region = $rateRequest->getRegionId(); - $on[] = "(state in ('{$region}', '*'))"; - - foreach ($on as $one) { - $attributeSelect->where($one); - } - $attributeSelect->where('entity_id = ?', $product->getId()); - $attributeSelect->limit(1); - - $order = array('state DESC', 'website_id DESC'); - + $attributeSelect + ->from($this->getResource()->getTable('weee/tax'), 'value') + ->where('attribute_id = ?', (int)$attribute->getId()) + ->where('website_id IN(?)', array($websiteId, 0)) + ->where('country = ?', $rateRequest->getCountryId()) + ->where('state IN(?)', array($rateRequest->getRegionId(), '*')) + ->where('entity_id = ?', (int)$product->getId()) + ->limit(1); + + $order = array('state ' . Varien_Db_Select::SQL_DESC, 'website_id ' . Varien_Db_Select::SQL_DESC); $attributeSelect->order($order); + $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { if ($discountPercent) { @@ -147,12 +162,14 @@ public function getProductWeeeAttributes($product, $shipping = null, $billing = } $taxAmount = $amount = 0; - $amount = $value; + $amount = $value; /** * We can't use FPT imcluding/excluding tax */ // if ($calculateTax && Mage::helper('weee')->isTaxable($store)) { -// $defaultPercent = Mage::getModel('tax/calculation')->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); +// $defaultPercent = Mage::getModel('tax/calculation') +// ->getRate($defaultRateRequest +// ->setProductClassId($product->getTaxClassId())); // $currentPercent = $product->getTaxPercent(); // // $taxAmount = Mage::app()->getStore()->roundPrice($value/(100+$defaultPercent)*$currentPercent); @@ -178,7 +195,8 @@ protected function _getDiscountPercentForProduct($product) $group = Mage::getSingleton('customer/session')->getCustomerGroupId(); $key = implode('-', array($website, $group, $product->getId())); if (!isset($this->_productDiscounts[$key])) { - $this->_productDiscounts[$key] = (int) $this->getResource()->getProductDiscountPercent($product->getId(), $website, $group); + $this->_productDiscounts[$key] = (int) $this->getResource() + ->getProductDiscountPercent($product->getId(), $website, $group); } if ($value = $this->_productDiscounts[$key]) { return 100-min(100, max(0, $value)); diff --git a/app/code/core/Mage/Weee/Model/Total/Creditmemo/Weee.php b/app/code/core/Mage/Weee/Model/Total/Creditmemo/Weee.php index e010893a89..71bc49fbb9 100644 --- a/app/code/core/Mage/Weee/Model/Total/Creditmemo/Weee.php +++ b/app/code/core/Mage/Weee/Model/Total/Creditmemo/Weee.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Model/Total/Invoice/Weee.php b/app/code/core/Mage/Weee/Model/Total/Invoice/Weee.php index e11f12699f..6b0827cd24 100644 --- a/app/code/core/Mage/Weee/Model/Total/Invoice/Weee.php +++ b/app/code/core/Mage/Weee/Model/Total/Invoice/Weee.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Model/Total/Quote/Nominal/Weee.php b/app/code/core/Mage/Weee/Model/Total/Quote/Nominal/Weee.php index 3397b23eb1..bd99fbea00 100644 --- a/app/code/core/Mage/Weee/Model/Total/Quote/Nominal/Weee.php +++ b/app/code/core/Mage/Weee/Model/Total/Quote/Nominal/Weee.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php b/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php index 6ec909bfe2..a09a376fea 100644 --- a/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php +++ b/app/code/core/Mage/Weee/Model/Total/Quote/Weee.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/etc/config.xml b/app/code/core/Mage/Weee/etc/config.xml index aaf68f5b2c..848d22bb9b 100644 --- a/app/code/core/Mage/Weee/etc/config.xml +++ b/app/code/core/Mage/Weee/etc/config.xml @@ -21,40 +21,47 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.13 + 1.6.0.0 Mage_Weee_Model - weee_mysql4 + weee_resource - - Mage_Weee_Model_Mysql4 + + Mage_Weee_Model_Resource + weee_mysql4 - weee_tax
      - weee_discount
      + + weee_tax
      +
      + + weee_discount
      +
      -
      +
      Mage_Weee - Mage_Weee_Model_Mysql4_Setup + Mage_Weee_Model_Resource_Setup - Mage_Weee_Block + + Mage_Weee_Block + @@ -130,7 +137,6 @@ * - * @@ -170,7 +176,6 @@ - @@ -205,9 +210,19 @@ + + + base_weee_tax_applied_row_amnt + + + base_weee_tax_applied_row_amnt + + + base_weee_tax_applied_row_amnt + +
      - @@ -245,7 +260,6 @@ - @@ -272,12 +286,13 @@ - - - weee.xml - + + + weee.xml + +
      diff --git a/app/code/core/Mage/Weee/etc/system.xml b/app/code/core/Mage/Weee/etc/system.xml index 759712ead6..113094e5d8 100644 --- a/app/code/core/Mage/Weee/etc/system.xml +++ b/app/code/core/Mage/Weee/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Weee/sql/weee_setup/install-1.6.0.0.php b/app/code/core/Mage/Weee/sql/weee_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..a7434f6282 --- /dev/null +++ b/app/code/core/Mage/Weee/sql/weee_setup/install-1.6.0.0.php @@ -0,0 +1,174 @@ +getConnection() + ->newTable($installer->getTable('weee/tax')) + ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'nullable' => false, + 'primary' => true, + ), 'Value Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website Id') + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('country', Varien_Db_Ddl_Table::TYPE_TEXT, 2, array( + 'nullable' => true, + ), 'Country') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Value') + ->addColumn('state', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '*', + ), 'State') + ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Attribute Id') + ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Entity Type Id') + ->addIndex($installer->getIdxName('weee/tax', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('weee/tax', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('weee/tax', array('country')), + array('country')) + ->addIndex($installer->getIdxName('weee/tax', array('attribute_id')), + array('attribute_id')) + ->addForeignKey($installer->getFkName('weee/tax', 'country', 'directory/country', 'country_id'), + 'country', $installer->getTable('directory/country'), 'country_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('weee/tax', 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('weee/tax', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('weee/tax', 'attribute_id', 'eav/attribute', 'attribute_id'), + 'attribute_id', $installer->getTable('eav/attribute'), 'attribute_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Weee Tax'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'weee/discount' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('weee/discount')) + ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Entity Id') + ->addColumn('website_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Website Id') + ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Customer Group Id') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + 'default' => '0.0000', + ), 'Value') + ->addIndex($installer->getIdxName('weee/discount', array('website_id')), + array('website_id')) + ->addIndex($installer->getIdxName('weee/discount', array('entity_id')), + array('entity_id')) + ->addIndex($installer->getIdxName('weee/discount', array('customer_group_id')), + array('customer_group_id')) + ->addForeignKey($installer->getFkName('weee/discount', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + 'customer_group_id', $installer->getTable('customer/customer_group'), 'customer_group_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('weee/discount', 'entity_id', 'catalog/product', 'entity_id'), + 'entity_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('weee/discount', 'website_id', 'core/website', 'website_id'), + 'website_id', $installer->getTable('core/website'), 'website_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Weee Discount'); +$installer->getConnection()->createTable($table); + +$installer->addAttribute('order_item', 'base_weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'base_weee_tax_applied_row_amnt', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'weee_tax_applied_row_amount', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'weee_tax_applied', array('type'=>'text')); + +$installer->addAttribute('quote_item', 'weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'weee_tax_row_disposition', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'base_weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'base_weee_tax_row_disposition', array('type'=>'decimal')); + +$installer->addAttribute('order_item', 'weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'weee_tax_row_disposition', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'base_weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('order_item', 'base_weee_tax_row_disposition', array('type'=>'decimal')); + +$installer->addAttribute('invoice_item', 'base_weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'base_weee_tax_applied_row_amnt', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'weee_tax_applied_row_amount', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'weee_tax_applied', array('type'=>'text')); +$installer->addAttribute('invoice_item', 'weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'weee_tax_row_disposition', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'base_weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('invoice_item', 'base_weee_tax_row_disposition', array('type'=>'decimal')); + +$installer->addAttribute('quote_item', 'weee_tax_applied', array('type'=>'text')); +$installer->addAttribute('quote_item', 'weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'weee_tax_applied_row_amount', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'base_weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('quote_item', 'base_weee_tax_applied_row_amnt', array('type'=>'decimal')); + +$installer->addAttribute('creditmemo_item', 'weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'weee_tax_row_disposition', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'base_weee_tax_disposition', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'base_weee_tax_row_disposition', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'weee_tax_applied', array('type'=>'text')); +$installer->addAttribute('creditmemo_item', 'base_weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'base_weee_tax_applied_row_amnt', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'weee_tax_applied_amount', array('type'=>'decimal')); +$installer->addAttribute('creditmemo_item', 'weee_tax_applied_row_amount', array('type'=>'decimal')); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-install-0.1.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-install-0.1.php index 9143f63440..ae0fc4a826 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-install-0.1.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-install-0.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.1-0.2.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.1-0.2.php index 043c6cd76a..592bbfba7d 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.1-0.2.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.1-0.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.10-0.11.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.10-0.11.php index f864ff856e..87af06a333 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.10-0.11.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.10-0.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.11-0.12.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.11-0.12.php index 075b15d4b6..0706ec9337 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.11-0.12.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.11-0.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.12-0.13.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.12-0.13.php index 7b4b72f874..40fe1386ca 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.12-0.13.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.12-0.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.2-0.3.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.2-0.3.php index 62e9938943..f6d388050a 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.2-0.3.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.2-0.3.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.3-0.4.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.3-0.4.php index 9ebf206236..661052cfb3 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.3-0.4.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.3-0.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.4-0.5.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.4-0.5.php index 49c73583ac..aedfb8856b 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.4-0.5.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.4-0.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.5-0.6.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.5-0.6.php index ec4ebeb307..610ea31632 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.5-0.6.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.5-0.6.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.6-0.7.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.6-0.7.php index dac2e7afcc..a9043165bb 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.6-0.7.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.6-0.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.7-0.8.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.7-0.8.php index 87d0870e29..9f24169d69 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.7-0.8.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.7-0.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.8-0.9.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.8-0.9.php index 6fa7213207..80c101cc61 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.8-0.9.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.8-0.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.9-0.10.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.9-0.10.php index 3f9a1d044f..842d7e8149 100644 --- a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.9-0.10.php +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-0.9-0.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..e035854ff1 --- /dev/null +++ b/app/code/core/Mage/Weee/sql/weee_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,564 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_GROUP' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_COUNTRY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_WEBSITE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('weee/tax'), + 'FK_WEEE_TAX_ATTRIBUTE_ID' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/discount'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_GROUP' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_WEBSITE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_PRODUCT_ENTITY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/tax'), + 'FK_CATALOG_PRODUCT_ENTITY_WEEE_TAX_COUNTRY' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('weee/tax'), + 'FK_WEEE_TAX_ATTRIBUTE_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('weee/tax') => array( + 'columns' => array( + 'value_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Value Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Id' + ), + 'country' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 2, + 'comment' => 'Country' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Value' + ), + 'state' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => '*', + 'comment' => 'State' + ), + 'attribute_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Attribute Id' + ), + 'entity_type_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Entity Type Id' + ) + ), + 'comment' => 'Weee Tax' + ), + $installer->getTable('weee/discount') => array( + 'columns' => array( + 'entity_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Entity Id' + ), + 'website_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Website Id' + ), + 'customer_group_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Customer Group Id' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'default' => '0.0000', + 'comment' => 'Value' + ) + ), + 'comment' => 'Weee Discount' + ), + $installer->getTable('sales/order_item') => array( + 'columns' => array( + 'weee_tax_applied' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Weee Tax Applied' + ), + 'weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Amount' + ), + 'weee_tax_applied_row_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Row Amount' + ), + 'base_weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Amount' + ), + 'weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Disposition' + ), + 'weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Row Disposition' + ), + 'base_weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Disposition' + ), + 'base_weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Row Disposition' + ) + ) + ), + $installer->getTable('sales/quote_item') => array( + 'columns' => array( + 'weee_tax_applied' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Weee Tax Applied' + ), + 'weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Amount' + ), + 'weee_tax_applied_row_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Row Amount' + ), + 'base_weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Amount' + ), + 'weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Disposition' + ), + 'weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Row Disposition' + ), + 'base_weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Disposition' + ), + 'base_weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Row Disposition' + ) + ) + ), + $installer->getTable('sales/invoice_item') => array( + 'columns' => array( + 'weee_tax_applied' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Weee Tax Applied' + ), + 'weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Amount' + ), + 'weee_tax_applied_row_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Row Amount' + ), + 'base_weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Amount' + ), + 'weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Disposition' + ), + 'weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Row Disposition' + ), + 'base_weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Disposition' + ), + 'base_weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Row Disposition' + ) + ) + ), + $installer->getTable('sales/creditmemo_item') => array( + 'columns' => array( + 'weee_tax_applied' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Weee Tax Applied' + ), + 'weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Amount' + ), + 'weee_tax_applied_row_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Applied Row Amount' + ), + 'base_weee_tax_applied_amount' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Amount' + ), + 'weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Disposition' + ), + 'weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Weee Tax Row Disposition' + ), + 'base_weee_tax_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Disposition' + ), + 'base_weee_tax_row_disposition' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Row Disposition' + ) + ) + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/order_item'), + 'base_weee_tax_applied_row_amount', + 'base_weee_tax_applied_row_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Row Amnt' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/quote_item'), + 'base_weee_tax_applied_row_amount', + 'base_weee_tax_applied_row_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Row Amnt' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/invoice_item'), + 'base_weee_tax_applied_row_amount', + 'base_weee_tax_applied_row_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Row Amnt' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('sales/creditmemo_item'), + 'base_weee_tax_applied_row_amount', + 'base_weee_tax_applied_row_amnt', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'comment' => 'Base Weee Tax Applied Row Amnt' + ) +); +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('weee/discount'), + $installer->getIdxName('weee/discount', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/discount'), + $installer->getIdxName('weee/discount', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/discount'), + $installer->getIdxName('weee/discount', array('customer_group_id')), + array('customer_group_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/tax'), + $installer->getIdxName('weee/tax', array('website_id')), + array('website_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/tax'), + $installer->getIdxName('weee/tax', array('entity_id')), + array('entity_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/tax'), + $installer->getIdxName('weee/tax', array('country')), + array('country') +); + +$installer->getConnection()->addIndex( + $installer->getTable('weee/tax'), + $installer->getIdxName('weee/tax', array('attribute_id')), + array('attribute_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/discount', 'customer_group_id', 'customer/customer_group', 'customer_group_id'), + $installer->getTable('weee/discount'), + 'customer_group_id', + $installer->getTable('customer/customer_group'), + 'customer_group_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/discount', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('weee/discount'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/discount', 'website_id', 'core/website', 'website_id'), + $installer->getTable('weee/discount'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/tax', 'country', 'directory/country', 'country_id'), + $installer->getTable('weee/tax'), + 'country', + $installer->getTable('directory/country'), + 'country_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/tax', 'entity_id', 'catalog/product', 'entity_id'), + $installer->getTable('weee/tax'), + 'entity_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/tax', 'website_id', 'core/website', 'website_id'), + $installer->getTable('weee/tax'), + 'website_id', + $installer->getTable('core/website'), + 'website_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('weee/tax', 'attribute_id', 'eav/attribute', 'attribute_id'), + $installer->getTable('weee/tax'), + 'attribute_id', + $installer->getTable('eav/attribute'), + 'attribute_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget.php index fe87e47eff..c94853a7ae 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Chooser.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Chooser.php index a510664aba..0108f58dab 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Chooser.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Chooser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Form.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Form.php index e20208d5d1..0a6b27d87d 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Form.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance.php index 34ab0c6b18..804e1795e2 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit.php index 4f4fbb97e1..0b389e08fb 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Block.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Block.php index ad26683c47..0e9019e43b 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Block.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Block.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Layout.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Layout.php index 0d4706dac7..ebf98c74f0 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Layout.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Template.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Template.php index 441bb32ae5..acde4b225c 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Template.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Form.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Form.php index 82f72f6e2f..dad0347233 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Form.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main.php index 7e1926a310..3b0e183190 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php index ac9d410cf9..6797219574 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Main/Layout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -301,12 +301,12 @@ public function getPageGroups() foreach ($widgetInstance->getPageGroups() as $pageGroup) { $pageGroups[] = array( 'page_id' => $pageGroup['page_id'], - 'group' => $pageGroup['group'], + 'group' => $pageGroup['page_group'], 'block' => $pageGroup['block_reference'], - 'for_value' => $pageGroup['for'], + 'for_value' => $pageGroup['page_for'], 'layout_handle' => $pageGroup['layout_handle'], - $pageGroup['group'].'_entities' => $pageGroup['entities'], - 'template' => $pageGroup['template'] + $pageGroup['page_group'].'_entities' => $pageGroup['entities'], + 'template' => $pageGroup['page_template'] ); } } diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php index 0ef6334900..cbeaafeeb6 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Properties.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php index 020a92d8a4..50069bfa50 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tabs.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tabs.php index ccf259e185..5ac217db3b 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tabs.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Grid.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Grid.php index fbaebc727d..15ca9ec5c3 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Grid.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -80,7 +80,7 @@ protected function _prepareColumns() $this->addColumn('type', array( 'header' => Mage::helper('widget')->__('Type'), 'align' => 'left', - 'index' => 'type', + 'index' => 'instance_type', 'type' => 'options', 'options' => $this->getTypesOptionsArray() )); diff --git a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Options.php b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Options.php index d650bc6d8a..64a827f6f1 100644 --- a/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Options.php +++ b/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Block/Interface.php b/app/code/core/Mage/Widget/Block/Interface.php index 28c414ff76..e53e5cb173 100644 --- a/app/code/core/Mage/Widget/Block/Interface.php +++ b/app/code/core/Mage/Widget/Block/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Helper/Data.php b/app/code/core/Mage/Widget/Helper/Data.php index 3f94af9a75..b1e121a251 100644 --- a/app/code/core/Mage/Widget/Helper/Data.php +++ b/app/code/core/Mage/Widget/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Model/Mysql4/Widget.php b/app/code/core/Mage/Widget/Model/Mysql4/Widget.php index 8d5c1c086a..457483c7c9 100644 --- a/app/code/core/Mage/Widget/Model/Mysql4/Widget.php +++ b/app/code/core/Mage/Widget/Model/Mysql4/Widget.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Preconfigured widget * @@ -31,33 +32,6 @@ * @package Mage_Widget * @author Magento Core Team */ -class Mage_Widget_Model_Mysql4_Widget extends Mage_Core_Model_Mysql4_Abstract +class Mage_Widget_Model_Mysql4_Widget extends Mage_Widget_Model_Resource_Widget { - protected function _construct() - { - $this->_init('widget/widget', 'widget_id'); - } - - /** - * Retrieves preconfigured parameters for widget - * - * @param int $widgetId - * @return array - */ - public function loadPreconfiguredWidget($widgetId) - { - $read = $this->_getReadAdapter(); - $select = $read->select(); - $select->from($this->getMainTable()) - ->where($this->getIdFieldName() . ' = ?', $widgetId); - - $widget = $read->fetchRow($select); - if (is_array($widget)) { - if ($widget['parameters']) { - $widget['parameters'] = unserialize($widget['parameters']); - } - return $widget; - } - return false; - } } diff --git a/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance.php b/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance.php index e2badd3cbc..92428d08ee 100644 --- a/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance.php +++ b/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Widget Instance Resource Model * @@ -31,311 +32,6 @@ * @package Mage_Widget * @author Magento Core Team */ -class Mage_Widget_Model_Mysql4_Widget_Instance extends Mage_Core_Model_Mysql4_Abstract +class Mage_Widget_Model_Mysql4_Widget_Instance extends Mage_Widget_Model_Resource_Widget_Instance { - protected $_handlesToCleanCache = array(); - - /** - * Constructor - */ - protected function _construct() - { - $this->_init('widget/widget_instance', 'instance_id'); - } - - /** - * Perform actions after object load - * - * @param Mage_Widget_Model_Widget_Instance $object - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $select = $this->_getReadAdapter()->select() - ->from($this->getTable('widget/widget_instance_page')) - ->where('instance_id = ?', $object->getId()); - $object->setData('page_groups', $this->_getReadAdapter()->fetchAll($select)); - return parent::_afterLoad($object); - } - - /** - * Perform actions after object save - * - * @param Mage_Widget_Model_Widget_Instance $object - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $pageTable = $this->getTable('widget/widget_instance_page'); - $pageLayoutTable = $this->getTable('widget/widget_instance_page_layout'); - $layoutUpdateTable = $this->getTable('core/layout_update'); - $layoutLinkTable = $this->getTable('core/layout_link'); - $write = $this->_getWriteAdapter(); - - $select = $write->select() - ->from($pageTable, array('page_id')) - ->where('instance_id = ?', $object->getId()); - $pageIds = $write->fetchCol($select); - - $removePageIds = array_diff($pageIds, $object->getData('page_group_ids')); - - $select = $write->select() - ->from($pageLayoutTable, array('layout_update_id')) - ->where('page_id in (?)', $pageIds); - $removeLayoutUpdateIds = $write->fetchCol($select); - - $this->_deleteWidgetInstancePages($removePageIds); - $write->delete($pageLayoutTable, $write->quoteInto('page_id in (?)', $pageIds)); - $this->_deleteLayoutUpdates($removeLayoutUpdateIds); - - foreach ($object->getData('page_groups') as $pageGroup) { - $pageLayoutUpdateIds = $this->_saveLayoutUpdates($object, $pageGroup); - $data = array( - 'group' => $pageGroup['group'], - 'layout_handle' => $pageGroup['layout_handle'], - 'block_reference' => $pageGroup['block_reference'], - 'for' => $pageGroup['for'], - 'entities' => $pageGroup['entities'], - 'template' => $pageGroup['template'], - ); - $pageId = $pageGroup['page_id']; - if (in_array($pageGroup['page_id'], $pageIds)) { - $write->update($pageTable, $data, $write->quoteInto('page_id = ?', $pageId)); - } else { - $write->insert($pageTable, - array_merge(array( - 'instance_id' => $object->getId()),$data - )); - $pageId = $write->lastInsertId(); - } - foreach ($pageLayoutUpdateIds as $layoutUpdateId) { - $write->insert($pageLayoutTable, array( - 'page_id' => $pageId, - 'layout_update_id' => $layoutUpdateId - )); - } - } - - return parent::_afterSave($object); - } - - /** - * Prepare and save layout updates data - * - * @param Mage_Widget_Model_Widget_Instance $widgetInstance - * @param array $pageGroupData - * @return array of inserted layout updates ids - */ - protected function _saveLayoutUpdates($widgetInstance, $pageGroupData) - { - $write = $this->_getWriteAdapter(); - $pageLayoutUpdateIds = array(); - $storeIds = $this->_prepareStoreIds($widgetInstance->getStoreIds()); - foreach ($pageGroupData['layout_handle_updates'] as $handle) { - $this->_getWriteAdapter()->insert( - $this->getTable('core/layout_update'), array( - 'handle' => $handle, - 'xml' => $widgetInstance->generateLayoutUpdateXml( - $pageGroupData['block_reference'], - $pageGroupData['template']), - 'sort_order' => $widgetInstance->getSortOrder() - )); - $layoutUpdateId = $this->_getWriteAdapter()->lastInsertId(); - $pageLayoutUpdateIds[] = $layoutUpdateId; - foreach ($storeIds as $storeId) { - $this->_getWriteAdapter()->insert( - $this->getTable('core/layout_link'), array( - 'store_id' => $storeId, - 'area' => $widgetInstance->getArea(), - 'package' => $widgetInstance->getPackage(), - 'theme' => $widgetInstance->getTheme(), - 'layout_update_id' => $layoutUpdateId - )); - } - } - return $pageLayoutUpdateIds; - } - - /** - * Prepare store ids. - * If one of store id is default (0) return all store ids - * - * @param array $storeIds - * @return array - */ - protected function _prepareStoreIds($storeIds) - { - if (in_array(0, $storeIds)) { - $storeIds = array(0); - } - return $storeIds; - } - - /** - * Perform actions before object delete. - * Collect page ids and layout update ids and set to object for further delete - * - * @param Varien_Object $object - */ - protected function _beforeDelete(Mage_Core_Model_Abstract $object) - { - $select = $this->_getWriteAdapter()->select() - ->from(array('main_table' => $this->getTable('widget/widget_instance_page')), array()) - ->joinInner( - array('layout_page_table' => $this->getTable('widget/widget_instance_page_layout')), - 'layout_page_table.page_id = main_table.page_id', - array('layout_page_table.layout_update_id') - ) - ->where('main_table.instance_id = ?', $object->getId()); - $object->setLayoutUpdateIdsToDelete($this->_getWriteAdapter()->fetchCol($select)); - return $this; - } - - /** - * Perform actions after object delete. - * Delete layout updates by layout update ids collected in _beforeSave - * - * @param Mage_Widget_Model_Widget_Instance $object - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _afterDelete(Mage_Core_Model_Abstract $object) - { - $this->_deleteLayoutUpdates($object->getLayoutUpdateIdsToDelete()); - return parent::_afterDelete($object); - } - - /** - * Delete widget instance pages by given ids - * - * @param array $pageIds - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _deleteWidgetInstancePages($pageIds) - { - $this->_getWriteAdapter()->delete( - $this->getTable('widget/widget_instance_page'), - $this->_getWriteAdapter()->quoteInto('page_id in (?)', $pageIds) - ); - $this->_getWriteAdapter()->delete( - $this->getTable('widget/widget_instance_page_layout'), - $this->_getWriteAdapter()->quoteInto('page_id in (?)', $pageIds) - ); - return $this; - } - - /** - * Delete layout updates by given ids - * - * @param array $layoutUpdateIds - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _deleteLayoutUpdates($layoutUpdateIds) - { - $this->_getWriteAdapter()->delete( - $this->getTable('core/layout_update'), - $this->_getWriteAdapter()->quoteInto('layout_update_id in (?)', $layoutUpdateIds) - ); - $this->_getWriteAdapter()->delete( - $this->getTable('core/layout_link'), - $this->_getWriteAdapter()->quoteInto('layout_update_id in (?)', $layoutUpdateIds) - ); - return $this; - } - - /** - * Get store ids to which specified item is assigned - * - * @param int $id - * @return array - */ - public function lookupStoreIds($id) - { - $storeIds = $this->_getReadAdapter()->fetchOne($this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'store_ids') - ->where("{$this->getIdFieldName()} = ?", $id) - ); - return $storeIds ? explode(',', $storeIds) : array(); - } - - - - - - - /** - * Cache related methods are deprecated after 1.4.0.0-rc1 - * Added cache invalidation on model level - */ - - /** - * Clean cache by handles - * @deprecated - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _cleanLayoutCache() - { - $handles = $this->getHandlesToCleanCache(); - if (!empty($handles) && Mage::app()->useCache('layout')) { - Mage::app()->cleanCache($handles); - } - return $this; - } - - /** - * Clean blocks HTML otput cache - * @deprecated - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - protected function _cleanBlocksOutputCache() - { - if (Mage::app()->useCache('block_html')) { - Mage::app()->cleanCache(array('block_html')); - } - return $this; - } - - /** - * Reset handles to clean in cache - * @deprecated - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - public function resetHandlesToCleanCache() - { - $this->_handlesToCleanCache = array(); - return $this; - } - - /** - * Setter - * @deprecated - * @param array $handles - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - public function setHandlesToCleanCache($handles) - { - $this->_handlesToCleanCache = $handles; - return $this; - } - - /** - * Add handle to clean in cache - * @deprecated - * @param string $handle - * @return Mage_Widget_Model_Mysql4_Widget_Instance - */ - public function addHandleToCleanCache($handle) - { - $this->_handlesToCleanCache[] = $handle; - return $this; - } - - /** - * Getter - * @deprecated - * @return array - */ - public function getHandlesToCleanCache() - { - return $this->_handlesToCleanCache; - } } diff --git a/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance/Collection.php b/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance/Collection.php index 3d59532ee3..6885d71bcc 100644 --- a/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance/Collection.php +++ b/app/code/core/Mage/Widget/Model/Mysql4/Widget/Instance/Collection.php @@ -20,10 +20,11 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** * Widget Instance Collection * @@ -31,36 +32,6 @@ * @package Mage_Widget * @author Magento Core Team */ -class Mage_Widget_Model_Mysql4_Widget_Instance_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Widget_Model_Mysql4_Widget_Instance_Collection extends Mage_Widget_Model_Resource_Widget_Instance_Collection { - /** - * Constructor - */ - protected function _construct() - { - parent::_construct(); - $this->_init('widget/widget_instance'); - } - - /** - * Filter by store ids - * - * @param array|integer $storeIds - * @param boolean $withDefaultStore if TRUE also filter by store id '0' - * @return Mage_Widget_Model_Mysql4_Widget_Instance_Collection - */ - public function addStoreFilter($storeIds = array(), $withDefaultStore = true) - { - if (!is_array($storeIds)) { - $storeIds = array($storeIds); - } - if ($withDefaultStore && !in_array(0, $storeIds)) { - array_unshift($storeIds, 0); - } - $select = $this->getSelect(); - foreach ($storeIds as $storeId) { - $select->orWhere('FIND_IN_SET(?, `store_ids`)', $storeId); - } - return $this; - } } diff --git a/app/code/core/Mage/Widget/Model/Observer.php b/app/code/core/Mage/Widget/Model/Observer.php index 6bbbf165f4..b1466a45b8 100644 --- a/app/code/core/Mage/Widget/Model/Observer.php +++ b/app/code/core/Mage/Widget/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Model/Resource/Widget.php b/app/code/core/Mage/Widget/Model/Resource/Widget.php new file mode 100755 index 0000000000..a3147b1ad5 --- /dev/null +++ b/app/code/core/Mage/Widget/Model/Resource/Widget.php @@ -0,0 +1,69 @@ + + */ +class Mage_Widget_Model_Resource_Widget extends Mage_Core_Model_Resource_Db_Abstract +{ + + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('widget/widget', 'widget_id'); + } + + /** + * Retrieves pre-configured parameters for widget + * + * @param int $widgetId + * @return array + */ + public function loadPreconfiguredWidget($widgetId) + { + $readAdapter = $this->_getReadAdapter(); + $select = $readAdapter->select() + ->from($this->getMainTable()) + ->where($this->getIdFieldName() . '=:' . $this->getIdFieldName()); + $bind = array($this->getIdFieldName() => $widgetId); + $widget = $readAdapter->fetchRow($select, $bind); + if (is_array($widget)) { + if ($widget['parameters']) { + $widget['parameters'] = unserialize($widget['parameters']); + } + return $widget; + } + return false; + } +} diff --git a/app/code/core/Mage/Widget/Model/Resource/Widget/Instance.php b/app/code/core/Mage/Widget/Model/Resource/Widget/Instance.php new file mode 100755 index 0000000000..b85db7aaff --- /dev/null +++ b/app/code/core/Mage/Widget/Model/Resource/Widget/Instance.php @@ -0,0 +1,282 @@ + + */ +class Mage_Widget_Model_Resource_Widget_Instance extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Define main table + * + */ + protected function _construct() + { + $this->_init('widget/widget_instance', 'instance_id'); + } + + /** + * Perform actions after object load + * + * @param Mage_Widget_Model_Widget_Instance $object + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getTable('widget/widget_instance_page')) + ->where('instance_id = ?', (int)$object->getId()); + $result = $adapter->fetchAll($select); + $object->setData('page_groups', $result); + return parent::_afterLoad($object); + } + + /** + * Perform actions after object save + * + * @param Mage_Widget_Model_Widget_Instance $object + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $pageTable = $this->getTable('widget/widget_instance_page'); + $pageLayoutTable = $this->getTable('widget/widget_instance_page_layout'); + $readAdapter = $this->_getReadAdapter(); + $writeAdapter = $this->_getWriteAdapter(); + + $select = $readAdapter->select() + ->from($pageTable, 'page_id') + ->where('instance_id = ?', (int)$object->getId()); + $pageIds = $readAdapter->fetchCol($select); + + $removePageIds = array_diff($pageIds, $object->getData('page_group_ids')); + + if (is_array($pageIds) && count($pageIds) > 0) { + $inCond = $readAdapter->prepareSqlCondition('page_id', array('in' => $pageIds)); + + $select = $readAdapter->select() + ->from($pageLayoutTable, 'layout_update_id') + ->where($inCond); + $removeLayoutUpdateIds = $readAdapter->fetchCol($select); + + $writeAdapter->delete($pageLayoutTable, $inCond); + $this->_deleteLayoutUpdates($removeLayoutUpdateIds); + } + + $this->_deleteWidgetInstancePages($removePageIds); + + foreach ($object->getData('page_groups') as $pageGroup) { + $pageLayoutUpdateIds = $this->_saveLayoutUpdates($object, $pageGroup); + $data = array( + 'page_group' => $pageGroup['group'], + 'layout_handle' => $pageGroup['layout_handle'], + 'block_reference' => $pageGroup['block_reference'], + 'page_for' => $pageGroup['for'], + 'entities' => $pageGroup['entities'], + 'page_template' => $pageGroup['template'], + ); + $pageId = $pageGroup['page_id']; + if (in_array($pageGroup['page_id'], $pageIds)) { + $writeAdapter->update($pageTable, $data, array('page_id = ?' => (int)$pageId)); + } else { + $writeAdapter->insert($pageTable, + array_merge(array('instance_id' => $object->getId()), + $data)); + $pageId = $writeAdapter->lastInsertId($pageTable); + } + foreach ($pageLayoutUpdateIds as $layoutUpdateId) { + $writeAdapter->insert($pageLayoutTable, array( + 'page_id' => $pageId, + 'layout_update_id' => $layoutUpdateId + )); + } + } + + return parent::_afterSave($object); + } + + /** + * Prepare and save layout updates data + * + * @param Mage_Widget_Model_Widget_Instance $widgetInstance + * @param array $pageGroupData + * @return array of inserted layout updates ids + */ + protected function _saveLayoutUpdates($widgetInstance, $pageGroupData) + { + $writeAdapter = $this->_getWriteAdapter(); + $pageLayoutUpdateIds = array(); + $storeIds = $this->_prepareStoreIds($widgetInstance->getStoreIds()); + $layoutUpdateTable = $this->getTable('core/layout_update'); + $layoutUpdateLinkTable = $this->getTable('core/layout_link'); + + foreach ($pageGroupData['layout_handle_updates'] as $handle) { + $xml = $widgetInstance->generateLayoutUpdateXml( + $pageGroupData['block_reference'], + $pageGroupData['template'] + ); + $insert = array( + 'handle' => $handle, + 'xml' => $xml + ); + if (strlen($widgetInstance->getSortOrder())) { + $insert['sort_order'] = $widgetInstance->getSortOrder(); + }; + + $writeAdapter->insert($layoutUpdateTable, $insert); + $layoutUpdateId = $writeAdapter->lastInsertId($layoutUpdateTable); + $pageLayoutUpdateIds[] = $layoutUpdateId; + + $data = array(); + foreach ($storeIds as $storeId) { + $data[] = array( + 'store_id' => $storeId, + 'area' => $widgetInstance->getArea(), + 'package' => $widgetInstance->getPackage(), + 'theme' => $widgetInstance->getTheme(), + 'layout_update_id' => $layoutUpdateId); + } + $writeAdapter->insertMultiple($layoutUpdateLinkTable, $data); + } + return $pageLayoutUpdateIds; + } + + /** + * Prepare store ids. + * If one of store id is default (0) return all store ids + * + * @param array $storeIds + * @return array + */ + protected function _prepareStoreIds($storeIds) + { + if (in_array('0', $storeIds)) { + $storeIds = array(0); + } + return $storeIds; + } + + /** + * Perform actions before object delete. + * Collect page ids and layout update ids and set to object for further delete + * + * @param Varien_Object $object + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _beforeDelete(Mage_Core_Model_Abstract $object) + { + $writeAdapter = $this->_getWriteAdapter(); + $select = $writeAdapter->select() + ->from(array('main_table' => $this->getTable('widget/widget_instance_page')), array()) + ->joinInner( + array('layout_page_table' => $this->getTable('widget/widget_instance_page_layout')), + 'layout_page_table.page_id = main_table.page_id', + array('layout_update_id') + ) + ->where('main_table.instance_id=?', $object->getId()); + $result = $writeAdapter->fetchCol($select); + $object->setLayoutUpdateIdsToDelete($result); + return $this; + } + + /** + * Perform actions after object delete. + * Delete layout updates by layout update ids collected in _beforeSave + * + * @param Mage_Widget_Model_Widget_Instance $object + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _afterDelete(Mage_Core_Model_Abstract $object) + { + $this->_deleteLayoutUpdates($object->getLayoutUpdateIdsToDelete()); + return parent::_afterDelete($object); + } + + /** + * Delete widget instance pages by given ids + * + * @param array $pageIds + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _deleteWidgetInstancePages($pageIds) + { + $writeAdapter = $this->_getWriteAdapter(); + if ($pageIds) { + $inCond = $writeAdapter->prepareSqlCondition('page_id', array( + 'in' => $pageIds + )); + $writeAdapter->delete( + $this->getTable('widget/widget_instance_page'), + $inCond + ); + } + return $this; + } + + /** + * Delete layout updates by given ids + * + * @param array $layoutUpdateIds + * @return Mage_Widget_Model_Resource_Widget_Instance + */ + protected function _deleteLayoutUpdates($layoutUpdateIds) + { + $writeAdapter = $this->_getWriteAdapter(); + if ($layoutUpdateIds) { + $inCond = $writeAdapter->prepareSqlCondition('layout_update_id', array( + 'in' => $layoutUpdateIds + )); + $writeAdapter->delete( + $this->getTable('core/layout_update'), + $inCond + ); + } + return $this; + } + + /** + * Get store ids to which specified item is assigned + * + * @param int $id + * @return array + */ + public function lookupStoreIds($id) + { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from($this->getMainTable(), 'store_ids') + ->where("{$this->getIdFieldName()} = ?", (int)$id); + $storeIds = $adapter->fetchOne($select); + return $storeIds ? explode(',', $storeIds) : array(); + } + +} diff --git a/app/code/core/Mage/Widget/Model/Resource/Widget/Instance/Collection.php b/app/code/core/Mage/Widget/Model/Resource/Widget/Instance/Collection.php new file mode 100755 index 0000000000..cc78826856 --- /dev/null +++ b/app/code/core/Mage/Widget/Model/Resource/Widget/Instance/Collection.php @@ -0,0 +1,71 @@ + + */ +class Mage_Widget_Model_Resource_Widget_Instance_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Constructor + * + */ + protected function _construct() + { + parent::_construct(); + $this->_init('widget/widget_instance'); + } + + /** + * Filter by store ids + * + * @param array|integer $storeIds + * @param boolean $withDefaultStore if TRUE also filter by store id '0' + * @return Mage_Widget_Model_Resource_Widget_Instance_Collection + */ + public function addStoreFilter($storeIds = array(), $withDefaultStore = true) + { + if (!is_array($storeIds)) { + $storeIds = array($storeIds); + } + if ($withDefaultStore && !in_array('0', $storeIds)) { + array_unshift($storeIds, 0); + } + $where = array(); + foreach ($storeIds as $storeId) { + $where[] = $this->_getConditionSql('store_ids', array('finset' => $storeId)); + } + + $this->_select->where(implode(' OR ', $where)); + + return $this; + } +} diff --git a/app/code/core/Mage/Widget/Model/Template/Filter.php b/app/code/core/Mage/Widget/Model/Template/Filter.php index f97d044099..39848de7f8 100644 --- a/app/code/core/Mage/Widget/Model/Template/Filter.php +++ b/app/code/core/Mage/Widget/Model/Template/Filter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -55,7 +55,7 @@ public function widgetDirective($construction) } elseif (!empty($params['id'])) { $preconfigured = Mage::getResourceSingleton('widget/widget') ->loadPreconfiguredWidget($params['id']); - $type = $preconfigured['type']; + $type = $preconfigured['widget_type']; $params = $preconfigured['parameters']; } else { return ''; diff --git a/app/code/core/Mage/Widget/Model/Widget.php b/app/code/core/Mage/Widget/Model/Widget.php index c7c785dbc8..7b01d970e5 100644 --- a/app/code/core/Mage/Widget/Model/Widget.php +++ b/app/code/core/Mage/Widget/Model/Widget.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Model/Widget/Config.php b/app/code/core/Mage/Widget/Model/Widget/Config.php index 427c93b7ac..10e0c1ba0d 100644 --- a/app/code/core/Mage/Widget/Model/Widget/Config.php +++ b/app/code/core/Mage/Widget/Model/Widget/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/Model/Widget/Instance.php b/app/code/core/Mage/Widget/Model/Widget/Instance.php index 32b8058f2a..7140edb55b 100644 --- a/app/code/core/Mage/Widget/Model/Widget/Instance.php +++ b/app/code/core/Mage/Widget/Model/Widget/Instance.php @@ -20,13 +20,22 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Widget Instance Model * + * @method Mage_Widget_Model_Resource_Widget_Instance _getResource() + * @method Mage_Widget_Model_Resource_Widget_Instance getResource() + * @method string getTitle() + * @method Mage_Widget_Model_Widget_Instance setTitle(string $value) + * @method Mage_Widget_Model_Widget_Instance setStoreIds(string $value) + * @method Mage_Widget_Model_Widget_Instance setWidgetParameters(string $value) + * @method int getSortOrder() + * @method Mage_Widget_Model_Widget_Instance setSortOrder(int $value) + * * @category Mage * @package Mage_Widget * @author Magento Core Team @@ -80,6 +89,20 @@ protected function _construct() } } + /** + * Init mapping array of short fields to + * its full names + * + * @return Varien_Object + */ + protected function _initOldFieldsMap() + { + $this->_oldFieldsMap = array( + 'type' => 'instance_type', + ); + return $this; + } + /** * Processing object before save data * @@ -137,6 +160,7 @@ protected function _beforeSave() } $this->setData('page_groups', $tmpPageGroups); $this->setData('page_group_ids', $pageGroupIds); + return parent::_beforeSave(); } diff --git a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php index 1a9a8c219b..68994d73e7 100644 --- a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php +++ b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -78,8 +78,6 @@ protected function _initWidgetInstance() $this->_getSession()->addError(Mage::helper('widget')->__('Wrong wigdet instance specified.')); return false; } - $data['type'] = $widgetInstance->getType(); - $data['package_theme'] = $widgetInstance->getPackageTheme(); } else { $widgetInstance->setType($type) ->setPackageTheme($packageTheme); diff --git a/app/code/core/Mage/Widget/controllers/Adminhtml/WidgetController.php b/app/code/core/Mage/Widget/controllers/Adminhtml/WidgetController.php index 7e2a5e9071..a0dc564c6d 100644 --- a/app/code/core/Mage/Widget/controllers/Adminhtml/WidgetController.php +++ b/app/code/core/Mage/Widget/controllers/Adminhtml/WidgetController.php @@ -20,16 +20,16 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Widgets management controller * - * @category Mage - * @package Mage_Widget - * @author Magento Core Team + * @category Mage + * @package Mage_Widget + * @author Magento Core Team */ class Mage_Widget_Adminhtml_WidgetController extends Mage_Adminhtml_Controller_Action { diff --git a/app/code/core/Mage/Widget/etc/adminhtml.xml b/app/code/core/Mage/Widget/etc/adminhtml.xml index dc2b79ff2e..8531d281fe 100644 --- a/app/code/core/Mage/Widget/etc/adminhtml.xml +++ b/app/code/core/Mage/Widget/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Widget/etc/config.xml b/app/code/core/Mage/Widget/etc/config.xml index a156f9a51d..7a5a475246 100644 --- a/app/code/core/Mage/Widget/etc/config.xml +++ b/app/code/core/Mage/Widget/etc/config.xml @@ -21,31 +21,40 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.0.0 + 1.6.0.0 Mage_Widget_Model - widget_mysql4 + widget_resource - - Mage_Widget_Model_Mysql4 + + Mage_Widget_Model_Resource + widget_mysql4 - widget
      - widget_instance
      - widget_instance_page
      - widget_instance_page_layout
      + + widget
      +
      + + widget_instance
      +
      + + widget_instance_page
      +
      + + widget_instance_page_layout
      +
      -
      +
      diff --git a/app/code/core/Mage/Widget/sql/widget_setup/install-1.6.0.0.php b/app/code/core/Mage/Widget/sql/widget_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..2a90ebaca5 --- /dev/null +++ b/app/code/core/Mage/Widget/sql/widget_setup/install-1.6.0.0.php @@ -0,0 +1,208 @@ +startSetup(); + +/** + * Create table 'widget/widget' + */ +if (!$installer->getConnection()->isTableExists($installer->getTable('widget/widget'))) { + $table = $installer->getConnection() + ->newTable($installer->getTable('widget/widget')) + ->addColumn('widget_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Widget Id') + ->addColumn('widget_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Widget code for template directive') + ->addColumn('widget_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Widget Type') + ->addColumn('parameters', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => true, + ), 'Parameters') + ->addIndex($installer->getIdxName('widget/widget', 'widget_code'), 'widget_code') + ->setComment('Preconfigured Widgets'); + $installer->getConnection()->createTable($table); +} else { + + $installer->getConnection()->dropIndex( + $installer->getTable('widget/widget'), + 'IDX_CODE' + ); + + $tables = array( + $installer->getTable('widget/widget') => array( + 'columns' => array( + 'widget_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Widget Id' + ), + 'parameters' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Parameters' + ) + ), + 'comment' => 'Preconfigured Widgets' + ) + ); + + $installer->getConnection()->modifyTables($tables); + + $installer->getConnection()->changeColumn( + $installer->getTable('widget/widget'), + 'code', + 'widget_code', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Widget code for template directive' + ) + ); + + $installer->getConnection()->changeColumn( + $installer->getTable('widget/widget'), + 'type', + 'widget_type', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Widget Type' + ) + ); + + $installer->getConnection()->addIndex( + $installer->getTable('widget/widget'), + $installer->getIdxName('widget/widget', array('widget_code')), + array('widget_code') + ); +} + +/** + * Create table 'widget/widget_instance' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('widget/widget_instance')) + ->addColumn('instance_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Instance Id') + ->addColumn('instance_type', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Instance Type') + ->addColumn('package_theme', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Package Theme') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Widget Title') + ->addColumn('store_ids', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + 'default' => '0', + ), 'Store ids') + ->addColumn('widget_parameters', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Widget parameters') + ->addColumn('sort_order', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sort order') + ->setComment('Instances of Widget for Package Theme'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'widget/widget_instance_page' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('widget/widget_instance_page')) + ->addColumn('page_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Page Id') + ->addColumn('instance_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Instance Id') + ->addColumn('page_group', Varien_Db_Ddl_Table::TYPE_TEXT, 25, array( + ), 'Block Group Type') + ->addColumn('layout_handle', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Layout Handle') + ->addColumn('block_reference', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Block Reference') + ->addColumn('page_for', Varien_Db_Ddl_Table::TYPE_TEXT, 25, array( + ), 'For instance entities') + ->addColumn('entities', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Catalog entities (comma separated)') + ->addColumn('page_template', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + ), 'Path to widget template') + ->addIndex($installer->getIdxName('widget/widget_instance_page', 'instance_id'), 'instance_id') + ->addForeignKey($installer->getFkName('widget/widget_instance_page', 'instance_id', 'widget/widget_instance', 'instance_id'), + 'instance_id', $installer->getTable('widget/widget_instance'), 'instance_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Instance of Widget on Page'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'widget/widget_instance_page_layout' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('widget/widget_instance_page_layout')) + ->addColumn('page_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Page Id') + ->addColumn('layout_update_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Layout Update Id') + ->addIndex($installer->getIdxName('widget/widget_instance_page_layout', 'page_id'), 'page_id') + ->addIndex($installer->getIdxName('widget/widget_instance_page_layout', 'layout_update_id'), 'layout_update_id') + ->addIndex($installer->getIdxName('widget/widget_instance_page_layout', array('layout_update_id', 'page_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('layout_update_id', 'page_id'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey($installer->getFkName('widget/widget_instance_page_layout', 'page_id', 'widget/widget_instance_page', 'page_id'), + 'page_id', $installer->getTable('widget/widget_instance_page'), 'page_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addForeignKey($installer->getFkName('widget/widget_instance_page_layout', 'layout_update_id', 'core/layout_update', 'layout_update_id'), + 'layout_update_id', $installer->getTable('core/layout_update'), 'layout_update_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Layout updates'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Widget/sql/widget_setup/mysql4-install-1.4.0.0.0.php b/app/code/core/Mage/Widget/sql/widget_setup/mysql4-install-1.4.0.0.0.php index b12ccb0d4c..cf571baa6c 100644 --- a/app/code/core/Mage/Widget/sql/widget_setup/mysql4-install-1.4.0.0.0.php +++ b/app/code/core/Mage/Widget/sql/widget_setup/mysql4-install-1.4.0.0.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Widget/sql/widget_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Widget/sql/widget_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..ca8330f7bb --- /dev/null +++ b/app/code/core/Mage/Widget/sql/widget_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,351 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('widget/widget_instance_page'), + 'FK_WIDGET_WIDGET_INSTANCE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('widget/widget_instance_page_layout'), + 'FK_WIDGET_WIDGET_INSTANCE_LAYOUT_UPDATE_ID' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('widget/widget_instance_page_layout'), + 'FK_WIDGET_WIDGET_INSTANCE_PAGE_ID' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('widget/widget'), + 'IDX_CODE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('widget/widget_instance_page'), + 'IDX_WIDGET_WIDGET_INSTANCE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('widget/widget_instance_page_layout'), + 'PAGE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('widget/widget_instance_page_layout'), + 'IDX_WIDGET_WIDGET_INSTANCE_PAGE_ID' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('widget/widget_instance_page_layout'), + 'IDX_WIDGET_WIDGET_INSTANCE_LAYOUT_UPDATE_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('widget/widget') => array( + 'columns' => array( + 'widget_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Widget Id' + ), + 'parameters' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Parameters' + ) + ), + 'comment' => 'Preconfigured Widgets' + ), + $installer->getTable('widget/widget_instance') => array( + 'columns' => array( + 'instance_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Instance Id' + ), + 'package_theme' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Package Theme' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Widget Title' + ), + 'store_ids' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Store ids' + ), + 'widget_parameters' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Widget parameters' + ), + 'sort_order' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sort order' + ) + ), + 'comment' => 'Instances of Widget for Package Theme' + ), + $installer->getTable('widget/widget_instance_page') => array( + 'columns' => array( + 'page_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Page Id' + ), + 'instance_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Instance Id' + ), + 'layout_handle' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Layout Handle' + ), + 'block_reference' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Block Reference' + ), + 'entities' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Catalog entities (comma separated)' + ) + ), + 'comment' => 'Instance of Widget on Page' + ), + $installer->getTable('widget/widget_instance_page_layout') => array( + 'columns' => array( + 'page_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Page Id' + ), + 'layout_update_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'default' => '0', + 'comment' => 'Layout Update Id' + ) + ), + 'comment' => 'Layout updates' + ) +); + +$installer->getConnection()->modifyTables($tables); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget'), + 'code', + 'widget_code', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Widget code for template directive' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget'), + 'type', + 'widget_type', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Widget Type' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget_instance'), + 'type', + 'instance_type', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Instance Type' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget_instance_page'), + 'group', + 'page_group', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 25, + 'comment' => 'Block Group Type' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget_instance_page'), + 'for', + 'page_for', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 25, + 'comment' => 'For instance entities' + ) +); + +$installer->getConnection()->changeColumn( + $installer->getTable('widget/widget_instance_page'), + 'template', + 'page_template', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'comment' => 'Path to widget template' + ) +); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('widget/widget'), + $installer->getIdxName('widget/widget', array('widget_code')), + array('widget_code') +); + +$installer->getConnection()->addIndex( + $installer->getTable('widget/widget_instance_page'), + $installer->getIdxName('widget/widget_instance_page', array('instance_id')), + array('instance_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('widget/widget_instance_page_layout'), + $installer->getIdxName( + 'widget/widget_instance_page_layout', + array('layout_update_id', 'page_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('layout_update_id', 'page_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('widget/widget_instance_page_layout'), + $installer->getIdxName('widget/widget_instance_page_layout', array('page_id')), + array('page_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('widget/widget_instance_page_layout'), + $installer->getIdxName('widget/widget_instance_page_layout', array('layout_update_id')), + array('layout_update_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'widget/widget_instance_page', + 'instance_id', + 'widget/widget_instance', + 'instance_id' + ), + $installer->getTable('widget/widget_instance_page'), + 'instance_id', + $installer->getTable('widget/widget_instance'), + 'instance_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'widget/widget_instance_page_layout', + 'page_id', + 'widget/widget_instance_page', + 'page_id' + ), + $installer->getTable('widget/widget_instance_page_layout'), + 'page_id', + $installer->getTable('widget/widget_instance_page'), + 'page_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName( + 'widget/widget_instance_page_layout', + 'layout_update_id', + 'core/layout_update', + 'layout_update_id' + ), + $installer->getTable('widget/widget_instance_page_layout'), + 'layout_update_id', + $installer->getTable('core/layout_update'), + 'layout_update_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Wishlist/Block/Abstract.php b/app/code/core/Mage/Wishlist/Block/Abstract.php index c3d2612ea6..6e62619c3e 100644 --- a/app/code/core/Mage/Wishlist/Block/Abstract.php +++ b/app/code/core/Mage/Wishlist/Block/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php index 1c5ba60b8d..a632009ddc 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php b/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php index e590db7a41..b4b393cd45 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Sidebar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -37,7 +37,7 @@ class Mage_Wishlist_Block_Customer_Sidebar extends Mage_Wishlist_Block_Abstract /** * Add sidebar conditions to collection * - * @param Mage_Wishlist_Model_Mysql4_Item_Collection $collection + * @param Mage_Wishlist_Model_Resource_Item_Collection $collection * @return Mage_Wishlist_Block_Customer_Wishlist */ protected function _prepareCollection($collection) diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php index ff92a26675..22fe09e18d 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ * * @category Mage * @package Mage_Wishlist - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Wishlist_Block_Customer_Wishlist extends Mage_Wishlist_Block_Abstract { diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php index 6770c96015..0e07231d41 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Wishlist/Item/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Item/Configure.php b/app/code/core/Mage/Wishlist/Block/Item/Configure.php index 2f1032b381..60fa9c7398 100644 --- a/app/code/core/Mage/Wishlist/Block/Item/Configure.php +++ b/app/code/core/Mage/Wishlist/Block/Item/Configure.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Links.php b/app/code/core/Mage/Wishlist/Block/Links.php index 45b3c1e875..3c149c79bf 100644 --- a/app/code/core/Mage/Wishlist/Block/Links.php +++ b/app/code/core/Mage/Wishlist/Block/Links.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Render/Item/Price.php b/app/code/core/Mage/Wishlist/Block/Render/Item/Price.php index 849a7d14c2..0d0cd9ff96 100644 --- a/app/code/core/Mage/Wishlist/Block/Render/Item/Price.php +++ b/app/code/core/Mage/Wishlist/Block/Render/Item/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Share/Email/Items.php b/app/code/core/Mage/Wishlist/Block/Share/Email/Items.php index 614f459169..020ff01e6a 100644 --- a/app/code/core/Mage/Wishlist/Block/Share/Email/Items.php +++ b/app/code/core/Mage/Wishlist/Block/Share/Email/Items.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ * * @category Mage * @package Mage_Wishlist - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Wishlist_Block_Share_Email_Items extends Mage_Wishlist_Block_Abstract { diff --git a/app/code/core/Mage/Wishlist/Block/Share/Email/Rss.php b/app/code/core/Mage/Wishlist/Block/Share/Email/Rss.php index b594be9f54..a2bbf166f1 100644 --- a/app/code/core/Mage/Wishlist/Block/Share/Email/Rss.php +++ b/app/code/core/Mage/Wishlist/Block/Share/Email/Rss.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php b/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php index b06537515c..6fcac49a11 100644 --- a/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Block/Share/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Controller/Abstract.php b/app/code/core/Mage/Wishlist/Controller/Abstract.php index 72f268ce58..aa040888c4 100644 --- a/app/code/core/Mage/Wishlist/Controller/Abstract.php +++ b/app/code/core/Mage/Wishlist/Controller/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Helper/Data.php b/app/code/core/Mage/Wishlist/Helper/Data.php index 90e778bd95..062e9963ad 100644 --- a/app/code/core/Mage/Wishlist/Helper/Data.php +++ b/app/code/core/Mage/Wishlist/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -226,9 +226,9 @@ protected function _getUrlStore($item) */ public function getRemoveUrl($item) { - return $this->_getUrl('wishlist/index/remove', array( - 'item' => $item->getWishlistItemId() - )); + return $this->_getUrl('wishlist/index/remove', + array('item' => $item->getWishlistItemId()) + ); } /** @@ -312,11 +312,14 @@ public function getAddUrlWithParams($item, array $params = array()) */ public function getAddToCartUrl($item) { - $continueUrl = Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array( - '_current' => true, - '_use_rewrite' => true, - '_store_to_url' => true, - ))); + $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED; + $continueUrl = Mage::helper('core')->urlEncode( + Mage::getUrl('*/*/*', array( + '_current' => true, + '_use_rewrite' => true, + '_store_to_url' => true, + )) + ); $urlParamName = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED; $params = array( diff --git a/app/code/core/Mage/Wishlist/Model/Config.php b/app/code/core/Mage/Wishlist/Model/Config.php index bd0a46d684..9c8c7d30c6 100644 --- a/app/code/core/Mage/Wishlist/Model/Config.php +++ b/app/code/core/Mage/Wishlist/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php b/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php index 409c64c722..7765170c63 100644 --- a/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php +++ b/app/code/core/Mage/Wishlist/Model/Config/Source/Summary.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Wishlist_Model_Config_Source_Summary diff --git a/app/code/core/Mage/Wishlist/Model/Item.php b/app/code/core/Mage/Wishlist/Model/Item.php index d4ba631340..1a9904dcfd 100644 --- a/app/code/core/Mage/Wishlist/Model/Item.php +++ b/app/code/core/Mage/Wishlist/Model/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,6 +28,19 @@ /** * Wishlist item model * + * @method Mage_Wishlist_Model_Resource_Item _getResource() + * @method Mage_Wishlist_Model_Resource_Item getResource() + * @method int getWishlistId() + * @method Mage_Wishlist_Model_Item setWishlistId(int $value) + * @method int getProductId() + * @method Mage_Wishlist_Model_Item setProductId(int $value) + * @method int getStoreId() + * @method Mage_Wishlist_Model_Item setStoreId(int $value) + * @method string getAddedAt() + * @method Mage_Wishlist_Model_Item setAddedAt(string $value) + * @method string getDescription() + * @method Mage_Wishlist_Model_Item setDescription(string $value) + * * @category Mage * @package Mage_Wishlist * @author Magento Core Team @@ -399,7 +412,14 @@ public function getProductUrl() public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); - $buyRequest = new Varien_Object($option ? unserialize($option->getValue()) : null); + $initialData = $option ? unserialize($option->getValue()) : null; + + // There can be wrong data due to bug in Grouped products - it formed 'info_buyRequest' as Varien_Object + if ($initialData instanceof Varien_Object) { + $initialData = $initialData->getData(); + } + + $buyRequest = new Varien_Object($initialData); $buyRequest->setOriginalQty($buyRequest->getQty()) ->setQty($this->getQty() * 1); return $buyRequest; diff --git a/app/code/core/Mage/Wishlist/Model/Item/Option.php b/app/code/core/Mage/Wishlist/Model/Item/Option.php index bcf210cd63..209f8a1a27 100644 --- a/app/code/core/Mage/Wishlist/Model/Item/Option.php +++ b/app/code/core/Mage/Wishlist/Model/Item/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Item.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Item.php index 3871b2e2f7..3b3cb93f7d 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Item.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Item.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,46 +28,10 @@ /** * Wishlist item model resource * - * @category Mage - * @package Mage_Wishlist + * @category Mage + * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Item extends Mage_Core_Model_Mysql4_Abstract +class Mage_Wishlist_Model_Mysql4_Item extends Mage_Wishlist_Model_Resource_Item { - /** - * Initialize connection and define main table - * - */ - protected function _construct() - { - $this->_init('wishlist/item', 'wishlist_item_id'); - } - - /** - * Load item by wishlist, product and shared stores - * - * @param Mage_Wishlist_Model_Item $object - * @param int $wishlistId - * @param int $productId - * @param array $sharedStores - * @return Mage_Wishlist_Model_Mysql4_Item - */ - public function loadByProductWishlist($object, $wishlistId, $productId, $sharedStores) - { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from($this->getMainTable()) - ->where('wishlist_id=?', $wishlistId) - ->where('product_id=?', $productId) - ->where('store_id IN(?)', $sharedStores); - - $data = $adapter->fetchRow($select); - if ($data) { - $object->setData($data); - } - - $this->_afterLoad($object); - - return $this; - } } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php index 0f9190f133..5e17ef1b33 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,422 +28,10 @@ /** * Wishlist item collection * - * @category Mage - * @package Mage_Wishlist + * @category Mage + * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Wishlist_Model_Mysql4_Item_Collection extends Mage_Wishlist_Model_Resource_Item_Collection { - /** - * Product Visibility Filter to product collection flag - * - * @var bool - */ - protected $_productVisible = false; - - /** - * Product Salable Filter to product collection flag - * - * @var bool - */ - protected $_productSalable = false; - - /** - * If product out of stock, its item will be removed after load - * - * @var bool - */ - protected $_productInStock = false; - - /** - * Product Ids array - * - * @var array - */ - protected $_productIds = array(); - - /** - * Store Ids array - * - * @var array - */ - protected $_storeIds = array(); - - /** - * Add days in whishlist filter of product collection - * - * @var boolean - */ - protected $_addDaysInWishlist = false; - - /** - * Sum of items collection qty - * - * @var int - */ - protected $_itemsQty; - - /** - * Whether product name attribute value table is joined in select - * - * @var boolean - */ - protected $_isProductNameJoined = false; - - /** - * Initialize resource model for collection - * - * @return void - */ - public function _construct() - { - $this->_init('wishlist/item'); - $this->addFilterToMap('store_id', 'main_table.store_id'); - } - - /** - * After load processing - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - /** - * Assign products - */ - $this->_assignOptions(); - $this->_assignProducts(); - $this->resetItemsDataChanged(); - - $this->getPageSize(); - - return $this; - } - - /** - * Add options to items - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - protected function _assignOptions() - { - $itemIds = array_keys($this->_items); - $optionCollection = Mage::getModel('wishlist/item_option')->getCollection() - ->addItemFilter($itemIds); - foreach ($this as $item) { - $item->setOptions($optionCollection->getOptionsByItem($item)); - } - $productIds = $optionCollection->getProductIds(); - $this->_productIds = array_merge($this->_productIds, $productIds); - - return $this; - } - - /** - * Add products to items and item options - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - protected function _assignProducts() - { - Varien_Profiler::start('WISHLIST:'.__METHOD__); - $productIds = array(); - foreach ($this as $item) { - $productIds[$item->getProductId()] = 1; - } - $this->_productIds = array_merge($this->_productIds, array_keys($productIds)); - $attributes = Mage::getSingleton('wishlist/config')->getProductAttributes(); - $productCollection = Mage::getModel('catalog/product')->getCollection() - ->addIdFilter($this->_productIds) - ->addAttributeToSelect($attributes) - ->addOptionsToResult() - ->addPriceData() - ->addUrlRewrite(); - - if ($this->_productVisible) { - Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($productCollection); - } - if ($this->_productSalable) { - $productCollection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($productCollection); - } - - foreach ($this->_storeIds as $id) { - $productCollection->addStoreFilter($id); - } - - Mage::dispatchEvent('wishlist_item_collection_products_after_load', array( - 'product_collection' => $productCollection - )); - - foreach ($this as $item) { - $product = $productCollection->getItemById($item->getProductId()); - if ($product) { - if (!$this->_productInStock && - !$product->isSalable() && - !Mage::helper('cataloginventory')->isShowOutOfStock()) { - $this->removeItemByKey($item->getId()); - } else { - $product->setCustomOptions(array()); - $item->setProduct($product); - $item->setProductName($product->getName()); - $item->setName($product->getName()); - $item->setPrice($product->getPrice()); - } - } else { - $item->isDeleted(true); - } - } - - Varien_Profiler::stop('WISHLIST:'.__METHOD__); - - return $this; - } - - /** - * Add filter by wishlist object - * - * @param Mage_Wishlist_Model_Wishlist $wishlist - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) - { - $this->addFieldToFilter('wishlist_id', $wishlist->getId()); - return $this; - } - - /** - * Add filter by shared stores - * - * @param int|array $store - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addStoreFilter($store = null) - { - if (is_null($store)) { - $store = Mage::app()->getStore()->getId(); - } - - if (!is_array($store)) { - $store = array($store); - } - $this->_storeIds = $store; - - $this->addFieldToFilter('store_id', $store); - return $this; - } - - /** - * Add items store data to collection - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addStoreData() - { - $storeTable = Mage::getSingleton('core/resource')->getTableName('core/store'); - $this->getSelect()->join(array('store'=>$storeTable), 'main_table.store_id=store.store_id', array( - 'store_name'=>'name', - 'item_store_id' => 'store_id' - )); - return $this; - } - - /** - * Add wishlist sort order - * - * @param string $attribute - * @param string $dir - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addWishListSortOrder($attribute = 'added_at', $dir = 'desc') - { - $this->setOrder($attribute, $dir); - return $this; - } - - /** - * Reset sort order - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function resetSortOrder() - { - $this->getSelect()->reset(Zend_Db_Select::ORDER); - return $this; - } - - /** - * Set product Visibility Filter to product collection flag - * - * @param bool $flag - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function setVisibilityFilter($flag = true) - { - $this->_productVisible = (bool)$flag; - return $this; - } - - /** - * Set Salable Filter. - * This filter apply Salable Product Types Filter to product collection. - * - * @param bool $flag - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function setSalableFilter($flag = true) - { - $this->_productSalable = (bool)$flag; - return $this; - } - - /** - * Set In Stock Filter. - * This filter remove items with no salable product. - * - * @param bool $flag - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function setInStockFilter($flag = true) - { - $this->_productInStock = (bool)$flag; - return $this; - } - - /** - * Set add days in whishlist - * - * This method appears in 1.5.0.0 in deprecated state, because: - * - we need it to make wishlist item collection interface as much as possible compatible with old - * wishlist product collection - * - this method is useless because we can calculate days in php, and don't use MySQL for it - * - * @deprecated after 1.4.2.0 - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addDaysInWishlist() - { - $this->_addDaysInWishlist = true; - $this->getSelect()->columns(array('days_in_wishlist' => - "(TO_DAYS('" . (substr(Mage::getSingleton('core/date')->date(), 0, -2) . '00') . "') ". - "- TO_DAYS(DATE_ADD(added_at, INTERVAL ".(int) Mage::getSingleton('core/date')->getGmtOffset()." SECOND)))" - )); - return $this; - } - - /** - * Adds filter on days in wishlist - * - * $constraints may contain 'from' and 'to' indexes with number of days to look for items - * - * @param array $constraints - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addDaysFilter($constraints) - { - if (!is_array($constraints)) { - return $this; - } - - $filter = array(); - - $now = Mage::getSingleton('core/date')->date(); - $gmtOffset = (int) Mage::getSingleton('core/date')->getGmtOffset(); - if (isset($constraints['from'])) { - $lastDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); - $lastDay->subSecond($gmtOffset) - ->subDay($constraints['from'] - 1); - $filter['to'] = $lastDay; - } - - if (isset($constraints['to'])) { - $firstDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); - $firstDay->subSecond($gmtOffset) - ->subDay($constraints['to']); - $filter['from'] = $firstDay; - } - - if ($filter) { - $filter['datetime'] = true; - $this->addFieldToFilter('added_at', $filter); - } - - return $this; - } - - /** - * Joins product name attribute value to use it in WHERE and ORDER clauses - * - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - protected function _joinProductNameTable() - { - if (!$this->_isProductNameJoined) { - $entityTypeId = Mage::getResourceModel('catalog/config') - ->getEntityTypeId(); - $attribute = Mage::getModel('catalog/entity_attribute') - ->loadByCode($entityTypeId, 'name'); - - $storeId = Mage::app()->getStore()->getId(); - - $this->getSelect() - ->join( - array('product_name_table' => $attribute->getBackendTable()), - 'product_name_table.entity_id=main_table.product_id' . - ' AND product_name_table.store_id=' . $storeId . - ' AND product_name_table.attribute_id=' . $attribute->getId(). - ' AND product_name_table.entity_type_id=' . $entityTypeId, - array() - ); - - $this->_isProductNameJoined = true; - } - return $this; - } - - /** - * Adds filter on product name - * - * @param string $productName - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function addProductNameFilter($productName) - { - $this->_joinProductNameTable(); - $this->getSelect() - ->where('INSTR(product_name_table.value, ?)', $productName); - - return $this; - } - - /** - * Sets ordering by product name - * - * @param string $dir - * @return Mage_Wishlist_Model_Mysql4_Item_Collection - */ - public function setOrderByProductName($dir) - { - $this->_joinProductNameTable(); - $this->getSelect()->order('product_name_table.value ' . $dir); - return $this; - } - - /** - * Get sum of items collection qty - * - * @return int - */ - public function getItemsQty(){ - if (is_null($this->_itemsQty)) { - $this->_itemsQty = 0; - foreach ($this as $wishlistItem) { - $qty = $wishlistItem->getQty(); - $this->_itemsQty += ($qty === 0) ? 1 : $qty; - } - } - - return (int)$this->_itemsQty; - } } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option.php index 47fec2571f..0857fd2580 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,10 +31,6 @@ * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Item_Option extends Mage_Core_Model_Mysql4_Abstract +class Mage_Wishlist_Model_Mysql4_Item_Option extends Mage_Wishlist_Model_Resource_Item_Option { - protected function _construct() - { - $this->_init('wishlist/item_option', 'option_id'); - } } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option/Collection.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option/Collection.php index b69da1838e..849b93318c 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Item/Option/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,144 +32,6 @@ * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Item_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Wishlist_Model_Mysql4_Item_Option_Collection extends Mage_Wishlist_Model_Resource_Item_Option_Collection { - /** - * Array of option ids grouped by item id - * - * @var array - */ - protected $_optionsByItem = array(); - - /** - * Array of option ids grouped by product id - * - * @var array - */ - protected $_optionsByProduct = array(); - - /** - * Define resource model for collection - * - * @return void - */ - protected function _construct() - { - $this->_init('wishlist/item_option'); - } - - /** - * Fill array of options by item and product - * - * @return Mage_Wishlist_Model_Mysql4_Item_Option_Collection - */ - protected function _afterLoad() - { - parent::_afterLoad(); - - foreach ($this as $option) { - $optionId = $option->getId(); - $itemId = $option->getWishlistItemId(); - $productId = $option->getProductId(); - if (isset($this->_optionsByItem[$itemId])) { - $this->_optionsByItem[$itemId][] = $optionId; - } else { - $this->_optionsByItem[$itemId] = array($optionId); - } - if (isset($this->_optionsByProduct[$productId])) { - $this->_optionsByProduct[$productId][] = $optionId; - } else { - $this->_optionsByProduct[$productId] = array($optionId); - } - } - - return $this; - } - - /** - * Apply quote item(s) filter to collection - * - * @param int | array $item - * @return Mage_Wishlist_Model_Mysql4_Item_Option_Collection - */ - public function addItemFilter($item) - { - if (empty($item)) { - $this->_totalRecords = 0; - $this->_setIsLoaded(true); - //$this->addFieldToFilter('item_id', ''); - } else if (is_array($item)) { - $this->addFieldToFilter('wishlist_item_id', array('in'=>$item)); - } else if ($item instanceof Mage_Wishlist_Model_Item) { - $this->addFieldToFilter('wishlist_item_id', $item->getId()); - } else { - $this->addFieldToFilter('wishlist_item_id', $item); - } - - return $this; - } - - /** - * Get array of all product ids - * - * @return array - */ - public function getProductIds() - { - $this->load(); - - return array_keys($this->_optionsByProduct); - } - - /** - * Get all option for item - * - * @param mixed $item - * @return array - */ - public function getOptionsByItem($item) - { - if ($item instanceof Mage_Wishlist_Model_Item) { - $itemId = $item->getId(); - } else { - $itemId = $item; - } - - $this->load(); - - $options = array(); - if (isset($this->_optionsByItem[$itemId])) { - foreach ($this->_optionsByItem[$itemId] as $optionId) { - $options[] = $this->_items[$optionId]; - } - } - - return $options; - } - - /** - * Get all option for item - * - * @param mixed $item - * @return array - */ - public function getOptionsByProduct($product) - { - if ($product instanceof Mage_Catalog_Model_Product) { - $productId = $product->getId(); - } else { - $productId = $product; - } - - $this->load(); - - $options = array(); - if (isset($this->_optionsByProduct[$productId])) { - foreach ($this->_optionsByProduct[$productId] as $optionId) { - $options[] = $this->_items[$optionId]; - } - } - - return $options; - } } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Product/Collection.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Product/Collection.php index 93a537342b..cd3abea11f 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Product/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Product/Collection.php @@ -20,158 +20,18 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Wishlist Product collection - * Deprecated because after Magento 1.4.2.0 it's impossible - * to use product collection in wishlist * - * @deprecated after 1.4.2.0 - * @category Mage - * @package Mage_Wishlist - * @author Magento Core Team + * @category Mage + * @package Mage_Wishlist + * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Product_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection +class Mage_Wishlist_Model_Mysql4_Product_Collection extends Mage_Wishlist_Model_Resource_Product_Collection { - /** - * Add days in whishlist filter of product collection - * - * @var boolean - */ - protected $_addDaysInWishlist = false; - - - - /** - * Get add days in whishlist filter of product collection flag - * - * @return boolean - */ - public function getDaysInWishlist() - { - return $this->_addDaysInWishlist; - } - - /** - * Set add days in whishlist filter of product collection flag - * - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - public function setDaysInWishlist($flag) - { - $this->_addDaysInWishlist = (bool) $flag; - return $this; - } - - /** - * Add wishlist filter to collection - * - * @param Mage_Wishlist_Model_Wishlist $wishlist - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) - { - $this->joinTable( - array('t_wi' => 'wishlist/item'), - 'product_id=entity_id', - array( - 'product_id' => 'product_id', - 'wishlist_item_description' => 'description', - 'item_store_id' => 'store_id', - 'added_at' => 'added_at', - 'wishlist_id' => 'wishlist_id', - 'wishlist_item_id' => 'wishlist_item_id', - ), - array( - 'wishlist_id' => $wishlist->getId(), - 'store_id' => array('in' => $wishlist->getSharedStoreIds()) - ) - ); - - $this->_productLimitationFilters['store_table'] = 't_wi'; - - $this->setFlag('url_data_object', true); - $this->setFlag('do_not_use_category_id', true); - - return $this; - } - - /** - * Add wishlist sort order - * - * @param string $attribute - * @param string $dir - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - public function addWishListSortOrder($attribute = 'added_at', $dir = 'desc') - { - $this->setOrder($attribute, $dir); - return $this; - } - - /** - * Reset sort order - * - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - public function resetSortOrder() - { - $this->getSelect()->reset(Zend_Db_Select::ORDER); - return $this; - } - - /** - * Add store data (days in wishlist) - * - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - public function addStoreData() - { - if (!$this->getDaysInWishlist()) { - return $this; - } - - $this->setDaysInWishlist(false); - - $dayTable = 't_wi'; //$this->_getAttributeTableAlias('days_in_wishlist'); - - $this->joinField('store_name', 'core/store', 'name', 'store_id=item_store_id'); - $this->joinField('days_in_wishlist', - 'wishlist/item', - "(TO_DAYS('" . (substr(Mage::getSingleton('core/date')->date(), 0, -2) . '00') . "') - TO_DAYS(DATE_ADD(".$dayTable.".added_at, INTERVAL " .(int) Mage::getSingleton('core/date')->getGmtOffset() . " SECOND)))", - 'wishlist_item_id=wishlist_item_id' - ); - - return $this; - } - - /** - * Rewrite retrieve attribute field name for wishlist attributes - * - * @param string $attributeCode - * @return Mage_Wishlist_Model_Mysql4_Product_Collection - */ - protected function _getAttributeFieldName($attributeCode) - { - if ($attributeCode == 'days_in_wishlist') { - return $this->_joinFields[$attributeCode]['field']; - } - return parent::_getAttributeFieldName($attributeCode); - } - - /** - * Prevent loading collection because since Magento 1.4.2.0 it's impossible - * to use product collection in wishlist - * - * @return bool - */ - public function load($printQuery = false, $logQuery = false) - { - return $this; - } } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist.php index 94365f0677..1757a613eb 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,44 +28,10 @@ /** * Wishlist model resource * - * @category Mage - * @package Mage_Wishlist + * @category Mage + * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Wishlist extends Mage_Core_Model_Mysql4_Abstract +class Mage_Wishlist_Model_Mysql4_Wishlist extends Mage_Wishlist_Model_Resource_Wishlist { - - protected $_itemsCount = null; - - protected $_customerIdFieldName = 'customer_id'; - - protected function _construct() - { - $this->_init('wishlist/wishlist', 'wishlist_id'); - } - - public function getCustomerIdFieldName() - { - return $this->_customerIdFieldName; - } - - public function setCustomerIdFieldName($fieldName) - { - $this->_customerIdFieldName = $fieldName; - return $this; - } - - public function fetchItemsCount(Mage_Wishlist_Model_Wishlist $wishlist) - { - if (is_null($this->_itemsCount)) { - $collection = $wishlist->getItemCollection() - ->addStoreFilter() - ->setVisibilityFilter(); - - $this->_itemsCount = $collection->getSize(); - } - - return $this->_itemsCount; - } - } diff --git a/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist/Collection.php b/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist/Collection.php index 6ac3b4599d..3d557c78ad 100644 --- a/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist/Collection.php +++ b/app/code/core/Mage/Wishlist/Model/Mysql4/Wishlist/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,17 +28,10 @@ /** * Wislist model collection * - * @category Mage - * @package Mage_Wishlist + * @category Mage + * @package Mage_Wishlist * @author Magento Core Team */ -class Mage_Wishlist_Model_Mysql4_Wishlist_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +class Mage_Wishlist_Model_Mysql4_Wishlist_Collection extends Mage_Wishlist_Model_Resource_Wishlist_Collection { - /** - * Initialize resource - */ - protected function _construct() - { - $this->_init('wishlist/wishlist'); - } } diff --git a/app/code/core/Mage/Wishlist/Model/Observer.php b/app/code/core/Mage/Wishlist/Model/Observer.php index 9062f875b0..8ef8f28add 100644 --- a/app/code/core/Mage/Wishlist/Model/Observer.php +++ b/app/code/core/Mage/Wishlist/Model/Observer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Helper/Mysql4.php b/app/code/core/Mage/Wishlist/Model/Resource/Helper/Mysql4.php new file mode 100644 index 0000000000..38760decce --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Helper/Mysql4.php @@ -0,0 +1,51 @@ + + */ +class Mage_Wishlist_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_Helper_Mysql4 +{ + /** + * Retrieve SQL fragment to calculate days in wishlist depending on current store settings + * + * @return Zend_Db_Expr + */ + public function getDaysInWishlist() + { + $offsetFromDb = (int) Mage::getSingleton('core/date')->getGmtOffset(); + $startDate = "DATE_ADD(added_at, INTERVAL " . $offsetFromDb . " SECOND)"; + + $nowDate = Mage::getSingleton('core/date')->date(); + + return $this->getDateDiff($startDate, $this->_getReadAdapter()->formatDate($nowDate)); + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item.php b/app/code/core/Mage/Wishlist/Model/Resource/Item.php new file mode 100755 index 0000000000..3974c327b8 --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item.php @@ -0,0 +1,76 @@ + + */ +class Mage_Wishlist_Model_Resource_Item extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Initialize connection and define main table + * + */ + protected function _construct() + { + $this->_init('wishlist/item', 'wishlist_item_id'); + } + + /** + * Load item by wishlist, product and shared stores + * + * @param Mage_Wishlist_Model_Item $object + * @param int $wishlistId + * @param int $productId + * @param array $sharedStores + * @return Mage_Wishlist_Model_Resource_Item + */ + public function loadByProductWishlist($object, $wishlistId, $productId, $sharedStores) + { + $adapter = $this->_getReadAdapter(); + $storeWhere = $adapter->quoteInto('store_id IN (?)', $sharedStores); + $select = $adapter->select() + ->from($this->getMainTable()) + ->where('wishlist_id=:wishlist_id AND ' + . 'product_id=:product_id AND ' + . $storeWhere); + $bind = array( + 'wishlist_id' => $wishlistId, + 'product_id' => $productId + ); + $data = $adapter->fetchRow($select, $bind); + if ($data) { + $object->setData($data); + } + $this->_afterLoad($object); + + return $this; + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php new file mode 100755 index 0000000000..70c46d151e --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item/Collection.php @@ -0,0 +1,450 @@ + + */ +class Mage_Wishlist_Model_Resource_Item_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Product Visibility Filter to product collection flag + * + * @var bool + */ + protected $_productVisible = false; + + /** + * Product Salable Filter to product collection flag + * + * @var bool + */ + protected $_productSalable = false; + + /** + * If product out of stock, its item will be removed after load + * + * @var bool + */ + protected $_productInStock = false; + + /** + * Product Ids array + * + * @var array + */ + protected $_productIds = array(); + + /** + * Store Ids array + * + * @var array + */ + protected $_storeIds = array(); + + /** + * Add days in whishlist filter of product collection + * + * @var boolean + */ + protected $_addDaysInWishlist = false; + + /** + * Sum of items collection qty + * + * @var int + */ + protected $_itemsQty; + + /** + * Whether product name attribute value table is joined in select + * + * @var boolean + */ + protected $_isProductNameJoined = false; + + /** + * Initialize resource model for collection + * + * @return void + */ + public function _construct() + { + $this->_init('wishlist/item'); + $this->addFilterToMap('store_id', 'main_table.store_id'); + } + + /** + * After load processing + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + /** + * Assign products + */ + $this->_assignOptions(); + $this->_assignProducts(); + $this->resetItemsDataChanged(); + + $this->getPageSize(); + + return $this; + } + + /** + * Add options to items + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + protected function _assignOptions() + { + $itemIds = array_keys($this->_items); + $optionCollection = Mage::getModel('wishlist/item_option')->getCollection() + ->addItemFilter($itemIds); + foreach ($this as $item) { + $item->setOptions($optionCollection->getOptionsByItem($item)); + } + $productIds = $optionCollection->getProductIds(); + $this->_productIds = array_merge($this->_productIds, $productIds); + + return $this; + } + + /** + * Add products to items and item options + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + protected function _assignProducts() + { + Varien_Profiler::start('WISHLIST:'.__METHOD__); + $productIds = array(); + foreach ($this as $item) { + $productIds[$item->getProductId()] = 1; + } + $this->_productIds = array_merge($this->_productIds, array_keys($productIds)); + $attributes = Mage::getSingleton('wishlist/config')->getProductAttributes(); + $productCollection = Mage::getModel('catalog/product')->getCollection() + ->addIdFilter($this->_productIds) + ->addAttributeToSelect($attributes) + ->addOptionsToResult() + ->addPriceData() + ->addUrlRewrite(); + + if ($this->_productVisible) { + Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($productCollection); + } + if ($this->_productSalable) { + $productCollection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($productCollection); + } + + foreach ($this->_storeIds as $id) { + $productCollection->addStoreFilter($id); + } + + Mage::dispatchEvent('wishlist_item_collection_products_after_load', array( + 'product_collection' => $productCollection + )); + + foreach ($this as $item) { + $product = $productCollection->getItemById($item->getProductId()); + if ($product) { + if (!$this->_productInStock && + !$product->isSalable() && + !Mage::helper('cataloginventory')->isShowOutOfStock()) { + $this->removeItemByKey($item->getId()); + } else { + $product->setCustomOptions(array()); + $item->setProduct($product); + $item->setProductName($product->getName()); + $item->setName($product->getName()); + $item->setPrice($product->getPrice()); + } + } else { + $item->isDeleted(true); + } + } + + Varien_Profiler::stop('WISHLIST:'.__METHOD__); + + return $this; + } + + /** + * Add filter by wishlist object + * + * @param Mage_Wishlist_Model_Wishlist $wishlist + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) + { + $this->addFieldToFilter('wishlist_id', $wishlist->getId()); + return $this; + } + + /** + * Add filter by shared stores + * + * @param int|array $store + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addStoreFilter($store = null) + { + if (is_null($store)) { + $store = Mage::app()->getStore()->getId(); + } + + if (!is_array($store)) { + $store = array($store); + } + $this->_storeIds = $store; + + $this->addFieldToFilter('store_id', $store); + return $this; + } + + /** + * Add items store data to collection + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addStoreData() + { + $storeTable = Mage::getSingleton('core/resource')->getTableName('core/store'); + $this->getSelect()->join(array('store'=>$storeTable), 'main_table.store_id=store.store_id', array( + 'store_name'=>'name', + 'item_store_id' => 'store_id' + )); + return $this; + } + + /** + * Add wishlist sort order + * + * @param string $attribute + * @param string $dir + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addWishListSortOrder($attribute = 'added_at', $dir = 'desc') + { + $this->setOrder($attribute, $dir); + return $this; + } + + /** + * Reset sort order + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function resetSortOrder() + { + $this->getSelect()->reset(Zend_Db_Select::ORDER); + return $this; + } + + /** + * Set product Visibility Filter to product collection flag + * + * @param bool $flag + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function setVisibilityFilter($flag = true) + { + $this->_productVisible = (bool)$flag; + return $this; + } + + /** + * Set Salable Filter. + * This filter apply Salable Product Types Filter to product collection. + * + * @param bool $flag + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function setSalableFilter($flag = true) + { + $this->_productSalable = (bool)$flag; + return $this; + } + + /** + * Set In Stock Filter. + * This filter remove items with no salable product. + * + * @param bool $flag + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function setInStockFilter($flag = true) + { + $this->_productInStock = (bool)$flag; + return $this; + } + + /** + * Set add days in whishlist + * + * This method appears in 1.5.0.0 in deprecated state, because: + * - we need it to make wishlist item collection interface as much as possible compatible with old + * wishlist product collection + * - this method is useless because we can calculate days in php, and don't use MySQL for it + * + * @deprecated after 1.4.2.0 + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addDaysInWishlist() + { + $this->_addDaysInWishlist = true; + + $dateDiff = Mage::getResourceHelper('wishlist') + ->getDaysInWishlist(); + $this->getSelect()->columns(array('days_in_wishlist' => $dateDiff)); + + return $this; + } + + /** + * Adds filter on days in wishlist + * + * $constraints may contain 'from' and 'to' indexes with number of days to look for items + * + * @param array $constraints + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addDaysFilter($constraints) + { + if (!is_array($constraints)) { + return $this; + } + + $filter = array(); + + $now = Mage::getSingleton('core/date')->date(); + $gmtOffset = (int) Mage::getSingleton('core/date')->getGmtOffset(); + if (isset($constraints['from'])) { + $lastDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $lastDay->subSecond($gmtOffset) + ->subDay($constraints['from'] - 1); + $filter['to'] = $lastDay; + } + + if (isset($constraints['to'])) { + $firstDay = new Zend_Date($now, Varien_Date::DATETIME_INTERNAL_FORMAT); + $firstDay->subSecond($gmtOffset) + ->subDay($constraints['to']); + $filter['from'] = $firstDay; + } + + if ($filter) { + $filter['datetime'] = true; + $this->addFieldToFilter('added_at', $filter); + } + + return $this; + } + + /** + * Joins product name attribute value to use it in WHERE and ORDER clauses + * + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + protected function _joinProductNameTable() + { + if (!$this->_isProductNameJoined) { + $entityTypeId = Mage::getResourceModel('catalog/config') + ->getEntityTypeId(); + $attribute = Mage::getModel('catalog/entity_attribute') + ->loadByCode($entityTypeId, 'name'); + + $storeId = Mage::app()->getStore()->getId(); + + $this->getSelect() + ->join( + array('product_name_table' => $attribute->getBackendTable()), + 'product_name_table.entity_id=main_table.product_id' . + ' AND product_name_table.store_id=' . $storeId . + ' AND product_name_table.attribute_id=' . $attribute->getId(). + ' AND product_name_table.entity_type_id=' . $entityTypeId, + array() + ); + + $this->_isProductNameJoined = true; + } + return $this; + } + + /** + * Adds filter on product name + * + * @param string $productName + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function addProductNameFilter($productName) + { + $this->_joinProductNameTable(); + $this->getSelect() + ->where('INSTR(product_name_table.value, ?)', $productName); + + return $this; + } + + /** + * Sets ordering by product name + * + * @param string $dir + * @return Mage_Wishlist_Model_Resource_Item_Collection + */ + public function setOrderByProductName($dir) + { + $this->_joinProductNameTable(); + $this->getSelect()->order('product_name_table.value ' . $dir); + return $this; + } + + /** + * Get sum of items collection qty + * + * @return int + */ + public function getItemsQty(){ + if (is_null($this->_itemsQty)) { + $this->_itemsQty = 0; + foreach ($this as $wishlistItem) { + $qty = $wishlistItem->getQty(); + $this->_itemsQty += ($qty === 0) ? 1 : $qty; + } + } + + return (int)$this->_itemsQty; + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item/Option.php b/app/code/core/Mage/Wishlist/Model/Resource/Item/Option.php new file mode 100644 index 0000000000..a47a869966 --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item/Option.php @@ -0,0 +1,40 @@ + + */ +class Mage_Wishlist_Model_Resource_Item_Option extends Mage_Core_Model_Resource_Db_Abstract +{ + protected function _construct() + { + $this->_init('wishlist/item_option', 'option_id'); + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Item/Option/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Item/Option/Collection.php new file mode 100644 index 0000000000..c9336178c4 --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Item/Option/Collection.php @@ -0,0 +1,174 @@ + + */ +class Mage_Wishlist_Model_Resource_Item_Option_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Array of option ids grouped by item id + * + * @var array + */ + protected $_optionsByItem = array(); + + /** + * Array of option ids grouped by product id + * + * @var array + */ + protected $_optionsByProduct = array(); + + /** + * Define resource model for collection + * + * @return void + */ + protected function _construct() + { + $this->_init('wishlist/item_option'); + } + + /** + * Fill array of options by item and product + * + * @return Mage_Wishlist_Model_Resource_Item_Option_Collection + */ + protected function _afterLoad() + { + parent::_afterLoad(); + + foreach ($this as $option) { + $optionId = $option->getId(); + $itemId = $option->getWishlistItemId(); + $productId = $option->getProductId(); + if (isset($this->_optionsByItem[$itemId])) { + $this->_optionsByItem[$itemId][] = $optionId; + } else { + $this->_optionsByItem[$itemId] = array($optionId); + } + if (isset($this->_optionsByProduct[$productId])) { + $this->_optionsByProduct[$productId][] = $optionId; + } else { + $this->_optionsByProduct[$productId] = array($optionId); + } + } + + return $this; + } + + /** + * Apply quote item(s) filter to collection + * + * @param int|array $item + * @return Mage_Wishlist_Model_Resource_Item_Option_Collection + */ + public function addItemFilter($item) + { + if (empty($item)) { + $this->_totalRecords = 0; + $this->_setIsLoaded(true); + } else if (is_array($item)) { + $this->addFieldToFilter('wishlist_item_id', array('in' => $item)); + } else if ($item instanceof Mage_Wishlist_Model_Item) { + $this->addFieldToFilter('wishlist_item_id', $item->getId()); + } else { + $this->addFieldToFilter('wishlist_item_id', $item); + } + + return $this; + } + + /** + * Get array of all product ids + * + * @return array + */ + public function getProductIds() + { + $this->load(); + + return array_keys($this->_optionsByProduct); + } + + /** + * Get all option for item + * + * @param mixed $item + * @return array + */ + public function getOptionsByItem($item) + { + if ($item instanceof Mage_Wishlist_Model_Item) { + $itemId = $item->getId(); + } else { + $itemId = $item; + } + + $this->load(); + + $options = array(); + if (isset($this->_optionsByItem[$itemId])) { + foreach ($this->_optionsByItem[$itemId] as $optionId) { + $options[] = $this->_items[$optionId]; + } + } + + return $options; + } + + /** + * Get all option for item + * + * @param mixed $item + * @return array + */ + public function getOptionsByProduct($product) + { + if ($product instanceof Mage_Catalog_Model_Product) { + $productId = $product->getId(); + } else { + $productId = $product; + } + + $this->load(); + + $options = array(); + if (isset($this->_optionsByProduct[$productId])) { + foreach ($this->_optionsByProduct[$productId] as $optionId) { + $options[] = $this->_items[$optionId]; + } + } + + return $options; + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Product/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Product/Collection.php new file mode 100755 index 0000000000..466e09e2b3 --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Product/Collection.php @@ -0,0 +1,183 @@ + + */ +class Mage_Wishlist_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection +{ + /** + * Add days in whishlist filter of product collection + * + * @var boolean + */ + protected $_addDaysInWishlist = false; + + /** + * Wishlist item table alias + * @var string + */ + protected $_wishlistItemTableAlias = 't_wi'; + + /** + * Get add days in whishlist filter of product collection flag + * + * @return boolean + */ + public function getDaysInWishlist() + { + return $this->_addDaysInWishlist; + } + + /** + * Set add days in whishlist filter of product collection flag + * + * @param unknown_type $flag + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + public function setDaysInWishlist($flag) + { + $this->_addDaysInWishlist = (bool) $flag; + return $this; + } + + /** + * Add wishlist filter to collection + * + * @param Mage_Wishlist_Model_Wishlist $wishlist + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + public function addWishlistFilter(Mage_Wishlist_Model_Wishlist $wishlist) + { + $this->joinTable( + array($this->_wishlistItemTableAlias => 'wishlist/item'), + 'product_id=entity_id', + array( + 'product_id' => 'product_id', + 'wishlist_item_description' => 'description', + 'item_store_id' => 'store_id', + 'added_at' => 'added_at', + 'wishlist_id' => 'wishlist_id', + 'wishlist_item_id' => 'wishlist_item_id', + ), + array( + 'wishlist_id' => $wishlist->getId(), + 'store_id' => array('in' => $wishlist->getSharedStoreIds()) + ) + ); + + $this->_productLimitationFilters['store_table'] = $this->_wishlistItemTableAlias; + + $this->setFlag('url_data_object', true); + $this->setFlag('do_not_use_category_id', true); + + return $this; + } + + /** + * Add wishlist sort order + * + * @param string $attribute + * @param string $dir + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + public function addWishListSortOrder($attribute = 'added_at', $dir = 'desc') + { + $this->setOrder($attribute, $dir); + return $this; + } + + /** + * Reset sort order + * + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + public function resetSortOrder() + { + $this->getSelect()->reset(Zend_Db_Select::ORDER); + return $this; + } + + /** + * Add store data (days in wishlist) + * + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + public function addStoreData() + { + $adapter = $this->getConnection(); + if (!$this->getDaysInWishlist()) { + return $this; + } + + $this->setDaysInWishlist(false); + + $resourceHelper = Mage::getResourceHelper('core'); + $nowDate = $adapter->formatDate(Mage::getSingleton('core/date')->date()); + + $this->joinField('store_name', 'core/store', 'name', 'store_id=item_store_id'); + $this->joinField('days_in_wishlist', + 'wishlist/item', + $resourceHelper->getDateDiff($this->_wishlistItemTableAlias . '.added_at', $nowDate), + 'wishlist_item_id=wishlist_item_id' + ); + + return $this; + } + + /** + * Rewrite retrieve attribute field name for wishlist attributes + * + * @param string $attributeCode + * @return Mage_Wishlist_Model_Resource_Product_Collection + */ + protected function _getAttributeFieldName($attributeCode) + { + if ($attributeCode == 'days_in_wishlist') { + return $this->_joinFields[$attributeCode]['field']; + } + return parent::_getAttributeFieldName($attributeCode); + } + + /** + * Prevent loading collection because after Magento 1.4.2.0 it's impossible + * to use product collection in wishlist + * + * @return bool + */ + public function load($printQuery = false, $logQuery = false) + { + return $this; + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Resource/Wishlist.php new file mode 100755 index 0000000000..e0d7394bed --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Wishlist.php @@ -0,0 +1,100 @@ + + */ +class Mage_Wishlist_Model_Resource_Wishlist extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Items count + * + * @var int + */ + protected $_itemsCount = null; + + /** + * CustomerId field name + * + * @var string + */ + protected $_customerIdFieldName = 'customer_id'; + + /** + * Wishlist constructor + * + */ + protected function _construct() + { + $this->_init('wishlist/wishlist', 'wishlist_id'); + } + + /** + * CustomerId field name getter + * + * @return string + */ + public function getCustomerIdFieldName() + { + return $this->_customerIdFieldName; + } + + /** + * CustomerId field name setter + * + * @param string $fieldName + * @return Mage_Wishlist_Model_Resource_Wishlist + */ + public function setCustomerIdFieldName($fieldName) + { + $this->_customerIdFieldName = $fieldName; + return $this; + } + + /** + * Fetch items count + * + * @param Mage_Wishlist_Model_Wishlist $wishlist + * @return int + */ + public function fetchItemsCount(Mage_Wishlist_Model_Wishlist $wishlist) + { + if (is_null($this->_itemsCount)) { + $collection = $wishlist->getItemCollection() + ->addStoreFilter() + ->setVisibilityFilter(); + + $this->_itemsCount = $collection->getSize(); + } + + return $this->_itemsCount; + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Resource/Wishlist/Collection.php b/app/code/core/Mage/Wishlist/Model/Resource/Wishlist/Collection.php new file mode 100755 index 0000000000..26142332fd --- /dev/null +++ b/app/code/core/Mage/Wishlist/Model/Resource/Wishlist/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_Wishlist_Model_Resource_Wishlist_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Initialize resource + * + */ + protected function _construct() + { + $this->_init('wishlist/wishlist'); + } +} diff --git a/app/code/core/Mage/Wishlist/Model/Session.php b/app/code/core/Mage/Wishlist/Model/Session.php index c4a118ad4b..0e8f11bef7 100644 --- a/app/code/core/Mage/Wishlist/Model/Session.php +++ b/app/code/core/Mage/Wishlist/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -30,7 +30,7 @@ * * @category Mage * @package Mage_Wishlist - * @author Magento Core Team + * @author Magento Core Team */ class Mage_Wishlist_Model_Session extends Mage_Core_Model_Session_Abstract { diff --git a/app/code/core/Mage/Wishlist/Model/Wishlist.php b/app/code/core/Mage/Wishlist/Model/Wishlist.php index cf8456109c..18e92a921c 100644 --- a/app/code/core/Mage/Wishlist/Model/Wishlist.php +++ b/app/code/core/Mage/Wishlist/Model/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -28,9 +28,18 @@ /** * Wishlist model * - * @category Mage - * @package Mage_Wishlist - * @author Magento Core Team + * @method Mage_Wishlist_Model_Resource_Wishlist _getResource() + * @method Mage_Wishlist_Model_Resource_Wishlist getResource() + * @method int getShared() + * @method Mage_Wishlist_Model_Wishlist setShared(int $value) + * @method string getSharingCode() + * @method Mage_Wishlist_Model_Wishlist setSharingCode(string $value) + * @method string getUpdatedAt() + * @method Mage_Wishlist_Model_Wishlist setUpdatedAt(string $value) + * + * @category Mage + * @package Mage_Wishlist + * @author Magento Core Team */ class Mage_Wishlist_Model_Wishlist extends Mage_Core_Model_Abstract { @@ -313,7 +322,9 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false continue; } $candidate->setWishlistStoreId($storeId); - $item = $this->_addCatalogProduct($candidate, $candidate->getQty(), $forciblySetQty); + + $qty = $candidate->getQty() ? $candidate->getQty() : 1; // No null values as qty. Convert zero to 1. + $item = $this->_addCatalogProduct($candidate, $qty, $forciblySetQty); $items[] = $item; // Collect errors instead of throwing first one diff --git a/app/code/core/Mage/Wishlist/controllers/IndexController.php b/app/code/core/Mage/Wishlist/controllers/IndexController.php index 4f24efb1bd..465fe24a64 100644 --- a/app/code/core/Mage/Wishlist/controllers/IndexController.php +++ b/app/code/core/Mage/Wishlist/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -358,7 +358,7 @@ public function removeAction() $id = (int) $this->getRequest()->getParam('item'); $item = Mage::getModel('wishlist/item')->load($id); - if($item->getWishlistId()==$wishlist->getId()) { + if($item->getWishlistId() == $wishlist->getId()) { try { $item->delete(); $wishlist->save(); @@ -468,9 +468,9 @@ public function sendAction() return $this->_redirect('*/*/'); } - $emails = explode(',', $this->getRequest()->getPost('emails')); - $message= nl2br(htmlspecialchars((string) $this->getRequest()->getPost('message'))); - $error = false; + $emails = explode(',', $this->getRequest()->getPost('emails')); + $message = nl2br(htmlspecialchars((string) $this->getRequest()->getPost('message'))); + $error = false; if (empty($emails)) { $error = $this->__('Email address can\'t be empty.'); } @@ -523,7 +523,8 @@ public function sendAction() 'addAllLink' => Mage::getUrl('*/shared/allcart', array('code' => $wishlist->getSharingCode())), 'viewOnSiteLink'=> Mage::getUrl('*/shared/index', array('code' => $wishlist->getSharingCode())), 'message' => $message - )); + ) + ); } $wishlist->setShared(1); diff --git a/app/code/core/Mage/Wishlist/controllers/SharedController.php b/app/code/core/Mage/Wishlist/controllers/SharedController.php index 714790ecee..afa38845c1 100644 --- a/app/code/core/Mage/Wishlist/controllers/SharedController.php +++ b/app/code/core/Mage/Wishlist/controllers/SharedController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/etc/adminhtml.xml b/app/code/core/Mage/Wishlist/etc/adminhtml.xml index 1e11a34585..207896588b 100644 --- a/app/code/core/Mage/Wishlist/etc/adminhtml.xml +++ b/app/code/core/Mage/Wishlist/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Wishlist/etc/config.xml b/app/code/core/Mage/Wishlist/etc/config.xml index f0838dc179..511cfbadbc 100644 --- a/app/code/core/Mage/Wishlist/etc/config.xml +++ b/app/code/core/Mage/Wishlist/etc/config.xml @@ -21,14 +21,14 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 0.7.9 + 1.6.0.0 @@ -40,10 +40,11 @@ Mage_Wishlist_Model - wishlist_mysql4 + wishlist_resource - - Mage_Wishlist_Model_Mysql4 + + Mage_Wishlist_Model_Resource + wishlist_mysql4 wishlist
      @@ -56,7 +57,7 @@ wishlist_item_option
      -
      +
      @@ -121,13 +122,13 @@ - - - - wishlist.xml - - - + + + + wishlist.xml + + + @@ -161,7 +162,6 @@ - diff --git a/app/code/core/Mage/Wishlist/etc/system.xml b/app/code/core/Mage/Wishlist/etc/system.xml index cf23736075..67d8670481 100644 --- a/app/code/core/Mage/Wishlist/etc/system.xml +++ b/app/code/core/Mage/Wishlist/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/install-1.6.0.0.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/install-1.6.0.0.php new file mode 100644 index 0000000000..d831327bb6 --- /dev/null +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/install-1.6.0.0.php @@ -0,0 +1,145 @@ +startSetup(); + +/** + * Create table 'wishlist/wishlist' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('wishlist/wishlist')) + ->addColumn('wishlist_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Wishlist ID') + ->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Customer ID') + ->addColumn('shared', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Sharing flag (0 or 1)') + ->addColumn('sharing_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + ), 'Sharing encrypted code') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Last updated date') + ->addIndex($installer->getIdxName('wishlist/wishlist', 'shared'), 'shared') + ->addIndex($installer->getIdxName('wishlist/wishlist', 'customer_id', Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + 'customer_id', + array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)) + ->addForeignKey($installer->getFkName('wishlist/wishlist', 'customer_id', 'customer/entity', 'entity_id'), + 'customer_id', $installer->getTable('customer/entity'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Wishlist main Table'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'wishlist/item' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('wishlist/item')) + ->addColumn('wishlist_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Wishlist item ID') + ->addColumn('wishlist_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Wishlist ID') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Product ID') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => true, + ), 'Store ID') + ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Add date and time') + ->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + ), 'Short description of wish list item') + ->addColumn('qty', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array( + 'nullable' => false, + ), 'Qty') + ->addIndex($installer->getIdxName('wishlist/item', 'wishlist_id'), 'wishlist_id') + ->addForeignKey($installer->getFkName('wishlist/item', 'wishlist_id', 'wishlist/wishlist', 'wishlist_id'), + 'wishlist_id', $installer->getTable('wishlist/wishlist'), 'wishlist_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('wishlist/item', 'product_id'), 'product_id') + ->addForeignKey($installer->getFkName('wishlist/item', 'product_id', 'catalog/product', 'entity_id'), + 'product_id', $installer->getTable('catalog/product'), 'entity_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->addIndex($installer->getIdxName('wishlist/item', 'store_id'), 'store_id') + ->addForeignKey($installer->getFkName('wishlist/item', 'store_id', 'core/store', 'store_id'), + 'store_id', $installer->getTable('core/store'), 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Wishlist items'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'wishlist/item_option' + */ +$table = $installer->getConnection() + ->newTable($installer->getTable('wishlist/item_option')) + ->addColumn('option_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Option Id') + ->addColumn('wishlist_item_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Wishlist Item Id') + ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Product Id') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Code') + ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Value') + ->addForeignKey($installer->getFkName('wishlist/item_option', 'wishlist_item_id', 'wishlist/item', 'wishlist_item_id'), + 'wishlist_item_id', $installer->getTable('wishlist/item'), 'wishlist_item_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE) + ->setComment('Wishlist Item Option Table'); +$installer->getConnection()->createTable($table); + +$installer->endSetup(); diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-install-0.7.0.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-install-0.7.0.php index 57375e17be..6ce20da535 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-install-0.7.0.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-install-0.7.0.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.0-0.7.1.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.0-0.7.1.php index 3219c36b31..99959a99db 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.0-0.7.1.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.0-0.7.1.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.1-0.7.2.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.1-0.7.2.php index e4698736a7..a4a6a7818e 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.1-0.7.2.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.1-0.7.2.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.2-0.7.4.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.2-0.7.4.php index 341e276e33..a675cd4f33 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.2-0.7.4.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.2-0.7.4.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.4-0.7.5.php index a16773f924..a3983c5c1b 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.4-0.7.5.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.5-0.7.6.php index 0f9c9eb00f..5983890e2b 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.5-0.7.6.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -20,7 +20,6 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.6-0.7.7.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.6-0.7.7.php index dab96d8c27..0e985ece64 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.6-0.7.7.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.6-0.7.7.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.7-0.7.8.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.7-0.7.8.php index 25df247641..7d3bfc6a9f 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.7-0.7.8.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.7-0.7.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.8-0.7.9.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.8-0.7.9.php index 003838869f..44d5b5f63f 100644 --- a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.8-0.7.9.php +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-0.7.8-0.7.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Wishlist - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100644 index 0000000000..8ac50f22da --- /dev/null +++ b/app/code/core/Mage/Wishlist/sql/wishlist_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,306 @@ +startSetup(); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $installer->getTable('wishlist/wishlist'), + 'FK_WISHLIST_CUSTOMER' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('wishlist/item'), + 'FK_WISHLIST_ITEM_PRODUCT' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('wishlist/item'), + 'FK_WISHLIST_ITEM_STORE' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('wishlist/item'), + 'FK_WISHLIST_ITEM_WISHLIST' +); + +$installer->getConnection()->dropForeignKey( + $installer->getTable('wishlist/item_option'), + 'FK_WISHLIST_ITEM_OPTION_ITEM_ID' +); + + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/wishlist'), + 'UNQ_CUSTOMER' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/wishlist'), + 'IDX_IS_SHARED' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/item'), + 'IDX_WISHLIST' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/item'), + 'IDX_PRODUCT' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/item'), + 'IDX_STORE' +); + +$installer->getConnection()->dropIndex( + $installer->getTable('wishlist/item_option'), + 'FK_WISHLIST_ITEM_OPTION_ITEM_ID' +); + + +/** + * Change columns + */ +$tables = array( + $installer->getTable('wishlist/wishlist') => array( + 'columns' => array( + 'wishlist_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Wishlist ID' + ), + 'customer_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Customer ID' + ), + 'shared' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Sharing flag (0 or 1)' + ), + 'sharing_code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'comment' => 'Sharing encrypted code' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Last updated date' + ) + ), + 'comment' => 'Wishlist main Table' + ), + $installer->getTable('wishlist/item') => array( + 'columns' => array( + 'wishlist_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Wishlist item ID' + ), + 'wishlist_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Wishlist ID' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Product ID' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store ID' + ), + 'added_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'comment' => 'Add date and time' + ), + 'description' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'comment' => 'Short description of wish list item' + ), + 'qty' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, + 'scale' => 4, + 'precision' => 12, + 'nullable' => false, + 'comment' => 'Qty' + ) + ), + 'comment' => 'Wishlist items' + ), + $installer->getTable('wishlist/item_option') => array( + 'columns' => array( + 'option_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Option Id' + ), + 'wishlist_item_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Wishlist Item Id' + ), + 'product_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Product Id' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Code' + ), + 'value' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64K', + 'nullable' => false, + 'comment' => 'Value' + ) + ), + 'comment' => 'Wishlist Item Option Table' + ) +); + +$installer->getConnection()->modifyTables($tables); + + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $installer->getTable('wishlist/wishlist'), + $installer->getIdxName( + 'wishlist/wishlist', + array('customer_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('customer_id'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +$installer->getConnection()->addIndex( + $installer->getTable('wishlist/wishlist'), + $installer->getIdxName('wishlist/wishlist', array('shared')), + array('shared') +); + +$installer->getConnection()->addIndex( + $installer->getTable('wishlist/item'), + $installer->getIdxName('wishlist/item', array('wishlist_id')), + array('wishlist_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('wishlist/item'), + $installer->getIdxName('wishlist/item', array('product_id')), + array('product_id') +); + +$installer->getConnection()->addIndex( + $installer->getTable('wishlist/item'), + $installer->getIdxName('wishlist/item', array('store_id')), + array('store_id') +); + + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName('wishlist/wishlist', 'customer_id', 'customer/entity', 'entity_id'), + $installer->getTable('wishlist/wishlist'), + 'customer_id', + $installer->getTable('customer/entity'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('wishlist/item', 'wishlist_id', 'wishlist/wishlist', 'wishlist_id'), + $installer->getTable('wishlist/item'), + 'wishlist_id', + $installer->getTable('wishlist/wishlist'), + 'wishlist_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('wishlist/item', 'product_id', 'catalog/product', 'entity_id'), + $installer->getTable('wishlist/item'), + 'product_id', + $installer->getTable('catalog/product'), + 'entity_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('wishlist/item', 'store_id', 'core/store', 'store_id'), + $installer->getTable('wishlist/item'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName('wishlist/item_option', 'wishlist_item_id', 'wishlist/item', 'wishlist_item_id'), + $installer->getTable('wishlist/item_option'), + 'wishlist_item_id', + $installer->getTable('wishlist/item'), + 'wishlist_item_id' +); + +$installer->endSetup(); diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php index ed4098ba61..08a88462f3 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php index 47f9c31fb6..4a159a7dc5 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/History/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php index 94cf1c86bb..04ceb529da 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php index 46e7c466c9..02bd7a268b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit extends Mage_Adminhtml_Block_Widget_Form_Container diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php index 03a4f7d415..a9a93f2983 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php index 928847adbc..3ac44d0e0f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Submission.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Submission extends Mage_Adminhtml_Block_Widget_Tabs diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php index 91b28a316e..9c73889246 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Cache.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php index b345e31f93..031b42b80f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Content diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php index 866f00b1cc..39e6cbbab7 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php index 25f9874f74..80f3db6d00 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion extends Mage_Adminhtml_Block_Widget_Accordion diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php index d3ca734a6e..b6b737d3c6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Images.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php index 9a3e73b117..ca8cc9e8ca 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php index 1b69c66f1b..85c10048ce 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Accordion/Themes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php index 9918c4cf3f..876a80553a 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Preview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php index 73a865d35b..99e4a642fb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Themes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php index 41dbbfb49c..2216fb75c9 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Flurryanalytics.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php index 83c887e0af..9fe77c41a8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/General.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php index 0382e43ea8..6c14ba4109 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Notification.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Notification diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php index 61fe6de466..7f2c42b671 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php index 9d299b2eab..7b450ae565 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Settings.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php index cf61736fc8..b8d852f8ea 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php index 929e5fa727..9119471835 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Submission/History.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php index 53dd10e18a..3d9042b07f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php index d8a9d1d7c1..02dae6f2a5 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Addrow.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php index 41ad94b739..060d0153b6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Color.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php index 3ecd26aac8..b0c8842e42 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php index 2664be796f..d6d92577a8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Datetime.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php index 63324848c0..c3b7eb4856 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Font.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php index 09a9a6855b..c00f893525 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php index 1150df3d25..5ad9f49ce6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php index 4cffd47ba4..fd676eeefe 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php index 35d5bbeee0..1a1ff95af0 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Theme.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php index ec1bde70a5..4adad9e7da 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Xmlconnect_Block_Adminhtml_Mobile_Grid extends Mage_Adminhtml_Block_Widget_Grid diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php index 3d55817be3..7af683e6cb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Bool.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php index 4b15440113..f1255ce7c6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Grid/Renderer/Type.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php index 1f5403e9c5..a79a5ba9fb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Content.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php index 83cddd688f..6b1100544b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Preview/Tabitems.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php index 0fbe192834..851b51a359 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission extends Mage_Adminhtml_Block_Widget_Form_Container diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php index 9c3b26ae8a..4bba1b6c06 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php index 6301bf5e35..6d0aa59233 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Androidmarket.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php index c076181dc6..55b4aa35c6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Renderer/Country/Istore.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php index d244a1cc0b..f34cb64436 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container extends Mage_Adminhtml_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php index 6f46cde568..814eaabb59 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Container/Submission.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Submission.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Submission.php deleted file mode 100644 index 5f627fdce7..0000000000 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tab/Submission.php +++ /dev/null @@ -1,285 +0,0 @@ -setShowGlobalIcon(true); - - } - - protected function _prepareLayout() - { - $application = Mage::registry('current_app'); - - $actionUrl = $this->getUrl('*/*/submissionPost', array('key' => $application->getId())); - $this->setChild('submission_scripts', - $this->getLayout()->createBlock('adminhtml/template') - ->setActionUrl($actionUrl) - ->setTemplate('xmlconnect/submission_scripts.phtml')); - if ($application->getIsResubmitAction()) { - $block = $this->getLayout()->createBlock('adminhtml/template') - ->setTemplate('xmlconnect/resubmit.phtml') - ->setActionUrl($actionUrl) - ->setActivationKey($application->getActivationKey()) - ->setResubmissionName('conf[submit_text][resubmission_activation_key]'); - $this->setChild('resubmit', $block); - - $block = $this->getLayout()->createBlock('adminhtml/template') - ->setTemplate('xmlconnect/images.phtml') - ->setImages($application->getImages()); - $this->setChild('images', $block); - } - parent::_prepareLayout(); - } - - - /** - * Add image uploader to fieldset - * - * @param Varien_Data_Form_Element_Fieldset $fieldset - * @param string $fieldName - * @param string $title - */ - protected function addImage($fieldset, $fieldName, $title, $note = '') - { - $fieldset->addField($fieldName, 'image', array( - 'name' => $fieldName, - 'label' => $title, - 'note' => !empty($note) ? $note : null, - )); - } - - protected function _prepareForm() - { - $form = new Varien_Data_Form(); - $this->setForm($form); - - $form->setAction($this->getUrl('*/mobile/submission')); - $application = Mage::registry('current_app'); - $isResubmit = $application->getIsResubmitAction(); - $formData = $application->getFormData(); - - $fieldset = $form->addFieldset('submit0', array('legend' => $this->__('Submission Fields'))); - - $fieldset->addField('conf/submit_text/title', 'text', array( - 'name' => 'conf[submit_text][title]', - 'label' => $this->__('Title'), - 'maxlength' => '200', - 'value' => isset($formData['conf[submit_text][title]']) ? $formData['conf[submit_text][title]'] : null, - 'note' => $this->__('This is the name that will appear beneath your app when users install it to their device. . We recommend choosing a name that is 10-12 characters in length, and that your customers will recognize.'), - 'required' => true, - )); - - $field = $fieldset->addField('conf/submit_text/description', 'textarea', array( - 'name' => 'conf[submit_text][description]', - 'label' => $this->__('Description'), - 'maxlength' => '500', - 'value' => isset($formData['conf[submit_text][description]']) ? $formData['conf[submit_text][description]'] : null, - 'note' => $this->__('This is the description that will appear in the iTunes marketplace. '), - 'required' => true, - )); - $field->setRows(15); - - $fieldset->addField('conf/submit_text/username/', 'text', array( - 'name' => 'conf[submit_text][username]', - 'label' => $this->__('Username'), - 'maxlength' => '40', - 'value' => isset($formData['conf[submit_text][username]']) ? $formData['conf[submit_text][username]'] : null, - 'note' => $this->__('Paypal Merchant Account Username.'), - 'required' => true, - )); - - $fieldset->addField('conf/submit_text/email', 'text', array( - 'name' => 'conf[submit_text][email]', - 'label' => $this->__('Email'), - 'class' => 'email', - 'maxlength' => '40', - 'value' => isset($formData['conf[submit_text][email]']) ? $formData['conf[submit_text][email]'] : null, - 'note' => $this->__('Paypal Merchant Account Email.'), - 'required' => true, - )); - - $fieldset->addField('conf/submit_text/price_free', 'radio', array( - 'name' => 'conf[submit_text][price_free]', - 'label' => $this->__('Price'), - 'value' => '1', - 'maxlength' => '40', - 'after_element_html' => $this->__('Free'), - 'onclick' => "$('conf/submit_text/price').setValue('')", - )); - - $fieldset->addField('conf/submit_text/price', 'text', array( - 'name' => 'conf[submit_text][price]', - 'label' => $this->__(' '), - 'maxlength' => '40', - 'value' => isset($formData['conf[submit_text][price]']) ? $formData['conf[submit_text][price]'] : null, - 'note' => $this->__('You can set any price you want for your app, or you can give it away for free. Most apps range from $0.99 - $4.99'), - 'onchange' => "$('conf/submit_text/price_free').checked = false", - - )); - - $selected = isset($formData['conf[submit_text][country]']) ? json_decode($formData['conf[submit_text][country]']) : null; - $fieldset->addField('conf/submit_text/country', 'multiselect', array( - 'name' => 'conf[submit_text][country][]', - 'label' => $this->__('Country'), - 'values' => Mage::helper('xmlconnect')->getCountryOptionsArray(), - 'value' => $selected, - 'note' => $this->__('Make this app available in the following territories'), - )); - - $fieldset->addField('conf/submit_text/country_additional', 'text', array( - 'name' => 'conf[submit_text][country_additional]', - 'label' => $this->__('Additional Countries'), - 'maxlength' => '200', - 'value' => isset($formData['conf[submit_text][country_additional]']) ? $formData['conf[submit_text][country_additional]'] : null, - 'note' => $this->__('You can set any additional countries added by Apple Store.'), - - )); - - $fieldset->addField('conf/submit_text/copyright', 'textarea', array( - 'name' => 'conf[submit_text][copyright]', - 'label' => $this->__('Copyright'), - 'maxlength' => '200', - 'value' => isset($formData['conf[submit_text][copyright]']) ? $formData['conf[submit_text][copyright]'] : null, - 'note' => $this->__('This will appear in the info section of your App (example: Copyright 2010 – Your Company, Inc.)'), - 'size' => '30', - 'required' => true, - )); - - $fieldset->addField('conf/submit_text/push_notification', 'checkbox', array( - 'name' => 'conf[submit_text][push_notification]', - 'label' => $this->__('Push Notification'), - 'checked' => isset($formData['conf[submit_text][push_notification]']), - 'value' => '1', - )); - - $fieldset = $form->addFieldset('submit1', array('legend' => $this->__('Icons'))); - $this->addImage($fieldset, 'conf/submit/icon', 'Application Icon', - $this->__('Apply will automatically resize this image for display in the App Store and on users’ devices. A gloss (i.e. gradient) will also be applied, so you do not need to apply a gradient. Image must be at least 512x512')); - $this->addImage($fieldset, 'conf/submit/loader_image', 'Loader Splash Screen', - $this->__('Users will see this image as the first screen while your application is loading. It is a 320x460 image.')); - - $this->addImage($fieldset, 'conf/submit/logo', $this->__('Custom application icon'), - $this->__('This icon will be used for users’ devices in case if different than AppSore icon needed. ')); - $this->addImage($fieldset, 'conf/submit/big_logo', $this->__('Copyright page logo'), - $this->__('Store logo that will be displayed on copyright page of application ')); - - $fieldset = $form->addFieldset('submit2', array('legend' => $this->__('Key'))); - $fieldset->addField('conf[submit_text][key]', 'text', array( - 'name' => 'conf[submit_text][key]', - 'label' => $this->__('Activation Key'), - 'value' => isset($formData['conf[submit_text][key]']) ? $formData['conf[submit_text][key]'] : null, - 'disabled' => $isResubmit, - 'after_element_html' => '' - . $this->__('Get Activation Key'). '', - )); - - if (!$isResubmit) { - $fieldset->addField('submit_application', 'button', array( - 'name' => 'submit_application', - 'label'=>$this->__('Submit'), - 'value' => $this->__('Submit Application'), - 'onclick' => 'submitApplication()', - )); - } else { - $fieldset->addField('submit_application', 'button', array( - 'name' => 'submit_application', - 'label'=> $this->__('Resubmit'), - 'value' => $this->__('Resubmit Application'), - 'onclick' => 'resubmitAction(); return false;', - )); - } - - return parent::_prepareForm(); - } - - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return $this->__('Submission'); - } - - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->__('Submission'); - } - - /** - * Returns status flag about this tab can be showen or not - * - * @return true - */ - public function canShowTab() - { - return true; - } - - /** - * Returns status flag about this tab hidden or not - * - * @return false - */ - public function isHidden() - { - return false; - } - - /** - * Configure image element type - * - */ - protected function _getAdditionalElementTypes() - { - return array( - 'image' => Mage::getConfig()->getBlockClassName('xmlconnect/adminhtml_mobile_helper_image'), - ); - } - - protected function _toHtml() - { - return parent::_toHtml() - . $this->getChildHtml('submission_scripts') - . (!Mage::registry('current_app')->getIsResubmitAction() ? '' : - ($this->getChildHtml('mobile_edit_tab_submission_history') - . $this->getChildHtml('resubmit') - . $this->getChildHtml('images'))); - } -} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php index 1a1b03ac2b..13d1d819bd 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Submission/Tabs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tabs extends Mage_Adminhtml_Block_Widget_Tabs diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php index 04af93a830..44ee685f87 100644 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Widget/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form extends Mage_Adminhtml_Block_Widget_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php index 547b53c3c7..e9c501591e 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php index 483a924755..c03bf096ac 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php index a64b90e440..2657bd4fc3 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form extends Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php index 3a847290b8..c6e12eec8c 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -33,7 +33,6 @@ */ class Mage_XmlConnect_Block_Adminhtml_Queue_Grid extends Mage_Adminhtml_Block_Widget_Grid { - /** * Constructor * @@ -57,7 +56,10 @@ protected function _prepareCollection() { $collection = Mage::getModel('xmlconnect/queue')->getCollection(); - $collection->addFieldToFilter('main_table.status', array('neq' => Mage_XmlConnect_Model_Queue::STATUS_DELETED)); + $collection->addFieldToFilter( + 'main_table.status', + array('neq' => Mage_XmlConnect_Model_Queue::STATUS_DELETED) + ); $this->setCollection($collection); return parent::_prepareCollection(); } @@ -69,10 +71,10 @@ protected function _prepareCollection() */ protected function _prepareColumns() { - $this->addColumn('id', array( + $this->addColumn('queue_id', array( 'header' => $this->__('ID'), 'align' => 'center', - 'index' => 'main_table.id', + 'index' => 'main_table.queue_id', 'width' => '40px', 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_id' )); @@ -88,7 +90,7 @@ protected function _prepareColumns() $this->addColumn('app_code', array( 'header' => $this->__('Application Name'), 'align' => 'left', - 'index' => 'main_table.app_code', + 'index' => 'app.code', 'type' => 'options', 'options' => Mage::helper('xmlconnect')->getApplications(), 'renderer' => 'xmlconnect/adminhtml_queue_grid_renderer_application' diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php index dfdbb039b9..1cfa571d86 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php index 1b27368e2c..7563ddf483 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Application.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php index 11ae295acc..71c58e040a 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Id.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php index f27cfbe5fa..c086643110 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Msgtitle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php index a5d2b09b91..045c83806c 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Pushtitle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php index b0ac6794c1..dd4f22359a 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Status.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php index 920c371858..27cb02e885 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Queue/Grid/Renderer/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php index ec5a184d1e..21ce0bf34c 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php index 229fd9a12e..b3ee7f5d8f 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php index fef8fdb0bc..4b01f9cbe8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Edit/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form @@ -74,8 +74,8 @@ protected function _prepareForm() )); } - $fieldset->addField('app_code', 'select', array( - 'name' => 'app_code', + $fieldset->addField('application_id', 'select', array( + 'name' => 'application_id', 'label' => $this->__('Application'), 'title' => $this->__('Application'), 'disabled' => $model->getId() || !$this->_fieldsEnabled ? true : false, diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php index 595e5eb268..eb8b356b66 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -67,17 +67,18 @@ protected function _prepareCollection() */ protected function _prepareColumns() { - $this->addColumn('id', array( + $this->addColumn('template_id', array( 'header' => $this->__('ID'), 'align' => 'center', - 'index' => 'id', + 'index' => 'template_id', 'width' => '40px' )); $this->addColumn('name', array( 'header' => $this->__('Template Name'), 'align' => 'left', - 'index' => 'name', + 'index' => 'main_table.name', + 'renderer' => 'xmlconnect/adminhtml_template_grid_renderer_name', 'escape' => true )); @@ -97,7 +98,7 @@ protected function _prepareColumns() $this->addColumn('app_code', array( 'header' => $this->__('Application'), - 'index' => 'app_code', + 'index' => 'app.code', 'type' => 'options', 'align' => 'left', 'options' => Mage::helper('xmlconnect')->getApplications(), diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php index 86ee846a02..ea28360376 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Application.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -31,7 +31,8 @@ * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { /** * Render grid row @@ -41,7 +42,7 @@ class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application extends */ public function render(Varien_Object $row) { - $str = htmlspecialchars($row->getAppName()); + $str = $this->escapeHtml($row->getAppName()); if ($str == '') { $str = ' --- '; } diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Name.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Name.php new file mode 100755 index 0000000000..640dba2fb0 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Grid/Renderer/Name.php @@ -0,0 +1,48 @@ + + */ +class Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Name + extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract +{ + /** + * Render grid row + * + * @param Varien_Object $row + * @return string + */ + public function render(Varien_Object $row) + { + $str = $this->escapeHtml($row->getName()); + return $str; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php index 3cd59feef1..4df9f7d6bf 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php index 884e772f92..30bfc62ed1 100755 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Adminhtml/Template/Preview/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cart.php b/app/code/core/Mage/XmlConnect/Block/Cart.php index 366e64b85b..3fd6a4e10b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php index cbd5c55c85..0d6f6efb19 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Info.php b/app/code/core/Mage/XmlConnect/Block/Cart/Info.php index 133dbef863..01b55fc516 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php index 1519d97139..bd3c9dd66c 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Paypal/Mep/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php b/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php index 641da00632..8f06864452 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php +++ b/app/code/core/Mage/XmlConnect/Block/Cart/Totals.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog.php b/app/code/core/Mage/XmlConnect/Block/Catalog.php index 05cc7e47f2..11a3ac0c7f 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_XmlConnect_Block_Catalog extends Mage_Core_Block_Template diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php index 20ebfdee30..14e3f01d01 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php index 9782ebea06..8642516871 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Category/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php index 90a6e172ee..a73c87f08a 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Filters.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php index 65677597b5..6adf92f6ba 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php index 046764ff70..df552c824e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Attributes.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php index a94058635e..1ea1ed5cc8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Gallery.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php index d37663bcda..d6cf5dcbda 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php index 3b729c822a..4bba8d0c4e 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php index b828df216f..100023eccc 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php index 90ff61a0c0..fc7c22f9ed 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Configurable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php index 6385ec9e8d..1deaf29ac8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Giftcard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php index df38f2f757..021742ab7d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Grouped.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php index 0e5d900f1e..113b9b232c 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php index 177528118d..d8cd010b93 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Options/Virtual.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php index 551c3ea3fd..af3c7ec22b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php index e2c32d67bb..5410ce54b1 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Bundle.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php index 54a500fe44..63a44cffb8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Default.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php index 5d849d4cc8..3219bf68ef 100755 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Price/Giftcard.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php index cf75ce4f60..a1b6a18abc 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Related.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php index 6ae58d495e..58f6dca3ed 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php index e4f5059c6d..47ce452d39 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Product/Review/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php index 3f115ac50e..9dee661fe3 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Search.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php b/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php index ad1d5f8689..0afb3ff789 100644 --- a/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php +++ b/app/code/core/Mage/XmlConnect/Block/Catalog/Search/Suggest.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php index cb27eaf8b2..1624c78cca 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Billing.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php index a2b7c5f61f..3ced72cc06 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php index caa6e4ad3b..f843baa390 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Address/Shipping.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php index 56392fc4d6..433fdcdca6 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Agreements.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php index d1fcf74dbb..e3870290bb 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php index 241c26fb06..8d105d42fe 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Order/Review/Info.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php index 195b34bf3c..7543f57081 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Authorizenet.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php index 4c362ce376..42963b123c 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Ccsave.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php index 6e8c906e97..c5c6032fbd 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Checkmo.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php index 5267ca982d..32bf19c8a8 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php index 55be52c13c..ceb8f11ced 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Direct.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php index 6153b4e65b..140ec5f327 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Paypal/Payflow.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php index f317d1f842..5181f6c0fb 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php index 5acf61c0b5..5fbb893ab6 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Authorizenet.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php index 543891dfee..a06e6a4600 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypal.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php index 357c873f82..d02bdaf9a8 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Paypaluk.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php index 8da1fd514b..9598488315 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Pbridge/Verisign.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php index 72766bc572..cbc2b84c2b 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Payment/Method/Purchaseorder.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php index 109cf9eef8..9cb4ebabbc 100755 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Pbridge/Result.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php index c3ec5f4b79..9b019bc173 100644 --- a/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php +++ b/app/code/core/Mage/XmlConnect/Block/Checkout/Shipping/Method/Avaliable.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Cms/Page.php b/app/code/core/Mage/XmlConnect/Block/Cms/Page.php index eea430042d..2598c21573 100644 --- a/app/code/core/Mage/XmlConnect/Block/Cms/Page.php +++ b/app/code/core/Mage/XmlConnect/Block/Cms/Page.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Configuration.php b/app/code/core/Mage/XmlConnect/Block/Configuration.php index 0013f8ab07..4000eb2cbe 100644 --- a/app/code/core/Mage/XmlConnect/Block/Configuration.php +++ b/app/code/core/Mage/XmlConnect/Block/Configuration.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php b/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php index d5adffe20c..9bdd28cd50 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php b/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php index e3ff77ff71..45dd51c49d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Address/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php index fb1f94ef94..c828121523 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php b/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php index cab202faab..15977b956d 100644 --- a/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php +++ b/app/code/core/Mage/XmlConnect/Block/Customer/Order/List.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Home.php b/app/code/core/Mage/XmlConnect/Block/Home.php index fca2f219ff..54e72600ca 100644 --- a/app/code/core/Mage/XmlConnect/Block/Home.php +++ b/app/code/core/Mage/XmlConnect/Block/Home.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Review/Form.php b/app/code/core/Mage/XmlConnect/Block/Review/Form.php index 326ec30172..bd60c76e76 100644 --- a/app/code/core/Mage/XmlConnect/Block/Review/Form.php +++ b/app/code/core/Mage/XmlConnect/Block/Review/Form.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Block/Wishlist.php b/app/code/core/Mage/XmlConnect/Block/Wishlist.php index aa25c12c49..8dbef83c99 100644 --- a/app/code/core/Mage/XmlConnect/Block/Wishlist.php +++ b/app/code/core/Mage/XmlConnect/Block/Wishlist.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Controller/Action.php b/app/code/core/Mage/XmlConnect/Controller/Action.php index d44417f0e2..1f6d68ad45 100644 --- a/app/code/core/Mage/XmlConnect/Controller/Action.php +++ b/app/code/core/Mage/XmlConnect/Controller/Action.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Android.php b/app/code/core/Mage/XmlConnect/Helper/Android.php index e6954bc556..4a9d2945ad 100755 --- a/app/code/core/Mage/XmlConnect/Helper/Android.php +++ b/app/code/core/Mage/XmlConnect/Helper/Android.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php b/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php index 193d20de8b..e24d48ad61 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php +++ b/app/code/core/Mage/XmlConnect/Helper/Catalog/Category/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Data.php b/app/code/core/Mage/XmlConnect/Helper/Data.php index c7692dd414..8616b76600 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Data.php +++ b/app/code/core/Mage/XmlConnect/Helper/Data.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -585,7 +585,7 @@ public function getApplicationOptions() $options = array(); foreach (Mage::getModel('xmlconnect/application')->getCollection() as $app) { if (self::isTemplateAllowedForApplication($app)) { - $options[] = array('value' => $app->getCode(), 'label' => $app->getName()); + $options[] = array('value' => $app->getId(), 'label' => $app->getName()); } } if (count($options) > 1) { diff --git a/app/code/core/Mage/XmlConnect/Helper/Image.php b/app/code/core/Mage/XmlConnect/Helper/Image.php index 7ed69bf91e..c24fd85701 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Image.php +++ b/app/code/core/Mage/XmlConnect/Helper/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -62,6 +62,7 @@ class Mage_XmlConnect_Helper_Image extends Mage_Core_Helper_Abstract * @var array|null */ protected $_confPaths = null; + /** * Process uploaded file * setup filenames to the configuration @@ -414,15 +415,13 @@ public function getDefaultDesignSuffixAsUrl($image = '') */ public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100) { - $customDirRoot = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'custom'; $screenSize = $width . 'x' . $height; - $customDir = $customDirRoot . DS . $screenSize; + $customDir = $this->getMediaPath('custom' . DS . $screenSize); $this->_verifyDirExist($customDir); $imageUrl = explode('/', $imageUrl); $file = $imageUrl[count($imageUrl)-1]; $filePath = $this->getDefaultSizeUploadDir() . DS . $file; - - if (!file_exists($customDir . $file)) { + if (!file_exists($customDir . DS . $file)) { $image = new Varien_Image($filePath); $widthOriginal = $image->getOriginalWidth(); $heightOriginal = $image->getOriginalHeight(); @@ -445,7 +444,7 @@ public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100) $image->save($customDir, basename($file)); } } - return Mage::getBaseUrl('media') . "xmlconnect/custom/{$screenSize}/" . basename($file); + return $this->getMediaUrl("custom/{$screenSize}/" . basename($file)); } /** @@ -641,9 +640,7 @@ protected function _verifyDirExist($dir) public function getCustomSizeUploadDir($screenSize) { $screenSize = $this->filterScreenSize($screenSize); - $customDirRoot = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'custom'; - $this->_verifyDirExist($customDirRoot); - $customDir = $customDirRoot . DS .$screenSize; + $customDir = $this->getMediaPath('custom' . DS .$screenSize); $this->_verifyDirExist($customDir); return $customDir; } @@ -655,7 +652,7 @@ public function getCustomSizeUploadDir($screenSize) */ public function getOriginalSizeUploadDir() { - $dir = Mage::getBaseDir('media') . DS . 'xmlconnect' . DS . 'original'; + $dir = $this->getMediaPath('original'); $this->_verifyDirExist($dir); return $dir; } @@ -667,7 +664,7 @@ public function getOriginalSizeUploadDir() */ public function getOldUploadDir() { - $dir = Mage::getBaseDir('media') . DS . 'xmlconnect'; + $dir = $this->getMediaPath(); $this->_verifyDirExist($dir); return $dir; } diff --git a/app/code/core/Mage/XmlConnect/Helper/Ipad.php b/app/code/core/Mage/XmlConnect/Helper/Ipad.php index 6ff940871a..d95fa54ab9 100755 --- a/app/code/core/Mage/XmlConnect/Helper/Ipad.php +++ b/app/code/core/Mage/XmlConnect/Helper/Ipad.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Iphone.php b/app/code/core/Mage/XmlConnect/Helper/Iphone.php index 810a9d38f0..1477ade214 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Iphone.php +++ b/app/code/core/Mage/XmlConnect/Helper/Iphone.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Payment.php b/app/code/core/Mage/XmlConnect/Helper/Payment.php index ed6262d333..ca4938fdb4 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Payment.php +++ b/app/code/core/Mage/XmlConnect/Helper/Payment.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Helper/Theme.php b/app/code/core/Mage/XmlConnect/Helper/Theme.php index 10b8e64c1b..a3be3f7212 100644 --- a/app/code/core/Mage/XmlConnect/Helper/Theme.php +++ b/app/code/core/Mage/XmlConnect/Helper/Theme.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 2827d17793..bfeb9dd081 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 43bad9e22e..7d1c69861a 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Application.php b/app/code/core/Mage/XmlConnect/Model/Application.php index 9a761a3f8b..88cfa15cf0 100644 --- a/app/code/core/Mage/XmlConnect/Model/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Application.php @@ -20,13 +20,15 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * @method Mage_XmlConnect_Model_Mysql4_Application _getResource() - * @method Mage_XmlConnect_Model_Mysql4_Application getResource() + * XmlConnect Model Application + * + * @method Mage_XmlConnect_Model_Resource_Application _getResource() + * @method Mage_XmlConnect_Model_Resource_Application getResource() * @method string getName() * @method Mage_XmlConnect_Model_Application setName(string $value) * @method string getCode() @@ -176,6 +178,27 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract */ 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 + * + * @var string + */ + 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 + * + * @var string + */ + 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 + * + * @var string + */ + const XML_PATH_URBAN_AIRSHIP_ABOUT_RICH_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_rich_push_url'; + /** * XML path to config copyright data * @@ -220,6 +243,27 @@ class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract */ const XML_PATH_DEFAULT_CACHE_LIFETIME = 'xmlconnect/mobile_application/cache_lifetime'; + /** + * XML path to How-To URL for twitter + * + * @var string + */ + const XML_PATH_HOWTO_TWITTER_URL = 'xmlconnect/social_networking/howto_twitter_url'; + + /** + * XML path to How-To URL for facebook + * + * @var string + */ + const XML_PATH_HOWTO_FACEBOOK_URL = 'xmlconnect/social_networking/howto_facebook_url'; + + /** + * XML path to How-To URL for linkedin + * + * @var string + */ + const XML_PATH_HOWTO_LINKEDIN_URL = 'xmlconnect/social_networking/howto_linkedin_url'; + /** * Initialize application * @@ -413,7 +457,6 @@ public function getRenderConf() /** * General configuration - $resulI = $this->_absPath($result); */ $result['general']['updateTimeUTC'] = strtotime($this->getUpdatedAt()); $result['general']['browsingMode'] = $this->getBrowsingMode(); 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 bcbef70361..66bfa13255 100644 --- a/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php +++ b/app/code/core/Mage/XmlConnect/Model/Catalog/Category/Image.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 6ecb4ebd65..a68fce610f 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/History.php b/app/code/core/Mage/XmlConnect/Model/History.php index 30e49b92dd..3ac634eca2 100644 --- a/app/code/core/Mage/XmlConnect/Model/History.php +++ b/app/code/core/Mage/XmlConnect/Model/History.php @@ -20,13 +20,16 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + /** - * @method Mage_XmlConnect_Model_Mysql4_History _getResource() - * @method Mage_XmlConnect_Model_Mysql4_History getResource() + * XmlConnect Model History + * + * @method Mage_XmlConnect_Model_Resource_History _getResource() + * @method Mage_XmlConnect_Model_Resource_History getResource() * @method int getApplicationId() * @method Mage_XmlConnect_Model_History setApplicationId(int $value) * @method string getCreatedAt() @@ -41,6 +44,10 @@ * @method Mage_XmlConnect_Model_History setActivationKey(string $value) * @method string getCode() * @method Mage_XmlConnect_Model_History setCode(string $value) + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Model_History extends Mage_Core_Model_Abstract { diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php index c45d96db9f..cec269874c 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application.php @@ -20,96 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_Application extends Mage_Core_Model_Mysql4_Abstract -{ - /** - * Constructor, setting table and index field - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/application', 'application_id'); - } - - /** - * Update Application Status field, insert data to history table - * - * @param int $applicationId - * @param string $status - * @return Mage_XmlConnect_Model_Mysql4_Application - */ - public function updateApplicationStatus($applicationId, $status) - { - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('status' => $status), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $applicationId) - ); - return $this; - } - - /** - * Processing object before save data - * Update app_code as Store + Device - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Abstract - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - if (!$object->getId()) { - $object->setCode($object->getCodePrefix()); - } - return parent::_beforeSave($object); - } - /** - * Processing object after save data - * Update app_code as Store + Device + 123 (increment). - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Abstract - */ - protected function _afterSave(Mage_Core_Model_Abstract $object) - { - $appCode = $object->getCode(); - $isCodePrefixed = $object->isCodePrefixed(); - if (!$isCodePrefixed) { - $this->_getWriteAdapter()->update( - $this->getMainTable(), - array('code' => $appCode . $object->getId()), - $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId()) - ); - } - return parent::_afterSave($object); - } - - /** - * Collect existing stores and type unique pairs - * - * @return array - */ - public function getExistingStoreDeviceType() - { - $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')); - } - - /** - * Update all applications "updated at" parameter with current date - * - * @return Mage_XmlConnect_Model_Mysql4_Application - */ - public function updateAllAppsUpdatedAtParameter() - { - $select = $this->_getWriteAdapter()->update($this->getMainTable(), array('updated_at' => date('Y-m-d H:i:s'))); - return $this; - } +/** + * XmlConnect Model Resource Application + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_Application extends Mage_XmlConnect_Model_Resource_Application +{ } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php index bc2285828d..9a77500bb3 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Application/Collection.php @@ -20,18 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_Application_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract + +/** + * XmlConnect Model Resource Application Collection + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_Application_Collection extends Mage_XmlConnect_Model_Resource_Application_Collection { - /** - * Constructor, setting table - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/application'); - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Category/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Category/Collection.php index 62e7cfaa28..fbffeace85 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Category/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Category/Collection.php @@ -20,77 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Category resource collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Mysql4_Category_Collection - extends Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection +class Mage_XmlConnect_Model_Mysql4_Category_Collection extends Mage_XmlConnect_Model_Resource_Category_Collection { - /** - * Level of parent categories - */ - const PARENT_CATEGORIES_LEVEL = 2; - - /** - * Before collection load - * - * @return Mage_XmlConnect_Model_Mysql4_Category_Collection - */ - protected function _beforeLoad() - { - $this->addNameToResult(); - $this->addAttributeToSelect('thumbnail'); - $this->addIsActiveFilter(); - return parent::_beforeLoad(); - } - - /** - * Adding filter level - * - * @param string $level - * @return Mage_XmlConnect_Model_Mysql4_Category_Collection - */ - public function addLevelExactFilter($level) - { - $this->getSelect()->where('e.level = ?', $level); - return $this; - } - - /** - * Set limit collection - * - * @param int $offset - * @param int $count - * @return Mage_XmlConnect_Model_Mysql4_Category_Collection - */ - public function setLimit($offset, $count) - { - $this->getSelect()->limit($count, $offset); - return $this; - } - - /** - * Adding parentCategory filter - * - * @param int $parentId - * @return Mage_XmlConnect_Model_Mysql4_Category_Collection - */ - public function addParentIdFilter($parentId) - { - if (!is_null($parentId)) { - $this->getSelect()->where('e.parent_id = ?', (int)$parentId); - } else { - $this->addLevelExactFilter(self::PARENT_CATEGORIES_LEVEL); - } - return $this; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php index 947546aaa0..42869e945f 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Cms/Page/Collection.php @@ -20,44 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Extended CMS page collection * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ - -class Mage_XmlConnect_Model_Mysql4_Cms_Page_Collection extends Mage_Cms_Model_Mysql4_Page_Collection +class Mage_XmlConnect_Model_Mysql4_Cms_Page_Collection extends Mage_XmlConnect_Model_Resource_Cms_Page_Collection { - /** - * Returns pairs identifier - title for unique identifiers - * and pairs identifier|page_id - title for non-unique after first - * - * @return array - */ - public function toOptionIdArray() - { - $res = array(); - $existingIdentifiers = array(); - foreach ($this as $item) { - $identifier = $item->getData('identifier'); - - $data['value'] = $identifier; - $data['label'] = $item->getData('title'); - if (in_array($identifier, $existingIdentifiers)) { - $data['value'] .= '|' . $item->getData('page_id'); - } else { - $existingIdentifiers[] = $identifier; - } - - $res[] = $data; - } - - return $res; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php index eec097716c..440deb8b61 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Filter/Collection.php @@ -20,83 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Filter collection * - * @category Mage - * @package Mage_Catalog + * @category Mage + * @package Mage_XmlConnect * @author Magento Core Team */ -class Mage_XmlConnect_Model_Mysql4_Filter_Collection extends Varien_Data_Collection +class Mage_XmlConnect_Model_Mysql4_Filter_Collection extends Mage_XmlConnect_Model_Resource_Filter_Collection { - /** - * Set CategoryId filter - * - * @param int $categoryId - * @return Mage_XmlConnect_Model_Mysql4_Filter_Collection - */ - public function setCategoryId($categoryId) - { - if ((int)$categoryId > 0) { - $this->addFilter('category_id', $categoryId); - } - return $this; - } - - /** - * Load data - * - * @param bool $printQuery - * @param bool $logQuery - * @return Mage_XmlConnect_Model_Mysql4_Filter_Collection - */ - public function load($printQuery = false, $logQuery = false) - { - if (empty($this->_items)) { - $layer = Mage::getSingleton('catalog/layer'); - foreach ($this->_filters as $filter) { - if ('category_id' == $filter['field']) { - $layer->setCurrentCategory((int)$filter['value']); - } - } - if ($layer->getCurrentCategory()->getIsAnchor()) { - foreach ($layer->getFilterableAttributes() as $attributeItem) { - $filterModelName = 'catalog/layer_filter_attribute'; - switch ($attributeItem->getAttributeCode()) { - case 'price': - $filterModelName = 'catalog/layer_filter_price'; - break; - case 'decimal': - $filterModelName = 'catalog/layer_filter_decimal'; - break; - default: - $filterModelName = 'catalog/layer_filter_attribute'; - break; - } - - $filterModel = Mage::getModel($filterModelName); - $filterModel->setLayer($layer)->setAttributeModel($attributeItem); - $filterValues = new Varien_Data_Collection; - foreach ($filterModel->getItems() as $valueItem) { - $valueObject = new Varien_Object(); - $valueObject->setLabel($valueItem->getLabel()); - $valueObject->setValueString($valueItem->getValueString()); - $valueObject->setProductsCount($valueItem->getCount()); - $filterValues->addItem($valueObject); - } - $item = new Varien_Object; - $item->setCode($attributeItem->getAttributeCode()); - $item->setName($filterModel->getName()); - $item->setValues($filterValues); - $this->addItem($item); - } - } - } - return $this; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php index 257823525d..b9c43e0f6e 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/History.php @@ -20,65 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_History extends Mage_Core_Model_Mysql4_Abstract -{ - /** - * Constructor, setting table and index field - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/history', 'history_id'); - } - - /** - * Serialization for 'params' variable - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Abstract - */ - protected function _beforeSave(Mage_Core_Model_Abstract $object) - { - $object->setParams(serialize($object->getParams())); - return parent::_beforeSave($object); - } - - /** - * Deserialization for 'params' variable - * - * @param Mage_Core_Model_Abstract $object - * @return Mage_Core_Model_Abstract - */ - protected function _afterLoad(Mage_Core_Model_Abstract $object) - { - $object->setParams(unserialize($object->getParams())); - return parent::_afterLoad($object); - } - /** - * Returns array of existing images - * - * @param int $id - application instance Id - * @return array - */ - 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 DESC')); - - $params = $this->_getReadAdapter()->fetchOne($select); - - if (isset($params)) { - $paramArray = unserialize($params); - } - return $paramArray; - } +/** + * XmlConnect Model Resource History + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_History extends Mage_XmlConnect_Model_Resource_History +{ } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php index 3539764f86..4419e5bd96 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/History/Collection.php @@ -20,50 +20,18 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * History resource collection * - * @category Mage - * @package Mage_XmlConnect - * @author Magento Core Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Model_Mysql4_History_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_XmlConnect_Model_Resource_History_Collection { - /** - * Internal constructor - */ - protected function _construct() - { - $this->_init('xmlconnect/history'); - } - - /** - * Filter collection by store - * - * @param int $storeId - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function addStoreFilter($storeId) - { - $this->addFieldToFilter('store_id', $storeId); - return $this; - } - - /** - * Filter collection by application_id - * - * @param int $applicationId - * @return Mage_Core_Model_Mysql4_Collection_Abstract - */ - public function addApplicationFilter($applicationId) - { - $this->addFieldToFilter('application_id', $applicationId); - return $this; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php index 404d258d01..3423248849 100755 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue.php @@ -20,18 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_Queue extends Mage_Core_Model_Mysql4_Abstract + +/** + * XmlConnect Model Resource Queue + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_Queue extends Mage_XmlConnect_Model_Resource_Queue { - /** - * Constructor, setting table and index field - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/queue', 'id'); - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php index 353e3930c3..e2643c75d2 100755 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Queue/Collection.php @@ -20,11 +20,10 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Queue resource collection * @@ -33,71 +32,6 @@ * @author Magento Core Team */ class Mage_XmlConnect_Model_Mysql4_Queue_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_XmlConnect_Model_Resource_Queue_Collection { - /** - * Internal constructor - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/queue'); - } - - /** - * Initialize collection select - * - * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinTemplateName() - ->_joinApplicationName(); - return $this; - } - - /** - * Join Template Name to collection - * - * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection - */ - protected function _joinTemplateName() - { - $this->getSelect() - ->joinLeft(array('t' => $this->getTable('xmlconnect/template')), 't.id = template_id', array( - 'template_name' => 't.name', - )); - return $this; - } - - /** - * Join Application Name to collection - * - * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection - */ - protected function _joinApplicationName() - { - $this->getSelect() - ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = main_table.app_code', array( - 'application_name' => 'app.name', - )); - return $this; - } - - /** - * Add filter by only ready fot sending item - * - * @return Mage_XmlConnect_Model_Mysql4_Queue_Collection - */ - public function addOnlyForSendingFilter() - { - $this->getSelect() - ->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE)) - ->where('main_table.exec_time < ?', Mage::getSingleton('core/date')->gmtDate()) - ->order(new Zend_Db_Expr('main_table.exec_time ' . Zend_Db_Select::SQL_ASC)); - - return $this; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php index c8c61b0cbb..d7b60f601d 100644 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Setup.php @@ -20,10 +20,18 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup -{ + +/** + * XML Connect Setup Resource Model + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_Setup extends Mage_XmlConnect_Model_Resource_Setup +{ } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php index 691632aa5a..0d9e803ea2 100755 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template.php @@ -20,18 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Model_Mysql4_Template extends Mage_Core_Model_Mysql4_Abstract + +/** + * XmlConnect Model Resource Template + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Mysql4_Template extends Mage_XmlConnect_Model_Resource_Template { - /** - * Constructor, setting table and index field - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/template', 'id'); - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php index a1810df109..fe7ea4390b 100755 --- a/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php +++ b/app/code/core/Mage/XmlConnect/Model/Mysql4/Template/Collection.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,41 +32,6 @@ * @author Magento Core Team */ class Mage_XmlConnect_Model_Mysql4_Template_Collection - extends Mage_Core_Model_Mysql4_Collection_Abstract + extends Mage_XmlConnect_Model_Resource_Template_Collection { - /** - * Internal constructor - * - * @return void - */ - protected function _construct() - { - $this->_init('xmlconnect/template'); - } - - /** - * Initialize collection select - * - * @return Mage_XmlConnect_Model_Mysql4_Template_Collection - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->_joinApplicationName(); - return $this; - } - - /** - * Join Application Name to collection - * - * @return Mage_XmlConnect_Model_Mysql4_Template_Collection - */ - protected function _joinApplicationName() - { - $this->getSelect() - ->joinLeft(array('app' => $this->getTable('xmlconnect/application')), 'app.code = app_code', array( - 'app_name' => 'app.name', - )); - return $this; - } } diff --git a/app/code/core/Mage/XmlConnect/Model/Observer.php b/app/code/core/Mage/XmlConnect/Model/Observer.php index d6dda20da1..d9ae7c2255 100644 --- a/app/code/core/Mage/XmlConnect/Model/Observer.php +++ b/app/code/core/Mage/XmlConnect/Model/Observer.php @@ -20,14 +20,16 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * XmlConnect module observer + * XmlConnect Model Observer * - * @author Magento Mobile Team + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team */ class Mage_XmlConnect_Model_Observer { 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 f902f73993..489bb2a744 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 @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ 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 e7b87cd03c..70aa22861b 100644 --- a/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php +++ b/app/code/core/Mage/XmlConnect/Model/Paypal/Mep/Checkout.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php b/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php index 86d0239286..24365f9781 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Android.php b/app/code/core/Mage/XmlConnect/Model/Preview/Android.php index 9d529ec90d..275b65b639 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Android.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Android.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Ipad.php b/app/code/core/Mage/XmlConnect/Model/Preview/Ipad.php index c734e8bb8a..b420564712 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Ipad.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Ipad.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php b/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php index 2d7057cd7d..639bfe6cd2 100755 --- a/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php +++ b/app/code/core/Mage/XmlConnect/Model/Preview/Iphone.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/Model/Queue.php b/app/code/core/Mage/XmlConnect/Model/Queue.php index a74d040e7f..0fb342f070 100755 --- a/app/code/core/Mage/XmlConnect/Model/Queue.php +++ b/app/code/core/Mage/XmlConnect/Model/Queue.php @@ -20,10 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * XmlConnect Model Queue + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Model_Queue extends Mage_Core_Model_Template { /** diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Application.php b/app/code/core/Mage/XmlConnect/Model/Resource/Application.php new file mode 100755 index 0000000000..a656bdeb38 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Application.php @@ -0,0 +1,130 @@ + + */ +class Mage_XmlConnect_Model_Resource_Application extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor, setting table and index field + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/application', 'application_id'); + } + + /** + * Update Application Status field, insert data to history table + * + * @param int $applicationId + * @param string $status + * @param Mage_XmlConnect_Model_Resource_Application $status + */ + public function updateApplicationStatus($applicationId, $status) + { + $this->_getWriteAdapter()->update( + $this->getMainTable(), + array('status' => $status), + $this->_getWriteAdapter()->quoteInto( + $this->getIdFieldName() . '=?', $applicationId + ) + ); + return $this; + } + + /** + * Processing object before save data + * Update app_code as Store + Device + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + if (!$object->getId()) { + $object->setCode($object->getCodePrefix()); + } + return parent::_beforeSave($object); + } + + /** + * Processing object after save data + * Update app_code as Store + Device + 123 (increment). + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Abstract + */ + protected function _afterSave(Mage_Core_Model_Abstract $object) + { + $appCode = $object->getCode(); + $isCodePrefixed = $object->isCodePrefixed(); + if (!$isCodePrefixed) { + $this->_getWriteAdapter()->update( + $this->getMainTable(), + array('code' => $appCode . $object->getId()), + $this->_getWriteAdapter()->quoteInto( + $this->getIdFieldName() . '=?', $object->getId() + ) + ); + } + return parent::_afterSave($object); + } + + /** + * Collect existing stores and type unique pairs + * + * @return array + */ + public function getExistingStoreDeviceType() + { + $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')); + } + + /** + * Update all applications "updated at" parameter with current date + * + * @return Mage_XmlConnect_Model_Resource_Application + */ + public function updateAllAppsUpdatedAtParameter() + { + $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 new file mode 100755 index 0000000000..4f4da73be8 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Application/Collection.php @@ -0,0 +1,45 @@ + + */ +class Mage_XmlConnect_Model_Resource_Application_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Constructor, setting table + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/application'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Category/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Category/Collection.php new file mode 100755 index 0000000000..9376578d14 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Category/Collection.php @@ -0,0 +1,96 @@ + + */ +class Mage_XmlConnect_Model_Resource_Category_Collection extends Mage_Catalog_Model_Resource_Category_Collection +{ + /** + * Default parent category level + * + * @var int + */ + const PARENT_CATEGORIES_LEVEL = 2; + + /** + * Before collection load + * + * @return Mage_XmlConnect_Model_Resource_Category_Collection + */ + protected function _beforeLoad() + { + $this->addNameToResult(); + $this->addAttributeToSelect('thumbnail'); + $this->addIsActiveFilter(); + return parent::_beforeLoad(); + } + + /** + * Adding filter level + * + * @param string $level + * @return Mage_XmlConnect_Model_Resource_Category_Collection + */ + public function addLevelExactFilter($level) + { + $this->getSelect()->where('e.level = ?', $level); + return $this; + } + + /** + * Set limit collection + * + * @param int $offset + * @param int $count + * @return Mage_XmlConnect_Model_Resource_Category_Collection + */ + public function setLimit($offset, $count) + { + $this->getSelect()->limit($count, $offset); + return $this; + } + + /** + * Adding parentCategory filter + * + * @param int $parentId + * @return Mage_XmlConnect_Model_Resource_Category_Collection + */ + public function addParentIdFilter($parentId) + { + if (!is_null($parentId)) { + $this->getSelect()->where('e.parent_id = ?', (int)$parentId); + } else { + $this->addLevelExactFilter(self::PARENT_CATEGORIES_LEVEL); + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Cms/Page/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Cms/Page/Collection.php new file mode 100755 index 0000000000..46fd005de2 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Cms/Page/Collection.php @@ -0,0 +1,62 @@ + + */ +class Mage_XmlConnect_Model_Resource_Cms_Page_Collection extends Mage_Cms_Model_Resource_Page_Collection +{ + /** + * Returns pairs identifier - title for unique identifiers + * and pairs identifier|page_id - title for non-unique after first + * + * @return array + */ + public function toOptionIdArray() + { + $res = array(); + $existingIdentifiers = array(); + foreach ($this as $item) { + $identifier = $item->getData('identifier'); + + $data['value'] = $identifier; + $data['label'] = $item->getData('title'); + if (in_array($identifier, $existingIdentifiers)) { + $data['value'] .= '|' . $item->getData('page_id'); + } else { + $existingIdentifiers[] = $identifier; + } + + $res[] = $data; + } + + return $res; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Filter/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Filter/Collection.php new file mode 100755 index 0000000000..bf6e2c6562 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Filter/Collection.php @@ -0,0 +1,101 @@ + + */ +class Mage_XmlConnect_Model_Resource_Filter_Collection extends Varien_Data_Collection +{ + /** + * Set CategoryId filter + * + * @param int $categoryId + * @return Mage_XmlConnect_Model_Resource_Filter_Collection + */ + public function setCategoryId($categoryId) + { + if ((int)$categoryId > 0) { + $this->addFilter('category_id', $categoryId); + } + return $this; + } + + /** + * Load data + * + * @param bool $printQuery + * @param bool $logQuery + * @return Mage_XmlConnect_Model_Resource_Filter_Collection + */ + public function load($printQuery = false, $logQuery = false) + { + if (empty($this->_items)) { + $layer = Mage::getSingleton('catalog/layer'); + foreach ($this->_filters as $filter) { + if ('category_id' == $filter['field']) { + $layer->setCurrentCategory((int)$filter['value']); + } + } + if ($layer->getCurrentCategory()->getIsAnchor()) { + foreach ($layer->getFilterableAttributes() as $attributeItem) { + $filterModelName = 'catalog/layer_filter_attribute'; + switch ($attributeItem->getAttributeCode()) { + case 'price': + $filterModelName = 'catalog/layer_filter_price'; + break; + case 'decimal': + $filterModelName = 'catalog/layer_filter_decimal'; + break; + default: + $filterModelName = 'catalog/layer_filter_attribute'; + break; + } + + $filterModel = Mage::getModel($filterModelName); + $filterModel->setLayer($layer)->setAttributeModel($attributeItem); + $filterValues = new Varien_Data_Collection; + foreach ($filterModel->getItems() as $valueItem) { + $valueObject = new Varien_Object(); + $valueObject->setLabel($valueItem->getLabel()); + $valueObject->setValueString($valueItem->getValueString()); + $valueObject->setProductsCount($valueItem->getCount()); + $filterValues->addItem($valueObject); + } + $item = new Varien_Object; + $item->setCode($attributeItem->getAttributeCode()); + $item->setName($filterModel->getName()); + $item->setValues($filterValues); + $this->addItem($item); + } + } + } + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/History.php b/app/code/core/Mage/XmlConnect/Model/Resource/History.php new file mode 100755 index 0000000000..355bed4aed --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/History.php @@ -0,0 +1,92 @@ + + */ +class Mage_XmlConnect_Model_Resource_History extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor, setting table and index field + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/history', 'history_id'); + } + + /** + * Serialization for 'params' variable + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Abstract + */ + protected function _beforeSave(Mage_Core_Model_Abstract $object) + { + $object->setParams(serialize($object->getParams())); + return parent::_beforeSave($object); + } + + /** + * Deserialization for 'params' variable + * + * @param Mage_Core_Model_Abstract $object + * @return Mage_Core_Model_Abstract + */ + protected function _afterLoad(Mage_Core_Model_Abstract $object) + { + $object->setParams(unserialize($object->getParams())); + return parent::_afterLoad($object); + } + + /** + * Returns array of existing images + * + * @param int $id application instance Id + * @return array + */ + 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)); + + $params = $this->_getReadAdapter()->fetchOne($select); + + if (isset($params)) { + $paramArray = unserialize($params); + } + return $paramArray; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php new file mode 100755 index 0000000000..a33349e517 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/History/Collection.php @@ -0,0 +1,68 @@ + + */ +class Mage_XmlConnect_Model_Resource_History_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Internal constructor + */ + protected function _construct() + { + $this->_init('xmlconnect/history'); + } + + /** + * Filter collection by store + * + * @param int $storeId + * @return Mage_XmlConnect_Model_Resource_History_Collection + */ + public function addStoreFilter($storeId) + { + $this->addFieldToFilter('store_id', $storeId); + return $this; + } + + /** + * Filter collection by application_id + * + * @param int $applicationId + * @return Mage_XmlConnect_Model_Resource_History_Collection + */ + public function addApplicationFilter($applicationId) + { + $this->addFieldToFilter('application_id', $applicationId); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php b/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php new file mode 100755 index 0000000000..7480e2a83d --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Queue.php @@ -0,0 +1,45 @@ + + */ +class Mage_XmlConnect_Model_Resource_Queue extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor, setting table and index field + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/queue', 'queue_id'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php new file mode 100755 index 0000000000..552812e95f --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Queue/Collection.php @@ -0,0 +1,117 @@ + + */ +class Mage_XmlConnect_Model_Resource_Queue_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Internal constructor + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/queue'); + } + + /** + * Initialize collection select + * + * @return Mage_XmlConnect_Model_Resource_Queue_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinNames(); + return $this; + } + + /** + * Join Template Name and Application Name to collection + * + * @return Mage_XmlConnect_Model_Resource_Queue_Collection + */ + protected function _joinNames() + { + $this->_joinTemplateName(); + $this->_joinApplicationName(); + return $this; + } + + /** + * Join Template Name to collection + * + * @return Mage_XmlConnect_Model_Resource_Queue_Collection + */ + protected function _joinTemplateName() + { + $this->getSelect() + ->joinLeft( + array('t' => $this->getTable('xmlconnect/template')), + 't.template_id = main_table.template_id', + array('template_name' => 't.name') + ); + return $this; + } + + /** + * Join Application Name to collection + * + * @return Mage_XmlConnect_Model_Resource_Queue_Collection + */ + protected function _joinApplicationName() + { + $this->getSelect() + ->joinLeft( + array('app' => $this->getTable('xmlconnect/application')), + 'app.application_id = t.application_id', + array('application_name' => 'app.name') + ); + return $this; + } + + /** + * Add filter by only ready fot sending item + * + * @return Mage_XmlConnect_Model_Resource_Queue_Collection + */ + public function addOnlyForSendingFilter() + { + $this->getSelect() + ->where('main_table.status in (?)', array(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE)) + ->where('main_table.exec_time < ?', Mage::getSingleton('core/date')->gmtDate()) + ->order(new Zend_Db_Expr('main_table.exec_time ' . Zend_Db_Select::SQL_ASC) + ); + return $this; + } +} diff --git a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Theme.php b/app/code/core/Mage/XmlConnect/Model/Resource/Setup.php old mode 100644 new mode 100755 similarity index 72% rename from app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Theme.php rename to app/code/core/Mage/XmlConnect/Model/Resource/Setup.php index 646e712ec0..38fd725905 --- a/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Design/Theme.php +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Setup.php @@ -20,14 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Theme extends Mage_Core_Block_Template + +/** + * XML Connect Setup Resource Model + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ +class Mage_XmlConnect_Model_Resource_Setup extends Mage_Catalog_Model_Resource_Setup { - public function __construct() - { - parent::__construct(); - $this->setTemplate('xmlconnect/theme.phtml'); - } -} \ No newline at end of file +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Template.php b/app/code/core/Mage/XmlConnect/Model/Resource/Template.php new file mode 100755 index 0000000000..345bf5c478 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Template.php @@ -0,0 +1,45 @@ + + */ +class Mage_XmlConnect_Model_Resource_Template extends Mage_Core_Model_Resource_Db_Abstract +{ + /** + * Constructor, setting table and index field + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/template', 'template_id'); + } +} diff --git a/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php b/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php new file mode 100755 index 0000000000..df5d6e899c --- /dev/null +++ b/app/code/core/Mage/XmlConnect/Model/Resource/Template/Collection.php @@ -0,0 +1,74 @@ + + */ +class Mage_XmlConnect_Model_Resource_Template_Collection + extends Mage_Core_Model_Resource_Db_Collection_Abstract +{ + /** + * Internal constructor + * + * @return void + */ + protected function _construct() + { + $this->_init('xmlconnect/template'); + } + + /** + * Initialize collection select + * + * @return Mage_XmlConnect_Model_Resource_Template_Collection + */ + protected function _initSelect() + { + parent::_initSelect(); + $this->_joinApplicationName(); + return $this; + } + + /** + * Join Application Name to collection + * + * @return Mage_XmlConnect_Model_Resource_Template_Collection + */ + 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') + ); + 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 8f1e1877d9..d253ed12bc 100644 --- a/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php +++ b/app/code/core/Mage/XmlConnect/Model/Simplexml/Element.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -42,7 +42,7 @@ public function appendChild($source) { if (sizeof($source->children())) { /** - * @see http://bugs.php.net/bug.php?id=41867 , fixed in 5.2.4 + * @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(); diff --git a/app/code/core/Mage/XmlConnect/Model/Tabs.php b/app/code/core/Mage/XmlConnect/Model/Tabs.php index 24ae0df0b8..2f18d3b18f 100644 --- a/app/code/core/Mage/XmlConnect/Model/Tabs.php +++ b/app/code/core/Mage/XmlConnect/Model/Tabs.php @@ -20,9 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * XmlConnect Model Tabs + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Model_Tabs { /** diff --git a/app/code/core/Mage/XmlConnect/Model/Template.php b/app/code/core/Mage/XmlConnect/Model/Template.php index 0381db53bf..3f7a0690c4 100755 --- a/app/code/core/Mage/XmlConnect/Model/Template.php +++ b/app/code/core/Mage/XmlConnect/Model/Template.php @@ -20,10 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * XmlConnect Model Template + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Model_Template extends Mage_Core_Model_Template { /** @@ -36,6 +43,25 @@ protected function _construct() $this->_init('xmlconnect/template'); } + /** + * Processing object before save data + * Add created_at and modified_at params + * + * @return Mage_XmlConnect_Model_Template + */ + protected function _beforeSave() + { + parent::_beforeSave(); + + $currentDate = Mage::getSingleton('core/date')->gmtDate(); + if (!$this->getId()) { + $this->setCreatedAt($currentDate); + } + $this->setModifiedAt($currentDate); + + return $this; + } + /** * Get template type * diff --git a/app/code/core/Mage/XmlConnect/Model/Theme.php b/app/code/core/Mage/XmlConnect/Model/Theme.php index 8bf1e632db..fa1d78aa89 100644 --- a/app/code/core/Mage/XmlConnect/Model/Theme.php +++ b/app/code/core/Mage/XmlConnect/Model/Theme.php @@ -20,10 +20,17 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +/** + * XmlConnect Model Theme + * + * @category Mage + * @package Mage_XmlConnect + * @author Magento Core Team + */ class Mage_XmlConnect_Model_Theme { protected $_file; @@ -64,7 +71,7 @@ public function __construct($file) /** * Get theme xml as array - * + * * @param array $xml * @return array */ diff --git a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php index 256ed96675..e83542e94d 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Adminhtml/MobileController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -1223,7 +1223,7 @@ public function saveTemplateAction() $this->_redirect('*/*/'); return; } - $template->setModifiedAt(Mage::getSingleton('core/date')->gmtDate())->addData($data); + $template->addData($data); $template->save(); } catch (Mage_Core_Exception $e) { $this->_getSession()->addException($e, $e->getMessage()); diff --git a/app/code/core/Mage/XmlConnect/controllers/CartController.php b/app/code/core/Mage/XmlConnect/controllers/CartController.php index 38c5206594..597444319e 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CartController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CartController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php index c85ce09e73..e512bba80e 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CatalogController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CatalogController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php index 51d02f0a28..dd28fc00fb 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CheckoutController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/CmsController.php b/app/code/core/Mage/XmlConnect/controllers/CmsController.php index 99cd88b583..9103c06f33 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CmsController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CmsController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php index 445032dfa3..a757a13131 100644 --- a/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php +++ b/app/code/core/Mage/XmlConnect/controllers/ConfigurationController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/CustomerController.php b/app/code/core/Mage/XmlConnect/controllers/CustomerController.php index 089678ee1d..72b33e306b 100644 --- a/app/code/core/Mage/XmlConnect/controllers/CustomerController.php +++ b/app/code/core/Mage/XmlConnect/controllers/CustomerController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/IndexController.php b/app/code/core/Mage/XmlConnect/controllers/IndexController.php index c73d409dda..8bbc928b3f 100644 --- a/app/code/core/Mage/XmlConnect/controllers/IndexController.php +++ b/app/code/core/Mage/XmlConnect/controllers/IndexController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php index a76563964d..121aaf4057 100644 --- a/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php +++ b/app/code/core/Mage/XmlConnect/controllers/Paypal/MepController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php b/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php index 0396cd488c..398050564a 100755 --- a/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php +++ b/app/code/core/Mage/XmlConnect/controllers/PbridgeController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/ReviewController.php b/app/code/core/Mage/XmlConnect/controllers/ReviewController.php index ec1c100f47..0a0d2f8268 100644 --- a/app/code/core/Mage/XmlConnect/controllers/ReviewController.php +++ b/app/code/core/Mage/XmlConnect/controllers/ReviewController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php index f774393b58..9c9c7c6d5d 100644 --- a/app/code/core/Mage/XmlConnect/controllers/WishlistController.php +++ b/app/code/core/Mage/XmlConnect/controllers/WishlistController.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/etc/adminhtml.xml b/app/code/core/Mage/XmlConnect/etc/adminhtml.xml index 3dc9b3d506..356987446b 100644 --- a/app/code/core/Mage/XmlConnect/etc/adminhtml.xml +++ b/app/code/core/Mage/XmlConnect/etc/adminhtml.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/config.xml b/app/code/core/Mage/XmlConnect/etc/config.xml index 6ec84e5bff..d045ae52a9 100644 --- a/app/code/core/Mage/XmlConnect/etc/config.xml +++ b/app/code/core/Mage/XmlConnect/etc/config.xml @@ -21,24 +21,25 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - 1.4.0.13 + 1.6.0.0 Mage_XmlConnect_Model - xmlconnect_mysql4 + xmlconnect_resource - - Mage_XmlConnect_Model_Mysql4 + + Mage_XmlConnect_Model_Resource + xmlconnect_mysql4 xmlconnect_application
      xmlconnect_history
      @@ -46,7 +47,7 @@ xmlconnect_queue
      -
      +
      @@ -62,7 +63,7 @@ Mage_XmlConnect - Mage_XmlConnect_Model_Mysql4_Setup + Mage_XmlConnect_Model_Resource_Setup
      diff --git a/app/code/core/Mage/XmlConnect/etc/system.xml b/app/code/core/Mage/XmlConnect/etc/system.xml index 48b396ecab..4408c82ca1 100644 --- a/app/code/core/Mage/XmlConnect/etc/system.xml +++ b/app/code/core/Mage/XmlConnect/etc/system.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/themes/custom.xml b/app/code/core/Mage/XmlConnect/etc/themes/custom.xml index ba83be6f0e..840ac1dc46 100644 --- a/app/code/core/Mage/XmlConnect/etc/themes/custom.xml +++ b/app/code/core/Mage/XmlConnect/etc/themes/custom.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/themes/default.xml b/app/code/core/Mage/XmlConnect/etc/themes/default.xml index cf6adae0cc..6a4c5c0169 100644 --- a/app/code/core/Mage/XmlConnect/etc/themes/default.xml +++ b/app/code/core/Mage/XmlConnect/etc/themes/default.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/themes/funk_leaf.xml b/app/code/core/Mage/XmlConnect/etc/themes/funk_leaf.xml index d1dd808745..4d6dca58d4 100644 --- a/app/code/core/Mage/XmlConnect/etc/themes/funk_leaf.xml +++ b/app/code/core/Mage/XmlConnect/etc/themes/funk_leaf.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/themes/hot_red.xml b/app/code/core/Mage/XmlConnect/etc/themes/hot_red.xml index 3c2f261cc4..65d6632046 100644 --- a/app/code/core/Mage/XmlConnect/etc/themes/hot_red.xml +++ b/app/code/core/Mage/XmlConnect/etc/themes/hot_red.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/etc/themes/sky_blue.xml b/app/code/core/Mage/XmlConnect/etc/themes/sky_blue.xml index fe0ff91c9c..0a620056d3 100644 --- a/app/code/core/Mage/XmlConnect/etc/themes/sky_blue.xml +++ b/app/code/core/Mage/XmlConnect/etc/themes/sky_blue.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/install-1.6.0.0.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/install-1.6.0.0.php new file mode 100755 index 0000000000..64b71dd3db --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/install-1.6.0.0.php @@ -0,0 +1,241 @@ +startSetup(); + +/** + * Create table 'xmlconnect_application' + */ +$appTableName = $installer->getTable('xmlconnect/application'); +$table = $installer->getConnection() + ->newTable($appTableName) + ->addColumn('application_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Application Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Application Name') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Application Code') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Device Type') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('active_from', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Active From') + ->addColumn('active_to', Varien_Db_Ddl_Table::TYPE_DATE, null, array( + ), 'Active To') + ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Updated At') + ->addColumn('configuration', Varien_Db_Ddl_Table::TYPE_BLOB, '64K', array( + ), 'Configuration Info') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + ), 'Status') + ->addColumn('browsing_mode', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'default' => '0', + ), 'Browsing Mode') + ->addIndex( + $installer->getIdxName($appTableName, array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ) + ->addForeignKey( + $installer->getFkName($appTableName, 'store_id', $installer->getTable('core/store'), 'store_id'), + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, + Varien_Db_Ddl_Table::ACTION_SET_NULL + ) + ->setComment('Xmlconnect Application'); +$installer->getConnection()->createTable($table); + +/** + * Create table 'xmlconnect_history' + */ +$historyTableName = $installer->getTable('xmlconnect/history'); +$historyTable = $installer->getConnection() + ->newTable($historyTableName) + ->addColumn('history_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'History Id') + ->addColumn('application_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Application Id') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + ), 'Store Id') + ->addColumn('params', Varien_Db_Ddl_Table::TYPE_BLOB, '64K', array( + ), 'Params') + ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 200, array( + 'nullable' => false, + ), 'Title') + ->addColumn('activation_key', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Activation Key') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Application Name') + ->addColumn('code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array( + 'nullable' => false, + ), 'Application Code') + ->addForeignKey( + $installer->getFkName($historyTableName, 'application_id', $appTableName, 'application_id'), + 'application_id', + $appTableName, + 'application_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Xmlconnect History'); +$installer->getConnection()->createTable($historyTable); + +$entityTypeId = $installer->getEntityTypeId('catalog_category'); +$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); +$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); + +$installer->addAttribute('catalog_category', 'thumbnail', array( + 'type' => 'varchar', + 'label' => 'Thumbnail Image', + 'input' => 'image', + 'backend' => 'catalog/category_attribute_backend_image', + 'required' => false, + 'sort_order' => 4, + 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, + 'group' => 'General Information' +)); + +/** + * Create table 'xmlconnect_notification_template' + */ +$templateTableName = $installer->getTable('xmlconnect/template'); +$templateTable = $installer->getConnection() + ->newTable($templateTableName) + ->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Template Id') + ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Template Name') + ->addColumn('push_title', Varien_Db_Ddl_Table::TYPE_TEXT, 140, array( + 'nullable' => false, + ), 'Push Notification Title') + ->addColumn('message_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'nullable' => false, + ), 'Message Title') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'nullable' => false, + ), 'Message Content') + ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('modified_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Modified At') + ->addColumn('application_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Application Id') + ->addForeignKey( + $installer->getFkName($templateTableName, 'application_id', $appTableName, 'application_id'), + 'application_id', + $appTableName, + 'application_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Xmlconnect Notification Template'); +$installer->getConnection()->createTable($templateTable); + + +/** + * Create table 'xmlconnect_queue' + */ +$queueTableName = $installer->getTable('xmlconnect/queue'); +$queueTable = $installer->getConnection() + ->newTable($queueTableName) + ->addColumn('queue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), 'Queue Id') + ->addColumn('create_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Created At') + ->addColumn('exec_time', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array( + ), 'Scheduled Execution Time') + ->addColumn('template_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( + 'unsigned' => true, + 'nullable' => false, + ), 'Template Id') + ->addColumn('push_title', Varien_Db_Ddl_Table::TYPE_TEXT, 140, array( + 'nullable' => false, + ), 'Push Notification Title') + ->addColumn('message_title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( + 'default' => '' + ), 'Message Title') + ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( + 'default' => '' + ), 'Message Content') + ->addColumn('status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array( + 'unsigned' => true, + 'nullable' => false, + 'default' => 0 + ), 'Status') + ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 12, array( + 'nullable' => false, + ), 'Type of Notification') + ->addForeignKey( + $installer->getFkName($queueTableName, 'template_id', $templateTableName, 'template_id'), + 'template_id', + $templateTableName, + 'template_id', + Varien_Db_Ddl_Table::ACTION_CASCADE, + Varien_Db_Ddl_Table::ACTION_CASCADE + ) + ->setComment('Xmlconnect Notification Queue'); +$installer->getConnection()->createTable($queueTable); + +$installer->endSetup(); diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php index 14dafc3aa4..37a2f800b6 100644 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-install-1.4.0.8.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php index 0a7e993a80..144c139f02 100755 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.10-1.4.0.11.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php index 07490d4ab9..4bb010134d 100755 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.11-1.4.0.12.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.12-1.4.0.13.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.12-1.4.0.13.php index 12bb467ca4..9dc7871211 100644 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.12-1.4.0.13.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.12-1.4.0.13.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php index 160bcc8e34..9773b412ec 100755 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.8-1.4.0.9.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php index 32b4e65dc3..80f39d72b7 100755 --- a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.4.0.9-1.4.0.10.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php new file mode 100755 index 0000000000..186687fb23 --- /dev/null +++ b/app/code/core/Mage/XmlConnect/sql/xmlconnect_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php @@ -0,0 +1,443 @@ +startSetup(); + +$appTableName = $installer->getTable('xmlconnect/application'); +$historyTableName = $installer->getTable('xmlconnect/history'); +$templateTableName = $installer->getTable('xmlconnect/template'); +$queueTableName = $installer->getTable('xmlconnect/queue'); + +/** + * Drop foreign keys + */ +$installer->getConnection()->dropForeignKey( + $appTableName, + 'FK_XMLCONNECT_APPLICAION_STORE' +); + +$installer->getConnection()->dropForeignKey( + $historyTableName, + 'FK_XMLCONNECT_HISTORY_APPLICATION' +); + +$installer->getConnection()->dropForeignKey( + $templateTableName, + 'FK_APP_CODE' +); + +$installer->getConnection()->dropForeignKey( + $queueTableName, + 'FK_TEMPLATE_ID' +); + +/** + * Drop indexes + */ +$installer->getConnection()->dropIndex( + $appTableName, + 'FK_XMLCONNECT_APPLICAION_STORE' +); + +$installer->getConnection()->dropIndex( + $historyTableName, + 'FK_XMLCONNECT_HISTORY_APPLICATION' +); + +$installer->getConnection()->dropIndex( + $appTableName, + 'UNQ_XMLCONNECT_APPLICATION_CODE' +); + +/** + * Modify fields for 'xmlconnect_notification_template' + */ +$installer->getConnection()->changeColumn( + $templateTableName, + 'id', + 'template_id', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'History Id' + ) +); + +$installer->getConnection()->addColumn($templateTableName, 'application_id', array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Application Id' + ) +); + +$installer->getConnection()->dropColumn($templateTableName, 'app_code'); + +/** + * Modify fields for 'xmlconnect_queue' + */ +$installer->getConnection()->changeColumn( + $queueTableName, + 'id', + 'queue_id', + array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Queue Id' + ) +); + +$installer->getConnection()->dropColumn($queueTableName, 'app_code'); + +/** + * Change columns + */ +$tables = array( + /** + * Modify table 'xmlconnect_application' + */ + $appTableName => array( + 'columns' => array( + 'application_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Application Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Application Name' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Application Code' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Device Type' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'active_from' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Active From' + ), + 'active_to' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_DATE, + 'comment' => 'Active To' + ), + 'updated_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Updated At' + ), + 'configuration' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BLOB, + 'length' => '64k', + 'comment' => 'Configuration Info' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => '0', + 'comment' => 'Status' + ), + 'browsing_mode' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'default' => '0', + 'comment' => 'Browsing Mode' + ) + ), + 'comment' => 'Xmlconnect Application' + ), + /** + * Modify table 'xmlconnect_history' + */ + $historyTableName => array( + 'columns' => array( + 'history_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'History Id' + ), + 'application_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Application Id' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Created At' + ), + 'store_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'comment' => 'Store Id' + ), + 'params' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_BLOB, + 'length' => '64k', + 'comment' => 'Params' + ), + 'title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 200, + 'nullable' => false, + 'comment' => 'Title' + ), + 'activation_key' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Activation Key' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Application Name' + ), + 'code' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 32, + 'nullable' => false, + 'comment' => 'Application Code' + ), + ), + 'comment' => 'Xmlconnect History' + ), + /** + * Modify table 'xmlconnect_notification_template' + */ + $templateTableName => array( + 'columns' => array( + 'template_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Template Id' + ), + 'application_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Application Id' + ), + 'name' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Template Name' + ), + 'push_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 140, + 'nullable' => false, + 'comment' => 'Push Notification Title' + ), + 'message_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => false, + 'comment' => 'Message Title' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64k', + 'nullable' => false, + 'comment' => 'Message Content' + ), + 'created_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Created At' + ), + 'modified_at' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Modified At' + ), + ), + 'comment' => 'Xmlconnect Notification Template' + ), + /** + * Modify table 'xmlconnect_queue' + */ + $queueTableName => array( + 'columns' => array( + 'queue_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + 'comment' => 'Queue Id' + ), + 'create_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Created At' + ), + 'exec_time' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP, + 'nullable' => true, + 'default' => null, + 'comment' => 'Scheduled Execution Time' + ), + 'template_id' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'comment' => 'Template Id' + ), + 'push_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 140, + 'nullable' => false, + 'comment' => 'Push Notification Title' + ), + 'message_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => true, + 'default' => '', + 'comment' => 'Message Title' + ), + 'content' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => '64k', + 'nullable' => true, + 'default' => '', + 'comment' => 'Message Content' + ), + 'push_title' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 140, + 'nullable' => false, + 'comment' => 'Push Notification Title' + ), + 'status' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'comment' => 'Status' + ), + 'type' => array( + 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, + 'length' => 12, + 'nullable' => false, + 'comment' => 'Type of Notification' + ), + ), + 'comment' => 'Xmlconnect Notification Queue' + ) +); + +$installer->getConnection()->modifyTables($tables); + +/** + * Add indexes + */ +$installer->getConnection()->addIndex( + $appTableName, + $installer->getIdxName($appTableName, array('code'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), + array('code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE +); + +/** + * Add foreign keys + */ +$installer->getConnection()->addForeignKey( + $installer->getFkName($appTableName, 'store_id', $installer->getTable('core/store'), 'store_id'), + $appTableName, + 'store_id', + $installer->getTable('core/store'), + 'store_id', + Varien_Db_Ddl_Table::ACTION_SET_NULL, + Varien_Db_Ddl_Table::ACTION_SET_NULL +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName($historyTableName, 'application_id', $appTableName, 'application_id'), + $historyTableName, + 'application_id', + $appTableName, + 'application_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName($templateTableName, 'application_id', $appTableName, 'application_id'), + $templateTableName, + 'application_id', + $appTableName, + 'application_id' +); + +$installer->getConnection()->addForeignKey( + $installer->getFkName($queueTableName, 'template_id', $templateTableName, 'template_id'), + $queueTableName, + 'template_id', + $templateTableName, + 'template_id' +); + +$installer->endSetup(); diff --git a/app/design/adminhtml/default/default/layout/admin.xml b/app/design/adminhtml/default/default/layout/admin.xml index 1cda1717b1..0edf5a0577 100644 --- a/app/design/adminhtml/default/default/layout/admin.xml +++ b/app/design/adminhtml/default/default/layout/admin.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/adminnotification.xml b/app/design/adminhtml/default/default/layout/adminnotification.xml index 6fda8dd930..508a8645f1 100644 --- a/app/design/adminhtml/default/default/layout/adminnotification.xml +++ b/app/design/adminhtml/default/default/layout/adminnotification.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/authorizenet.xml b/app/design/adminhtml/default/default/layout/authorizenet.xml index 11e8f64531..423270a232 100644 --- a/app/design/adminhtml/default/default/layout/authorizenet.xml +++ b/app/design/adminhtml/default/default/layout/authorizenet.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/layout/bundle.xml b/app/design/adminhtml/default/default/layout/bundle.xml index 2b4b8c5138..9d7e1c3c71 100644 --- a/app/design/adminhtml/default/default/layout/bundle.xml +++ b/app/design/adminhtml/default/default/layout/bundle.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/catalog.xml b/app/design/adminhtml/default/default/layout/catalog.xml index 30e26ded1b..a52053bff3 100644 --- a/app/design/adminhtml/default/default/layout/catalog.xml +++ b/app/design/adminhtml/default/default/layout/catalog.xml @@ -21,13 +21,19 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> + + Catalog + + + catalog/products + @@ -71,7 +77,7 @@ - + @@ -127,6 +133,18 @@ + + + + + + + + + + + + @@ -250,7 +268,7 @@ Layout handle for configurable products - + diff --git a/app/design/adminhtml/default/default/layout/centinel.xml b/app/design/adminhtml/default/default/layout/centinel.xml index 0a7ad1cd53..ae1f72f22c 100644 --- a/app/design/adminhtml/default/default/layout/centinel.xml +++ b/app/design/adminhtml/default/default/layout/centinel.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/layout/cms.xml b/app/design/adminhtml/default/default/layout/cms.xml index 55dddc2f97..f822d9bdff 100644 --- a/app/design/adminhtml/default/default/layout/cms.xml +++ b/app/design/adminhtml/default/default/layout/cms.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/compiler.xml b/app/design/adminhtml/default/default/layout/compiler.xml index 942468ef32..51c177ee4c 100644 --- a/app/design/adminhtml/default/default/layout/compiler.xml +++ b/app/design/adminhtml/default/default/layout/compiler.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/connect.xml b/app/design/adminhtml/default/default/layout/connect.xml index 1b63ada8f9..f15ca59f47 100644 --- a/app/design/adminhtml/default/default/layout/connect.xml +++ b/app/design/adminhtml/default/default/layout/connect.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/customer.xml b/app/design/adminhtml/default/default/layout/customer.xml index eca83a4e00..b5b7415149 100644 --- a/app/design/adminhtml/default/default/layout/customer.xml +++ b/app/design/adminhtml/default/default/layout/customer.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/dataflow.xml b/app/design/adminhtml/default/default/layout/dataflow.xml index 1dfae43002..534129275b 100644 --- a/app/design/adminhtml/default/default/layout/dataflow.xml +++ b/app/design/adminhtml/default/default/layout/dataflow.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/downloadable.xml b/app/design/adminhtml/default/default/layout/downloadable.xml index 885e4d6522..b675fd26e8 100644 --- a/app/design/adminhtml/default/default/layout/downloadable.xml +++ b/app/design/adminhtml/default/default/layout/downloadable.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/giftmessage.xml b/app/design/adminhtml/default/default/layout/giftmessage.xml index b3bd9e203f..1807b0c565 100644 --- a/app/design/adminhtml/default/default/layout/giftmessage.xml +++ b/app/design/adminhtml/default/default/layout/giftmessage.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/googleoptimizer.xml b/app/design/adminhtml/default/default/layout/googleoptimizer.xml index 5bb64d8bea..f8d02ac484 100644 --- a/app/design/adminhtml/default/default/layout/googleoptimizer.xml +++ b/app/design/adminhtml/default/default/layout/googleoptimizer.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/importexport.xml b/app/design/adminhtml/default/default/layout/importexport.xml index d7fe41c19c..db5c57aa90 100644 --- a/app/design/adminhtml/default/default/layout/importexport.xml +++ b/app/design/adminhtml/default/default/layout/importexport.xml @@ -30,9 +30,4 @@ - - - - - diff --git a/app/design/adminhtml/default/default/layout/index.xml b/app/design/adminhtml/default/default/layout/index.xml index af021a425d..4cfe406b76 100644 --- a/app/design/adminhtml/default/default/layout/index.xml +++ b/app/design/adminhtml/default/default/layout/index.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/main.xml b/app/design/adminhtml/default/default/layout/main.xml index afc1207a07..5048d7d6ba 100644 --- a/app/design/adminhtml/default/default/layout/main.xml +++ b/app/design/adminhtml/default/default/layout/main.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/layout/moneybookers.xml b/app/design/adminhtml/default/default/layout/moneybookers.xml index a67253f39e..862ab1ad4f 100644 --- a/app/design/adminhtml/default/default/layout/moneybookers.xml +++ b/app/design/adminhtml/default/default/layout/moneybookers.xml @@ -15,7 +15,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/newsletter.xml b/app/design/adminhtml/default/default/layout/newsletter.xml index 80c90e996e..6aedea1f47 100644 --- a/app/design/adminhtml/default/default/layout/newsletter.xml +++ b/app/design/adminhtml/default/default/layout/newsletter.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/pagecache.xml b/app/design/adminhtml/default/default/layout/pagecache.xml index 718019da85..a58dd03f1f 100644 --- a/app/design/adminhtml/default/default/layout/pagecache.xml +++ b/app/design/adminhtml/default/default/layout/pagecache.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/promo.xml b/app/design/adminhtml/default/default/layout/promo.xml index e8e87026aa..6916db131b 100644 --- a/app/design/adminhtml/default/default/layout/promo.xml +++ b/app/design/adminhtml/default/default/layout/promo.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/report.xml b/app/design/adminhtml/default/default/layout/report.xml index edc49b0527..c042d44672 100644 --- a/app/design/adminhtml/default/default/layout/report.xml +++ b/app/design/adminhtml/default/default/layout/report.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/rss.xml b/app/design/adminhtml/default/default/layout/rss.xml index fe667f4622..d2cef7e84e 100644 --- a/app/design/adminhtml/default/default/layout/rss.xml +++ b/app/design/adminhtml/default/default/layout/rss.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/sales.xml b/app/design/adminhtml/default/default/layout/sales.xml index c612fb6c76..9a3a4ab703 100644 --- a/app/design/adminhtml/default/default/layout/sales.xml +++ b/app/design/adminhtml/default/default/layout/sales.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/search.xml b/app/design/adminhtml/default/default/layout/search.xml index 0d20377043..92d266f100 100644 --- a/app/design/adminhtml/default/default/layout/search.xml +++ b/app/design/adminhtml/default/default/layout/search.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/tag.xml b/app/design/adminhtml/default/default/layout/tag.xml index 67eb5c9e04..b47e61f329 100644 --- a/app/design/adminhtml/default/default/layout/tag.xml +++ b/app/design/adminhtml/default/default/layout/tag.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/widget.xml b/app/design/adminhtml/default/default/layout/widget.xml index 9980ec6e4e..756652ceac 100644 --- a/app/design/adminhtml/default/default/layout/widget.xml +++ b/app/design/adminhtml/default/default/layout/widget.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/layout/xmlconnect.xml b/app/design/adminhtml/default/default/layout/xmlconnect.xml index 47fc4ca9bd..3bdea0a1f3 100644 --- a/app/design/adminhtml/default/default/layout/xmlconnect.xml +++ b/app/design/adminhtml/default/default/layout/xmlconnect.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/design/adminhtml/default/default/template/access_denied.phtml b/app/design/adminhtml/default/default/template/access_denied.phtml index c5ede4b6d3..fd916949f6 100644 --- a/app/design/adminhtml/default/default/template/access_denied.phtml +++ b/app/design/adminhtml/default/default/template/access_denied.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml b/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml index be795783b2..838135e745 100644 --- a/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml +++ b/app/design/adminhtml/default/default/template/api/role_users_grid_js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/roleinfo.phtml b/app/design/adminhtml/default/default/template/api/roleinfo.phtml index 2527dd911b..e74f891234 100644 --- a/app/design/adminhtml/default/default/template/api/roleinfo.phtml +++ b/app/design/adminhtml/default/default/template/api/roleinfo.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/roles.phtml b/app/design/adminhtml/default/default/template/api/roles.phtml index b43a57bf5f..4713c7b0d1 100644 --- a/app/design/adminhtml/default/default/template/api/roles.phtml +++ b/app/design/adminhtml/default/default/template/api/roles.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/rolesedit.phtml b/app/design/adminhtml/default/default/template/api/rolesedit.phtml index fd6ceec466..07c06c7b75 100644 --- a/app/design/adminhtml/default/default/template/api/rolesedit.phtml +++ b/app/design/adminhtml/default/default/template/api/rolesedit.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/rolesusers.phtml b/app/design/adminhtml/default/default/template/api/rolesusers.phtml index f7d8772f46..3727f5c4ac 100644 --- a/app/design/adminhtml/default/default/template/api/rolesusers.phtml +++ b/app/design/adminhtml/default/default/template/api/rolesusers.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/user_roles_grid_js.phtml b/app/design/adminhtml/default/default/template/api/user_roles_grid_js.phtml index 4878418043..57a60860f8 100644 --- a/app/design/adminhtml/default/default/template/api/user_roles_grid_js.phtml +++ b/app/design/adminhtml/default/default/template/api/user_roles_grid_js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/userinfo.phtml b/app/design/adminhtml/default/default/template/api/userinfo.phtml index 9fe3dcb562..c9be39d10b 100644 --- a/app/design/adminhtml/default/default/template/api/userinfo.phtml +++ b/app/design/adminhtml/default/default/template/api/userinfo.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/usernroles.phtml b/app/design/adminhtml/default/default/template/api/usernroles.phtml index 045100a5a6..8106d8e6ff 100644 --- a/app/design/adminhtml/default/default/template/api/usernroles.phtml +++ b/app/design/adminhtml/default/default/template/api/usernroles.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/userroles.phtml b/app/design/adminhtml/default/default/template/api/userroles.phtml index 01015f6029..e0addd3939 100644 --- a/app/design/adminhtml/default/default/template/api/userroles.phtml +++ b/app/design/adminhtml/default/default/template/api/userroles.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/api/users.phtml b/app/design/adminhtml/default/default/template/api/users.phtml index b4380ae0b5..da6c6b1ade 100644 --- a/app/design/adminhtml/default/default/template/api/users.phtml +++ b/app/design/adminhtml/default/default/template/api/users.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/authorizenet/directpost/iframe.phtml b/app/design/adminhtml/default/default/template/authorizenet/directpost/iframe.phtml index b548da0537..1532c0a9cc 100644 --- a/app/design/adminhtml/default/default/template/authorizenet/directpost/iframe.phtml +++ b/app/design/adminhtml/default/default/template/authorizenet/directpost/iframe.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/authorizenet/directpost/info.phtml b/app/design/adminhtml/default/default/template/authorizenet/directpost/info.phtml index 2dcb4cf6fe..c05c2ec9c2 100644 --- a/app/design/adminhtml/default/default/template/authorizenet/directpost/info.phtml +++ b/app/design/adminhtml/default/default/template/authorizenet/directpost/info.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/backup/left.phtml b/app/design/adminhtml/default/default/template/backup/left.phtml index 11b8a14044..c7d1080d63 100644 --- a/app/design/adminhtml/default/default/template/backup/left.phtml +++ b/app/design/adminhtml/default/default/template/backup/left.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/backup/list.phtml b/app/design/adminhtml/default/default/template/backup/list.phtml index 4a937dc1e6..bc4dad963d 100644 --- a/app/design/adminhtml/default/default/template/backup/list.phtml +++ b/app/design/adminhtml/default/default/template/backup/list.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml index 7e4a4caa30..f9abd9b342 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/bundle.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/checkbox.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/checkbox.phtml index ad48eb44c4..99922bb755 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/checkbox.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/checkbox.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/multi.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/multi.phtml index 0815280251..7aa2dcd86e 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/multi.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/multi.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/radio.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/radio.phtml index faa14e07ee..a7a02b4799 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/radio.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/radio.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/select.phtml b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/select.phtml index 1219fcebc0..b96cfbd21c 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/select.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/composite/fieldset/options/type/select.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle.phtml b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle.phtml index 5969d73392..d2ab034fff 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option.phtml b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option.phtml index 3f25421882..c028d6a31a 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/search.phtml b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/search.phtml index c0eb15d356..7a2fe9ba4f 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/search.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/search.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/selection.phtml b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/selection.phtml index 179b92d2a8..49ce080751 100644 --- a/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/selection.phtml +++ b/app/design/adminhtml/default/default/template/bundle/product/edit/bundle/option/selection.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/create/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/create/items/renderer.phtml index a6a5091aac..07e2569aed 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/create/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/create/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/view/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/view/items/renderer.phtml index 5b2a1d9f3f..2f310231c8 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/view/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/creditmemo/view/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/invoice/create/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/invoice/create/items/renderer.phtml index df18c2c6b7..d87f03d005 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/invoice/create/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/invoice/create/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/invoice/view/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/invoice/view/items/renderer.phtml index b87871056c..128570e272 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/invoice/view/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/invoice/view/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/order/view/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/order/view/items/renderer.phtml index c48646d470..a5b7d2696c 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/order/view/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/order/view/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/shipment/create/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/shipment/create/items/renderer.phtml index 8bf03a6243..643fd4be42 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/shipment/create/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/shipment/create/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/bundle/sales/shipment/view/items/renderer.phtml b/app/design/adminhtml/default/default/template/bundle/sales/shipment/view/items/renderer.phtml index 45f62d581c..96e66e7234 100644 --- a/app/design/adminhtml/default/default/template/bundle/sales/shipment/view/items/renderer.phtml +++ b/app/design/adminhtml/default/default/template/bundle/sales/shipment/view/items/renderer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml index 436a4505d5..e80f37103d 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/category/edit.phtml b/app/design/adminhtml/default/default/template/catalog/category/edit.phtml index 4ad029ed4b..997e78812d 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/edit.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/edit.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml b/app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml index f0761e741d..e5a8e7e3d6 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/category/tree.phtml b/app/design/adminhtml/default/default/template/catalog/category/tree.phtml index 0b5da90ff7..d511fb68bd 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/tree.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/tree.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/category/widget/tree.phtml b/app/design/adminhtml/default/default/template/catalog/category/widget/tree.phtml index a7114f85c2..5dd3a0d85e 100644 --- a/app/design/adminhtml/default/default/template/catalog/category/widget/tree.phtml +++ b/app/design/adminhtml/default/default/template/catalog/category/widget/tree.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml b/app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml index ce6b60a772..eaa1ff880d 100644 --- a/app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml +++ b/app/design/adminhtml/default/default/template/catalog/form/renderer/fieldset/element.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/form/renderer/googleoptimizer/import.phtml b/app/design/adminhtml/default/default/template/catalog/form/renderer/googleoptimizer/import.phtml index 605ceae4b7..1c1db39c12 100644 --- a/app/design/adminhtml/default/default/template/catalog/form/renderer/googleoptimizer/import.phtml +++ b/app/design/adminhtml/default/default/template/catalog/form/renderer/googleoptimizer/import.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product.phtml b/app/design/adminhtml/default/default/template/catalog/product.phtml index af837e3e8a..539eb1ce62 100644 --- a/app/design/adminhtml/default/default/template/catalog/product.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml index 21f3f85e4f..6894d7458b 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml index e7aa972edf..a0ab7f942c 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/options.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/options.phtml index 76904d3fd6..3d20e5f2a1 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/options.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/options.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml index b654eaf82b..4438cef1f5 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml index f0e3c6b6c9..2acd065758 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml index ac95e5b10b..91fe9250a4 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml index 841d36f19c..c6584ab878 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/main.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/main.phtml index f347a85dc6..f441969008 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/main.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/main.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml index 4549e03291..10db89f251 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/configure.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/configurable.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/configurable.phtml index 46173ed39c..a3c805a84d 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/configurable.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/configurable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/grouped.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/grouped.phtml index c7c9b160ac..838da270e8 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/grouped.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/grouped.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options.phtml index e3e94af043..23f32a90ef 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/js.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/js.phtml index 447e5c552c..d5d6361a36 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/js.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/date.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/date.phtml index 118134abd8..15f2f2c65a 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/date.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/date.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/default.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/default.phtml index 3524ff8080..8337938533 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/default.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/default.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/file.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/file.phtml index 87b6f5179e..8bf3b9cc67 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/file.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/file.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/select.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/select.phtml index aa2cec0e8e..c22d95f248 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/select.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/select.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/text.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/text.phtml index bf4d05fc05..2cfdcb4117 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/text.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/options/type/text.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/qty.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/qty.phtml index 8af048b408..21615723eb 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/qty.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/qty.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/simple.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/simple.phtml deleted file mode 100644 index d1119168e9..0000000000 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/simple.phtml +++ /dev/null @@ -1,34 +0,0 @@ - -
      -
      -

      __('Simple Product') ?>

      -
      -
      - Simple Product Fields -
      -
      \ No newline at end of file diff --git a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/virtual.phtml b/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/virtual.phtml deleted file mode 100644 index 6b86e00aab..0000000000 --- a/app/design/adminhtml/default/default/template/catalog/product/composite/fieldset/virtual.phtml +++ /dev/null @@ -1,34 +0,0 @@ - -
      -
      -

      __('Virtual Product') ?>

      -
      -
      - Virtual Product Fields -
      -
      \ No newline at end of file diff --git a/app/design/adminhtml/default/default/template/catalog/product/created.phtml b/app/design/adminhtml/default/default/template/catalog/product/created.phtml index a1e967d3a3..7f5cd5e680 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/created.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/created.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit.phtml index 64326a872c..c1deda643d 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/action/attribute.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/action/attribute.phtml index 2219c8f596..9884f9373b 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/action/attribute.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/action/attribute.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/action/inventory.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/action/inventory.phtml index 3343737067..b62594e751 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/action/inventory.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/action/inventory.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/action/websites.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/action/websites.phtml index a573609333..236227c301 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/action/websites.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/action/websites.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml index eb8d8348a6..9c3a17048e 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml index 36427a318b..208a28b038 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml index 09a7f8ec30..c5f469d9ee 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options/option.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/date.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/date.phtml index 2ca3c48b6f..ef7fdba37a 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/date.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/date.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/file.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/file.phtml index 606d555267..ab2988c991 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/file.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/file.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml index a469bb287c..0135504786 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/text.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/text.phtml index 821bc906c4..753ce5eef5 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/text.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/text.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/price/tier.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/price/tier.phtml index a3e8b4d91c..7af1fe4e28 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/price/tier.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/price/tier.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /* @var $this Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier */ diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/serializer.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/serializer.phtml index cb513ed18b..00d66f8c15 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/serializer.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/serializer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/super/config.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/super/config.phtml index d1c4d6715e..6b0ce10cfe 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/super/config.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/super/config.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/edit/websites.phtml b/app/design/adminhtml/default/default/template/catalog/product/edit/websites.phtml index c48a7522c2..85659c84f0 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/edit/websites.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/edit/websites.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml b/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml index b3051d58d7..a9a6b6f6b3 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/js.phtml b/app/design/adminhtml/default/default/template/catalog/product/js.phtml index 6d1dafc442..0ee95ee4d8 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/js.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/price.phtml b/app/design/adminhtml/default/default/template/catalog/product/price.phtml index 58dd3dd761..991737ddb6 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/price.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/price.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/tab/alert.phtml b/app/design/adminhtml/default/default/template/catalog/product/tab/alert.phtml index 62e7c81b6f..cd5980b417 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/tab/alert.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/tab/alert.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml b/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml index 59b423172a..0515a0d871 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/product/widget/chooser/container.phtml b/app/design/adminhtml/default/default/template/catalog/product/widget/chooser/container.phtml index 67fe1a921a..beaccd822d 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/widget/chooser/container.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/widget/chooser/container.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/catalog/wysiwyg/js.phtml b/app/design/adminhtml/default/default/template/catalog/wysiwyg/js.phtml index b32c5e3851..926b55367d 100644 --- a/app/design/adminhtml/default/default/template/catalog/wysiwyg/js.phtml +++ b/app/design/adminhtml/default/default/template/catalog/wysiwyg/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/centinel/authentication/complete.phtml b/app/design/adminhtml/default/default/template/centinel/authentication/complete.phtml index 4bf135ebca..c7eaa698bc 100644 --- a/app/design/adminhtml/default/default/template/centinel/authentication/complete.phtml +++ b/app/design/adminhtml/default/default/template/centinel/authentication/complete.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/centinel/authentication/start.phtml b/app/design/adminhtml/default/default/template/centinel/authentication/start.phtml index 69e3a0a4af..7d57ed85cb 100644 --- a/app/design/adminhtml/default/default/template/centinel/authentication/start.phtml +++ b/app/design/adminhtml/default/default/template/centinel/authentication/start.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/centinel/validation/form.phtml b/app/design/adminhtml/default/default/template/centinel/validation/form.phtml index df43375f70..f572a48bf4 100644 --- a/app/design/adminhtml/default/default/template/centinel/validation/form.phtml +++ b/app/design/adminhtml/default/default/template/centinel/validation/form.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/content.phtml b/app/design/adminhtml/default/default/template/cms/browser/content.phtml index ed74ab0140..7466ac1ac6 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/content.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/content.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/content/files.phtml b/app/design/adminhtml/default/default/template/cms/browser/content/files.phtml index 7f90e29cf5..c101e3545a 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/content/files.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/content/files.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/content/newfolder.phtml b/app/design/adminhtml/default/default/template/cms/browser/content/newfolder.phtml index f27142b5df..022cea673e 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/content/newfolder.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/content/newfolder.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/content/uploader.phtml b/app/design/adminhtml/default/default/template/cms/browser/content/uploader.phtml index c08419a530..3f9cb77f71 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/content/uploader.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/content/uploader.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/js.phtml b/app/design/adminhtml/default/default/template/cms/browser/js.phtml index d3b4a81ca0..7f05ec014a 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/js.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/browser/tree.phtml b/app/design/adminhtml/default/default/template/cms/browser/tree.phtml index 8028252123..7fd684b922 100644 --- a/app/design/adminhtml/default/default/template/cms/browser/tree.phtml +++ b/app/design/adminhtml/default/default/template/cms/browser/tree.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/cms/page/edit/form/renderer/content.phtml b/app/design/adminhtml/default/default/template/cms/page/edit/form/renderer/content.phtml index 71714affa2..8347946083 100644 --- a/app/design/adminhtml/default/default/template/cms/page/edit/form/renderer/content.phtml +++ b/app/design/adminhtml/default/default/template/cms/page/edit/form/renderer/content.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/coming.phtml b/app/design/adminhtml/default/default/template/coming.phtml index ef94959744..287ef7a15a 100644 --- a/app/design/adminhtml/default/default/template/coming.phtml +++ b/app/design/adminhtml/default/default/template/coming.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/compiler/process.phtml b/app/design/adminhtml/default/default/template/compiler/process.phtml index 1724a96900..9f0fbefa21 100644 --- a/app/design/adminhtml/default/default/template/compiler/process.phtml +++ b/app/design/adminhtml/default/default/template/compiler/process.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/authors.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/authors.phtml index 3f6c30009f..11b5fe2d1f 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/authors.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/authors.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/contents.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/contents.phtml index e3827ed91f..89518bf151 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/contents.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/contents.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/depends.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/depends.phtml index 3be89e3569..e2a90dbd2c 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/depends.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/depends.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/load.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/load.phtml index 2bb7d06adb..6103ecad84 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/load.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/load.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/package.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/package.phtml index 20377a46b4..eb1a12800c 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/package.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/package.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/connect/extension/custom/release.phtml b/app/design/adminhtml/default/default/template/connect/extension/custom/release.phtml index 47f5c773a5..fbc08a27e9 100644 --- a/app/design/adminhtml/default/default/template/connect/extension/custom/release.phtml +++ b/app/design/adminhtml/default/default/template/connect/extension/custom/release.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/edit/js.phtml b/app/design/adminhtml/default/default/template/customer/edit/js.phtml index 6fb770f7bd..90a187665f 100644 --- a/app/design/adminhtml/default/default/template/customer/edit/js.phtml +++ b/app/design/adminhtml/default/default/template/customer/edit/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/edit/tab/view/grid/item.phtml b/app/design/adminhtml/default/default/template/customer/edit/tab/view/grid/item.phtml index b99d97955e..7fce785e0d 100644 --- a/app/design/adminhtml/default/default/template/customer/edit/tab/view/grid/item.phtml +++ b/app/design/adminhtml/default/default/template/customer/edit/tab/view/grid/item.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/online.phtml b/app/design/adminhtml/default/default/template/customer/online.phtml index 738c9b8344..3f54eccf21 100644 --- a/app/design/adminhtml/default/default/template/customer/online.phtml +++ b/app/design/adminhtml/default/default/template/customer/online.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/addresses.phtml b/app/design/adminhtml/default/default/template/customer/tab/addresses.phtml index 3566bc284d..ef09ff8b79 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/addresses.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/addresses.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> @@ -114,7 +114,6 @@ getFormObject()->setHtmlIdPrefix($_templatePrefix) - ->setValues(array('country_id' => Mage::helper('core')->getDefaultCountry($customer->getStore()))) ->setFieldNameSuffix('address['.$_templatePrefix.']'); ?> getFormObject()->getHtml() ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/cart.phtml b/app/design/adminhtml/default/default/template/customer/tab/cart.phtml index cc4d682803..512e7a16f6 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/cart.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/cart.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/newsletter.phtml b/app/design/adminhtml/default/default/template/customer/tab/newsletter.phtml index 65fdad3ae1..1e3ddc990e 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/newsletter.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/newsletter.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/view.phtml b/app/design/adminhtml/default/default/template/customer/tab/view.phtml index 731e159810..dc22466d85 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/view.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/view.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/view/sales.phtml b/app/design/adminhtml/default/default/template/customer/tab/view/sales.phtml index fb7c559c55..c35ab690b1 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/view/sales.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/view/sales.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/customer/tab/wishlist.phtml b/app/design/adminhtml/default/default/template/customer/tab/wishlist.phtml index 0e50be2da3..57e4a6e0c6 100644 --- a/app/design/adminhtml/default/default/template/customer/tab/wishlist.phtml +++ b/app/design/adminhtml/default/default/template/customer/tab/wishlist.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/graph.phtml b/app/design/adminhtml/default/default/template/dashboard/graph.phtml index 4ddae62701..4382550c3e 100644 --- a/app/design/adminhtml/default/default/template/dashboard/graph.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/graph.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /* diff --git a/app/design/adminhtml/default/default/template/dashboard/graph/disabled.phtml b/app/design/adminhtml/default/default/template/dashboard/graph/disabled.phtml index cd63b976ba..b5ca4cf6f0 100644 --- a/app/design/adminhtml/default/default/template/dashboard/graph/disabled.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/graph/disabled.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/grid.phtml b/app/design/adminhtml/default/default/template/dashboard/grid.phtml index 57b77767be..8f8b526d71 100644 --- a/app/design/adminhtml/default/default/template/dashboard/grid.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/grid.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/index.phtml b/app/design/adminhtml/default/default/template/dashboard/index.phtml index 6dd7d58d80..588504bd14 100644 --- a/app/design/adminhtml/default/default/template/dashboard/index.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/index.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/salebar.phtml b/app/design/adminhtml/default/default/template/dashboard/salebar.phtml index 1a36140c5b..ca849d1ec2 100644 --- a/app/design/adminhtml/default/default/template/dashboard/salebar.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/salebar.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/searches.phtml b/app/design/adminhtml/default/default/template/dashboard/searches.phtml index 952e4587d4..02928d0534 100644 --- a/app/design/adminhtml/default/default/template/dashboard/searches.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/searches.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/store/switcher.phtml b/app/design/adminhtml/default/default/template/dashboard/store/switcher.phtml index 427cf196e0..52c1d4daeb 100644 --- a/app/design/adminhtml/default/default/template/dashboard/store/switcher.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/store/switcher.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/dashboard/totalbar.phtml b/app/design/adminhtml/default/default/template/dashboard/totalbar.phtml index 0fa9313904..f3c124c831 100644 --- a/app/design/adminhtml/default/default/template/dashboard/totalbar.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/totalbar.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/directory/js/optional_zip_countries.phtml b/app/design/adminhtml/default/default/template/directory/js/optional_zip_countries.phtml index de4a11a543..34ec85c64a 100644 --- a/app/design/adminhtml/default/default/template/directory/js/optional_zip_countries.phtml +++ b/app/design/adminhtml/default/default/template/directory/js/optional_zip_countries.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/product/composite/fieldset/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/product/composite/fieldset/downloadable.phtml index 0193a2517d..8245d26baf 100644 --- a/app/design/adminhtml/default/default/template/downloadable/product/composite/fieldset/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/product/composite/fieldset/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable.phtml index 4d4ba7bff5..188b66fc16 100644 --- a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> @@ -137,7 +137,9 @@ Downloadable.FileUploader.prototype = { } ); if ($(this.idName+'_save')) { - $(this.idName+'_save').value = this.fileValue.toJSON(); + $(this.idName+'_save').value = this.fileValue.toJSON + ? this.fileValue.toJSON() + : Object.toJSON(this.fileValue); } Downloadable.setUploaderObj( this.type, @@ -207,7 +209,9 @@ Downloadable.FileList.prototype = { this.updateFiles(); }, updateFiles: function() { - this.getElement('save').value = this.file.toJSON(); + this.getElement('save').value = this.file.toJSON + ? this.file.toJSON() + : Object.toJSON(this.file); this.file.each(function(row){ row.size = this.uploader.formatSize(row.size); $(this.containerId + '-old').innerHTML = this.listTemplate.evaluate(row); diff --git a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/links.phtml b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/links.phtml index 5ce50cca3d..bf5f4fc473 100644 --- a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/links.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/links.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/samples.phtml b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/samples.phtml index bfe987bb9e..3116693f0a 100644 --- a/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/samples.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/product/edit/downloadable/samples.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/creditmemo/name.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/creditmemo/name.phtml index 6f04c73e91..ae058b604f 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/creditmemo/name.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/creditmemo/name.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/invoice/name.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/invoice/name.phtml index be285e3036..668a3368cd 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/invoice/name.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/invoice/name.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/name.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/name.phtml index 09c53b5f5d..7bba1a45c3 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/name.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/items/column/downloadable/name.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/create/items/renderer/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/create/items/renderer/downloadable.phtml index 897efe3c03..666d34b024 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/create/items/renderer/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/create/items/renderer/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/view/items/renderer/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/view/items/renderer/downloadable.phtml index 97ac689c61..89501f5b52 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/view/items/renderer/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/order/creditmemo/view/items/renderer/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/create/items/renderer/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/create/items/renderer/downloadable.phtml index 94e575dfe7..019ae5f559 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/create/items/renderer/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/create/items/renderer/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/view/items/renderer/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/view/items/renderer/downloadable.phtml index 8cfcf69089..d04f924390 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/view/items/renderer/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/order/invoice/view/items/renderer/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml b/app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml index 0d190a55e0..7397b6a419 100644 --- a/app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml +++ b/app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml b/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml index f0e3c6b6c9..2acd065758 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/email/order/items.phtml b/app/design/adminhtml/default/default/template/email/order/items.phtml index 59273aa8c2..c9c7d352a7 100644 --- a/app/design/adminhtml/default/default/template/email/order/items.phtml +++ b/app/design/adminhtml/default/default/template/email/order/items.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/example.phtml b/app/design/adminhtml/default/default/template/example.phtml index 033464bb72..9fcd49d1d4 100644 --- a/app/design/adminhtml/default/default/template/example.phtml +++ b/app/design/adminhtml/default/default/template/example.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/forgotpassword.phtml b/app/design/adminhtml/default/default/template/forgotpassword.phtml index 38726115bb..8f1d9c3163 100644 --- a/app/design/adminhtml/default/default/template/forgotpassword.phtml +++ b/app/design/adminhtml/default/default/template/forgotpassword.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/formkey.phtml b/app/design/adminhtml/default/default/template/formkey.phtml index 31bc4f2bbd..a8e94b7d75 100644 --- a/app/design/adminhtml/default/default/template/formkey.phtml +++ b/app/design/adminhtml/default/default/template/formkey.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/form.phtml b/app/design/adminhtml/default/default/template/giftmessage/form.phtml index f4a096573b..6b1c09bbc7 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/form.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/form.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/giftoptionsform.phtml b/app/design/adminhtml/default/default/template/giftmessage/giftoptionsform.phtml index 33f54671b2..3422d8fbb3 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/giftoptionsform.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/giftoptionsform.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/helper.phtml b/app/design/adminhtml/default/default/template/giftmessage/helper.phtml index 4374d5a204..55d44648d2 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/helper.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/helper.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/popup.phtml b/app/design/adminhtml/default/default/template/giftmessage/popup.phtml index ed5e2baa63..b892717ca8 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/popup.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/popup.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/giftoptions.phtml b/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/giftoptions.phtml index 7665fbbd51..8934bb3df7 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/giftoptions.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/giftoptions.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/items.phtml b/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/items.phtml index b4fa61f6f8..57595cc328 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/items.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/sales/order/create/items.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/giftoptions.phtml b/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/giftoptions.phtml index ac0650d4ed..4b9d1e554a 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/giftoptions.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/giftoptions.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/items.phtml b/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/items.phtml index 60ecb4d7fb..59ccc54359 100644 --- a/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/items.phtml +++ b/app/design/adminhtml/default/default/template/giftmessage/sales/order/view/items.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/googlebase/captcha.phtml b/app/design/adminhtml/default/default/template/googlebase/captcha.phtml index 7e00b2de72..6ea56e8ca1 100644 --- a/app/design/adminhtml/default/default/template/googlebase/captcha.phtml +++ b/app/design/adminhtml/default/default/template/googlebase/captcha.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/googlebase/items.phtml b/app/design/adminhtml/default/default/template/googlebase/items.phtml index 940564a5fd..78c58a8351 100644 --- a/app/design/adminhtml/default/default/template/googlebase/items.phtml +++ b/app/design/adminhtml/default/default/template/googlebase/items.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/googlebase/types/edit/attributes.phtml b/app/design/adminhtml/default/default/template/googlebase/types/edit/attributes.phtml index ad1aaac89e..a7029b1de8 100644 --- a/app/design/adminhtml/default/default/template/googlebase/types/edit/attributes.phtml +++ b/app/design/adminhtml/default/default/template/googlebase/types/edit/attributes.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/googleoptimizer/cms/edit/renderer/conversion.phtml b/app/design/adminhtml/default/default/template/googleoptimizer/cms/edit/renderer/conversion.phtml index 4534db5b17..7b66051532 100644 --- a/app/design/adminhtml/default/default/template/googleoptimizer/cms/edit/renderer/conversion.phtml +++ b/app/design/adminhtml/default/default/template/googleoptimizer/cms/edit/renderer/conversion.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/googleoptimizer/js.phtml b/app/design/adminhtml/default/default/template/googleoptimizer/js.phtml index 46fb5d1d76..82f52d1b1e 100644 --- a/app/design/adminhtml/default/default/template/googleoptimizer/js.phtml +++ b/app/design/adminhtml/default/default/template/googleoptimizer/js.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/adminhtml/default/default/template/importexport/busy.phtml b/app/design/adminhtml/default/default/template/importexport/busy.phtml index 32281ef336..456a88f946 100644 --- a/app/design/adminhtml/default/default/template/importexport/busy.phtml +++ b/app/design/adminhtml/default/default/template/importexport/busy.phtml @@ -1,3 +1,29 @@ +

      __('System busy'); ?>

      diff --git a/app/design/adminhtml/default/default/template/importexport/export/form/after.phtml b/app/design/adminhtml/default/default/template/importexport/export/form/after.phtml index 1f76b94b65..45be749741 100644 --- a/app/design/adminhtml/default/default/template/importexport/export/form/after.phtml +++ b/app/design/adminhtml/default/default/template/importexport/export/form/after.phtml @@ -1,3 +1,29 @@ + - + getShortDescription()):?>

      __('Quick Overview') ?>

      diff --git a/app/design/frontend/default/modern/template/catalog/product/view/media.phtml b/app/design/frontend/default/modern/template/catalog/product/view/media.phtml index 9c9ece1e22..527397676e 100644 --- a/app/design/frontend/default/modern/template/catalog/product/view/media.phtml +++ b/app/design/frontend/default/modern/template/catalog/product/view/media.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/frontend/default/modern/template/catalog/product/view/tabs.phtml b/app/design/frontend/default/modern/template/catalog/product/view/tabs.phtml index 3b82cb03c3..b9693992f1 100644 --- a/app/design/frontend/default/modern/template/catalog/product/view/tabs.phtml +++ b/app/design/frontend/default/modern/template/catalog/product/view/tabs.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/frontend/default/modern/template/catalogsearch/form.mini.phtml b/app/design/frontend/default/modern/template/catalogsearch/form.mini.phtml index abd43f18ca..1283d1b909 100644 --- a/app/design/frontend/default/modern/template/catalogsearch/form.mini.phtml +++ b/app/design/frontend/default/modern/template/catalogsearch/form.mini.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/frontend/default/modern/template/checkout/cart.phtml b/app/design/frontend/default/modern/template/checkout/cart.phtml index 0f7d718dbf..7f12065a07 100644 --- a/app/design/frontend/default/modern/template/checkout/cart.phtml +++ b/app/design/frontend/default/modern/template/checkout/cart.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/frontend/default/modern/template/newsletter/subscribe.phtml b/app/design/frontend/default/modern/template/newsletter/subscribe.phtml index ecf2b6f3ef..aadb52d5b4 100644 --- a/app/design/frontend/default/modern/template/newsletter/subscribe.phtml +++ b/app/design/frontend/default/modern/template/newsletter/subscribe.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/frontend/default/modern/template/page/3columns.phtml b/app/design/frontend/default/modern/template/page/3columns.phtml index a116ad7a33..aa8a272082 100644 --- a/app/design/frontend/default/modern/template/page/3columns.phtml +++ b/app/design/frontend/default/modern/template/page/3columns.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/frontend/default/modern/template/page/html/footer.phtml b/app/design/frontend/default/modern/template/page/html/footer.phtml index 8c4100f5db..8b1791b093 100644 --- a/app/design/frontend/default/modern/template/page/html/footer.phtml +++ b/app/design/frontend/default/modern/template/page/html/footer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/frontend/default/modern/template/page/html/header.phtml b/app/design/frontend/default/modern/template/page/html/header.phtml index f42740c9ec..d4aa6b4ffa 100644 --- a/app/design/frontend/default/modern/template/page/html/header.phtml +++ b/app/design/frontend/default/modern/template/page/html/header.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /** diff --git a/app/design/frontend/default/modern/template/sample/home.phtml b/app/design/frontend/default/modern/template/sample/home.phtml index 64a282422e..0fbcf4aba5 100644 --- a/app/design/frontend/default/modern/template/sample/home.phtml +++ b/app/design/frontend/default/modern/template/sample/home.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_modern - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/install/default/default/layout/main.xml b/app/design/install/default/default/layout/main.xml index 3c5fc210e3..61a3f713c3 100644 --- a/app/design/install/default/default/layout/main.xml +++ b/app/design/install/default/default/layout/main.xml @@ -21,7 +21,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -32,7 +32,14 @@ - + + + + + + mysql4install/db_type_mysql4 + + diff --git a/app/design/install/default/default/template/install/begin.phtml b/app/design/install/default/default/template/install/begin.phtml index 4f07bc1317..306d43c11b 100644 --- a/app/design/install/default/default/template/install/begin.phtml +++ b/app/design/install/default/default/template/install/begin.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/install/default/default/template/install/config.phtml b/app/design/install/default/default/template/install/config.phtml index bf4d74cb12..6d0e7a2d3c 100644 --- a/app/design/install/default/default/template/install/config.phtml +++ b/app/design/install/default/default/template/install/config.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -28,53 +28,18 @@ * Install configuration template * * @see Mage_Install_Block_Config + * @var $this Mage_Install_Block_Config */ ?>

      __('Configuration') ?>

      getMessagesBlock()->getGroupedHtml() ?> - getInstaller()->getServerCheckStatus()): ?>
      -
      - __('Connection') ?> -

      __('Database Connection') ?>

      -
        -
      • -
        -
        - -

        - __('You can specify server port, ex.: localhost:3307
        If you are not using default UNIX socket, you can specify it here instead of host, ex.: /var/run/mysqld/mysqld.sock') ?>
        -

        -
        -
        -
        - -
        -
      • -
      • -
        -
        - -
        -
        -
        - -
        -
      • -
      • -
        -
        - -

        - __('(Optional. Leave blank for no prefix)') ?> -

        -
        -
      • -
      -
      + + +getLayout()->getBlock('database')->toHtml() ?>
      __('Web access options') ?> diff --git a/app/design/install/default/default/template/install/create_admin.phtml b/app/design/install/default/default/template/install/create_admin.phtml index fca179212c..61df414140 100644 --- a/app/design/install/default/default/template/install/create_admin.phtml +++ b/app/design/install/default/default/template/install/create_admin.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/install/default/default/template/install/db/main.phtml b/app/design/install/default/default/template/install/db/main.phtml new file mode 100644 index 0000000000..5358cf2403 --- /dev/null +++ b/app/design/install/default/default/template/install/db/main.phtml @@ -0,0 +1,75 @@ + + + +
      + __('Connection') ?> +

      __('Database Connection') ?>

      +
        + getDatabaseBlocks(); ?> + 0): ?> +
      • +
        +
        + +
        +
      • + + + + + getDatabaseBlock($block->getIdPrefix()) ?> +
        getFormData()->getDbModel() != $block->getIdPrefix()):?>style="display:none;">toHtml(); ?>
        + +
      +
      diff --git a/app/design/install/default/default/template/install/db/mysql4.phtml b/app/design/install/default/default/template/install/db/mysql4.phtml new file mode 100644 index 0000000000..9b3c6fd147 --- /dev/null +++ b/app/design/install/default/default/template/install/db/mysql4.phtml @@ -0,0 +1,65 @@ + +
    • +
      +
      + +

      + __('You can specify server port, ex.: localhost:3307
      If you are not using default UNIX socket, you can specify it here instead of host, ex.: /var/run/mysqld/mysqld.sock') ?>
      +

      +
      +
      +
      + +
      +
    • +
    • +
      +
      + +
      +
      +
      + +
      +
    • +
    • +
      +
      + +

      + __('(Optional. Leave blank for no prefix)') ?> +

      +
      +
    • diff --git a/app/design/install/default/default/template/install/download.phtml b/app/design/install/default/default/template/install/download.phtml index be32ae71cc..5582ef84fc 100644 --- a/app/design/install/default/default/template/install/download.phtml +++ b/app/design/install/default/default/template/install/download.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/install/default/default/template/install/end.phtml b/app/design/install/default/default/template/install/end.phtml index 9ca754abcb..b00b7ae3f2 100644 --- a/app/design/install/default/default/template/install/end.phtml +++ b/app/design/install/default/default/template/install/end.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/install/default/default/template/install/locale.phtml b/app/design/install/default/default/template/install/locale.phtml index 067a85f9eb..850ecd958c 100644 --- a/app/design/install/default/default/template/install/locale.phtml +++ b/app/design/install/default/default/template/install/locale.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/app/design/install/default/default/template/install/state.phtml b/app/design/install/default/default/template/install/state.phtml index 38aaef5cf6..842203c6c0 100644 --- a/app/design/install/default/default/template/install/state.phtml +++ b/app/design/install/default/default/template/install/state.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/design/install/default/default/template/page.phtml b/app/design/install/default/default/template/page.phtml index 7c5649e537..866ebb7759 100644 --- a/app/design/install/default/default/template/page.phtml +++ b/app/design/install/default/default/template/page.phtml @@ -20,7 +20,7 @@ * * @category design * @package default_default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> @@ -40,6 +40,7 @@ + diff --git a/app/etc/config.xml b/app/etc/config.xml index a833fa3e68..3a570d79ef 100644 --- a/app/etc/config.xml +++ b/app/etc/config.xml @@ -21,20 +21,20 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - + localhost - + magento mysql4 @@ -76,6 +76,7 @@ + Varien_Db_Adapter_Pdo_Mysql Mage_Core_Model_Resource_Type_Db_Pdo_Mysql @@ -87,23 +88,37 @@ Mage_Core_Model - core_mysql4 + core_resource - - Mage_Core_Model_Mysql4 + + Mage_Core_Model_Resource + core_mysql4 - core_config_data
      - core_website
      - core_store
      - core_resource
      - core_cache
      - core_cache_tag
      - core_cache_option
      + + core_config_data
      +
      + + core_website
      +
      + + core_store
      +
      + + core_resource
      +
      + + core_cache
      +
      + + core_cache_tag
      +
      + + core_cache_option
      +
      -
      +
      - @@ -131,4 +146,7 @@ + + Varien +
      diff --git a/app/etc/local.xml.template b/app/etc/local.xml.template index 578b008004..fe17daa992 100644 --- a/app/etc/local.xml.template +++ b/app/etc/local.xml.template @@ -44,6 +44,10 @@ {{db_user}} {{db_pass}} {{db_name}} + {{db_init_statemants}} + {{db_model}} + {{db_type}} + {{db_pdo_type}} 1 diff --git a/app/etc/modules/Find_Feed.xml b/app/etc/modules/Find_Feed.xml index 101edb900b..3b7cc1b052 100644 --- a/app/etc/modules/Find_Feed.xml +++ b/app/etc/modules/Find_Feed.xml @@ -21,14 +21,14 @@ * * @category Find * @package Find_Feed - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - true + false community diff --git a/app/etc/modules/Mage_All.xml b/app/etc/modules/Mage_All.xml index e659f18109..44cd9edad7 100644 --- a/app/etc/modules/Mage_All.xml +++ b/app/etc/modules/Mage_All.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -252,6 +252,7 @@ core + @@ -376,6 +377,7 @@ + diff --git a/app/etc/modules/Mage_Api.xml b/app/etc/modules/Mage_Api.xml index 25dc17b7ca..221755f06b 100644 --- a/app/etc/modules/Mage_Api.xml +++ b/app/etc/modules/Mage_Api.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Api - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Authorizenet.xml b/app/etc/modules/Mage_Authorizenet.xml index 01dc57da13..81a887a220 100755 --- a/app/etc/modules/Mage_Authorizenet.xml +++ b/app/etc/modules/Mage_Authorizenet.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Authorizenet - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Bundle.xml b/app/etc/modules/Mage_Bundle.xml index f1077150d5..548c813708 100644 --- a/app/etc/modules/Mage_Bundle.xml +++ b/app/etc/modules/Mage_Bundle.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Bundle - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Centinel.xml b/app/etc/modules/Mage_Centinel.xml index 30b5e87fee..180c0cec2b 100644 --- a/app/etc/modules/Mage_Centinel.xml +++ b/app/etc/modules/Mage_Centinel.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Centinel - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Compiler.xml b/app/etc/modules/Mage_Compiler.xml index 6b1279d37d..b1b3a4481f 100644 --- a/app/etc/modules/Mage_Compiler.xml +++ b/app/etc/modules/Mage_Compiler.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Compiler - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Connect.xml b/app/etc/modules/Mage_Connect.xml index e7a1ab546f..8125e961d6 100644 --- a/app/etc/modules/Mage_Connect.xml +++ b/app/etc/modules/Mage_Connect.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Downloadable.xml b/app/etc/modules/Mage_Downloadable.xml index 6221111506..4d18665fa6 100644 --- a/app/etc/modules/Mage_Downloadable.xml +++ b/app/etc/modules/Mage_Downloadable.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Downloadable - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -32,6 +32,7 @@ core + diff --git a/app/etc/modules/Mage_ImportExport.xml b/app/etc/modules/Mage_ImportExport.xml index 85d375e787..314f4dc676 100755 --- a/app/etc/modules/Mage_ImportExport.xml +++ b/app/etc/modules/Mage_ImportExport.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_ImportExport - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -30,6 +30,9 @@ true core + + + diff --git a/app/etc/modules/Mage_PageCache.xml b/app/etc/modules/Mage_PageCache.xml index 3abd89dcdb..34ee30e9c3 100644 --- a/app/etc/modules/Mage_PageCache.xml +++ b/app/etc/modules/Mage_PageCache.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_PageCache - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Weee.xml b/app/etc/modules/Mage_Weee.xml index edf31b4a9c..3b55ba4196 100644 --- a/app/etc/modules/Mage_Weee.xml +++ b/app/etc/modules/Mage_Weee.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Weee - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_Widget.xml b/app/etc/modules/Mage_Widget.xml index 1c1816ac4e..d3958ba92b 100644 --- a/app/etc/modules/Mage_Widget.xml +++ b/app/etc/modules/Mage_Widget.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_Widget - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Mage_XmlConnect.xml b/app/etc/modules/Mage_XmlConnect.xml index dbab532279..9b36095f4f 100644 --- a/app/etc/modules/Mage_XmlConnect.xml +++ b/app/etc/modules/Mage_XmlConnect.xml @@ -21,7 +21,7 @@ * * @category Mage * @package Mage_XmlConnect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/app/etc/modules/Phoenix_Moneybookers.xml b/app/etc/modules/Phoenix_Moneybookers.xml index eacc75ee3e..dcd3f49736 100644 --- a/app/etc/modules/Phoenix_Moneybookers.xml +++ b/app/etc/modules/Phoenix_Moneybookers.xml @@ -15,7 +15,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> diff --git a/app/locale/en_US/Mage_Adminhtml.csv b/app/locale/en_US/Mage_Adminhtml.csv index 173c7f8395..e9408eff51 100644 --- a/app/locale/en_US/Mage_Adminhtml.csv +++ b/app/locale/en_US/Mage_Adminhtml.csv @@ -75,7 +75,6 @@ "Add New URL Rewrite","Add New URL Rewrite" "Add New User","Add New User" "Add New Variable","Add New Variable" -"Add New osCommerce Profile","Add New osCommerce Profile" "Add PHP Extension dependency","Add PHP Extension dependency" "Add Package dependency","Add Package dependency" "Add URL Rewrite","Add URL Rewrite" @@ -222,7 +221,6 @@ "Clear","Clear" "Close","Close" "Comment text field cannot be empty.","Comment text field cannot be empty." -"Comments History","Comments History" "Complete","Complete" "Configuration","Configuration" "Confirmed email:","Confirmed email:" @@ -276,7 +274,6 @@ "Data Format","Data Format" "Data transfer:","Data transfer:" "Database","Database" -"Dataflow - Advance Profiles","Dataflow - Advance Profiles" "Dataflow - Advanced Profiles","Dataflow - Advanced Profiles" "Dataflow - Profiles","Dataflow - Profiles" "Date","Date" @@ -359,7 +356,6 @@ "Expiration Date: %s/%s","Expiration Date: %s/%s" "Export","Export" "Export CSV","Export CSV" -"Export FAQ","Export FAQ" "Export Filters","Export Filters" "Export to:","Export to:" "Export:","Export:" @@ -381,7 +377,6 @@ "File name:","File name:" "File size should be more than 0 bytes","File size should be more than 0 bytes" "Files","Files" -"Final Price","Final Price" "Finished profile execution.","Finished profile execution." "First Invoice Created Date","First Invoice Created Date" "First Name","First Name" @@ -433,8 +428,6 @@ "Images (.gif, .jpg, .png)","Images (.gif, .jpg, .png)" "Images Cache","Images Cache" "Import","Import" -"Import / Export FAQ (Frequently Asked Questions)","Import / Export FAQ (Frequently Asked Questions)" -"Import FAQ","Import FAQ" "Import Service","Import Service" "Import and Export","Import and Export" "Import and Export Tax Rates","Import and Export Tax Rates" @@ -546,8 +539,6 @@ "Manage Stores","Manage Stores" "Manage Tax Rules","Manage Tax Rules" "Manage Tax Zones and Rates","Manage Tax Zones and Rates" -"Manage osCommerce Orders","Manage osCommerce Orders" -"Manage osCommerce Profiles","Manage osCommerce Profiles" "Manual","Manual" "Matched Expression","Matched Expression" "Max","Max" @@ -750,7 +741,6 @@ "Preview","Preview" "Preview Template","Preview Template" "Previous page","Previous page" -"Price","Price" "Price alert subscription was saved.","Price alert subscription was saved." "Price:","Price:" "Processed %s%% %s/%d records","Processed %s%% %s/%d records" @@ -779,7 +769,6 @@ "Promo","Promo" "Promotions","Promotions" "Purchased Item","Purchased Item" -"Qty","Qty" "Qty:","Qty:" "Quantity","Quantity" "Queue Refresh","Queue Refresh" @@ -905,7 +894,6 @@ "Skip Category Selection","Skip Category Selection" "Some items in this order have different invoice and shipment types. You can create shipment only after the invoice is created.","Some items in this order have different invoice and shipment types. You can create shipment only after the invoice is created." "Some of the ordered items do not exist in the catalog anymore and will be removed if you try to edit the order.","Some of the ordered items do not exist in the catalog anymore and will be removed if you try to edit the order." -"Some other FAQ","Some other FAQ" "Sorry, this feature is coming soon...","Sorry, this feature is coming soon..." "Sort Order","Sort Order" "Special Price:","Special Price:" diff --git a/app/locale/en_US/Mage_Api.csv b/app/locale/en_US/Mage_Api.csv index d79807793c..1543a10a72 100644 --- a/app/locale/en_US/Mage_Api.csv +++ b/app/locale/en_US/Mage_Api.csv @@ -74,7 +74,6 @@ "Clear","Clear" "Client Session Timeout (sec.)","Client Session Timeout (sec.)" "Close","Close" -"Comments History","Comments History" "Confirmed email:","Confirmed email:" "Connect with the Magento Community","Connect with the Magento Community" "Contents","Contents" @@ -128,7 +127,6 @@ "Expiration Date","Expiration Date" "Expiration Date: %s/%s","Expiration Date: %s/%s" "Export","Export" -"Export FAQ","Export FAQ" "Export Filters","Export Filters" "Export to:","Export to:" "Export:","Export:" @@ -141,7 +139,6 @@ "File mode","File mode" "File name:","File name:" "Files","Files" -"Final Price","Final Price" "Finished profile execution.","Finished profile execution." "First Name:","First Name:" "For latest version visit: %s","For latest version visit: %s" @@ -161,8 +158,6 @@ "Ignore","Ignore" "Images","Images" "Import","Import" -"Import / Export FAQ (Frequently Asked Questions)","Import / Export FAQ (Frequently Asked Questions)" -"Import FAQ","Import FAQ" "Import Service","Import Service" "Important: ","Important: " "In Database:","In Database:" @@ -233,7 +228,6 @@ "Only mapped fields","Only mapped fields" "Options menu items","Options menu items" "Order ID","Order ID" -"Order Totals","Order Totals" "Order cannot be placed.","Order cannot be placed." "Original Magento attribute names in first row:","Original Magento attribute names in first row:" "Out of stock","Out of stock" @@ -286,15 +280,12 @@ "Prev. year (hold for menu)","Prev. year (hold for menu)" "Preview","Preview" "Previous page","Previous page" -"Price","Price" "Price:","Price:" -"Product","Product" "Product Name3 ","Product Name3 " "Product Name3 1","Product Name3 1" "Product Name3 2","Product Name3 2" "Products","Products" "Profile Information","Profile Information" -"Qty","Qty" "Qty:","Qty:" "Read details","Read details" "Reference ID","Reference ID" @@ -309,7 +300,6 @@ "Role Users","Role Users" "Roles","Roles" "Roles Resources","Roles Resources" -"SKU","SKU" "SKU:","SKU:" "SORT BY:","SORT BY:" "Save Theme","Save Theme" @@ -329,7 +319,6 @@ "Show confirmation page: ","Show confirmation page: " "Silent Post URL:","Silent Post URL:" "Some items in this order have different invoice and shipment types. You can create shipment only after the invoice is created.","Some items in this order have different invoice and shipment types. You can create shipment only after the invoice is created." -"Some other FAQ","Some other FAQ" "Sort Order","Sort Order" "Special Price:","Special Price:" "Spreadsheet Name:","Spreadsheet Name:" diff --git a/app/locale/en_US/Mage_Catalog.csv b/app/locale/en_US/Mage_Catalog.csv index a096837ab9..c5c21445b3 100644 --- a/app/locale/en_US/Mage_Catalog.csv +++ b/app/locale/en_US/Mage_Catalog.csv @@ -46,11 +46,10 @@ "Allow HTML Tags on Frontend","Allow HTML Tags on Frontend" "Allowed File Extensions","Allowed File Extensions" "Allowed file extensions to upload","Allowed file extensions to upload" -"An error occurred while adding customers for the %s alert. Message: %s","An error occurred while adding customers for the %s alert. Message: %s" "An error occurred while adding products to websites.","An error occurred while adding products to websites." "An error occurred while clearing comparison list.","An error occurred while clearing comparison list." "An error occurred while removing products from websites.","An error occurred while removing products from websites." -"An error occurred while saving the URL rewrite.","An error occurred while saving the URL rewrite." +"An error occurred while saving the URL rewrite","An error occurred while saving the URL rewrite" "An error occurred while saving the attribute set.","An error occurred while saving the attribute set." "An error occurred while saving the product. ","An error occurred while saving the product. " "An error occurred while saving the search query.","An error occurred while saving the search query." @@ -152,6 +151,7 @@ "Category URL Suffix","Category URL Suffix" "Category attributes API","Category attributes API" "Category move error","Category move error" +"Category move operation is not possible: the current category was not found.","Category move operation is not possible: the current category was not found." "Category move operation is not possible: the new parent category was not found.","Category move operation is not possible: the new parent category was not found." "Category must be an instance of Mage_Catalog_Model_Category.","Category must be an instance of Mage_Catalog_Model_Category." "Center","Center" @@ -192,7 +192,6 @@ "Customer Group","Customer Group" "Customers Reviews","Customers Reviews" "Customers Tagged Product","Customers Tagged Product" -"Customers for alert %s were successfuly added to queue","Customers for alert %s were successfuly added to queue" "Data Type for Saving in Database","Data Type for Saving in Database" "Date & Time Custom Options","Date & Time Custom Options" "Date Fields Order","Date Fields Order" @@ -236,7 +235,6 @@ "Edit Search '%s'","Edit Search '%s'" "Edit Set Name","Edit Set Name" "Email","Email" -"Email to %s was not sent.","Email to %s was not sent." "Email to a Friend","Email to a Friend" "Empty","Empty" "Enable Qty Increments","Enable Qty Increments" @@ -293,7 +291,7 @@ "Input Type","Input Type" "Integer","Integer" "Invalid Tier Prices","Invalid Tier Prices" -"Invalid attribute %s.","Invalid attribute %s." +"Invalid attribute %s","Invalid attribute %s" "Invalid attribute option specified for attribute %s (%s), skipping the record.","Invalid attribute option specified for attribute %s (%s), skipping the record." "Invalid attribute set specified, skipping the record.","Invalid attribute set specified, skipping the record." "Invalid block: %s.","Invalid block: %s." @@ -306,7 +304,6 @@ "Invalid store specified","Invalid store specified" "Invalid store specified, skipping the record.","Invalid store specified, skipping the record." "Invalid tier prices. The product is not associated to the requested website.","Invalid tier prices. The product is not associated to the requested website." -"Invalid transactional email code.","Invalid transactional email code." "Inventory","Inventory" "Is Default","Is Default" "Is Required","Is Required" @@ -418,7 +415,6 @@ "Position in Layered Navigation","Position in Layered Navigation" "Position of attribute in layered navigation block","Position of attribute in layered navigation block" "Prev","Prev" -"Previous","Previous" "Price","Price" "Price Navigation Step Calculation","Price Navigation Step Calculation" "Price Type","Price Type" @@ -532,6 +528,7 @@ "Save and Continue Edit","Save and Continue Edit" "Saved %d record(s)","Saved %d record(s)" "Scope","Scope" +"Scope must not be changed, because the attribute is used in configurable products.","Scope must not be changed, because the attribute is used in configurable products." "Search","Search" "Search Engine Optimizations","Search Engine Optimizations" "Search Information","Search Information" @@ -590,18 +587,18 @@ "Tax","Tax" "Template","Template" "Text","Text" -"The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module.","The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module." +"The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module","The Flat Catalog module has a limit of %2\$d filterable and/or sortable attributes. Currently there are %1\$d of them. Please reduce the number of filterable/sortable attributes in order to use this module" "The attribute model is not defined","The attribute model is not defined" "The attribute set has been saved.","The attribute set has been saved." "The base directory to upload file is not specified.","The base directory to upload file is not specified." "The category has been deleted.","The category has been deleted." "The category has been saved.","The category has been saved." "The comparison list was cleared.","The comparison list was cleared." -"The email template is not specified by administrator.","The email template is not specified by administrator." "The file you uploaded is larger than %s Megabytes allowed by server","The file you uploaded is larger than %s Megabytes allowed by server" "The filters must be an array.","The filters must be an array." "The image contents is not valid base64 data.","The image contents is not valid base64 data." "The image is not specified.","The image is not specified." +"The model collection resource name is not defined.","The model collection resource name is not defined." "The product %s has been added to comparison list.","The product %s has been added to comparison list." "The product %s has been removed from comparison list.","The product %s has been removed from comparison list." "The product attribute has been deleted.","The product attribute has been deleted." @@ -637,7 +634,7 @@ "Tile","Tile" "Time Format","Time Format" "Title","Title" -"To reindex the enabled product(s), the store or product must be specified.","To reindex the enabled product(s), the store or product must be specified." +"To reindex the enabled product(s), the store or product must be specified","To reindex the enabled product(s), the store or product must be specified" "Top/Left","Top/Left" "Top/Right","Top/Right" "Total Qty Base Items","Total Qty Base Items" @@ -718,12 +715,8 @@ "Wrong product type to extract configurable options.","Wrong product type to extract configurable options." "Year Range","Year Range" "Yes","Yes" -"You cannot email this product to a friend.","You cannot email this product to a friend." "You cannot remove system attribute from this set.","You cannot remove system attribute from this set." -"You cannot send more than %d emails at a time.","You cannot send more than %d emails at a time." -"You have exceeded limit of %d sends in an hour.","You have exceeded limit of %d sends in an hour." "You have no items to compare.","You have no items to compare." -"You have to specify at least one recipient.","You have to specify at least one recipient." "You may also be interested in the following product(s)","You may also be interested in the following product(s)" "Zoom In","Zoom In" "Zoom Out","Zoom Out" diff --git a/app/locale/en_US/Mage_CatalogInventory.csv b/app/locale/en_US/Mage_CatalogInventory.csv index 6e899b2e85..387987ba5a 100644 --- a/app/locale/en_US/Mage_CatalogInventory.csv +++ b/app/locale/en_US/Mage_CatalogInventory.csv @@ -1,4 +1,3 @@ -"""%s"" is not available in the requested quantity. %s of the items will be backordered.","""%s"" is not available in the requested quantity. %s of the items will be backordered." "%s is available for purchase in increments of %s only.","%s is available for purchase in increments of %s only." "%s is not a correct comparsion method.","%s is not a correct comparsion method." "Note that these settings are applicable to cart line items, not the whole cart.","Note that these settings are applicable to cart line items, not the whole cart." @@ -34,20 +33,12 @@ "Retrieve stock data by product ids","Retrieve stock data by product ids" "Rule price","Rule price" "Set Items' Status to be In Stock When Order is Cancelled","Set Items' Status to be In Stock When Order is Cancelled" -"Some of the products are currently out of stock","Some of the products are currently out of stock" -"Some of the products cannot be ordered in requested quantity.","Some of the products cannot be ordered in requested quantity." "Some of the products cannot be ordered in the requested quantity.","Some of the products cannot be ordered in the requested quantity." "Stock Options","Stock Options" "Stock Status","Stock Status" -"The maximum quantity allowed for purchase is %s.","The maximum quantity allowed for purchase is %s." -"The minimum quantity allowed for purchase is %s.","The minimum quantity allowed for purchase is %s." -"The requested quantity for ""%s"" is not available.","The requested quantity for ""%s"" is not available." -"The requested quantity is not available.","The requested quantity is not available." "The stock item for Product in option is not valid.","The stock item for Product in option is not valid." "The stock item for Product is not valid.","The stock item for Product is not valid." "This product is available for purchase in increments of %s only.","This product is available for purchase in increments of %s only." -"This product is currently out of stock.","This product is currently out of stock." -"This product is not available in the requested quantity. %s of the items will be backordered.","This product is not available in the requested quantity. %s of the items will be backordered." "To Fixed Value","To Fixed Value" "To Percentage","To Percentage" "Undefined product type.","Undefined product type." diff --git a/app/locale/en_US/Mage_Checkout.csv b/app/locale/en_US/Mage_Checkout.csv index 28cecee10d..ce5438606e 100644 --- a/app/locale/en_US/Mage_Checkout.csv +++ b/app/locale/en_US/Mage_Checkout.csv @@ -304,4 +304,3 @@ "Your order number is ","Your order number is " "Your recurring payment profiles:","Your recurring payment profiles:" "Zip/Postal Code","Zip/Postal Code" -"osCommerce Orders","osCommerce Orders" diff --git a/app/locale/en_US/Mage_Core.csv b/app/locale/en_US/Mage_Core.csv index 9532849366..7cc352179e 100644 --- a/app/locale/en_US/Mage_Core.csv +++ b/app/locale/en_US/Mage_Core.csv @@ -46,9 +46,9 @@ "Cache storage may contain additional data. Are you sure that you want flush it?","Cache storage may contain additional data. Are you sure that you want flush it?" "Can not create invoice. Order was not found.","Can not create invoice. Order was not found." "Can't retrieve request object","Can't retrieve request object" +"Can\'t retrieve entity config: %s","Can\'t retrieve entity config: %s" "Cancel","Cancel" "Cannot complete this operation from non-admin area.","Cannot complete this operation from non-admin area." -"Cannot retrieve entity config: %s","Cannot retrieve entity config: %s" "Card type does not match credit card number.","Card type does not match credit card number." "Code","Code" "Controller file was loaded but class does not exist","Controller file was loaded but class does not exist" @@ -138,8 +138,10 @@ "Invalid block name to set child %s: %s","Invalid block name to set child %s: %s" "Invalid block type: %s","Invalid block type: %s" "Invalid block: %s","Invalid block: %s" +"Invalid connection","Invalid connection" "Invalid layout update handle","Invalid layout update handle" "Invalid messages storage ""%s"" for layout messages initialization","Invalid messages storage ""%s"" for layout messages initialization" +"Invalid query","Invalid query" "Invalid transactional email code: ","Invalid transactional email code: " "Invalid website\'s configuration path: %s","Invalid website\'s configuration path: %s" "JavaScript Settings","JavaScript Settings" @@ -165,7 +167,6 @@ "Miscellaneous Scripts","Miscellaneous Scripts" "Model class does not exist: %s.","Model class does not exist: %s." "Model collection resource name is not defined.","Model collection resource name is not defined." -"Module ""%1$s"" cannot depend on ""%2$s"".","Module ""%1$s"" cannot depend on ""%2$s""." "Module ""%1$s"" requires module ""%2$s"".","Module ""%1$s"" requires module ""%2$s""." "Name","Name" "New Design Change","New Design Change" @@ -173,6 +174,7 @@ "New Store View","New Store View" "New Website","New Website" "No","No" +"Offloader header","Offloader header" "Package","Package" "Pagination","Pagination" "Pagination Frame","Pagination Frame" @@ -289,7 +291,6 @@ "Templates","Templates" "Text length does not satisfy specified text range.","Text length does not satisfy specified text range." "The %s you entered is invalid. Please make sure that it follows ""http://domain.com/"" format.","The %s you entered is invalid. Please make sure that it follows ""http://domain.com/"" format." -"The model collection resource name is not defined.","The model collection resource name is not defined." "The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter","The store code may contain only letters (a-z), numbers (0-9) or underscore(_), the first character must be a letter" "The store does not exist","The store does not exist" "The store has been deleted.","The store has been deleted." @@ -329,6 +330,7 @@ "Unable to proceed. Please, try again.","Unable to proceed. Please, try again." "Unable to save file ""%s"" at ""%s""","Unable to save file ""%s"" at ""%s""" "Unable to save file: %s","Unable to save file: %s" +"Unknown old style column type definition: {$definition}.","Unknown old style column type definition: {$definition}." "Unknown scope ""%s"".","Unknown scope ""%s""." "Unsecure","Unsecure" "Url Options","Url Options" @@ -356,6 +358,7 @@ "Welcome Text","Welcome Text" "Wrong file info format","Wrong file info format" "Wrong number of arguments for %s","Wrong number of arguments for %s" +"Wrong old style column type definition: {$definition}.","Wrong old style column type definition: {$definition}." "Yes","Yes" "Your design change for the specified store intersects with another one, please specify another date range.","Your design change for the specified store intersects with another one, please specify another date range." "Your order cannot be completed at this time as there is no payment methods available for it.","Your order cannot be completed at this time as there is no payment methods available for it." diff --git a/app/locale/en_US/Mage_Customer.csv b/app/locale/en_US/Mage_Customer.csv index e1fddf6e72..3d943b9f2e 100644 --- a/app/locale/en_US/Mage_Customer.csv +++ b/app/locale/en_US/Mage_Customer.csv @@ -123,8 +123,8 @@ "Customer Since","Customer Since" "Customer View","Customer View" "Customer collection expected.","Customer collection expected." -"Customer email is required.","Customer email is required." -"Customer website ID must be specified when using the website scope.","Customer website ID must be specified when using the website scope." +"Customer email is required","Customer email is required" +"Customer website ID must be specified when using the website scope","Customer website ID must be specified when using the website scope" "Customer will stay on the current page if ""No"" is selected.","Customer will stay on the current page if ""No"" is selected." "Customers","Customers" "Customers Only","Customers Only" @@ -372,7 +372,7 @@ "The customer does not have default billing address.","The customer does not have default billing address." "The customer group has been deleted.","The customer group has been deleted." "The customer group has been saved.","The customer group has been saved." -"The group ""%s"" cannot be deleted.","The group ""%s"" cannot be deleted." +"The group ""%s"" cannot be deleted","The group ""%s"" cannot be deleted" "The password must have at least 6 characters. Leading or trailing spaces will be ignored.","The password must have at least 6 characters. Leading or trailing spaces will be ignored." "The suffix that goes after name (Jr., Sr., etc.)","The suffix that goes after name (Jr., Sr., etc.)" "The title that goes before name (Mr., Mrs., etc.)","The title that goes before name (Mr., Mrs., etc.)" @@ -381,7 +381,7 @@ "There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.","There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account." "This account is not confirmed.","This account is not confirmed." "This account is not confirmed. Click here to resend confirmation email.","This account is not confirmed. Click here to resend confirmation email." -"This customer email already exists.","This customer email already exists." +"This customer email already exists","This customer email already exists" "This customer has no saved addresses.","This customer has no saved addresses." "This email address was not found in our records.","This email address was not found in our records." "This email does not require confirmation.","This email does not require confirmation." @@ -411,7 +411,7 @@ "Wrong confirmation key.","Wrong confirmation key." "Wrong customer account specified.","Wrong customer account specified." "Wrong email.","Wrong email." -"Wrong transactional account email type.","Wrong transactional account email type." +"Wrong transactional account email type","Wrong transactional account email type" "YYYY","YYYY" "Year","Year" "Yes","Yes" diff --git a/app/locale/en_US/Mage_Eav.csv b/app/locale/en_US/Mage_Eav.csv index c3f8412184..483276bd66 100644 --- a/app/locale/en_US/Mage_Eav.csv +++ b/app/locale/en_US/Mage_Eav.csv @@ -1,57 +1,61 @@ -"A joint field with this alias (%s) is already declared.","A joint field with this alias (%s) is already declared." +"A joint field with this alias (%s) is already declared","A joint field with this alias (%s) is already declared" "Add Option","Add Option" "An error occurred while loading a record, aborting. Error: %s","An error occurred while loading a record, aborting. Error: %s" "An error occurred while loading the collection, aborting. Error: %s","An error occurred while loading the collection, aborting. Error: %s" "An error occurred while saving a record, aborting. Error: ","An error occurred while saving a record, aborting. Error: " -"Attempt to add an invalid object.","Attempt to add an invalid object." -"Attribute '%s' used in configurable products.","Attribute '%s' used in configurable products." +"Attempt to add an invalid object","Attempt to add an invalid object" +"Attribute '%s' used in configurable products","Attribute '%s' used in configurable products" "Attribute Code","Attribute Code" "Attribute Label","Attribute Label" "Attribute Properties","Attribute Properties" "Attribute set with the ""%s"" name already exists.","Attribute set with the ""%s"" name already exists." "Attribute with the same code","Attribute with the same code" +"Can\'t create table: %s","Can\'t create table: %s" "Catalog Input Type for Store Owner","Catalog Input Type for Store Owner" -"Data integrity: No header row found for attribute.","Data integrity: No header row found for attribute." +"Data integrity: No header row found for attribute","Data integrity: No header row found for attribute" "Date","Date" "Decimal Number","Decimal Number" "Default Product Listing Sort by not exists on Available Product Listing Sort By","Default Product Listing Sort by not exists on Available Product Listing Sort By" "Default Value","Default Value" -"Default option value is not defined.","Default option value is not defined." +"Default option value is not defined","Default option value is not defined" "Delete","Delete" "Dropdown","Dropdown" "Email","Email" "Entity collection expected.","Entity collection expected." "Entity collections expected.","Entity collections expected." -"Entity is not initialized.","Entity is not initialized." -"Failed to load node %s from config.","Failed to load node %s from config." -"For internal use. Must be unique with no spaces","For internal use. Must be unique with no spaces" +"Entity is not initialized","Entity is not initialized" +"Failed to load node %s from config","Failed to load node %s from config" "Form Element with the same attribute","Form Element with the same attribute" "Form Fieldset with the same code","Form Fieldset with the same code" "Form Type with the same code","Form Type with the same code" -"Frontend label is not defined.","Frontend label is not defined." +"Frontend label is not defined","Frontend label is not defined" "Input Validation for Store Owner","Input Validation for Store Owner" "Integer Number","Integer Number" "Invalid EAV attribute.","Invalid EAV attribute." -"Invalid alias, already exists in joint attributes.","Invalid alias, already exists in joint attributes." -"Invalid attribute name: %s.","Invalid attribute name: %s." +"Invalid alias, already exists in joint attributes","Invalid alias, already exists in joint attributes" +"Invalid attribute name: %s","Invalid attribute name: %s" "Invalid attribute requested: %s","Invalid attribute requested: %s" -"Invalid attribute type.","Invalid attribute type." +"Invalid attribute type","Invalid attribute type" "Invalid character encountered in increment ID: %s","Invalid character encountered in increment ID: %s" +"Invalid date","Invalid date" +"Invalid default date","Invalid default date" +"Invalid default decimal value","Invalid default decimal value" "Invalid entity specified","Invalid entity specified" "Invalid entity supplied.","Invalid entity supplied." -"Invalid entity supplied: %s.","Invalid entity supplied: %s." -"Invalid entity type.","Invalid entity type." +"Invalid entity supplied: %s","Invalid entity supplied: %s" +"Invalid entity type","Invalid entity type" "Invalid entity_id, skipping the record.","Invalid entity_id, skipping the record." "Invalid entity_type specified: %s","Invalid entity_type specified: %s" -"Invalid foreign key.","Invalid foreign key." +"Invalid foreign key","Invalid foreign key" "Invalid form type.","Invalid form type." -"Invalid joint fields.","Invalid joint fields." +"Invalid joint fields","Invalid joint fields" "Invalid store specified","Invalid store specified" -"Joined field with this alias is already declared.","Joined field with this alias is already declared." -"Joint field or attribute expression with this alias is already declared.","Joint field or attribute expression with this alias is already declared." +"Joined field with this alias is already declared","Joined field with this alias is already declared" +"Joint field or attribute expression with this alias is already declared","Joint field or attribute expression with this alias is already declared" "Letters","Letters" "Letters (a-z, A-Z) or Numbers (0-9)","Letters (a-z, A-Z) or Numbers (0-9)" "Loaded %d records","Loaded %d records" +"Maximum length of attribute code must be less then %s symbols","Maximum length of attribute code must be less then %s symbols" "Multiple Select","Multiple Select" "No","No" "No options found in config node %s","No options found in config node %s" @@ -61,22 +65,22 @@ "Problem saving the collection, aborting. Error: %s","Problem saving the collection, aborting. Error: %s" "Required","Required" "Saved %d record(s).","Saved %d record(s)." -"Scope must not be changed, because the attribute is used in configurable products.","Scope must not be changed, because the attribute is used in configurable products." +"Source model ""%s"" not found for attribute ""%s""","Source model ""%s"" not found for attribute ""%s""" "System","System" "Text Area","Text Area" "Text Field","Text Field" -"The attribute code \'%s\' is reserved by system. Please try another attribute code.","The attribute code \'%s\' is reserved by system. Please try another attribute code." +"The attribute code \'%s\' is reserved by system. Please try another attribute code","The attribute code \'%s\' is reserved by system. Please try another attribute code" +"The value of attribute ""%s"" must be unique","The value of attribute ""%s"" must be unique" "The value of attribute ""%s"" must be unique.","The value of attribute ""%s"" must be unique." -"This attribute is used in configurable products.","This attribute is used in configurable products." +"This attribute is used in configurable products","This attribute is used in configurable products" "URL","URL" "Unique Value","Unique Value" "Unique Value (not shared with other products)","Unique Value (not shared with other products)" -"Unknown parameter.","Unknown parameter." -"Valid store_id is expected.","Valid store_id is expected." +"Unknown parameter","Unknown parameter" "Values Required","Values Required" -"Wrong attribute ID.","Wrong attribute ID." -"Wrong attribute group ID.","Wrong attribute group ID." -"Wrong attribute set ID.","Wrong attribute set ID." -"Wrong entity ID.","Wrong entity ID." +"Wrong attribute group ID","Wrong attribute group ID" +"Wrong attribute set ID","Wrong attribute set ID" +"Wrong entity ID","Wrong entity ID" +"Wrong type definition for %s","Wrong type definition for %s" "Yes","Yes" "Yes/No","Yes/No" diff --git a/app/locale/en_US/Mage_GoogleBase.csv b/app/locale/en_US/Mage_GoogleBase.csv index c5138a2faf..daa8fcf337 100644 --- a/app/locale/en_US/Mage_GoogleBase.csv +++ b/app/locale/en_US/Mage_GoogleBase.csv @@ -1,6 +1,3 @@ -"Account Login","Account Login" -"Account Password","Account Password" -"Account Type","Account Type" "Active","Active" "Add Attribute Mapping","Add Attribute Mapping" "Add New Attribute","Add New Attribute" @@ -15,8 +12,6 @@ "AuthSub","AuthSub" "Available Products","Available Products" "Base Currency should be set to %s for %s in system configuration. Otherwise item prices won't be correct in Google Base.","Base Currency should be set to %s for %s in system configuration. Otherwise item prices won't be correct in Google Base." -"British Pound Sterling","British Pound Sterling" -"Cannot update Google Base Item for Store '%s'","Cannot update Google Base Item for Store '%s'" "Captcha confirmation error: %s","Captcha confirmation error: %s" "Captcha has been confirmed.","Captcha has been confirmed." "Catalog","Catalog" @@ -30,9 +25,7 @@ "Edit Item Type","Edit Item Type" "Edit Item Type ""%s""","Edit Item Type ""%s""" "Error: %s","Error: %s" -"Euro","Euro" "Expires","Expires" -"Germany","Germany" "Google","Google" "Google Base","Google Base" "Google Base Attribute","Google Base Attribute" @@ -77,12 +70,8 @@ "Total of %d items(s) have been removed from Google Base.","Total of %d items(s) have been removed from Google Base." "Total of %d items(s) have been saved as inactive items.","Total of %d items(s) have been saved as inactive items." "Total of %d product(s) have been added to Google Base.","Total of %d product(s) have been added to Google Base." -"US Dollar","US Dollar" "Unable to connect to Google Base. Please, check Account settings in configuration.","Unable to connect to Google Base. Please, check Account settings in configuration." "Unable to select a Store View.","Unable to select a Store View." -"United Kingdom","United Kingdom" -"United States","United States" -"Update Google Base Item when Product is Updated","Update Google Base Item when Product is Updated" "View Available Products","View Available Products" "View Item in Google Base","View Item in Google Base" "Yes","Yes" diff --git a/app/locale/en_US/Mage_ImportExport.csv b/app/locale/en_US/Mage_ImportExport.csv index 373859c0a1..029ea5d197 100644 --- a/app/locale/en_US/Mage_ImportExport.csv +++ b/app/locale/en_US/Mage_ImportExport.csv @@ -6,7 +6,7 @@ "Can not find required columns: ","Can not find required columns: " "Can not get autoincrement value","Can not get autoincrement value" "Check Data","Check Data" -"Column names has duplicates","Column names has duplicates" +"Column names have duplicates","Column names have duplicates" "Column names is empty or is not an array","Column names is empty or is not an array" "Column names: ""%s"" are invalid","Column names: ""%s"" are invalid" "Continue","Continue" diff --git a/app/locale/en_US/Mage_Install.csv b/app/locale/en_US/Mage_Install.csv index 4228ce9afa..e2abbd0d2a 100644 --- a/app/locale/en_US/Mage_Install.csv +++ b/app/locale/en_US/Mage_Install.csv @@ -24,9 +24,9 @@ "Database Connection","Database Connection" "Database Name","Database Name" "Database Name cannot be empty.","Database Name cannot be empty." +"Database Type","Database Type" "Database connection error.","Database connection error." "Database host","Database host" -"Database server does not support the InnoDB storage engine.","Database server does not support the InnoDB storage engine." "Database user name","Database user name" "Database user password","Database user password" "Default Currency","Default Currency" @@ -71,6 +71,7 @@ "Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.","Magento is a trademark of Magento Inc. Copyright © %s Magento Inc." "Magento uses this key to encrypt passwords, credit cards and more. If this field is left empty the system will create an encryption key for you and will display it on the next page.","Magento uses this key to encrypt passwords, credit cards and more. If this field is left empty the system will create an encryption key for you and will display it on the next page." "Manual Downloads and Upgrades","Manual Downloads and Upgrades" +"No resource for %s DB model.","No resource for %s DB model." "One of PHP Extensions ""%s"" must be loaded.","One of PHP Extensions ""%s"" must be loaded." "PHP Extension '%s' loaded","PHP Extension '%s' loaded" "PHP extension ""%s"" must be loaded.","PHP extension ""%s"" must be loaded." @@ -102,8 +103,6 @@ "Tables Prefix","Tables Prefix" "The URL ""%s"" is invalid.","The URL ""%s"" is invalid." "The URL ""%s"" is not accessible.","The URL ""%s"" is not accessible." -"The database server version does not match system requirements (required: %s, actual: %s).","The database server version does not match system requirements (required: %s, actual: %s)." -"The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter.","The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter." "There was a problem installing Magento packages. Please read the log, correct errors and try again.","There was a problem installing Magento packages. Please read the log, correct errors and try again." "Time Zone","Time Zone" "Use Secure URLs (SSL)","Use Secure URLs (SSL)" diff --git a/app/locale/en_US/Mage_Paypal.csv b/app/locale/en_US/Mage_Paypal.csv index 38d15c9386..69ba3fe09a 100644 --- a/app/locale/en_US/Mage_Paypal.csv +++ b/app/locale/en_US/Mage_Paypal.csv @@ -38,7 +38,10 @@ "Authenticated, Bad Result","Authenticated, Bad Result" "Authenticated, Good Result","Authenticated, Good Result" "Authorization","Authorization" +"Authorization Honor Period","Authorization Honor Period" "Authorization transaction is required to void.","Authorization transaction is required to void." +"Authorized amount of %s.","Authorized amount of %s." +"Authorizing amount of %s is pending approval on gateway.","Authorizing amount of %s is pending approval on gateway." "Auto","Auto" "AutoSweep","AutoSweep" "Available Balance","Available Balance" @@ -218,9 +221,13 @@ "Notified customer about invoice #%s.","Notified customer about invoice #%s." "Now accepting PayPal (150 X 40)","Now accepting PayPal (150 X 40)" "Now accepting PayPal (150 X 60)","Now accepting PayPal (150 X 60)" +"Number of Child Authorizations","Number of Child Authorizations" "Open Authorization","Open Authorization" "Order","Order" "Order ID","Order ID" +"Order Valid Period","Order Valid Period" +"Ordered amount of %s.","Ordered amount of %s." +"Ordering amount of %s is pending approval on gateway.","Ordering amount of %s is pending approval on gateway." "Page Background Color","Page Background Color" "Page Style","Page Style" "Part of the address information matched","Part of the address information matched" @@ -334,6 +341,8 @@ "Solo","Solo" "Sorry, no quotes are available for this order at this time.","Sorry, no quotes are available for this order at this time." "Sort Order","Sort Order" +"Specifies what the Authorization Honor Period is on the merchant’s PayPal account. It must mirror the setting in PayPal.","Specifies what the Authorization Honor Period is on the merchant’s PayPal account. It must mirror the setting in PayPal." +"Specifies what the Order Valid Period is on the merchant’s PayPal account. It must mirror the setting in PayPal.","Specifies what the Order Valid Period is on the merchant’s PayPal account. It must mirror the setting in PayPal." "Static","Static" "Submitting order information...","Submitting order information..." "Subscriber name is too long.","Subscriber name is too long." @@ -346,7 +355,9 @@ "Test Mode","Test Mode" "The background color for the checkout page around the header and payment form.","The background color for the checkout page around the header and payment form." "The background color for the header of the checkout page. Case-insensitive six-character HTML hexadecimal color code in ASCII.","The background color for the header of the checkout page. Case-insensitive six-character HTML hexadecimal color code in ASCII." +"The default number of child authorizations in your PayPal account is 1. To do multiple authorizations please contact PayPal to request an increase.","The default number of child authorizations in your PayPal account is 1. To do multiple authorizations please contact PayPal to request an increase." "The image at the top left of the checkout page. Max size is 750x90-pixel. https is highly encouraged.","The image at the top left of the checkout page. Max size is 750x90-pixel. https is highly encouraged." +"The maximum number of child authorizations is reached.","The maximum number of child authorizations is reached." "The merchant account is not yet verified.","The merchant account is not yet verified." "The payment curency does not match any of the merchant\'s balances currency.","The payment curency does not match any of the merchant\'s balances currency." "The payment eCheck is not yet cleared.","The payment eCheck is not yet cleared." diff --git a/app/locale/en_US/Mage_Reports.csv b/app/locale/en_US/Mage_Reports.csv index 27d9e2f705..0c055c4619 100644 --- a/app/locale/en_US/Mage_Reports.csv +++ b/app/locale/en_US/Mage_Reports.csv @@ -15,6 +15,7 @@ "Bought from wishlists","Bought from wishlists" "CSV","CSV" "Carts","Carts" +"Catalog Category (Without Subcategories)","Catalog Category (Without Subcategories)" "Compared Products Grid Template","Compared Products Grid Template" "Compared Products List Template","Compared Products List Template" "Coupons","Coupons" diff --git a/app/locale/en_US/Mage_Review.csv b/app/locale/en_US/Mage_Review.csv index 269db45382..9eef53f76e 100644 --- a/app/locale/en_US/Mage_Review.csv +++ b/app/locale/en_US/Mage_Review.csv @@ -28,6 +28,7 @@ "Customer My Account Product Reviews","Customer My Account Product Reviews" "Customer My Account Review Details","Customer My Account Review Details" "Customer Reviews","Customer Reviews" +"Customers Reviews","Customers Reviews" "Delete","Delete" "Delete Review","Delete Review" "Detailed Rating","Detailed Rating" @@ -56,6 +57,7 @@ "Product Review (submitted on %s):","Product Review (submitted on %s):" "Product Reviews","Product Reviews" "Product SKU","Product SKU" +"Products Reviews","Products Reviews" "Qty","Qty" "Rating:","Rating:" "Review","Review" diff --git a/app/locale/en_US/Mage_Sales.csv b/app/locale/en_US/Mage_Sales.csv index 11f39eebef..8918b949ac 100644 --- a/app/locale/en_US/Mage_Sales.csv +++ b/app/locale/en_US/Mage_Sales.csv @@ -577,16 +577,23 @@ "Select","Select" "Select from existing customer addresses:","Select from existing customer addresses:" "Send Credit Memo Comment Email Copy To","Send Credit Memo Comment Email Copy To" +"Send Credit Memo Comments Email Copy Method","Send Credit Memo Comments Email Copy Method" +"Send Credit Memo Email Copy Method","Send Credit Memo Email Copy Method" "Send Credit Memo Email Copy To","Send Credit Memo Email Copy To" "Send Email","Send Email" "Send Invoice Comment Email Copy To","Send Invoice Comment Email Copy To" +"Send Invoice Comments Email Copy Method","Send Invoice Comments Email Copy Method" +"Send Invoice Email Copy Method","Send Invoice Email Copy Method" "Send Invoice Email Copy To","Send Invoice Email Copy To" "Send Order Comment Email Copy To","Send Order Comment Email Copy To" +"Send Order Comments Email Copy Method","Send Order Comments Email Copy Method" "Send Order Email","Send Order Email" "Send Order Email Copy Method","Send Order Email Copy Method" "Send Order Email Copy To","Send Order Email Copy To" "Send Sales Emails","Send Sales Emails" "Send Shipment Comment Email Copy To","Send Shipment Comment Email Copy To" +"Send Shipment Comments Email Copy Method","Send Shipment Comments Email Copy Method" +"Send Shipment Email Copy Method","Send Shipment Email Copy Method" "Send Shipment Email Copy To","Send Shipment Email Copy To" "Send Tracking Information","Send Tracking Information" "Set order for existing transactions not allowed","Set order for existing transactions not allowed" @@ -694,7 +701,6 @@ "This order contains (%s) items and therefore cannot be edited through the admin interface at this time, if you wish to continue editing the (%s) items will be removed, the order will be canceled and a new order will be placed.","This order contains (%s) items and therefore cannot be edited through the admin interface at this time, if you wish to continue editing the (%s) items will be removed, the order will be canceled and a new order will be placed." "This order no longer exists.","This order no longer exists." "This product does not have any configurable options","This product does not have any configurable options" -"This product has not been configured.","This product has not been configured." "This profile state cannot be changed to ""%s"".","This profile state cannot be changed to ""%s""." "This will create an offline refund. To create an online refund, open an invoice and create credit memo for it. Do you wish to proceed?","This will create an offline refund. To create an online refund, open an invoice and create credit memo for it. Do you wish to proceed?" "Tier Pricing","Tier Pricing" diff --git a/app/locale/en_US/Mage_Usa.csv b/app/locale/en_US/Mage_Usa.csv index 3eed43143a..a9fb4a4f83 100644 --- a/app/locale/en_US/Mage_Usa.csv +++ b/app/locale/en_US/Mage_Usa.csv @@ -17,7 +17,6 @@ "Additional Protection Min Subtotal","Additional Protection Min Subtotal" "Additional Protection Value","Additional Protection Value" "Additional Protection Value Rounding Method","Additional Protection Value Rounding Method" -"All Services","All Services" "Allowed Methods","Allowed Methods" "Bound Printed Matter","Bound Printed Matter" "Business Service Center","Business Service Center" diff --git a/app/locale/en_US/Mage_XmlConnect.csv b/app/locale/en_US/Mage_XmlConnect.csv index 3aadafe700..d4cccdabc2 100644 --- a/app/locale/en_US/Mage_XmlConnect.csv +++ b/app/locale/en_US/Mage_XmlConnect.csv @@ -1,4 +1,3 @@ -" "," " " But cart has some errors."," But cart has some errors." """Description"" is more than %d characters long","""Description"" is more than %d characters long" """Title"" is more than %d characters long","""Title"" is more than %d characters long" @@ -27,7 +26,6 @@ "Add to Cart","Add to Cart" "Add to Wishlist","Add to Wishlist" "Additional Address","Additional Address" -"Additional Countries","Additional Countries" "Address","Address" "Address 2","Address 2" "Address data not specified.","Address data not specified." @@ -78,7 +76,6 @@ "Application Master Secret","Application Master Secret" "Application Name","Application Name" "Application Secret","Application Secret" -"Apply will automatically resize this image for display in the App Store and on users’ devices. A gloss (i.e. gradient) will also be applied, so you do not need to apply a gradient. Image must be at least 512x512","Apply will automatically resize this image for display in the App Store and on users’ devices. A gloss (i.e. gradient) will also be applied, so you do not need to apply a gradient. Image must be at least 512x512" "Are you sure you whant to cancel a message?","Are you sure you whant to cancel a message?" "Are you sure you whant to delete a message?","Are you sure you whant to delete a message?" "Are you sure you what to cancel selected records?","Are you sure you what to cancel selected records?" @@ -147,7 +144,6 @@ "Copyright","Copyright" "Copyright Page Logo","Copyright Page Logo" "Copyright Page Logo
      (iPhone 4 retina)","Copyright Page Logo
      (iPhone 4 retina)" -"Copyright page logo","Copyright page logo" "Country","Country" "Country options don\'t recognized for ""%s"".","Country options don\'t recognized for ""%s""." "Coupon code %s is not valid.","Coupon code %s is not valid." @@ -163,7 +159,6 @@ "Custom App Icon","Custom App Icon" "Custom App Icon
      (iPhone 4 retina)","Custom App Icon
      (iPhone 4 retina)" "Custom Colors","Custom Colors" -"Custom application icon","Custom application icon" "Customer authentication problem.","Customer authentication problem." "Customer email not specified.","Customer email not specified." "Customer logout problem.","Customer logout problem." @@ -224,7 +219,6 @@ "Free","Free" "Funk Leaf","Funk Leaf" "General","General" -"Get Activation Key","Get Activation Key" "Get Content from CMS Page","Get Content from CMS Page" "Grand Total (Excl. Tax)","Grand Total (Excl. Tax)" "Grand Total (Incl. Tax)","Grand Total (Incl. Tax)" @@ -338,8 +332,6 @@ "Payment Method has been set.","Payment Method has been set." "Payment Methods","Payment Methods" "Payment method was successfully set.","Payment method was successfully set." -"Paypal Merchant Account Email.","Paypal Merchant Account Email." -"Paypal Merchant Account Username.","Paypal Merchant Account Username." "Please Select Application","Please Select Application" "Please Select Device Type","Please Select Device Type" "Please agree to all the terms and conditions before placing the order.","Please agree to all the terms and conditions before placing the order." @@ -392,9 +384,7 @@ "Related Product Background Color","Related Product Background Color" "Reset theme to default","Reset theme to default" "Resubmission Key","Resubmission Key" -"Resubmit","Resubmit" "Resubmit App","Resubmit App" -"Resubmit Application","Resubmit Application" "Review","Review" "SORT BY:","SORT BY:" "Save","Save" @@ -434,18 +424,15 @@ "Store View","Store View" "Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px.","Store logo that is displayed on copyright page of app. Preferred size: 100px x 100px." "Store logo that is displayed on copyright page of app. Preferred size: 200px x 200px.","Store logo that is displayed on copyright page of app. Preferred size: 200px x 200px." -"Store logo that will be displayed on copyright page of application ","Store logo that will be displayed on copyright page of application " "Street Address","Street Address" "Street Address 2","Street Address 2" "Submission","Submission" "Submission Fields","Submission Fields" "Submission History","Submission History" -"Submit","Submit" "Submit App","Submit App" "Submit App ""%s""","Submit App ""%s""" "Submit App failure. %s","Submit App failure. %s" "Submit App failure. Invalid activation key provided","Submit App failure. Invalid activation key provided" -"Submit Application","Submit Application" "Submitted","Submitted" "Subtotal (Excl. Tax)","Subtotal (Excl. Tax)" "Subtotal (Incl. Tax)","Subtotal (Incl. Tax)" @@ -471,10 +458,6 @@ "Theme name is not set.","Theme name is not set." "There were some problems with the data.","There were some problems with the data." "This email address was not found in our records.","This email address was not found in our records." -"This icon will be used for users’ devices in case if different than AppSore icon needed. ","This icon will be used for users’ devices in case if different than AppSore icon needed. " -"This is the description that will appear in the iTunes marketplace. ","This is the description that will appear in the iTunes marketplace. " -"This is the name that will appear beneath your app when users install it to their device. . We recommend choosing a name that is 10-12 characters in length, and that your customers will recognize.","This is the name that will appear beneath your app when users install it to their device. . We recommend choosing a name that is 10-12 characters in length, and that your customers will recognize." -"This will appear in the info section of your App (example: Copyright 2010 – Your Company, Inc.)","This will appear in the info section of your App (example: Copyright 2010 – Your Company, Inc.)" "Title","Title" "Title bar","Title bar" "To activate PayPal MEP payment method activate Express checkout first. ","To activate PayPal MEP payment method activate Express checkout first. " @@ -507,8 +490,6 @@ "Urban Airship Push Notification","Urban Airship Push Notification" "Use as my default billing address","Use as my default billing address" "Use as my default shipping address","Use as my default shipping address" -"Username","Username" -"Users will see this image as the first screen while your application is loading. It is a 320x460 image.","Users will see this image as the first screen while your application is loading. It is a 320x460 image." "View Details","View Details" "View Gallery","View Gallery" "Website is offline.","Website is offline." @@ -520,8 +501,6 @@ "Wrong email format","Wrong email format" "Wrong theme format.","Wrong theme format." "You are already logged in.","You are already logged in." -"You can set any additional countries added by Apple Store.","You can set any additional countries added by Apple Store." -"You can set any price you want for your app, or you can give it away for free. Most apps range from $0.99 - $4.99","You can set any price you want for your app, or you can give it away for free. Most apps range from $0.99 - $4.99" "You can watch statistics here.","You can watch statistics here." "You will receive an order confirmation email with details of your order and a link to track its progress.","You will receive an order confirmation email with details of your order and a link to track its progress." "Your order # is: %s. ","Your order # is: %s. " diff --git a/app/locale/en_US/template/email/account_new_confirmation.html b/app/locale/en_US/template/email/account_new_confirmation.html index 836965b2c9..b0a8f0a959 100644 --- a/app/locale/en_US/template/email/account_new_confirmation.html +++ b/app/locale/en_US/template/email/account_new_confirmation.html @@ -28,7 +28,7 @@ -

      Dear {{htmlescape var=$customer.name}},

      +

      Dear {{htmlescape var=$customer.name}},

      Your e-mail {{var customer.email}} must be confirmed before using it to log in to our store.

      To confirm the e-mail and instantly log in, please, use this confirmation link. This link is valid only once.

      diff --git a/downloader/Maged/Connect.php b/downloader/Maged/Connect.php index f2de9f65a0..d7a0516131 100644 --- a/downloader/Maged/Connect.php +++ b/downloader/Maged/Connect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Connect/Frontend.php b/downloader/Maged/Connect/Frontend.php index 4e22d47ba9..0b608d884b 100644 --- a/downloader/Maged/Connect/Frontend.php +++ b/downloader/Maged/Connect/Frontend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Controller.php b/downloader/Maged/Controller.php index 54e7ed58fe..b514c4af70 100755 --- a/downloader/Maged/Controller.php +++ b/downloader/Maged/Controller.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -32,7 +32,6 @@ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - final class Maged_Controller { /** @@ -155,7 +154,7 @@ private function getFtpPost($post){ $ftp = 'ftp://'; $post['ftp_proto'] = 'ftp://'; - if (!empty($post['ftp_path']) && strlen(trim($post['ftp_path'], '\\/'))>0) { + if (!empty($post['ftp_path']) && strlen(trim($post['ftp_path'], '\\/')) > 0) { $post['ftp_path'] = '/' . trim($post['ftp_path'], '\\/') . '/'; } else { $post['ftp_path'] = '/'; @@ -164,30 +163,32 @@ private function getFtpPost($post){ $start = stripos($post['ftp_host'],'ftp://'); if ($start !== false){ $post['ftp_proto'] = 'ftp://'; - $post['ftp_host'] = substr($post['ftp_host'], $start+6-1); + $post['ftp_host'] = substr($post['ftp_host'], $start + 6 - 1); } $start = stripos($post['ftp_host'],'ftps://'); - if ($start !== false){ + if ($start !== false) { $post['ftp_proto'] = 'ftps://'; - $post['ftp_host'] = substr($post['ftp_host'], $start+7-1); + $post['ftp_host'] = substr($post['ftp_host'], $start + 7 - 1); } $post['ftp_host'] = trim($post['ftp_host'], '\\/'); - - if (!empty($post['ftp_login']) && !empty($post['ftp_password'])){ - $ftp = sprintf("%s%s:%s@%s%s", + if (!empty($post['ftp_login']) && !empty($post['ftp_password'])){ + $ftp = sprintf("%s%s:%s@%s%s", $post['ftp_proto'], $post['ftp_login'], $post['ftp_password'], $post['ftp_host'], $post['ftp_path'] ); - } elseif (!empty($post['ftp_login'])) { - - $ftp = sprintf("%s%s@%s%s", $post['ftp_proto'], $post['ftp_login'],$post['ftp_host'],$post['ftp_path']); - + $ftp = sprintf( + "%s%s@%s%s", + $post['ftp_proto'], + $post['ftp_login'], + $post['ftp_host'], + $post['ftp_path'] + ); } else { $ftp = $post['ftp_proto'] . $post['ftp_host'] . $post['ftp_path']; } @@ -198,7 +199,6 @@ private function getFtpPost($post){ /** * NoRoute - * */ public function norouteAction() { @@ -208,7 +208,6 @@ public function norouteAction() /** * Login - * */ public function loginAction() { @@ -218,7 +217,6 @@ public function loginAction() /** * Logout - * */ public function logoutAction() { @@ -228,14 +226,18 @@ public function logoutAction() /** * Index - * */ public function indexAction() { $config = $this->config(); if (!$this->isInstalled()) { $this->view()->set('mage_url', dirname(dirname($_SERVER['SCRIPT_NAME']))); - $this->view()->set('use_custom_permissions_mode', $config->__get('use_custom_permissions_mode')?$config->__get('use_custom_permissions_mode'):'0'); + $this->view()->set( + 'use_custom_permissions_mode', + $config->__get('use_custom_permissions_mode') + ? $config->__get('use_custom_permissions_mode') + : '0' + ); $this->view()->set('mkdir_mode', decoct($config->__get('global_dir_mode'))); $this->view()->set('chmod_file_mode', decoct($config->__get('global_file_mode'))); $this->view()->set('protocol', $config->__get('protocol')); @@ -252,21 +254,21 @@ public function indexAction() /** * Empty Action - * */ public function emptyAction() { - $this->model('connect', true)->connect()->runHtmlConsole('Please wait, preparing for updates...'); + $this->model('connect', true) + ->connect() + ->runHtmlConsole('Please wait, preparing for updates...'); } /** * Install all magento - * */ public function connectInstallAllAction() { $p = &$_POST; - $ftp = $this->getFtpPost($p); + $this->getFtpPost($p); $errors = $this->model('connect', true)->validateConfigPost($p); /* todo show errors */ if ($errors) { @@ -294,7 +296,6 @@ public function connectInstallAllAction() /** * Connect packages - * */ public function connectPackagesAction() { @@ -310,24 +311,26 @@ public function connectPackagesAction() if (!$this->isWritable() && empty($remoteConfig)) { $this->view()->set('writable_warning', true); } - + echo $this->view()->template('connect/packages.phtml'); } /** * Connect packages POST - * */ public function connectPackagesPostAction() { $actions = isset($_POST['actions']) ? $_POST['actions'] : array(); - $ignoreLocalModification = isset($_POST['ignore_local_modification'])?$_POST['ignore_local_modification']:''; + if (isset($_POST['ignore_local_modification'])) { + $ignoreLocalModification = $_POST['ignore_local_modification']; + } else { + $ignoreLocalModification = ''; + } $this->model('connect', true)->applyPackagesActions($actions, $ignoreLocalModification); } /** * Prepare package to install, get dependency info. - * */ public function connectPreparePackagePostAction() { @@ -337,8 +340,8 @@ public function connectPreparePackagePostAction() } $prepareResult = $this->model('connect', true)->prepareToInstall($_POST['install_package_id']); - $packages = isset($prepareResult['data'])? $prepareResult['data']:array(); - $errors = isset($prepareResult['errors'])? $prepareResult['errors']:array(); + $packages = isset($prepareResult['data']) ? $prepareResult['data'] : array(); + $errors = isset($prepareResult['errors']) ? $prepareResult['errors'] : array(); $this->view()->set('packages', $packages); $this->view()->set('errors', $errors); @@ -349,7 +352,6 @@ public function connectPreparePackagePostAction() /** * Install package - * */ public function connectInstallPackagePostAction() { @@ -362,7 +364,6 @@ public function connectInstallPackagePostAction() /** * Install uploaded package - * */ public function connectInstallPackageUploadAction() { @@ -383,7 +384,7 @@ public function connectInstallPackageUploadAction() return; } - $target = $this->_mageDir . DS . "var/".uniqid().$info['name']; + $target = $this->_mageDir . DS . "var/" . uniqid() . $info['name']; $res = move_uploaded_file($info['tmp_name'], $target); if(false === $res) { echo "Error moving uploaded file"; @@ -396,7 +397,6 @@ public function connectInstallPackageUploadAction() /** * Settings - * */ public function settingsAction() { @@ -410,14 +410,14 @@ public function settingsAction() $this->channelConfig()->setSettingsView($this->session(), $this->view()); - $fs_disabled=!$this->isWritable(); - $ftpParams=$config->__get('remote_config')?@parse_url($config->__get('remote_config')):''; + $fs_disabled =! $this->isWritable(); + $ftpParams = $config->__get('remote_config') ? @parse_url($config->__get('remote_config')) : ''; $this->view()->set('fs_disabled', $fs_disabled); - $this->view()->set('deployment_type', ($fs_disabled||!empty($ftpParams)?'ftp':'fs')); + $this->view()->set('deployment_type', ($fs_disabled || !empty($ftpParams) ? 'ftp' : 'fs')); - if(!empty($ftpParams)){ - $this->view()->set('ftp_host', sprintf("%s://%s",$ftpParams['scheme'],$ftpParams['host'])); + if (!empty($ftpParams)) { + $this->view()->set('ftp_host', sprintf("%s://%s", $ftpParams['scheme'], $ftpParams['host'])); $this->view()->set('ftp_login', $ftpParams['user']); $this->view()->set('ftp_password', $ftpParams['pass']); $this->view()->set('ftp_path', $ftpParams['path']); @@ -427,12 +427,11 @@ public function settingsAction() /** * Settings post - * */ public function settingsPostAction() { if ($_POST) { - $ftp=$this->getFtpPost($_POST); + $ftp = $this->getFtpPost($_POST); $errors = $this->model('connect', true)->validateConfigPost($_POST); if ($errors) { foreach ($errors as $err) { @@ -442,9 +441,9 @@ public function settingsPostAction() return; } try { - if( 'ftp' == $_POST['deployment_type']&&!empty($_POST['ftp_host'])){ + if('ftp' == $_POST['deployment_type'] && !empty($_POST['ftp_host'])) { $this->model('connect', true)->connect()->setRemoteConfig($ftp); - }else{ + } else { $this->model('connect', true)->connect()->setRemoteConfig(''); $_POST['ftp'] = ''; } @@ -452,9 +451,8 @@ public function settingsPostAction() $this->model('connect', true)->saveConfigPost($_POST); $this->channelConfig()->setSettingsSession($_POST, $this->session()); $this->model('connect', true)->connect()->run('sync'); - } catch (Exception $e) { - $this->session()->addMessage('error', "Unable to save settings: ".$e->getMessage()); + $this->session()->addMessage('error', "Unable to save settings: " . $e->getMessage()); } } $this->redirect($this->url('settings')); @@ -464,7 +462,6 @@ public function settingsPostAction() /** * Constructor - * */ public function __construct() { @@ -474,7 +471,6 @@ public function __construct() /** * Run - * */ public static function run() { @@ -699,10 +695,10 @@ public function processRedirect() { if ($this->_redirectUrl) { if (headers_sent()) { - echo ''; + echo ''; exit; } else { - header("Location: ".$this->_redirectUrl); + header("Location: " . $this->_redirectUrl); exit; } } @@ -730,7 +726,7 @@ public function forward($action) */ public function getActionMethod($action = null) { - $method = (!is_null($action) ? $action : $this->_action).'Action'; + $method = (!is_null($action) ? $action : $this->_action) . 'Action'; return $method; } @@ -753,7 +749,6 @@ public function url($action = '', $params = array()) /** * Dispatch process - * */ public function dispatch() { @@ -773,7 +768,6 @@ public function dispatch() $this->_isDispatched = true; $method = $this->getActionMethod(); - //echo($method);exit(); $this->$method(); } @@ -791,7 +785,6 @@ public function isWritable() $this->_writable = is_writable($this->getMageDir() . DIRECTORY_SEPARATOR) && is_writable($this->filepath()) && (!file_exists($this->filepath('config.ini') || is_writable($this->filepath('config.ini')))); - } return $this->_writable; } @@ -855,21 +848,20 @@ protected function _getMaintenanceFilePath() /** * Begin install package(s) - * */ public function startInstall() { if ($this->_getMaintenanceFlag()) { $maintenance_filename='maintenance.flag'; $config = $this->config(); - if(!$this->isWritable()||strlen($config->__get('remote_config'))>0){ + if (!$this->isWritable() || strlen($config->__get('remote_config')) > 0) { $ftpObj = new Mage_Connect_Ftp(); $ftpObj->connect($config->__get('remote_config')); $tempFile = tempnam(sys_get_temp_dir(),'maintenance'); @file_put_contents($tempFile, 'maintenance'); - $ret=$ftpObj->upload($maintenance_filename, $tempFile); + $ftpObj->upload($maintenance_filename, $tempFile); $ftpObj->close(); - }else{ + } else { @file_put_contents($this->_getMaintenanceFilePath(), 'maintenance'); } } @@ -877,7 +869,6 @@ public function startInstall() /** * End install package(s) - * */ public function endInstall() { @@ -888,9 +879,11 @@ public function endInstall() } Mage::app()->cleanCache(); } catch (Exception $e) { - $this->session()->addMessage('error', "Exception during cache and session cleaning: ".$e->getMessage()); + $this->session()->addMessage( + 'error', + "Exception during cache and session cleaning: ".$e->getMessage() + ); } - // reinit config and apply all updates Mage::app()->getConfig()->reinit(); Mage_Core_Model_Resource_Setup::applyAllUpdates(); @@ -900,12 +893,12 @@ public function endInstall() if ($this->_getMaintenanceFlag()) { $maintenance_filename='maintenance.flag'; $config = $this->config(); - if(!$this->isWritable()&&strlen($config->__get('remote_config'))>0){ + if (!$this->isWritable() && strlen($config->__get('remote_config')) > 0) { $ftpObj = new Mage_Connect_Ftp(); $ftpObj->connect($config->__get('remote_config')); $ftpObj->delete($maintenance_filename); $ftpObj->close(); - }else{ + } else { @unlink($this->_getMaintenanceFilePath()); } } @@ -920,7 +913,12 @@ public function endInstall() public static function getVersion() { $i = self::getVersionInfo(); - return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-'); + return trim( + "{$i['major']}.{$i['minor']}.{$i['revision']}" + . ($i['patch'] != '' ? ".{$i['patch']}" : "") + . "-{$i['stability']}{$i['number']}", + '.-' + ); } /** @@ -935,10 +933,9 @@ public static function getVersionInfo() 'major' => '1', 'minor' => '5', 'revision' => '0', - 'patch' => '1', + 'patch' => '0', 'stability' => '', 'number' => '', ); } - } diff --git a/downloader/Maged/Exception.php b/downloader/Maged/Exception.php index 93783c9a34..9bccdde77b 100755 --- a/downloader/Maged/Exception.php +++ b/downloader/Maged/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model.php b/downloader/Maged/Model.php index 03dec77d58..4dce6b8947 100755 --- a/downloader/Maged/Model.php +++ b/downloader/Maged/Model.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Config.php b/downloader/Maged/Model/Config.php index f03626777b..8d1a05292c 100644 --- a/downloader/Maged/Model/Config.php +++ b/downloader/Maged/Model/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Config/Abstract.php b/downloader/Maged/Model/Config/Abstract.php index 2fea12a5ab..cc0faae61e 100644 --- a/downloader/Maged/Model/Config/Abstract.php +++ b/downloader/Maged/Model/Config/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Config/Community.php b/downloader/Maged/Model/Config/Community.php index dde8c0ebcb..90eb69cd01 100644 --- a/downloader/Maged/Model/Config/Community.php +++ b/downloader/Maged/Model/Config/Community.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Config/Interface.php b/downloader/Maged/Model/Config/Interface.php index e2b2002f99..918f035f1e 100644 --- a/downloader/Maged/Model/Config/Interface.php +++ b/downloader/Maged/Model/Config/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Connect.php b/downloader/Maged/Model/Connect.php index fdb0fec884..b557e82b68 100644 --- a/downloader/Maged/Model/Connect.php +++ b/downloader/Maged/Model/Connect.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Connect/Request.php b/downloader/Maged/Model/Connect/Request.php index 5d3507987e..7f1609cf90 100644 --- a/downloader/Maged/Model/Connect/Request.php +++ b/downloader/Maged/Model/Connect/Request.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Dowloader.php b/downloader/Maged/Model/Dowloader.php index ce8fc441f4..06a34ce36e 100755 --- a/downloader/Maged/Model/Dowloader.php +++ b/downloader/Maged/Model/Dowloader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/Maged/Model/Session.php b/downloader/Maged/Model/Session.php index 46f6fb12b1..138f6a3330 100644 --- a/downloader/Maged/Model/Session.php +++ b/downloader/Maged/Model/Session.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -34,19 +34,18 @@ */ class Maged_Model_Session extends Maged_Model { - /** - * Session - * - * @var Mage_Admin_Model_Session - */ + * Session + * + * @var Mage_Admin_Model_Session + */ protected $_session; /** - * Init session - * - * @return Maged_Model_Session - */ + * Init session + * + * @return Maged_Model_Session + */ public function start() { if (class_exists('Mage') && Mage::isInstalled()) { @@ -60,22 +59,22 @@ public function start() } /** - * Get value by key - * - * @param string $key - * @return mixed - */ + * Get value by key + * + * @param string $key + * @return mixed + */ public function get($key) { return isset($_SESSION[$key]) ? $_SESSION[$key] : null; } /** - * Set value for key - * - * @param string $key - * @param mixed $value - */ + * Set value for key + * + * @param string $key + * @param mixed $value + */ public function set($key, $value) { $_SESSION[$key] = $value; @@ -83,8 +82,8 @@ public function set($key, $value) } /** - * Authentication to downloader - */ + * Authentication to downloader + */ public function authenticate() { if (!$this->_session) { @@ -95,7 +94,7 @@ public function authenticate() $this->set('return_url', $_GET['return']); } - if ($this->getUserId()) { + if ($this->_checkUserAccess()) { return $this; } @@ -104,40 +103,58 @@ public function authenticate() } try { - if ( (isset($_POST['username']) && empty($_POST['username'])) || - (isset($_POST['password']) && empty($_POST['password']))) - { + if ( (isset($_POST['username']) && empty($_POST['username'])) + || (isset($_POST['password']) && empty($_POST['password']))) { $this->addMessage('error', 'Invalid user name or password'); } if (empty($_POST['username']) || empty($_POST['password'])) { $this->controller()->setAction('login'); return $this; } - $user = $this->_session->login($_POST['username'], $_POST['password']); $this->_session->refreshAcl(); - - if (!$user->getId() || !$this->_session->isAllowed('all')) { - $this->addMessage('error', 'Invalid user name or password'); - $this->controller()->setAction('login'); + if ($this->_checkUserAccess($user)) { return $this; } - } catch (Exception $e) { - $this->addMessage('error', $e->getMessage()); - } $this->controller() - ->redirect($this->controller()->url($this->controller()->getAction()).'&loggedin', true); + ->redirect( + $this->controller()->url('loggedin'), + true + ); } /** - * Log Out - * - * @return Maged_Model_Session - */ + * Check is user logged in and permissions + * + * @param Mage_Admin_Model_User|null $user + * @return bool + */ + protected function _checkUserAccess($user = null) + { + if ($user && !$user->getId()) { + $this->addMessage('error', 'Invalid user name or password'); + $this->controller()->setAction('login'); + } elseif ($this->getUserId() || ($user && $user->getId())) { + if ($this->_session->isAllowed('all')) { + return true; + } else { + $this->logout(); + $this->addMessage('error', 'Access Denied', true); + $this->controller()->setAction('login'); + } + } + return false; + } + + /** + * Log Out + * + * @return Maged_Model_Session + */ public function logout() { if (!$this->_session) { @@ -148,36 +165,40 @@ public function logout() } /** - * Retrieve user - * - * @return mixed - */ + * Retrieve user + * + * @return mixed + */ public function getUserId() { - return ($session = $this->_session) && ($user = $session->getUser()) ? $user->getId() : false; + if (($session = $this->_session) && ($user = $session->getUser())) { + return $user->getId(); + } + return false; } /** - * Add Message - * - * @param string $type - * @param string $msg - * @return Maged_Model_Session - */ - public function addMessage($type, $msg) + * Add Message + * + * @param string $type + * @param string $msg + * @param string $clear + * @return Maged_Model_Session + */ + public function addMessage($type, $msg, $clear = false) { - $msgs = $this->getMessages(false); + $msgs = $this->getMessages($clear); $msgs[$type][] = $msg; $this->set('messages', $msgs); return $this; } /** - * Retrieve messages from cache - * - * @param boolean $clear - * @return mixed - */ + * Retrieve messages from cache + * + * @param boolean $clear + * @return mixed + */ public function getMessages($clear = true) { $msgs = $this->get('messages'); @@ -189,10 +210,10 @@ public function getMessages($clear = true) } /** - * Retrieve url to adminhtml - * - * @return string - */ + * Retrieve url to adminhtml + * + * @return string + */ public function getReturnUrl() { if (!$this->_session || !$this->_session->isLoggedIn()) { diff --git a/downloader/Maged/View.php b/downloader/Maged/View.php index 35ae46790c..a83f35c1e2 100755 --- a/downloader/Maged/View.php +++ b/downloader/Maged/View.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/config.ini b/downloader/config.ini index 9d0d96870a..b2c56fcdc7 100755 --- a/downloader/config.ini +++ b/downloader/config.ini @@ -1 +1 @@ -root_channel=community +root_channel=community \ No newline at end of file diff --git a/downloader/index.php b/downloader/index.php index f159d3abbe..4bc284e435 100755 --- a/downloader/index.php +++ b/downloader/index.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive.php b/downloader/lib/Mage/Archive.php index 9884e329fe..1d3cc3fe94 100644 --- a/downloader/lib/Mage/Archive.php +++ b/downloader/lib/Mage/Archive.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive/Abstract.php b/downloader/lib/Mage/Archive/Abstract.php index 67b412b6e7..4871259695 100644 --- a/downloader/lib/Mage/Archive/Abstract.php +++ b/downloader/lib/Mage/Archive/Abstract.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive/Bz.php b/downloader/lib/Mage/Archive/Bz.php index eff6fa7351..cf5c42cd87 100644 --- a/downloader/lib/Mage/Archive/Bz.php +++ b/downloader/lib/Mage/Archive/Bz.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive/Gz.php b/downloader/lib/Mage/Archive/Gz.php index a0cd5898e0..0e8dfd1d6b 100644 --- a/downloader/lib/Mage/Archive/Gz.php +++ b/downloader/lib/Mage/Archive/Gz.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive/Interface.php b/downloader/lib/Mage/Archive/Interface.php index f20977f407..8ef9af3c84 100644 --- a/downloader/lib/Mage/Archive/Interface.php +++ b/downloader/lib/Mage/Archive/Interface.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Archive/Tar.php b/downloader/lib/Mage/Archive/Tar.php index dc6cf1da78..dca45fcd3c 100644 --- a/downloader/lib/Mage/Archive/Tar.php +++ b/downloader/lib/Mage/Archive/Tar.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Archive - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Autoload/Simple.php b/downloader/lib/Mage/Autoload/Simple.php index e5b11e49a1..83e1a5a4f0 100644 --- a/downloader/lib/Mage/Autoload/Simple.php +++ b/downloader/lib/Mage/Autoload/Simple.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Autoload - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Channel/Generator.php b/downloader/lib/Mage/Connect/Channel/Generator.php index e71c87437a..73563fc62d 100644 --- a/downloader/lib/Mage/Connect/Channel/Generator.php +++ b/downloader/lib/Mage/Connect/Channel/Generator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Channel/Parser.php b/downloader/lib/Mage/Connect/Channel/Parser.php index cd0c3bfc44..f9e05c347e 100644 --- a/downloader/lib/Mage/Connect/Channel/Parser.php +++ b/downloader/lib/Mage/Connect/Channel/Parser.php @@ -20,6 +20,6 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Channel/VO.php b/downloader/lib/Mage/Connect/Channel/VO.php index 07b5f0d7c5..165ea6ee70 100644 --- a/downloader/lib/Mage/Connect/Channel/VO.php +++ b/downloader/lib/Mage/Connect/Channel/VO.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command.php b/downloader/lib/Mage/Connect/Command.php index 26a7d6760d..d679eae354 100644 --- a/downloader/lib/Mage/Connect/Command.php +++ b/downloader/lib/Mage/Connect/Command.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Channels.php b/downloader/lib/Mage/Connect/Command/Channels.php index c1c40ac210..483a855992 100644 --- a/downloader/lib/Mage/Connect/Command/Channels.php +++ b/downloader/lib/Mage/Connect/Command/Channels.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Channels_Header.php b/downloader/lib/Mage/Connect/Command/Channels_Header.php index 47bbf3bc77..dba6b6bec3 100644 --- a/downloader/lib/Mage/Connect/Command/Channels_Header.php +++ b/downloader/lib/Mage/Connect/Command/Channels_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Config.php b/downloader/lib/Mage/Connect/Command/Config.php index 364ddfb1d3..f7023e1323 100644 --- a/downloader/lib/Mage/Connect/Command/Config.php +++ b/downloader/lib/Mage/Connect/Command/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Config_Header.php b/downloader/lib/Mage/Connect/Command/Config_Header.php index 6220c1d9c8..c812b30079 100644 --- a/downloader/lib/Mage/Connect/Command/Config_Header.php +++ b/downloader/lib/Mage/Connect/Command/Config_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Install.php b/downloader/lib/Mage/Connect/Command/Install.php index f3b77fdcef..d3974bde0e 100644 --- a/downloader/lib/Mage/Connect/Command/Install.php +++ b/downloader/lib/Mage/Connect/Command/Install.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Install_Header.php b/downloader/lib/Mage/Connect/Command/Install_Header.php index 8db1b78428..75e07ffcd3 100644 --- a/downloader/lib/Mage/Connect/Command/Install_Header.php +++ b/downloader/lib/Mage/Connect/Command/Install_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Package.php b/downloader/lib/Mage/Connect/Command/Package.php index f4f58e30cd..3516bdc0ef 100644 --- a/downloader/lib/Mage/Connect/Command/Package.php +++ b/downloader/lib/Mage/Connect/Command/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Package_Header.php b/downloader/lib/Mage/Connect/Command/Package_Header.php index de6aa9284e..f738ba800d 100644 --- a/downloader/lib/Mage/Connect/Command/Package_Header.php +++ b/downloader/lib/Mage/Connect/Command/Package_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Registry.php b/downloader/lib/Mage/Connect/Command/Registry.php index 844df42358..f2fc850733 100644 --- a/downloader/lib/Mage/Connect/Command/Registry.php +++ b/downloader/lib/Mage/Connect/Command/Registry.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Registry_Header.php b/downloader/lib/Mage/Connect/Command/Registry_Header.php index 9fc6260672..410625e3c4 100644 --- a/downloader/lib/Mage/Connect/Command/Registry_Header.php +++ b/downloader/lib/Mage/Connect/Command/Registry_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Remote.php b/downloader/lib/Mage/Connect/Command/Remote.php index 2c71c9ddbb..d2a39a03f7 100644 --- a/downloader/lib/Mage/Connect/Command/Remote.php +++ b/downloader/lib/Mage/Connect/Command/Remote.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Command/Remote_Header.php b/downloader/lib/Mage/Connect/Command/Remote_Header.php index 6fe6b916aa..dcfd359eea 100644 --- a/downloader/lib/Mage/Connect/Command/Remote_Header.php +++ b/downloader/lib/Mage/Connect/Command/Remote_Header.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Config.php b/downloader/lib/Mage/Connect/Config.php index fa24c17fb1..2df0dbb299 100644 --- a/downloader/lib/Mage/Connect/Config.php +++ b/downloader/lib/Mage/Connect/Config.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Connect_Config diff --git a/downloader/lib/Mage/Connect/Converter.php b/downloader/lib/Mage/Connect/Converter.php index cf66b0ba9b..c228668690 100644 --- a/downloader/lib/Mage/Connect/Converter.php +++ b/downloader/lib/Mage/Connect/Converter.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Frontend.php b/downloader/lib/Mage/Connect/Frontend.php index efb61c5c1a..20f486e2d1 100644 --- a/downloader/lib/Mage/Connect/Frontend.php +++ b/downloader/lib/Mage/Connect/Frontend.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Frontend/CLI.php b/downloader/lib/Mage/Connect/Frontend/CLI.php index 4d822829b6..a0d0c4b88f 100644 --- a/downloader/lib/Mage/Connect/Frontend/CLI.php +++ b/downloader/lib/Mage/Connect/Frontend/CLI.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Ftp.php b/downloader/lib/Mage/Connect/Ftp.php index da4c55092c..f7b6b52b49 100644 --- a/downloader/lib/Mage/Connect/Ftp.php +++ b/downloader/lib/Mage/Connect/Ftp.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Loader.php b/downloader/lib/Mage/Connect/Loader.php index 7652bab979..f622fcc206 100644 --- a/downloader/lib/Mage/Connect/Loader.php +++ b/downloader/lib/Mage/Connect/Loader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Loader/Ftp.php b/downloader/lib/Mage/Connect/Loader/Ftp.php index 3efa8fa213..c410bde397 100644 --- a/downloader/lib/Mage/Connect/Loader/Ftp.php +++ b/downloader/lib/Mage/Connect/Loader/Ftp.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package.php b/downloader/lib/Mage/Connect/Package.php index 982f37ec85..d031edbac3 100644 --- a/downloader/lib/Mage/Connect/Package.php +++ b/downloader/lib/Mage/Connect/Package.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package/Hotfix.php b/downloader/lib/Mage/Connect/Package/Hotfix.php index cdef438a77..3c1ba94136 100644 --- a/downloader/lib/Mage/Connect/Package/Hotfix.php +++ b/downloader/lib/Mage/Connect/Package/Hotfix.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package/Reader.php b/downloader/lib/Mage/Connect/Package/Reader.php index 6e1a07378b..3776698d1d 100644 --- a/downloader/lib/Mage/Connect/Package/Reader.php +++ b/downloader/lib/Mage/Connect/Package/Reader.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package/Target.php b/downloader/lib/Mage/Connect/Package/Target.php index ccd456d898..435d7c7907 100644 --- a/downloader/lib/Mage/Connect/Package/Target.php +++ b/downloader/lib/Mage/Connect/Package/Target.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package/VO.php b/downloader/lib/Mage/Connect/Package/VO.php index 26ff22f221..0a31198dd8 100644 --- a/downloader/lib/Mage/Connect/Package/VO.php +++ b/downloader/lib/Mage/Connect/Package/VO.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Package/Writer.php b/downloader/lib/Mage/Connect/Package/Writer.php index a14d53a864..2018e3c9ae 100644 --- a/downloader/lib/Mage/Connect/Package/Writer.php +++ b/downloader/lib/Mage/Connect/Package/Writer.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Packager.php b/downloader/lib/Mage/Connect/Packager.php index e7fcca12fa..c594fea728 100644 --- a/downloader/lib/Mage/Connect/Packager.php +++ b/downloader/lib/Mage/Connect/Packager.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Rest.php b/downloader/lib/Mage/Connect/Rest.php index 3ca7e6e4e3..4ec1ad8894 100644 --- a/downloader/lib/Mage/Connect/Rest.php +++ b/downloader/lib/Mage/Connect/Rest.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Singleconfig.php b/downloader/lib/Mage/Connect/Singleconfig.php index 46f219314d..ab5d330db5 100644 --- a/downloader/lib/Mage/Connect/Singleconfig.php +++ b/downloader/lib/Mage/Connect/Singleconfig.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Structures/Graph.php b/downloader/lib/Mage/Connect/Structures/Graph.php index aa29d68831..8bcb9d73e8 100644 --- a/downloader/lib/Mage/Connect/Structures/Graph.php +++ b/downloader/lib/Mage/Connect/Structures/Graph.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Structures/Node.php b/downloader/lib/Mage/Connect/Structures/Node.php index e887b5e18d..4abae47902 100644 --- a/downloader/lib/Mage/Connect/Structures/Node.php +++ b/downloader/lib/Mage/Connect/Structures/Node.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Connect/Validator.php b/downloader/lib/Mage/Connect/Validator.php index 3341215912..10636040e9 100644 --- a/downloader/lib/Mage/Connect/Validator.php +++ b/downloader/lib/Mage/Connect/Validator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/DB/Exception.php b/downloader/lib/Mage/DB/Exception.php index 7824ceffc3..14038cfcdf 100644 --- a/downloader/lib/Mage/DB/Exception.php +++ b/downloader/lib/Mage/DB/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_DB - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/DB/Mysqli.php b/downloader/lib/Mage/DB/Mysqli.php index 2b8debf024..7871e92f64 100644 --- a/downloader/lib/Mage/DB/Mysqli.php +++ b/downloader/lib/Mage/DB/Mysqli.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_DB - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/Exception.php b/downloader/lib/Mage/Exception.php index 09adbfdf80..0f91be1c6d 100644 --- a/downloader/lib/Mage/Exception.php +++ b/downloader/lib/Mage/Exception.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Exception - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/HTTP/Client.php b/downloader/lib/Mage/HTTP/Client.php index 4189bb635b..797b9f627a 100644 --- a/downloader/lib/Mage/HTTP/Client.php +++ b/downloader/lib/Mage/HTTP/Client.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_HTTP - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/HTTP/Client/Curl.php b/downloader/lib/Mage/HTTP/Client/Curl.php index 261d89f433..0840f18500 100644 --- a/downloader/lib/Mage/HTTP/Client/Curl.php +++ b/downloader/lib/Mage/HTTP/Client/Curl.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_HTTP - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/HTTP/Client/Socket.php b/downloader/lib/Mage/HTTP/Client/Socket.php index 9ec091a3d6..6a428f5f71 100644 --- a/downloader/lib/Mage/HTTP/Client/Socket.php +++ b/downloader/lib/Mage/HTTP/Client/Socket.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_HTTP - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/HTTP/IClient.php b/downloader/lib/Mage/HTTP/IClient.php index 3d19a0aad3..1d351b88e5 100644 --- a/downloader/lib/Mage/HTTP/IClient.php +++ b/downloader/lib/Mage/HTTP/IClient.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_HTTP - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/System/Args.php b/downloader/lib/Mage/System/Args.php index cca88518a4..3dd4442a4b 100644 --- a/downloader/lib/Mage/System/Args.php +++ b/downloader/lib/Mage/System/Args.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_System - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/lib/Mage/System/Dirs.php b/downloader/lib/Mage/System/Dirs.php index ab276a0cd8..866cf4c793 100644 --- a/downloader/lib/Mage/System/Dirs.php +++ b/downloader/lib/Mage/System/Dirs.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_System - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_System_Dirs diff --git a/downloader/lib/Mage/Xml/Generator.php b/downloader/lib/Mage/Xml/Generator.php index bfafa48d0f..79eb709eba 100644 --- a/downloader/lib/Mage/Xml/Generator.php +++ b/downloader/lib/Mage/Xml/Generator.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Xml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Xml_Generator diff --git a/downloader/lib/Mage/Xml/Parser.php b/downloader/lib/Mage/Xml/Parser.php index da4fc1d0f2..5411c2d7ab 100644 --- a/downloader/lib/Mage/Xml/Parser.php +++ b/downloader/lib/Mage/Xml/Parser.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Xml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_Xml_Parser diff --git a/downloader/mage.php b/downloader/mage.php index 9c2ca2458b..eaf65a78e0 100644 --- a/downloader/mage.php +++ b/downloader/mage.php @@ -20,7 +20,7 @@ * * @category Mage * @package Mage_Connect - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/downloader/skin/boxes.css b/downloader/skin/boxes.css index 87b385868b..f35d236647 100644 --- a/downloader/skin/boxes.css +++ b/downloader/skin/boxes.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /* diff --git a/downloader/skin/ie7boxes.css b/downloader/skin/ie7boxes.css index d381e9b23b..01b21b645b 100644 --- a/downloader/skin/ie7boxes.css +++ b/downloader/skin/ie7boxes.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ .main { height:auto !important; } diff --git a/downloader/skin/ieboxes.css b/downloader/skin/ieboxes.css index 7d2d44d7d3..13c0deef26 100644 --- a/downloader/skin/ieboxes.css +++ b/downloader/skin/ieboxes.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ button, .form-button { filter:chroma(color=#000000); overflow:visible; width:auto; } diff --git a/downloader/skin/install/boxes.css b/downloader/skin/install/boxes.css index 8847a89b69..eef0413bcd 100644 --- a/downloader/skin/install/boxes.css +++ b/downloader/skin/install/boxes.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/downloader/skin/install/clears.css b/downloader/skin/install/clears.css index 2182b64a6d..4edc49323a 100644 --- a/downloader/skin/install/clears.css +++ b/downloader/skin/install/clears.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/downloader/skin/install/ie7minus.css b/downloader/skin/install/ie7minus.css index 3db5bb64e3..fbe2dc3afb 100644 --- a/downloader/skin/install/ie7minus.css +++ b/downloader/skin/install/ie7minus.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/downloader/skin/install/iestyles.css b/downloader/skin/install/iestyles.css index a387c78a96..7154566a32 100644 --- a/downloader/skin/install/iestyles.css +++ b/downloader/skin/install/iestyles.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ .col2-set, diff --git a/downloader/skin/install/reset.css b/downloader/skin/install/reset.css index fcc26b2f6b..177f95b698 100644 --- a/downloader/skin/install/reset.css +++ b/downloader/skin/install/reset.css @@ -19,7 +19,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /******************************************/ diff --git a/downloader/template/connect/iframe.phtml b/downloader/template/connect/iframe.phtml index 4832e4d483..a20161c48c 100644 --- a/downloader/template/connect/iframe.phtml +++ b/downloader/template/connect/iframe.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/connect/packages.phtml b/downloader/template/connect/packages.phtml index 770e78c825..0f0ce2bc24 100644 --- a/downloader/template/connect/packages.phtml +++ b/downloader/template/connect/packages.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/connect/packages_prepare.phtml b/downloader/template/connect/packages_prepare.phtml index 405ac9d96c..36d2198d9c 100644 --- a/downloader/template/connect/packages_prepare.phtml +++ b/downloader/template/connect/packages_prepare.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/exception.phtml b/downloader/template/exception.phtml index cd99d94781..c961fa45be 100644 --- a/downloader/template/exception.phtml +++ b/downloader/template/exception.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/footer.phtml b/downloader/template/footer.phtml index 495b399b46..0733e19cf5 100755 --- a/downloader/template/footer.phtml +++ b/downloader/template/footer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/header.phtml b/downloader/template/header.phtml index dd3afdaf34..0f4fc494df 100644 --- a/downloader/template/header.phtml +++ b/downloader/template/header.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/index.phtml b/downloader/template/index.phtml index d4d7ea13a1..5a6c59b911 100755 --- a/downloader/template/index.phtml +++ b/downloader/template/index.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/install/download.phtml b/downloader/template/install/download.phtml index 6726abf73f..488e7147f5 100644 --- a/downloader/template/install/download.phtml +++ b/downloader/template/install/download.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/install/footer.phtml b/downloader/template/install/footer.phtml index a04646162b..9c7e422c9c 100644 --- a/downloader/template/install/footer.phtml +++ b/downloader/template/install/footer.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/install/header.phtml b/downloader/template/install/header.phtml index f52ee3367c..07c92673c4 100644 --- a/downloader/template/install/header.phtml +++ b/downloader/template/install/header.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/install/writable.phtml b/downloader/template/install/writable.phtml index fb783e3d4c..30c0bd88e0 100644 --- a/downloader/template/install/writable.phtml +++ b/downloader/template/install/writable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/login.phtml b/downloader/template/login.phtml index dcf62b1695..5221b24524 100755 --- a/downloader/template/login.phtml +++ b/downloader/template/login.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/messages.phtml b/downloader/template/messages.phtml index a68bf70d46..4a0cf4dcb3 100755 --- a/downloader/template/messages.phtml +++ b/downloader/template/messages.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/noroute.phtml b/downloader/template/noroute.phtml index 6de0281372..3c88a57716 100755 --- a/downloader/template/noroute.phtml +++ b/downloader/template/noroute.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/downloader/template/settings.phtml b/downloader/template/settings.phtml index 5484e962ba..61ea08db4f 100755 --- a/downloader/template/settings.phtml +++ b/downloader/template/settings.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> @@ -46,6 +46,7 @@ function changeDeploymentType (element) document.getElementById('deployment_type_panel').style.display = disabledMode; } +

      Settings

      diff --git a/downloader/template/writable.phtml b/downloader/template/writable.phtml index f1368e3fd5..9572eb5389 100755 --- a/downloader/template/writable.phtml +++ b/downloader/template/writable.phtml @@ -20,7 +20,7 @@ * * @category design * @package default - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/errors/404.php b/errors/404.php index 3d6de1911e..31b9da1e80 100644 --- a/errors/404.php +++ b/errors/404.php @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/errors/503.php b/errors/503.php index 5d9fa20ec6..bd85f185df 100644 --- a/errors/503.php +++ b/errors/503.php @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/errors/default/404.phtml b/errors/default/404.phtml index 5394f61a61..2181856522 100644 --- a/errors/default/404.phtml +++ b/errors/default/404.phtml @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/errors/default/503.phtml b/errors/default/503.phtml index 4e9fb2fbda..379a7ea813 100644 --- a/errors/default/503.phtml +++ b/errors/default/503.phtml @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/errors/default/css/styles.css b/errors/default/css/styles.css index 8b7747fe8a..01641c3c0f 100644 --- a/errors/default/css/styles.css +++ b/errors/default/css/styles.css @@ -19,7 +19,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /* Reset ================================================================================= */ diff --git a/errors/default/page.phtml b/errors/default/page.phtml index e95fb309bb..40f41fd800 100644 --- a/errors/default/page.phtml +++ b/errors/default/page.phtml @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/errors/default/report.phtml b/errors/default/report.phtml index 9e0a754c2f..841ec3333f 100644 --- a/errors/default/report.phtml +++ b/errors/default/report.phtml @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> diff --git a/app/code/core/Mage/Shipping/Model/Rule/Abstract.php b/errors/design.xml similarity index 84% rename from app/code/core/Mage/Shipping/Model/Rule/Abstract.php rename to errors/design.xml index 3d65473853..92181678e6 100644 --- a/app/code/core/Mage/Shipping/Model/Rule/Abstract.php +++ b/errors/design.xml @@ -1,4 +1,5 @@ - + + + default + diff --git a/errors/local.xml.sample b/errors/local.xml.sample index 6862ab4a42..232cfc93d6 100644 --- a/errors/local.xml.sample +++ b/errors/local.xml.sample @@ -21,7 +21,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> diff --git a/errors/processor.php b/errors/processor.php index de281c5cbf..e7ad0db025 100644 --- a/errors/processor.php +++ b/errors/processor.php @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/errors/report.php b/errors/report.php index 8f23bc24e4..eaff181a90 100644 --- a/errors/report.php +++ b/errors/report.php @@ -20,7 +20,7 @@ * * @category Mage * @package Errors - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/install.php b/install.php index 8b3d3caf52..a96fa2c023 100644 --- a/install.php +++ b/install.php @@ -83,6 +83,7 @@ * --db_host // required, You can specify server port, ex.: localhost:3307 * // If you are not using default UNIX socket, you can specify it * // here instead of host, ex.: /var/run/mysqld/mysqld.sock + * --db_model // Database type (mysql4 by default) * --db_name // required, Database Name * --db_user // required, Database User Name * --db_pass // required, Database User Password diff --git a/js/jscolor/jscolor/arrow.gif b/js/jscolor/arrow.gif similarity index 100% rename from js/jscolor/jscolor/arrow.gif rename to js/jscolor/arrow.gif diff --git a/js/jscolor/jscolor/cross.gif b/js/jscolor/cross.gif similarity index 100% rename from js/jscolor/jscolor/cross.gif rename to js/jscolor/cross.gif diff --git a/js/jscolor/jscolor/demo.html b/js/jscolor/demo.html similarity index 100% rename from js/jscolor/jscolor/demo.html rename to js/jscolor/demo.html diff --git a/js/jscolor/jscolor/hs.png b/js/jscolor/hs.png similarity index 100% rename from js/jscolor/jscolor/hs.png rename to js/jscolor/hs.png diff --git a/js/jscolor/jscolor/hv.png b/js/jscolor/hv.png similarity index 100% rename from js/jscolor/jscolor/hv.png rename to js/jscolor/hv.png diff --git a/js/jscolor/jscolor/jscolor.js b/js/jscolor/jscolor.js similarity index 100% rename from js/jscolor/jscolor/jscolor.js rename to js/jscolor/jscolor.js diff --git a/js/lib/dropdown.js b/js/lib/dropdown.js index ba15d2d85e..a7d79cceda 100644 --- a/js/lib/dropdown.js +++ b/js/lib/dropdown.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ dropdown = function() { diff --git a/js/lib/flex.js b/js/lib/flex.js index 596469d7e0..4ba34b6f91 100644 --- a/js/lib/flex.js +++ b/js/lib/flex.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/accordion.js b/js/mage/adminhtml/accordion.js index 61c8a26671..578fa64e3a 100644 --- a/js/mage/adminhtml/accordion.js +++ b/js/mage/adminhtml/accordion.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var varienAccordion = new Class.create(); diff --git a/js/mage/adminhtml/browser.js b/js/mage/adminhtml/browser.js index 9ef7fdca53..12eceb82b9 100644 --- a/js/mage/adminhtml/browser.js +++ b/js/mage/adminhtml/browser.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ MediabrowserUtility = { @@ -314,7 +314,7 @@ Mediabrowser.prototype = { i++; }); new Ajax.Request(this.deleteFilesUrl, { - parameters: {files: ids.toJSON()}, + parameters: {files: Object.toJSON(ids)}, onSuccess: function(transport) { try { this.onAjaxSuccess(transport); diff --git a/js/mage/adminhtml/events.js b/js/mage/adminhtml/events.js index 5eb028abb6..3c60a7083a 100644 --- a/js/mage/adminhtml/events.js +++ b/js/mage/adminhtml/events.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ // from http://www.someelement.com/2007/03/eventpublisher-custom-events-la-pubsub.html diff --git a/js/mage/adminhtml/flexuploader.js b/js/mage/adminhtml/flexuploader.js index 01f0b77603..f2737c3be3 100644 --- a/js/mage/adminhtml/flexuploader.js +++ b/js/mage/adminhtml/flexuploader.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index d8815979fb..6f0a32d651 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var varienForm = new Class.create(); diff --git a/js/mage/adminhtml/giftmessage.js b/js/mage/adminhtml/giftmessage.js index fb852d135a..798b4a9452 100644 --- a/js/mage/adminhtml/giftmessage.js +++ b/js/mage/adminhtml/giftmessage.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/giftoptions/tooltip.js b/js/mage/adminhtml/giftoptions/tooltip.js index a8c5f5620c..8c2a517e41 100644 --- a/js/mage/adminhtml/giftoptions/tooltip.js +++ b/js/mage/adminhtml/giftoptions/tooltip.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/grid.js b/js/mage/adminhtml/grid.js index f80e74955e..9127d1530d 100644 --- a/js/mage/adminhtml/grid.js +++ b/js/mage/adminhtml/grid.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var varienGrid = new Class.create(); diff --git a/js/mage/adminhtml/hash.js b/js/mage/adminhtml/hash.js index 55f42eda49..53f0295c83 100644 --- a/js/mage/adminhtml/hash.js +++ b/js/mage/adminhtml/hash.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /* diff --git a/js/mage/adminhtml/image.js b/js/mage/adminhtml/image.js index 99b0b351e3..c3ac501691 100644 --- a/js/mage/adminhtml/image.js +++ b/js/mage/adminhtml/image.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/loader.js b/js/mage/adminhtml/loader.js index 08bd31170a..128c177d2f 100644 --- a/js/mage/adminhtml/loader.js +++ b/js/mage/adminhtml/loader.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -41,15 +41,23 @@ Ajax.Request.addMethods({ if (!url.match(new RegExp('[?&]isAjax=true',''))) { url = url.match(new RegExp('\\?',"g")) ? url + '&isAjax=true' : url + '?isAjax=true'; } - if (!this.options.parameters) { - this.options.parameters = { + if (Object.isString(this.options.parameters) + && this.options.parameters.indexOf('form_key=') == -1 + ) { + this.options.parameters += '&' + Object.toQueryString({ form_key: FORM_KEY - }; - } - if (!this.options.parameters.form_key) { - this.options.parameters.form_key = FORM_KEY; + }); + } else { + if (!this.options.parameters) { + this.options.parameters = { + form_key: FORM_KEY + }; + } + if (!this.options.parameters.form_key) { + this.options.parameters.form_key = FORM_KEY; + } } - + this.request(url); }, respondToReadyState: function(readyState) { diff --git a/js/mage/adminhtml/magento-all.js b/js/mage/adminhtml/magento-all.js index 35ee9d2397..a88299ab54 100644 --- a/js/mage/adminhtml/magento-all.js +++ b/js/mage/adminhtml/magento-all.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/moneybookers.js b/js/mage/adminhtml/moneybookers.js index 078b72f32e..bc86f4b23f 100644 --- a/js/mage/adminhtml/moneybookers.js +++ b/js/mage/adminhtml/moneybookers.js @@ -13,7 +13,7 @@ * * @category Phoenix * @package Phoenix_Moneybookers - * @copyright Copyright (c) 2009 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) + * @copyright Copyright (c) 2011 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/js/mage/adminhtml/product.js b/js/mage/adminhtml/product.js index dbb00b9e87..5787b785a4 100644 --- a/js/mage/adminhtml/product.js +++ b/js/mage/adminhtml/product.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -119,7 +119,7 @@ Product.Gallery.prototype = { this.updateImages(); }, updateImages : function() { - this.getElement('save').value = this.images.toJSON(); + this.getElement('save').value = Object.toJSON(this.images); $H(this.imageTypes).each( function(pair) { this.getFileElement('no_selection', @@ -174,7 +174,7 @@ Product.Gallery.prototype = { 'cell-remove input').checked ? 1 : 0); this.images[index].disabled = (this.getFileElement(file, 'cell-disable input').checked ? 1 : 0); - this.getElement('save').value = this.images.toJSON(); + this.getElement('save').value = Object.toJSON(this.images); this.updateState(file); this.container.setHasChanges(); }, @@ -195,7 +195,7 @@ Product.Gallery.prototype = { } }.bind(this)); - this.getElement('save_image').value = $H(this.imagesValues).toJSON(); + this.getElement('save_image').value = Object.toJSON($H(this.imagesValues)); }, updateVisualisation : function(file) { var image = this.getImageByFile(file); @@ -744,8 +744,8 @@ Product.Configurable.prototype = { this.updateSaveInput(); }, updateSaveInput : function() { - $(this.idPrefix + 'save_attributes').value = this.attributes.toJSON(); - $(this.idPrefix + 'save_links').value = this.links.toJSON(); + $(this.idPrefix + 'save_attributes').value = Object.toJSON(this.attributes); + $(this.idPrefix + 'save_links').value = Object.toJSON(this.links); }, initializeAdvicesForSimpleForm : function() { if ($(this.idPrefix + 'simple_form').advicesInited) { diff --git a/js/mage/adminhtml/product/composite/configure.js b/js/mage/adminhtml/product/composite/configure.js index 80a4015cd1..4d2c123796 100644 --- a/js/mage/adminhtml/product/composite/configure.js +++ b/js/mage/adminhtml/product/composite/configure.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -368,6 +368,8 @@ ProductConfigure.prototype = { if (Object.isFunction(this.onLoadIFrameCallback[this.current.listType])) { this.onLoadIFrameCallback[this.current.listType](response); } + + document.fire(this.current.listType + ':afterIFrameLoaded'); } this.clean('current'); }, diff --git a/js/mage/adminhtml/rules.js b/js/mage/adminhtml/rules.js index 9dd8803e2c..7b80af9d44 100644 --- a/js/mage/adminhtml/rules.js +++ b/js/mage/adminhtml/rules.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/sales.js b/js/mage/adminhtml/sales.js index d9c4936463..cd6d8154f6 100644 --- a/js/mage/adminhtml/sales.js +++ b/js/mage/adminhtml/sales.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var AdminOrder = new Class.create(); diff --git a/js/mage/adminhtml/sales/centinel.js b/js/mage/adminhtml/sales/centinel.js index 606e4896a3..961bee937e 100644 --- a/js/mage/adminhtml/sales/centinel.js +++ b/js/mage/adminhtml/sales/centinel.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var centinelValidator = new Class.create(); diff --git a/js/mage/adminhtml/scrollbar.js b/js/mage/adminhtml/scrollbar.js index b7e06d505c..7e5204c391 100644 --- a/js/mage/adminhtml/scrollbar.js +++ b/js/mage/adminhtml/scrollbar.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /************************************************** diff --git a/js/mage/adminhtml/tabs.js b/js/mage/adminhtml/tabs.js index a40305c48a..c5be1fc84d 100644 --- a/js/mage/adminhtml/tabs.js +++ b/js/mage/adminhtml/tabs.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var varienTabs = new Class.create(); diff --git a/js/mage/adminhtml/tools.js b/js/mage/adminhtml/tools.js index 0470cd655e..682239e7b4 100644 --- a/js/mage/adminhtml/tools.js +++ b/js/mage/adminhtml/tools.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ function setLocation(url){ diff --git a/js/mage/adminhtml/uploader.js b/js/mage/adminhtml/uploader.js index 437ad20f1a..913d3ab1d7 100644 --- a/js/mage/adminhtml/uploader.js +++ b/js/mage/adminhtml/uploader.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ /** diff --git a/js/mage/adminhtml/variables.js b/js/mage/adminhtml/variables.js index cec1f9e43d..8b54d92d5e 100644 --- a/js/mage/adminhtml/variables.js +++ b/js/mage/adminhtml/variables.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentovariable/editor_plugin.js b/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentovariable/editor_plugin.js index f49d135e33..60f8971a23 100644 --- a/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentovariable/editor_plugin.js +++ b/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentovariable/editor_plugin.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentowidget/editor_plugin.js b/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentowidget/editor_plugin.js index cddbe8de44..7519bd879c 100644 --- a/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentowidget/editor_plugin.js +++ b/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentowidget/editor_plugin.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ tinyMCE.addI18n({en:{ diff --git a/js/mage/adminhtml/wysiwyg/tiny_mce/setup.js b/js/mage/adminhtml/wysiwyg/tiny_mce/setup.js index d50b2e324f..d4e22d6b39 100644 --- a/js/mage/adminhtml/wysiwyg/tiny_mce/setup.js +++ b/js/mage/adminhtml/wysiwyg/tiny_mce/setup.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ @@ -172,7 +172,7 @@ tinyMceWysiwygSetup.prototype = var storeId = this.config.store_id !== null ? this.config.store_id : 0; var wUrl = this.config.files_browser_window_url + 'target_element_id/' + this.id + '/' + - 'store/' + storeId + '/'; + 'store/' + storeId + '/'; this.mediaBrowserOpener = o.win; this.mediaBrowserOpener.blur(); @@ -349,4 +349,3 @@ tinyMceWysiwygSetup.prototype = return this.config.widget_placeholders.indexOf(filename) != -1; } } - diff --git a/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css b/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css index e40f9ad835..08b0098a15 100644 --- a/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css +++ b/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css b/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css index 9bc1977e94..cf23ae0398 100644 --- a/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css +++ b/js/mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/adminhtml/wysiwyg/widget.js b/js/mage/adminhtml/wysiwyg/widget.js index 5e7f2778dd..a05a1e6d23 100644 --- a/js/mage/adminhtml/wysiwyg/widget.js +++ b/js/mage/adminhtml/wysiwyg/widget.js @@ -19,7 +19,7 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/centinel.js b/js/mage/centinel.js index a74170a4bc..8fcd5802a9 100644 --- a/js/mage/centinel.js +++ b/js/mage/centinel.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var CentinelAuthenticate = Class.create(); diff --git a/js/mage/cookies.js b/js/mage/cookies.js index 792067b50d..26a204701a 100644 --- a/js/mage/cookies.js +++ b/js/mage/cookies.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ // old school cookie functions grabbed off the web diff --git a/js/mage/directpost.js b/js/mage/directpost.js index 6afb5254cf..67740e09a6 100644 --- a/js/mage/directpost.js +++ b/js/mage/directpost.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ var directPost = Class.create(); diff --git a/js/mage/translate.js b/js/mage/translate.js index 4e5df1aad8..78b29263a0 100644 --- a/js/mage/translate.js +++ b/js/mage/translate.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/translate_inline.css b/js/mage/translate_inline.css index 06d487ddcd..9d1f035f7e 100644 --- a/js/mage/translate_inline.css +++ b/js/mage/translate_inline.css @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/mage/translate_inline.js b/js/mage/translate_inline.js index 3dd9a4eaf3..41db5212b8 100644 --- a/js/mage/translate_inline.js +++ b/js/mage/translate_inline.js @@ -19,7 +19,7 @@ * * @category Mage * @package js - * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com) + * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/js/prototype/prototype.js b/js/prototype/prototype.js index 96e3f6e577..474b2231bb 100644 --- a/js/prototype/prototype.js +++ b/js/prototype/prototype.js @@ -1,5 +1,5 @@ -/* Prototype JavaScript framework, version 1.6.0.3 - * (c) 2005-2008 Sam Stephenson +/* Prototype JavaScript framework, version 1.7 + * (c) 2005-2010 Sam Stephenson * * Prototype is freely distributable under the terms of an MIT-style license. * For details, see the Prototype web site: http://www.prototypejs.org/ @@ -7,32 +7,53 @@ *--------------------------------------------------------------------------*/ var Prototype = { - Version: '1.6.0.3', - - Browser: { - IE: !!(window.attachEvent && - navigator.userAgent.indexOf('Opera') === -1), - Opera: navigator.userAgent.indexOf('Opera') > -1, - WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, - Gecko: navigator.userAgent.indexOf('Gecko') > -1 && - navigator.userAgent.indexOf('KHTML') === -1, - MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) - }, + + Version: '1.7', + + Browser: (function(){ + var ua = navigator.userAgent; + var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; + return { + IE: !!window.attachEvent && !isOpera, + Opera: isOpera, + WebKit: ua.indexOf('AppleWebKit/') > -1, + Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1, + MobileSafari: /Apple.*Mobile/.test(ua) + } + })(), BrowserFeatures: { XPath: !!document.evaluate, + SelectorsAPI: !!document.querySelector, - ElementExtensions: !!window.HTMLElement, - SpecificElementExtensions: - document.createElement('div')['__proto__'] && - document.createElement('div')['__proto__'] !== - document.createElement('form')['__proto__'] + + ElementExtensions: (function() { + var constructor = window.Element || window.HTMLElement; + return !!(constructor && constructor.prototype); + })(), + SpecificElementExtensions: (function() { + if (typeof window.HTMLDivElement !== 'undefined') + return true; + + var div = document.createElement('div'), + form = document.createElement('form'), + isSupported = false; + + if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) { + isSupported = true; + } + + div = form = null; + + return isSupported; + })() }, ScriptFragment: ']*>([\\S\\s]*?)<\/script>', JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, emptyFunction: function() { }, + K: function(x) { return x } }; @@ -40,9 +61,38 @@ if (Prototype.Browser.MobileSafari) Prototype.BrowserFeatures.SpecificElementExtensions = false; +var Abstract = { }; + + +var Try = { + these: function() { + var returnValue; + + for (var i = 0, length = arguments.length; i < length; i++) { + var lambda = arguments[i]; + try { + returnValue = lambda(); + break; + } catch (e) { } + } + + return returnValue; + } +}; + /* Based on Alex Arnell's inheritance implementation. */ -var Class = { - create: function() { + +var Class = (function() { + + var IS_DONTENUM_BUGGY = (function(){ + for (var p in { toString: 1 }) { + if (p === 'toString') return false; + } + return true; + })(); + + function subclass() {}; + function create() { var parent = null, properties = $A(arguments); if (Object.isFunction(properties[0])) parent = properties.shift(); @@ -56,39 +106,39 @@ var Class = { klass.subclasses = []; if (parent) { - var subclass = function() { }; subclass.prototype = parent.prototype; klass.prototype = new subclass; parent.subclasses.push(klass); } - for (var i = 0; i < properties.length; i++) + for (var i = 0, length = properties.length; i < length; i++) klass.addMethods(properties[i]); if (!klass.prototype.initialize) klass.prototype.initialize = Prototype.emptyFunction; klass.prototype.constructor = klass; - return klass; } -}; -Class.Methods = { - addMethods: function(source) { - var ancestor = this.superclass && this.superclass.prototype; - var properties = Object.keys(source); + function addMethods(source) { + var ancestor = this.superclass && this.superclass.prototype, + properties = Object.keys(source); - if (!Object.keys({ toString: true }).length) - properties.push("toString", "valueOf"); + if (IS_DONTENUM_BUGGY) { + if (source.toString != Object.prototype.toString) + properties.push("toString"); + if (source.valueOf != Object.prototype.valueOf) + properties.push("valueOf"); + } for (var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; if (ancestor && Object.isFunction(value) && - value.argumentNames().first() == "$super") { + value.argumentNames()[0] == "$super") { var method = value; value = (function(m) { - return function() { return ancestor[m].apply(this, arguments) }; + return function() { return ancestor[m].apply(this, arguments); }; })(property).wrap(method); value.valueOf = method.valueOf.bind(method); @@ -99,198 +149,338 @@ Class.Methods = { return this; } -}; -var Abstract = { }; + return { + create: create, + Methods: { + addMethods: addMethods + } + }; +})(); +(function() { -Object.extend = function(destination, source) { - for (var property in source) - destination[property] = source[property]; - return destination; -}; + var _toString = Object.prototype.toString, + NULL_TYPE = 'Null', + UNDEFINED_TYPE = 'Undefined', + BOOLEAN_TYPE = 'Boolean', + NUMBER_TYPE = 'Number', + STRING_TYPE = 'String', + OBJECT_TYPE = 'Object', + FUNCTION_CLASS = '[object Function]', + BOOLEAN_CLASS = '[object Boolean]', + NUMBER_CLASS = '[object Number]', + STRING_CLASS = '[object String]', + ARRAY_CLASS = '[object Array]', + DATE_CLASS = '[object Date]', + NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON && + typeof JSON.stringify === 'function' && + JSON.stringify(0) === '0' && + typeof JSON.stringify(Prototype.K) === 'undefined'; + + function Type(o) { + switch(o) { + case null: return NULL_TYPE; + case (void 0): return UNDEFINED_TYPE; + } + var type = typeof o; + switch(type) { + case 'boolean': return BOOLEAN_TYPE; + case 'number': return NUMBER_TYPE; + case 'string': return STRING_TYPE; + } + return OBJECT_TYPE; + } + + function extend(destination, source) { + for (var property in source) + destination[property] = source[property]; + return destination; + } -Object.extend(Object, { - inspect: function(object) { + function inspect(object) { try { - if (Object.isUndefined(object)) return 'undefined'; + if (isUndefined(object)) return 'undefined'; if (object === null) return 'null'; return object.inspect ? object.inspect() : String(object); } catch (e) { if (e instanceof RangeError) return '...'; throw e; } - }, + } - toJSON: function(object) { - var type = typeof object; - switch (type) { - case 'undefined': - case 'function': - case 'unknown': return; - case 'boolean': return object.toString(); + function toJSON(value) { + return Str('', { '': value }, []); + } + + function Str(key, holder, stack) { + var value = holder[key], + type = typeof value; + + if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') { + value = value.toJSON(key); } - if (object === null) return 'null'; - if (object.toJSON) return object.toJSON(); - if (Object.isElement(object)) return; + var _class = _toString.call(value); - var results = []; - for (var property in object) { - var value = Object.toJSON(object[property]); - if (!Object.isUndefined(value)) - results.push(property.toJSON() + ': ' + value); + switch (_class) { + case NUMBER_CLASS: + case BOOLEAN_CLASS: + case STRING_CLASS: + value = value.valueOf(); } - return '{' + results.join(', ') + '}'; - }, + switch (value) { + case null: return 'null'; + case true: return 'true'; + case false: return 'false'; + } + + type = typeof value; + switch (type) { + case 'string': + return value.inspect(true); + case 'number': + return isFinite(value) ? String(value) : 'null'; + case 'object': + + for (var i = 0, length = stack.length; i < length; i++) { + if (stack[i] === value) { throw new TypeError(); } + } + stack.push(value); - toQueryString: function(object) { + var partial = []; + if (_class === ARRAY_CLASS) { + for (var i = 0, length = value.length; i < length; i++) { + var str = Str(i, value, stack); + partial.push(typeof str === 'undefined' ? 'null' : str); + } + partial = '[' + partial.join(',') + ']'; + } else { + var keys = Object.keys(value); + for (var i = 0, length = keys.length; i < length; i++) { + var key = keys[i], str = Str(key, value, stack); + if (typeof str !== "undefined") { + partial.push(key.inspect(true)+ ':' + str); + } + } + partial = '{' + partial.join(',') + '}'; + } + stack.pop(); + return partial; + } + } + + function stringify(object) { + return JSON.stringify(object); + } + + function toQueryString(object) { return $H(object).toQueryString(); - }, + } - toHTML: function(object) { + function toHTML(object) { return object && object.toHTML ? object.toHTML() : String.interpret(object); - }, + } - keys: function(object) { - var keys = []; - for (var property in object) - keys.push(property); - return keys; - }, + function keys(object) { + if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); } + var results = []; + for (var property in object) { + if (object.hasOwnProperty(property)) { + results.push(property); + } + } + return results; + } - values: function(object) { - var values = []; + function values(object) { + var results = []; for (var property in object) - values.push(object[property]); - return values; - }, + results.push(object[property]); + return results; + } - clone: function(object) { - return Object.extend({ }, object); - }, + function clone(object) { + return extend({ }, object); + } - isElement: function(object) { + function isElement(object) { return !!(object && object.nodeType == 1); - }, + } - isArray: function(object) { - return object != null && typeof object == "object" && - 'splice' in object && 'join' in object; - }, + function isArray(object) { + return _toString.call(object) === ARRAY_CLASS; + } + + var hasNativeIsArray = (typeof Array.isArray == 'function') + && Array.isArray([]) && !Array.isArray({}); - isHash: function(object) { + if (hasNativeIsArray) { + isArray = Array.isArray; + } + + function isHash(object) { return object instanceof Hash; - }, + } - isFunction: function(object) { - return typeof object == "function"; - }, + function isFunction(object) { + return _toString.call(object) === FUNCTION_CLASS; + } - isString: function(object) { - return typeof object == "string"; - }, + function isString(object) { + return _toString.call(object) === STRING_CLASS; + } - isNumber: function(object) { - return typeof object == "number"; - }, + function isNumber(object) { + return _toString.call(object) === NUMBER_CLASS; + } - isUndefined: function(object) { - return typeof object == "undefined"; + function isDate(object) { + return _toString.call(object) === DATE_CLASS; } -}); -Object.extend(Function.prototype, { - argumentNames: function() { - var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1] + function isUndefined(object) { + return typeof object === "undefined"; + } + + extend(Object, { + extend: extend, + inspect: inspect, + toJSON: NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON, + toQueryString: toQueryString, + toHTML: toHTML, + keys: Object.keys || keys, + values: values, + clone: clone, + isElement: isElement, + isArray: isArray, + isHash: isHash, + isFunction: isFunction, + isString: isString, + isNumber: isNumber, + isDate: isDate, + isUndefined: isUndefined + }); +})(); +Object.extend(Function.prototype, (function() { + var slice = Array.prototype.slice; + + function update(array, args) { + var arrayLength = array.length, length = args.length; + while (length--) array[arrayLength + length] = args[length]; + return array; + } + + function merge(array, args) { + array = slice.call(array, 0); + return update(array, args); + } + + function argumentNames() { + var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1] + .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '') .replace(/\s+/g, '').split(','); return names.length == 1 && !names[0] ? [] : names; - }, + } - bind: function() { + function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; - var __method = this, args = $A(arguments), object = args.shift(); + var __method = this, args = slice.call(arguments, 1); return function() { - return __method.apply(object, args.concat($A(arguments))); + var a = merge(args, arguments); + return __method.apply(context, a); } - }, + } - bindAsEventListener: function() { - var __method = this, args = $A(arguments), object = args.shift(); + function bindAsEventListener(context) { + var __method = this, args = slice.call(arguments, 1); return function(event) { - return __method.apply(object, [event || window.event].concat(args)); + var a = update([event || window.event], args); + return __method.apply(context, a); } - }, + } - curry: function() { + function curry() { if (!arguments.length) return this; - var __method = this, args = $A(arguments); + var __method = this, args = slice.call(arguments, 0); return function() { - return __method.apply(this, args.concat($A(arguments))); + var a = merge(args, arguments); + return __method.apply(this, a); } - }, + } - delay: function() { - var __method = this, args = $A(arguments), timeout = args.shift() * 1000; + function delay(timeout) { + var __method = this, args = slice.call(arguments, 1); + timeout = timeout * 1000; return window.setTimeout(function() { return __method.apply(__method, args); }, timeout); - }, + } - defer: function() { - var args = [0.01].concat($A(arguments)); + function defer() { + var args = update([0.01], arguments); return this.delay.apply(this, args); - }, + } - wrap: function(wrapper) { + function wrap(wrapper) { var __method = this; return function() { - return wrapper.apply(this, [__method.bind(this)].concat($A(arguments))); + var a = update([__method.bind(this)], arguments); + return wrapper.apply(this, a); } - }, + } - methodize: function() { + function methodize() { if (this._methodized) return this._methodized; var __method = this; return this._methodized = function() { - return __method.apply(null, [this].concat($A(arguments))); + var a = update([this], arguments); + return __method.apply(null, a); }; } -}); -Date.prototype.toJSON = function() { - return '"' + this.getUTCFullYear() + '-' + - (this.getUTCMonth() + 1).toPaddedString(2) + '-' + - this.getUTCDate().toPaddedString(2) + 'T' + - this.getUTCHours().toPaddedString(2) + ':' + - this.getUTCMinutes().toPaddedString(2) + ':' + - this.getUTCSeconds().toPaddedString(2) + 'Z"'; -}; + return { + argumentNames: argumentNames, + bind: bind, + bindAsEventListener: bindAsEventListener, + curry: curry, + delay: delay, + defer: defer, + wrap: wrap, + methodize: methodize + } +})()); -var Try = { - these: function() { - var returnValue; - for (var i = 0, length = arguments.length; i < length; i++) { - var lambda = arguments[i]; - try { - returnValue = lambda(); - break; - } catch (e) { } - } - return returnValue; +(function(proto) { + + + function toISOString() { + return this.getUTCFullYear() + '-' + + (this.getUTCMonth() + 1).toPaddedString(2) + '-' + + this.getUTCDate().toPaddedString(2) + 'T' + + this.getUTCHours().toPaddedString(2) + ':' + + this.getUTCMinutes().toPaddedString(2) + ':' + + this.getUTCSeconds().toPaddedString(2) + 'Z'; } -}; + + + function toJSON() { + return this.toISOString(); + } + + if (!proto.toISOString) proto.toISOString = toISOString; + if (!proto.toJSON) proto.toJSON = toJSON; + +})(Date.prototype); + RegExp.prototype.match = RegExp.prototype.test; RegExp.escape = function(str) { return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); }; - -/*--------------------------------------------------------------------------*/ - var PeriodicalExecuter = Class.create({ initialize: function(callback, frequency) { this.callback = callback; @@ -319,8 +509,10 @@ var PeriodicalExecuter = Class.create({ try { this.currentlyExecuting = true; this.execute(); - } finally { this.currentlyExecuting = false; + } catch(e) { + this.currentlyExecuting = false; + throw e; } } } @@ -339,10 +531,28 @@ Object.extend(String, { } }); -Object.extend(String.prototype, { - gsub: function(pattern, replacement) { +Object.extend(String.prototype, (function() { + var NATIVE_JSON_PARSE_SUPPORT = window.JSON && + typeof JSON.parse === 'function' && + JSON.parse('{"test": true}').test; + + function prepareReplacement(replacement) { + if (Object.isFunction(replacement)) return replacement; + var template = new Template(replacement); + return function(match) { return template.evaluate(match) }; + } + + function gsub(pattern, replacement) { var result = '', source = this, match; - replacement = arguments.callee.prepareReplacement(replacement); + replacement = prepareReplacement(replacement); + + if (Object.isString(pattern)) + pattern = RegExp.escape(pattern); + + if (!(pattern.length || pattern.source)) { + replacement = replacement(''); + return replacement + source.split('').join(replacement) + replacement; + } while (source.length > 0) { if (match = source.match(pattern)) { @@ -354,76 +564,72 @@ Object.extend(String.prototype, { } } return result; - }, + } - sub: function(pattern, replacement, count) { - replacement = this.gsub.prepareReplacement(replacement); + function sub(pattern, replacement, count) { + replacement = prepareReplacement(replacement); count = Object.isUndefined(count) ? 1 : count; return this.gsub(pattern, function(match) { if (--count < 0) return match[0]; return replacement(match); }); - }, + } - scan: function(pattern, iterator) { + function scan(pattern, iterator) { this.gsub(pattern, iterator); return String(this); - }, + } - truncate: function(length, truncation) { + function truncate(length, truncation) { length = length || 30; truncation = Object.isUndefined(truncation) ? '...' : truncation; return this.length > length ? this.slice(0, length - truncation.length) + truncation : String(this); - }, + } - strip: function() { + function strip() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); - }, + } - stripTags: function() { - return this.replace(/<\/?[^>]+>/gi, ''); - }, + function stripTags() { + return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, ''); + } - stripScripts: function() { + function stripScripts() { return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); - }, + } - extractScripts: function() { - var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); - var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); + function extractScripts() { + var matchAll = new RegExp(Prototype.ScriptFragment, 'img'), + matchOne = new RegExp(Prototype.ScriptFragment, 'im'); return (this.match(matchAll) || []).map(function(scriptTag) { return (scriptTag.match(matchOne) || ['', ''])[1]; }); - }, + } - evalScripts: function() { + function evalScripts() { return this.extractScripts().map(function(script) { return eval(script) }); - }, + } - escapeHTML: function() { - var self = arguments.callee; - self.text.data = this; - return self.div.innerHTML; - }, + function escapeHTML() { + return this.replace(/&/g,'&').replace(//g,'>'); + } + + function unescapeHTML() { + return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); + } - unescapeHTML: function() { - var div = new Element('div'); - div.innerHTML = this.stripTags(); - return div.childNodes[0] ? (div.childNodes.length > 1 ? - $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : - div.childNodes[0].nodeValue) : ''; - }, - toQueryParams: function(separator) { + function toQueryParams(separator) { var match = this.strip().match(/([^?#]*)(#.*)?$/); if (!match) return { }; return match[1].split(separator || '&').inject({ }, function(hash, pair) { if ((pair = pair.split('='))[0]) { - var key = decodeURIComponent(pair.shift()); - var value = pair.length > 1 ? pair.join('=') : pair[0]; + var key = decodeURIComponent(pair.shift()), + value = pair.length > 1 ? pair.join('=') : pair[0]; + if (value != undefined) value = decodeURIComponent(value); if (key in hash) { @@ -434,128 +640,144 @@ Object.extend(String.prototype, { } return hash; }); - }, + } - toArray: function() { + function toArray() { return this.split(''); - }, + } - succ: function() { + function succ() { return this.slice(0, this.length - 1) + String.fromCharCode(this.charCodeAt(this.length - 1) + 1); - }, + } - times: function(count) { + function times(count) { return count < 1 ? '' : new Array(count + 1).join(this); - }, - - camelize: function() { - var parts = this.split('-'), len = parts.length; - if (len == 1) return parts[0]; - - var camelized = this.charAt(0) == '-' - ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) - : parts[0]; - - for (var i = 1; i < len; i++) - camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); + } - return camelized; - }, + function camelize() { + return this.replace(/-+(.)?/g, function(match, chr) { + return chr ? chr.toUpperCase() : ''; + }); + } - capitalize: function() { + function capitalize() { return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); - }, + } - underscore: function() { - return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase(); - }, + function underscore() { + return this.replace(/::/g, '/') + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') + .replace(/([a-z\d])([A-Z])/g, '$1_$2') + .replace(/-/g, '_') + .toLowerCase(); + } - dasherize: function() { - return this.gsub(/_/,'-'); - }, + function dasherize() { + return this.replace(/_/g, '-'); + } - inspect: function(useDoubleQuotes) { - var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { - var character = String.specialChar[match[0]]; - return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); + function inspect(useDoubleQuotes) { + var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) { + if (character in String.specialChar) { + return String.specialChar[character]; + } + return '\\u00' + character.charCodeAt().toPaddedString(2, 16); }); if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; return "'" + escapedString.replace(/'/g, '\\\'') + "'"; - }, - - toJSON: function() { - return this.inspect(true); - }, + } - unfilterJSON: function(filter) { - return this.sub(filter || Prototype.JSONFilter, '#{1}'); - }, + function unfilterJSON(filter) { + return this.replace(filter || Prototype.JSONFilter, '$1'); + } - isJSON: function() { + function isJSON() { var str = this; if (str.blank()) return false; - str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''); - return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str); - }, + str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'); + str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); + str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); + return (/^[\],:{}\s]*$/).test(str); + } - evalJSON: function(sanitize) { - var json = this.unfilterJSON(); + function evalJSON(sanitize) { + var json = this.unfilterJSON(), + cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + if (cx.test(json)) { + json = json.replace(cx, function (a) { + return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } try { if (!sanitize || json.isJSON()) return eval('(' + json + ')'); } catch (e) { } throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); - }, + } + + function parseJSON() { + var json = this.unfilterJSON(); + return JSON.parse(json); + } - include: function(pattern) { + function include(pattern) { return this.indexOf(pattern) > -1; - }, + } - startsWith: function(pattern) { - return this.indexOf(pattern) === 0; - }, + function startsWith(pattern) { + return this.lastIndexOf(pattern, 0) === 0; + } - endsWith: function(pattern) { + function endsWith(pattern) { var d = this.length - pattern.length; - return d >= 0 && this.lastIndexOf(pattern) === d; - }, + return d >= 0 && this.indexOf(pattern, d) === d; + } - empty: function() { + function empty() { return this == ''; - }, + } - blank: function() { + function blank() { return /^\s*$/.test(this); - }, - - interpolate: function(object, pattern) { - return new Template(this, pattern).evaluate(object); } -}); -if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { - escapeHTML: function() { - return this.replace(/&/g,'&').replace(//g,'>'); - }, - unescapeHTML: function() { - return this.stripTags().replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); + function interpolate(object, pattern) { + return new Template(this, pattern).evaluate(object); } -}); - -String.prototype.gsub.prepareReplacement = function(replacement) { - if (Object.isFunction(replacement)) return replacement; - var template = new Template(replacement); - return function(match) { return template.evaluate(match) }; -}; - -String.prototype.parseQuery = String.prototype.toQueryParams; - -Object.extend(String.prototype.escapeHTML, { - div: document.createElement('div'), - text: document.createTextNode('') -}); -String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text); + return { + gsub: gsub, + sub: sub, + scan: scan, + truncate: truncate, + strip: String.prototype.trim || strip, + stripTags: stripTags, + stripScripts: stripScripts, + extractScripts: extractScripts, + evalScripts: evalScripts, + escapeHTML: escapeHTML, + unescapeHTML: unescapeHTML, + toQueryParams: toQueryParams, + parseQuery: toQueryParams, + toArray: toArray, + succ: succ, + times: times, + camelize: camelize, + capitalize: capitalize, + underscore: underscore, + dasherize: dasherize, + inspect: inspect, + unfilterJSON: unfilterJSON, + isJSON: isJSON, + evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON, + include: include, + startsWith: startsWith, + endsWith: endsWith, + empty: empty, + blank: blank, + interpolate: interpolate + }; +})()); var Template = Class.create({ initialize: function(template, pattern) { @@ -564,22 +786,23 @@ var Template = Class.create({ }, evaluate: function(object) { - if (Object.isFunction(object.toTemplateReplacements)) + if (object && Object.isFunction(object.toTemplateReplacements)) object = object.toTemplateReplacements(); return this.template.gsub(this.pattern, function(match) { - if (object == null) return ''; + if (object == null) return (match[1] + ''); var before = match[1] || ''; if (before == '\\') return match[2]; - var ctx = object, expr = match[3]; - var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; + var ctx = object, expr = match[3], + pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/; + match = pattern.exec(expr); if (match == null) return before; while (match != null) { - var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1]; + var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); @@ -594,8 +817,8 @@ Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; var $break = { }; -var Enumerable = { - each: function(iterator, context) { +var Enumerable = (function() { + function each(iterator, context) { var index = 0; try { this._each(function(value) { @@ -605,17 +828,17 @@ var Enumerable = { if (e != $break) throw e; } return this; - }, + } - eachSlice: function(number, iterator, context) { + function eachSlice(number, iterator, context) { var index = -number, slices = [], array = this.toArray(); if (number < 1) return array; while ((index += number) < array.length) slices.push(array.slice(index, index+number)); return slices.collect(iterator, context); - }, + } - all: function(iterator, context) { + function all(iterator, context) { iterator = iterator || Prototype.K; var result = true; this.each(function(value, index) { @@ -623,9 +846,9 @@ var Enumerable = { if (!result) throw $break; }); return result; - }, + } - any: function(iterator, context) { + function any(iterator, context) { iterator = iterator || Prototype.K; var result = false; this.each(function(value, index) { @@ -633,18 +856,18 @@ var Enumerable = { throw $break; }); return result; - }, + } - collect: function(iterator, context) { + function collect(iterator, context) { iterator = iterator || Prototype.K; var results = []; this.each(function(value, index) { results.push(iterator.call(context, value, index)); }); return results; - }, + } - detect: function(iterator, context) { + function detect(iterator, context) { var result; this.each(function(value, index) { if (iterator.call(context, value, index)) { @@ -653,32 +876,32 @@ var Enumerable = { } }); return result; - }, + } - findAll: function(iterator, context) { + function findAll(iterator, context) { var results = []; this.each(function(value, index) { if (iterator.call(context, value, index)) results.push(value); }); return results; - }, + } - grep: function(filter, iterator, context) { + function grep(filter, iterator, context) { iterator = iterator || Prototype.K; var results = []; if (Object.isString(filter)) - filter = new RegExp(filter); + filter = new RegExp(RegExp.escape(filter)); this.each(function(value, index) { if (filter.match(value)) results.push(iterator.call(context, value, index)); }); return results; - }, + } - include: function(object) { + function include(object) { if (Object.isFunction(this.indexOf)) if (this.indexOf(object) != -1) return true; @@ -690,31 +913,31 @@ var Enumerable = { } }); return found; - }, + } - inGroupsOf: function(number, fillWith) { + function inGroupsOf(number, fillWith) { fillWith = Object.isUndefined(fillWith) ? null : fillWith; return this.eachSlice(number, function(slice) { while(slice.length < number) slice.push(fillWith); return slice; }); - }, + } - inject: function(memo, iterator, context) { + function inject(memo, iterator, context) { this.each(function(value, index) { memo = iterator.call(context, memo, value, index); }); return memo; - }, + } - invoke: function(method) { + function invoke(method) { var args = $A(arguments).slice(1); return this.map(function(value) { return value[method].apply(value, args); }); - }, + } - max: function(iterator, context) { + function max(iterator, context) { iterator = iterator || Prototype.K; var result; this.each(function(value, index) { @@ -723,9 +946,9 @@ var Enumerable = { result = value; }); return result; - }, + } - min: function(iterator, context) { + function min(iterator, context) { iterator = iterator || Prototype.K; var result; this.each(function(value, index) { @@ -734,9 +957,9 @@ var Enumerable = { result = value; }); return result; - }, + } - partition: function(iterator, context) { + function partition(iterator, context) { iterator = iterator || Prototype.K; var trues = [], falses = []; this.each(function(value, index) { @@ -744,26 +967,26 @@ var Enumerable = { trues : falses).push(value); }); return [trues, falses]; - }, + } - pluck: function(property) { + function pluck(property) { var results = []; this.each(function(value) { results.push(value[property]); }); return results; - }, + } - reject: function(iterator, context) { + function reject(iterator, context) { var results = []; this.each(function(value, index) { if (!iterator.call(context, value, index)) results.push(value); }); return results; - }, + } - sortBy: function(iterator, context) { + function sortBy(iterator, context) { return this.map(function(value, index) { return { value: value, @@ -773,13 +996,13 @@ var Enumerable = { var a = left.criteria, b = right.criteria; return a < b ? -1 : a > b ? 1 : 0; }).pluck('value'); - }, + } - toArray: function() { + function toArray() { return this.map(); - }, + } - zip: function() { + function zip() { var iterator = Prototype.K, args = $A(arguments); if (Object.isFunction(args.last())) iterator = args.pop(); @@ -788,336 +1011,416 @@ var Enumerable = { return this.map(function(value, index) { return iterator(collections.pluck(index)); }); - }, + } - size: function() { + function size() { return this.toArray().length; - }, + } - inspect: function() { + function inspect() { return '#'; } -}; -Object.extend(Enumerable, { - map: Enumerable.collect, - find: Enumerable.detect, - select: Enumerable.findAll, - filter: Enumerable.findAll, - member: Enumerable.include, - entries: Enumerable.toArray, - every: Enumerable.all, - some: Enumerable.any -}); + + + + + + + + + return { + each: each, + eachSlice: eachSlice, + all: all, + every: all, + any: any, + some: any, + collect: collect, + map: collect, + detect: detect, + findAll: findAll, + select: findAll, + filter: findAll, + grep: grep, + include: include, + member: include, + inGroupsOf: inGroupsOf, + inject: inject, + invoke: invoke, + max: max, + min: min, + partition: partition, + pluck: pluck, + reject: reject, + sortBy: sortBy, + toArray: toArray, + entries: toArray, + zip: zip, + size: size, + inspect: inspect, + find: detect + }; +})(); + function $A(iterable) { if (!iterable) return []; - if (iterable.toArray) return iterable.toArray(); + if ('toArray' in Object(iterable)) return iterable.toArray(); var length = iterable.length || 0, results = new Array(length); while (length--) results[length] = iterable[length]; return results; } -if (Prototype.Browser.WebKit) { - $A = function(iterable) { - if (!iterable) return []; - // In Safari, only use the `toArray` method if it's not a NodeList. - // A NodeList is a function, has an function `item` property, and a numeric - // `length` property. Adapted from Google Doctype. - if (!(typeof iterable === 'function' && typeof iterable.length === - 'number' && typeof iterable.item === 'function') && iterable.toArray) - return iterable.toArray(); - var length = iterable.length || 0, results = new Array(length); - while (length--) results[length] = iterable[length]; - return results; - }; + +function $w(string) { + if (!Object.isString(string)) return []; + string = string.strip(); + return string ? string.split(/\s+/) : []; } Array.from = $A; -Object.extend(Array.prototype, Enumerable); -if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse; +(function() { + var arrayProto = Array.prototype, + slice = arrayProto.slice, + _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available -Object.extend(Array.prototype, { - _each: function(iterator) { - for (var i = 0, length = this.length; i < length; i++) - iterator(this[i]); - }, + function each(iterator, context) { + for (var i = 0, length = this.length >>> 0; i < length; i++) { + if (i in this) iterator.call(context, this[i], i, this); + } + } + if (!_each) _each = each; - clear: function() { + function clear() { this.length = 0; return this; - }, + } - first: function() { + function first() { return this[0]; - }, + } - last: function() { + function last() { return this[this.length - 1]; - }, + } - compact: function() { + function compact() { return this.select(function(value) { return value != null; }); - }, + } - flatten: function() { + function flatten() { return this.inject([], function(array, value) { - return array.concat(Object.isArray(value) ? - value.flatten() : [value]); + if (Object.isArray(value)) + return array.concat(value.flatten()); + array.push(value); + return array; }); - }, + } - without: function() { - var values = $A(arguments); + function without() { + var values = slice.call(arguments, 0); return this.select(function(value) { return !values.include(value); }); - }, - - reverse: function(inline) { - return (inline !== false ? this : this.toArray())._reverse(); - }, + } - reduce: function() { - return this.length > 1 ? this : this[0]; - }, + function reverse(inline) { + return (inline === false ? this.toArray() : this)._reverse(); + } - uniq: function(sorted) { + function uniq(sorted) { return this.inject([], function(array, value, index) { if (0 == index || (sorted ? array.last() != value : !array.include(value))) array.push(value); return array; }); - }, + } - intersect: function(array) { + function intersect(array) { return this.uniq().findAll(function(item) { return array.detect(function(value) { return item === value }); }); - }, + } - clone: function() { - return [].concat(this); - }, - size: function() { + function clone() { + return slice.call(this, 0); + } + + function size() { return this.length; - }, + } - inspect: function() { + function inspect() { return '[' + this.map(Object.inspect).join(', ') + ']'; - }, - - toJSON: function() { - var results = []; - this.each(function(object) { - var value = Object.toJSON(object); - if (!Object.isUndefined(value)) results.push(value); - }); - return '[' + results.join(', ') + ']'; } -}); -// use native browser JS 1.6 implementation if available -if (Object.isFunction(Array.prototype.forEach)) - Array.prototype._each = Array.prototype.forEach; - -if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) { - i || (i = 0); - var length = this.length; - if (i < 0) i = length + i; - for (; i < length; i++) - if (this[i] === item) return i; - return -1; -}; - -if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) { - i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1; - var n = this.slice(0, i).reverse().indexOf(item); - return (n < 0) ? n : i - n - 1; -}; - -Array.prototype.toArray = Array.prototype.clone; + function indexOf(item, i) { + i || (i = 0); + var length = this.length; + if (i < 0) i = length + i; + for (; i < length; i++) + if (this[i] === item) return i; + return -1; + } -function $w(string) { - if (!Object.isString(string)) return []; - string = string.strip(); - return string ? string.split(/\s+/) : []; -} + function lastIndexOf(item, i) { + i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1; + var n = this.slice(0, i).reverse().indexOf(item); + return (n < 0) ? n : i - n - 1; + } -if (Prototype.Browser.Opera){ - Array.prototype.concat = function() { - var array = []; - for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); + function concat() { + var array = slice.call(this, 0), item; for (var i = 0, length = arguments.length; i < length; i++) { - if (Object.isArray(arguments[i])) { - for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) - array.push(arguments[i][j]); + item = arguments[i]; + if (Object.isArray(item) && !('callee' in item)) { + for (var j = 0, arrayLength = item.length; j < arrayLength; j++) + array.push(item[j]); } else { - array.push(arguments[i]); + array.push(item); } } return array; - }; -} -Object.extend(Number.prototype, { - toColorPart: function() { - return this.toPaddedString(2, 16); - }, - - succ: function() { - return this + 1; - }, + } - times: function(iterator, context) { - $R(0, this, true).each(iterator, context); - return this; - }, + Object.extend(arrayProto, Enumerable); + + if (!arrayProto._reverse) + arrayProto._reverse = arrayProto.reverse; + + Object.extend(arrayProto, { + _each: _each, + clear: clear, + first: first, + last: last, + compact: compact, + flatten: flatten, + without: without, + reverse: reverse, + uniq: uniq, + intersect: intersect, + clone: clone, + toArray: clone, + size: size, + inspect: inspect + }); - toPaddedString: function(length, radix) { - var string = this.toString(radix || 10); - return '0'.times(length - string.length) + string; - }, + var CONCAT_ARGUMENTS_BUGGY = (function() { + return [].concat(arguments)[0][0] !== 1; + })(1,2) - toJSON: function() { - return isFinite(this) ? this.toString() : 'null'; - } -}); + if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat; -$w('abs round ceil floor').each(function(method){ - Number.prototype[method] = Math[method].methodize(); -}); + if (!arrayProto.indexOf) arrayProto.indexOf = indexOf; + if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf; +})(); function $H(object) { return new Hash(object); }; var Hash = Class.create(Enumerable, (function() { + function initialize(object) { + this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); + } - function toQueryPair(key, value) { - if (Object.isUndefined(value)) return key; - return key + '=' + encodeURIComponent(String.interpret(value)); + + function _each(iterator) { + for (var key in this._object) { + var value = this._object[key], pair = [key, value]; + pair.key = key; + pair.value = value; + iterator(pair); + } } - return { - initialize: function(object) { - this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); - }, + function set(key, value) { + return this._object[key] = value; + } - _each: function(iterator) { - for (var key in this._object) { - var value = this._object[key], pair = [key, value]; - pair.key = key; - pair.value = value; - iterator(pair); - } - }, + function get(key) { + if (this._object[key] !== Object.prototype[key]) + return this._object[key]; + } - set: function(key, value) { - return this._object[key] = value; - }, + function unset(key) { + var value = this._object[key]; + delete this._object[key]; + return value; + } - get: function(key) { - // simulating poorly supported hasOwnProperty - if (this._object[key] !== Object.prototype[key]) - return this._object[key]; - }, + function toObject() { + return Object.clone(this._object); + } - unset: function(key) { - var value = this._object[key]; - delete this._object[key]; - return value; - }, - toObject: function() { - return Object.clone(this._object); - }, - keys: function() { - return this.pluck('key'); - }, + function keys() { + return this.pluck('key'); + } - values: function() { - return this.pluck('value'); - }, + function values() { + return this.pluck('value'); + } - index: function(value) { - var match = this.detect(function(pair) { - return pair.value === value; - }); - return match && match.key; - }, + function index(value) { + var match = this.detect(function(pair) { + return pair.value === value; + }); + return match && match.key; + } - merge: function(object) { - return this.clone().update(object); - }, + function merge(object) { + return this.clone().update(object); + } - update: function(object) { - return new Hash(object).inject(this, function(result, pair) { - result.set(pair.key, pair.value); - return result; - }); - }, + function update(object) { + return new Hash(object).inject(this, function(result, pair) { + result.set(pair.key, pair.value); + return result; + }); + } - toQueryString: function() { - return this.inject([], function(results, pair) { - var key = encodeURIComponent(pair.key), values = pair.value; + function toQueryPair(key, value) { + if (Object.isUndefined(value)) return key; + return key + '=' + encodeURIComponent(String.interpret(value)); + } - if (values && typeof values == 'object') { - if (Object.isArray(values)) - return results.concat(values.map(toQueryPair.curry(key))); - } else results.push(toQueryPair(key, values)); - return results; - }).join('&'); - }, + function toQueryString() { + return this.inject([], function(results, pair) { + var key = encodeURIComponent(pair.key), values = pair.value; - inspect: function() { - return '#'; - }, + if (values && typeof values == 'object') { + if (Object.isArray(values)) { + var queryValues = []; + for (var i = 0, len = values.length, value; i < len; i++) { + value = values[i]; + queryValues.push(toQueryPair(key, value)); + } + return results.concat(queryValues); + } + } else results.push(toQueryPair(key, values)); + return results; + }).join('&'); + } - toJSON: function() { - return Object.toJSON(this.toObject()); - }, + function inspect() { + return '#'; + } - clone: function() { - return new Hash(this); - } + function clone() { + return new Hash(this); } + + return { + initialize: initialize, + _each: _each, + set: set, + get: get, + unset: unset, + toObject: toObject, + toTemplateReplacements: toObject, + keys: keys, + values: values, + index: index, + merge: merge, + update: update, + toQueryString: toQueryString, + inspect: inspect, + toJSON: toObject, + clone: clone + }; })()); -Hash.prototype.toTemplateReplacements = Hash.prototype.toObject; Hash.from = $H; -var ObjectRange = Class.create(Enumerable, { - initialize: function(start, end, exclusive) { +Object.extend(Number.prototype, (function() { + function toColorPart() { + return this.toPaddedString(2, 16); + } + + function succ() { + return this + 1; + } + + function times(iterator, context) { + $R(0, this, true).each(iterator, context); + return this; + } + + function toPaddedString(length, radix) { + var string = this.toString(radix || 10); + return '0'.times(length - string.length) + string; + } + + function abs() { + return Math.abs(this); + } + + function round() { + return Math.round(this); + } + + function ceil() { + return Math.ceil(this); + } + + function floor() { + return Math.floor(this); + } + + return { + toColorPart: toColorPart, + succ: succ, + times: times, + toPaddedString: toPaddedString, + abs: abs, + round: round, + ceil: ceil, + floor: floor + }; +})()); + +function $R(start, end, exclusive) { + return new ObjectRange(start, end, exclusive); +} + +var ObjectRange = Class.create(Enumerable, (function() { + function initialize(start, end, exclusive) { this.start = start; this.end = end; this.exclusive = exclusive; - }, + } - _each: function(iterator) { + function _each(iterator) { var value = this.start; while (this.include(value)) { iterator(value); value = value.succ(); } - }, + } - include: function(value) { + function include(value) { if (value < this.start) return false; if (this.exclusive) return value < this.end; return value <= this.end; } -}); -var $R = function(start, end, exclusive) { - return new ObjectRange(start, end, exclusive); -}; + return { + initialize: initialize, + _each: _each, + include: include + }; +})()); + + var Ajax = { getTransport: function() { @@ -1164,7 +1467,6 @@ Ajax.Responders.register({ onCreate: function() { Ajax.activeRequestCount++ }, onComplete: function() { Ajax.activeRequestCount-- } }); - Ajax.Base = Class.create({ initialize: function(options) { this.options = { @@ -1180,13 +1482,10 @@ Ajax.Base = Class.create({ this.options.method = this.options.method.toLowerCase(); - if (Object.isString(this.options.parameters)) - this.options.parameters = this.options.parameters.toQueryParams(); - else if (Object.isHash(this.options.parameters)) + if (Object.isHash(this.options.parameters)) this.options.parameters = this.options.parameters.toObject(); } }); - Ajax.Request = Class.create(Ajax.Base, { _complete: false, @@ -1199,24 +1498,21 @@ Ajax.Request = Class.create(Ajax.Base, { request: function(url) { this.url = url; this.method = this.options.method; - var params = Object.clone(this.options.parameters); + var params = Object.isString(this.options.parameters) ? + this.options.parameters : + Object.toQueryString(this.options.parameters); if (!['get', 'post'].include(this.method)) { - // simulate other verbs over post - params['_method'] = this.method; + params += (params ? '&' : '') + "_method=" + this.method; this.method = 'post'; } - this.parameters = params; - - if (params = Object.toQueryString(params)) { - // when GET, append parameters to URL - if (this.method == 'get') - this.url += (this.url.include('?') ? '&' : '?') + params; - else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) - params += '&_='; + if (params && this.method === 'get') { + this.url += (this.url.include('?') ? '&' : '?') + params; } + this.parameters = params.toQueryParams(); + try { var response = new Ajax.Response(this); if (this.options.onCreate) this.options.onCreate(response); @@ -1269,7 +1565,6 @@ Ajax.Request = Class.create(Ajax.Base, { headers['Connection'] = 'close'; } - // user-defined headers if (typeof this.options.requestHeaders == 'object') { var extras = this.options.requestHeaders; @@ -1286,11 +1581,12 @@ Ajax.Request = Class.create(Ajax.Base, { success: function() { var status = this.getStatus(); - return !status || (status >= 200 && status < 300); + return !status || (status >= 200 && status < 300) || status == 304; }, getStatus: function() { try { + if (this.transport.status === 1223) return 204; return this.transport.status || 0; } catch (e) { return 0 } }, @@ -1323,7 +1619,6 @@ Ajax.Request = Class.create(Ajax.Base, { } if (state == 'Complete') { - // avoid memory leak in MSIE: clean up this.transport.onreadystatechange = Prototype.emptyFunction; } }, @@ -1340,7 +1635,7 @@ Ajax.Request = Class.create(Ajax.Base, { getHeader: function(name) { try { return this.transport.getResponseHeader(name) || null; - } catch (e) { return null } + } catch (e) { return null; } }, evalResponse: function() { @@ -1360,20 +1655,27 @@ Ajax.Request = Class.create(Ajax.Base, { Ajax.Request.Events = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; + + + + + + + Ajax.Response = Class.create({ initialize: function(request){ this.request = request; var transport = this.transport = request.transport, readyState = this.readyState = transport.readyState; - if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) { + if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) { this.status = this.getStatus(); this.statusText = this.getStatusText(); this.responseText = String.interpret(transport.responseText); this.headerJSON = this._getHeaderJSON(); } - if(readyState == 4) { + if (readyState == 4) { var xml = transport.responseXML; this.responseXML = Object.isUndefined(xml) ? null : xml; this.responseJSON = this._getResponseJSON(); @@ -1381,6 +1683,7 @@ Ajax.Response = Class.create({ }, status: 0, + statusText: '', getStatus: Ajax.Request.prototype.getStatus, @@ -1510,6 +1813,8 @@ Ajax.PeriodicalUpdater = Class.create(Ajax.Base, { this.updater = new Ajax.Updater(this.container, this.url, this.options); } }); + + function $(element) { if (arguments.length > 1) { for (var i = 0, elements = [], length = arguments.length; i < length; i++) @@ -1534,10 +1839,9 @@ if (Prototype.BrowserFeatures.XPath) { /*--------------------------------------------------------------------------*/ -if (!window.Node) var Node = { }; +if (!Node) var Node = { }; if (!Node.ELEMENT_NODE) { - // DOM level 2 ECMAScript Language Binding Object.extend(Node, { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, @@ -1554,26 +1858,63 @@ if (!Node.ELEMENT_NODE) { }); } -(function() { - var element = this.Element; - this.Element = function(tagName, attributes) { + + +(function(global) { + function shouldUseCache(tagName, attributes) { + if (tagName === 'select') return false; + if ('type' in attributes) return false; + return true; + } + + var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){ + try { + var el = document.createElement(''); + return el.tagName.toLowerCase() === 'input' && el.name === 'x'; + } + catch(err) { + return false; + } + })(); + + var element = global.Element; + + global.Element = function(tagName, attributes) { attributes = attributes || { }; tagName = tagName.toLowerCase(); var cache = Element.cache; - if (Prototype.Browser.IE && attributes.name) { + + if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) { tagName = '<' + tagName + ' name="' + attributes.name + '">'; delete attributes.name; return Element.writeAttribute(document.createElement(tagName), attributes); } + if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName)); - return Element.writeAttribute(cache[tagName].cloneNode(false), attributes); + + var node = shouldUseCache(tagName, attributes) ? + cache[tagName].cloneNode(false) : document.createElement(tagName); + + return Element.writeAttribute(node, attributes); }; - Object.extend(this.Element, element || { }); - if (element) this.Element.prototype = element.prototype; -}).call(window); + Object.extend(global.Element, element || { }); + if (element) global.Element.prototype = element.prototype; + +})(this); + +Element.idCounter = 1; Element.cache = { }; +Element._purgeElement = function(element) { + var uid = element._prototypeUID; + if (uid) { + Element.stopObserving(element); + element._prototypeUID = void 0; + delete Element.Storage[uid]; + } +} + Element.Methods = { visible: function(element) { return $(element).style.display != 'none'; @@ -1603,15 +1944,116 @@ Element.Methods = { return element; }, - update: function(element, content) { - element = $(element); - if (content && content.toElement) content = content.toElement(); - if (Object.isElement(content)) return element.update().insert(content); - content = Object.toHTML(content); - element.innerHTML = content.stripScripts(); - content.evalScripts.bind(content).defer(); - return element; - }, + update: (function(){ + + var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){ + var el = document.createElement("select"), + isBuggy = true; + el.innerHTML = ""; + if (el.options && el.options[0]) { + isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION"; + } + el = null; + return isBuggy; + })(); + + var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){ + try { + var el = document.createElement("table"); + if (el && el.tBodies) { + el.innerHTML = "test"; + var isBuggy = typeof el.tBodies[0] == "undefined"; + el = null; + return isBuggy; + } + } catch (e) { + return true; + } + })(); + + var LINK_ELEMENT_INNERHTML_BUGGY = (function() { + try { + var el = document.createElement('div'); + el.innerHTML = ""; + var isBuggy = (el.childNodes.length === 0); + el = null; + return isBuggy; + } catch(e) { + return true; + } + })(); + + var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY || + TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY; + + var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () { + var s = document.createElement("script"), + isBuggy = false; + try { + s.appendChild(document.createTextNode("")); + isBuggy = !s.firstChild || + s.firstChild && s.firstChild.nodeType !== 3; + } catch (e) { + isBuggy = true; + } + s = null; + return isBuggy; + })(); + + + function update(element, content) { + element = $(element); + var purgeElement = Element._purgeElement; + + var descendants = element.getElementsByTagName('*'), + i = descendants.length; + while (i--) purgeElement(descendants[i]); + + if (content && content.toElement) + content = content.toElement(); + + if (Object.isElement(content)) + return element.update().insert(content); + + content = Object.toHTML(content); + + var tagName = element.tagName.toUpperCase(); + + if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) { + element.text = content; + return element; + } + + if (ANY_INNERHTML_BUGGY) { + if (tagName in Element._insertionTranslations.tags) { + while (element.firstChild) { + element.removeChild(element.firstChild); + } + Element._getContentFromAnonymousElement(tagName, content.stripScripts()) + .each(function(node) { + element.appendChild(node) + }); + } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf(' -1) { + while (element.firstChild) { + element.removeChild(element.firstChild); + } + var nodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts(), true); + nodes.each(function(node) { element.appendChild(node) }); + } + else { + element.innerHTML = content.stripScripts(); + } + } + else { + element.innerHTML = content.stripScripts(); + } + + content.evalScripts.bind(content).defer(); + return element; + } + + return update; + })(), replace: function(element, content) { element = $(element); @@ -1679,28 +2121,35 @@ Element.Methods = { element = $(element); var result = '<' + element.tagName.toLowerCase(); $H({'id': 'id', 'className': 'class'}).each(function(pair) { - var property = pair.first(), attribute = pair.last(); - var value = (element[property] || '').toString(); + var property = pair.first(), + attribute = pair.last(), + value = (element[property] || '').toString(); if (value) result += ' ' + attribute + '=' + value.inspect(true); }); return result + '>'; }, - recursivelyCollect: function(element, property) { + recursivelyCollect: function(element, property, maximumLength) { element = $(element); + maximumLength = maximumLength || -1; var elements = []; - while (element = element[property]) + + while (element = element[property]) { if (element.nodeType == 1) elements.push(Element.extend(element)); + if (elements.length == maximumLength) + break; + } + return elements; }, ancestors: function(element) { - return $(element).recursivelyCollect('parentNode'); + return Element.recursivelyCollect(element, 'parentNode'); }, descendants: function(element) { - return $(element).select("*"); + return Element.select(element, "*"); }, firstDescendant: function(element) { @@ -1710,78 +2159,96 @@ Element.Methods = { }, immediateDescendants: function(element) { - if (!(element = $(element).firstChild)) return []; - while (element && element.nodeType != 1) element = element.nextSibling; - if (element) return [element].concat($(element).nextSiblings()); - return []; + var results = [], child = $(element).firstChild; + while (child) { + if (child.nodeType === 1) { + results.push(Element.extend(child)); + } + child = child.nextSibling; + } + return results; }, - previousSiblings: function(element) { - return $(element).recursivelyCollect('previousSibling'); + previousSiblings: function(element, maximumLength) { + return Element.recursivelyCollect(element, 'previousSibling'); }, nextSiblings: function(element) { - return $(element).recursivelyCollect('nextSibling'); + return Element.recursivelyCollect(element, 'nextSibling'); }, siblings: function(element) { element = $(element); - return element.previousSiblings().reverse().concat(element.nextSiblings()); + return Element.previousSiblings(element).reverse() + .concat(Element.nextSiblings(element)); }, match: function(element, selector) { + element = $(element); if (Object.isString(selector)) - selector = new Selector(selector); - return selector.match($(element)); + return Prototype.Selector.match(element, selector); + return selector.match(element); }, up: function(element, expression, index) { element = $(element); if (arguments.length == 1) return $(element.parentNode); - var ancestors = element.ancestors(); + var ancestors = Element.ancestors(element); return Object.isNumber(expression) ? ancestors[expression] : - Selector.findElement(ancestors, expression, index); + Prototype.Selector.find(ancestors, expression, index); }, down: function(element, expression, index) { element = $(element); - if (arguments.length == 1) return element.firstDescendant(); - return Object.isNumber(expression) ? element.descendants()[expression] : + if (arguments.length == 1) return Element.firstDescendant(element); + return Object.isNumber(expression) ? Element.descendants(element)[expression] : Element.select(element, expression)[index || 0]; }, previous: function(element, expression, index) { element = $(element); - if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); - var previousSiblings = element.previousSiblings(); - return Object.isNumber(expression) ? previousSiblings[expression] : - Selector.findElement(previousSiblings, expression, index); + if (Object.isNumber(expression)) index = expression, expression = false; + if (!Object.isNumber(index)) index = 0; + + if (expression) { + return Prototype.Selector.find(element.previousSiblings(), expression, index); + } else { + return element.recursivelyCollect("previousSibling", index + 1)[index]; + } }, next: function(element, expression, index) { element = $(element); - if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); - var nextSiblings = element.nextSiblings(); - return Object.isNumber(expression) ? nextSiblings[expression] : - Selector.findElement(nextSiblings, expression, index); + if (Object.isNumber(expression)) index = expression, expression = false; + if (!Object.isNumber(index)) index = 0; + + if (expression) { + return Prototype.Selector.find(element.nextSiblings(), expression, index); + } else { + var maximumLength = Object.isNumber(index) ? index + 1 : 1; + return element.recursivelyCollect("nextSibling", index + 1)[index]; + } }, - select: function() { - var args = $A(arguments), element = $(args.shift()); - return Selector.findChildElements(element, args); + + select: function(element) { + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element); }, - adjacent: function() { - var args = $A(arguments), element = $(args.shift()); - return Selector.findChildElements(element.parentNode, args).without(element); + adjacent: function(element) { + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element.parentNode).without(element); }, identify: function(element) { element = $(element); - var id = element.readAttribute('id'), self = arguments.callee; + var id = Element.readAttribute(element, 'id'); if (id) return id; - do { id = 'anonymous_element_' + self.counter++ } while ($(id)); - element.writeAttribute('id', id); + do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id)); + Element.writeAttribute(element, 'id', id); return id; }, @@ -1820,11 +2287,11 @@ Element.Methods = { }, getHeight: function(element) { - return $(element).getDimensions().height; + return Element.getDimensions(element).height; }, getWidth: function(element) { - return $(element).getDimensions().width; + return Element.getDimensions(element).width; }, classNames: function(element) { @@ -1840,7 +2307,7 @@ Element.Methods = { addClassName: function(element, className) { if (!(element = $(element))) return; - if (!element.hasClassName(className)) + if (!Element.hasClassName(element, className)) element.className += (element.className ? ' ' : '') + className; return element; }, @@ -1854,11 +2321,10 @@ Element.Methods = { toggleClassName: function(element, className) { if (!(element = $(element))) return; - return element[element.hasClassName(className) ? - 'removeClassName' : 'addClassName'](className); + return Element[Element.hasClassName(element, className) ? + 'removeClassName' : 'addClassName'](element, className); }, - // removes whitespace-only text node children cleanWhitespace: function(element) { element = $(element); var node = element.firstChild; @@ -1892,7 +2358,7 @@ Element.Methods = { scrollTo: function(element) { element = $(element); - var pos = element.cumulativeOffset(); + var pos = Element.cumulativeOffset(element); window.scrollTo(pos[0], pos[1]); return element; }, @@ -1938,37 +2404,12 @@ Element.Methods = { return element; }, - getDimensions: function(element) { - element = $(element); - var display = element.getStyle('display'); - if (display != 'none' && display != null) // Safari bug - return {width: element.offsetWidth, height: element.offsetHeight}; - - // All *Width and *Height properties give 0 on elements with display none, - // so enable the element temporarily - var els = element.style; - var originalVisibility = els.visibility; - var originalPosition = els.position; - var originalDisplay = els.display; - els.visibility = 'hidden'; - els.position = 'absolute'; - els.display = 'block'; - var originalWidth = element.clientWidth; - var originalHeight = element.clientHeight; - els.display = originalDisplay; - els.position = originalPosition; - els.visibility = originalVisibility; - return {width: originalWidth, height: originalHeight}; - }, - makePositioned: function(element) { element = $(element); var pos = Element.getStyle(element, 'position'); if (pos == 'static' || !pos) { element._madePositioned = true; element.style.position = 'relative'; - // Opera returns the offset relative to the positioning context, when an - // element is position relative but top and left have not been defined if (Prototype.Browser.Opera) { element.style.top = 0; element.style.left = 0; @@ -2007,119 +2448,6 @@ Element.Methods = { return element; }, - cumulativeOffset: function(element) { - var valueT = 0, valueL = 0; - do { - valueT += element.offsetTop || 0; - valueL += element.offsetLeft || 0; - element = element.offsetParent; - } while (element); - return Element._returnOffset(valueL, valueT); - }, - - positionedOffset: function(element) { - var valueT = 0, valueL = 0; - do { - valueT += element.offsetTop || 0; - valueL += element.offsetLeft || 0; - element = element.offsetParent; - if (element) { - if (element.tagName.toUpperCase() == 'BODY') break; - var p = Element.getStyle(element, 'position'); - if (p !== 'static') break; - } - } while (element); - return Element._returnOffset(valueL, valueT); - }, - - absolutize: function(element) { - element = $(element); - if (element.getStyle('position') == 'absolute') return element; - // Position.prepare(); // To be done manually by Scripty when it needs it. - - var offsets = element.positionedOffset(); - var top = offsets[1]; - var left = offsets[0]; - var width = element.clientWidth; - var height = element.clientHeight; - - element._originalLeft = left - parseFloat(element.style.left || 0); - element._originalTop = top - parseFloat(element.style.top || 0); - element._originalWidth = element.style.width; - element._originalHeight = element.style.height; - - element.style.position = 'absolute'; - element.style.top = top + 'px'; - element.style.left = left + 'px'; - element.style.width = width + 'px'; - element.style.height = height + 'px'; - return element; - }, - - relativize: function(element) { - element = $(element); - if (element.getStyle('position') == 'relative') return element; - // Position.prepare(); // To be done manually by Scripty when it needs it. - - element.style.position = 'relative'; - var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); - var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); - - element.style.top = top + 'px'; - element.style.left = left + 'px'; - element.style.height = element._originalHeight; - element.style.width = element._originalWidth; - return element; - }, - - cumulativeScrollOffset: function(element) { - var valueT = 0, valueL = 0; - do { - valueT += element.scrollTop || 0; - valueL += element.scrollLeft || 0; - element = element.parentNode; - } while (element); - return Element._returnOffset(valueL, valueT); - }, - - getOffsetParent: function(element) { - if (element.offsetParent) return $(element.offsetParent); - if (element == document.body) return $(element); - if(element.tagName.toUpperCase()=='HTML') //for IE6,7 - return $(document.body); // - - while ((element = element.parentNode) && element != document.body) - if (Element.getStyle(element, 'position') != 'static') - return $(element); - - return $(document.body); - }, - - viewportOffset: function(forElement) { - var valueT = 0, valueL = 0; - - var element = forElement; - do { - valueT += element.offsetTop || 0; - valueL += element.offsetLeft || 0; - - // Safari fix - if (element.offsetParent == document.body && - Element.getStyle(element, 'position') == 'absolute') break; - - } while (element = element.offsetParent); - - element = forElement; - do { - if (!Prototype.Browser.Opera || (element.tagName && (element.tagName.toUpperCase() == 'BODY'))) { - valueT -= element.scrollTop || 0; - valueL -= element.scrollLeft || 0; - } - } while (element = element.parentNode); - - return Element._returnOffset(valueL, valueT); - }, - clonePosition: function(element, source) { var options = Object.extend({ setLeft: true, @@ -2130,28 +2458,21 @@ Element.Methods = { offsetLeft: 0 }, arguments[2] || { }); - // find page position of source source = $(source); - var p = source.viewportOffset(); + var p = Element.viewportOffset(source), delta = [0, 0], parent = null; - // find coordinate system to use element = $(element); - var delta = [0, 0]; - var parent = null; - // delta [0,0] will do fine with position: fixed elements, - // position:absolute needs offsetParent deltas + if (Element.getStyle(element, 'position') == 'absolute') { - parent = element.getOffsetParent(); - delta = parent.viewportOffset(); + parent = Element.getOffsetParent(element); + delta = Element.viewportOffset(parent); } - // correct by body offsets (fixes Safari) if (parent == document.body) { delta[0] -= document.body.offsetLeft; delta[1] -= document.body.offsetTop; } - // set position if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px'; if (options.setWidth) element.style.width = source.offsetWidth + 'px'; @@ -2160,10 +2481,9 @@ Element.Methods = { } }; -Element.Methods.identify.counter = 1; - Object.extend(Element.Methods, { getElementsBySelector: Element.Methods.select, + childElements: Element.Methods.immediateDescendants }); @@ -2181,14 +2501,9 @@ if (Prototype.Browser.Opera) { Element.Methods.getStyle = Element.Methods.getStyle.wrap( function(proceed, element, style) { switch (style) { - case 'left': case 'top': case 'right': case 'bottom': - if (proceed(element, 'position') === 'static') return null; case 'height': case 'width': - // returns '0px' for hidden elements; we want it to return null if (!Element.visible(element)) return null; - // returns the border-box dimensions rather than the content-box - // dimensions, so we subtract padding and borders from the value var dim = parseInt(proceed(element, style), 10); if (dim !== element['offset' + style.capitalize()]) @@ -2221,52 +2536,6 @@ if (Prototype.Browser.Opera) { } else if (Prototype.Browser.IE) { - // IE doesn't report offsets correctly for static elements, so we change them - // to "relative" to get the values, then change them back. - Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap( - function(proceed, element) { - element = $(element); - // IE throws an error if element is not in document - try { element.offsetParent } - catch(e) { return $(document.body) } - var position = element.getStyle('position'); - if (position !== 'static') return proceed(element); - element.setStyle({ position: 'relative' }); - var value = proceed(element); - element.setStyle({ position: position }); - return value; - } - ); - - $w('positionedOffset viewportOffset').each(function(method) { - Element.Methods[method] = Element.Methods[method].wrap( - function(proceed, element) { - element = $(element); - try { element.offsetParent } - catch(e) { return Element._returnOffset(0,0) } - var position = element.getStyle('position'); - if (position !== 'static') return proceed(element); - // Trigger hasLayout on the offset parent so that IE6 reports - // accurate offsetTop and offsetLeft values for position: fixed. - var offsetParent = element.getOffsetParent(); - if (offsetParent && offsetParent.getStyle('position') === 'fixed') - offsetParent.setStyle({ zoom: 1 }); - element.setStyle({ position: 'relative' }); - var value = proceed(element); - element.setStyle({ position: position }); - return value; - } - ); - }); - - Element.Methods.cumulativeOffset = Element.Methods.cumulativeOffset.wrap( - function(proceed, element) { - try { element.offsetParent } - catch(e) { return Element._returnOffset(0,0) } - return proceed(element); - } - ); - Element.Methods.getStyle = function(element, style) { element = $(element); style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); @@ -2308,36 +2577,90 @@ else if (Prototype.Browser.IE) { return element; }; - Element._attributeTranslations = { - read: { - names: { - 'class': 'className', - 'for': 'htmlFor' - }, - values: { - _getAttr: function(element, attribute) { - return element.getAttribute(attribute, 2); - }, - _getAttrNode: function(element, attribute) { - var node = element.getAttributeNode(attribute); - return node ? node.value : ""; - }, - _getEv: function(element, attribute) { - attribute = element.getAttribute(attribute); - return attribute ? attribute.toString().slice(23, -2) : null; - }, - _flag: function(element, attribute) { - return $(element).hasAttribute(attribute) ? attribute : null; - }, - style: function(element) { - return element.style.cssText.toLowerCase(); + Element._attributeTranslations = (function(){ + + var classProp = 'className', + forProp = 'for', + el = document.createElement('div'); + + el.setAttribute(classProp, 'x'); + + if (el.className !== 'x') { + el.setAttribute('class', 'x'); + if (el.className === 'x') { + classProp = 'class'; + } + } + el = null; + + el = document.createElement('label'); + el.setAttribute(forProp, 'x'); + if (el.htmlFor !== 'x') { + el.setAttribute('htmlFor', 'x'); + if (el.htmlFor === 'x') { + forProp = 'htmlFor'; + } + } + el = null; + + return { + read: { + names: { + 'class': classProp, + 'className': classProp, + 'for': forProp, + 'htmlFor': forProp }, - title: function(element) { - return element.title; + values: { + _getAttr: function(element, attribute) { + return element.getAttribute(attribute); + }, + _getAttr2: function(element, attribute) { + return element.getAttribute(attribute, 2); + }, + _getAttrNode: function(element, attribute) { + var node = element.getAttributeNode(attribute); + return node ? node.value : ""; + }, + _getEv: (function(){ + + var el = document.createElement('div'), f; + el.onclick = Prototype.emptyFunction; + var value = el.getAttribute('onclick'); + + if (String(value).indexOf('{') > -1) { + f = function(element, attribute) { + attribute = element.getAttribute(attribute); + if (!attribute) return null; + attribute = attribute.toString(); + attribute = attribute.split('{')[1]; + attribute = attribute.split('}')[0]; + return attribute.strip(); + }; + } + else if (value === '') { + f = function(element, attribute) { + attribute = element.getAttribute(attribute); + if (!attribute) return null; + return attribute.strip(); + }; + } + el = null; + return f; + })(), + _flag: function(element, attribute) { + return $(element).hasAttribute(attribute) ? attribute : null; + }, + style: function(element) { + return element.style.cssText.toLowerCase(); + }, + title: function(element) { + return element.title; + } } } } - }; + })(); Element._attributeTranslations.write = { names: Object.extend({ @@ -2365,8 +2688,8 @@ else if (Prototype.Browser.IE) { (function(v) { Object.extend(v, { - href: v._getAttr, - src: v._getAttr, + href: v._getAttr2, + src: v._getAttr2, type: v._getAttr, action: v._getAttrNode, disabled: v._flag, @@ -2393,6 +2716,26 @@ else if (Prototype.Browser.IE) { onchange: v._getEv }); })(Element._attributeTranslations.read.values); + + if (Prototype.BrowserFeatures.ElementExtensions) { + (function() { + function _descendants(element) { + var nodes = element.getElementsByTagName('*'), results = []; + for (var i = 0, node; node = nodes[i]; i++) + if (node.tagName !== "!") // Filter out comment nodes. + results.push(node); + return results; + } + + Element.Methods.down = function(element, expression, index) { + element = $(element); + if (arguments.length == 1) return element.firstDescendant(); + return Object.isNumber(expression) ? _descendants(element)[expression] : + Element.select(element, expression)[index || 0]; + } + })(); + } + } else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) { @@ -2411,7 +2754,7 @@ else if (Prototype.Browser.WebKit) { (value < 0.00001) ? 0 : value; if (value == 1) - if(element.tagName.toUpperCase() == 'IMG' && element.width) { + if (element.tagName.toUpperCase() == 'IMG' && element.width) { element.width++; element.width--; } else try { var n = document.createTextNode(' '); @@ -2421,49 +2764,9 @@ else if (Prototype.Browser.WebKit) { return element; }; - - // Safari returns margins on body which is incorrect if the child is absolutely - // positioned. For performance reasons, redefine Element#cumulativeOffset for - // KHTML/WebKit only. - Element.Methods.cumulativeOffset = function(element) { - var valueT = 0, valueL = 0; - do { - valueT += element.offsetTop || 0; - valueL += element.offsetLeft || 0; - if (element.offsetParent == document.body) - if (Element.getStyle(element, 'position') == 'absolute') break; - - element = element.offsetParent; - } while (element); - - return Element._returnOffset(valueL, valueT); - }; -} - -if (Prototype.Browser.IE || Prototype.Browser.Opera) { - // IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements - Element.Methods.update = function(element, content) { - element = $(element); - - if (content && content.toElement) content = content.toElement(); - if (Object.isElement(content)) return element.update().insert(content); - - content = Object.toHTML(content); - var tagName = element.tagName.toUpperCase(); - - if (tagName in Element._insertionTranslations.tags) { - $A(element.childNodes).each(function(node) { element.removeChild(node) }); - Element._getContentFromAnonymousElement(tagName, content.stripScripts()) - .each(function(node) { element.appendChild(node) }); - } - else element.innerHTML = content.stripScripts(); - - content.evalScripts.bind(content).defer(); - return element; - }; } -if ('outerHTML' in document.createElement('div')) { +if ('outerHTML' in document.documentElement) { Element.Methods.replace = function(element, content) { element = $(element); @@ -2477,8 +2780,8 @@ if ('outerHTML' in document.createElement('div')) { var parent = element.parentNode, tagName = parent.tagName.toUpperCase(); if (Element._insertionTranslations.tags[tagName]) { - var nextSibling = element.next(); - var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); + var nextSibling = element.next(), + fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts()); parent.removeChild(element); if (nextSibling) fragments.each(function(node) { parent.insertBefore(node, nextSibling) }); @@ -2499,12 +2802,27 @@ Element._returnOffset = function(l, t) { return result; }; -Element._getContentFromAnonymousElement = function(tagName, html) { - var div = new Element('div'), t = Element._insertionTranslations.tags[tagName]; - if (t) { - div.innerHTML = t[0] + html + t[1]; - t[2].times(function() { div = div.firstChild }); - } else div.innerHTML = html; +Element._getContentFromAnonymousElement = function(tagName, html, force) { + var div = new Element('div'), + t = Element._insertionTranslations.tags[tagName]; + + var workaround = false; + if (t) workaround = true; + else if (force) { + workaround = true; + t = ['', '', 0]; + } + + if (workaround) { + div.innerHTML = ' ' + t[0] + html + t[1]; + div.removeChild(div.firstChild); + for (var i = t[2]; i--; ) { + div = div.firstChild; + } + } + else { + div.innerHTML = html; + } return $A(div.childNodes); }; @@ -2531,12 +2849,13 @@ Element._insertionTranslations = { }; (function() { - Object.extend(this.tags, { - THEAD: this.tags.TBODY, - TFOOT: this.tags.TBODY, - TH: this.tags.TD + var tags = Element._insertionTranslations.tags; + Object.extend(tags, { + THEAD: tags.TBODY, + TFOOT: tags.TBODY, + TH: tags.TD }); -}).call(Element._insertionTranslations); +})(); Element.Methods.Simulated = { hasAttribute: function(element, attribute) { @@ -2550,41 +2869,81 @@ Element.Methods.ByTag = { }; Object.extend(Element, Element.Methods); -if (!Prototype.BrowserFeatures.ElementExtensions && - document.createElement('div')['__proto__']) { - window.HTMLElement = { }; - window.HTMLElement.prototype = document.createElement('div')['__proto__']; - Prototype.BrowserFeatures.ElementExtensions = true; -} +(function(div) { + + if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) { + window.HTMLElement = { }; + window.HTMLElement.prototype = div['__proto__']; + Prototype.BrowserFeatures.ElementExtensions = true; + } + + div = null; + +})(document.createElement('div')); Element.extend = (function() { - if (Prototype.BrowserFeatures.SpecificElementExtensions) + + function checkDeficiency(tagName) { + if (typeof window.Element != 'undefined') { + var proto = window.Element.prototype; + if (proto) { + var id = '_' + (Math.random()+'').slice(2), + el = document.createElement(tagName); + proto[id] = 'x'; + var isBuggy = (el[id] !== 'x'); + delete proto[id]; + el = null; + return isBuggy; + } + } + return false; + } + + function extendElementWith(element, methods) { + for (var property in methods) { + var value = methods[property]; + if (Object.isFunction(value) && !(property in element)) + element[property] = value.methodize(); + } + } + + var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object'); + + if (Prototype.BrowserFeatures.SpecificElementExtensions) { + if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) { + return function(element) { + if (element && typeof element._extendedByPrototype == 'undefined') { + var t = element.tagName; + if (t && (/^(?:object|applet|embed)$/i.test(t))) { + extendElementWith(element, Element.Methods); + extendElementWith(element, Element.Methods.Simulated); + extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]); + } + } + return element; + } + } return Prototype.K; + } var Methods = { }, ByTag = Element.Methods.ByTag; var extend = Object.extend(function(element) { - if (!element || element._extendedByPrototype || + if (!element || typeof element._extendedByPrototype != 'undefined' || element.nodeType != 1 || element == window) return element; var methods = Object.clone(Methods), - tagName = element.tagName.toUpperCase(), property, value; + tagName = element.tagName.toUpperCase(); - // extend methods for specific tags if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]); - for (property in methods) { - value = methods[property]; - if (Object.isFunction(value) && !(property in element)) - element[property] = value.methodize(); - } + extendElementWith(element, methods); element._extendedByPrototype = Prototype.emptyFunction; return element; }, { refresh: function() { - // extend methods for all tags (Safari doesn't need this) if (!Prototype.BrowserFeatures.ElementExtensions) { Object.extend(Methods, Element.Methods); Object.extend(Methods, Element.Methods.Simulated); @@ -2596,10 +2955,14 @@ Element.extend = (function() { return extend; })(); -Element.hasAttribute = function(element, attribute) { - if (element.hasAttribute) return element.hasAttribute(attribute); - return Element.Methods.Simulated.hasAttribute(element, attribute); -}; +if (document.documentElement.hasAttribute) { + Element.hasAttribute = function(element, attribute) { + return element.hasAttribute(attribute); + }; +} +else { + Element.hasAttribute = Element.Methods.Simulated.hasAttribute; +} Element.addMethods = function(methods) { var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag; @@ -2611,7 +2974,8 @@ Element.addMethods = function(methods) { "FORM": Object.clone(Form.Methods), "INPUT": Object.clone(Form.Element.Methods), "SELECT": Object.clone(Form.Element.Methods), - "TEXTAREA": Object.clone(Form.Element.Methods) + "TEXTAREA": Object.clone(Form.Element.Methods), + "BUTTON": Object.clone(Form.Element.Methods) }); } @@ -2663,14 +3027,19 @@ Element.addMethods = function(methods) { klass = 'HTML' + tagName.capitalize() + 'Element'; if (window[klass]) return window[klass]; - window[klass] = { }; - window[klass].prototype = document.createElement(tagName)['__proto__']; - return window[klass]; + var element = document.createElement(tagName), + proto = element['__proto__'] || element.constructor.prototype; + + element = null; + return proto; } + var elementPrototype = window.HTMLElement ? HTMLElement.prototype : + Element.prototype; + if (F.ElementExtensions) { - copy(Element.Methods, HTMLElement.prototype); - copy(Element.Methods.Simulated, HTMLElement.prototype, true); + copy(Element.Methods, elementPrototype); + copy(Element.Methods.Simulated, elementPrototype, true); } if (F.SpecificElementExtensions) { @@ -2688,791 +3057,1947 @@ Element.addMethods = function(methods) { Element.cache = { }; }; + document.viewport = { + getDimensions: function() { - var dimensions = { }, B = Prototype.Browser; - $w('width height').each(function(d) { - var D = d.capitalize(); - if (B.WebKit && !document.evaluate) { - // Safari <3.0 needs self.innerWidth/Height - dimensions[d] = self['inner' + D]; - } else if (B.Opera && parseFloat(window.opera.version()) < 9.5) { - // Opera <9.5 needs document.body.clientWidth/Height - dimensions[d] = document.body['client' + D] - } else { - dimensions[d] = document.documentElement['client' + D]; - } - }); - return dimensions; - }, - - getWidth: function() { - return this.getDimensions().width; - }, - - getHeight: function() { - return this.getDimensions().height; + return { width: this.getWidth(), height: this.getHeight() }; }, getScrollOffsets: function() { return Element._returnOffset( window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, - window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); + window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); } }; -/* Portions of the Selector class are derived from Jack Slocum's DomQuery, - * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style - * license. Please see http://www.yui-ext.com/ for more information. */ - -var Selector = Class.create({ - initialize: function(expression) { - this.expression = expression.strip(); - - if (this.shouldUseSelectorsAPI()) { - this.mode = 'selectorsAPI'; - } else if (this.shouldUseXPath()) { - this.mode = 'xpath'; - this.compileXPathMatcher(); - } else { - this.mode = "normal"; - this.compileMatcher(); - } - }, +(function(viewport) { + var B = Prototype.Browser, doc = document, element, property = {}; - shouldUseXPath: function() { - if (!Prototype.BrowserFeatures.XPath) return false; + function getRootElement() { + if (B.WebKit && !doc.evaluate) + return document; - var e = this.expression; + if (B.Opera && window.parseFloat(window.opera.version()) < 9.5) + return document.body; - // Safari 3 chokes on :*-of-type and :empty - if (Prototype.Browser.WebKit && - (e.include("-of-type") || e.include(":empty"))) - return false; + return document.documentElement; + } - // XPath can't do namespaced attributes, nor can it read - // the "checked" property from DOM nodes - if ((/(\[[\w-]*?:|:checked)/).test(e)) - return false; + function define(D) { + if (!element) element = getRootElement(); - return true; - }, + property[D] = 'client' + D; - shouldUseSelectorsAPI: function() { - if (!Prototype.BrowserFeatures.SelectorsAPI) return false; + viewport['get' + D] = function() { return element[property[D]] }; + return viewport['get' + D](); + } - if (!Selector._div) Selector._div = new Element('div'); + viewport.getWidth = define.curry('Width'); - // Make sure the browser treats the selector as valid. Test on an - // isolated element to minimize cost of this check. - try { - Selector._div.querySelector(this.expression); - } catch(e) { - return false; + viewport.getHeight = define.curry('Height'); +})(document.viewport); + + +Element.Storage = { + UID: 1 +}; + +Element.addMethods({ + getStorage: function(element) { + if (!(element = $(element))) return; + + var uid; + if (element === window) { + uid = 0; + } else { + if (typeof element._prototypeUID === "undefined") + element._prototypeUID = Element.Storage.UID++; + uid = element._prototypeUID; } - return true; + if (!Element.Storage[uid]) + Element.Storage[uid] = $H(); + + return Element.Storage[uid]; }, - compileMatcher: function() { - var e = this.expression, ps = Selector.patterns, h = Selector.handlers, - c = Selector.criteria, le, p, m; + store: function(element, key, value) { + if (!(element = $(element))) return; + + if (arguments.length === 2) { + Element.getStorage(element).update(key); + } else { + Element.getStorage(element).set(key, value); + } - if (Selector._cache[e]) { - this.matcher = Selector._cache[e]; - return; + return element; + }, + + retrieve: function(element, key, defaultValue) { + if (!(element = $(element))) return; + var hash = Element.getStorage(element), value = hash.get(key); + + if (Object.isUndefined(value)) { + hash.set(key, defaultValue); + value = defaultValue; } - this.matcher = ["this.matcher = function(root) {", - "var r = root, h = Selector.handlers, c = false, n;"]; + return value; + }, - while (e && le != e && (/\S/).test(e)) { - le = e; - for (var i in ps) { - p = ps[i]; - if (m = e.match(p)) { - this.matcher.push(Object.isFunction(c[i]) ? c[i](m) : - new Template(c[i]).evaluate(m)); - e = e.replace(m[0], ''); - break; - } + clone: function(element, deep) { + if (!(element = $(element))) return; + var clone = element.cloneNode(deep); + clone._prototypeUID = void 0; + if (deep) { + var descendants = Element.select(clone, '*'), + i = descendants.length; + while (i--) { + descendants[i]._prototypeUID = void 0; } } - - this.matcher.push("return h.unique(n);\n}"); - eval(this.matcher.join('\n')); - Selector._cache[this.expression] = this.matcher; + return Element.extend(clone); }, - compileXPathMatcher: function() { - var e = this.expression, ps = Selector.patterns, - x = Selector.xpath, le, m; + purge: function(element) { + if (!(element = $(element))) return; + var purgeElement = Element._purgeElement; + + purgeElement(element); + + var descendants = element.getElementsByTagName('*'), + i = descendants.length; + + while (i--) purgeElement(descendants[i]); + + return null; + } +}); + +(function() { - if (Selector._cache[e]) { - this.xpath = Selector._cache[e]; return; + function toDecimal(pctString) { + var match = pctString.match(/^(\d+)%?$/i); + if (!match) return null; + return (Number(match[1]) / 100); + } + + function getPixelValue(value, property, context) { + var element = null; + if (Object.isElement(value)) { + element = value; + value = element.getStyle(property); } - this.matcher = ['.//*']; - while (e && le != e && (/\S/).test(e)) { - le = e; - for (var i in ps) { - if (m = e.match(ps[i])) { - this.matcher.push(Object.isFunction(x[i]) ? x[i](m) : - new Template(x[i]).evaluate(m)); - e = e.replace(m[0], ''); - break; - } - } + if (value === null) { + return null; } - this.xpath = this.matcher.join(''); - Selector._cache[this.expression] = this.xpath; - }, + if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) { + return window.parseFloat(value); + } - findElements: function(root) { - root = root || document; - var e = this.expression, results; - - switch (this.mode) { - case 'selectorsAPI': - // querySelectorAll queries document-wide, then filters to descendants - // of the context element. That's not what we want. - // Add an explicit context to the selector if necessary. - if (root !== document) { - var oldId = root.id, id = $(root).identify(); - e = "#" + id + " " + e; - } + var isPercentage = value.include('%'), isViewport = (context === document.viewport); - results = $A(root.querySelectorAll(e)).map(Element.extend); - root.id = oldId; + if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) { + var style = element.style.left, rStyle = element.runtimeStyle.left; + element.runtimeStyle.left = element.currentStyle.left; + element.style.left = value || 0; + value = element.style.pixelLeft; + element.style.left = style; + element.runtimeStyle.left = rStyle; - return results; - case 'xpath': - return document._getElementsByXPath(this.xpath, root); - default: - return this.matcher(root); + return value; } - }, - match: function(element) { - this.tokens = []; - - var e = this.expression, ps = Selector.patterns, as = Selector.assertions; - var le, p, m; - - while (e && le !== e && (/\S/).test(e)) { - le = e; - for (var i in ps) { - p = ps[i]; - if (m = e.match(p)) { - // use the Selector.assertions methods unless the selector - // is too complex. - if (as[i]) { - this.tokens.push([i, Object.clone(m)]); - e = e.replace(m[0], ''); - } else { - // reluctantly do a document-wide search - // and look for a match in the array - return this.findElements(document).include(element); - } + if (element && isPercentage) { + context = context || element.parentNode; + var decimal = toDecimal(value); + var whole = null; + var position = element.getStyle('position'); + + var isHorizontal = property.include('left') || property.include('right') || + property.include('width'); + + var isVertical = property.include('top') || property.include('bottom') || + property.include('height'); + + if (context === document.viewport) { + if (isHorizontal) { + whole = document.viewport.getWidth(); + } else if (isVertical) { + whole = document.viewport.getHeight(); + } + } else { + if (isHorizontal) { + whole = $(context).measure('width'); + } else if (isVertical) { + whole = $(context).measure('height'); } } + + return (whole === null) ? 0 : whole * decimal; } - var match = true, name, matches; - for (var i = 0, token; token = this.tokens[i]; i++) { - name = token[0], matches = token[1]; - if (!Selector.assertions[name](element, matches)) { - match = false; break; - } + return 0; + } + + function toCSSPixels(number) { + if (Object.isString(number) && number.endsWith('px')) { + return number; } + return number + 'px'; + } - return match; - }, + function isDisplayed(element) { + var originalElement = element; + while (element && element.parentNode) { + var display = element.getStyle('display'); + if (display === 'none') { + return false; + } + element = $(element.parentNode); + } + return true; + } - toString: function() { - return this.expression; - }, + var hasLayout = Prototype.K; + if ('currentStyle' in document.documentElement) { + hasLayout = function(element) { + if (!element.currentStyle.hasLayout) { + element.style.zoom = 1; + } + return element; + }; + } - inspect: function() { - return "#"; + function cssNameFor(key) { + if (key.include('border')) key = key + '-width'; + return key.camelize(); } -}); -Object.extend(Selector, { - _cache: { }, - - xpath: { - descendant: "//*", - child: "/*", - adjacent: "/following-sibling::*[1]", - laterSibling: '/following-sibling::*', - tagName: function(m) { - if (m[1] == '*') return ''; - return "[local-name()='" + m[1].toLowerCase() + - "' or local-name()='" + m[1].toUpperCase() + "']"; + Element.Layout = Class.create(Hash, { + initialize: function($super, element, preCompute) { + $super(); + this.element = $(element); + + Element.Layout.PROPERTIES.each( function(property) { + this._set(property, null); + }, this); + + if (preCompute) { + this._preComputing = true; + this._begin(); + Element.Layout.PROPERTIES.each( this._compute, this ); + this._end(); + this._preComputing = false; + } + }, + + _set: function(property, value) { + return Hash.prototype.set.call(this, property, value); + }, + + set: function(property, value) { + throw "Properties of Element.Layout are read-only."; + }, + + get: function($super, property) { + var value = $super(property); + return value === null ? this._compute(property) : value; + }, + + _begin: function() { + if (this._prepared) return; + + var element = this.element; + if (isDisplayed(element)) { + this._prepared = true; + return; + } + + var originalStyles = { + position: element.style.position || '', + width: element.style.width || '', + visibility: element.style.visibility || '', + display: element.style.display || '' + }; + + element.store('prototype_original_styles', originalStyles); + + var position = element.getStyle('position'), + width = element.getStyle('width'); + + if (width === "0px" || width === null) { + element.style.display = 'block'; + width = element.getStyle('width'); + } + + var context = (position === 'fixed') ? document.viewport : + element.parentNode; + + element.setStyle({ + position: 'absolute', + visibility: 'hidden', + display: 'block' + }); + + var positionedWidth = element.getStyle('width'); + + var newWidth; + if (width && (positionedWidth === width)) { + newWidth = getPixelValue(element, 'width', context); + } else if (position === 'absolute' || position === 'fixed') { + newWidth = getPixelValue(element, 'width', context); + } else { + var parent = element.parentNode, pLayout = $(parent).getLayout(); + + newWidth = pLayout.get('width') - + this.get('margin-left') - + this.get('border-left') - + this.get('padding-left') - + this.get('padding-right') - + this.get('border-right') - + this.get('margin-right'); + } + + element.setStyle({ width: newWidth + 'px' }); + + this._prepared = true; }, - className: "[contains(concat(' ', @class, ' '), ' #{1} ')]", - id: "[@id='#{1}']", - attrPresence: function(m) { - m[1] = m[1].toLowerCase(); - return new Template("[@#{1}]").evaluate(m); + + _end: function() { + var element = this.element; + var originalStyles = element.retrieve('prototype_original_styles'); + element.store('prototype_original_styles', null); + element.setStyle(originalStyles); + this._prepared = false; }, - attr: function(m) { - m[1] = m[1].toLowerCase(); - m[3] = m[5] || m[6]; - return new Template(Selector.xpath.operators[m[2]]).evaluate(m); + + _compute: function(property) { + var COMPUTATIONS = Element.Layout.COMPUTATIONS; + if (!(property in COMPUTATIONS)) { + throw "Property not found."; + } + + return this._set(property, COMPUTATIONS[property].call(this, this.element)); }, - pseudo: function(m) { - var h = Selector.xpath.pseudos[m[1]]; - if (!h) return ''; - if (Object.isFunction(h)) return h(m); - return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m); + + toObject: function() { + var args = $A(arguments); + var keys = (args.length === 0) ? Element.Layout.PROPERTIES : + args.join(' ').split(' '); + var obj = {}; + keys.each( function(key) { + if (!Element.Layout.PROPERTIES.include(key)) return; + var value = this.get(key); + if (value != null) obj[key] = value; + }, this); + return obj; }, - operators: { - '=': "[@#{1}='#{3}']", - '!=': "[@#{1}!='#{3}']", - '^=': "[starts-with(@#{1}, '#{3}')]", - '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']", - '*=': "[contains(@#{1}, '#{3}')]", - '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]", - '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]" + + toHash: function() { + var obj = this.toObject.apply(this, arguments); + return new Hash(obj); }, - pseudos: { - 'first-child': '[not(preceding-sibling::*)]', - 'last-child': '[not(following-sibling::*)]', - 'only-child': '[not(preceding-sibling::* or following-sibling::*)]', - 'empty': "[count(*) = 0 and (count(text()) = 0)]", - 'checked': "[@checked]", - 'disabled': "[(@disabled) and (@type!='hidden')]", - 'enabled': "[not(@disabled) and (@type!='hidden')]", - 'not': function(m) { - var e = m[6], p = Selector.patterns, - x = Selector.xpath, le, v; - - var exclusion = []; - while (e && le != e && (/\S/).test(e)) { - le = e; - for (var i in p) { - if (m = e.match(p[i])) { - v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m); - exclusion.push("(" + v.substring(1, v.length - 1) + ")"); - e = e.replace(m[0], ''); - break; - } - } + + toCSS: function() { + var args = $A(arguments); + var keys = (args.length === 0) ? Element.Layout.PROPERTIES : + args.join(' ').split(' '); + var css = {}; + + keys.each( function(key) { + if (!Element.Layout.PROPERTIES.include(key)) return; + if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return; + + var value = this.get(key); + if (value != null) css[cssNameFor(key)] = value + 'px'; + }, this); + return css; + }, + + inspect: function() { + return "#"; + } + }); + + Object.extend(Element.Layout, { + PROPERTIES: $w('height width top left right bottom border-left border-right border-top border-bottom padding-left padding-right padding-top padding-bottom margin-top margin-bottom margin-left margin-right padding-box-width padding-box-height border-box-width border-box-height margin-box-width margin-box-height'), + + COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'), + + COMPUTATIONS: { + 'height': function(element) { + if (!this._preComputing) this._begin(); + + var bHeight = this.get('border-box-height'); + if (bHeight <= 0) { + if (!this._preComputing) this._end(); + return 0; + } + + var bTop = this.get('border-top'), + bBottom = this.get('border-bottom'); + + var pTop = this.get('padding-top'), + pBottom = this.get('padding-bottom'); + + if (!this._preComputing) this._end(); + + return bHeight - bTop - bBottom - pTop - pBottom; + }, + + 'width': function(element) { + if (!this._preComputing) this._begin(); + + var bWidth = this.get('border-box-width'); + if (bWidth <= 0) { + if (!this._preComputing) this._end(); + return 0; } - return "[not(" + exclusion.join(" and ") + ")]"; + + var bLeft = this.get('border-left'), + bRight = this.get('border-right'); + + var pLeft = this.get('padding-left'), + pRight = this.get('padding-right'); + + if (!this._preComputing) this._end(); + + return bWidth - bLeft - bRight - pLeft - pRight; + }, + + 'padding-box-height': function(element) { + var height = this.get('height'), + pTop = this.get('padding-top'), + pBottom = this.get('padding-bottom'); + + return height + pTop + pBottom; + }, + + 'padding-box-width': function(element) { + var width = this.get('width'), + pLeft = this.get('padding-left'), + pRight = this.get('padding-right'); + + return width + pLeft + pRight; + }, + + 'border-box-height': function(element) { + if (!this._preComputing) this._begin(); + var height = element.offsetHeight; + if (!this._preComputing) this._end(); + return height; + }, + + 'border-box-width': function(element) { + if (!this._preComputing) this._begin(); + var width = element.offsetWidth; + if (!this._preComputing) this._end(); + return width; + }, + + 'margin-box-height': function(element) { + var bHeight = this.get('border-box-height'), + mTop = this.get('margin-top'), + mBottom = this.get('margin-bottom'); + + if (bHeight <= 0) return 0; + + return bHeight + mTop + mBottom; + }, + + 'margin-box-width': function(element) { + var bWidth = this.get('border-box-width'), + mLeft = this.get('margin-left'), + mRight = this.get('margin-right'); + + if (bWidth <= 0) return 0; + + return bWidth + mLeft + mRight; + }, + + 'top': function(element) { + var offset = element.positionedOffset(); + return offset.top; + }, + + 'bottom': function(element) { + var offset = element.positionedOffset(), + parent = element.getOffsetParent(), + pHeight = parent.measure('height'); + + var mHeight = this.get('border-box-height'); + + return pHeight - mHeight - offset.top; + }, + + 'left': function(element) { + var offset = element.positionedOffset(); + return offset.left; + }, + + 'right': function(element) { + var offset = element.positionedOffset(), + parent = element.getOffsetParent(), + pWidth = parent.measure('width'); + + var mWidth = this.get('border-box-width'); + + return pWidth - mWidth - offset.left; + }, + + 'padding-top': function(element) { + return getPixelValue(element, 'paddingTop'); + }, + + 'padding-bottom': function(element) { + return getPixelValue(element, 'paddingBottom'); }, - 'nth-child': function(m) { - return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m); + + 'padding-left': function(element) { + return getPixelValue(element, 'paddingLeft'); }, - 'nth-last-child': function(m) { - return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m); + + 'padding-right': function(element) { + return getPixelValue(element, 'paddingRight'); }, - 'nth-of-type': function(m) { - return Selector.xpath.pseudos.nth("position() ", m); + + 'border-top': function(element) { + return getPixelValue(element, 'borderTopWidth'); }, - 'nth-last-of-type': function(m) { - return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m); + + 'border-bottom': function(element) { + return getPixelValue(element, 'borderBottomWidth'); }, - 'first-of-type': function(m) { - m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m); + + 'border-left': function(element) { + return getPixelValue(element, 'borderLeftWidth'); }, - 'last-of-type': function(m) { - m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m); + + 'border-right': function(element) { + return getPixelValue(element, 'borderRightWidth'); }, - 'only-of-type': function(m) { - var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m); + + 'margin-top': function(element) { + return getPixelValue(element, 'marginTop'); }, - nth: function(fragment, m) { - var mm, formula = m[6], predicate; - if (formula == 'even') formula = '2n+0'; - if (formula == 'odd') formula = '2n+1'; - if (mm = formula.match(/^(\d+)$/)) // digit only - return '[' + fragment + "= " + mm[1] + ']'; - if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b - if (mm[1] == "-") mm[1] = -1; - var a = mm[1] ? Number(mm[1]) : 1; - var b = mm[2] ? Number(mm[2]) : 0; - predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " + - "((#{fragment} - #{b}) div #{a} >= 0)]"; - return new Template(predicate).evaluate({ - fragment: fragment, a: a, b: b }); - } + + 'margin-bottom': function(element) { + return getPixelValue(element, 'marginBottom'); + }, + + 'margin-left': function(element) { + return getPixelValue(element, 'marginLeft'); + }, + + 'margin-right': function(element) { + return getPixelValue(element, 'marginRight'); } } - }, + }); - criteria: { - tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', - className: 'n = h.className(n, r, "#{1}", c); c = false;', - id: 'n = h.id(n, r, "#{1}", c); c = false;', - attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;', - attr: function(m) { - m[3] = (m[5] || m[6]); - return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m); - }, - pseudo: function(m) { - if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); - return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m); - }, - descendant: 'c = "descendant";', - child: 'c = "child";', - adjacent: 'c = "adjacent";', - laterSibling: 'c = "laterSibling";' - }, + if ('getBoundingClientRect' in document.documentElement) { + Object.extend(Element.Layout.COMPUTATIONS, { + 'right': function(element) { + var parent = hasLayout(element.getOffsetParent()); + var rect = element.getBoundingClientRect(), + pRect = parent.getBoundingClientRect(); - patterns: { - // combinators must be listed first - // (and descendant needs to be last combinator) - laterSibling: /^\s*~\s*/, - child: /^\s*>\s*/, - adjacent: /^\s*\+\s*/, - descendant: /^\s/, - - // selectors follow - tagName: /^\s*(\*|[\w\-]+)(\b|$)?/, - id: /^#([\w\-\*]+)(\b|$)/, - className: /^\.([\w\-\*]+)(\b|$)/, - pseudo: -/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/, - attrPresence: /^\[((?:[\w]+:)?[\w]+)\]/, - attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ - }, + return (pRect.right - rect.right).round(); + }, + + 'bottom': function(element) { + var parent = hasLayout(element.getOffsetParent()); + var rect = element.getBoundingClientRect(), + pRect = parent.getBoundingClientRect(); + + return (pRect.bottom - rect.bottom).round(); + } + }); + } - // for Selector.match and Element#match - assertions: { - tagName: function(element, matches) { - return matches[1].toUpperCase() == element.tagName.toUpperCase(); + Element.Offset = Class.create({ + initialize: function(left, top) { + this.left = left.round(); + this.top = top.round(); + + this[0] = this.left; + this[1] = this.top; }, - className: function(element, matches) { - return Element.hasClassName(element, matches[1]); + relativeTo: function(offset) { + return new Element.Offset( + this.left - offset.left, + this.top - offset.top + ); }, - id: function(element, matches) { - return element.id === matches[1]; + inspect: function() { + return "#".interpolate(this); }, - attrPresence: function(element, matches) { - return Element.hasAttribute(element, matches[1]); + toString: function() { + return "[#{left}, #{top}]".interpolate(this); }, - attr: function(element, matches) { - var nodeValue = Element.readAttribute(element, matches[1]); - return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]); + toArray: function() { + return [this.left, this.top]; } - }, + }); - handlers: { - // UTILITY FUNCTIONS - // joins two collections - concat: function(a, b) { - for (var i = 0, node; node = b[i]; i++) - a.push(node); - return a; - }, + function getLayout(element, preCompute) { + return new Element.Layout(element, preCompute); + } - // marks an array of nodes for counting - mark: function(nodes) { - var _true = Prototype.emptyFunction; - for (var i = 0, node; node = nodes[i]; i++) - node._countedByPrototype = _true; - return nodes; - }, + function measure(element, property) { + return $(element).getLayout().get(property); + } - unmark: function(nodes) { - for (var i = 0, node; node = nodes[i]; i++) - node._countedByPrototype = undefined; - return nodes; - }, + function getDimensions(element) { + element = $(element); + var display = Element.getStyle(element, 'display'); - // mark each child node with its position (for nth calls) - // "ofType" flag indicates whether we're indexing for nth-of-type - // rather than nth-child - index: function(parentNode, reverse, ofType) { - parentNode._countedByPrototype = Prototype.emptyFunction; - if (reverse) { - for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { - var node = nodes[i]; - if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++; - } - } else { - for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) - if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++; - } - }, + if (display && display !== 'none') { + return { width: element.offsetWidth, height: element.offsetHeight }; + } - // filters out duplicates and extends all nodes - unique: function(nodes) { - if (nodes.length == 0) return nodes; - var results = [], n; - for (var i = 0, l = nodes.length; i < l; i++) - if (!(n = nodes[i])._countedByPrototype) { - n._countedByPrototype = Prototype.emptyFunction; - results.push(Element.extend(n)); - } - return Selector.handlers.unmark(results); - }, + var style = element.style; + var originalStyles = { + visibility: style.visibility, + position: style.position, + display: style.display + }; - // COMBINATOR FUNCTIONS - descendant: function(nodes) { - var h = Selector.handlers; - for (var i = 0, results = [], node; node = nodes[i]; i++) - h.concat(results, node.getElementsByTagName('*')); - return results; - }, + var newStyles = { + visibility: 'hidden', + display: 'block' + }; - child: function(nodes) { - var h = Selector.handlers; - for (var i = 0, results = [], node; node = nodes[i]; i++) { - for (var j = 0, child; child = node.childNodes[j]; j++) - if (child.nodeType == 1 && child.tagName != '!') results.push(child); - } - return results; - }, + if (originalStyles.position !== 'fixed') + newStyles.position = 'absolute'; - adjacent: function(nodes) { - for (var i = 0, results = [], node; node = nodes[i]; i++) { - var next = this.nextElementSibling(node); - if (next) results.push(next); - } - return results; - }, + Element.setStyle(element, newStyles); - laterSibling: function(nodes) { - var h = Selector.handlers; - for (var i = 0, results = [], node; node = nodes[i]; i++) - h.concat(results, Element.nextSiblings(node)); - return results; - }, + var dimensions = { + width: element.offsetWidth, + height: element.offsetHeight + }; - nextElementSibling: function(node) { - while (node = node.nextSibling) - if (node.nodeType == 1) return node; - return null; - }, + Element.setStyle(element, originalStyles); - previousElementSibling: function(node) { - while (node = node.previousSibling) - if (node.nodeType == 1) return node; - return null; - }, + return dimensions; + } - // TOKEN FUNCTIONS - tagName: function(nodes, root, tagName, combinator) { - var uTagName = tagName.toUpperCase(); - var results = [], h = Selector.handlers; - if (nodes) { - if (combinator) { - // fastlane for ordinary descendant combinators - if (combinator == "descendant") { - for (var i = 0, node; node = nodes[i]; i++) - h.concat(results, node.getElementsByTagName(tagName)); - return results; - } else nodes = this[combinator](nodes); - if (tagName == "*") return nodes; - } - for (var i = 0, node; node = nodes[i]; i++) - if (node.tagName.toUpperCase() === uTagName) results.push(node); - return results; - } else return root.getElementsByTagName(tagName); - }, + function getOffsetParent(element) { + element = $(element); - id: function(nodes, root, id, combinator) { - var targetNode = $(id), h = Selector.handlers; - if (!targetNode) return []; - if (!nodes && root == document) return [targetNode]; - if (nodes) { - if (combinator) { - if (combinator == 'child') { - for (var i = 0, node; node = nodes[i]; i++) - if (targetNode.parentNode == node) return [targetNode]; - } else if (combinator == 'descendant') { - for (var i = 0, node; node = nodes[i]; i++) - if (Element.descendantOf(targetNode, node)) return [targetNode]; - } else if (combinator == 'adjacent') { - for (var i = 0, node; node = nodes[i]; i++) - if (Selector.handlers.previousElementSibling(targetNode) == node) - return [targetNode]; - } else nodes = h[combinator](nodes); - } - for (var i = 0, node; node = nodes[i]; i++) - if (node == targetNode) return [targetNode]; - return []; - } - return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : []; - }, + if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element)) + return $(document.body); - className: function(nodes, root, className, combinator) { - if (nodes && combinator) nodes = this[combinator](nodes); - return Selector.handlers.byClassName(nodes, root, className); - }, + var isInline = (Element.getStyle(element, 'display') === 'inline'); + if (!isInline && element.offsetParent) return $(element.offsetParent); - byClassName: function(nodes, root, className) { - if (!nodes) nodes = Selector.handlers.descendant([root]); - var needle = ' ' + className + ' '; - for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) { - nodeClassName = node.className; - if (nodeClassName.length == 0) continue; - if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle)) - results.push(node); + while ((element = element.parentNode) && element !== document.body) { + if (Element.getStyle(element, 'position') !== 'static') { + return isHtml(element) ? $(document.body) : $(element); } - return results; - }, + } - attrPresence: function(nodes, root, attr, combinator) { - if (!nodes) nodes = root.getElementsByTagName("*"); - if (nodes && combinator) nodes = this[combinator](nodes); - var results = []; - for (var i = 0, node; node = nodes[i]; i++) - if (Element.hasAttribute(node, attr)) results.push(node); - return results; - }, + return $(document.body); + } - attr: function(nodes, root, attr, value, operator, combinator) { - if (!nodes) nodes = root.getElementsByTagName("*"); - if (nodes && combinator) nodes = this[combinator](nodes); - var handler = Selector.operators[operator], results = []; - for (var i = 0, node; node = nodes[i]; i++) { - var nodeValue = Element.readAttribute(node, attr); - if (nodeValue === null) continue; - if (handler(nodeValue, value)) results.push(node); - } - return results; - }, - pseudo: function(nodes, name, value, root, combinator) { - if (nodes && combinator) nodes = this[combinator](nodes); - if (!nodes) nodes = root.getElementsByTagName("*"); - return Selector.pseudos[name](nodes, value, root); + function cumulativeOffset(element) { + element = $(element); + var valueT = 0, valueL = 0; + if (element.parentNode) { + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + } while (element); } - }, + return new Element.Offset(valueL, valueT); + } - pseudos: { - 'first-child': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) { - if (Selector.handlers.previousElementSibling(node)) continue; - results.push(node); - } - return results; - }, - 'last-child': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) { - if (Selector.handlers.nextElementSibling(node)) continue; - results.push(node); - } - return results; - }, - 'only-child': function(nodes, value, root) { - var h = Selector.handlers; - for (var i = 0, results = [], node; node = nodes[i]; i++) - if (!h.previousElementSibling(node) && !h.nextElementSibling(node)) - results.push(node); - return results; - }, - 'nth-child': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, formula, root); - }, - 'nth-last-child': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, formula, root, true); - }, - 'nth-of-type': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, formula, root, false, true); - }, - 'nth-last-of-type': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, formula, root, true, true); - }, - 'first-of-type': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, "1", root, false, true); - }, - 'last-of-type': function(nodes, formula, root) { - return Selector.pseudos.nth(nodes, "1", root, true, true); - }, - 'only-of-type': function(nodes, formula, root) { - var p = Selector.pseudos; - return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root); - }, + function positionedOffset(element) { + element = $(element); - // handles the an+b logic - getIndices: function(a, b, total) { - if (a == 0) return b > 0 ? [b] : []; - return $R(1, total).inject([], function(memo, i) { - if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i); - return memo; - }); - }, + var layout = element.getLayout(); - // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type - nth: function(nodes, formula, root, reverse, ofType) { - if (nodes.length == 0) return []; - if (formula == 'even') formula = '2n+0'; - if (formula == 'odd') formula = '2n+1'; - var h = Selector.handlers, results = [], indexed = [], m; - h.mark(nodes); - for (var i = 0, node; node = nodes[i]; i++) { - if (!node.parentNode._countedByPrototype) { - h.index(node.parentNode, reverse, ofType); - indexed.push(node.parentNode); - } - } - if (formula.match(/^\d+$/)) { // just a number - formula = Number(formula); - for (var i = 0, node; node = nodes[i]; i++) - if (node.nodeIndex == formula) results.push(node); - } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b - if (m[1] == "-") m[1] = -1; - var a = m[1] ? Number(m[1]) : 1; - var b = m[2] ? Number(m[2]) : 0; - var indices = Selector.pseudos.getIndices(a, b, nodes.length); - for (var i = 0, node, l = indices.length; node = nodes[i]; i++) { - for (var j = 0; j < l; j++) - if (node.nodeIndex == indices[j]) results.push(node); - } + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + element = element.offsetParent; + if (element) { + if (isBody(element)) break; + var p = Element.getStyle(element, 'position'); + if (p !== 'static') break; } - h.unmark(nodes); - h.unmark(indexed); - return results; - }, + } while (element); + + valueL -= layout.get('margin-top'); + valueT -= layout.get('margin-left'); + + return new Element.Offset(valueL, valueT); + } + + function cumulativeScrollOffset(element) { + var valueT = 0, valueL = 0; + do { + valueT += element.scrollTop || 0; + valueL += element.scrollLeft || 0; + element = element.parentNode; + } while (element); + return new Element.Offset(valueL, valueT); + } + + function viewportOffset(forElement) { + element = $(element); + var valueT = 0, valueL = 0, docBody = document.body; + + var element = forElement; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + if (element.offsetParent == docBody && + Element.getStyle(element, 'position') == 'absolute') break; + } while (element = element.offsetParent); - 'empty': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) { - // IE treats comments as element nodes - if (node.tagName == '!' || node.firstChild) continue; - results.push(node); + element = forElement; + do { + if (element != docBody) { + valueT -= element.scrollTop || 0; + valueL -= element.scrollLeft || 0; } - return results; - }, + } while (element = element.parentNode); + return new Element.Offset(valueL, valueT); + } - 'not': function(nodes, selector, root) { - var h = Selector.handlers, selectorType, m; - var exclusions = new Selector(selector).findElements(root); - h.mark(exclusions); - for (var i = 0, results = [], node; node = nodes[i]; i++) - if (!node._countedByPrototype) results.push(node); - h.unmark(exclusions); - return results; - }, + function absolutize(element) { + element = $(element); - 'enabled': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) - if (!node.disabled && (!node.type || node.type !== 'hidden')) - results.push(node); - return results; - }, + if (Element.getStyle(element, 'position') === 'absolute') { + return element; + } - 'disabled': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) - if (node.disabled) results.push(node); - return results; - }, + var offsetParent = getOffsetParent(element); + var eOffset = element.viewportOffset(), + pOffset = offsetParent.viewportOffset(); - 'checked': function(nodes, value, root) { - for (var i = 0, results = [], node; node = nodes[i]; i++) - if (node.checked) results.push(node); - return results; + var offset = eOffset.relativeTo(pOffset); + var layout = element.getLayout(); + + element.store('prototype_absolutize_original_styles', { + left: element.getStyle('left'), + top: element.getStyle('top'), + width: element.getStyle('width'), + height: element.getStyle('height') + }); + + element.setStyle({ + position: 'absolute', + top: offset.top + 'px', + left: offset.left + 'px', + width: layout.get('width') + 'px', + height: layout.get('height') + 'px' + }); + + return element; + } + + function relativize(element) { + element = $(element); + if (Element.getStyle(element, 'position') === 'relative') { + return element; } - }, - operators: { - '=': function(nv, v) { return nv == v; }, - '!=': function(nv, v) { return nv != v; }, - '^=': function(nv, v) { return nv == v || nv && nv.startsWith(v); }, - '$=': function(nv, v) { return nv == v || nv && nv.endsWith(v); }, - '*=': function(nv, v) { return nv == v || nv && nv.include(v); }, - '$=': function(nv, v) { return nv.endsWith(v); }, - '*=': function(nv, v) { return nv.include(v); }, - '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); }, - '|=': function(nv, v) { return ('-' + (nv || "").toUpperCase() + - '-').include('-' + (v || "").toUpperCase() + '-'); } - }, + var originalStyles = + element.retrieve('prototype_absolutize_original_styles'); - split: function(expression) { - var expressions = []; - expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) { - expressions.push(m[1].strip()); + if (originalStyles) element.setStyle(originalStyles); + return element; + } + + if (Prototype.Browser.IE) { + getOffsetParent = getOffsetParent.wrap( + function(proceed, element) { + element = $(element); + + if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element)) + return $(document.body); + + var position = element.getStyle('position'); + if (position !== 'static') return proceed(element); + + element.setStyle({ position: 'relative' }); + var value = proceed(element); + element.setStyle({ position: position }); + return value; + } + ); + + positionedOffset = positionedOffset.wrap(function(proceed, element) { + element = $(element); + if (!element.parentNode) return new Element.Offset(0, 0); + var position = element.getStyle('position'); + if (position !== 'static') return proceed(element); + + var offsetParent = element.getOffsetParent(); + if (offsetParent && offsetParent.getStyle('position') === 'fixed') + hasLayout(offsetParent); + + element.setStyle({ position: 'relative' }); + var value = proceed(element); + element.setStyle({ position: position }); + return value; }); - return expressions; - }, + } else if (Prototype.Browser.Webkit) { + cumulativeOffset = function(element) { + element = $(element); + var valueT = 0, valueL = 0; + do { + valueT += element.offsetTop || 0; + valueL += element.offsetLeft || 0; + if (element.offsetParent == document.body) + if (Element.getStyle(element, 'position') == 'absolute') break; - matchElements: function(elements, expression) { - var matches = $$(expression), h = Selector.handlers; - h.mark(matches); - for (var i = 0, results = [], element; element = elements[i]; i++) - if (element._countedByPrototype) results.push(element); - h.unmark(matches); - return results; - }, + element = element.offsetParent; + } while (element); - findElement: function(elements, expression, index) { - if (Object.isNumber(expression)) { - index = expression; expression = false; + return new Element.Offset(valueL, valueT); + }; + } + + + Element.addMethods({ + getLayout: getLayout, + measure: measure, + getDimensions: getDimensions, + getOffsetParent: getOffsetParent, + cumulativeOffset: cumulativeOffset, + positionedOffset: positionedOffset, + cumulativeScrollOffset: cumulativeScrollOffset, + viewportOffset: viewportOffset, + absolutize: absolutize, + relativize: relativize + }); + + function isBody(element) { + return element.nodeName.toUpperCase() === 'BODY'; + } + + function isHtml(element) { + return element.nodeName.toUpperCase() === 'HTML'; + } + + function isDocument(element) { + return element.nodeType === Node.DOCUMENT_NODE; + } + + function isDetached(element) { + return element !== document.body && + !Element.descendantOf(element, document.body); + } + + if ('getBoundingClientRect' in document.documentElement) { + Element.addMethods({ + viewportOffset: function(element) { + element = $(element); + if (isDetached(element)) return new Element.Offset(0, 0); + + var rect = element.getBoundingClientRect(), + docEl = document.documentElement; + return new Element.Offset(rect.left - docEl.clientLeft, + rect.top - docEl.clientTop); + } + }); + } +})(); +window.$$ = function() { + var expression = $A(arguments).join(', '); + return Prototype.Selector.select(expression, document); +}; + +Prototype.Selector = (function() { + + function select() { + throw new Error('Method "Prototype.Selector.select" must be defined.'); + } + + function match() { + throw new Error('Method "Prototype.Selector.match" must be defined.'); + } + + function find(elements, expression, index) { + index = index || 0; + var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i; + + for (i = 0; i < length; i++) { + if (match(elements[i], expression) && index == matchIndex++) { + return Element.extend(elements[i]); + } } - return Selector.matchElements(elements, expression || '*')[index || 0]; - }, + } - findChildElements: function(element, expressions) { - expressions = Selector.split(expressions.join(',')); - var results = [], h = Selector.handlers; - for (var i = 0, l = expressions.length, selector; i < l; i++) { - selector = new Selector(expressions[i].strip()); - h.concat(results, selector.findElements(element)); + function extendElements(elements) { + for (var i = 0, length = elements.length; i < length; i++) { + Element.extend(elements[i]); } - return (l > 1) ? h.unique(results) : results; + return elements; } + + + var K = Prototype.K; + + return { + select: select, + match: match, + find: find, + extendElements: (Element.extend === K) ? K : extendElements, + extendElement: Element.extend + }; +})(); +Prototype._original_property = window.Sizzle; +/*! + * Sizzle CSS Selector Engine - v1.0 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){ + +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, + done = 0, + toString = Object.prototype.toString, + hasDuplicate = false, + baseHasDuplicate = true; + +[0, 0].sort(function(){ + baseHasDuplicate = false; + return 0; }); -if (Prototype.Browser.IE) { - Object.extend(Selector.handlers, { - // IE returns comment nodes on getElementsByTagName("*"). - // Filter them out. - concat: function(a, b) { - for (var i = 0, node; node = b[i]; i++) - if (node.tagName !== "!") a.push(node); - return a; - }, +var Sizzle = function(selector, context, results, seed) { + results = results || []; + var origContext = context = context || document; + + if ( context.nodeType !== 1 && context.nodeType !== 9 ) { + return []; + } + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context), + soFar = selector; + + while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) { + soFar = m[3]; + + parts.push( m[1] ); + + if ( m[2] ) { + extra = m[3]; + break; + } + } + + if ( parts.length > 1 && origPOS.exec( selector ) ) { + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { + set = posProcess( parts[0] + parts[1], context ); + } else { + set = Expr.relative[ parts[0] ] ? + [ context ] : + Sizzle( parts.shift(), context ); + + while ( parts.length ) { + selector = parts.shift(); + + if ( Expr.relative[ selector ] ) + selector += parts.shift(); + + set = posProcess( selector, set ); + } + } + } else { + if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && + Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { + var ret = Sizzle.find( parts.shift(), context, contextXML ); + context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; + } + + if ( context ) { + var ret = seed ? + { expr: parts.pop(), set: makeArray(seed) } : + Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); + set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; + + if ( parts.length > 0 ) { + checkSet = makeArray(set); + } else { + prune = false; + } + + while ( parts.length ) { + var cur = parts.pop(), pop = cur; + + if ( !Expr.relative[ cur ] ) { + cur = ""; + } else { + pop = parts.pop(); + } + + if ( pop == null ) { + pop = context; + } + + Expr.relative[ cur ]( checkSet, pop, contextXML ); + } + } else { + checkSet = parts = []; + } + } + + if ( !checkSet ) { + checkSet = set; + } + + if ( !checkSet ) { + throw "Syntax error, unrecognized expression: " + (cur || selector); + } + + if ( toString.call(checkSet) === "[object Array]" ) { + if ( !prune ) { + results.push.apply( results, checkSet ); + } else if ( context && context.nodeType === 1 ) { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { + results.push( set[i] ); + } + } + } else { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { + results.push( set[i] ); + } + } + } + } else { + makeArray( checkSet, results ); + } + + if ( extra ) { + Sizzle( extra, origContext, results, seed ); + Sizzle.uniqueSort( results ); + } + + return results; +}; - // IE improperly serializes _countedByPrototype in (inner|outer)HTML. - unmark: function(nodes) { - for (var i = 0, node; node = nodes[i]; i++) - node.removeAttribute('_countedByPrototype'); - return nodes; - } - }); +Sizzle.uniqueSort = function(results){ + if ( sortOrder ) { + hasDuplicate = baseHasDuplicate; + results.sort(sortOrder); + + if ( hasDuplicate ) { + for ( var i = 1; i < results.length; i++ ) { + if ( results[i] === results[i-1] ) { + results.splice(i--, 1); + } + } + } + } + + return results; +}; + +Sizzle.matches = function(expr, set){ + return Sizzle(expr, null, null, set); +}; + +Sizzle.find = function(expr, context, isXML){ + var set, match; + + if ( !expr ) { + return []; + } + + for ( var i = 0, l = Expr.order.length; i < l; i++ ) { + var type = Expr.order[i], match; + + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { + var left = match[1]; + match.splice(1,1); + + if ( left.substr( left.length - 1 ) !== "\\" ) { + match[1] = (match[1] || "").replace(/\\/g, ""); + set = Expr.find[ type ]( match, context, isXML ); + if ( set != null ) { + expr = expr.replace( Expr.match[ type ], "" ); + break; + } + } + } + } + + if ( !set ) { + set = context.getElementsByTagName("*"); + } + + return {set: set, expr: expr}; +}; + +Sizzle.filter = function(expr, set, inplace, not){ + var old = expr, result = [], curLoop = set, match, anyFound, + isXMLFilter = set && set[0] && isXML(set[0]); + + while ( expr && set.length ) { + for ( var type in Expr.filter ) { + if ( (match = Expr.match[ type ].exec( expr )) != null ) { + var filter = Expr.filter[ type ], found, item; + anyFound = false; + + if ( curLoop == result ) { + result = []; + } + + if ( Expr.preFilter[ type ] ) { + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); + + if ( !match ) { + anyFound = found = true; + } else if ( match === true ) { + continue; + } + } + + if ( match ) { + for ( var i = 0; (item = curLoop[i]) != null; i++ ) { + if ( item ) { + found = filter( item, match, i, curLoop ); + var pass = not ^ !!found; + + if ( inplace && found != null ) { + if ( pass ) { + anyFound = true; + } else { + curLoop[i] = false; + } + } else if ( pass ) { + result.push( item ); + anyFound = true; + } + } + } + } + + if ( found !== undefined ) { + if ( !inplace ) { + curLoop = result; + } + + expr = expr.replace( Expr.match[ type ], "" ); + + if ( !anyFound ) { + return []; + } + + break; + } + } + } + + if ( expr == old ) { + if ( anyFound == null ) { + throw "Syntax error, unrecognized expression: " + expr; + } else { + break; + } + } + + old = expr; + } + + return curLoop; +}; + +var Expr = Sizzle.selectors = { + order: [ "ID", "NAME", "TAG" ], + match: { + ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/ + }, + leftMatch: {}, + attrMap: { + "class": "className", + "for": "htmlFor" + }, + attrHandle: { + href: function(elem){ + return elem.getAttribute("href"); + } + }, + relative: { + "+": function(checkSet, part, isXML){ + var isPartStr = typeof part === "string", + isTag = isPartStr && !/\W/.test(part), + isPartStrNotTag = isPartStr && !isTag; + + if ( isTag && !isXML ) { + part = part.toUpperCase(); + } + + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { + if ( (elem = checkSet[i]) ) { + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} + + checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ? + elem || false : + elem === part; + } + } + + if ( isPartStrNotTag ) { + Sizzle.filter( part, checkSet, true ); + } + }, + ">": function(checkSet, part, isXML){ + var isPartStr = typeof part === "string"; + + if ( isPartStr && !/\W/.test(part) ) { + part = isXML ? part : part.toUpperCase(); + + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + var parent = elem.parentNode; + checkSet[i] = parent.nodeName === part ? parent : false; + } + } + } else { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + checkSet[i] = isPartStr ? + elem.parentNode : + elem.parentNode === part; + } + } + + if ( isPartStr ) { + Sizzle.filter( part, checkSet, true ); + } + } + }, + "": function(checkSet, part, isXML){ + var doneName = done++, checkFn = dirCheck; + + if ( !/\W/.test(part) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } + + checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); + }, + "~": function(checkSet, part, isXML){ + var doneName = done++, checkFn = dirCheck; + + if ( typeof part === "string" && !/\W/.test(part) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } + + checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); + } + }, + find: { + ID: function(match, context, isXML){ + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + return m ? [m] : []; + } + }, + NAME: function(match, context, isXML){ + if ( typeof context.getElementsByName !== "undefined" ) { + var ret = [], results = context.getElementsByName(match[1]); + + for ( var i = 0, l = results.length; i < l; i++ ) { + if ( results[i].getAttribute("name") === match[1] ) { + ret.push( results[i] ); + } + } + + return ret.length === 0 ? null : ret; + } + }, + TAG: function(match, context){ + return context.getElementsByTagName(match[1]); + } + }, + preFilter: { + CLASS: function(match, curLoop, inplace, result, not, isXML){ + match = " " + match[1].replace(/\\/g, "") + " "; + + if ( isXML ) { + return match; + } + + for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { + if ( elem ) { + if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) { + if ( !inplace ) + result.push( elem ); + } else if ( inplace ) { + curLoop[i] = false; + } + } + } + + return false; + }, + ID: function(match){ + return match[1].replace(/\\/g, ""); + }, + TAG: function(match, curLoop){ + for ( var i = 0; curLoop[i] === false; i++ ){} + return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase(); + }, + CHILD: function(match){ + if ( match[1] == "nth" ) { + var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( + match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" || + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); + + match[2] = (test[1] + (test[2] || 1)) - 0; + match[3] = test[3] - 0; + } + + match[0] = done++; + + return match; + }, + ATTR: function(match, curLoop, inplace, result, not, isXML){ + var name = match[1].replace(/\\/g, ""); + + if ( !isXML && Expr.attrMap[name] ) { + match[1] = Expr.attrMap[name]; + } + + if ( match[2] === "~=" ) { + match[4] = " " + match[4] + " "; + } + + return match; + }, + PSEUDO: function(match, curLoop, inplace, result, not){ + if ( match[1] === "not" ) { + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { + match[3] = Sizzle(match[3], null, null, curLoop); + } else { + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); + if ( !inplace ) { + result.push.apply( result, ret ); + } + return false; + } + } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { + return true; + } + + return match; + }, + POS: function(match){ + match.unshift( true ); + return match; + } + }, + filters: { + enabled: function(elem){ + return elem.disabled === false && elem.type !== "hidden"; + }, + disabled: function(elem){ + return elem.disabled === true; + }, + checked: function(elem){ + return elem.checked === true; + }, + selected: function(elem){ + elem.parentNode.selectedIndex; + return elem.selected === true; + }, + parent: function(elem){ + return !!elem.firstChild; + }, + empty: function(elem){ + return !elem.firstChild; + }, + has: function(elem, i, match){ + return !!Sizzle( match[3], elem ).length; + }, + header: function(elem){ + return /h\d/i.test( elem.nodeName ); + }, + text: function(elem){ + return "text" === elem.type; + }, + radio: function(elem){ + return "radio" === elem.type; + }, + checkbox: function(elem){ + return "checkbox" === elem.type; + }, + file: function(elem){ + return "file" === elem.type; + }, + password: function(elem){ + return "password" === elem.type; + }, + submit: function(elem){ + return "submit" === elem.type; + }, + image: function(elem){ + return "image" === elem.type; + }, + reset: function(elem){ + return "reset" === elem.type; + }, + button: function(elem){ + return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON"; + }, + input: function(elem){ + return /input|select|textarea|button/i.test(elem.nodeName); + } + }, + setFilters: { + first: function(elem, i){ + return i === 0; + }, + last: function(elem, i, match, array){ + return i === array.length - 1; + }, + even: function(elem, i){ + return i % 2 === 0; + }, + odd: function(elem, i){ + return i % 2 === 1; + }, + lt: function(elem, i, match){ + return i < match[3] - 0; + }, + gt: function(elem, i, match){ + return i > match[3] - 0; + }, + nth: function(elem, i, match){ + return match[3] - 0 == i; + }, + eq: function(elem, i, match){ + return match[3] - 0 == i; + } + }, + filter: { + PSEUDO: function(elem, match, i, array){ + var name = match[1], filter = Expr.filters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } else if ( name === "contains" ) { + return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0; + } else if ( name === "not" ) { + var not = match[3]; + + for ( var i = 0, l = not.length; i < l; i++ ) { + if ( not[i] === elem ) { + return false; + } + } + + return true; + } + }, + CHILD: function(elem, match){ + var type = match[1], node = elem; + switch (type) { + case 'only': + case 'first': + while ( (node = node.previousSibling) ) { + if ( node.nodeType === 1 ) return false; + } + if ( type == 'first') return true; + node = elem; + case 'last': + while ( (node = node.nextSibling) ) { + if ( node.nodeType === 1 ) return false; + } + return true; + case 'nth': + var first = match[2], last = match[3]; + + if ( first == 1 && last == 0 ) { + return true; + } + + var doneName = match[0], + parent = elem.parentNode; + + if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { + var count = 0; + for ( node = parent.firstChild; node; node = node.nextSibling ) { + if ( node.nodeType === 1 ) { + node.nodeIndex = ++count; + } + } + parent.sizcache = doneName; + } + + var diff = elem.nodeIndex - last; + if ( first == 0 ) { + return diff == 0; + } else { + return ( diff % first == 0 && diff / first >= 0 ); + } + } + }, + ID: function(elem, match){ + return elem.nodeType === 1 && elem.getAttribute("id") === match; + }, + TAG: function(elem, match){ + return (match === "*" && elem.nodeType === 1) || elem.nodeName === match; + }, + CLASS: function(elem, match){ + return (" " + (elem.className || elem.getAttribute("class")) + " ") + .indexOf( match ) > -1; + }, + ATTR: function(elem, match){ + var name = match[1], + result = Expr.attrHandle[ name ] ? + Expr.attrHandle[ name ]( elem ) : + elem[ name ] != null ? + elem[ name ] : + elem.getAttribute( name ), + value = result + "", + type = match[2], + check = match[4]; + + return result == null ? + type === "!=" : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !check ? + value && result !== false : + type === "!=" ? + value != check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0, check.length + 1) === check + "-" : + false; + }, + POS: function(elem, match, i, array){ + var name = match[2], filter = Expr.setFilters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } + } + } +}; + +var origPOS = Expr.match.POS; + +for ( var type in Expr.match ) { + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source ); +} + +var makeArray = function(array, results) { + array = Array.prototype.slice.call( array, 0 ); + + if ( results ) { + results.push.apply( results, array ); + return results; + } + + return array; +}; + +try { + Array.prototype.slice.call( document.documentElement.childNodes, 0 ); + +} catch(e){ + makeArray = function(array, results) { + var ret = results || []; + + if ( toString.call(array) === "[object Array]" ) { + Array.prototype.push.apply( ret, array ); + } else { + if ( typeof array.length === "number" ) { + for ( var i = 0, l = array.length; i < l; i++ ) { + ret.push( array[i] ); + } + } else { + for ( var i = 0; array[i]; i++ ) { + ret.push( array[i] ); + } + } + } + + return ret; + }; } -function $$() { - return Selector.findChildElements(document, $A(arguments)); +var sortOrder; + +if ( document.documentElement.compareDocumentPosition ) { + sortOrder = function( a, b ) { + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; +} else if ( "sourceIndex" in document.documentElement ) { + sortOrder = function( a, b ) { + if ( !a.sourceIndex || !b.sourceIndex ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var ret = a.sourceIndex - b.sourceIndex; + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; +} else if ( document.createRange ) { + sortOrder = function( a, b ) { + if ( !a.ownerDocument || !b.ownerDocument ) { + if ( a == b ) { + hasDuplicate = true; + } + return 0; + } + + var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); + aRange.setStart(a, 0); + aRange.setEnd(a, 0); + bRange.setStart(b, 0); + bRange.setEnd(b, 0); + var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); + if ( ret === 0 ) { + hasDuplicate = true; + } + return ret; + }; } + +(function(){ + var form = document.createElement("div"), + id = "script" + (new Date).getTime(); + form.innerHTML = ""; + + var root = document.documentElement; + root.insertBefore( form, root.firstChild ); + + if ( !!document.getElementById( id ) ) { + Expr.find.ID = function(match, context, isXML){ + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; + } + }; + + Expr.filter.ID = function(elem, match){ + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); + return elem.nodeType === 1 && node && node.nodeValue === match; + }; + } + + root.removeChild( form ); + root = form = null; // release memory in IE +})(); + +(function(){ + + var div = document.createElement("div"); + div.appendChild( document.createComment("") ); + + if ( div.getElementsByTagName("*").length > 0 ) { + Expr.find.TAG = function(match, context){ + var results = context.getElementsByTagName(match[1]); + + if ( match[1] === "*" ) { + var tmp = []; + + for ( var i = 0; results[i]; i++ ) { + if ( results[i].nodeType === 1 ) { + tmp.push( results[i] ); + } + } + + results = tmp; + } + + return results; + }; + } + + div.innerHTML = ""; + if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && + div.firstChild.getAttribute("href") !== "#" ) { + Expr.attrHandle.href = function(elem){ + return elem.getAttribute("href", 2); + }; + } + + div = null; // release memory in IE +})(); + +if ( document.querySelectorAll ) (function(){ + var oldSizzle = Sizzle, div = document.createElement("div"); + div.innerHTML = "

      "; + + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { + return; + } + + Sizzle = function(query, context, extra, seed){ + context = context || document; + + if ( !seed && context.nodeType === 9 && !isXML(context) ) { + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(e){} + } + + return oldSizzle(query, context, extra, seed); + }; + + for ( var prop in oldSizzle ) { + Sizzle[ prop ] = oldSizzle[ prop ]; + } + + div = null; // release memory in IE +})(); + +if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){ + var div = document.createElement("div"); + div.innerHTML = "
      "; + + if ( div.getElementsByClassName("e").length === 0 ) + return; + + div.lastChild.className = "e"; + + if ( div.getElementsByClassName("e").length === 1 ) + return; + + Expr.order.splice(1, 0, "CLASS"); + Expr.find.CLASS = function(match, context, isXML) { + if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { + return context.getElementsByClassName(match[1]); + } + }; + + div = null; // release memory in IE +})(); + +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + var sibDir = dir == "previousSibling" && !isXML; + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + if ( sibDir && elem.nodeType === 1 ){ + elem.sizcache = doneName; + elem.sizset = i; + } + elem = elem[dir]; + var match = false; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 && !isXML ){ + elem.sizcache = doneName; + elem.sizset = i; + } + + if ( elem.nodeName === cur ) { + match = elem; + break; + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + var sibDir = dir == "previousSibling" && !isXML; + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + if ( sibDir && elem.nodeType === 1 ) { + elem.sizcache = doneName; + elem.sizset = i; + } + elem = elem[dir]; + var match = false; + + while ( elem ) { + if ( elem.sizcache === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 ) { + if ( !isXML ) { + elem.sizcache = doneName; + elem.sizset = i; + } + if ( typeof cur !== "string" ) { + if ( elem === cur ) { + match = true; + break; + } + + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { + match = elem; + break; + } + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +var contains = document.compareDocumentPosition ? function(a, b){ + return a.compareDocumentPosition(b) & 16; +} : function(a, b){ + return a !== b && (a.contains ? a.contains(b) : true); +}; + +var isXML = function(elem){ + return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || + !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; +}; + +var posProcess = function(selector, context){ + var tmpSet = [], later = "", match, + root = context.nodeType ? [context] : context; + + while ( (match = Expr.match.PSEUDO.exec( selector )) ) { + later += match[0]; + selector = selector.replace( Expr.match.PSEUDO, "" ); + } + + selector = Expr.relative[selector] ? selector + "*" : selector; + + for ( var i = 0, l = root.length; i < l; i++ ) { + Sizzle( selector, root[i], tmpSet ); + } + + return Sizzle.filter( later, tmpSet ); +}; + + +window.Sizzle = Sizzle; + +})(); + +;(function(engine) { + var extendElements = Prototype.Selector.extendElements; + + function select(selector, scope) { + return extendElements(engine(selector, scope || document)); + } + + function match(element, selector) { + return engine.matches(selector, [element]).length == 1; + } + + Prototype.Selector.engine = engine; + Prototype.Selector.select = select; + Prototype.Selector.match = match; +})(Sizzle); + +window.Sizzle = Prototype._original_property; +delete Prototype._original_property; + var Form = { reset: function(form) { - $(form).reset(); + form = $(form); + form.reset(); return form; }, serializeElements: function(elements, options) { if (typeof options != 'object') options = { hash: !!options }; else if (Object.isUndefined(options.hash)) options.hash = true; - var key, value, submitted = false, submit = options.submit; + var key, value, submitted = false, submit = options.submit, accumulator, initial; + + if (options.hash) { + initial = {}; + accumulator = function(result, key, value) { + if (key in result) { + if (!Object.isArray(result[key])) result[key] = [result[key]]; + result[key].push(value); + } else result[key] = value; + return result; + }; + } else { + initial = ''; + accumulator = function(result, key, value) { + return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + } - var data = elements.inject({ }, function(result, element) { + return elements.inject(initial, function(result, element) { if (!element.disabled && element.name) { key = element.name; value = $(element).getValue(); if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted && submit !== false && (!submit || key == submit) && (submitted = true)))) { - if (key in result) { - // a key is already present; construct an array of values - if (!Object.isArray(result[key])) result[key] = [result[key]]; - result[key].push(value); - } - else result[key] = value; + result = accumulator(result, key, value); } } return result; }); - - return options.hash ? data : Object.toQueryString(data); } }; @@ -3482,13 +5007,18 @@ Form.Methods = { }, getElements: function(form) { - return $A($(form).getElementsByTagName('*')).inject([], - function(elements, child) { - if (Form.Element.Serializers[child.tagName.toLowerCase()]) - elements.push(Element.extend(child)); - return elements; - } - ); + var elements = $(form).getElementsByTagName('*'), + element, + arr = [ ], + serializers = Form.Element.Serializers; + for (var i = 0; element = elements[i]; i++) { + arr.push(element); + } + return arr.inject([], function(elements, child) { + if (serializers[child.tagName.toLowerCase()]) + elements.push(Element.extend(child)); + return elements; + }) }, getInputs: function(form, typeName, name) { @@ -3528,13 +5058,14 @@ Form.Methods = { }).sortBy(function(element) { return element.tabIndex }).first(); return firstByIndex ? firstByIndex : elements.find(function(element) { - return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); + return /^(?:input|select|textarea)$/i.test(element.tagName); }); }, focusFirstElement: function(form) { form = $(form); - form.findFirstElement().activate(); + var element = form.findFirstElement(); + if (element) element.activate(); return form; }, @@ -3559,6 +5090,7 @@ Form.Methods = { /*--------------------------------------------------------------------------*/ + Form.Element = { focus: function(element) { $(element).focus(); @@ -3572,6 +5104,7 @@ Form.Element = { }; Form.Element.Methods = { + serialize: function(element) { element = $(element); if (!element.disabled && element.name) { @@ -3612,7 +5145,7 @@ Form.Element.Methods = { try { element.focus(); if (element.select && (element.tagName.toLowerCase() != 'input' || - !['button', 'reset', 'submit'].include(element.type))) + !(/^(?:button|reset|submit)$/i.test(element.type)))) element.select(); } catch (e) { } return element; @@ -3634,75 +5167,86 @@ Form.Element.Methods = { /*--------------------------------------------------------------------------*/ var Field = Form.Element; + var $F = Form.Element.Methods.getValue; /*--------------------------------------------------------------------------*/ -Form.Element.Serializers = { - input: function(element, value) { +Form.Element.Serializers = (function() { + function input(element, value) { switch (element.type.toLowerCase()) { case 'checkbox': case 'radio': - return Form.Element.Serializers.inputSelector(element, value); + return inputSelector(element, value); default: - return Form.Element.Serializers.textarea(element, value); + return valueSelector(element, value); } - }, + } - inputSelector: function(element, value) { - if (Object.isUndefined(value)) return element.checked ? element.value : null; + function inputSelector(element, value) { + if (Object.isUndefined(value)) + return element.checked ? element.value : null; else element.checked = !!value; - }, + } - textarea: function(element, value) { + function valueSelector(element, value) { if (Object.isUndefined(value)) return element.value; else element.value = value; - }, + } - select: function(element, value) { + function select(element, value) { if (Object.isUndefined(value)) - return this[element.type == 'select-one' ? - 'selectOne' : 'selectMany'](element); - else { - var opt, currentValue, single = !Object.isArray(value); - for (var i = 0, length = element.length; i < length; i++) { - opt = element.options[i]; - currentValue = this.optionValue(opt); - if (single) { - if (currentValue == value) { - opt.selected = true; - return; - } + return (element.type === 'select-one' ? selectOne : selectMany)(element); + + var opt, currentValue, single = !Object.isArray(value); + for (var i = 0, length = element.length; i < length; i++) { + opt = element.options[i]; + currentValue = this.optionValue(opt); + if (single) { + if (currentValue == value) { + opt.selected = true; + return; } - else opt.selected = value.include(currentValue); } + else opt.selected = value.include(currentValue); } - }, + } - selectOne: function(element) { + function selectOne(element) { var index = element.selectedIndex; - return index >= 0 ? this.optionValue(element.options[index]) : null; - }, + return index >= 0 ? optionValue(element.options[index]) : null; + } - selectMany: function(element) { + function selectMany(element) { var values, length = element.length; if (!length) return null; for (var i = 0, values = []; i < length; i++) { var opt = element.options[i]; - if (opt.selected) values.push(this.optionValue(opt)); + if (opt.selected) values.push(optionValue(opt)); } return values; - }, + } - optionValue: function(opt) { - // extend element because hasAttribute may not be native - return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text; + function optionValue(opt) { + return Element.hasAttribute(opt, 'value') ? opt.value : opt.text; } -}; + + return { + input: input, + inputSelector: inputSelector, + textarea: valueSelector, + select: select, + selectOne: selectOne, + selectMany: selectMany, + optionValue: optionValue, + button: valueSelector + }; +})(); /*--------------------------------------------------------------------------*/ + Abstract.TimedObserver = Class.create(PeriodicalExecuter, { initialize: function($super, element, frequency, callback) { $super(callback, frequency); @@ -3784,360 +5328,527 @@ Form.EventObserver = Class.create(Abstract.EventObserver, { return Form.serialize(this.element); } }); -if (!window.Event) var Event = { }; - -Object.extend(Event, { - KEY_BACKSPACE: 8, - KEY_TAB: 9, - KEY_RETURN: 13, - KEY_ESC: 27, - KEY_LEFT: 37, - KEY_UP: 38, - KEY_RIGHT: 39, - KEY_DOWN: 40, - KEY_DELETE: 46, - KEY_HOME: 36, - KEY_END: 35, - KEY_PAGEUP: 33, - KEY_PAGEDOWN: 34, - KEY_INSERT: 45, - - cache: { }, - - relatedTarget: function(event) { - var element; - switch(event.type) { - case 'mouseover': element = event.fromElement; break; - case 'mouseout': element = event.toElement; break; - default: return null; - } - return Element.extend(element); +(function() { + + var Event = { + KEY_BACKSPACE: 8, + KEY_TAB: 9, + KEY_RETURN: 13, + KEY_ESC: 27, + KEY_LEFT: 37, + KEY_UP: 38, + KEY_RIGHT: 39, + KEY_DOWN: 40, + KEY_DELETE: 46, + KEY_HOME: 36, + KEY_END: 35, + KEY_PAGEUP: 33, + KEY_PAGEDOWN: 34, + KEY_INSERT: 45, + + cache: {} + }; + + var docEl = document.documentElement; + var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl + && 'onmouseleave' in docEl; + + + + var isIELegacyEvent = function(event) { return false; }; + + if (window.attachEvent) { + if (window.addEventListener) { + isIELegacyEvent = function(event) { + return !(event instanceof window.Event); + }; + } else { + isIELegacyEvent = function(event) { return true; }; + } } -}); -Event.Methods = (function() { - var isButton; + var _isButton; - if (Prototype.Browser.IE) { - var buttonMap = { 0: 1, 1: 4, 2: 2 }; - isButton = function(event, code) { - return event.button == buttonMap[code]; - }; + function _isButtonForDOMEvents(event, code) { + return event.which ? (event.which === code + 1) : (event.button === code); + } - } else if (Prototype.Browser.WebKit) { - isButton = function(event, code) { - switch (code) { - case 0: return event.which == 1 && !event.metaKey; - case 1: return event.which == 1 && event.metaKey; - default: return false; - } - }; + var legacyButtonMap = { 0: 1, 1: 4, 2: 2 }; + function _isButtonForLegacyEvents(event, code) { + return event.button === legacyButtonMap[code]; + } - } else { - isButton = function(event, code) { - return event.which ? (event.which === code + 1) : (event.button === code); - }; + function _isButtonForWebKit(event, code) { + switch (code) { + case 0: return event.which == 1 && !event.metaKey; + case 1: return event.which == 2 || (event.which == 1 && event.metaKey); + case 2: return event.which == 3; + default: return false; + } } - return { - isLeftClick: function(event) { return isButton(event, 0) }, - isMiddleClick: function(event) { return isButton(event, 1) }, - isRightClick: function(event) { return isButton(event, 2) }, - - element: function(event) { - event = Event.extend(event); - - var node = event.target, - type = event.type, - currentTarget = event.currentTarget; - - if (currentTarget && currentTarget.tagName) { - // Firefox screws up the "click" event when moving between radio buttons - // via arrow keys. It also screws up the "load" and "error" events on images, - // reporting the document as the target instead of the original image. - if (type === 'load' || type === 'error' || - (type === 'click' && currentTarget.tagName.toLowerCase() === 'input' - && currentTarget.type === 'radio')) - node = currentTarget; + if (window.attachEvent) { + if (!window.addEventListener) { + _isButton = _isButtonForLegacyEvents; + } else { + _isButton = function(event, code) { + return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) : + _isButtonForDOMEvents(event, code); } - if (node) { - if (node.nodeType == Node.TEXT_NODE) node = node.parentNode; - return Element.extend(node); - } else return false; - }, + } + } else if (Prototype.Browser.WebKit) { + _isButton = _isButtonForWebKit; + } else { + _isButton = _isButtonForDOMEvents; + } - findElement: function(event, expression) { - var element = Event.element(event); - if (!expression) return element; - var elements = [element].concat(element.ancestors()); - return Selector.findElement(elements, expression, 0); - }, + function isLeftClick(event) { return _isButton(event, 0) } - pointer: function(event) { - var docElement = document.documentElement, - body = document.body || { scrollLeft: 0, scrollTop: 0 }; - return { - x: event.pageX || (event.clientX + - (docElement.scrollLeft || body.scrollLeft) - - (docElement.clientLeft || 0)), - y: event.pageY || (event.clientY + - (docElement.scrollTop || body.scrollTop) - - (docElement.clientTop || 0)) - }; - }, + function isMiddleClick(event) { return _isButton(event, 1) } + + function isRightClick(event) { return _isButton(event, 2) } + + function element(event) { + event = Event.extend(event); + + var node = event.target, type = event.type, + currentTarget = event.currentTarget; + + if (currentTarget && currentTarget.tagName) { + if (type === 'load' || type === 'error' || + (type === 'click' && currentTarget.tagName.toLowerCase() === 'input' + && currentTarget.type === 'radio')) + node = currentTarget; + } + + if (node.nodeType == Node.TEXT_NODE) + node = node.parentNode; + + return Element.extend(node); + } - pointerX: function(event) { return Event.pointer(event).x }, - pointerY: function(event) { return Event.pointer(event).y }, + function findElement(event, expression) { + var element = Event.element(event); - stop: function(event) { - Event.extend(event); - event.preventDefault(); - event.stopPropagation(); - event.stopped = true; + if (!expression) return element; + while (element) { + if (Object.isElement(element) && Prototype.Selector.match(element, expression)) { + return Element.extend(element); + } + element = element.parentNode; } + } + + function pointer(event) { + return { x: pointerX(event), y: pointerY(event) }; + } + + function pointerX(event) { + var docElement = document.documentElement, + body = document.body || { scrollLeft: 0 }; + + return event.pageX || (event.clientX + + (docElement.scrollLeft || body.scrollLeft) - + (docElement.clientLeft || 0)); + } + + function pointerY(event) { + var docElement = document.documentElement, + body = document.body || { scrollTop: 0 }; + + return event.pageY || (event.clientY + + (docElement.scrollTop || body.scrollTop) - + (docElement.clientTop || 0)); + } + + + function stop(event) { + Event.extend(event); + event.preventDefault(); + event.stopPropagation(); + + event.stopped = true; + } + + + Event.Methods = { + isLeftClick: isLeftClick, + isMiddleClick: isMiddleClick, + isRightClick: isRightClick, + + element: element, + findElement: findElement, + + pointer: pointer, + pointerX: pointerX, + pointerY: pointerY, + + stop: stop }; -})(); -Event.extend = (function() { var methods = Object.keys(Event.Methods).inject({ }, function(m, name) { m[name] = Event.Methods[name].methodize(); return m; }); - if (Prototype.Browser.IE) { - Object.extend(methods, { + if (window.attachEvent) { + function _relatedTarget(event) { + var element; + switch (event.type) { + case 'mouseover': + case 'mouseenter': + element = event.fromElement; + break; + case 'mouseout': + case 'mouseleave': + element = event.toElement; + break; + default: + return null; + } + return Element.extend(element); + } + + var additionalMethods = { stopPropagation: function() { this.cancelBubble = true }, preventDefault: function() { this.returnValue = false }, - inspect: function() { return "[object Event]" } - }); + inspect: function() { return '[object Event]' } + }; - return function(event) { + Event.extend = function(event, element) { if (!event) return false; - if (event._extendedByPrototype) return event; + if (!isIELegacyEvent(event)) return event; + + if (event._extendedByPrototype) return event; event._extendedByPrototype = Prototype.emptyFunction; + var pointer = Event.pointer(event); + Object.extend(event, { - target: event.srcElement, - relatedTarget: Event.relatedTarget(event), + target: event.srcElement || element, + relatedTarget: _relatedTarget(event), pageX: pointer.x, pageY: pointer.y }); - return Object.extend(event, methods); - }; + Object.extend(event, methods); + Object.extend(event, additionalMethods); + + return event; + }; } else { - Event.prototype = Event.prototype || document.createEvent("HTMLEvents")['__proto__']; + Event.extend = Prototype.K; + } + + if (window.addEventListener) { + Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__; Object.extend(Event.prototype, methods); - return Prototype.K; } -})(); -Object.extend(Event, (function() { - var cache = Event.cache; + function _createResponder(element, eventName, handler) { + var registry = Element.retrieve(element, 'prototype_event_registry'); - function getEventID(element) { - try { - if (element._prototypeEventID) return element._prototypeEventID[0]; - arguments.callee.id = arguments.callee.id || 1; - return element._prototypeEventID = [++arguments.callee.id]; - } catch (error) { - return false; + if (Object.isUndefined(registry)) { + CACHE.push(element); + registry = Element.retrieve(element, 'prototype_event_registry', $H()); } - } - function getDOMEventName(eventName) { - if (eventName && eventName.include(':')) return "dataavailable"; - return eventName; - } - - function getCacheForID(id) { - return cache[id] = cache[id] || { }; - } + var respondersForEvent = registry.get(eventName); + if (Object.isUndefined(respondersForEvent)) { + respondersForEvent = []; + registry.set(eventName, respondersForEvent); + } - function getWrappersForEventName(id, eventName) { - var c = getCacheForID(id); - return c[eventName] = c[eventName] || []; - } + if (respondersForEvent.pluck('handler').include(handler)) return false; - function createWrapper(element, eventName, handler) { - var id = getEventID(element); - var c = getWrappersForEventName(id, eventName); - if (c.pluck("handler").include(handler)) return false; + var responder; + if (eventName.include(":")) { + responder = function(event) { + if (Object.isUndefined(event.eventName)) + return false; - var wrapper = function(event) { - if (!Event || !Event.extend || - (event.eventName && event.eventName != eventName)) + if (event.eventName !== eventName) return false; - Event.extend(event); - handler.call(element, event); - }; + Event.extend(event, element); + handler.call(element, event); + }; + } else { + if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED && + (eventName === "mouseenter" || eventName === "mouseleave")) { + if (eventName === "mouseenter" || eventName === "mouseleave") { + responder = function(event) { + Event.extend(event, element); + + var parent = event.relatedTarget; + while (parent && parent !== element) { + try { parent = parent.parentNode; } + catch(e) { parent = element; } + } - wrapper.handler = handler; - c.push(wrapper); - return wrapper; - } + if (parent === element) return; - function findWrapper(id, eventName, handler) { - var c = getWrappersForEventName(id, eventName); - return c.find(function(wrapper) { return wrapper.handler == handler }); - } + handler.call(element, event); + }; + } + } else { + responder = function(event) { + Event.extend(event, element); + handler.call(element, event); + }; + } + } - function destroyWrapper(id, eventName, handler) { - var c = getCacheForID(id); - if (!c[eventName]) return false; - c[eventName] = c[eventName].without(findWrapper(id, eventName, handler)); + responder.handler = handler; + respondersForEvent.push(responder); + return responder; } - function destroyCache() { - for (var id in cache) - for (var eventName in cache[id]) - cache[id][eventName] = null; + function _destroyCache() { + for (var i = 0, length = CACHE.length; i < length; i++) { + Event.stopObserving(CACHE[i]); + CACHE[i] = null; + } } + var CACHE = []; - // Internet Explorer needs to remove event handlers on page unload - // in order to avoid memory leaks. - if (window.attachEvent) { - window.attachEvent("onunload", destroyCache); - } + if (Prototype.Browser.IE) + window.attachEvent('onunload', _destroyCache); - // Safari has a dummy event handler on page unload so that it won't - // use its bfcache. Safari <= 3.1 has an issue with restoring the "document" - // object when page is returned to via the back button using its bfcache. - if (Prototype.Browser.WebKit) { + if (Prototype.Browser.WebKit) window.addEventListener('unload', Prototype.emptyFunction, false); + + + var _getDOMEventName = Prototype.K, + translations = { mouseenter: "mouseover", mouseleave: "mouseout" }; + + if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) { + _getDOMEventName = function(eventName) { + return (translations[eventName] || eventName); + }; } - return { - observe: function(element, eventName, handler) { - element = $(element); - var name = getDOMEventName(eventName); + function observe(element, eventName, handler) { + element = $(element); - var wrapper = createWrapper(element, eventName, handler); - if (!wrapper) return element; + var responder = _createResponder(element, eventName, handler); - if (element.addEventListener) { - element.addEventListener(name, wrapper, false); - } else { - element.attachEvent("on" + name, wrapper); + if (!responder) return element; + + if (eventName.include(':')) { + if (element.addEventListener) + element.addEventListener("dataavailable", responder, false); + else { + element.attachEvent("ondataavailable", responder); + element.attachEvent("onlosecapture", responder); } + } else { + var actualEventName = _getDOMEventName(eventName); + + if (element.addEventListener) + element.addEventListener(actualEventName, responder, false); + else + element.attachEvent("on" + actualEventName, responder); + } + + return element; + } + function stopObserving(element, eventName, handler) { + element = $(element); + + var registry = Element.retrieve(element, 'prototype_event_registry'); + if (!registry) return element; + + if (!eventName) { + registry.each( function(pair) { + var eventName = pair.key; + stopObserving(element, eventName); + }); return element; - }, + } - stopObserving: function(element, eventName, handler) { - element = $(element); - var id = getEventID(element), name = getDOMEventName(eventName); + var responders = registry.get(eventName); + if (!responders) return element; - if (!handler && eventName) { - getWrappersForEventName(id, eventName).each(function(wrapper) { - element.stopObserving(eventName, wrapper.handler); - }); - return element; + if (!handler) { + responders.each(function(r) { + stopObserving(element, eventName, r.handler); + }); + return element; + } - } else if (!eventName) { - Object.keys(getCacheForID(id)).each(function(eventName) { - element.stopObserving(eventName); - }); - return element; + var i = responders.length, responder; + while (i--) { + if (responders[i].handler === handler) { + responder = responders[i]; + break; + } + } + if (!responder) return element; + + if (eventName.include(':')) { + if (element.removeEventListener) + element.removeEventListener("dataavailable", responder, false); + else { + element.detachEvent("ondataavailable", responder); + element.detachEvent("onlosecapture", responder); } + } else { + var actualEventName = _getDOMEventName(eventName); + if (element.removeEventListener) + element.removeEventListener(actualEventName, responder, false); + else + element.detachEvent('on' + actualEventName, responder); + } - var wrapper = findWrapper(id, eventName, handler); - if (!wrapper) return element; + registry.set(eventName, responders.without(responder)); - if (element.removeEventListener) { - element.removeEventListener(name, wrapper, false); - } else { - element.detachEvent("on" + name, wrapper); - } + return element; + } - destroyWrapper(id, eventName, handler); + function fire(element, eventName, memo, bubble) { + element = $(element); - return element; - }, + if (Object.isUndefined(bubble)) + bubble = true; - fire: function(element, eventName, memo) { - element = $(element); - if (element == document && document.createEvent && !element.dispatchEvent) - element = document.documentElement; + if (element == document && document.createEvent && !element.dispatchEvent) + element = document.documentElement; - var event; - if (document.createEvent) { - event = document.createEvent("HTMLEvents"); - event.initEvent("dataavailable", true, true); - } else { - event = document.createEventObject(); - event.eventType = "ondataavailable"; - } + var event; + if (document.createEvent) { + event = document.createEvent('HTMLEvents'); + event.initEvent('dataavailable', bubble, true); + } else { + event = document.createEventObject(); + event.eventType = bubble ? 'ondataavailable' : 'onlosecapture'; + } - event.eventName = eventName; - event.memo = memo || { }; + event.eventName = eventName; + event.memo = memo || { }; - if (document.createEvent) { - element.dispatchEvent(event); - } else { - element.fireEvent(event.eventType, event); - } + if (document.createEvent) + element.dispatchEvent(event); + else + element.fireEvent(event.eventType, event); + + return Event.extend(event); + } + + Event.Handler = Class.create({ + initialize: function(element, eventName, selector, callback) { + this.element = $(element); + this.eventName = eventName; + this.selector = selector; + this.callback = callback; + this.handler = this.handleEvent.bind(this); + }, + + start: function() { + Event.observe(this.element, this.eventName, this.handler); + return this; + }, + + stop: function() { + Event.stopObserving(this.element, this.eventName, this.handler); + return this; + }, - return Event.extend(event); + handleEvent: function(event) { + var element = Event.findElement(event, this.selector); + if (element) this.callback.call(this.element, event, element); } - }; -})()); + }); -Object.extend(Event, Event.Methods); + function on(element, eventName, selector, callback) { + element = $(element); + if (Object.isFunction(selector) && Object.isUndefined(callback)) { + callback = selector, selector = null; + } -Element.addMethods({ - fire: Event.fire, - observe: Event.observe, - stopObserving: Event.stopObserving -}); + return new Event.Handler(element, eventName, selector, callback).start(); + } -Object.extend(document, { - fire: Element.Methods.fire.methodize(), - observe: Element.Methods.observe.methodize(), - stopObserving: Element.Methods.stopObserving.methodize(), - loaded: false -}); + Object.extend(Event, Event.Methods); + + Object.extend(Event, { + fire: fire, + observe: observe, + stopObserving: stopObserving, + on: on + }); + + Element.addMethods({ + fire: fire, + + observe: observe, + + stopObserving: stopObserving, + + on: on + }); + + Object.extend(document, { + fire: fire.methodize(), + + observe: observe.methodize(), + + stopObserving: stopObserving.methodize(), + + on: on.methodize(), + + loaded: false + }); + + if (window.Event) Object.extend(window.Event, Event); + else window.Event = Event; +})(); (function() { /* Support for the DOMContentLoaded event is based on work by Dan Webb, - Matthias Miller, Dean Edwards and John Resig. */ + Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */ var timer; function fireContentLoadedEvent() { if (document.loaded) return; - if (timer) window.clearInterval(timer); - document.fire("dom:loaded"); + if (timer) window.clearTimeout(timer); document.loaded = true; + document.fire('dom:loaded'); } - if (document.addEventListener) { - if (Prototype.Browser.WebKit) { - timer = window.setInterval(function() { - if (/loaded|complete/.test(document.readyState)) - fireContentLoadedEvent(); - }, 0); - - Event.observe(window, "load", fireContentLoadedEvent); + function checkReadyState() { + if (document.readyState === 'complete') { + document.stopObserving('readystatechange', checkReadyState); + fireContentLoadedEvent(); + } + } - } else { - document.addEventListener("DOMContentLoaded", - fireContentLoadedEvent, false); + function pollDoScroll() { + try { document.documentElement.doScroll('left'); } + catch(e) { + timer = pollDoScroll.defer(); + return; } + fireContentLoadedEvent(); + } + if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false); } else { - document.write("